blob: ec258aeba7683e8e5233961a9893dc77afcb8e61 [file] [log] [blame]
Ken Cox12e364b2014-03-04 07:58:07 -06001/* visorchipset_main.c
2 *
Benjamin Romerf6d0c1e2014-04-23 14:58:34 -04003 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
Ken Cox12e364b2014-03-04 07:58:07 -06004 * 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"
Ken Cox12e364b2014-03-04 07:58:07 -060019#include "visorchipset.h"
20#include "procobjecttree.h"
21#include "visorchannel.h"
22#include "periodic_work.h"
Ken Cox12e364b2014-03-04 07:58:07 -060023#include "file.h"
24#include "parser.h"
Ken Cox12e364b2014-03-04 07:58:07 -060025#include "uisutils.h"
Ken Cox12e364b2014-03-04 07:58:07 -060026#include "controlvmcompletionstatus.h"
27#include "guestlinuxdebug.h"
Ken Cox12e364b2014-03-04 07:58:07 -060028
29#include <linux/nls.h>
30#include <linux/netdevice.h>
31#include <linux/platform_device.h>
Benjamin Romer90addb02014-05-06 09:58:23 -040032#include <linux/uuid.h>
Ken Cox12e364b2014-03-04 07:58:07 -060033
34#define CURRENT_FILE_PC VISOR_CHIPSET_PC_visorchipset_main_c
35#define TEST_VNIC_PHYSITF "eth0" /* physical network itf for
36 * vnic loopback test */
37#define TEST_VNIC_SWITCHNO 1
38#define TEST_VNIC_BUSNO 9
39
40#define MAX_NAME_SIZE 128
41#define MAX_IP_SIZE 50
42#define MAXOUTSTANDINGCHANNELCOMMAND 256
43#define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1
44#define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100
45
46/* When the controlvm channel is idle for at least MIN_IDLE_SECONDS,
47* we switch to slow polling mode. As soon as we get a controlvm
48* message, we switch back to fast polling mode.
49*/
50#define MIN_IDLE_SECONDS 10
Ken Coxbd5b9b32014-03-13 15:39:22 -050051static ulong Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
52static ulong Most_recent_message_jiffies; /* when we got our last
53 * controlvm message */
Ken Cox12e364b2014-03-04 07:58:07 -060054static inline char *
55NONULLSTR(char *s)
56{
57 if (s)
58 return s;
Benjamin Romere22a4a02014-08-18 09:34:54 -040059 return "";
Ken Cox12e364b2014-03-04 07:58:07 -060060}
61
62static int serverregistered;
63static int clientregistered;
64
65#define MAX_CHIPSET_EVENTS 2
Benjamin Romerc2422332014-07-29 15:09:40 -040066static u8 chipset_events[MAX_CHIPSET_EVENTS] = { 0, 0 };
Ken Cox12e364b2014-03-04 07:58:07 -060067
68static struct delayed_work Periodic_controlvm_work;
69static struct workqueue_struct *Periodic_controlvm_workqueue;
Ken Coxbd5b9b32014-03-13 15:39:22 -050070static DEFINE_SEMAPHORE(NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -060071
Benjamin Romer98d7b592014-10-23 14:30:26 -040072static struct controlvm_message_header g_DiagMsgHdr;
73static struct controlvm_message_header g_ChipSetMsgHdr;
74static struct controlvm_message_header g_DelDumpMsgHdr;
Benjamin Romer90addb02014-05-06 09:58:23 -040075static const uuid_le UltraDiagPoolChannelProtocolGuid =
Benjamin Romer9eee5d12014-10-23 14:29:47 -040076 SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID;
Ken Cox12e364b2014-03-04 07:58:07 -060077/* 0xffffff is an invalid Bus/Device number */
78static ulong g_diagpoolBusNo = 0xffffff;
79static ulong g_diagpoolDevNo = 0xffffff;
Benjamin Romer2ea51172014-10-23 14:30:25 -040080static struct controlvm_message_packet g_DeviceChangeStatePacket;
Ken Cox12e364b2014-03-04 07:58:07 -060081
82/* Only VNIC and VHBA channels are sent to visorclientbus (aka
83 * "visorhackbus")
84 */
85#define FOR_VISORHACKBUS(channel_type_guid) \
Benjamin Romer9eee5d12014-10-23 14:29:47 -040086 (((uuid_le_cmp(channel_type_guid,\
87 spar_vnic_channel_protocol_uuid) == 0)\
88 || (uuid_le_cmp(channel_type_guid,\
89 spar_vhba_channel_protocol_uuid) == 0)))
Ken Cox12e364b2014-03-04 07:58:07 -060090#define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid)))
91
92#define is_diagpool_channel(channel_type_guid) \
Benjamin Romer90addb02014-05-06 09:58:23 -040093 (uuid_le_cmp(channel_type_guid, UltraDiagPoolChannelProtocolGuid) == 0)
Ken Cox12e364b2014-03-04 07:58:07 -060094
Ken Cox12e364b2014-03-04 07:58:07 -060095static LIST_HEAD(BusInfoList);
96static LIST_HEAD(DevInfoList);
97
Bryan Thompson383df642014-12-05 17:09:25 -050098static struct visorchannel *ControlVm_channel;
Ken Cox12e364b2014-03-04 07:58:07 -060099
Frederico Cadete84b11df2015-02-18 19:53:40 +0100100struct controlvm_payload_info {
Benjamin Romerc2422332014-07-29 15:09:40 -0400101 u8 __iomem *ptr; /* pointer to base address of payload pool */
Benjamin Romer5fc02292014-07-31 12:00:51 -0400102 u64 offset; /* offset from beginning of controlvm
Ken Cox12e364b2014-03-04 07:58:07 -0600103 * channel to beginning of payload * pool */
Benjamin Romerb3c55b12014-07-31 12:00:50 -0400104 u32 bytes; /* number of bytes in payload pool */
Frederico Cadete84b11df2015-02-18 19:53:40 +0100105};
Ken Cox12e364b2014-03-04 07:58:07 -0600106
107/* Manages the request payload in the controlvm channel */
Frederico Cadete84b11df2015-02-18 19:53:40 +0100108static struct controlvm_payload_info ControlVm_payload_info;
Ken Cox12e364b2014-03-04 07:58:07 -0600109
Benjamin Romer9fd1b952014-10-23 14:29:55 -0400110static struct channel_header *Test_Vnic_channel;
Ken Cox12e364b2014-03-04 07:58:07 -0600111
Frederico Cadete84b11df2015-02-18 19:53:40 +0100112struct livedump_info {
Benjamin Romer98d7b592014-10-23 14:30:26 -0400113 struct controlvm_message_header Dumpcapture_header;
114 struct controlvm_message_header Gettextdump_header;
115 struct controlvm_message_header Dumpcomplete_header;
Ken Cox12e364b2014-03-04 07:58:07 -0600116 BOOL Gettextdump_outstanding;
117 u32 crc32;
118 ulong length;
119 atomic_t buffers_in_use;
120 ulong destination;
Frederico Cadete84b11df2015-02-18 19:53:40 +0100121};
Ken Cox12e364b2014-03-04 07:58:07 -0600122/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
123 * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation.
124 */
Frederico Cadete84b11df2015-02-18 19:53:40 +0100125static struct livedump_info LiveDump_info;
Ken Cox12e364b2014-03-04 07:58:07 -0600126
127/* The following globals are used to handle the scenario where we are unable to
128 * offload the payload from a controlvm message due to memory requirements. In
129 * this scenario, we simply stash the controlvm message, then attempt to
130 * process it again the next time controlvm_periodic_work() runs.
131 */
Benjamin Romer3ab47702014-10-23 14:30:31 -0400132static struct controlvm_message ControlVm_Pending_Msg;
Ken Cox12e364b2014-03-04 07:58:07 -0600133static BOOL ControlVm_Pending_Msg_Valid = FALSE;
134
135/* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
136 * TRANSMIT_FILE PutFile payloads.
137 */
138static struct kmem_cache *Putfile_buffer_list_pool;
139static const char Putfile_buffer_list_pool_name[] =
140 "controlvm_putfile_buffer_list_pool";
141
142/* This identifies a data buffer that has been received via a controlvm messages
143 * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation.
144 */
145struct putfile_buffer_entry {
146 struct list_head next; /* putfile_buffer_entry list */
147 PARSER_CONTEXT *parser_ctx; /* points to buffer containing input data */
148};
149
150/* List of struct putfile_request *, via next_putfile_request member.
151 * Each entry in this list identifies an outstanding TRANSMIT_FILE
152 * conversation.
153 */
154static LIST_HEAD(Putfile_request_list);
155
156/* This describes a buffer and its current state of transfer (e.g., how many
157 * bytes have already been supplied as putfile data, and how many bytes are
158 * remaining) for a putfile_request.
159 */
160struct putfile_active_buffer {
161 /* a payload from a controlvm message, containing a file data buffer */
162 PARSER_CONTEXT *parser_ctx;
163 /* points within data area of parser_ctx to next byte of data */
164 u8 *pnext;
165 /* # bytes left from <pnext> to the end of this data buffer */
166 size_t bytes_remaining;
167};
168
169#define PUTFILE_REQUEST_SIG 0x0906101302281211
170/* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE
171 * conversation. Structs of this type are dynamically linked into
172 * <Putfile_request_list>.
173 */
174struct putfile_request {
175 u64 sig; /* PUTFILE_REQUEST_SIG */
176
177 /* header from original TransmitFile request */
Benjamin Romer98d7b592014-10-23 14:30:26 -0400178 struct controlvm_message_header controlvm_header;
Ken Cox12e364b2014-03-04 07:58:07 -0600179 u64 file_request_number; /* from original TransmitFile request */
180
181 /* link to next struct putfile_request */
182 struct list_head next_putfile_request;
183
184 /* most-recent sequence number supplied via a controlvm message */
185 u64 data_sequence_number;
186
187 /* head of putfile_buffer_entry list, which describes the data to be
188 * supplied as putfile data;
189 * - this list is added to when controlvm messages come in that supply
190 * file data
191 * - this list is removed from via the hotplug program that is actually
192 * consuming these buffers to write as file data */
193 struct list_head input_buffer_list;
194 spinlock_t req_list_lock; /* lock for input_buffer_list */
195
196 /* waiters for input_buffer_list to go non-empty */
197 wait_queue_head_t input_buffer_wq;
198
199 /* data not yet read within current putfile_buffer_entry */
200 struct putfile_active_buffer active_buf;
201
202 /* <0 = failed, 0 = in-progress, >0 = successful; */
203 /* note that this must be set with req_list_lock, and if you set <0, */
204 /* it is your responsibility to also free up all of the other objects */
205 /* in this struct (like input_buffer_list, active_buf.parser_ctx) */
206 /* before releasing the lock */
207 int completion_status;
208};
209
Ken Coxbd5b9b32014-03-13 15:39:22 -0500210static atomic_t Visorchipset_cache_buffers_in_use = ATOMIC_INIT(0);
Ken Cox12e364b2014-03-04 07:58:07 -0600211
212struct parahotplug_request {
213 struct list_head list;
214 int id;
215 unsigned long expiration;
Benjamin Romer3ab47702014-10-23 14:30:31 -0400216 struct controlvm_message msg;
Ken Cox12e364b2014-03-04 07:58:07 -0600217};
218
219static LIST_HEAD(Parahotplug_request_list);
220static DEFINE_SPINLOCK(Parahotplug_request_list_lock); /* lock for above */
221static void parahotplug_process_list(void);
222
223/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
224 * CONTROLVM_REPORTEVENT.
225 */
Benjamin Romerfe90d892014-10-31 09:57:32 -0400226static struct visorchipset_busdev_notifiers BusDev_Server_Notifiers;
227static struct visorchipset_busdev_notifiers BusDev_Client_Notifiers;
Ken Cox12e364b2014-03-04 07:58:07 -0600228
229static void bus_create_response(ulong busNo, int response);
230static void bus_destroy_response(ulong busNo, int response);
231static void device_create_response(ulong busNo, ulong devNo, int response);
232static void device_destroy_response(ulong busNo, ulong devNo, int response);
233static void device_resume_response(ulong busNo, ulong devNo, int response);
234
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400235static struct visorchipset_busdev_responders BusDev_Responders = {
Ken Cox12e364b2014-03-04 07:58:07 -0600236 .bus_create = bus_create_response,
237 .bus_destroy = bus_destroy_response,
238 .device_create = device_create_response,
239 .device_destroy = device_destroy_response,
Ken Cox927c7922014-03-05 14:52:25 -0600240 .device_pause = visorchipset_device_pause_response,
Ken Cox12e364b2014-03-04 07:58:07 -0600241 .device_resume = device_resume_response,
242};
243
244/* info for /dev/visorchipset */
245static dev_t MajorDev = -1; /**< indicates major num for device */
246
Benjamin Romer19f66342014-07-22 09:56:25 -0400247/* prototypes for attributes */
248static ssize_t toolaction_show(struct device *dev,
249 struct device_attribute *attr, char *buf);
250static ssize_t toolaction_store(struct device *dev,
251 struct device_attribute *attr, const char *buf, size_t count);
252static DEVICE_ATTR_RW(toolaction);
253
Benjamin Romer54b31222014-07-22 09:56:26 -0400254static ssize_t boottotool_show(struct device *dev,
255 struct device_attribute *attr, char *buf);
256static ssize_t boottotool_store(struct device *dev,
257 struct device_attribute *attr, const char *buf, size_t count);
258static DEVICE_ATTR_RW(boottotool);
259
Benjamin Romer422af172014-07-24 14:08:42 -0400260static ssize_t error_show(struct device *dev, struct device_attribute *attr,
261 char *buf);
262static ssize_t error_store(struct device *dev, struct device_attribute *attr,
263 const char *buf, size_t count);
264static DEVICE_ATTR_RW(error);
265
266static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
267 char *buf);
268static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
269 const char *buf, size_t count);
270static DEVICE_ATTR_RW(textid);
271
272static ssize_t remaining_steps_show(struct device *dev,
273 struct device_attribute *attr, char *buf);
274static ssize_t remaining_steps_store(struct device *dev,
275 struct device_attribute *attr, const char *buf, size_t count);
276static DEVICE_ATTR_RW(remaining_steps);
277
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400278static ssize_t chipsetready_store(struct device *dev,
279 struct device_attribute *attr, const char *buf, size_t count);
280static DEVICE_ATTR_WO(chipsetready);
281
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400282static ssize_t devicedisabled_store(struct device *dev,
283 struct device_attribute *attr, const char *buf, size_t count);
284static DEVICE_ATTR_WO(devicedisabled);
285
286static ssize_t deviceenabled_store(struct device *dev,
287 struct device_attribute *attr, const char *buf, size_t count);
288static DEVICE_ATTR_WO(deviceenabled);
289
Benjamin Romer19f66342014-07-22 09:56:25 -0400290static struct attribute *visorchipset_install_attrs[] = {
291 &dev_attr_toolaction.attr,
Benjamin Romer54b31222014-07-22 09:56:26 -0400292 &dev_attr_boottotool.attr,
Benjamin Romer422af172014-07-24 14:08:42 -0400293 &dev_attr_error.attr,
294 &dev_attr_textid.attr,
295 &dev_attr_remaining_steps.attr,
Benjamin Romer19f66342014-07-22 09:56:25 -0400296 NULL
297};
298
299static struct attribute_group visorchipset_install_group = {
300 .name = "install",
301 .attrs = visorchipset_install_attrs
302};
303
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400304static struct attribute *visorchipset_guest_attrs[] = {
305 &dev_attr_chipsetready.attr,
306 NULL
307};
308
309static struct attribute_group visorchipset_guest_group = {
310 .name = "guest",
311 .attrs = visorchipset_guest_attrs
312};
313
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400314static struct attribute *visorchipset_parahotplug_attrs[] = {
315 &dev_attr_devicedisabled.attr,
316 &dev_attr_deviceenabled.attr,
317 NULL
318};
319
320static struct attribute_group visorchipset_parahotplug_group = {
321 .name = "parahotplug",
322 .attrs = visorchipset_parahotplug_attrs
323};
324
Benjamin Romer19f66342014-07-22 09:56:25 -0400325static const struct attribute_group *visorchipset_dev_groups[] = {
326 &visorchipset_install_group,
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400327 &visorchipset_guest_group,
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400328 &visorchipset_parahotplug_group,
Benjamin Romer19f66342014-07-22 09:56:25 -0400329 NULL
330};
331
Ken Cox12e364b2014-03-04 07:58:07 -0600332/* /sys/devices/platform/visorchipset */
333static struct platform_device Visorchipset_platform_device = {
334 .name = "visorchipset",
335 .id = -1,
Benjamin Romer19f66342014-07-22 09:56:25 -0400336 .dev.groups = visorchipset_dev_groups,
Ken Cox12e364b2014-03-04 07:58:07 -0600337};
338
339/* Function prototypes */
Benjamin Romer98d7b592014-10-23 14:30:26 -0400340static void controlvm_respond(struct controlvm_message_header *msgHdr,
341 int response);
342static void controlvm_respond_chipset_init(
343 struct controlvm_message_header *msgHdr, int response,
344 enum ultra_chipset_feature features);
345static void controlvm_respond_physdev_changestate(
346 struct controlvm_message_header *msgHdr, int response,
347 struct spar_segment_state state);
Ken Cox12e364b2014-03-04 07:58:07 -0600348
Vincent Bernatd746cb52014-08-01 10:29:30 +0200349static ssize_t toolaction_show(struct device *dev,
350 struct device_attribute *attr,
351 char *buf)
Benjamin Romer19f66342014-07-22 09:56:25 -0400352{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400353 u8 toolAction;
Benjamin Romer19f66342014-07-22 09:56:25 -0400354
355 visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400356 offsetof(struct spar_controlvm_channel_protocol,
357 tool_action), &toolAction, sizeof(u8));
Benjamin Romer19f66342014-07-22 09:56:25 -0400358 return scnprintf(buf, PAGE_SIZE, "%u\n", toolAction);
359}
360
Vincent Bernatd746cb52014-08-01 10:29:30 +0200361static ssize_t toolaction_store(struct device *dev,
362 struct device_attribute *attr,
363 const char *buf, size_t count)
Benjamin Romer19f66342014-07-22 09:56:25 -0400364{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400365 u8 toolAction;
366 int ret;
Benjamin Romer19f66342014-07-22 09:56:25 -0400367
Benjamin Romer66e24b72014-07-25 13:55:10 -0400368 if (kstrtou8(buf, 10, &toolAction) != 0)
369 return -EINVAL;
370
371 ret = visorchannel_write(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400372 offsetof(struct spar_controlvm_channel_protocol, tool_action),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400373 &toolAction, sizeof(u8));
374
375 if (ret)
376 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400377 return count;
Benjamin Romer19f66342014-07-22 09:56:25 -0400378}
379
Vincent Bernatd746cb52014-08-01 10:29:30 +0200380static ssize_t boottotool_show(struct device *dev,
381 struct device_attribute *attr,
382 char *buf)
Benjamin Romer54b31222014-07-22 09:56:26 -0400383{
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400384 struct efi_spar_indication efiSparIndication;
Benjamin Romer54b31222014-07-22 09:56:26 -0400385
386 visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400387 offsetof(struct spar_controlvm_channel_protocol,
388 efi_spar_ind), &efiSparIndication,
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400389 sizeof(struct efi_spar_indication));
Benjamin Romer54b31222014-07-22 09:56:26 -0400390 return scnprintf(buf, PAGE_SIZE, "%u\n",
Benjamin Romer24503012014-10-23 14:30:22 -0400391 efiSparIndication.boot_to_tool);
Benjamin Romer54b31222014-07-22 09:56:26 -0400392}
393
Vincent Bernatd746cb52014-08-01 10:29:30 +0200394static ssize_t boottotool_store(struct device *dev,
395 struct device_attribute *attr,
396 const char *buf, size_t count)
Benjamin Romer54b31222014-07-22 09:56:26 -0400397{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400398 int val, ret;
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400399 struct efi_spar_indication efiSparIndication;
Benjamin Romer54b31222014-07-22 09:56:26 -0400400
Benjamin Romer66e24b72014-07-25 13:55:10 -0400401 if (kstrtoint(buf, 10, &val) != 0)
402 return -EINVAL;
403
Benjamin Romer24503012014-10-23 14:30:22 -0400404 efiSparIndication.boot_to_tool = val;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400405 ret = visorchannel_write(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400406 offsetof(struct spar_controlvm_channel_protocol,
407 efi_spar_ind),
Benjamin Romer54b31222014-07-22 09:56:26 -0400408 &(efiSparIndication),
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400409 sizeof(struct efi_spar_indication));
Benjamin Romer66e24b72014-07-25 13:55:10 -0400410
411 if (ret)
412 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400413 return count;
Benjamin Romer54b31222014-07-22 09:56:26 -0400414}
Benjamin Romer422af172014-07-24 14:08:42 -0400415
416static ssize_t error_show(struct device *dev, struct device_attribute *attr,
417 char *buf)
418{
419 u32 error;
420
421 visorchannel_read(ControlVm_channel, offsetof(
Benjamin Romerd19642f2014-10-23 14:30:34 -0400422 struct spar_controlvm_channel_protocol, installation_error),
Benjamin Romer422af172014-07-24 14:08:42 -0400423 &error, sizeof(u32));
424 return scnprintf(buf, PAGE_SIZE, "%i\n", error);
425}
426
427static ssize_t error_store(struct device *dev, struct device_attribute *attr,
428 const char *buf, size_t count)
429{
430 u32 error;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400431 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400432
Benjamin Romer66e24b72014-07-25 13:55:10 -0400433 if (kstrtou32(buf, 10, &error) != 0)
434 return -EINVAL;
435
436 ret = visorchannel_write(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400437 offsetof(struct spar_controlvm_channel_protocol,
438 installation_error),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400439 &error, sizeof(u32));
440 if (ret)
441 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400442 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400443}
444
445static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
446 char *buf)
447{
448 u32 textId;
449
450 visorchannel_read(ControlVm_channel, offsetof(
Benjamin Romerd19642f2014-10-23 14:30:34 -0400451 struct spar_controlvm_channel_protocol, installation_text_id),
Benjamin Romer422af172014-07-24 14:08:42 -0400452 &textId, sizeof(u32));
453 return scnprintf(buf, PAGE_SIZE, "%i\n", textId);
454}
455
456static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
457 const char *buf, size_t count)
458{
459 u32 textId;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400460 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400461
Benjamin Romer66e24b72014-07-25 13:55:10 -0400462 if (kstrtou32(buf, 10, &textId) != 0)
463 return -EINVAL;
464
465 ret = visorchannel_write(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400466 offsetof(struct spar_controlvm_channel_protocol,
467 installation_text_id),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400468 &textId, sizeof(u32));
469 if (ret)
470 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400471 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400472}
473
474
475static ssize_t remaining_steps_show(struct device *dev,
476 struct device_attribute *attr, char *buf)
477{
478 u16 remainingSteps;
479
480 visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400481 offsetof(struct spar_controlvm_channel_protocol,
482 installation_remaining_steps),
Benjamin Romer422af172014-07-24 14:08:42 -0400483 &remainingSteps,
484 sizeof(u16));
485 return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps);
486}
487
488static ssize_t remaining_steps_store(struct device *dev,
489 struct device_attribute *attr, const char *buf, size_t count)
490{
491 u16 remainingSteps;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400492 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400493
Benjamin Romer66e24b72014-07-25 13:55:10 -0400494 if (kstrtou16(buf, 10, &remainingSteps) != 0)
495 return -EINVAL;
496
497 ret = visorchannel_write(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400498 offsetof(struct spar_controlvm_channel_protocol,
499 installation_remaining_steps),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400500 &remainingSteps, sizeof(u16));
501 if (ret)
502 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400503 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400504}
505
Ken Cox12e364b2014-03-04 07:58:07 -0600506#if 0
507static void
508testUnicode(void)
509{
510 wchar_t unicodeString[] = { 'a', 'b', 'c', 0 };
511 char s[sizeof(unicodeString) * NLS_MAX_CHARSET_SIZE];
512 wchar_t unicode2[99];
513
514 /* NOTE: Either due to a bug, or feature I don't understand, the
515 * kernel utf8_mbstowcs() and utf_wcstombs() do NOT copy the
516 * trailed NUL byte!! REALLY!!!!! Arrrrgggghhhhh
517 */
518
519 LOGINF("sizeof(wchar_t) = %d", sizeof(wchar_t));
520 LOGINF("utf8_wcstombs=%d",
521 chrs = utf8_wcstombs(s, unicodeString, sizeof(s)));
522 if (chrs >= 0)
523 s[chrs] = '\0'; /* GRRRRRRRR */
524 LOGINF("s='%s'", s);
525 LOGINF("utf8_mbstowcs=%d", chrs = utf8_mbstowcs(unicode2, s, 100));
526 if (chrs >= 0)
527 unicode2[chrs] = 0; /* GRRRRRRRR */
528 if (memcmp(unicodeString, unicode2, sizeof(unicodeString)) == 0)
529 LOGINF("strings match... good");
530 else
531 LOGINF("strings did not match!!");
532}
533#endif
534
535static void
536busInfo_clear(void *v)
537{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400538 struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v);
Ken Cox12e364b2014-03-04 07:58:07 -0600539
Benjamin Romer33192fa2014-10-31 09:57:27 -0400540 if (p->proc_object) {
541 visor_proc_DestroyObject(p->proc_object);
542 p->proc_object = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600543 }
544 kfree(p->name);
545 p->name = NULL;
546
547 kfree(p->description);
548 p->description = NULL;
549
550 p->state.created = 0;
Benjamin Romer33192fa2014-10-31 09:57:27 -0400551 memset(p, 0, sizeof(struct visorchipset_bus_info));
Ken Cox12e364b2014-03-04 07:58:07 -0600552}
553
554static void
555devInfo_clear(void *v)
556{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400557 struct visorchipset_device_info *p =
558 (struct visorchipset_device_info *)(v);
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400559
Ken Cox12e364b2014-03-04 07:58:07 -0600560 p->state.created = 0;
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400561 memset(p, 0, sizeof(struct visorchipset_device_info));
Ken Cox12e364b2014-03-04 07:58:07 -0600562}
563
Benjamin Romerc2422332014-07-29 15:09:40 -0400564static u8
Ken Cox12e364b2014-03-04 07:58:07 -0600565check_chipset_events(void)
566{
567 int i;
Benjamin Romerc2422332014-07-29 15:09:40 -0400568 u8 send_msg = 1;
Ken Cox12e364b2014-03-04 07:58:07 -0600569 /* Check events to determine if response should be sent */
570 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
571 send_msg &= chipset_events[i];
572 return send_msg;
573}
574
575static void
576clear_chipset_events(void)
577{
578 int i;
579 /* Clear chipset_events */
580 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
581 chipset_events[i] = 0;
582}
583
584void
Benjamin Romerfe90d892014-10-31 09:57:32 -0400585visorchipset_register_busdev_server(
586 struct visorchipset_busdev_notifiers *notifiers,
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400587 struct visorchipset_busdev_responders *responders,
Benjamin Romer1e7a59c2014-10-31 09:57:35 -0400588 struct ultra_vbus_deviceinfo *driver_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600589{
Benjamin Romerf2170622014-08-05 14:57:47 -0400590 down(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600591 if (notifiers == NULL) {
592 memset(&BusDev_Server_Notifiers, 0,
593 sizeof(BusDev_Server_Notifiers));
594 serverregistered = 0; /* clear flag */
595 } else {
596 BusDev_Server_Notifiers = *notifiers;
597 serverregistered = 1; /* set flag */
598 }
599 if (responders)
600 *responders = BusDev_Responders;
Benjamin Romer1e7a59c2014-10-31 09:57:35 -0400601 if (driver_info)
602 bus_device_info_init(driver_info, "chipset", "visorchipset",
Ken Cox836bee92014-06-26 09:55:55 -0500603 VERSION, NULL);
Ken Cox12e364b2014-03-04 07:58:07 -0600604
Benjamin Romerf2170622014-08-05 14:57:47 -0400605 up(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600606}
607EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server);
608
609void
Benjamin Romerfe90d892014-10-31 09:57:32 -0400610visorchipset_register_busdev_client(
611 struct visorchipset_busdev_notifiers *notifiers,
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400612 struct visorchipset_busdev_responders *responders,
Benjamin Romer43fce012014-10-31 09:57:34 -0400613 struct ultra_vbus_deviceinfo *driver_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600614{
Benjamin Romerf2170622014-08-05 14:57:47 -0400615 down(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600616 if (notifiers == NULL) {
617 memset(&BusDev_Client_Notifiers, 0,
618 sizeof(BusDev_Client_Notifiers));
619 clientregistered = 0; /* clear flag */
620 } else {
621 BusDev_Client_Notifiers = *notifiers;
622 clientregistered = 1; /* set flag */
623 }
624 if (responders)
625 *responders = BusDev_Responders;
Benjamin Romer43fce012014-10-31 09:57:34 -0400626 if (driver_info)
627 bus_device_info_init(driver_info, "chipset(bolts)",
628 "visorchipset", VERSION, NULL);
Benjamin Romerf2170622014-08-05 14:57:47 -0400629 up(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600630}
631EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client);
632
633static void
634cleanup_controlvm_structures(void)
635{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400636 struct visorchipset_bus_info *bi, *tmp_bi;
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400637 struct visorchipset_device_info *di, *tmp_di;
Ken Cox12e364b2014-03-04 07:58:07 -0600638
Dan Carpentere6b1ea72014-04-10 12:45:45 +0300639 list_for_each_entry_safe(bi, tmp_bi, &BusInfoList, entry) {
Ken Cox12e364b2014-03-04 07:58:07 -0600640 busInfo_clear(bi);
641 list_del(&bi->entry);
642 kfree(bi);
643 }
644
Dan Carpentere6b1ea72014-04-10 12:45:45 +0300645 list_for_each_entry_safe(di, tmp_di, &DevInfoList, entry) {
Ken Cox12e364b2014-03-04 07:58:07 -0600646 devInfo_clear(di);
647 list_del(&di->entry);
648 kfree(di);
649 }
650}
651
652static void
Benjamin Romer3ab47702014-10-23 14:30:31 -0400653chipset_init(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -0600654{
655 static int chipset_inited;
Benjamin Romerb9b141e2014-10-23 14:30:24 -0400656 enum ultra_chipset_feature features = 0;
Ken Cox12e364b2014-03-04 07:58:07 -0600657 int rc = CONTROLVM_RESP_SUCCESS;
658
659 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
660 if (chipset_inited) {
Ken Cox22ad57b2014-03-19 13:06:25 -0500661 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
662 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -0600663 }
664 chipset_inited = 1;
665 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO);
666
667 /* Set features to indicate we support parahotplug (if Command
668 * also supports it). */
669 features =
Benjamin Romer2ea51172014-10-23 14:30:25 -0400670 inmsg->cmd.init_chipset.
Ken Cox12e364b2014-03-04 07:58:07 -0600671 features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG;
672
673 /* Set the "reply" bit so Command knows this is a
674 * features-aware driver. */
675 features |= ULTRA_CHIPSET_FEATURE_REPLY;
676
677Away:
678 if (rc < 0)
679 cleanup_controlvm_structures();
Benjamin Romer98d7b592014-10-23 14:30:26 -0400680 if (inmsg->hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -0600681 controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
682}
683
684static void
Benjamin Romer3ab47702014-10-23 14:30:31 -0400685controlvm_init_response(struct controlvm_message *msg,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400686 struct controlvm_message_header *msgHdr, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600687{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400688 memset(msg, 0, sizeof(struct controlvm_message));
Benjamin Romer98d7b592014-10-23 14:30:26 -0400689 memcpy(&msg->hdr, msgHdr, sizeof(struct controlvm_message_header));
690 msg->hdr.payload_bytes = 0;
691 msg->hdr.payload_vm_offset = 0;
692 msg->hdr.payload_max_bytes = 0;
Ken Cox12e364b2014-03-04 07:58:07 -0600693 if (response < 0) {
Benjamin Romer98d7b592014-10-23 14:30:26 -0400694 msg->hdr.flags.failed = 1;
695 msg->hdr.completion_status = (u32) (-response);
Ken Cox12e364b2014-03-04 07:58:07 -0600696 }
697}
698
699static void
Benjamin Romer98d7b592014-10-23 14:30:26 -0400700controlvm_respond(struct controlvm_message_header *msgHdr, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600701{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400702 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400703
Ken Cox12e364b2014-03-04 07:58:07 -0600704 controlvm_init_response(&outmsg, msgHdr, response);
705 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send
706 * back the deviceChangeState structure in the packet. */
Benjamin Romer98d7b592014-10-23 14:30:26 -0400707 if (msgHdr->id == CONTROLVM_DEVICE_CHANGESTATE
Benjamin Romer2ea51172014-10-23 14:30:25 -0400708 && g_DeviceChangeStatePacket.device_change_state.bus_no ==
Ken Cox12e364b2014-03-04 07:58:07 -0600709 g_diagpoolBusNo
Benjamin Romer2ea51172014-10-23 14:30:25 -0400710 && g_DeviceChangeStatePacket.device_change_state.dev_no ==
Ken Cox12e364b2014-03-04 07:58:07 -0600711 g_diagpoolDevNo)
712 outmsg.cmd = g_DeviceChangeStatePacket;
Benjamin Romer2098dbd2015-03-04 12:14:22 -0500713 if (outmsg.hdr.flags.test_message == 1)
Ken Cox12e364b2014-03-04 07:58:07 -0600714 return;
Benjamin Romer2098dbd2015-03-04 12:14:22 -0500715
Ken Cox12e364b2014-03-04 07:58:07 -0600716 if (!visorchannel_signalinsert(ControlVm_channel,
717 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600718 return;
719 }
720}
721
722static void
Benjamin Romer98d7b592014-10-23 14:30:26 -0400723controlvm_respond_chipset_init(struct controlvm_message_header *msgHdr,
724 int response,
Benjamin Romerb9b141e2014-10-23 14:30:24 -0400725 enum ultra_chipset_feature features)
Ken Cox12e364b2014-03-04 07:58:07 -0600726{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400727 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400728
Ken Cox12e364b2014-03-04 07:58:07 -0600729 controlvm_init_response(&outmsg, msgHdr, response);
Benjamin Romer2ea51172014-10-23 14:30:25 -0400730 outmsg.cmd.init_chipset.features = features;
Ken Cox12e364b2014-03-04 07:58:07 -0600731 if (!visorchannel_signalinsert(ControlVm_channel,
732 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600733 return;
734 }
735}
736
Benjamin Romer98d7b592014-10-23 14:30:26 -0400737static void controlvm_respond_physdev_changestate(
738 struct controlvm_message_header *msgHdr, int response,
739 struct spar_segment_state state)
Ken Cox12e364b2014-03-04 07:58:07 -0600740{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400741 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400742
Ken Cox12e364b2014-03-04 07:58:07 -0600743 controlvm_init_response(&outmsg, msgHdr, response);
Benjamin Romer2ea51172014-10-23 14:30:25 -0400744 outmsg.cmd.device_change_state.state = state;
745 outmsg.cmd.device_change_state.flags.phys_device = 1;
Ken Cox12e364b2014-03-04 07:58:07 -0600746 if (!visorchannel_signalinsert(ControlVm_channel,
747 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600748 return;
749 }
750}
751
752void
Benjamin Romer2c683cd2014-10-31 09:57:22 -0400753visorchipset_save_message(struct controlvm_message *msg,
754 enum crash_obj_type type)
Ken Cox12e364b2014-03-04 07:58:07 -0600755{
Benjamin Romerb3c55b12014-07-31 12:00:50 -0400756 u32 localSavedCrashMsgOffset;
Benjamin Romerb06bdf72014-07-31 12:00:49 -0400757 u16 localSavedCrashMsgCount;
Ken Cox12e364b2014-03-04 07:58:07 -0600758
759 /* get saved message count */
760 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400761 offsetof(struct spar_controlvm_channel_protocol,
762 saved_crash_message_count),
Benjamin Romerb06bdf72014-07-31 12:00:49 -0400763 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600764 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
765 POSTCODE_SEVERITY_ERR);
766 return;
767 }
768
769 if (localSavedCrashMsgCount != CONTROLVM_CRASHMSG_MAX) {
Ken Cox12e364b2014-03-04 07:58:07 -0600770 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
771 localSavedCrashMsgCount,
772 POSTCODE_SEVERITY_ERR);
773 return;
774 }
775
776 /* get saved crash message offset */
777 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400778 offsetof(struct spar_controlvm_channel_protocol,
779 saved_crash_message_offset),
Benjamin Romerb3c55b12014-07-31 12:00:50 -0400780 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600781 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
782 POSTCODE_SEVERITY_ERR);
783 return;
784 }
785
Benjamin Romer2c683cd2014-10-31 09:57:22 -0400786 if (type == CRASH_BUS) {
Ken Cox12e364b2014-03-04 07:58:07 -0600787 if (visorchannel_write(ControlVm_channel,
788 localSavedCrashMsgOffset,
Benjamin Romer3ab47702014-10-23 14:30:31 -0400789 msg,
790 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600791 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC,
792 POSTCODE_SEVERITY_ERR);
793 return;
794 }
795 } else {
796 if (visorchannel_write(ControlVm_channel,
797 localSavedCrashMsgOffset +
Benjamin Romer3ab47702014-10-23 14:30:31 -0400798 sizeof(struct controlvm_message), msg,
799 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600800 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC,
801 POSTCODE_SEVERITY_ERR);
802 return;
803 }
804 }
805}
806EXPORT_SYMBOL_GPL(visorchipset_save_message);
807
808static void
Benjamin Romer53bebb12014-10-23 14:30:17 -0400809bus_responder(enum controlvm_id cmdId, ulong busNo, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600810{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400811 struct visorchipset_bus_info *p = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600812 BOOL need_clear = FALSE;
813
814 p = findbus(&BusInfoList, busNo);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500815 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600816 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500817
Ken Cox12e364b2014-03-04 07:58:07 -0600818 if (response < 0) {
819 if ((cmdId == CONTROLVM_BUS_CREATE) &&
820 (response != (-CONTROLVM_RESP_ERROR_ALREADY_DONE)))
821 /* undo the row we just created... */
822 delbusdevices(&DevInfoList, busNo);
823 } else {
824 if (cmdId == CONTROLVM_BUS_CREATE)
825 p->state.created = 1;
826 if (cmdId == CONTROLVM_BUS_DESTROY)
827 need_clear = TRUE;
828 }
829
Benjamin Romer0aca78442015-03-04 12:14:25 -0500830 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600831 return; /* no controlvm response needed */
Benjamin Romer0aca78442015-03-04 12:14:25 -0500832 if (p->pending_msg_hdr.id != (u32) cmdId)
Ken Cox12e364b2014-03-04 07:58:07 -0600833 return;
Benjamin Romer33192fa2014-10-31 09:57:27 -0400834 controlvm_respond(&p->pending_msg_hdr, response);
835 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600836 if (need_clear) {
837 busInfo_clear(p);
838 delbusdevices(&DevInfoList, busNo);
839 }
840}
841
842static void
Benjamin Romer53bebb12014-10-23 14:30:17 -0400843device_changestate_responder(enum controlvm_id cmdId,
Ken Cox12e364b2014-03-04 07:58:07 -0600844 ulong busNo, ulong devNo, int response,
Benjamin Romer3f833b52014-10-23 14:30:12 -0400845 struct spar_segment_state responseState)
Ken Cox12e364b2014-03-04 07:58:07 -0600846{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400847 struct visorchipset_device_info *p = NULL;
Benjamin Romer3ab47702014-10-23 14:30:31 -0400848 struct controlvm_message outmsg;
Ken Cox12e364b2014-03-04 07:58:07 -0600849
Ken Cox12e364b2014-03-04 07:58:07 -0600850 p = finddevice(&DevInfoList, busNo, devNo);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500851 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600852 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500853 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600854 return; /* no controlvm response needed */
Benjamin Romer0aca78442015-03-04 12:14:25 -0500855 if (p->pending_msg_hdr.id != cmdId)
Ken Cox12e364b2014-03-04 07:58:07 -0600856 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600857
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400858 controlvm_init_response(&outmsg, &p->pending_msg_hdr, response);
Ken Cox12e364b2014-03-04 07:58:07 -0600859
Benjamin Romer2ea51172014-10-23 14:30:25 -0400860 outmsg.cmd.device_change_state.bus_no = busNo;
861 outmsg.cmd.device_change_state.dev_no = devNo;
862 outmsg.cmd.device_change_state.state = responseState;
Ken Cox12e364b2014-03-04 07:58:07 -0600863
864 if (!visorchannel_signalinsert(ControlVm_channel,
Benjamin Romer0aca78442015-03-04 12:14:25 -0500865 CONTROLVM_QUEUE_REQUEST, &outmsg))
Ken Cox12e364b2014-03-04 07:58:07 -0600866 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600867
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400868 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600869}
870
871static void
Benjamin Romer53bebb12014-10-23 14:30:17 -0400872device_responder(enum controlvm_id cmdId, ulong busNo, ulong devNo,
873 int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600874{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400875 struct visorchipset_device_info *p = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600876 BOOL need_clear = FALSE;
877
878 p = finddevice(&DevInfoList, busNo, devNo);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500879 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600880 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600881 if (response >= 0) {
882 if (cmdId == CONTROLVM_DEVICE_CREATE)
883 p->state.created = 1;
884 if (cmdId == CONTROLVM_DEVICE_DESTROY)
885 need_clear = TRUE;
886 }
887
Benjamin Romer0aca78442015-03-04 12:14:25 -0500888 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600889 return; /* no controlvm response needed */
Benjamin Romer0aca78442015-03-04 12:14:25 -0500890
891 if (p->pending_msg_hdr.id != (u32) cmdId)
Ken Cox12e364b2014-03-04 07:58:07 -0600892 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500893
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400894 controlvm_respond(&p->pending_msg_hdr, response);
895 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600896 if (need_clear)
897 devInfo_clear(p);
898}
899
900static void
Benjamin Romerb3c55b12014-07-31 12:00:50 -0400901bus_epilog(u32 busNo,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400902 u32 cmd, struct controlvm_message_header *msgHdr,
Ken Cox12e364b2014-03-04 07:58:07 -0600903 int response, BOOL needResponse)
904{
905 BOOL notified = FALSE;
906
Benjamin Romer33192fa2014-10-31 09:57:27 -0400907 struct visorchipset_bus_info *pBusInfo = findbus(&BusInfoList, busNo);
Ken Cox12e364b2014-03-04 07:58:07 -0600908
Benjamin Romer0aca78442015-03-04 12:14:25 -0500909 if (!pBusInfo)
Ken Cox12e364b2014-03-04 07:58:07 -0600910 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500911
Ken Cox12e364b2014-03-04 07:58:07 -0600912 if (needResponse) {
Benjamin Romer33192fa2014-10-31 09:57:27 -0400913 memcpy(&pBusInfo->pending_msg_hdr, msgHdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400914 sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -0600915 } else
Benjamin Romer33192fa2014-10-31 09:57:27 -0400916 pBusInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600917
Benjamin Romerf2170622014-08-05 14:57:47 -0400918 down(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600919 if (response == CONTROLVM_RESP_SUCCESS) {
920 switch (cmd) {
921 case CONTROLVM_BUS_CREATE:
922 /* We can't tell from the bus_create
923 * information which of our 2 bus flavors the
924 * devices on this bus will ultimately end up.
925 * FORTUNATELY, it turns out it is harmless to
926 * send the bus_create to both of them. We can
927 * narrow things down a little bit, though,
928 * because we know: - BusDev_Server can handle
929 * either server or client devices
930 * - BusDev_Client can handle ONLY client
931 * devices */
932 if (BusDev_Server_Notifiers.bus_create) {
933 (*BusDev_Server_Notifiers.bus_create) (busNo);
934 notified = TRUE;
935 }
936 if ((!pBusInfo->flags.server) /*client */ &&
937 BusDev_Client_Notifiers.bus_create) {
938 (*BusDev_Client_Notifiers.bus_create) (busNo);
939 notified = TRUE;
940 }
941 break;
942 case CONTROLVM_BUS_DESTROY:
943 if (BusDev_Server_Notifiers.bus_destroy) {
944 (*BusDev_Server_Notifiers.bus_destroy) (busNo);
945 notified = TRUE;
946 }
947 if ((!pBusInfo->flags.server) /*client */ &&
948 BusDev_Client_Notifiers.bus_destroy) {
949 (*BusDev_Client_Notifiers.bus_destroy) (busNo);
950 notified = TRUE;
951 }
952 break;
953 }
954 }
955 if (notified)
956 /* The callback function just called above is responsible
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400957 * for calling the appropriate visorchipset_busdev_responders
Ken Cox12e364b2014-03-04 07:58:07 -0600958 * function, which will call bus_responder()
959 */
960 ;
961 else
962 bus_responder(cmd, busNo, response);
Benjamin Romerf2170622014-08-05 14:57:47 -0400963 up(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600964}
965
966static void
Benjamin Romer3f833b52014-10-23 14:30:12 -0400967device_epilog(u32 busNo, u32 devNo, struct spar_segment_state state, u32 cmd,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400968 struct controlvm_message_header *msgHdr, int response,
Ken Cox12e364b2014-03-04 07:58:07 -0600969 BOOL needResponse, BOOL for_visorbus)
970{
Benjamin Romerfe90d892014-10-31 09:57:32 -0400971 struct visorchipset_busdev_notifiers *notifiers = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600972 BOOL notified = FALSE;
973
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400974 struct visorchipset_device_info *pDevInfo =
Ken Cox12e364b2014-03-04 07:58:07 -0600975 finddevice(&DevInfoList, busNo, devNo);
976 char *envp[] = {
977 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
978 NULL
979 };
980
Benjamin Romer0aca78442015-03-04 12:14:25 -0500981 if (!pDevInfo)
Ken Cox12e364b2014-03-04 07:58:07 -0600982 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500983
Ken Cox12e364b2014-03-04 07:58:07 -0600984 if (for_visorbus)
985 notifiers = &BusDev_Server_Notifiers;
986 else
987 notifiers = &BusDev_Client_Notifiers;
988 if (needResponse) {
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400989 memcpy(&pDevInfo->pending_msg_hdr, msgHdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400990 sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -0600991 } else
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400992 pDevInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600993
Benjamin Romerf2170622014-08-05 14:57:47 -0400994 down(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -0600995 if (response >= 0) {
996 switch (cmd) {
997 case CONTROLVM_DEVICE_CREATE:
998 if (notifiers->device_create) {
999 (*notifiers->device_create) (busNo, devNo);
1000 notified = TRUE;
1001 }
1002 break;
1003 case CONTROLVM_DEVICE_CHANGESTATE:
1004 /* ServerReady / ServerRunning / SegmentStateRunning */
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001005 if (state.alive == segment_state_running.alive &&
1006 state.operating ==
1007 segment_state_running.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -06001008 if (notifiers->device_resume) {
1009 (*notifiers->device_resume) (busNo,
1010 devNo);
1011 notified = TRUE;
1012 }
1013 }
1014 /* ServerNotReady / ServerLost / SegmentStateStandby */
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001015 else if (state.alive == segment_state_standby.alive &&
Benjamin Romer3f833b52014-10-23 14:30:12 -04001016 state.operating ==
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001017 segment_state_standby.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -06001018 /* technically this is standby case
1019 * where server is lost
1020 */
1021 if (notifiers->device_pause) {
1022 (*notifiers->device_pause) (busNo,
1023 devNo);
1024 notified = TRUE;
1025 }
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001026 } else if (state.alive == segment_state_paused.alive &&
Benjamin Romer3f833b52014-10-23 14:30:12 -04001027 state.operating ==
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001028 segment_state_paused.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -06001029 /* this is lite pause where channel is
1030 * still valid just 'pause' of it
1031 */
1032 if (busNo == g_diagpoolBusNo
1033 && devNo == g_diagpoolDevNo) {
Ken Cox12e364b2014-03-04 07:58:07 -06001034 /* this will trigger the
1035 * diag_shutdown.sh script in
1036 * the visorchipset hotplug */
1037 kobject_uevent_env
1038 (&Visorchipset_platform_device.dev.
1039 kobj, KOBJ_ONLINE, envp);
1040 }
1041 }
1042 break;
1043 case CONTROLVM_DEVICE_DESTROY:
1044 if (notifiers->device_destroy) {
1045 (*notifiers->device_destroy) (busNo, devNo);
1046 notified = TRUE;
1047 }
1048 break;
1049 }
1050 }
1051 if (notified)
1052 /* The callback function just called above is responsible
Benjamin Romer929aa8a2014-10-31 09:57:33 -04001053 * for calling the appropriate visorchipset_busdev_responders
Ken Cox12e364b2014-03-04 07:58:07 -06001054 * function, which will call device_responder()
1055 */
1056 ;
1057 else
1058 device_responder(cmd, busNo, devNo, response);
Benjamin Romerf2170622014-08-05 14:57:47 -04001059 up(&NotifierLock);
Ken Cox12e364b2014-03-04 07:58:07 -06001060}
1061
1062static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001063bus_create(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001064{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001065 struct controlvm_message_packet *cmd = &inmsg->cmd;
1066 ulong busNo = cmd->create_bus.bus_no;
Ken Cox12e364b2014-03-04 07:58:07 -06001067 int rc = CONTROLVM_RESP_SUCCESS;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001068 struct visorchipset_bus_info *pBusInfo = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001069
1070
1071 pBusInfo = findbus(&BusInfoList, busNo);
1072 if (pBusInfo && (pBusInfo->state.created == 1)) {
Ken Cox12e364b2014-03-04 07:58:07 -06001073 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo,
1074 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001075 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1076 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001077 }
Benjamin Romer33192fa2014-10-31 09:57:27 -04001078 pBusInfo = kzalloc(sizeof(struct visorchipset_bus_info), GFP_KERNEL);
Ken Cox12e364b2014-03-04 07:58:07 -06001079 if (pBusInfo == NULL) {
Ken Cox12e364b2014-03-04 07:58:07 -06001080 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo,
1081 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001082 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
1083 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001084 }
1085
Ken Cox12e364b2014-03-04 07:58:07 -06001086 INIT_LIST_HEAD(&pBusInfo->entry);
Benjamin Romer33192fa2014-10-31 09:57:27 -04001087 pBusInfo->bus_no = busNo;
1088 pBusInfo->dev_no = cmd->create_bus.dev_count;
Ken Cox12e364b2014-03-04 07:58:07 -06001089
1090 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1091
Benjamin Romer98d7b592014-10-23 14:30:26 -04001092 if (inmsg->hdr.flags.test_message == 1)
Benjamin Romer33192fa2014-10-31 09:57:27 -04001093 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
Ken Cox12e364b2014-03-04 07:58:07 -06001094 else
Benjamin Romer33192fa2014-10-31 09:57:27 -04001095 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
Ken Cox12e364b2014-03-04 07:58:07 -06001096
Benjamin Romer98d7b592014-10-23 14:30:26 -04001097 pBusInfo->flags.server = inmsg->hdr.flags.server;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001098 pBusInfo->chan_info.channel_addr = cmd->create_bus.channel_addr;
1099 pBusInfo->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes;
1100 pBusInfo->chan_info.channel_type_uuid =
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001101 cmd->create_bus.bus_data_type_uuid;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001102 pBusInfo->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid;
Ken Cox12e364b2014-03-04 07:58:07 -06001103
1104 list_add(&pBusInfo->entry, &BusInfoList);
1105
1106 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO);
1107
1108Away:
1109 bus_epilog(busNo, CONTROLVM_BUS_CREATE, &inmsg->hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001110 rc, inmsg->hdr.flags.response_expected == 1);
Ken Cox12e364b2014-03-04 07:58:07 -06001111}
1112
1113static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001114bus_destroy(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001115{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001116 struct controlvm_message_packet *cmd = &inmsg->cmd;
1117 ulong busNo = cmd->destroy_bus.bus_no;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001118 struct visorchipset_bus_info *pBusInfo;
Ken Cox12e364b2014-03-04 07:58:07 -06001119 int rc = CONTROLVM_RESP_SUCCESS;
1120
1121 pBusInfo = findbus(&BusInfoList, busNo);
1122 if (!pBusInfo) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001123 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1124 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001125 }
1126 if (pBusInfo->state.created == 0) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001127 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1128 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001129 }
1130
1131Away:
1132 bus_epilog(busNo, CONTROLVM_BUS_DESTROY, &inmsg->hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001133 rc, inmsg->hdr.flags.response_expected == 1);
Ken Cox12e364b2014-03-04 07:58:07 -06001134}
1135
1136static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001137bus_configure(struct controlvm_message *inmsg, PARSER_CONTEXT *parser_ctx)
Ken Cox12e364b2014-03-04 07:58:07 -06001138{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001139 struct controlvm_message_packet *cmd = &inmsg->cmd;
1140 ulong busNo = cmd->configure_bus.bus_no;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001141 struct visorchipset_bus_info *pBusInfo = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001142 int rc = CONTROLVM_RESP_SUCCESS;
1143 char s[99];
1144
Benjamin Romer2ea51172014-10-23 14:30:25 -04001145 busNo = cmd->configure_bus.bus_no;
Ken Cox12e364b2014-03-04 07:58:07 -06001146 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1147
1148 pBusInfo = findbus(&BusInfoList, busNo);
1149 if (!pBusInfo) {
Ken Cox12e364b2014-03-04 07:58:07 -06001150 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1151 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001152 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1153 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001154 }
1155 if (pBusInfo->state.created == 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001156 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1157 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001158 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1159 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001160 }
1161 /* TBD - add this check to other commands also... */
Benjamin Romer33192fa2014-10-31 09:57:27 -04001162 if (pBusInfo->pending_msg_hdr.id != CONTROLVM_INVALID) {
Ken Cox12e364b2014-03-04 07:58:07 -06001163 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1164 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001165 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT;
1166 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001167 }
1168
Benjamin Romer33192fa2014-10-31 09:57:27 -04001169 pBusInfo->partition_handle = cmd->configure_bus.guest_handle;
1170 pBusInfo->partition_uuid = parser_id_get(parser_ctx);
Ken Cox12e364b2014-03-04 07:58:07 -06001171 parser_param_start(parser_ctx, PARSERSTRING_NAME);
1172 pBusInfo->name = parser_string_get(parser_ctx);
1173
Benjamin Romer33192fa2014-10-31 09:57:27 -04001174 visorchannel_uuid_id(&pBusInfo->partition_uuid, s);
Ken Cox12e364b2014-03-04 07:58:07 -06001175 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO);
1176Away:
1177 bus_epilog(busNo, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001178 rc, inmsg->hdr.flags.response_expected == 1);
Ken Cox12e364b2014-03-04 07:58:07 -06001179}
1180
1181static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001182my_device_create(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001183{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001184 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romerf91b9262014-10-23 14:30:27 -04001185 ulong busNo = cmd->create_device.bus_no;
1186 ulong devNo = cmd->create_device.dev_no;
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001187 struct visorchipset_device_info *pDevInfo = NULL;
Benjamin Romer33192fa2014-10-31 09:57:27 -04001188 struct visorchipset_bus_info *pBusInfo = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001189 int rc = CONTROLVM_RESP_SUCCESS;
1190
1191 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1192 if (pDevInfo && (pDevInfo->state.created == 1)) {
Ken Cox12e364b2014-03-04 07:58:07 -06001193 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1194 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001195 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1196 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001197 }
1198 pBusInfo = findbus(&BusInfoList, busNo);
1199 if (!pBusInfo) {
Ken Cox12e364b2014-03-04 07:58:07 -06001200 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1201 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001202 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1203 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001204 }
1205 if (pBusInfo->state.created == 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001206 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1207 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001208 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1209 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001210 }
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001211 pDevInfo = kzalloc(sizeof(struct visorchipset_device_info), GFP_KERNEL);
Ken Cox12e364b2014-03-04 07:58:07 -06001212 if (pDevInfo == NULL) {
Ken Cox12e364b2014-03-04 07:58:07 -06001213 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1214 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001215 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
1216 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001217 }
Andreea-Cristina Bernat97a84f12014-03-14 04:20:06 +02001218
Ken Cox12e364b2014-03-04 07:58:07 -06001219 INIT_LIST_HEAD(&pDevInfo->entry);
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001220 pDevInfo->bus_no = busNo;
1221 pDevInfo->dev_no = devNo;
1222 pDevInfo->dev_inst_uuid = cmd->create_device.dev_inst_uuid;
Ken Cox12e364b2014-03-04 07:58:07 -06001223 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo,
1224 POSTCODE_SEVERITY_INFO);
1225
Benjamin Romer98d7b592014-10-23 14:30:26 -04001226 if (inmsg->hdr.flags.test_message == 1)
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001227 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
Ken Cox12e364b2014-03-04 07:58:07 -06001228 else
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001229 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1230 pDevInfo->chan_info.channel_addr = cmd->create_device.channel_addr;
1231 pDevInfo->chan_info.n_channel_bytes = cmd->create_device.channel_bytes;
1232 pDevInfo->chan_info.channel_type_uuid =
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001233 cmd->create_device.data_type_uuid;
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001234 pDevInfo->chan_info.intr = cmd->create_device.intr;
Ken Cox12e364b2014-03-04 07:58:07 -06001235 list_add(&pDevInfo->entry, &DevInfoList);
1236 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, devNo, busNo,
1237 POSTCODE_SEVERITY_INFO);
1238Away:
1239 /* get the bus and devNo for DiagPool channel */
Sudip Mukherjee930a0212014-11-07 17:48:35 +05301240 if (pDevInfo &&
1241 is_diagpool_channel(pDevInfo->chan_info.channel_type_uuid)) {
Ken Cox12e364b2014-03-04 07:58:07 -06001242 g_diagpoolBusNo = busNo;
1243 g_diagpoolDevNo = devNo;
Ken Cox12e364b2014-03-04 07:58:07 -06001244 }
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001245 device_epilog(busNo, devNo, segment_state_running,
Ken Cox12e364b2014-03-04 07:58:07 -06001246 CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001247 inmsg->hdr.flags.response_expected == 1,
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001248 FOR_VISORBUS(pDevInfo->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001249}
1250
1251static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001252my_device_changestate(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001253{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001254 struct controlvm_message_packet *cmd = &inmsg->cmd;
1255 ulong busNo = cmd->device_change_state.bus_no;
1256 ulong devNo = cmd->device_change_state.dev_no;
1257 struct spar_segment_state state = cmd->device_change_state.state;
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001258 struct visorchipset_device_info *pDevInfo = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001259 int rc = CONTROLVM_RESP_SUCCESS;
1260
1261 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1262 if (!pDevInfo) {
Ken Cox12e364b2014-03-04 07:58:07 -06001263 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, devNo, busNo,
1264 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001265 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
1266 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001267 }
1268 if (pDevInfo->state.created == 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001269 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, devNo, busNo,
1270 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001271 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -06001272 }
1273Away:
1274 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
1275 device_epilog(busNo, devNo, state, CONTROLVM_DEVICE_CHANGESTATE,
1276 &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001277 inmsg->hdr.flags.response_expected == 1,
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001278 FOR_VISORBUS(
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001279 pDevInfo->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001280}
1281
1282static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001283my_device_destroy(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001284{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001285 struct controlvm_message_packet *cmd = &inmsg->cmd;
1286 ulong busNo = cmd->destroy_device.bus_no;
1287 ulong devNo = cmd->destroy_device.dev_no;
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001288 struct visorchipset_device_info *pDevInfo = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001289 int rc = CONTROLVM_RESP_SUCCESS;
1290
1291 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1292 if (!pDevInfo) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001293 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
1294 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001295 }
1296 if (pDevInfo->state.created == 0) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001297 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Ken Cox12e364b2014-03-04 07:58:07 -06001298 }
1299
1300Away:
1301 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001302 device_epilog(busNo, devNo, segment_state_running,
Ken Cox12e364b2014-03-04 07:58:07 -06001303 CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001304 inmsg->hdr.flags.response_expected == 1,
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001305 FOR_VISORBUS(
Benjamin Romer246e0cd2014-10-31 09:57:24 -04001306 pDevInfo->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001307}
1308
1309/* When provided with the physical address of the controlvm channel
1310 * (phys_addr), the offset to the payload area we need to manage
1311 * (offset), and the size of this payload area (bytes), fills in the
Frederico Cadete84b11df2015-02-18 19:53:40 +01001312 * controlvm_payload_info struct. Returns TRUE for success or FALSE
Ken Cox12e364b2014-03-04 07:58:07 -06001313 * for failure.
1314 */
1315static int
Benjamin Romer5fc02292014-07-31 12:00:51 -04001316initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes,
Frederico Cadete84b11df2015-02-18 19:53:40 +01001317 struct controlvm_payload_info *info)
Ken Cox12e364b2014-03-04 07:58:07 -06001318{
Benjamin Romerc2422332014-07-29 15:09:40 -04001319 u8 __iomem *payload = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001320 int rc = CONTROLVM_RESP_SUCCESS;
1321
1322 if (info == NULL) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001323 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1324 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001325 }
Frederico Cadete84b11df2015-02-18 19:53:40 +01001326 memset(info, 0, sizeof(struct controlvm_payload_info));
Ken Cox12e364b2014-03-04 07:58:07 -06001327 if ((offset == 0) || (bytes == 0)) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001328 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1329 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001330 }
1331 payload = ioremap_cache(phys_addr + offset, bytes);
1332 if (payload == NULL) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001333 rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
1334 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001335 }
1336
1337 info->offset = offset;
1338 info->bytes = bytes;
1339 info->ptr = payload;
Ken Cox12e364b2014-03-04 07:58:07 -06001340
1341Away:
1342 if (rc < 0) {
1343 if (payload != NULL) {
1344 iounmap(payload);
1345 payload = NULL;
1346 }
1347 }
1348 return rc;
1349}
1350
1351static void
Frederico Cadete84b11df2015-02-18 19:53:40 +01001352destroy_controlvm_payload_info(struct controlvm_payload_info *info)
Ken Cox12e364b2014-03-04 07:58:07 -06001353{
1354 if (info->ptr != NULL) {
1355 iounmap(info->ptr);
1356 info->ptr = NULL;
1357 }
Frederico Cadete84b11df2015-02-18 19:53:40 +01001358 memset(info, 0, sizeof(struct controlvm_payload_info));
Ken Cox12e364b2014-03-04 07:58:07 -06001359}
1360
1361static void
1362initialize_controlvm_payload(void)
1363{
1364 HOSTADDRESS phys_addr = visorchannel_get_physaddr(ControlVm_channel);
Benjamin Romer5fc02292014-07-31 12:00:51 -04001365 u64 payloadOffset = 0;
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001366 u32 payloadBytes = 0;
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001367
Ken Cox12e364b2014-03-04 07:58:07 -06001368 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001369 offsetof(struct spar_controlvm_channel_protocol,
1370 request_payload_offset),
Ken Cox12e364b2014-03-04 07:58:07 -06001371 &payloadOffset, sizeof(payloadOffset)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001372 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1373 POSTCODE_SEVERITY_ERR);
1374 return;
1375 }
1376 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001377 offsetof(struct spar_controlvm_channel_protocol,
1378 request_payload_bytes),
Ken Cox12e364b2014-03-04 07:58:07 -06001379 &payloadBytes, sizeof(payloadBytes)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001380 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1381 POSTCODE_SEVERITY_ERR);
1382 return;
1383 }
1384 initialize_controlvm_payload_info(phys_addr,
1385 payloadOffset, payloadBytes,
1386 &ControlVm_payload_info);
1387}
1388
1389/* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1390 * Returns CONTROLVM_RESP_xxx code.
1391 */
1392int
1393visorchipset_chipset_ready(void)
1394{
1395 kobject_uevent(&Visorchipset_platform_device.dev.kobj, KOBJ_ONLINE);
1396 return CONTROLVM_RESP_SUCCESS;
1397}
1398EXPORT_SYMBOL_GPL(visorchipset_chipset_ready);
1399
1400int
1401visorchipset_chipset_selftest(void)
1402{
1403 char env_selftest[20];
1404 char *envp[] = { env_selftest, NULL };
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001405
Ken Cox12e364b2014-03-04 07:58:07 -06001406 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
1407 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1408 envp);
1409 return CONTROLVM_RESP_SUCCESS;
1410}
1411EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest);
1412
1413/* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1414 * Returns CONTROLVM_RESP_xxx code.
1415 */
1416int
1417visorchipset_chipset_notready(void)
1418{
1419 kobject_uevent(&Visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE);
1420 return CONTROLVM_RESP_SUCCESS;
1421}
1422EXPORT_SYMBOL_GPL(visorchipset_chipset_notready);
1423
1424static void
Benjamin Romer98d7b592014-10-23 14:30:26 -04001425chipset_ready(struct controlvm_message_header *msgHdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001426{
1427 int rc = visorchipset_chipset_ready();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001428
Ken Cox12e364b2014-03-04 07:58:07 -06001429 if (rc != CONTROLVM_RESP_SUCCESS)
1430 rc = -rc;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001431 if (msgHdr->flags.response_expected && !visorchipset_holdchipsetready)
Ken Cox12e364b2014-03-04 07:58:07 -06001432 controlvm_respond(msgHdr, rc);
Benjamin Romer98d7b592014-10-23 14:30:26 -04001433 if (msgHdr->flags.response_expected && visorchipset_holdchipsetready) {
Ken Cox12e364b2014-03-04 07:58:07 -06001434 /* Send CHIPSET_READY response when all modules have been loaded
1435 * and disks mounted for the partition
1436 */
1437 g_ChipSetMsgHdr = *msgHdr;
Ken Cox12e364b2014-03-04 07:58:07 -06001438 }
1439}
1440
1441static void
Benjamin Romer98d7b592014-10-23 14:30:26 -04001442chipset_selftest(struct controlvm_message_header *msgHdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001443{
1444 int rc = visorchipset_chipset_selftest();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001445
Ken Cox12e364b2014-03-04 07:58:07 -06001446 if (rc != CONTROLVM_RESP_SUCCESS)
1447 rc = -rc;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001448 if (msgHdr->flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001449 controlvm_respond(msgHdr, rc);
1450}
1451
1452static void
Benjamin Romer98d7b592014-10-23 14:30:26 -04001453chipset_notready(struct controlvm_message_header *msgHdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001454{
1455 int rc = visorchipset_chipset_notready();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001456
Ken Cox12e364b2014-03-04 07:58:07 -06001457 if (rc != CONTROLVM_RESP_SUCCESS)
1458 rc = -rc;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001459 if (msgHdr->flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001460 controlvm_respond(msgHdr, rc);
1461}
1462
1463/* This is your "one-stop" shop for grabbing the next message from the
1464 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1465 */
1466static BOOL
Benjamin Romer3ab47702014-10-23 14:30:31 -04001467read_controlvm_event(struct controlvm_message *msg)
Ken Cox12e364b2014-03-04 07:58:07 -06001468{
1469 if (visorchannel_signalremove(ControlVm_channel,
1470 CONTROLVM_QUEUE_EVENT, msg)) {
1471 /* got a message */
Benjamin Romer0aca78442015-03-04 12:14:25 -05001472 if (msg->hdr.flags.test_message == 1)
Ken Cox12e364b2014-03-04 07:58:07 -06001473 return FALSE;
Benjamin Romere22a4a02014-08-18 09:34:54 -04001474 return TRUE;
Ken Cox12e364b2014-03-04 07:58:07 -06001475 }
1476 return FALSE;
1477}
1478
1479/*
1480 * The general parahotplug flow works as follows. The visorchipset
1481 * driver receives a DEVICE_CHANGESTATE message from Command
1482 * specifying a physical device to enable or disable. The CONTROLVM
1483 * message handler calls parahotplug_process_message, which then adds
1484 * the message to a global list and kicks off a udev event which
1485 * causes a user level script to enable or disable the specified
1486 * device. The udev script then writes to
1487 * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write
1488 * to get called, at which point the appropriate CONTROLVM message is
1489 * retrieved from the list and responded to.
1490 */
1491
1492#define PARAHOTPLUG_TIMEOUT_MS 2000
1493
1494/*
1495 * Generate unique int to match an outstanding CONTROLVM message with a
1496 * udev script /proc response
1497 */
1498static int
1499parahotplug_next_id(void)
1500{
1501 static atomic_t id = ATOMIC_INIT(0);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001502
Ken Cox12e364b2014-03-04 07:58:07 -06001503 return atomic_inc_return(&id);
1504}
1505
1506/*
1507 * Returns the time (in jiffies) when a CONTROLVM message on the list
1508 * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future
1509 */
1510static unsigned long
1511parahotplug_next_expiration(void)
1512{
Nicholas Mc Guire2cc1a1b2015-01-31 12:02:08 +01001513 return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS);
Ken Cox12e364b2014-03-04 07:58:07 -06001514}
1515
1516/*
1517 * Create a parahotplug_request, which is basically a wrapper for a
1518 * CONTROLVM_MESSAGE that we can stick on a list
1519 */
1520static struct parahotplug_request *
Benjamin Romer3ab47702014-10-23 14:30:31 -04001521parahotplug_request_create(struct controlvm_message *msg)
Ken Cox12e364b2014-03-04 07:58:07 -06001522{
Quentin Lambertea0dcfc2015-02-10 15:12:07 +01001523 struct parahotplug_request *req;
1524
1525 req = kmalloc(sizeof(*req), GFP_KERNEL|__GFP_NORETRY);
Ken Cox12e364b2014-03-04 07:58:07 -06001526 if (req == NULL)
1527 return NULL;
1528
1529 req->id = parahotplug_next_id();
1530 req->expiration = parahotplug_next_expiration();
1531 req->msg = *msg;
1532
1533 return req;
1534}
1535
1536/*
1537 * Free a parahotplug_request.
1538 */
1539static void
1540parahotplug_request_destroy(struct parahotplug_request *req)
1541{
1542 kfree(req);
1543}
1544
1545/*
1546 * Cause uevent to run the user level script to do the disable/enable
1547 * specified in (the CONTROLVM message in) the specified
1548 * parahotplug_request
1549 */
1550static void
1551parahotplug_request_kickoff(struct parahotplug_request *req)
1552{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001553 struct controlvm_message_packet *cmd = &req->msg.cmd;
Ken Cox12e364b2014-03-04 07:58:07 -06001554 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
1555 env_func[40];
1556 char *envp[] = {
1557 env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
1558 };
1559
1560 sprintf(env_cmd, "SPAR_PARAHOTPLUG=1");
1561 sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id);
1562 sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001563 cmd->device_change_state.state.active);
Ken Cox12e364b2014-03-04 07:58:07 -06001564 sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001565 cmd->device_change_state.bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -06001566 sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001567 cmd->device_change_state.dev_no >> 3);
Ken Cox12e364b2014-03-04 07:58:07 -06001568 sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001569 cmd->device_change_state.dev_no & 0x7);
Ken Cox12e364b2014-03-04 07:58:07 -06001570
Ken Cox12e364b2014-03-04 07:58:07 -06001571 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1572 envp);
1573}
1574
1575/*
1576 * Remove any request from the list that's been on there too long and
1577 * respond with an error.
1578 */
1579static void
1580parahotplug_process_list(void)
1581{
1582 struct list_head *pos = NULL;
1583 struct list_head *tmp = NULL;
1584
1585 spin_lock(&Parahotplug_request_list_lock);
1586
1587 list_for_each_safe(pos, tmp, &Parahotplug_request_list) {
1588 struct parahotplug_request *req =
1589 list_entry(pos, struct parahotplug_request, list);
1590 if (time_after_eq(jiffies, req->expiration)) {
1591 list_del(pos);
Benjamin Romer98d7b592014-10-23 14:30:26 -04001592 if (req->msg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001593 controlvm_respond_physdev_changestate(
1594 &req->msg.hdr,
1595 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT,
Benjamin Romer2ea51172014-10-23 14:30:25 -04001596 req->msg.cmd.device_change_state.state);
Ken Cox12e364b2014-03-04 07:58:07 -06001597 parahotplug_request_destroy(req);
1598 }
1599 }
1600
1601 spin_unlock(&Parahotplug_request_list_lock);
1602}
1603
1604/*
1605 * Called from the /proc handler, which means the user script has
1606 * finished the enable/disable. Find the matching identifier, and
1607 * respond to the CONTROLVM message with success.
1608 */
1609static int
Benjamin Romerb06bdf72014-07-31 12:00:49 -04001610parahotplug_request_complete(int id, u16 active)
Ken Cox12e364b2014-03-04 07:58:07 -06001611{
1612 struct list_head *pos = NULL;
1613 struct list_head *tmp = NULL;
1614
1615 spin_lock(&Parahotplug_request_list_lock);
1616
1617 /* Look for a request matching "id". */
1618 list_for_each_safe(pos, tmp, &Parahotplug_request_list) {
1619 struct parahotplug_request *req =
1620 list_entry(pos, struct parahotplug_request, list);
1621 if (req->id == id) {
1622 /* Found a match. Remove it from the list and
1623 * respond.
1624 */
1625 list_del(pos);
1626 spin_unlock(&Parahotplug_request_list_lock);
Benjamin Romer2ea51172014-10-23 14:30:25 -04001627 req->msg.cmd.device_change_state.state.active = active;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001628 if (req->msg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001629 controlvm_respond_physdev_changestate(
1630 &req->msg.hdr, CONTROLVM_RESP_SUCCESS,
Benjamin Romer2ea51172014-10-23 14:30:25 -04001631 req->msg.cmd.device_change_state.state);
Ken Cox12e364b2014-03-04 07:58:07 -06001632 parahotplug_request_destroy(req);
1633 return 0;
1634 }
1635 }
1636
1637 spin_unlock(&Parahotplug_request_list_lock);
1638 return -1;
1639}
1640
1641/*
1642 * Enables or disables a PCI device by kicking off a udev script
1643 */
Ken Coxbd5b9b32014-03-13 15:39:22 -05001644static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001645parahotplug_process_message(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001646{
1647 struct parahotplug_request *req;
1648
1649 req = parahotplug_request_create(inmsg);
1650
Benjamin Romer0aca78442015-03-04 12:14:25 -05001651 if (req == NULL)
Ken Cox12e364b2014-03-04 07:58:07 -06001652 return;
Ken Cox12e364b2014-03-04 07:58:07 -06001653
Benjamin Romer2ea51172014-10-23 14:30:25 -04001654 if (inmsg->cmd.device_change_state.state.active) {
Ken Cox12e364b2014-03-04 07:58:07 -06001655 /* For enable messages, just respond with success
1656 * right away. This is a bit of a hack, but there are
1657 * issues with the early enable messages we get (with
1658 * either the udev script not detecting that the device
1659 * is up, or not getting called at all). Fortunately
1660 * the messages that get lost don't matter anyway, as
1661 * devices are automatically enabled at
1662 * initialization.
1663 */
1664 parahotplug_request_kickoff(req);
1665 controlvm_respond_physdev_changestate(&inmsg->hdr,
Benjamin Romer2ea51172014-10-23 14:30:25 -04001666 CONTROLVM_RESP_SUCCESS, inmsg->cmd.
1667 device_change_state.state);
Ken Cox12e364b2014-03-04 07:58:07 -06001668 parahotplug_request_destroy(req);
1669 } else {
1670 /* For disable messages, add the request to the
1671 * request list before kicking off the udev script. It
1672 * won't get responded to until the script has
1673 * indicated it's done.
1674 */
1675 spin_lock(&Parahotplug_request_list_lock);
1676 list_add_tail(&(req->list), &Parahotplug_request_list);
1677 spin_unlock(&Parahotplug_request_list_lock);
1678
1679 parahotplug_request_kickoff(req);
1680 }
1681}
1682
Ken Cox12e364b2014-03-04 07:58:07 -06001683/* Process a controlvm message.
1684 * Return result:
1685 * FALSE - this function will return FALSE only in the case where the
1686 * controlvm message was NOT processed, but processing must be
1687 * retried before reading the next controlvm message; a
1688 * scenario where this can occur is when we need to throttle
1689 * the allocation of memory in which to copy out controlvm
1690 * payload data
1691 * TRUE - processing of the controlvm message completed,
1692 * either successfully or with an error.
1693 */
1694static BOOL
Benjamin Romer3ab47702014-10-23 14:30:31 -04001695handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr)
Ken Cox12e364b2014-03-04 07:58:07 -06001696{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001697 struct controlvm_message_packet *cmd = &inmsg.cmd;
Benjamin Romer5fc02292014-07-31 12:00:51 -04001698 u64 parametersAddr = 0;
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001699 u32 parametersBytes = 0;
Ken Cox12e364b2014-03-04 07:58:07 -06001700 PARSER_CONTEXT *parser_ctx = NULL;
1701 BOOL isLocalAddr = FALSE;
Benjamin Romer3ab47702014-10-23 14:30:31 -04001702 struct controlvm_message ackmsg;
Ken Cox12e364b2014-03-04 07:58:07 -06001703
1704 /* create parsing context if necessary */
Benjamin Romer98d7b592014-10-23 14:30:26 -04001705 isLocalAddr = (inmsg.hdr.flags.test_message == 1);
Benjamin Romer0aca78442015-03-04 12:14:25 -05001706 if (channel_addr == 0)
Ken Cox12e364b2014-03-04 07:58:07 -06001707 return TRUE;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001708 parametersAddr = channel_addr + inmsg.hdr.payload_vm_offset;
1709 parametersBytes = inmsg.hdr.payload_bytes;
Ken Cox12e364b2014-03-04 07:58:07 -06001710
1711 /* Parameter and channel addresses within test messages actually lie
1712 * within our OS-controlled memory. We need to know that, because it
1713 * makes a difference in how we compute the virtual address.
1714 */
1715 if (parametersAddr != 0 && parametersBytes != 0) {
1716 BOOL retry = FALSE;
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001717
Ken Cox12e364b2014-03-04 07:58:07 -06001718 parser_ctx =
1719 parser_init_byteStream(parametersAddr, parametersBytes,
1720 isLocalAddr, &retry);
Benjamin Romer1b088722015-03-04 12:14:26 -05001721 if (!parser_ctx && retry)
1722 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06001723 }
1724
1725 if (!isLocalAddr) {
1726 controlvm_init_response(&ackmsg, &inmsg.hdr,
1727 CONTROLVM_RESP_SUCCESS);
Benjamin Romer1b088722015-03-04 12:14:26 -05001728 if (ControlVm_channel)
1729 visorchannel_signalinsert(ControlVm_channel,
1730 CONTROLVM_QUEUE_ACK,
1731 &ackmsg);
Ken Cox12e364b2014-03-04 07:58:07 -06001732 }
Benjamin Romer98d7b592014-10-23 14:30:26 -04001733 switch (inmsg.hdr.id) {
Ken Cox12e364b2014-03-04 07:58:07 -06001734 case CONTROLVM_CHIPSET_INIT:
Ken Cox12e364b2014-03-04 07:58:07 -06001735 chipset_init(&inmsg);
1736 break;
1737 case CONTROLVM_BUS_CREATE:
Ken Cox12e364b2014-03-04 07:58:07 -06001738 bus_create(&inmsg);
1739 break;
1740 case CONTROLVM_BUS_DESTROY:
Ken Cox12e364b2014-03-04 07:58:07 -06001741 bus_destroy(&inmsg);
1742 break;
1743 case CONTROLVM_BUS_CONFIGURE:
Ken Cox12e364b2014-03-04 07:58:07 -06001744 bus_configure(&inmsg, parser_ctx);
1745 break;
1746 case CONTROLVM_DEVICE_CREATE:
Ken Cox12e364b2014-03-04 07:58:07 -06001747 my_device_create(&inmsg);
1748 break;
1749 case CONTROLVM_DEVICE_CHANGESTATE:
Benjamin Romer2ea51172014-10-23 14:30:25 -04001750 if (cmd->device_change_state.flags.phys_device) {
Ken Cox12e364b2014-03-04 07:58:07 -06001751 parahotplug_process_message(&inmsg);
1752 } else {
Ken Cox12e364b2014-03-04 07:58:07 -06001753 /* save the hdr and cmd structures for later use */
1754 /* when sending back the response to Command */
1755 my_device_changestate(&inmsg);
1756 g_DiagMsgHdr = inmsg.hdr;
1757 g_DeviceChangeStatePacket = inmsg.cmd;
1758 break;
1759 }
1760 break;
1761 case CONTROLVM_DEVICE_DESTROY:
Ken Cox12e364b2014-03-04 07:58:07 -06001762 my_device_destroy(&inmsg);
1763 break;
1764 case CONTROLVM_DEVICE_CONFIGURE:
Ken Cox12e364b2014-03-04 07:58:07 -06001765 /* no op for now, just send a respond that we passed */
Benjamin Romer98d7b592014-10-23 14:30:26 -04001766 if (inmsg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001767 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1768 break;
1769 case CONTROLVM_CHIPSET_READY:
Ken Cox12e364b2014-03-04 07:58:07 -06001770 chipset_ready(&inmsg.hdr);
1771 break;
1772 case CONTROLVM_CHIPSET_SELFTEST:
Ken Cox12e364b2014-03-04 07:58:07 -06001773 chipset_selftest(&inmsg.hdr);
1774 break;
1775 case CONTROLVM_CHIPSET_STOP:
Ken Cox12e364b2014-03-04 07:58:07 -06001776 chipset_notready(&inmsg.hdr);
1777 break;
1778 default:
Benjamin Romer98d7b592014-10-23 14:30:26 -04001779 if (inmsg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001780 controlvm_respond(&inmsg.hdr,
1781 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN);
1782 break;
1783 }
1784
1785 if (parser_ctx != NULL) {
1786 parser_done(parser_ctx);
1787 parser_ctx = NULL;
1788 }
1789 return TRUE;
1790}
1791
Vincent Bernatd746cb52014-08-01 10:29:30 +02001792static HOSTADDRESS controlvm_get_channel_address(void)
Benjamin Romer524b0b62014-07-17 12:39:57 -04001793{
Benjamin Romer5fc02292014-07-31 12:00:51 -04001794 u64 addr = 0;
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001795 u32 size = 0;
Benjamin Romer524b0b62014-07-17 12:39:57 -04001796
Benjamin Romer0aca78442015-03-04 12:14:25 -05001797 if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size)))
Benjamin Romer524b0b62014-07-17 12:39:57 -04001798 return 0;
Benjamin Romer0aca78442015-03-04 12:14:25 -05001799
Benjamin Romer524b0b62014-07-17 12:39:57 -04001800 return addr;
1801}
1802
Ken Cox12e364b2014-03-04 07:58:07 -06001803static void
1804controlvm_periodic_work(struct work_struct *work)
1805{
Benjamin Romer3ab47702014-10-23 14:30:31 -04001806 struct controlvm_message inmsg;
Ken Cox12e364b2014-03-04 07:58:07 -06001807 BOOL gotACommand = FALSE;
1808 BOOL handle_command_failed = FALSE;
Benjamin Romer5fc02292014-07-31 12:00:51 -04001809 static u64 Poll_Count;
Ken Cox12e364b2014-03-04 07:58:07 -06001810
1811 /* make sure visorbus server is registered for controlvm callbacks */
1812 if (visorchipset_serverregwait && !serverregistered)
Ken Cox097f4c12014-03-19 13:06:23 -05001813 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001814 /* make sure visorclientbus server is regsitered for controlvm
1815 * callbacks
1816 */
1817 if (visorchipset_clientregwait && !clientregistered)
Ken Cox097f4c12014-03-19 13:06:23 -05001818 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001819
Ken Cox12e364b2014-03-04 07:58:07 -06001820 Poll_Count++;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001821 if (Poll_Count >= 250)
Ken Cox12e364b2014-03-04 07:58:07 -06001822 ; /* keep going */
1823 else
Ken Cox097f4c12014-03-19 13:06:23 -05001824 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001825
1826 /* Check events to determine if response to CHIPSET_READY
1827 * should be sent
1828 */
1829 if (visorchipset_holdchipsetready
Benjamin Romer98d7b592014-10-23 14:30:26 -04001830 && (g_ChipSetMsgHdr.id != CONTROLVM_INVALID)) {
Ken Cox12e364b2014-03-04 07:58:07 -06001831 if (check_chipset_events() == 1) {
Ken Cox12e364b2014-03-04 07:58:07 -06001832 controlvm_respond(&g_ChipSetMsgHdr, 0);
1833 clear_chipset_events();
1834 memset(&g_ChipSetMsgHdr, 0,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001835 sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06001836 }
1837 }
1838
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001839 while (visorchannel_signalremove(ControlVm_channel,
1840 CONTROLVM_QUEUE_RESPONSE,
1841 &inmsg)) {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001842 }
1843 if (!gotACommand) {
1844 if (ControlVm_Pending_Msg_Valid) {
1845 /* we throttled processing of a prior
1846 * msg, so try to process it again
1847 * rather than reading a new one
1848 */
1849 inmsg = ControlVm_Pending_Msg;
1850 ControlVm_Pending_Msg_Valid = FALSE;
1851 gotACommand = TRUE;
1852 } else
1853 gotACommand = read_controlvm_event(&inmsg);
Ken Cox12e364b2014-03-04 07:58:07 -06001854 }
1855
1856 handle_command_failed = FALSE;
1857 while (gotACommand && (!handle_command_failed)) {
1858 Most_recent_message_jiffies = jiffies;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001859 if (handle_command(inmsg,
1860 visorchannel_get_physaddr
1861 (ControlVm_channel)))
1862 gotACommand = read_controlvm_event(&inmsg);
1863 else {
1864 /* this is a scenario where throttling
1865 * is required, but probably NOT an
1866 * error...; we stash the current
1867 * controlvm msg so we will attempt to
1868 * reprocess it on our next loop
1869 */
1870 handle_command_failed = TRUE;
1871 ControlVm_Pending_Msg = inmsg;
1872 ControlVm_Pending_Msg_Valid = TRUE;
Ken Cox12e364b2014-03-04 07:58:07 -06001873 }
1874 }
1875
1876 /* parahotplug_worker */
1877 parahotplug_process_list();
1878
Ken Cox12e364b2014-03-04 07:58:07 -06001879Away:
1880
1881 if (time_after(jiffies,
1882 Most_recent_message_jiffies + (HZ * MIN_IDLE_SECONDS))) {
1883 /* it's been longer than MIN_IDLE_SECONDS since we
1884 * processed our last controlvm message; slow down the
1885 * polling
1886 */
1887 if (Poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_SLOW) {
Ken Cox12e364b2014-03-04 07:58:07 -06001888 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
1889 }
1890 } else {
1891 if (Poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_FAST) {
1892 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
Ken Cox12e364b2014-03-04 07:58:07 -06001893 }
1894 }
1895
Daeseok Youn4b4b5352014-03-11 00:31:03 -07001896 queue_delayed_work(Periodic_controlvm_workqueue,
1897 &Periodic_controlvm_work, Poll_jiffies);
Ken Cox12e364b2014-03-04 07:58:07 -06001898}
1899
1900static void
1901setup_crash_devices_work_queue(struct work_struct *work)
1902{
1903
Benjamin Romer3ab47702014-10-23 14:30:31 -04001904 struct controlvm_message localCrashCreateBusMsg;
1905 struct controlvm_message localCrashCreateDevMsg;
1906 struct controlvm_message msg;
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001907 u32 localSavedCrashMsgOffset;
Benjamin Romerb06bdf72014-07-31 12:00:49 -04001908 u16 localSavedCrashMsgCount;
Ken Cox12e364b2014-03-04 07:58:07 -06001909
1910 /* make sure visorbus server is registered for controlvm callbacks */
1911 if (visorchipset_serverregwait && !serverregistered)
Ken Cox097f4c12014-03-19 13:06:23 -05001912 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001913
1914 /* make sure visorclientbus server is regsitered for controlvm
1915 * callbacks
1916 */
1917 if (visorchipset_clientregwait && !clientregistered)
Ken Cox097f4c12014-03-19 13:06:23 -05001918 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06001919
1920 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1921
1922 /* send init chipset msg */
Benjamin Romer98d7b592014-10-23 14:30:26 -04001923 msg.hdr.id = CONTROLVM_CHIPSET_INIT;
Benjamin Romer2ea51172014-10-23 14:30:25 -04001924 msg.cmd.init_chipset.bus_count = 23;
1925 msg.cmd.init_chipset.switch_count = 0;
Ken Cox12e364b2014-03-04 07:58:07 -06001926
1927 chipset_init(&msg);
1928
Ken Cox12e364b2014-03-04 07:58:07 -06001929 /* get saved message count */
1930 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001931 offsetof(struct spar_controlvm_channel_protocol,
1932 saved_crash_message_count),
Benjamin Romerb06bdf72014-07-31 12:00:49 -04001933 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001934 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1935 POSTCODE_SEVERITY_ERR);
1936 return;
1937 }
1938
1939 if (localSavedCrashMsgCount != CONTROLVM_CRASHMSG_MAX) {
Ken Cox12e364b2014-03-04 07:58:07 -06001940 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
1941 localSavedCrashMsgCount,
1942 POSTCODE_SEVERITY_ERR);
1943 return;
1944 }
1945
1946 /* get saved crash message offset */
1947 if (visorchannel_read(ControlVm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001948 offsetof(struct spar_controlvm_channel_protocol,
1949 saved_crash_message_offset),
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001950 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001951 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1952 POSTCODE_SEVERITY_ERR);
1953 return;
1954 }
1955
1956 /* read create device message for storage bus offset */
1957 if (visorchannel_read(ControlVm_channel,
1958 localSavedCrashMsgOffset,
1959 &localCrashCreateBusMsg,
Benjamin Romer3ab47702014-10-23 14:30:31 -04001960 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001961 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC,
1962 POSTCODE_SEVERITY_ERR);
1963 return;
1964 }
1965
1966 /* read create device message for storage device */
1967 if (visorchannel_read(ControlVm_channel,
1968 localSavedCrashMsgOffset +
Benjamin Romer3ab47702014-10-23 14:30:31 -04001969 sizeof(struct controlvm_message),
Ken Cox12e364b2014-03-04 07:58:07 -06001970 &localCrashCreateDevMsg,
Benjamin Romer3ab47702014-10-23 14:30:31 -04001971 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001972 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC,
1973 POSTCODE_SEVERITY_ERR);
1974 return;
1975 }
1976
1977 /* reuse IOVM create bus message */
Benjamin Romer2ea51172014-10-23 14:30:25 -04001978 if (localCrashCreateBusMsg.cmd.create_bus.channel_addr != 0)
Ken Cox12e364b2014-03-04 07:58:07 -06001979 bus_create(&localCrashCreateBusMsg);
1980 else {
Ken Cox12e364b2014-03-04 07:58:07 -06001981 POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC,
1982 POSTCODE_SEVERITY_ERR);
1983 return;
1984 }
1985
1986 /* reuse create device message for storage device */
Benjamin Romerf91b9262014-10-23 14:30:27 -04001987 if (localCrashCreateDevMsg.cmd.create_device.channel_addr != 0)
Ken Cox12e364b2014-03-04 07:58:07 -06001988 my_device_create(&localCrashCreateDevMsg);
1989 else {
Ken Cox12e364b2014-03-04 07:58:07 -06001990 POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC,
1991 POSTCODE_SEVERITY_ERR);
1992 return;
1993 }
Ken Cox12e364b2014-03-04 07:58:07 -06001994 POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC, POSTCODE_SEVERITY_INFO);
1995 return;
1996
1997Away:
1998
1999 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
2000
Daeseok Youn4b4b5352014-03-11 00:31:03 -07002001 queue_delayed_work(Periodic_controlvm_workqueue,
2002 &Periodic_controlvm_work, Poll_jiffies);
Ken Cox12e364b2014-03-04 07:58:07 -06002003}
2004
2005static void
2006bus_create_response(ulong busNo, int response)
2007{
2008 bus_responder(CONTROLVM_BUS_CREATE, busNo, response);
2009}
2010
2011static void
2012bus_destroy_response(ulong busNo, int response)
2013{
2014 bus_responder(CONTROLVM_BUS_DESTROY, busNo, response);
2015}
2016
2017static void
2018device_create_response(ulong busNo, ulong devNo, int response)
2019{
2020 device_responder(CONTROLVM_DEVICE_CREATE, busNo, devNo, response);
2021}
2022
2023static void
2024device_destroy_response(ulong busNo, ulong devNo, int response)
2025{
2026 device_responder(CONTROLVM_DEVICE_DESTROY, busNo, devNo, response);
2027}
2028
2029void
Benjamin Romer8420f412014-10-31 09:57:36 -04002030visorchipset_device_pause_response(ulong bus_no, ulong dev_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06002031{
2032
2033 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
Benjamin Romer8420f412014-10-31 09:57:36 -04002034 bus_no, dev_no, response,
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04002035 segment_state_standby);
Ken Cox12e364b2014-03-04 07:58:07 -06002036}
Ken Cox927c7922014-03-05 14:52:25 -06002037EXPORT_SYMBOL_GPL(visorchipset_device_pause_response);
Ken Cox12e364b2014-03-04 07:58:07 -06002038
2039static void
2040device_resume_response(ulong busNo, ulong devNo, int response)
2041{
2042 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
2043 busNo, devNo, response,
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04002044 segment_state_running);
Ken Cox12e364b2014-03-04 07:58:07 -06002045}
2046
2047BOOL
Benjamin Romer77db7122014-10-31 09:57:37 -04002048visorchipset_get_bus_info(ulong bus_no, struct visorchipset_bus_info *bus_info)
Ken Cox12e364b2014-03-04 07:58:07 -06002049{
Benjamin Romer77db7122014-10-31 09:57:37 -04002050 void *p = findbus(&BusInfoList, bus_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002051
Benjamin Romer0aca78442015-03-04 12:14:25 -05002052 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002053 return FALSE;
Benjamin Romer77db7122014-10-31 09:57:37 -04002054 memcpy(bus_info, p, sizeof(struct visorchipset_bus_info));
Ken Cox12e364b2014-03-04 07:58:07 -06002055 return TRUE;
2056}
2057EXPORT_SYMBOL_GPL(visorchipset_get_bus_info);
2058
2059BOOL
Benjamin Romer58dd8f2d2014-10-31 09:57:40 -04002060visorchipset_set_bus_context(ulong bus_no, void *context)
Ken Cox12e364b2014-03-04 07:58:07 -06002061{
Benjamin Romer58dd8f2d2014-10-31 09:57:40 -04002062 struct visorchipset_bus_info *p = findbus(&BusInfoList, bus_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002063
Benjamin Romer0aca78442015-03-04 12:14:25 -05002064 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002065 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06002066 p->bus_driver_context = context;
2067 return TRUE;
2068}
2069EXPORT_SYMBOL_GPL(visorchipset_set_bus_context);
2070
2071BOOL
Benjamin Romerb486df12014-10-31 09:57:38 -04002072visorchipset_get_device_info(ulong bus_no, ulong dev_no,
2073 struct visorchipset_device_info *dev_info)
Ken Cox12e364b2014-03-04 07:58:07 -06002074{
Benjamin Romerb486df12014-10-31 09:57:38 -04002075 void *p = finddevice(&DevInfoList, bus_no, dev_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002076
Benjamin Romer0aca78442015-03-04 12:14:25 -05002077 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002078 return FALSE;
Benjamin Romerb486df12014-10-31 09:57:38 -04002079 memcpy(dev_info, p, sizeof(struct visorchipset_device_info));
Ken Cox12e364b2014-03-04 07:58:07 -06002080 return TRUE;
2081}
2082EXPORT_SYMBOL_GPL(visorchipset_get_device_info);
2083
2084BOOL
Benjamin Romercf0bd0b2014-10-31 09:57:41 -04002085visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context)
Ken Cox12e364b2014-03-04 07:58:07 -06002086{
Benjamin Romer246e0cd2014-10-31 09:57:24 -04002087 struct visorchipset_device_info *p =
Benjamin Romercf0bd0b2014-10-31 09:57:41 -04002088 finddevice(&DevInfoList, bus_no, dev_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002089
Benjamin Romer0aca78442015-03-04 12:14:25 -05002090 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002091 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06002092 p->bus_driver_context = context;
2093 return TRUE;
2094}
2095EXPORT_SYMBOL_GPL(visorchipset_set_device_context);
2096
2097/* Generic wrapper function for allocating memory from a kmem_cache pool.
2098 */
2099void *
2100visorchipset_cache_alloc(struct kmem_cache *pool, BOOL ok_to_block,
2101 char *fn, int ln)
2102{
2103 gfp_t gfp;
2104 void *p;
2105
2106 if (ok_to_block)
2107 gfp = GFP_KERNEL;
2108 else
2109 gfp = GFP_ATOMIC;
2110 /* __GFP_NORETRY means "ok to fail", meaning
2111 * kmem_cache_alloc() can return NULL, implying the caller CAN
2112 * cope with failure. If you do NOT specify __GFP_NORETRY,
2113 * Linux will go to extreme measures to get memory for you
2114 * (like, invoke oom killer), which will probably cripple the
2115 * system.
2116 */
2117 gfp |= __GFP_NORETRY;
2118 p = kmem_cache_alloc(pool, gfp);
Benjamin Romer0aca78442015-03-04 12:14:25 -05002119 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002120 return NULL;
Benjamin Romer0aca78442015-03-04 12:14:25 -05002121
Ken Cox12e364b2014-03-04 07:58:07 -06002122 atomic_inc(&Visorchipset_cache_buffers_in_use);
2123 return p;
2124}
2125
2126/* Generic wrapper function for freeing memory from a kmem_cache pool.
2127 */
2128void
2129visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln)
2130{
Benjamin Romer0aca78442015-03-04 12:14:25 -05002131 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002132 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -05002133
Ken Cox12e364b2014-03-04 07:58:07 -06002134 atomic_dec(&Visorchipset_cache_buffers_in_use);
2135 kmem_cache_free(pool, p);
2136}
2137
Benjamin Romer18b87ed2014-07-24 14:08:43 -04002138static ssize_t chipsetready_store(struct device *dev,
2139 struct device_attribute *attr, const char *buf, size_t count)
Ken Cox12e364b2014-03-04 07:58:07 -06002140{
Benjamin Romer18b87ed2014-07-24 14:08:43 -04002141 char msgtype[64];
Ken Cox12e364b2014-03-04 07:58:07 -06002142
Benjamin Romer66e24b72014-07-25 13:55:10 -04002143 if (sscanf(buf, "%63s", msgtype) != 1)
Ken Cox12e364b2014-03-04 07:58:07 -06002144 return -EINVAL;
Benjamin Romer66e24b72014-07-25 13:55:10 -04002145
2146 if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) {
2147 chipset_events[0] = 1;
2148 return count;
2149 } else if (strcmp(msgtype, "MODULES_LOADED") == 0) {
2150 chipset_events[1] = 1;
2151 return count;
Benjamin Romere22a4a02014-08-18 09:34:54 -04002152 }
2153 return -EINVAL;
Ken Cox12e364b2014-03-04 07:58:07 -06002154}
2155
Benjamin Romere56fa7c2014-07-29 11:11:21 -04002156/* The parahotplug/devicedisabled interface gets called by our support script
2157 * when an SR-IOV device has been shut down. The ID is passed to the script
2158 * and then passed back when the device has been removed.
2159 */
2160static ssize_t devicedisabled_store(struct device *dev,
2161 struct device_attribute *attr, const char *buf, size_t count)
2162{
2163 uint id;
2164
2165 if (kstrtouint(buf, 10, &id) != 0)
2166 return -EINVAL;
2167
2168 parahotplug_request_complete(id, 0);
2169 return count;
2170}
2171
2172/* The parahotplug/deviceenabled interface gets called by our support script
2173 * when an SR-IOV device has been recovered. The ID is passed to the script
2174 * and then passed back when the device has been brought back up.
2175 */
2176static ssize_t deviceenabled_store(struct device *dev,
2177 struct device_attribute *attr, const char *buf, size_t count)
2178{
2179 uint id;
2180
2181 if (kstrtouint(buf, 10, &id) != 0)
2182 return -EINVAL;
2183
2184 parahotplug_request_complete(id, 1);
2185 return count;
2186}
2187
Ken Cox12e364b2014-03-04 07:58:07 -06002188static int __init
2189visorchipset_init(void)
2190{
2191 int rc = 0, x = 0;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002192 HOSTADDRESS addr;
Ken Cox12e364b2014-03-04 07:58:07 -06002193
Ken Coxfcd0157e2014-04-28 12:23:13 -05002194 if (!unisys_spar_platform)
2195 return -ENODEV;
2196
Ken Cox12e364b2014-03-04 07:58:07 -06002197 memset(&BusDev_Server_Notifiers, 0, sizeof(BusDev_Server_Notifiers));
2198 memset(&BusDev_Client_Notifiers, 0, sizeof(BusDev_Client_Notifiers));
2199 memset(&ControlVm_payload_info, 0, sizeof(ControlVm_payload_info));
2200 memset(&LiveDump_info, 0, sizeof(LiveDump_info));
2201 atomic_set(&LiveDump_info.buffers_in_use, 0);
2202
Ken Cox9f8d0e82014-03-19 13:06:19 -05002203 if (visorchipset_testvnic) {
Ken Cox9f8d0e82014-03-19 13:06:19 -05002204 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, x, DIAG_SEVERITY_ERR);
2205 rc = x;
2206 goto Away;
2207 }
Ken Cox12e364b2014-03-04 07:58:07 -06002208
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002209 addr = controlvm_get_channel_address();
2210 if (addr != 0) {
2211 ControlVm_channel =
2212 visorchannel_create_with_lock
2213 (addr,
Benjamin Romerd19642f2014-10-23 14:30:34 -04002214 sizeof(struct spar_controlvm_channel_protocol),
Benjamin Romer5fbaa4b2014-10-23 14:30:14 -04002215 spar_controlvm_channel_protocol_uuid);
Benjamin Romer93a84562014-10-23 14:30:05 -04002216 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
2217 visorchannel_get_header(ControlVm_channel))) {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002218 initialize_controlvm_payload();
2219 } else {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002220 visorchannel_destroy(ControlVm_channel);
2221 ControlVm_channel = NULL;
2222 return -ENODEV;
2223 }
2224 } else {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002225 return -ENODEV;
2226 }
2227
Ken Cox12e364b2014-03-04 07:58:07 -06002228 MajorDev = MKDEV(visorchipset_major, 0);
Ken Cox9f8d0e82014-03-19 13:06:19 -05002229 rc = visorchipset_file_init(MajorDev, &ControlVm_channel);
Ken Cox4cb005a2014-03-19 13:06:20 -05002230 if (rc < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002231 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
2232 goto Away;
2233 }
Ken Cox9f8d0e82014-03-19 13:06:19 -05002234
Benjamin Romer98d7b592014-10-23 14:30:26 -04002235 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002236
Benjamin Romer98d7b592014-10-23 14:30:26 -04002237 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002238
Benjamin Romer98d7b592014-10-23 14:30:26 -04002239 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002240
Ken Cox12e364b2014-03-04 07:58:07 -06002241 Putfile_buffer_list_pool =
2242 kmem_cache_create(Putfile_buffer_list_pool_name,
2243 sizeof(struct putfile_buffer_entry),
2244 0, SLAB_HWCACHE_ALIGN, NULL);
2245 if (!Putfile_buffer_list_pool) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002246 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
2247 rc = -1;
2248 goto Away;
Ken Cox12e364b2014-03-04 07:58:07 -06002249 }
Benjamin Romer2098dbd2015-03-04 12:14:22 -05002250 if (!visorchipset_disable_controlvm) {
Ken Cox12e364b2014-03-04 07:58:07 -06002251 /* if booting in a crash kernel */
2252 if (visorchipset_crash_kernel)
2253 INIT_DELAYED_WORK(&Periodic_controlvm_work,
2254 setup_crash_devices_work_queue);
2255 else
2256 INIT_DELAYED_WORK(&Periodic_controlvm_work,
2257 controlvm_periodic_work);
2258 Periodic_controlvm_workqueue =
2259 create_singlethread_workqueue("visorchipset_controlvm");
2260
Ken Cox4cb005a2014-03-19 13:06:20 -05002261 if (Periodic_controlvm_workqueue == NULL) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002262 POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC,
2263 DIAG_SEVERITY_ERR);
2264 rc = -ENOMEM;
2265 goto Away;
2266 }
Ken Cox12e364b2014-03-04 07:58:07 -06002267 Most_recent_message_jiffies = jiffies;
2268 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
Ken Cox9f8d0e82014-03-19 13:06:19 -05002269 rc = queue_delayed_work(Periodic_controlvm_workqueue,
2270 &Periodic_controlvm_work, Poll_jiffies);
Ken Cox4cb005a2014-03-19 13:06:20 -05002271 if (rc < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002272 POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC,
2273 DIAG_SEVERITY_ERR);
2274 goto Away;
2275 }
Ken Cox9f8d0e82014-03-19 13:06:19 -05002276
Ken Cox12e364b2014-03-04 07:58:07 -06002277 }
2278
2279 Visorchipset_platform_device.dev.devt = MajorDev;
Ken Cox4cb005a2014-03-19 13:06:20 -05002280 if (platform_device_register(&Visorchipset_platform_device) < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002281 POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR);
2282 rc = -1;
2283 goto Away;
2284 }
Ken Cox12e364b2014-03-04 07:58:07 -06002285 POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC, POSTCODE_SEVERITY_INFO);
Ken Cox22ad57b2014-03-19 13:06:25 -05002286 rc = 0;
Ken Cox12e364b2014-03-04 07:58:07 -06002287Away:
Ken Cox12e364b2014-03-04 07:58:07 -06002288 if (rc) {
Ken Cox12e364b2014-03-04 07:58:07 -06002289 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
2290 POSTCODE_SEVERITY_ERR);
2291 }
2292 return rc;
2293}
2294
2295static void
2296visorchipset_exit(void)
2297{
Ken Cox12e364b2014-03-04 07:58:07 -06002298 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
2299
2300 if (visorchipset_disable_controlvm) {
2301 ;
2302 } else {
2303 cancel_delayed_work(&Periodic_controlvm_work);
2304 flush_workqueue(Periodic_controlvm_workqueue);
2305 destroy_workqueue(Periodic_controlvm_workqueue);
2306 Periodic_controlvm_workqueue = NULL;
2307 destroy_controlvm_payload_info(&ControlVm_payload_info);
2308 }
2309 Test_Vnic_channel = NULL;
2310 if (Putfile_buffer_list_pool) {
2311 kmem_cache_destroy(Putfile_buffer_list_pool);
2312 Putfile_buffer_list_pool = NULL;
2313 }
Benjamin Romer17833192014-07-15 13:30:41 -04002314
Ken Cox12e364b2014-03-04 07:58:07 -06002315 cleanup_controlvm_structures();
2316
Benjamin Romer98d7b592014-10-23 14:30:26 -04002317 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002318
Benjamin Romer98d7b592014-10-23 14:30:26 -04002319 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002320
Benjamin Romer98d7b592014-10-23 14:30:26 -04002321 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002322
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002323 visorchannel_destroy(ControlVm_channel);
2324
Ken Cox12e364b2014-03-04 07:58:07 -06002325 visorchipset_file_cleanup();
2326 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06002327}
2328
2329module_param_named(testvnic, visorchipset_testvnic, int, S_IRUGO);
2330MODULE_PARM_DESC(visorchipset_testvnic, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet");
2331int visorchipset_testvnic = 0;
2332
2333module_param_named(testvnicclient, visorchipset_testvnicclient, int, S_IRUGO);
2334MODULE_PARM_DESC(visorchipset_testvnicclient, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest");
2335int visorchipset_testvnicclient = 0;
2336
2337module_param_named(testmsg, visorchipset_testmsg, int, S_IRUGO);
2338MODULE_PARM_DESC(visorchipset_testmsg,
2339 "1 to manufacture the chipset, bus, and switch messages");
2340int visorchipset_testmsg = 0;
2341
2342module_param_named(major, visorchipset_major, int, S_IRUGO);
2343MODULE_PARM_DESC(visorchipset_major, "major device number to use for the device node");
2344int visorchipset_major = 0;
2345
2346module_param_named(serverregwait, visorchipset_serverregwait, int, S_IRUGO);
2347MODULE_PARM_DESC(visorchipset_serverreqwait,
2348 "1 to have the module wait for the visor bus to register");
2349int visorchipset_serverregwait = 0; /* default is off */
2350module_param_named(clientregwait, visorchipset_clientregwait, int, S_IRUGO);
2351MODULE_PARM_DESC(visorchipset_clientregwait, "1 to have the module wait for the visorclientbus to register");
2352int visorchipset_clientregwait = 1; /* default is on */
2353module_param_named(testteardown, visorchipset_testteardown, int, S_IRUGO);
2354MODULE_PARM_DESC(visorchipset_testteardown,
2355 "1 to test teardown of the chipset, bus, and switch");
2356int visorchipset_testteardown = 0; /* default is off */
2357module_param_named(disable_controlvm, visorchipset_disable_controlvm, int,
2358 S_IRUGO);
2359MODULE_PARM_DESC(visorchipset_disable_controlvm,
2360 "1 to disable polling of controlVm channel");
2361int visorchipset_disable_controlvm = 0; /* default is off */
2362module_param_named(crash_kernel, visorchipset_crash_kernel, int, S_IRUGO);
2363MODULE_PARM_DESC(visorchipset_crash_kernel,
2364 "1 means we are running in crash kernel");
2365int visorchipset_crash_kernel = 0; /* default is running in non-crash kernel */
2366module_param_named(holdchipsetready, visorchipset_holdchipsetready,
2367 int, S_IRUGO);
2368MODULE_PARM_DESC(visorchipset_holdchipsetready,
2369 "1 to hold response to CHIPSET_READY");
2370int visorchipset_holdchipsetready = 0; /* default is to send CHIPSET_READY
2371 * response immediately */
2372module_init(visorchipset_init);
2373module_exit(visorchipset_exit);
2374
2375MODULE_AUTHOR("Unisys");
2376MODULE_LICENSE("GPL");
2377MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver "
2378 VERSION);
2379MODULE_VERSION(VERSION);