blob: 17fe06ec7d342ccb62a9b132effdb6830c6ae55e [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
Benjamin Romer911e2132015-03-16 13:57:47 -040051static ulong poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
Benjamin Romerb53e0e92015-03-16 13:57:56 -040052static ulong most_recent_message_jiffies; /* when we got our last
Ken Coxbd5b9b32014-03-13 15:39:22 -050053 * 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
Benjamin Romer9232d2d2015-03-16 13:57:57 -040068static struct delayed_work periodic_controlvm_work;
69static struct workqueue_struct *periodic_controlvm_workqueue;
Benjamin Romer8f1947a2015-03-16 13:57:59 -040070static DEFINE_SEMAPHORE(notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -060071
Benjamin Romerda021f02015-03-16 13:57:58 -040072static struct controlvm_message_header g_diag_msg_hdr;
73static struct controlvm_message_header g_chipset_msg_hdr;
74static struct controlvm_message_header g_del_dump_msg_hdr;
Benjamin Romer59827f02015-03-16 13:58:00 -040075static const uuid_le spar_diag_pool_channel_protocol_uuid =
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 */
Benjamin Romer83d48902015-03-16 13:58:01 -040078static ulong g_diagpool_bus_no = 0xffffff;
79static ulong g_diagpool_dev_no = 0xffffff;
Benjamin Romer4f44b722015-03-16 13:58:02 -040080static struct controlvm_message_packet g_devicechangestate_packet;
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,\
Benjamin Romer0639ba62015-03-16 13:58:04 -040087 spar_vnic_channel_protocol_uuid) == 0) ||\
88 (uuid_le_cmp(channel_type_guid,\
Benjamin Romer9eee5d12014-10-23 14:29:47 -040089 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 Romer59827f02015-03-16 13:58:00 -040093 (uuid_le_cmp(channel_type_guid,\
94 spar_diag_pool_channel_protocol_uuid) == 0)
Ken Cox12e364b2014-03-04 07:58:07 -060095
Benjamin Romer1390b882015-03-16 13:58:03 -040096static LIST_HEAD(bus_info_list);
97static LIST_HEAD(dev_info_list);
Ken Cox12e364b2014-03-04 07:58:07 -060098
Benjamin Romerc3d9a222015-03-16 13:58:05 -040099static struct visorchannel *controlvm_channel;
Ken Cox12e364b2014-03-04 07:58:07 -0600100
Benjamin Romer84982fb2015-03-16 13:58:07 -0400101/* Manages the request payload in the controlvm channel */
102static struct controlvm_payload_info {
Benjamin Romerc2422332014-07-29 15:09:40 -0400103 u8 __iomem *ptr; /* pointer to base address of payload pool */
Benjamin Romer5fc02292014-07-31 12:00:51 -0400104 u64 offset; /* offset from beginning of controlvm
Ken Cox12e364b2014-03-04 07:58:07 -0600105 * channel to beginning of payload * pool */
Benjamin Romerb3c55b12014-07-31 12:00:50 -0400106 u32 bytes; /* number of bytes in payload pool */
Benjamin Romer84982fb2015-03-16 13:58:07 -0400107} controlvm_payload_info;
Ken Cox12e364b2014-03-04 07:58:07 -0600108
Benjamin Romerea33b4ee52015-03-16 13:58:08 -0400109/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
110 * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation.
111 */
112static struct livedump_info {
113 struct controlvm_message_header dumpcapture_header;
114 struct controlvm_message_header gettextdump_header;
115 struct controlvm_message_header dumpcomplete_header;
116 BOOL gettextdump_outstanding;
Ken Cox12e364b2014-03-04 07:58:07 -0600117 u32 crc32;
118 ulong length;
119 atomic_t buffers_in_use;
120 ulong destination;
Benjamin Romerea33b4ee52015-03-16 13:58:08 -0400121} livedump_info;
Ken Cox12e364b2014-03-04 07:58:07 -0600122
123/* The following globals are used to handle the scenario where we are unable to
124 * offload the payload from a controlvm message due to memory requirements. In
125 * this scenario, we simply stash the controlvm message, then attempt to
126 * process it again the next time controlvm_periodic_work() runs.
127 */
Benjamin Romer7166ed12015-03-16 13:58:38 -0400128static struct controlvm_message controlvm_pending_msg;
129static BOOL controlvm_pending_msg_valid = FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -0600130
131/* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
132 * TRANSMIT_FILE PutFile payloads.
133 */
Benjamin Romer1eee0012015-03-16 13:58:39 -0400134static struct kmem_cache *putfile_buffer_list_pool;
135static const char putfile_buffer_list_pool_name[] =
Ken Cox12e364b2014-03-04 07:58:07 -0600136 "controlvm_putfile_buffer_list_pool";
137
138/* This identifies a data buffer that has been received via a controlvm messages
139 * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation.
140 */
141struct putfile_buffer_entry {
142 struct list_head next; /* putfile_buffer_entry list */
Benjamin Romer317d9612015-03-16 13:57:51 -0400143 struct parser_context *parser_ctx; /* points to input data buffer */
Ken Cox12e364b2014-03-04 07:58:07 -0600144};
145
146/* List of struct putfile_request *, via next_putfile_request member.
147 * Each entry in this list identifies an outstanding TRANSMIT_FILE
148 * conversation.
149 */
Benjamin Romer1eee0012015-03-16 13:58:39 -0400150static LIST_HEAD(putfile_request_list);
Ken Cox12e364b2014-03-04 07:58:07 -0600151
152/* This describes a buffer and its current state of transfer (e.g., how many
153 * bytes have already been supplied as putfile data, and how many bytes are
154 * remaining) for a putfile_request.
155 */
156struct putfile_active_buffer {
157 /* a payload from a controlvm message, containing a file data buffer */
Benjamin Romer317d9612015-03-16 13:57:51 -0400158 struct parser_context *parser_ctx;
Ken Cox12e364b2014-03-04 07:58:07 -0600159 /* points within data area of parser_ctx to next byte of data */
160 u8 *pnext;
161 /* # bytes left from <pnext> to the end of this data buffer */
162 size_t bytes_remaining;
163};
164
165#define PUTFILE_REQUEST_SIG 0x0906101302281211
166/* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE
167 * conversation. Structs of this type are dynamically linked into
168 * <Putfile_request_list>.
169 */
170struct putfile_request {
171 u64 sig; /* PUTFILE_REQUEST_SIG */
172
173 /* header from original TransmitFile request */
Benjamin Romer98d7b592014-10-23 14:30:26 -0400174 struct controlvm_message_header controlvm_header;
Ken Cox12e364b2014-03-04 07:58:07 -0600175 u64 file_request_number; /* from original TransmitFile request */
176
177 /* link to next struct putfile_request */
178 struct list_head next_putfile_request;
179
180 /* most-recent sequence number supplied via a controlvm message */
181 u64 data_sequence_number;
182
183 /* head of putfile_buffer_entry list, which describes the data to be
184 * supplied as putfile data;
185 * - this list is added to when controlvm messages come in that supply
186 * file data
187 * - this list is removed from via the hotplug program that is actually
188 * consuming these buffers to write as file data */
189 struct list_head input_buffer_list;
190 spinlock_t req_list_lock; /* lock for input_buffer_list */
191
192 /* waiters for input_buffer_list to go non-empty */
193 wait_queue_head_t input_buffer_wq;
194
195 /* data not yet read within current putfile_buffer_entry */
196 struct putfile_active_buffer active_buf;
197
198 /* <0 = failed, 0 = in-progress, >0 = successful; */
199 /* note that this must be set with req_list_lock, and if you set <0, */
200 /* it is your responsibility to also free up all of the other objects */
201 /* in this struct (like input_buffer_list, active_buf.parser_ctx) */
202 /* before releasing the lock */
203 int completion_status;
204};
205
Benjamin Romer712f42c2015-03-16 13:58:40 -0400206static atomic_t visorchipset_cache_buffers_in_use = ATOMIC_INIT(0);
Ken Cox12e364b2014-03-04 07:58:07 -0600207
208struct parahotplug_request {
209 struct list_head list;
210 int id;
211 unsigned long expiration;
Benjamin Romer3ab47702014-10-23 14:30:31 -0400212 struct controlvm_message msg;
Ken Cox12e364b2014-03-04 07:58:07 -0600213};
214
Benjamin Romerddf5de52015-03-16 13:58:41 -0400215static LIST_HEAD(parahotplug_request_list);
216static DEFINE_SPINLOCK(parahotplug_request_list_lock); /* lock for above */
Ken Cox12e364b2014-03-04 07:58:07 -0600217static void parahotplug_process_list(void);
218
219/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
220 * CONTROLVM_REPORTEVENT.
221 */
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400222static struct visorchipset_busdev_notifiers busdev_server_notifiers;
223static struct visorchipset_busdev_notifiers busdev_client_notifiers;
Ken Cox12e364b2014-03-04 07:58:07 -0600224
Benjamin Romer8e3fedd2015-03-16 13:58:43 -0400225static void bus_create_response(ulong bus_no, int response);
226static void bus_destroy_response(ulong bus_no, int response);
227static void device_create_response(ulong bus_no, ulong dev_no, int response);
228static void device_destroy_response(ulong bus_no, ulong dev_no, int response);
229static void device_resume_response(ulong bus_no, ulong dev_no, int response);
Ken Cox12e364b2014-03-04 07:58:07 -0600230
Benjamin Romer8e3fedd2015-03-16 13:58:43 -0400231static struct visorchipset_busdev_responders busdev_responders = {
Ken Cox12e364b2014-03-04 07:58:07 -0600232 .bus_create = bus_create_response,
233 .bus_destroy = bus_destroy_response,
234 .device_create = device_create_response,
235 .device_destroy = device_destroy_response,
Ken Cox927c7922014-03-05 14:52:25 -0600236 .device_pause = visorchipset_device_pause_response,
Ken Cox12e364b2014-03-04 07:58:07 -0600237 .device_resume = device_resume_response,
238};
239
240/* info for /dev/visorchipset */
Benjamin Romer5aa8ae52015-03-16 13:58:44 -0400241static dev_t major_dev = -1; /**< indicates major num for device */
Ken Cox12e364b2014-03-04 07:58:07 -0600242
Benjamin Romer19f66342014-07-22 09:56:25 -0400243/* prototypes for attributes */
244static ssize_t toolaction_show(struct device *dev,
245 struct device_attribute *attr, char *buf);
246static ssize_t toolaction_store(struct device *dev,
247 struct device_attribute *attr, const char *buf, size_t count);
248static DEVICE_ATTR_RW(toolaction);
249
Benjamin Romer54b31222014-07-22 09:56:26 -0400250static ssize_t boottotool_show(struct device *dev,
251 struct device_attribute *attr, char *buf);
252static ssize_t boottotool_store(struct device *dev,
253 struct device_attribute *attr, const char *buf, size_t count);
254static DEVICE_ATTR_RW(boottotool);
255
Benjamin Romer422af172014-07-24 14:08:42 -0400256static ssize_t error_show(struct device *dev, struct device_attribute *attr,
257 char *buf);
258static ssize_t error_store(struct device *dev, struct device_attribute *attr,
259 const char *buf, size_t count);
260static DEVICE_ATTR_RW(error);
261
262static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
263 char *buf);
264static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
265 const char *buf, size_t count);
266static DEVICE_ATTR_RW(textid);
267
268static ssize_t remaining_steps_show(struct device *dev,
269 struct device_attribute *attr, char *buf);
270static ssize_t remaining_steps_store(struct device *dev,
271 struct device_attribute *attr, const char *buf, size_t count);
272static DEVICE_ATTR_RW(remaining_steps);
273
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400274static ssize_t chipsetready_store(struct device *dev,
275 struct device_attribute *attr, const char *buf, size_t count);
276static DEVICE_ATTR_WO(chipsetready);
277
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400278static ssize_t devicedisabled_store(struct device *dev,
279 struct device_attribute *attr, const char *buf, size_t count);
280static DEVICE_ATTR_WO(devicedisabled);
281
282static ssize_t deviceenabled_store(struct device *dev,
283 struct device_attribute *attr, const char *buf, size_t count);
284static DEVICE_ATTR_WO(deviceenabled);
285
Benjamin Romer19f66342014-07-22 09:56:25 -0400286static struct attribute *visorchipset_install_attrs[] = {
287 &dev_attr_toolaction.attr,
Benjamin Romer54b31222014-07-22 09:56:26 -0400288 &dev_attr_boottotool.attr,
Benjamin Romer422af172014-07-24 14:08:42 -0400289 &dev_attr_error.attr,
290 &dev_attr_textid.attr,
291 &dev_attr_remaining_steps.attr,
Benjamin Romer19f66342014-07-22 09:56:25 -0400292 NULL
293};
294
295static struct attribute_group visorchipset_install_group = {
296 .name = "install",
297 .attrs = visorchipset_install_attrs
298};
299
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400300static struct attribute *visorchipset_guest_attrs[] = {
301 &dev_attr_chipsetready.attr,
302 NULL
303};
304
305static struct attribute_group visorchipset_guest_group = {
306 .name = "guest",
307 .attrs = visorchipset_guest_attrs
308};
309
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400310static struct attribute *visorchipset_parahotplug_attrs[] = {
311 &dev_attr_devicedisabled.attr,
312 &dev_attr_deviceenabled.attr,
313 NULL
314};
315
316static struct attribute_group visorchipset_parahotplug_group = {
317 .name = "parahotplug",
318 .attrs = visorchipset_parahotplug_attrs
319};
320
Benjamin Romer19f66342014-07-22 09:56:25 -0400321static const struct attribute_group *visorchipset_dev_groups[] = {
322 &visorchipset_install_group,
Benjamin Romer18b87ed2014-07-24 14:08:43 -0400323 &visorchipset_guest_group,
Benjamin Romere56fa7c2014-07-29 11:11:21 -0400324 &visorchipset_parahotplug_group,
Benjamin Romer19f66342014-07-22 09:56:25 -0400325 NULL
326};
327
Ken Cox12e364b2014-03-04 07:58:07 -0600328/* /sys/devices/platform/visorchipset */
Benjamin Romereb34e872015-03-16 13:58:45 -0400329static struct platform_device visorchipset_platform_device = {
Ken Cox12e364b2014-03-04 07:58:07 -0600330 .name = "visorchipset",
331 .id = -1,
Benjamin Romer19f66342014-07-22 09:56:25 -0400332 .dev.groups = visorchipset_dev_groups,
Ken Cox12e364b2014-03-04 07:58:07 -0600333};
334
335/* Function prototypes */
Benjamin Romerb3168c72015-03-16 13:58:46 -0400336static void controlvm_respond(struct controlvm_message_header *msg_hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400337 int response);
338static void controlvm_respond_chipset_init(
Benjamin Romerb3168c72015-03-16 13:58:46 -0400339 struct controlvm_message_header *msg_hdr, int response,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400340 enum ultra_chipset_feature features);
341static void controlvm_respond_physdev_changestate(
Benjamin Romerb3168c72015-03-16 13:58:46 -0400342 struct controlvm_message_header *msg_hdr, int response,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400343 struct spar_segment_state state);
Ken Cox12e364b2014-03-04 07:58:07 -0600344
Vincent Bernatd746cb52014-08-01 10:29:30 +0200345static ssize_t toolaction_show(struct device *dev,
346 struct device_attribute *attr,
347 char *buf)
Benjamin Romer19f66342014-07-22 09:56:25 -0400348{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400349 u8 toolAction;
Benjamin Romer19f66342014-07-22 09:56:25 -0400350
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400351 visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400352 offsetof(struct spar_controlvm_channel_protocol,
353 tool_action), &toolAction, sizeof(u8));
Benjamin Romer19f66342014-07-22 09:56:25 -0400354 return scnprintf(buf, PAGE_SIZE, "%u\n", toolAction);
355}
356
Vincent Bernatd746cb52014-08-01 10:29:30 +0200357static ssize_t toolaction_store(struct device *dev,
358 struct device_attribute *attr,
359 const char *buf, size_t count)
Benjamin Romer19f66342014-07-22 09:56:25 -0400360{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400361 u8 toolAction;
362 int ret;
Benjamin Romer19f66342014-07-22 09:56:25 -0400363
Benjamin Romer66e24b72014-07-25 13:55:10 -0400364 if (kstrtou8(buf, 10, &toolAction) != 0)
365 return -EINVAL;
366
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400367 ret = visorchannel_write(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400368 offsetof(struct spar_controlvm_channel_protocol, tool_action),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400369 &toolAction, sizeof(u8));
370
371 if (ret)
372 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400373 return count;
Benjamin Romer19f66342014-07-22 09:56:25 -0400374}
375
Vincent Bernatd746cb52014-08-01 10:29:30 +0200376static ssize_t boottotool_show(struct device *dev,
377 struct device_attribute *attr,
378 char *buf)
Benjamin Romer54b31222014-07-22 09:56:26 -0400379{
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400380 struct efi_spar_indication efiSparIndication;
Benjamin Romer54b31222014-07-22 09:56:26 -0400381
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400382 visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400383 offsetof(struct spar_controlvm_channel_protocol,
384 efi_spar_ind), &efiSparIndication,
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400385 sizeof(struct efi_spar_indication));
Benjamin Romer54b31222014-07-22 09:56:26 -0400386 return scnprintf(buf, PAGE_SIZE, "%u\n",
Benjamin Romer24503012014-10-23 14:30:22 -0400387 efiSparIndication.boot_to_tool);
Benjamin Romer54b31222014-07-22 09:56:26 -0400388}
389
Vincent Bernatd746cb52014-08-01 10:29:30 +0200390static ssize_t boottotool_store(struct device *dev,
391 struct device_attribute *attr,
392 const char *buf, size_t count)
Benjamin Romer54b31222014-07-22 09:56:26 -0400393{
Benjamin Romer66e24b72014-07-25 13:55:10 -0400394 int val, ret;
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400395 struct efi_spar_indication efiSparIndication;
Benjamin Romer54b31222014-07-22 09:56:26 -0400396
Benjamin Romer66e24b72014-07-25 13:55:10 -0400397 if (kstrtoint(buf, 10, &val) != 0)
398 return -EINVAL;
399
Benjamin Romer24503012014-10-23 14:30:22 -0400400 efiSparIndication.boot_to_tool = val;
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400401 ret = visorchannel_write(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400402 offsetof(struct spar_controlvm_channel_protocol,
403 efi_spar_ind),
Benjamin Romer54b31222014-07-22 09:56:26 -0400404 &(efiSparIndication),
Benjamin Romer755e2ec2014-10-23 14:30:21 -0400405 sizeof(struct efi_spar_indication));
Benjamin Romer66e24b72014-07-25 13:55:10 -0400406
407 if (ret)
408 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400409 return count;
Benjamin Romer54b31222014-07-22 09:56:26 -0400410}
Benjamin Romer422af172014-07-24 14:08:42 -0400411
412static ssize_t error_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
414{
415 u32 error;
416
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400417 visorchannel_read(controlvm_channel, offsetof(
Benjamin Romerd19642f2014-10-23 14:30:34 -0400418 struct spar_controlvm_channel_protocol, installation_error),
Benjamin Romer422af172014-07-24 14:08:42 -0400419 &error, sizeof(u32));
420 return scnprintf(buf, PAGE_SIZE, "%i\n", error);
421}
422
423static ssize_t error_store(struct device *dev, struct device_attribute *attr,
424 const char *buf, size_t count)
425{
426 u32 error;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400427 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400428
Benjamin Romer66e24b72014-07-25 13:55:10 -0400429 if (kstrtou32(buf, 10, &error) != 0)
430 return -EINVAL;
431
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400432 ret = visorchannel_write(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400433 offsetof(struct spar_controlvm_channel_protocol,
434 installation_error),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400435 &error, sizeof(u32));
436 if (ret)
437 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400438 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400439}
440
441static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
442 char *buf)
443{
444 u32 textId;
445
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400446 visorchannel_read(controlvm_channel, offsetof(
Benjamin Romerd19642f2014-10-23 14:30:34 -0400447 struct spar_controlvm_channel_protocol, installation_text_id),
Benjamin Romer422af172014-07-24 14:08:42 -0400448 &textId, sizeof(u32));
449 return scnprintf(buf, PAGE_SIZE, "%i\n", textId);
450}
451
452static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
453 const char *buf, size_t count)
454{
455 u32 textId;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400456 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400457
Benjamin Romer66e24b72014-07-25 13:55:10 -0400458 if (kstrtou32(buf, 10, &textId) != 0)
459 return -EINVAL;
460
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400461 ret = visorchannel_write(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400462 offsetof(struct spar_controlvm_channel_protocol,
463 installation_text_id),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400464 &textId, sizeof(u32));
465 if (ret)
466 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400467 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400468}
469
Benjamin Romer422af172014-07-24 14:08:42 -0400470static ssize_t remaining_steps_show(struct device *dev,
471 struct device_attribute *attr, char *buf)
472{
473 u16 remainingSteps;
474
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400475 visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400476 offsetof(struct spar_controlvm_channel_protocol,
477 installation_remaining_steps),
Benjamin Romer422af172014-07-24 14:08:42 -0400478 &remainingSteps,
479 sizeof(u16));
480 return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps);
481}
482
483static ssize_t remaining_steps_store(struct device *dev,
484 struct device_attribute *attr, const char *buf, size_t count)
485{
486 u16 remainingSteps;
Benjamin Romer66e24b72014-07-25 13:55:10 -0400487 int ret;
Benjamin Romer422af172014-07-24 14:08:42 -0400488
Benjamin Romer66e24b72014-07-25 13:55:10 -0400489 if (kstrtou16(buf, 10, &remainingSteps) != 0)
490 return -EINVAL;
491
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400492 ret = visorchannel_write(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400493 offsetof(struct spar_controlvm_channel_protocol,
494 installation_remaining_steps),
Benjamin Romer66e24b72014-07-25 13:55:10 -0400495 &remainingSteps, sizeof(u16));
496 if (ret)
497 return ret;
Benjamin Romere22a4a02014-08-18 09:34:54 -0400498 return count;
Benjamin Romer422af172014-07-24 14:08:42 -0400499}
500
Ken Cox12e364b2014-03-04 07:58:07 -0600501static void
Benjamin Romer9b989a982015-03-16 13:58:11 -0400502bus_info_clear(void *v)
Ken Cox12e364b2014-03-04 07:58:07 -0600503{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400504 struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v);
Ken Cox12e364b2014-03-04 07:58:07 -0600505
Ken Cox12e364b2014-03-04 07:58:07 -0600506 kfree(p->name);
507 p->name = NULL;
508
509 kfree(p->description);
510 p->description = NULL;
511
512 p->state.created = 0;
Benjamin Romer33192fa2014-10-31 09:57:27 -0400513 memset(p, 0, sizeof(struct visorchipset_bus_info));
Ken Cox12e364b2014-03-04 07:58:07 -0600514}
515
516static void
Benjamin Romer9b989a982015-03-16 13:58:11 -0400517dev_info_clear(void *v)
Ken Cox12e364b2014-03-04 07:58:07 -0600518{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400519 struct visorchipset_device_info *p =
520 (struct visorchipset_device_info *)(v);
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400521
Ken Cox12e364b2014-03-04 07:58:07 -0600522 p->state.created = 0;
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400523 memset(p, 0, sizeof(struct visorchipset_device_info));
Ken Cox12e364b2014-03-04 07:58:07 -0600524}
525
Benjamin Romerc2422332014-07-29 15:09:40 -0400526static u8
Ken Cox12e364b2014-03-04 07:58:07 -0600527check_chipset_events(void)
528{
529 int i;
Benjamin Romerc2422332014-07-29 15:09:40 -0400530 u8 send_msg = 1;
Ken Cox12e364b2014-03-04 07:58:07 -0600531 /* Check events to determine if response should be sent */
532 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
533 send_msg &= chipset_events[i];
534 return send_msg;
535}
536
537static void
538clear_chipset_events(void)
539{
540 int i;
541 /* Clear chipset_events */
542 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
543 chipset_events[i] = 0;
544}
545
546void
Benjamin Romerfe90d892014-10-31 09:57:32 -0400547visorchipset_register_busdev_server(
548 struct visorchipset_busdev_notifiers *notifiers,
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400549 struct visorchipset_busdev_responders *responders,
Benjamin Romer1e7a59c2014-10-31 09:57:35 -0400550 struct ultra_vbus_deviceinfo *driver_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600551{
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400552 down(&notifier_lock);
Benjamin Romer38f736e2015-03-16 13:58:13 -0400553 if (!notifiers) {
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400554 memset(&busdev_server_notifiers, 0,
555 sizeof(busdev_server_notifiers));
Ken Cox12e364b2014-03-04 07:58:07 -0600556 serverregistered = 0; /* clear flag */
557 } else {
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400558 busdev_server_notifiers = *notifiers;
Ken Cox12e364b2014-03-04 07:58:07 -0600559 serverregistered = 1; /* set flag */
560 }
561 if (responders)
Benjamin Romer8e3fedd2015-03-16 13:58:43 -0400562 *responders = busdev_responders;
Benjamin Romer1e7a59c2014-10-31 09:57:35 -0400563 if (driver_info)
564 bus_device_info_init(driver_info, "chipset", "visorchipset",
Ken Cox836bee92014-06-26 09:55:55 -0500565 VERSION, NULL);
Ken Cox12e364b2014-03-04 07:58:07 -0600566
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400567 up(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -0600568}
569EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server);
570
571void
Benjamin Romerfe90d892014-10-31 09:57:32 -0400572visorchipset_register_busdev_client(
573 struct visorchipset_busdev_notifiers *notifiers,
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400574 struct visorchipset_busdev_responders *responders,
Benjamin Romer43fce012014-10-31 09:57:34 -0400575 struct ultra_vbus_deviceinfo *driver_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600576{
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400577 down(&notifier_lock);
Benjamin Romer38f736e2015-03-16 13:58:13 -0400578 if (!notifiers) {
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400579 memset(&busdev_client_notifiers, 0,
580 sizeof(busdev_client_notifiers));
Ken Cox12e364b2014-03-04 07:58:07 -0600581 clientregistered = 0; /* clear flag */
582 } else {
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400583 busdev_client_notifiers = *notifiers;
Ken Cox12e364b2014-03-04 07:58:07 -0600584 clientregistered = 1; /* set flag */
585 }
586 if (responders)
Benjamin Romer8e3fedd2015-03-16 13:58:43 -0400587 *responders = busdev_responders;
Benjamin Romer43fce012014-10-31 09:57:34 -0400588 if (driver_info)
589 bus_device_info_init(driver_info, "chipset(bolts)",
590 "visorchipset", VERSION, NULL);
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400591 up(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -0600592}
593EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client);
594
595static void
596cleanup_controlvm_structures(void)
597{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400598 struct visorchipset_bus_info *bi, *tmp_bi;
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400599 struct visorchipset_device_info *di, *tmp_di;
Ken Cox12e364b2014-03-04 07:58:07 -0600600
Benjamin Romer1390b882015-03-16 13:58:03 -0400601 list_for_each_entry_safe(bi, tmp_bi, &bus_info_list, entry) {
Benjamin Romer9b989a982015-03-16 13:58:11 -0400602 bus_info_clear(bi);
Ken Cox12e364b2014-03-04 07:58:07 -0600603 list_del(&bi->entry);
604 kfree(bi);
605 }
606
Benjamin Romer1390b882015-03-16 13:58:03 -0400607 list_for_each_entry_safe(di, tmp_di, &dev_info_list, entry) {
Benjamin Romer9b989a982015-03-16 13:58:11 -0400608 dev_info_clear(di);
Ken Cox12e364b2014-03-04 07:58:07 -0600609 list_del(&di->entry);
610 kfree(di);
611 }
612}
613
614static void
Benjamin Romer3ab47702014-10-23 14:30:31 -0400615chipset_init(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -0600616{
617 static int chipset_inited;
Benjamin Romerb9b141e2014-10-23 14:30:24 -0400618 enum ultra_chipset_feature features = 0;
Ken Cox12e364b2014-03-04 07:58:07 -0600619 int rc = CONTROLVM_RESP_SUCCESS;
620
621 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
622 if (chipset_inited) {
Ken Cox22ad57b2014-03-19 13:06:25 -0500623 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Benjamin Romere3199b22015-03-16 13:58:14 -0400624 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -0600625 }
626 chipset_inited = 1;
627 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO);
628
629 /* Set features to indicate we support parahotplug (if Command
630 * also supports it). */
631 features =
Benjamin Romer2ea51172014-10-23 14:30:25 -0400632 inmsg->cmd.init_chipset.
Ken Cox12e364b2014-03-04 07:58:07 -0600633 features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG;
634
635 /* Set the "reply" bit so Command knows this is a
636 * features-aware driver. */
637 features |= ULTRA_CHIPSET_FEATURE_REPLY;
638
Benjamin Romere3199b22015-03-16 13:58:14 -0400639cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -0600640 if (rc < 0)
641 cleanup_controlvm_structures();
Benjamin Romer98d7b592014-10-23 14:30:26 -0400642 if (inmsg->hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -0600643 controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
644}
645
646static void
Benjamin Romer3ab47702014-10-23 14:30:31 -0400647controlvm_init_response(struct controlvm_message *msg,
Benjamin Romerb3168c72015-03-16 13:58:46 -0400648 struct controlvm_message_header *msg_hdr, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600649{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400650 memset(msg, 0, sizeof(struct controlvm_message));
Benjamin Romerb3168c72015-03-16 13:58:46 -0400651 memcpy(&msg->hdr, msg_hdr, sizeof(struct controlvm_message_header));
Benjamin Romer98d7b592014-10-23 14:30:26 -0400652 msg->hdr.payload_bytes = 0;
653 msg->hdr.payload_vm_offset = 0;
654 msg->hdr.payload_max_bytes = 0;
Ken Cox12e364b2014-03-04 07:58:07 -0600655 if (response < 0) {
Benjamin Romer98d7b592014-10-23 14:30:26 -0400656 msg->hdr.flags.failed = 1;
657 msg->hdr.completion_status = (u32) (-response);
Ken Cox12e364b2014-03-04 07:58:07 -0600658 }
659}
660
661static void
Benjamin Romerb3168c72015-03-16 13:58:46 -0400662controlvm_respond(struct controlvm_message_header *msg_hdr, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600663{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400664 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400665
Benjamin Romerb3168c72015-03-16 13:58:46 -0400666 controlvm_init_response(&outmsg, msg_hdr, response);
Ken Cox12e364b2014-03-04 07:58:07 -0600667 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send
668 * back the deviceChangeState structure in the packet. */
Benjamin Romerb3168c72015-03-16 13:58:46 -0400669 if (msg_hdr->id == CONTROLVM_DEVICE_CHANGESTATE &&
Benjamin Romer0639ba62015-03-16 13:58:04 -0400670 g_devicechangestate_packet.device_change_state.bus_no ==
671 g_diagpool_bus_no &&
672 g_devicechangestate_packet.device_change_state.dev_no ==
Benjamin Romer83d48902015-03-16 13:58:01 -0400673 g_diagpool_dev_no)
Benjamin Romer4f44b722015-03-16 13:58:02 -0400674 outmsg.cmd = g_devicechangestate_packet;
Benjamin Romer2098dbd2015-03-04 12:14:22 -0500675 if (outmsg.hdr.flags.test_message == 1)
Ken Cox12e364b2014-03-04 07:58:07 -0600676 return;
Benjamin Romer2098dbd2015-03-04 12:14:22 -0500677
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400678 if (!visorchannel_signalinsert(controlvm_channel,
Ken Cox12e364b2014-03-04 07:58:07 -0600679 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600680 return;
681 }
682}
683
684static void
Benjamin Romerb3168c72015-03-16 13:58:46 -0400685controlvm_respond_chipset_init(struct controlvm_message_header *msg_hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400686 int response,
Benjamin Romerb9b141e2014-10-23 14:30:24 -0400687 enum ultra_chipset_feature features)
Ken Cox12e364b2014-03-04 07:58:07 -0600688{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400689 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400690
Benjamin Romerb3168c72015-03-16 13:58:46 -0400691 controlvm_init_response(&outmsg, msg_hdr, response);
Benjamin Romer2ea51172014-10-23 14:30:25 -0400692 outmsg.cmd.init_chipset.features = features;
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400693 if (!visorchannel_signalinsert(controlvm_channel,
Ken Cox12e364b2014-03-04 07:58:07 -0600694 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600695 return;
696 }
697}
698
Benjamin Romer98d7b592014-10-23 14:30:26 -0400699static void controlvm_respond_physdev_changestate(
Benjamin Romerb3168c72015-03-16 13:58:46 -0400700 struct controlvm_message_header *msg_hdr, int response,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400701 struct spar_segment_state state)
Ken Cox12e364b2014-03-04 07:58:07 -0600702{
Benjamin Romer3ab47702014-10-23 14:30:31 -0400703 struct controlvm_message outmsg;
Benjamin Romer26eb2c02014-08-18 09:34:53 -0400704
Benjamin Romerb3168c72015-03-16 13:58:46 -0400705 controlvm_init_response(&outmsg, msg_hdr, response);
Benjamin Romer2ea51172014-10-23 14:30:25 -0400706 outmsg.cmd.device_change_state.state = state;
707 outmsg.cmd.device_change_state.flags.phys_device = 1;
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400708 if (!visorchannel_signalinsert(controlvm_channel,
Ken Cox12e364b2014-03-04 07:58:07 -0600709 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
Ken Cox12e364b2014-03-04 07:58:07 -0600710 return;
711 }
712}
713
714void
Benjamin Romer2c683cd2014-10-31 09:57:22 -0400715visorchipset_save_message(struct controlvm_message *msg,
716 enum crash_obj_type type)
Ken Cox12e364b2014-03-04 07:58:07 -0600717{
Benjamin Romer45772252015-03-16 13:58:15 -0400718 u32 crash_msg_offset;
719 u16 crash_msg_count;
Ken Cox12e364b2014-03-04 07:58:07 -0600720
721 /* get saved message count */
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400722 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400723 offsetof(struct spar_controlvm_channel_protocol,
724 saved_crash_message_count),
Benjamin Romer45772252015-03-16 13:58:15 -0400725 &crash_msg_count, sizeof(u16)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600726 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
727 POSTCODE_SEVERITY_ERR);
728 return;
729 }
730
Benjamin Romer45772252015-03-16 13:58:15 -0400731 if (crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
Ken Cox12e364b2014-03-04 07:58:07 -0600732 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
Benjamin Romer45772252015-03-16 13:58:15 -0400733 crash_msg_count,
Ken Cox12e364b2014-03-04 07:58:07 -0600734 POSTCODE_SEVERITY_ERR);
735 return;
736 }
737
738 /* get saved crash message offset */
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400739 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -0400740 offsetof(struct spar_controlvm_channel_protocol,
741 saved_crash_message_offset),
Benjamin Romer45772252015-03-16 13:58:15 -0400742 &crash_msg_offset, sizeof(u32)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600743 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
744 POSTCODE_SEVERITY_ERR);
745 return;
746 }
747
Benjamin Romer2c683cd2014-10-31 09:57:22 -0400748 if (type == CRASH_BUS) {
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400749 if (visorchannel_write(controlvm_channel,
Benjamin Romer45772252015-03-16 13:58:15 -0400750 crash_msg_offset,
Benjamin Romer3ab47702014-10-23 14:30:31 -0400751 msg,
752 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600753 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC,
754 POSTCODE_SEVERITY_ERR);
755 return;
756 }
757 } else {
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400758 if (visorchannel_write(controlvm_channel,
Benjamin Romer45772252015-03-16 13:58:15 -0400759 crash_msg_offset +
Benjamin Romer3ab47702014-10-23 14:30:31 -0400760 sizeof(struct controlvm_message), msg,
761 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -0600762 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC,
763 POSTCODE_SEVERITY_ERR);
764 return;
765 }
766 }
767}
768EXPORT_SYMBOL_GPL(visorchipset_save_message);
769
770static void
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400771bus_responder(enum controlvm_id cmd_id, ulong bus_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600772{
Benjamin Romer33192fa2014-10-31 09:57:27 -0400773 struct visorchipset_bus_info *p = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600774 BOOL need_clear = FALSE;
775
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400776 p = findbus(&bus_info_list, bus_no);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500777 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600778 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500779
Ken Cox12e364b2014-03-04 07:58:07 -0600780 if (response < 0) {
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400781 if ((cmd_id == CONTROLVM_BUS_CREATE) &&
Ken Cox12e364b2014-03-04 07:58:07 -0600782 (response != (-CONTROLVM_RESP_ERROR_ALREADY_DONE)))
783 /* undo the row we just created... */
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400784 delbusdevices(&dev_info_list, bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600785 } else {
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400786 if (cmd_id == CONTROLVM_BUS_CREATE)
Ken Cox12e364b2014-03-04 07:58:07 -0600787 p->state.created = 1;
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400788 if (cmd_id == CONTROLVM_BUS_DESTROY)
Ken Cox12e364b2014-03-04 07:58:07 -0600789 need_clear = TRUE;
790 }
791
Benjamin Romer0aca78442015-03-04 12:14:25 -0500792 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600793 return; /* no controlvm response needed */
Benjamin Romer6b59b312015-03-16 13:58:18 -0400794 if (p->pending_msg_hdr.id != (u32)cmd_id)
Ken Cox12e364b2014-03-04 07:58:07 -0600795 return;
Benjamin Romer33192fa2014-10-31 09:57:27 -0400796 controlvm_respond(&p->pending_msg_hdr, response);
797 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600798 if (need_clear) {
Benjamin Romer9b989a982015-03-16 13:58:11 -0400799 bus_info_clear(p);
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400800 delbusdevices(&dev_info_list, bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600801 }
802}
803
804static void
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400805device_changestate_responder(enum controlvm_id cmd_id,
806 ulong bus_no, ulong dev_no, int response,
807 struct spar_segment_state response_state)
Ken Cox12e364b2014-03-04 07:58:07 -0600808{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400809 struct visorchipset_device_info *p = NULL;
Benjamin Romer3ab47702014-10-23 14:30:31 -0400810 struct controlvm_message outmsg;
Ken Cox12e364b2014-03-04 07:58:07 -0600811
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400812 p = finddevice(&dev_info_list, bus_no, dev_no);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500813 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600814 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500815 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600816 return; /* no controlvm response needed */
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400817 if (p->pending_msg_hdr.id != cmd_id)
Ken Cox12e364b2014-03-04 07:58:07 -0600818 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600819
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400820 controlvm_init_response(&outmsg, &p->pending_msg_hdr, response);
Ken Cox12e364b2014-03-04 07:58:07 -0600821
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400822 outmsg.cmd.device_change_state.bus_no = bus_no;
823 outmsg.cmd.device_change_state.dev_no = dev_no;
824 outmsg.cmd.device_change_state.state = response_state;
Ken Cox12e364b2014-03-04 07:58:07 -0600825
Benjamin Romerc3d9a222015-03-16 13:58:05 -0400826 if (!visorchannel_signalinsert(controlvm_channel,
Benjamin Romer0aca78442015-03-04 12:14:25 -0500827 CONTROLVM_QUEUE_REQUEST, &outmsg))
Ken Cox12e364b2014-03-04 07:58:07 -0600828 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600829
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400830 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600831}
832
833static void
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400834device_responder(enum controlvm_id cmd_id, ulong bus_no, ulong dev_no,
Benjamin Romer53bebb12014-10-23 14:30:17 -0400835 int response)
Ken Cox12e364b2014-03-04 07:58:07 -0600836{
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400837 struct visorchipset_device_info *p = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600838 BOOL need_clear = FALSE;
839
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400840 p = finddevice(&dev_info_list, bus_no, dev_no);
Benjamin Romer0aca78442015-03-04 12:14:25 -0500841 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -0600842 return;
Ken Cox12e364b2014-03-04 07:58:07 -0600843 if (response >= 0) {
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400844 if (cmd_id == CONTROLVM_DEVICE_CREATE)
Ken Cox12e364b2014-03-04 07:58:07 -0600845 p->state.created = 1;
Benjamin Romerfbb31f42015-03-16 13:58:16 -0400846 if (cmd_id == CONTROLVM_DEVICE_DESTROY)
Ken Cox12e364b2014-03-04 07:58:07 -0600847 need_clear = TRUE;
848 }
849
Benjamin Romer0aca78442015-03-04 12:14:25 -0500850 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
Ken Cox12e364b2014-03-04 07:58:07 -0600851 return; /* no controlvm response needed */
Benjamin Romer0aca78442015-03-04 12:14:25 -0500852
Benjamin Romer6b59b312015-03-16 13:58:18 -0400853 if (p->pending_msg_hdr.id != (u32)cmd_id)
Ken Cox12e364b2014-03-04 07:58:07 -0600854 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500855
Benjamin Romer246e0cd2014-10-31 09:57:24 -0400856 controlvm_respond(&p->pending_msg_hdr, response);
857 p->pending_msg_hdr.id = CONTROLVM_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -0600858 if (need_clear)
Benjamin Romer9b989a982015-03-16 13:58:11 -0400859 dev_info_clear(p);
Ken Cox12e364b2014-03-04 07:58:07 -0600860}
861
862static void
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400863bus_epilog(u32 bus_no,
864 u32 cmd, struct controlvm_message_header *msg_hdr,
865 int response, BOOL need_response)
Ken Cox12e364b2014-03-04 07:58:07 -0600866{
867 BOOL notified = FALSE;
868
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400869 struct visorchipset_bus_info *bus_info = findbus(&bus_info_list,
870 bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600871
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400872 if (!bus_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600873 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500874
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400875 if (need_response) {
876 memcpy(&bus_info->pending_msg_hdr, msg_hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400877 sizeof(struct controlvm_message_header));
Benjamin Romer75c1f8b2015-03-16 13:58:19 -0400878 } else {
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400879 bus_info->pending_msg_hdr.id = CONTROLVM_INVALID;
Benjamin Romer75c1f8b2015-03-16 13:58:19 -0400880 }
Ken Cox12e364b2014-03-04 07:58:07 -0600881
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400882 down(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -0600883 if (response == CONTROLVM_RESP_SUCCESS) {
884 switch (cmd) {
885 case CONTROLVM_BUS_CREATE:
886 /* We can't tell from the bus_create
887 * information which of our 2 bus flavors the
888 * devices on this bus will ultimately end up.
889 * FORTUNATELY, it turns out it is harmless to
890 * send the bus_create to both of them. We can
891 * narrow things down a little bit, though,
892 * because we know: - BusDev_Server can handle
893 * either server or client devices
894 * - BusDev_Client can handle ONLY client
895 * devices */
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400896 if (busdev_server_notifiers.bus_create) {
897 (*busdev_server_notifiers.bus_create) (bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600898 notified = TRUE;
899 }
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400900 if ((!bus_info->flags.server) /*client */ &&
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400901 busdev_client_notifiers.bus_create) {
902 (*busdev_client_notifiers.bus_create) (bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600903 notified = TRUE;
904 }
905 break;
906 case CONTROLVM_BUS_DESTROY:
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400907 if (busdev_server_notifiers.bus_destroy) {
908 (*busdev_server_notifiers.bus_destroy) (bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600909 notified = TRUE;
910 }
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400911 if ((!bus_info->flags.server) /*client */ &&
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400912 busdev_client_notifiers.bus_destroy) {
913 (*busdev_client_notifiers.bus_destroy) (bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600914 notified = TRUE;
915 }
916 break;
917 }
918 }
919 if (notified)
920 /* The callback function just called above is responsible
Benjamin Romer929aa8a2014-10-31 09:57:33 -0400921 * for calling the appropriate visorchipset_busdev_responders
Ken Cox12e364b2014-03-04 07:58:07 -0600922 * function, which will call bus_responder()
923 */
924 ;
925 else
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400926 bus_responder(cmd, bus_no, response);
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400927 up(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -0600928}
929
930static void
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400931device_epilog(u32 bus_no, u32 dev_no, struct spar_segment_state state, u32 cmd,
932 struct controlvm_message_header *msg_hdr, int response,
933 BOOL need_response, BOOL for_visorbus)
Ken Cox12e364b2014-03-04 07:58:07 -0600934{
Benjamin Romerfe90d892014-10-31 09:57:32 -0400935 struct visorchipset_busdev_notifiers *notifiers = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -0600936 BOOL notified = FALSE;
937
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400938 struct visorchipset_device_info *dev_info =
939 finddevice(&dev_info_list, bus_no, dev_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600940 char *envp[] = {
941 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
942 NULL
943 };
944
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400945 if (!dev_info)
Ken Cox12e364b2014-03-04 07:58:07 -0600946 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -0500947
Ken Cox12e364b2014-03-04 07:58:07 -0600948 if (for_visorbus)
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400949 notifiers = &busdev_server_notifiers;
Ken Cox12e364b2014-03-04 07:58:07 -0600950 else
Benjamin Romer6fe345a2015-03-16 13:58:42 -0400951 notifiers = &busdev_client_notifiers;
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400952 if (need_response) {
953 memcpy(&dev_info->pending_msg_hdr, msg_hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -0400954 sizeof(struct controlvm_message_header));
Benjamin Romer75c1f8b2015-03-16 13:58:19 -0400955 } else {
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400956 dev_info->pending_msg_hdr.id = CONTROLVM_INVALID;
Benjamin Romer75c1f8b2015-03-16 13:58:19 -0400957 }
Ken Cox12e364b2014-03-04 07:58:07 -0600958
Benjamin Romer8f1947a2015-03-16 13:57:59 -0400959 down(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -0600960 if (response >= 0) {
961 switch (cmd) {
962 case CONTROLVM_DEVICE_CREATE:
963 if (notifiers->device_create) {
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400964 (*notifiers->device_create) (bus_no, dev_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600965 notified = TRUE;
966 }
967 break;
968 case CONTROLVM_DEVICE_CHANGESTATE:
969 /* ServerReady / ServerRunning / SegmentStateRunning */
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -0400970 if (state.alive == segment_state_running.alive &&
971 state.operating ==
972 segment_state_running.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -0600973 if (notifiers->device_resume) {
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400974 (*notifiers->device_resume) (bus_no,
975 dev_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600976 notified = TRUE;
977 }
978 }
979 /* ServerNotReady / ServerLost / SegmentStateStandby */
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -0400980 else if (state.alive == segment_state_standby.alive &&
Benjamin Romer3f833b52014-10-23 14:30:12 -0400981 state.operating ==
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -0400982 segment_state_standby.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -0600983 /* technically this is standby case
984 * where server is lost
985 */
986 if (notifiers->device_pause) {
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400987 (*notifiers->device_pause) (bus_no,
988 dev_no);
Ken Cox12e364b2014-03-04 07:58:07 -0600989 notified = TRUE;
990 }
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -0400991 } else if (state.alive == segment_state_paused.alive &&
Benjamin Romer3f833b52014-10-23 14:30:12 -0400992 state.operating ==
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -0400993 segment_state_paused.operating) {
Ken Cox12e364b2014-03-04 07:58:07 -0600994 /* this is lite pause where channel is
995 * still valid just 'pause' of it
996 */
Benjamin Romer2836c6a2015-03-16 13:58:17 -0400997 if (bus_no == g_diagpool_bus_no &&
998 dev_no == g_diagpool_dev_no) {
Ken Cox12e364b2014-03-04 07:58:07 -0600999 /* this will trigger the
1000 * diag_shutdown.sh script in
1001 * the visorchipset hotplug */
1002 kobject_uevent_env
Benjamin Romereb34e872015-03-16 13:58:45 -04001003 (&visorchipset_platform_device.dev.
Ken Cox12e364b2014-03-04 07:58:07 -06001004 kobj, KOBJ_ONLINE, envp);
1005 }
1006 }
1007 break;
1008 case CONTROLVM_DEVICE_DESTROY:
1009 if (notifiers->device_destroy) {
Benjamin Romer2836c6a2015-03-16 13:58:17 -04001010 (*notifiers->device_destroy) (bus_no, dev_no);
Ken Cox12e364b2014-03-04 07:58:07 -06001011 notified = TRUE;
1012 }
1013 break;
1014 }
1015 }
1016 if (notified)
1017 /* The callback function just called above is responsible
Benjamin Romer929aa8a2014-10-31 09:57:33 -04001018 * for calling the appropriate visorchipset_busdev_responders
Ken Cox12e364b2014-03-04 07:58:07 -06001019 * function, which will call device_responder()
1020 */
1021 ;
1022 else
Benjamin Romer2836c6a2015-03-16 13:58:17 -04001023 device_responder(cmd, bus_no, dev_no, response);
Benjamin Romer8f1947a2015-03-16 13:57:59 -04001024 up(&notifier_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001025}
1026
1027static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001028bus_create(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001029{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001030 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001031 ulong bus_no = cmd->create_bus.bus_no;
Ken Cox12e364b2014-03-04 07:58:07 -06001032 int rc = CONTROLVM_RESP_SUCCESS;
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001033 struct visorchipset_bus_info *bus_info = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001034
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001035 bus_info = findbus(&bus_info_list, bus_no);
1036 if (bus_info && (bus_info->state.created == 1)) {
1037 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001038 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001039 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001040 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001041 }
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001042 bus_info = kzalloc(sizeof(*bus_info), GFP_KERNEL);
1043 if (!bus_info) {
1044 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001045 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001046 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001047 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001048 }
1049
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001050 INIT_LIST_HEAD(&bus_info->entry);
1051 bus_info->bus_no = bus_no;
1052 bus_info->dev_no = cmd->create_bus.dev_count;
Ken Cox12e364b2014-03-04 07:58:07 -06001053
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001054 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06001055
Benjamin Romer98d7b592014-10-23 14:30:26 -04001056 if (inmsg->hdr.flags.test_message == 1)
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001057 bus_info->chan_info.addr_type = ADDRTYPE_LOCALTEST;
Ken Cox12e364b2014-03-04 07:58:07 -06001058 else
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001059 bus_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
Ken Cox12e364b2014-03-04 07:58:07 -06001060
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001061 bus_info->flags.server = inmsg->hdr.flags.server;
1062 bus_info->chan_info.channel_addr = cmd->create_bus.channel_addr;
1063 bus_info->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes;
1064 bus_info->chan_info.channel_type_uuid =
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001065 cmd->create_bus.bus_data_type_uuid;
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001066 bus_info->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid;
Ken Cox12e364b2014-03-04 07:58:07 -06001067
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001068 list_add(&bus_info->entry, &bus_info_list);
Ken Cox12e364b2014-03-04 07:58:07 -06001069
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001070 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06001071
Benjamin Romer6c5fed32015-03-16 13:58:20 -04001072cleanup:
1073 bus_epilog(bus_no, CONTROLVM_BUS_CREATE, &inmsg->hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001074 rc, inmsg->hdr.flags.response_expected == 1);
Ken Cox12e364b2014-03-04 07:58:07 -06001075}
1076
1077static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001078bus_destroy(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001079{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001080 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romerdff54cd2015-03-16 13:58:21 -04001081 ulong bus_no = cmd->destroy_bus.bus_no;
1082 struct visorchipset_bus_info *bus_info;
Ken Cox12e364b2014-03-04 07:58:07 -06001083 int rc = CONTROLVM_RESP_SUCCESS;
1084
Benjamin Romerdff54cd2015-03-16 13:58:21 -04001085 bus_info = findbus(&bus_info_list, bus_no);
1086 if (!bus_info)
Ken Cox22ad57b2014-03-19 13:06:25 -05001087 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
Benjamin Romerdff54cd2015-03-16 13:58:21 -04001088 else if (bus_info->state.created == 0)
Ken Cox22ad57b2014-03-19 13:06:25 -05001089 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Ken Cox12e364b2014-03-04 07:58:07 -06001090
Benjamin Romerdff54cd2015-03-16 13:58:21 -04001091 bus_epilog(bus_no, CONTROLVM_BUS_DESTROY, &inmsg->hdr,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001092 rc, inmsg->hdr.flags.response_expected == 1);
Ken Cox12e364b2014-03-04 07:58:07 -06001093}
1094
1095static void
Benjamin Romer317d9612015-03-16 13:57:51 -04001096bus_configure(struct controlvm_message *inmsg,
1097 struct parser_context *parser_ctx)
Ken Cox12e364b2014-03-04 07:58:07 -06001098{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001099 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romer654bada2015-03-16 13:58:22 -04001100 ulong bus_no = cmd->configure_bus.bus_no;
1101 struct visorchipset_bus_info *bus_info = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001102 int rc = CONTROLVM_RESP_SUCCESS;
1103 char s[99];
1104
Benjamin Romer654bada2015-03-16 13:58:22 -04001105 bus_no = cmd->configure_bus.bus_no;
1106 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, bus_no,
1107 POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06001108
Benjamin Romer654bada2015-03-16 13:58:22 -04001109 bus_info = findbus(&bus_info_list, bus_no);
1110 if (!bus_info) {
1111 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001112 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001113 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
Benjamin Romer654bada2015-03-16 13:58:22 -04001114 } else if (bus_info->state.created == 0) {
1115 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001116 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001117 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
Benjamin Romer654bada2015-03-16 13:58:22 -04001118 } else if (bus_info->pending_msg_hdr.id != CONTROLVM_INVALID) {
1119 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001120 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001121 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT;
Benjamin Romer654bada2015-03-16 13:58:22 -04001122 } else {
1123 bus_info->partition_handle = cmd->configure_bus.guest_handle;
1124 bus_info->partition_uuid = parser_id_get(parser_ctx);
1125 parser_param_start(parser_ctx, PARSERSTRING_NAME);
1126 bus_info->name = parser_string_get(parser_ctx);
1127
1128 visorchannel_uuid_id(&bus_info->partition_uuid, s);
1129 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, bus_no,
1130 POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06001131 }
Benjamin Romer654bada2015-03-16 13:58:22 -04001132 bus_epilog(bus_no, CONTROLVM_BUS_CONFIGURE, &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 -04001137my_device_create(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001138{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001139 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001140 ulong bus_no = cmd->create_device.bus_no;
1141 ulong dev_no = cmd->create_device.dev_no;
1142 struct visorchipset_device_info *dev_info = NULL;
1143 struct visorchipset_bus_info *bus_info = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001144 int rc = CONTROLVM_RESP_SUCCESS;
1145
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001146 dev_info = finddevice(&dev_info_list, bus_no, dev_no);
1147 if (dev_info && (dev_info->state.created == 1)) {
1148 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001149 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001150 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001151 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001152 }
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001153 bus_info = findbus(&bus_info_list, bus_no);
1154 if (!bus_info) {
1155 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001156 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001157 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001158 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001159 }
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001160 if (bus_info->state.created == 0) {
1161 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001162 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001163 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001164 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001165 }
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001166 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
1167 if (!dev_info) {
1168 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001169 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001170 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001171 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001172 }
Andreea-Cristina Bernat97a84f12014-03-14 04:20:06 +02001173
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001174 INIT_LIST_HEAD(&dev_info->entry);
1175 dev_info->bus_no = bus_no;
1176 dev_info->dev_no = dev_no;
1177 dev_info->dev_inst_uuid = cmd->create_device.dev_inst_uuid;
1178 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001179 POSTCODE_SEVERITY_INFO);
1180
Benjamin Romer98d7b592014-10-23 14:30:26 -04001181 if (inmsg->hdr.flags.test_message == 1)
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001182 dev_info->chan_info.addr_type = ADDRTYPE_LOCALTEST;
Ken Cox12e364b2014-03-04 07:58:07 -06001183 else
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001184 dev_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1185 dev_info->chan_info.channel_addr = cmd->create_device.channel_addr;
1186 dev_info->chan_info.n_channel_bytes = cmd->create_device.channel_bytes;
1187 dev_info->chan_info.channel_type_uuid =
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001188 cmd->create_device.data_type_uuid;
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001189 dev_info->chan_info.intr = cmd->create_device.intr;
1190 list_add(&dev_info->entry, &dev_info_list);
1191 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001192 POSTCODE_SEVERITY_INFO);
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001193cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -06001194 /* get the bus and devNo for DiagPool channel */
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001195 if (dev_info &&
1196 is_diagpool_channel(dev_info->chan_info.channel_type_uuid)) {
1197 g_diagpool_bus_no = bus_no;
1198 g_diagpool_dev_no = dev_no;
Ken Cox12e364b2014-03-04 07:58:07 -06001199 }
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001200 device_epilog(bus_no, dev_no, segment_state_running,
Ken Cox12e364b2014-03-04 07:58:07 -06001201 CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001202 inmsg->hdr.flags.response_expected == 1,
Benjamin Romerc60c8e22015-03-16 13:58:23 -04001203 FOR_VISORBUS(dev_info->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001204}
1205
1206static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001207my_device_changestate(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001208{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001209 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romer0278a902015-03-16 13:58:24 -04001210 ulong bus_no = cmd->device_change_state.bus_no;
1211 ulong dev_no = cmd->device_change_state.dev_no;
Benjamin Romer2ea51172014-10-23 14:30:25 -04001212 struct spar_segment_state state = cmd->device_change_state.state;
Benjamin Romer0278a902015-03-16 13:58:24 -04001213 struct visorchipset_device_info *dev_info = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001214 int rc = CONTROLVM_RESP_SUCCESS;
1215
Benjamin Romer0278a902015-03-16 13:58:24 -04001216 dev_info = finddevice(&dev_info_list, bus_no, dev_no);
1217 if (!dev_info) {
1218 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001219 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001220 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
Benjamin Romer0278a902015-03-16 13:58:24 -04001221 } else if (dev_info->state.created == 0) {
1222 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
Ken Cox12e364b2014-03-04 07:58:07 -06001223 POSTCODE_SEVERITY_ERR);
Ken Cox22ad57b2014-03-19 13:06:25 -05001224 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
Ken Cox12e364b2014-03-04 07:58:07 -06001225 }
Benjamin Romer0278a902015-03-16 13:58:24 -04001226 if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info)
1227 device_epilog(bus_no, dev_no, state,
1228 CONTROLVM_DEVICE_CHANGESTATE, &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001229 inmsg->hdr.flags.response_expected == 1,
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001230 FOR_VISORBUS(
Benjamin Romer0278a902015-03-16 13:58:24 -04001231 dev_info->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001232}
1233
1234static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001235my_device_destroy(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001236{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001237 struct controlvm_message_packet *cmd = &inmsg->cmd;
Benjamin Romer61715c82015-03-16 13:58:25 -04001238 ulong bus_no = cmd->destroy_device.bus_no;
1239 ulong dev_no = cmd->destroy_device.dev_no;
1240 struct visorchipset_device_info *dev_info = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001241 int rc = CONTROLVM_RESP_SUCCESS;
1242
Benjamin Romer61715c82015-03-16 13:58:25 -04001243 dev_info = finddevice(&dev_info_list, bus_no, dev_no);
1244 if (!dev_info)
Ken Cox22ad57b2014-03-19 13:06:25 -05001245 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
Benjamin Romer61715c82015-03-16 13:58:25 -04001246 else if (dev_info->state.created == 0)
Ken Cox22ad57b2014-03-19 13:06:25 -05001247 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
Ken Cox12e364b2014-03-04 07:58:07 -06001248
Benjamin Romer61715c82015-03-16 13:58:25 -04001249 if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info)
1250 device_epilog(bus_no, dev_no, segment_state_running,
Ken Cox12e364b2014-03-04 07:58:07 -06001251 CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001252 inmsg->hdr.flags.response_expected == 1,
Benjamin Romer9b1caee2014-10-31 09:57:23 -04001253 FOR_VISORBUS(
Benjamin Romer61715c82015-03-16 13:58:25 -04001254 dev_info->chan_info.channel_type_uuid));
Ken Cox12e364b2014-03-04 07:58:07 -06001255}
1256
1257/* When provided with the physical address of the controlvm channel
1258 * (phys_addr), the offset to the payload area we need to manage
1259 * (offset), and the size of this payload area (bytes), fills in the
Frederico Cadete84b11df2015-02-18 19:53:40 +01001260 * controlvm_payload_info struct. Returns TRUE for success or FALSE
Ken Cox12e364b2014-03-04 07:58:07 -06001261 * for failure.
1262 */
1263static int
Benjamin Romer5fc02292014-07-31 12:00:51 -04001264initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes,
Frederico Cadete84b11df2015-02-18 19:53:40 +01001265 struct controlvm_payload_info *info)
Ken Cox12e364b2014-03-04 07:58:07 -06001266{
Benjamin Romerc2422332014-07-29 15:09:40 -04001267 u8 __iomem *payload = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06001268 int rc = CONTROLVM_RESP_SUCCESS;
1269
Benjamin Romer38f736e2015-03-16 13:58:13 -04001270 if (!info) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001271 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
Benjamin Romerf118a392015-03-16 13:58:26 -04001272 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001273 }
Frederico Cadete84b11df2015-02-18 19:53:40 +01001274 memset(info, 0, sizeof(struct controlvm_payload_info));
Ken Cox12e364b2014-03-04 07:58:07 -06001275 if ((offset == 0) || (bytes == 0)) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001276 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
Benjamin Romerf118a392015-03-16 13:58:26 -04001277 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001278 }
1279 payload = ioremap_cache(phys_addr + offset, bytes);
Benjamin Romer38f736e2015-03-16 13:58:13 -04001280 if (!payload) {
Ken Cox22ad57b2014-03-19 13:06:25 -05001281 rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
Benjamin Romerf118a392015-03-16 13:58:26 -04001282 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001283 }
1284
1285 info->offset = offset;
1286 info->bytes = bytes;
1287 info->ptr = payload;
Ken Cox12e364b2014-03-04 07:58:07 -06001288
Benjamin Romerf118a392015-03-16 13:58:26 -04001289cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -06001290 if (rc < 0) {
Benjamin Romerf118a392015-03-16 13:58:26 -04001291 if (payload) {
Ken Cox12e364b2014-03-04 07:58:07 -06001292 iounmap(payload);
1293 payload = NULL;
1294 }
1295 }
1296 return rc;
1297}
1298
1299static void
Frederico Cadete84b11df2015-02-18 19:53:40 +01001300destroy_controlvm_payload_info(struct controlvm_payload_info *info)
Ken Cox12e364b2014-03-04 07:58:07 -06001301{
Benjamin Romer597c3382015-03-16 13:58:27 -04001302 if (info->ptr) {
Ken Cox12e364b2014-03-04 07:58:07 -06001303 iounmap(info->ptr);
1304 info->ptr = NULL;
1305 }
Frederico Cadete84b11df2015-02-18 19:53:40 +01001306 memset(info, 0, sizeof(struct controlvm_payload_info));
Ken Cox12e364b2014-03-04 07:58:07 -06001307}
1308
1309static void
1310initialize_controlvm_payload(void)
1311{
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001312 HOSTADDRESS phys_addr = visorchannel_get_physaddr(controlvm_channel);
Benjamin Romercafefc02015-03-16 13:58:28 -04001313 u64 payload_offset = 0;
1314 u32 payload_bytes = 0;
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001315
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001316 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001317 offsetof(struct spar_controlvm_channel_protocol,
1318 request_payload_offset),
Benjamin Romercafefc02015-03-16 13:58:28 -04001319 &payload_offset, sizeof(payload_offset)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001320 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1321 POSTCODE_SEVERITY_ERR);
1322 return;
1323 }
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001324 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001325 offsetof(struct spar_controlvm_channel_protocol,
1326 request_payload_bytes),
Benjamin Romercafefc02015-03-16 13:58:28 -04001327 &payload_bytes, sizeof(payload_bytes)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001328 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1329 POSTCODE_SEVERITY_ERR);
1330 return;
1331 }
1332 initialize_controlvm_payload_info(phys_addr,
Benjamin Romercafefc02015-03-16 13:58:28 -04001333 payload_offset, payload_bytes,
Benjamin Romer84982fb2015-03-16 13:58:07 -04001334 &controlvm_payload_info);
Ken Cox12e364b2014-03-04 07:58:07 -06001335}
1336
1337/* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1338 * Returns CONTROLVM_RESP_xxx code.
1339 */
1340int
1341visorchipset_chipset_ready(void)
1342{
Benjamin Romereb34e872015-03-16 13:58:45 -04001343 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_ONLINE);
Ken Cox12e364b2014-03-04 07:58:07 -06001344 return CONTROLVM_RESP_SUCCESS;
1345}
1346EXPORT_SYMBOL_GPL(visorchipset_chipset_ready);
1347
1348int
1349visorchipset_chipset_selftest(void)
1350{
1351 char env_selftest[20];
1352 char *envp[] = { env_selftest, NULL };
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001353
Ken Cox12e364b2014-03-04 07:58:07 -06001354 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
Benjamin Romereb34e872015-03-16 13:58:45 -04001355 kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
Ken Cox12e364b2014-03-04 07:58:07 -06001356 envp);
1357 return CONTROLVM_RESP_SUCCESS;
1358}
1359EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest);
1360
1361/* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1362 * Returns CONTROLVM_RESP_xxx code.
1363 */
1364int
1365visorchipset_chipset_notready(void)
1366{
Benjamin Romereb34e872015-03-16 13:58:45 -04001367 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE);
Ken Cox12e364b2014-03-04 07:58:07 -06001368 return CONTROLVM_RESP_SUCCESS;
1369}
1370EXPORT_SYMBOL_GPL(visorchipset_chipset_notready);
1371
1372static void
Benjamin Romer77a04492015-03-16 13:58:47 -04001373chipset_ready(struct controlvm_message_header *msg_hdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001374{
1375 int rc = visorchipset_chipset_ready();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001376
Ken Cox12e364b2014-03-04 07:58:07 -06001377 if (rc != CONTROLVM_RESP_SUCCESS)
1378 rc = -rc;
Benjamin Romer77a04492015-03-16 13:58:47 -04001379 if (msg_hdr->flags.response_expected && !visorchipset_holdchipsetready)
1380 controlvm_respond(msg_hdr, rc);
1381 if (msg_hdr->flags.response_expected && visorchipset_holdchipsetready) {
Ken Cox12e364b2014-03-04 07:58:07 -06001382 /* Send CHIPSET_READY response when all modules have been loaded
1383 * and disks mounted for the partition
1384 */
Benjamin Romer77a04492015-03-16 13:58:47 -04001385 g_chipset_msg_hdr = *msg_hdr;
Ken Cox12e364b2014-03-04 07:58:07 -06001386 }
1387}
1388
1389static void
Benjamin Romer77a04492015-03-16 13:58:47 -04001390chipset_selftest(struct controlvm_message_header *msg_hdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001391{
1392 int rc = visorchipset_chipset_selftest();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001393
Ken Cox12e364b2014-03-04 07:58:07 -06001394 if (rc != CONTROLVM_RESP_SUCCESS)
1395 rc = -rc;
Benjamin Romer77a04492015-03-16 13:58:47 -04001396 if (msg_hdr->flags.response_expected)
1397 controlvm_respond(msg_hdr, rc);
Ken Cox12e364b2014-03-04 07:58:07 -06001398}
1399
1400static void
Benjamin Romer77a04492015-03-16 13:58:47 -04001401chipset_notready(struct controlvm_message_header *msg_hdr)
Ken Cox12e364b2014-03-04 07:58:07 -06001402{
1403 int rc = visorchipset_chipset_notready();
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001404
Ken Cox12e364b2014-03-04 07:58:07 -06001405 if (rc != CONTROLVM_RESP_SUCCESS)
1406 rc = -rc;
Benjamin Romer77a04492015-03-16 13:58:47 -04001407 if (msg_hdr->flags.response_expected)
1408 controlvm_respond(msg_hdr, rc);
Ken Cox12e364b2014-03-04 07:58:07 -06001409}
1410
1411/* This is your "one-stop" shop for grabbing the next message from the
1412 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1413 */
1414static BOOL
Benjamin Romer3ab47702014-10-23 14:30:31 -04001415read_controlvm_event(struct controlvm_message *msg)
Ken Cox12e364b2014-03-04 07:58:07 -06001416{
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001417 if (visorchannel_signalremove(controlvm_channel,
Ken Cox12e364b2014-03-04 07:58:07 -06001418 CONTROLVM_QUEUE_EVENT, msg)) {
1419 /* got a message */
Benjamin Romer0aca78442015-03-04 12:14:25 -05001420 if (msg->hdr.flags.test_message == 1)
Ken Cox12e364b2014-03-04 07:58:07 -06001421 return FALSE;
Benjamin Romere22a4a02014-08-18 09:34:54 -04001422 return TRUE;
Ken Cox12e364b2014-03-04 07:58:07 -06001423 }
1424 return FALSE;
1425}
1426
1427/*
1428 * The general parahotplug flow works as follows. The visorchipset
1429 * driver receives a DEVICE_CHANGESTATE message from Command
1430 * specifying a physical device to enable or disable. The CONTROLVM
1431 * message handler calls parahotplug_process_message, which then adds
1432 * the message to a global list and kicks off a udev event which
1433 * causes a user level script to enable or disable the specified
1434 * device. The udev script then writes to
1435 * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write
1436 * to get called, at which point the appropriate CONTROLVM message is
1437 * retrieved from the list and responded to.
1438 */
1439
1440#define PARAHOTPLUG_TIMEOUT_MS 2000
1441
1442/*
1443 * Generate unique int to match an outstanding CONTROLVM message with a
1444 * udev script /proc response
1445 */
1446static int
1447parahotplug_next_id(void)
1448{
1449 static atomic_t id = ATOMIC_INIT(0);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001450
Ken Cox12e364b2014-03-04 07:58:07 -06001451 return atomic_inc_return(&id);
1452}
1453
1454/*
1455 * Returns the time (in jiffies) when a CONTROLVM message on the list
1456 * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future
1457 */
1458static unsigned long
1459parahotplug_next_expiration(void)
1460{
Nicholas Mc Guire2cc1a1b2015-01-31 12:02:08 +01001461 return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS);
Ken Cox12e364b2014-03-04 07:58:07 -06001462}
1463
1464/*
1465 * Create a parahotplug_request, which is basically a wrapper for a
1466 * CONTROLVM_MESSAGE that we can stick on a list
1467 */
1468static struct parahotplug_request *
Benjamin Romer3ab47702014-10-23 14:30:31 -04001469parahotplug_request_create(struct controlvm_message *msg)
Ken Cox12e364b2014-03-04 07:58:07 -06001470{
Quentin Lambertea0dcfc2015-02-10 15:12:07 +01001471 struct parahotplug_request *req;
1472
Benjamin Romer6a55e3c2015-03-16 13:58:30 -04001473 req = kmalloc(sizeof(*req), GFP_KERNEL | __GFP_NORETRY);
Benjamin Romer38f736e2015-03-16 13:58:13 -04001474 if (!req)
Ken Cox12e364b2014-03-04 07:58:07 -06001475 return NULL;
1476
1477 req->id = parahotplug_next_id();
1478 req->expiration = parahotplug_next_expiration();
1479 req->msg = *msg;
1480
1481 return req;
1482}
1483
1484/*
1485 * Free a parahotplug_request.
1486 */
1487static void
1488parahotplug_request_destroy(struct parahotplug_request *req)
1489{
1490 kfree(req);
1491}
1492
1493/*
1494 * Cause uevent to run the user level script to do the disable/enable
1495 * specified in (the CONTROLVM message in) the specified
1496 * parahotplug_request
1497 */
1498static void
1499parahotplug_request_kickoff(struct parahotplug_request *req)
1500{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001501 struct controlvm_message_packet *cmd = &req->msg.cmd;
Ken Cox12e364b2014-03-04 07:58:07 -06001502 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
1503 env_func[40];
1504 char *envp[] = {
1505 env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
1506 };
1507
1508 sprintf(env_cmd, "SPAR_PARAHOTPLUG=1");
1509 sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id);
1510 sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001511 cmd->device_change_state.state.active);
Ken Cox12e364b2014-03-04 07:58:07 -06001512 sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001513 cmd->device_change_state.bus_no);
Ken Cox12e364b2014-03-04 07:58:07 -06001514 sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001515 cmd->device_change_state.dev_no >> 3);
Ken Cox12e364b2014-03-04 07:58:07 -06001516 sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d",
Benjamin Romer2ea51172014-10-23 14:30:25 -04001517 cmd->device_change_state.dev_no & 0x7);
Ken Cox12e364b2014-03-04 07:58:07 -06001518
Benjamin Romereb34e872015-03-16 13:58:45 -04001519 kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
Ken Cox12e364b2014-03-04 07:58:07 -06001520 envp);
1521}
1522
1523/*
1524 * Remove any request from the list that's been on there too long and
1525 * respond with an error.
1526 */
1527static void
1528parahotplug_process_list(void)
1529{
1530 struct list_head *pos = NULL;
1531 struct list_head *tmp = NULL;
1532
Benjamin Romerddf5de52015-03-16 13:58:41 -04001533 spin_lock(&parahotplug_request_list_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001534
Benjamin Romerddf5de52015-03-16 13:58:41 -04001535 list_for_each_safe(pos, tmp, &parahotplug_request_list) {
Ken Cox12e364b2014-03-04 07:58:07 -06001536 struct parahotplug_request *req =
1537 list_entry(pos, struct parahotplug_request, list);
Benjamin Romer55b33412015-03-16 13:58:29 -04001538
1539 if (!time_after_eq(jiffies, req->expiration))
1540 continue;
1541
1542 list_del(pos);
1543 if (req->msg.hdr.flags.response_expected)
1544 controlvm_respond_physdev_changestate(
1545 &req->msg.hdr,
1546 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT,
1547 req->msg.cmd.device_change_state.state);
1548 parahotplug_request_destroy(req);
Ken Cox12e364b2014-03-04 07:58:07 -06001549 }
1550
Benjamin Romerddf5de52015-03-16 13:58:41 -04001551 spin_unlock(&parahotplug_request_list_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001552}
1553
1554/*
1555 * Called from the /proc handler, which means the user script has
1556 * finished the enable/disable. Find the matching identifier, and
1557 * respond to the CONTROLVM message with success.
1558 */
1559static int
Benjamin Romerb06bdf72014-07-31 12:00:49 -04001560parahotplug_request_complete(int id, u16 active)
Ken Cox12e364b2014-03-04 07:58:07 -06001561{
1562 struct list_head *pos = NULL;
1563 struct list_head *tmp = NULL;
1564
Benjamin Romerddf5de52015-03-16 13:58:41 -04001565 spin_lock(&parahotplug_request_list_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001566
1567 /* Look for a request matching "id". */
Benjamin Romerddf5de52015-03-16 13:58:41 -04001568 list_for_each_safe(pos, tmp, &parahotplug_request_list) {
Ken Cox12e364b2014-03-04 07:58:07 -06001569 struct parahotplug_request *req =
1570 list_entry(pos, struct parahotplug_request, list);
1571 if (req->id == id) {
1572 /* Found a match. Remove it from the list and
1573 * respond.
1574 */
1575 list_del(pos);
Benjamin Romerddf5de52015-03-16 13:58:41 -04001576 spin_unlock(&parahotplug_request_list_lock);
Benjamin Romer2ea51172014-10-23 14:30:25 -04001577 req->msg.cmd.device_change_state.state.active = active;
Benjamin Romer98d7b592014-10-23 14:30:26 -04001578 if (req->msg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001579 controlvm_respond_physdev_changestate(
1580 &req->msg.hdr, CONTROLVM_RESP_SUCCESS,
Benjamin Romer2ea51172014-10-23 14:30:25 -04001581 req->msg.cmd.device_change_state.state);
Ken Cox12e364b2014-03-04 07:58:07 -06001582 parahotplug_request_destroy(req);
1583 return 0;
1584 }
1585 }
1586
Benjamin Romerddf5de52015-03-16 13:58:41 -04001587 spin_unlock(&parahotplug_request_list_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001588 return -1;
1589}
1590
1591/*
1592 * Enables or disables a PCI device by kicking off a udev script
1593 */
Ken Coxbd5b9b32014-03-13 15:39:22 -05001594static void
Benjamin Romer3ab47702014-10-23 14:30:31 -04001595parahotplug_process_message(struct controlvm_message *inmsg)
Ken Cox12e364b2014-03-04 07:58:07 -06001596{
1597 struct parahotplug_request *req;
1598
1599 req = parahotplug_request_create(inmsg);
1600
Benjamin Romer38f736e2015-03-16 13:58:13 -04001601 if (!req)
Ken Cox12e364b2014-03-04 07:58:07 -06001602 return;
Ken Cox12e364b2014-03-04 07:58:07 -06001603
Benjamin Romer2ea51172014-10-23 14:30:25 -04001604 if (inmsg->cmd.device_change_state.state.active) {
Ken Cox12e364b2014-03-04 07:58:07 -06001605 /* For enable messages, just respond with success
1606 * right away. This is a bit of a hack, but there are
1607 * issues with the early enable messages we get (with
1608 * either the udev script not detecting that the device
1609 * is up, or not getting called at all). Fortunately
1610 * the messages that get lost don't matter anyway, as
1611 * devices are automatically enabled at
1612 * initialization.
1613 */
1614 parahotplug_request_kickoff(req);
1615 controlvm_respond_physdev_changestate(&inmsg->hdr,
Benjamin Romer2ea51172014-10-23 14:30:25 -04001616 CONTROLVM_RESP_SUCCESS, inmsg->cmd.
1617 device_change_state.state);
Ken Cox12e364b2014-03-04 07:58:07 -06001618 parahotplug_request_destroy(req);
1619 } else {
1620 /* For disable messages, add the request to the
1621 * request list before kicking off the udev script. It
1622 * won't get responded to until the script has
1623 * indicated it's done.
1624 */
Benjamin Romerddf5de52015-03-16 13:58:41 -04001625 spin_lock(&parahotplug_request_list_lock);
1626 list_add_tail(&req->list, &parahotplug_request_list);
1627 spin_unlock(&parahotplug_request_list_lock);
Ken Cox12e364b2014-03-04 07:58:07 -06001628
1629 parahotplug_request_kickoff(req);
1630 }
1631}
1632
Ken Cox12e364b2014-03-04 07:58:07 -06001633/* Process a controlvm message.
1634 * Return result:
1635 * FALSE - this function will return FALSE only in the case where the
1636 * controlvm message was NOT processed, but processing must be
1637 * retried before reading the next controlvm message; a
1638 * scenario where this can occur is when we need to throttle
1639 * the allocation of memory in which to copy out controlvm
1640 * payload data
1641 * TRUE - processing of the controlvm message completed,
1642 * either successfully or with an error.
1643 */
1644static BOOL
Benjamin Romer3ab47702014-10-23 14:30:31 -04001645handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr)
Ken Cox12e364b2014-03-04 07:58:07 -06001646{
Benjamin Romer2ea51172014-10-23 14:30:25 -04001647 struct controlvm_message_packet *cmd = &inmsg.cmd;
Benjamin Romer818352a2015-03-16 13:58:31 -04001648 u64 parm_addr = 0;
1649 u32 parm_bytes = 0;
Benjamin Romer317d9612015-03-16 13:57:51 -04001650 struct parser_context *parser_ctx = NULL;
Benjamin Romer818352a2015-03-16 13:58:31 -04001651 bool local_addr = false;
Benjamin Romer3ab47702014-10-23 14:30:31 -04001652 struct controlvm_message ackmsg;
Ken Cox12e364b2014-03-04 07:58:07 -06001653
1654 /* create parsing context if necessary */
Benjamin Romer818352a2015-03-16 13:58:31 -04001655 local_addr = (inmsg.hdr.flags.test_message == 1);
Benjamin Romer0aca78442015-03-04 12:14:25 -05001656 if (channel_addr == 0)
Ken Cox12e364b2014-03-04 07:58:07 -06001657 return TRUE;
Benjamin Romer818352a2015-03-16 13:58:31 -04001658 parm_addr = channel_addr + inmsg.hdr.payload_vm_offset;
1659 parm_bytes = inmsg.hdr.payload_bytes;
Ken Cox12e364b2014-03-04 07:58:07 -06001660
1661 /* Parameter and channel addresses within test messages actually lie
1662 * within our OS-controlled memory. We need to know that, because it
1663 * makes a difference in how we compute the virtual address.
1664 */
Benjamin Romer818352a2015-03-16 13:58:31 -04001665 if (parm_addr != 0 && parm_bytes != 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001666 BOOL retry = FALSE;
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001667
Ken Cox12e364b2014-03-04 07:58:07 -06001668 parser_ctx =
Benjamin Romer818352a2015-03-16 13:58:31 -04001669 parser_init_byte_stream(parm_addr, parm_bytes,
1670 local_addr, &retry);
Benjamin Romer1b088722015-03-04 12:14:26 -05001671 if (!parser_ctx && retry)
1672 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06001673 }
1674
Benjamin Romer818352a2015-03-16 13:58:31 -04001675 if (!local_addr) {
Ken Cox12e364b2014-03-04 07:58:07 -06001676 controlvm_init_response(&ackmsg, &inmsg.hdr,
1677 CONTROLVM_RESP_SUCCESS);
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001678 if (controlvm_channel)
1679 visorchannel_signalinsert(controlvm_channel,
Benjamin Romer1b088722015-03-04 12:14:26 -05001680 CONTROLVM_QUEUE_ACK,
1681 &ackmsg);
Ken Cox12e364b2014-03-04 07:58:07 -06001682 }
Benjamin Romer98d7b592014-10-23 14:30:26 -04001683 switch (inmsg.hdr.id) {
Ken Cox12e364b2014-03-04 07:58:07 -06001684 case CONTROLVM_CHIPSET_INIT:
Ken Cox12e364b2014-03-04 07:58:07 -06001685 chipset_init(&inmsg);
1686 break;
1687 case CONTROLVM_BUS_CREATE:
Ken Cox12e364b2014-03-04 07:58:07 -06001688 bus_create(&inmsg);
1689 break;
1690 case CONTROLVM_BUS_DESTROY:
Ken Cox12e364b2014-03-04 07:58:07 -06001691 bus_destroy(&inmsg);
1692 break;
1693 case CONTROLVM_BUS_CONFIGURE:
Ken Cox12e364b2014-03-04 07:58:07 -06001694 bus_configure(&inmsg, parser_ctx);
1695 break;
1696 case CONTROLVM_DEVICE_CREATE:
Ken Cox12e364b2014-03-04 07:58:07 -06001697 my_device_create(&inmsg);
1698 break;
1699 case CONTROLVM_DEVICE_CHANGESTATE:
Benjamin Romer2ea51172014-10-23 14:30:25 -04001700 if (cmd->device_change_state.flags.phys_device) {
Ken Cox12e364b2014-03-04 07:58:07 -06001701 parahotplug_process_message(&inmsg);
1702 } else {
Ken Cox12e364b2014-03-04 07:58:07 -06001703 /* save the hdr and cmd structures for later use */
1704 /* when sending back the response to Command */
1705 my_device_changestate(&inmsg);
Benjamin Romerda021f02015-03-16 13:57:58 -04001706 g_diag_msg_hdr = inmsg.hdr;
Benjamin Romer4f44b722015-03-16 13:58:02 -04001707 g_devicechangestate_packet = inmsg.cmd;
Ken Cox12e364b2014-03-04 07:58:07 -06001708 break;
1709 }
1710 break;
1711 case CONTROLVM_DEVICE_DESTROY:
Ken Cox12e364b2014-03-04 07:58:07 -06001712 my_device_destroy(&inmsg);
1713 break;
1714 case CONTROLVM_DEVICE_CONFIGURE:
Ken Cox12e364b2014-03-04 07:58:07 -06001715 /* no op for now, just send a respond that we passed */
Benjamin Romer98d7b592014-10-23 14:30:26 -04001716 if (inmsg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001717 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1718 break;
1719 case CONTROLVM_CHIPSET_READY:
Ken Cox12e364b2014-03-04 07:58:07 -06001720 chipset_ready(&inmsg.hdr);
1721 break;
1722 case CONTROLVM_CHIPSET_SELFTEST:
Ken Cox12e364b2014-03-04 07:58:07 -06001723 chipset_selftest(&inmsg.hdr);
1724 break;
1725 case CONTROLVM_CHIPSET_STOP:
Ken Cox12e364b2014-03-04 07:58:07 -06001726 chipset_notready(&inmsg.hdr);
1727 break;
1728 default:
Benjamin Romer98d7b592014-10-23 14:30:26 -04001729 if (inmsg.hdr.flags.response_expected)
Ken Cox12e364b2014-03-04 07:58:07 -06001730 controlvm_respond(&inmsg.hdr,
Benjamin Romer818352a2015-03-16 13:58:31 -04001731 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN);
Ken Cox12e364b2014-03-04 07:58:07 -06001732 break;
1733 }
1734
Benjamin Romer38f736e2015-03-16 13:58:13 -04001735 if (parser_ctx) {
Ken Cox12e364b2014-03-04 07:58:07 -06001736 parser_done(parser_ctx);
1737 parser_ctx = NULL;
1738 }
1739 return TRUE;
1740}
1741
Vincent Bernatd746cb52014-08-01 10:29:30 +02001742static HOSTADDRESS controlvm_get_channel_address(void)
Benjamin Romer524b0b62014-07-17 12:39:57 -04001743{
Benjamin Romer5fc02292014-07-31 12:00:51 -04001744 u64 addr = 0;
Benjamin Romerb3c55b12014-07-31 12:00:50 -04001745 u32 size = 0;
Benjamin Romer524b0b62014-07-17 12:39:57 -04001746
Benjamin Romer0aca78442015-03-04 12:14:25 -05001747 if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size)))
Benjamin Romer524b0b62014-07-17 12:39:57 -04001748 return 0;
Benjamin Romer0aca78442015-03-04 12:14:25 -05001749
Benjamin Romer524b0b62014-07-17 12:39:57 -04001750 return addr;
1751}
1752
Ken Cox12e364b2014-03-04 07:58:07 -06001753static void
1754controlvm_periodic_work(struct work_struct *work)
1755{
Benjamin Romer3ab47702014-10-23 14:30:31 -04001756 struct controlvm_message inmsg;
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001757 BOOL got_command = FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06001758 BOOL handle_command_failed = FALSE;
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001759 static u64 poll_count;
Ken Cox12e364b2014-03-04 07:58:07 -06001760
1761 /* make sure visorbus server is registered for controlvm callbacks */
1762 if (visorchipset_serverregwait && !serverregistered)
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001763 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001764 /* make sure visorclientbus server is regsitered for controlvm
1765 * callbacks
1766 */
1767 if (visorchipset_clientregwait && !clientregistered)
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001768 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001769
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001770 poll_count++;
1771 if (poll_count >= 250)
Ken Cox12e364b2014-03-04 07:58:07 -06001772 ; /* keep going */
1773 else
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001774 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001775
1776 /* Check events to determine if response to CHIPSET_READY
1777 * should be sent
1778 */
Benjamin Romer0639ba62015-03-16 13:58:04 -04001779 if (visorchipset_holdchipsetready &&
1780 (g_chipset_msg_hdr.id != CONTROLVM_INVALID)) {
Ken Cox12e364b2014-03-04 07:58:07 -06001781 if (check_chipset_events() == 1) {
Benjamin Romerda021f02015-03-16 13:57:58 -04001782 controlvm_respond(&g_chipset_msg_hdr, 0);
Ken Cox12e364b2014-03-04 07:58:07 -06001783 clear_chipset_events();
Benjamin Romerda021f02015-03-16 13:57:58 -04001784 memset(&g_chipset_msg_hdr, 0,
Benjamin Romer98d7b592014-10-23 14:30:26 -04001785 sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06001786 }
1787 }
1788
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001789 while (visorchannel_signalremove(controlvm_channel,
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001790 CONTROLVM_QUEUE_RESPONSE,
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001791 &inmsg))
1792 ;
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001793 if (!got_command) {
Benjamin Romer7166ed12015-03-16 13:58:38 -04001794 if (controlvm_pending_msg_valid) {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001795 /* we throttled processing of a prior
1796 * msg, so try to process it again
1797 * rather than reading a new one
1798 */
Benjamin Romer7166ed12015-03-16 13:58:38 -04001799 inmsg = controlvm_pending_msg;
1800 controlvm_pending_msg_valid = FALSE;
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001801 got_command = true;
Benjamin Romer75c1f8b2015-03-16 13:58:19 -04001802 } else {
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001803 got_command = read_controlvm_event(&inmsg);
Benjamin Romer75c1f8b2015-03-16 13:58:19 -04001804 }
Ken Cox12e364b2014-03-04 07:58:07 -06001805 }
1806
1807 handle_command_failed = FALSE;
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001808 while (got_command && (!handle_command_failed)) {
Benjamin Romerb53e0e92015-03-16 13:57:56 -04001809 most_recent_message_jiffies = jiffies;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001810 if (handle_command(inmsg,
1811 visorchannel_get_physaddr
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001812 (controlvm_channel)))
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001813 got_command = read_controlvm_event(&inmsg);
Benjamin Romer8a1182e2014-07-17 12:39:58 -04001814 else {
1815 /* this is a scenario where throttling
1816 * is required, but probably NOT an
1817 * error...; we stash the current
1818 * controlvm msg so we will attempt to
1819 * reprocess it on our next loop
1820 */
1821 handle_command_failed = TRUE;
Benjamin Romer7166ed12015-03-16 13:58:38 -04001822 controlvm_pending_msg = inmsg;
1823 controlvm_pending_msg_valid = TRUE;
Ken Cox12e364b2014-03-04 07:58:07 -06001824 }
1825 }
1826
1827 /* parahotplug_worker */
1828 parahotplug_process_list();
1829
Benjamin Romer1c1ed292015-03-16 13:58:32 -04001830cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -06001831
1832 if (time_after(jiffies,
Benjamin Romerb53e0e92015-03-16 13:57:56 -04001833 most_recent_message_jiffies + (HZ * MIN_IDLE_SECONDS))) {
Ken Cox12e364b2014-03-04 07:58:07 -06001834 /* it's been longer than MIN_IDLE_SECONDS since we
1835 * processed our last controlvm message; slow down the
1836 * polling
1837 */
Benjamin Romer911e2132015-03-16 13:57:47 -04001838 if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_SLOW)
1839 poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
Ken Cox12e364b2014-03-04 07:58:07 -06001840 } else {
Benjamin Romer911e2132015-03-16 13:57:47 -04001841 if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_FAST)
1842 poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
Ken Cox12e364b2014-03-04 07:58:07 -06001843 }
1844
Benjamin Romer9232d2d2015-03-16 13:57:57 -04001845 queue_delayed_work(periodic_controlvm_workqueue,
1846 &periodic_controlvm_work, poll_jiffies);
Ken Cox12e364b2014-03-04 07:58:07 -06001847}
1848
1849static void
1850setup_crash_devices_work_queue(struct work_struct *work)
1851{
Benjamin Romere6bdb902015-03-16 13:58:33 -04001852 struct controlvm_message local_crash_bus_msg;
1853 struct controlvm_message local_crash_dev_msg;
Benjamin Romer3ab47702014-10-23 14:30:31 -04001854 struct controlvm_message msg;
Benjamin Romere6bdb902015-03-16 13:58:33 -04001855 u32 local_crash_msg_offset;
1856 u16 local_crash_msg_count;
Ken Cox12e364b2014-03-04 07:58:07 -06001857
1858 /* make sure visorbus server is registered for controlvm callbacks */
1859 if (visorchipset_serverregwait && !serverregistered)
Benjamin Romere6bdb902015-03-16 13:58:33 -04001860 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001861
1862 /* make sure visorclientbus server is regsitered for controlvm
1863 * callbacks
1864 */
1865 if (visorchipset_clientregwait && !clientregistered)
Benjamin Romere6bdb902015-03-16 13:58:33 -04001866 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06001867
1868 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1869
1870 /* send init chipset msg */
Benjamin Romer98d7b592014-10-23 14:30:26 -04001871 msg.hdr.id = CONTROLVM_CHIPSET_INIT;
Benjamin Romer2ea51172014-10-23 14:30:25 -04001872 msg.cmd.init_chipset.bus_count = 23;
1873 msg.cmd.init_chipset.switch_count = 0;
Ken Cox12e364b2014-03-04 07:58:07 -06001874
1875 chipset_init(&msg);
1876
Ken Cox12e364b2014-03-04 07:58:07 -06001877 /* get saved message count */
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001878 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001879 offsetof(struct spar_controlvm_channel_protocol,
1880 saved_crash_message_count),
Benjamin Romere6bdb902015-03-16 13:58:33 -04001881 &local_crash_msg_count, sizeof(u16)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001882 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1883 POSTCODE_SEVERITY_ERR);
1884 return;
1885 }
1886
Benjamin Romere6bdb902015-03-16 13:58:33 -04001887 if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
Ken Cox12e364b2014-03-04 07:58:07 -06001888 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
Benjamin Romere6bdb902015-03-16 13:58:33 -04001889 local_crash_msg_count,
Ken Cox12e364b2014-03-04 07:58:07 -06001890 POSTCODE_SEVERITY_ERR);
1891 return;
1892 }
1893
1894 /* get saved crash message offset */
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001895 if (visorchannel_read(controlvm_channel,
Benjamin Romerd19642f2014-10-23 14:30:34 -04001896 offsetof(struct spar_controlvm_channel_protocol,
1897 saved_crash_message_offset),
Benjamin Romere6bdb902015-03-16 13:58:33 -04001898 &local_crash_msg_offset, sizeof(u32)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001899 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1900 POSTCODE_SEVERITY_ERR);
1901 return;
1902 }
1903
1904 /* read create device message for storage bus offset */
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001905 if (visorchannel_read(controlvm_channel,
Benjamin Romere6bdb902015-03-16 13:58:33 -04001906 local_crash_msg_offset,
1907 &local_crash_bus_msg,
Benjamin Romer3ab47702014-10-23 14:30:31 -04001908 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001909 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC,
1910 POSTCODE_SEVERITY_ERR);
1911 return;
1912 }
1913
1914 /* read create device message for storage device */
Benjamin Romerc3d9a222015-03-16 13:58:05 -04001915 if (visorchannel_read(controlvm_channel,
Benjamin Romere6bdb902015-03-16 13:58:33 -04001916 local_crash_msg_offset +
Benjamin Romer3ab47702014-10-23 14:30:31 -04001917 sizeof(struct controlvm_message),
Benjamin Romere6bdb902015-03-16 13:58:33 -04001918 &local_crash_dev_msg,
Benjamin Romer3ab47702014-10-23 14:30:31 -04001919 sizeof(struct controlvm_message)) < 0) {
Ken Cox12e364b2014-03-04 07:58:07 -06001920 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC,
1921 POSTCODE_SEVERITY_ERR);
1922 return;
1923 }
1924
1925 /* reuse IOVM create bus message */
Benjamin Romere6bdb902015-03-16 13:58:33 -04001926 if (local_crash_bus_msg.cmd.create_bus.channel_addr != 0) {
1927 bus_create(&local_crash_bus_msg);
Benjamin Romer75c1f8b2015-03-16 13:58:19 -04001928 } else {
Ken Cox12e364b2014-03-04 07:58:07 -06001929 POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC,
1930 POSTCODE_SEVERITY_ERR);
1931 return;
1932 }
1933
1934 /* reuse create device message for storage device */
Benjamin Romere6bdb902015-03-16 13:58:33 -04001935 if (local_crash_dev_msg.cmd.create_device.channel_addr != 0) {
1936 my_device_create(&local_crash_dev_msg);
Benjamin Romer75c1f8b2015-03-16 13:58:19 -04001937 } else {
Ken Cox12e364b2014-03-04 07:58:07 -06001938 POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC,
1939 POSTCODE_SEVERITY_ERR);
1940 return;
1941 }
Ken Cox12e364b2014-03-04 07:58:07 -06001942 POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC, POSTCODE_SEVERITY_INFO);
1943 return;
1944
Benjamin Romere6bdb902015-03-16 13:58:33 -04001945cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -06001946
Benjamin Romer911e2132015-03-16 13:57:47 -04001947 poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
Ken Cox12e364b2014-03-04 07:58:07 -06001948
Benjamin Romer9232d2d2015-03-16 13:57:57 -04001949 queue_delayed_work(periodic_controlvm_workqueue,
1950 &periodic_controlvm_work, poll_jiffies);
Ken Cox12e364b2014-03-04 07:58:07 -06001951}
1952
1953static void
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001954bus_create_response(ulong bus_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001955{
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001956 bus_responder(CONTROLVM_BUS_CREATE, bus_no, response);
Ken Cox12e364b2014-03-04 07:58:07 -06001957}
1958
1959static void
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001960bus_destroy_response(ulong bus_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001961{
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001962 bus_responder(CONTROLVM_BUS_DESTROY, bus_no, response);
Ken Cox12e364b2014-03-04 07:58:07 -06001963}
1964
1965static void
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001966device_create_response(ulong bus_no, ulong dev_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001967{
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001968 device_responder(CONTROLVM_DEVICE_CREATE, bus_no, dev_no, response);
Ken Cox12e364b2014-03-04 07:58:07 -06001969}
1970
1971static void
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001972device_destroy_response(ulong bus_no, ulong dev_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001973{
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001974 device_responder(CONTROLVM_DEVICE_DESTROY, bus_no, dev_no, response);
Ken Cox12e364b2014-03-04 07:58:07 -06001975}
1976
1977void
Benjamin Romer8420f412014-10-31 09:57:36 -04001978visorchipset_device_pause_response(ulong bus_no, ulong dev_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001979{
Ken Cox12e364b2014-03-04 07:58:07 -06001980 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
Benjamin Romer8420f412014-10-31 09:57:36 -04001981 bus_no, dev_no, response,
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001982 segment_state_standby);
Ken Cox12e364b2014-03-04 07:58:07 -06001983}
Ken Cox927c7922014-03-05 14:52:25 -06001984EXPORT_SYMBOL_GPL(visorchipset_device_pause_response);
Ken Cox12e364b2014-03-04 07:58:07 -06001985
1986static void
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001987device_resume_response(ulong bus_no, ulong dev_no, int response)
Ken Cox12e364b2014-03-04 07:58:07 -06001988{
1989 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
Benjamin Romer8e3fedd2015-03-16 13:58:43 -04001990 bus_no, dev_no, response,
Benjamin Romerbd0d2dc2014-10-23 14:30:13 -04001991 segment_state_running);
Ken Cox12e364b2014-03-04 07:58:07 -06001992}
1993
1994BOOL
Benjamin Romer77db7122014-10-31 09:57:37 -04001995visorchipset_get_bus_info(ulong bus_no, struct visorchipset_bus_info *bus_info)
Ken Cox12e364b2014-03-04 07:58:07 -06001996{
Benjamin Romer1390b882015-03-16 13:58:03 -04001997 void *p = findbus(&bus_info_list, bus_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04001998
Benjamin Romer0aca78442015-03-04 12:14:25 -05001999 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002000 return FALSE;
Benjamin Romer77db7122014-10-31 09:57:37 -04002001 memcpy(bus_info, p, sizeof(struct visorchipset_bus_info));
Ken Cox12e364b2014-03-04 07:58:07 -06002002 return TRUE;
2003}
2004EXPORT_SYMBOL_GPL(visorchipset_get_bus_info);
2005
2006BOOL
Benjamin Romer58dd8f2d2014-10-31 09:57:40 -04002007visorchipset_set_bus_context(ulong bus_no, void *context)
Ken Cox12e364b2014-03-04 07:58:07 -06002008{
Benjamin Romer1390b882015-03-16 13:58:03 -04002009 struct visorchipset_bus_info *p = findbus(&bus_info_list, bus_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002010
Benjamin Romer0aca78442015-03-04 12:14:25 -05002011 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002012 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06002013 p->bus_driver_context = context;
2014 return TRUE;
2015}
2016EXPORT_SYMBOL_GPL(visorchipset_set_bus_context);
2017
2018BOOL
Benjamin Romerb486df12014-10-31 09:57:38 -04002019visorchipset_get_device_info(ulong bus_no, ulong dev_no,
2020 struct visorchipset_device_info *dev_info)
Ken Cox12e364b2014-03-04 07:58:07 -06002021{
Benjamin Romer1390b882015-03-16 13:58:03 -04002022 void *p = finddevice(&dev_info_list, bus_no, dev_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002023
Benjamin Romer0aca78442015-03-04 12:14:25 -05002024 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002025 return FALSE;
Benjamin Romerb486df12014-10-31 09:57:38 -04002026 memcpy(dev_info, p, sizeof(struct visorchipset_device_info));
Ken Cox12e364b2014-03-04 07:58:07 -06002027 return TRUE;
2028}
2029EXPORT_SYMBOL_GPL(visorchipset_get_device_info);
2030
2031BOOL
Benjamin Romercf0bd0b2014-10-31 09:57:41 -04002032visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context)
Ken Cox12e364b2014-03-04 07:58:07 -06002033{
Benjamin Romer246e0cd2014-10-31 09:57:24 -04002034 struct visorchipset_device_info *p =
Benjamin Romer1390b882015-03-16 13:58:03 -04002035 finddevice(&dev_info_list, bus_no, dev_no);
Benjamin Romer26eb2c02014-08-18 09:34:53 -04002036
Benjamin Romer0aca78442015-03-04 12:14:25 -05002037 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002038 return FALSE;
Ken Cox12e364b2014-03-04 07:58:07 -06002039 p->bus_driver_context = context;
2040 return TRUE;
2041}
2042EXPORT_SYMBOL_GPL(visorchipset_set_device_context);
2043
2044/* Generic wrapper function for allocating memory from a kmem_cache pool.
2045 */
2046void *
2047visorchipset_cache_alloc(struct kmem_cache *pool, BOOL ok_to_block,
2048 char *fn, int ln)
2049{
2050 gfp_t gfp;
2051 void *p;
2052
2053 if (ok_to_block)
2054 gfp = GFP_KERNEL;
2055 else
2056 gfp = GFP_ATOMIC;
2057 /* __GFP_NORETRY means "ok to fail", meaning
2058 * kmem_cache_alloc() can return NULL, implying the caller CAN
2059 * cope with failure. If you do NOT specify __GFP_NORETRY,
2060 * Linux will go to extreme measures to get memory for you
2061 * (like, invoke oom killer), which will probably cripple the
2062 * system.
2063 */
2064 gfp |= __GFP_NORETRY;
2065 p = kmem_cache_alloc(pool, gfp);
Benjamin Romer0aca78442015-03-04 12:14:25 -05002066 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002067 return NULL;
Benjamin Romer0aca78442015-03-04 12:14:25 -05002068
Benjamin Romer712f42c2015-03-16 13:58:40 -04002069 atomic_inc(&visorchipset_cache_buffers_in_use);
Ken Cox12e364b2014-03-04 07:58:07 -06002070 return p;
2071}
2072
2073/* Generic wrapper function for freeing memory from a kmem_cache pool.
2074 */
2075void
2076visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln)
2077{
Benjamin Romer0aca78442015-03-04 12:14:25 -05002078 if (!p)
Ken Cox12e364b2014-03-04 07:58:07 -06002079 return;
Benjamin Romer0aca78442015-03-04 12:14:25 -05002080
Benjamin Romer712f42c2015-03-16 13:58:40 -04002081 atomic_dec(&visorchipset_cache_buffers_in_use);
Ken Cox12e364b2014-03-04 07:58:07 -06002082 kmem_cache_free(pool, p);
2083}
2084
Benjamin Romer18b87ed2014-07-24 14:08:43 -04002085static ssize_t chipsetready_store(struct device *dev,
2086 struct device_attribute *attr, const char *buf, size_t count)
Ken Cox12e364b2014-03-04 07:58:07 -06002087{
Benjamin Romer18b87ed2014-07-24 14:08:43 -04002088 char msgtype[64];
Ken Cox12e364b2014-03-04 07:58:07 -06002089
Benjamin Romer66e24b72014-07-25 13:55:10 -04002090 if (sscanf(buf, "%63s", msgtype) != 1)
Ken Cox12e364b2014-03-04 07:58:07 -06002091 return -EINVAL;
Benjamin Romer66e24b72014-07-25 13:55:10 -04002092
2093 if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) {
2094 chipset_events[0] = 1;
2095 return count;
2096 } else if (strcmp(msgtype, "MODULES_LOADED") == 0) {
2097 chipset_events[1] = 1;
2098 return count;
Benjamin Romere22a4a02014-08-18 09:34:54 -04002099 }
2100 return -EINVAL;
Ken Cox12e364b2014-03-04 07:58:07 -06002101}
2102
Benjamin Romere56fa7c2014-07-29 11:11:21 -04002103/* The parahotplug/devicedisabled interface gets called by our support script
2104 * when an SR-IOV device has been shut down. The ID is passed to the script
2105 * and then passed back when the device has been removed.
2106 */
2107static ssize_t devicedisabled_store(struct device *dev,
2108 struct device_attribute *attr, const char *buf, size_t count)
2109{
2110 uint id;
2111
2112 if (kstrtouint(buf, 10, &id) != 0)
2113 return -EINVAL;
2114
2115 parahotplug_request_complete(id, 0);
2116 return count;
2117}
2118
2119/* The parahotplug/deviceenabled interface gets called by our support script
2120 * when an SR-IOV device has been recovered. The ID is passed to the script
2121 * and then passed back when the device has been brought back up.
2122 */
2123static ssize_t deviceenabled_store(struct device *dev,
2124 struct device_attribute *attr, const char *buf, size_t count)
2125{
2126 uint id;
2127
2128 if (kstrtouint(buf, 10, &id) != 0)
2129 return -EINVAL;
2130
2131 parahotplug_request_complete(id, 1);
2132 return count;
2133}
2134
Ken Cox12e364b2014-03-04 07:58:07 -06002135static int __init
2136visorchipset_init(void)
2137{
2138 int rc = 0, x = 0;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002139 HOSTADDRESS addr;
Ken Cox12e364b2014-03-04 07:58:07 -06002140
Ken Coxfcd0157e2014-04-28 12:23:13 -05002141 if (!unisys_spar_platform)
2142 return -ENODEV;
2143
Benjamin Romer6fe345a2015-03-16 13:58:42 -04002144 memset(&busdev_server_notifiers, 0, sizeof(busdev_server_notifiers));
2145 memset(&busdev_client_notifiers, 0, sizeof(busdev_client_notifiers));
Benjamin Romer84982fb2015-03-16 13:58:07 -04002146 memset(&controlvm_payload_info, 0, sizeof(controlvm_payload_info));
Benjamin Romerea33b4ee52015-03-16 13:58:08 -04002147 memset(&livedump_info, 0, sizeof(livedump_info));
2148 atomic_set(&livedump_info.buffers_in_use, 0);
Ken Cox12e364b2014-03-04 07:58:07 -06002149
Ken Cox9f8d0e82014-03-19 13:06:19 -05002150 if (visorchipset_testvnic) {
Ken Cox9f8d0e82014-03-19 13:06:19 -05002151 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, x, DIAG_SEVERITY_ERR);
2152 rc = x;
Benjamin Romera6a39892015-03-16 13:58:34 -04002153 goto cleanup;
Ken Cox9f8d0e82014-03-19 13:06:19 -05002154 }
Ken Cox12e364b2014-03-04 07:58:07 -06002155
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002156 addr = controlvm_get_channel_address();
2157 if (addr != 0) {
Benjamin Romerc3d9a222015-03-16 13:58:05 -04002158 controlvm_channel =
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002159 visorchannel_create_with_lock
2160 (addr,
Benjamin Romerd19642f2014-10-23 14:30:34 -04002161 sizeof(struct spar_controlvm_channel_protocol),
Benjamin Romer5fbaa4b2014-10-23 14:30:14 -04002162 spar_controlvm_channel_protocol_uuid);
Benjamin Romer93a84562014-10-23 14:30:05 -04002163 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
Benjamin Romerc3d9a222015-03-16 13:58:05 -04002164 visorchannel_get_header(controlvm_channel))) {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002165 initialize_controlvm_payload();
2166 } else {
Benjamin Romerc3d9a222015-03-16 13:58:05 -04002167 visorchannel_destroy(controlvm_channel);
2168 controlvm_channel = NULL;
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002169 return -ENODEV;
2170 }
2171 } else {
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002172 return -ENODEV;
2173 }
2174
Benjamin Romer5aa8ae52015-03-16 13:58:44 -04002175 major_dev = MKDEV(visorchipset_major, 0);
2176 rc = visorchipset_file_init(major_dev, &controlvm_channel);
Ken Cox4cb005a2014-03-19 13:06:20 -05002177 if (rc < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002178 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
Benjamin Romera6a39892015-03-16 13:58:34 -04002179 goto cleanup;
Ken Cox4cb005a2014-03-19 13:06:20 -05002180 }
Ken Cox9f8d0e82014-03-19 13:06:19 -05002181
Benjamin Romerda021f02015-03-16 13:57:58 -04002182 memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002183
Benjamin Romerda021f02015-03-16 13:57:58 -04002184 memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002185
Benjamin Romerda021f02015-03-16 13:57:58 -04002186 memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002187
Benjamin Romer1eee0012015-03-16 13:58:39 -04002188 putfile_buffer_list_pool =
2189 kmem_cache_create(putfile_buffer_list_pool_name,
Ken Cox12e364b2014-03-04 07:58:07 -06002190 sizeof(struct putfile_buffer_entry),
2191 0, SLAB_HWCACHE_ALIGN, NULL);
Benjamin Romer1eee0012015-03-16 13:58:39 -04002192 if (!putfile_buffer_list_pool) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002193 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
2194 rc = -1;
Benjamin Romera6a39892015-03-16 13:58:34 -04002195 goto cleanup;
Ken Cox12e364b2014-03-04 07:58:07 -06002196 }
Benjamin Romer2098dbd2015-03-04 12:14:22 -05002197 if (!visorchipset_disable_controlvm) {
Ken Cox12e364b2014-03-04 07:58:07 -06002198 /* if booting in a crash kernel */
2199 if (visorchipset_crash_kernel)
Benjamin Romer9232d2d2015-03-16 13:57:57 -04002200 INIT_DELAYED_WORK(&periodic_controlvm_work,
Ken Cox12e364b2014-03-04 07:58:07 -06002201 setup_crash_devices_work_queue);
2202 else
Benjamin Romer9232d2d2015-03-16 13:57:57 -04002203 INIT_DELAYED_WORK(&periodic_controlvm_work,
Ken Cox12e364b2014-03-04 07:58:07 -06002204 controlvm_periodic_work);
Benjamin Romer9232d2d2015-03-16 13:57:57 -04002205 periodic_controlvm_workqueue =
Ken Cox12e364b2014-03-04 07:58:07 -06002206 create_singlethread_workqueue("visorchipset_controlvm");
2207
Benjamin Romer38f736e2015-03-16 13:58:13 -04002208 if (!periodic_controlvm_workqueue) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002209 POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC,
2210 DIAG_SEVERITY_ERR);
2211 rc = -ENOMEM;
Benjamin Romera6a39892015-03-16 13:58:34 -04002212 goto cleanup;
Ken Cox4cb005a2014-03-19 13:06:20 -05002213 }
Benjamin Romerb53e0e92015-03-16 13:57:56 -04002214 most_recent_message_jiffies = jiffies;
Benjamin Romer911e2132015-03-16 13:57:47 -04002215 poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
Benjamin Romer9232d2d2015-03-16 13:57:57 -04002216 rc = queue_delayed_work(periodic_controlvm_workqueue,
2217 &periodic_controlvm_work, poll_jiffies);
Ken Cox4cb005a2014-03-19 13:06:20 -05002218 if (rc < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002219 POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC,
2220 DIAG_SEVERITY_ERR);
Benjamin Romera6a39892015-03-16 13:58:34 -04002221 goto cleanup;
Ken Cox4cb005a2014-03-19 13:06:20 -05002222 }
Ken Cox12e364b2014-03-04 07:58:07 -06002223 }
2224
Benjamin Romereb34e872015-03-16 13:58:45 -04002225 visorchipset_platform_device.dev.devt = major_dev;
2226 if (platform_device_register(&visorchipset_platform_device) < 0) {
Ken Cox4cb005a2014-03-19 13:06:20 -05002227 POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR);
2228 rc = -1;
Benjamin Romera6a39892015-03-16 13:58:34 -04002229 goto cleanup;
Ken Cox4cb005a2014-03-19 13:06:20 -05002230 }
Ken Cox12e364b2014-03-04 07:58:07 -06002231 POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC, POSTCODE_SEVERITY_INFO);
Ken Cox22ad57b2014-03-19 13:06:25 -05002232 rc = 0;
Benjamin Romera6a39892015-03-16 13:58:34 -04002233cleanup:
Ken Cox12e364b2014-03-04 07:58:07 -06002234 if (rc) {
Ken Cox12e364b2014-03-04 07:58:07 -06002235 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
2236 POSTCODE_SEVERITY_ERR);
2237 }
2238 return rc;
2239}
2240
2241static void
2242visorchipset_exit(void)
2243{
Ken Cox12e364b2014-03-04 07:58:07 -06002244 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
2245
2246 if (visorchipset_disable_controlvm) {
2247 ;
2248 } else {
Benjamin Romer9232d2d2015-03-16 13:57:57 -04002249 cancel_delayed_work(&periodic_controlvm_work);
2250 flush_workqueue(periodic_controlvm_workqueue);
2251 destroy_workqueue(periodic_controlvm_workqueue);
2252 periodic_controlvm_workqueue = NULL;
Benjamin Romer84982fb2015-03-16 13:58:07 -04002253 destroy_controlvm_payload_info(&controlvm_payload_info);
Ken Cox12e364b2014-03-04 07:58:07 -06002254 }
Benjamin Romer1eee0012015-03-16 13:58:39 -04002255 if (putfile_buffer_list_pool) {
2256 kmem_cache_destroy(putfile_buffer_list_pool);
2257 putfile_buffer_list_pool = NULL;
Ken Cox12e364b2014-03-04 07:58:07 -06002258 }
Benjamin Romer17833192014-07-15 13:30:41 -04002259
Ken Cox12e364b2014-03-04 07:58:07 -06002260 cleanup_controlvm_structures();
2261
Benjamin Romerda021f02015-03-16 13:57:58 -04002262 memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002263
Benjamin Romerda021f02015-03-16 13:57:58 -04002264 memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002265
Benjamin Romerda021f02015-03-16 13:57:58 -04002266 memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header));
Ken Cox12e364b2014-03-04 07:58:07 -06002267
Benjamin Romerc3d9a222015-03-16 13:58:05 -04002268 visorchannel_destroy(controlvm_channel);
Benjamin Romer8a1182e2014-07-17 12:39:58 -04002269
Ken Cox12e364b2014-03-04 07:58:07 -06002270 visorchipset_file_cleanup();
2271 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
Ken Cox12e364b2014-03-04 07:58:07 -06002272}
2273
2274module_param_named(testvnic, visorchipset_testvnic, int, S_IRUGO);
2275MODULE_PARM_DESC(visorchipset_testvnic, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet");
2276int visorchipset_testvnic = 0;
2277
2278module_param_named(testvnicclient, visorchipset_testvnicclient, int, S_IRUGO);
2279MODULE_PARM_DESC(visorchipset_testvnicclient, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest");
2280int visorchipset_testvnicclient = 0;
2281
2282module_param_named(testmsg, visorchipset_testmsg, int, S_IRUGO);
2283MODULE_PARM_DESC(visorchipset_testmsg,
2284 "1 to manufacture the chipset, bus, and switch messages");
2285int visorchipset_testmsg = 0;
2286
2287module_param_named(major, visorchipset_major, int, S_IRUGO);
2288MODULE_PARM_DESC(visorchipset_major, "major device number to use for the device node");
2289int visorchipset_major = 0;
2290
2291module_param_named(serverregwait, visorchipset_serverregwait, int, S_IRUGO);
2292MODULE_PARM_DESC(visorchipset_serverreqwait,
2293 "1 to have the module wait for the visor bus to register");
2294int visorchipset_serverregwait = 0; /* default is off */
2295module_param_named(clientregwait, visorchipset_clientregwait, int, S_IRUGO);
2296MODULE_PARM_DESC(visorchipset_clientregwait, "1 to have the module wait for the visorclientbus to register");
2297int visorchipset_clientregwait = 1; /* default is on */
2298module_param_named(testteardown, visorchipset_testteardown, int, S_IRUGO);
2299MODULE_PARM_DESC(visorchipset_testteardown,
2300 "1 to test teardown of the chipset, bus, and switch");
2301int visorchipset_testteardown = 0; /* default is off */
2302module_param_named(disable_controlvm, visorchipset_disable_controlvm, int,
2303 S_IRUGO);
2304MODULE_PARM_DESC(visorchipset_disable_controlvm,
2305 "1 to disable polling of controlVm channel");
2306int visorchipset_disable_controlvm = 0; /* default is off */
2307module_param_named(crash_kernel, visorchipset_crash_kernel, int, S_IRUGO);
2308MODULE_PARM_DESC(visorchipset_crash_kernel,
2309 "1 means we are running in crash kernel");
2310int visorchipset_crash_kernel = 0; /* default is running in non-crash kernel */
2311module_param_named(holdchipsetready, visorchipset_holdchipsetready,
2312 int, S_IRUGO);
2313MODULE_PARM_DESC(visorchipset_holdchipsetready,
2314 "1 to hold response to CHIPSET_READY");
2315int visorchipset_holdchipsetready = 0; /* default is to send CHIPSET_READY
2316 * response immediately */
2317module_init(visorchipset_init);
2318module_exit(visorchipset_exit);
2319
2320MODULE_AUTHOR("Unisys");
2321MODULE_LICENSE("GPL");
2322MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver "
2323 VERSION);
2324MODULE_VERSION(VERSION);