2014-03-04 13:58:07 +00:00
|
|
|
/* visorchipset_main.c
|
|
|
|
*
|
2015-07-16 16:40:48 +00:00
|
|
|
* Copyright (C) 2010 - 2015 UNISYS CORPORATION
|
2014-03-04 13:58:07 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2015-07-16 16:40:48 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2014-03-04 13:58:07 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2015-05-05 22:37:02 +00:00
|
|
|
#include <linux/acpi.h>
|
2015-05-05 22:36:14 +00:00
|
|
|
#include <linux/ctype.h>
|
2015-05-05 22:36:13 +00:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2014-03-04 13:58:07 +00:00
|
|
|
#include <linux/nls.h>
|
|
|
|
#include <linux/netdevice.h>
|
2014-05-06 13:58:23 +00:00
|
|
|
#include <linux/uuid.h>
|
2015-04-06 14:27:40 +00:00
|
|
|
#include <linux/crash_dump.h>
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-05-05 22:37:02 +00:00
|
|
|
#include "visorbus.h"
|
|
|
|
#include "visorbus_private.h"
|
2015-05-13 17:22:10 +00:00
|
|
|
#include "vmcallinterface.h"
|
2015-05-05 22:37:02 +00:00
|
|
|
|
2016-12-01 06:31:10 +00:00
|
|
|
#define CURRENT_FILE_PC VISOR_BUS_PC_visorchipset_c
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2017-03-17 15:27:20 +00:00
|
|
|
#define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1
|
2014-03-04 13:58:07 +00:00
|
|
|
#define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100
|
|
|
|
|
2015-12-09 15:27:05 +00:00
|
|
|
#define MAX_CONTROLVM_PAYLOAD_BYTES (1024 * 128)
|
2015-05-05 22:36:16 +00:00
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
#define UNISYS_SPAR_LEAF_ID 0x40000000
|
|
|
|
|
|
|
|
/* The s-Par leaf ID returns "UnisysSpar64" encoded across ebx, ecx, edx */
|
|
|
|
#define UNISYS_SPAR_ID_EBX 0x73696e55
|
|
|
|
#define UNISYS_SPAR_ID_ECX 0x70537379
|
|
|
|
#define UNISYS_SPAR_ID_EDX 0x34367261
|
|
|
|
|
2016-06-11 01:48:18 +00:00
|
|
|
/*
|
|
|
|
* When the controlvm channel is idle for at least MIN_IDLE_SECONDS,
|
|
|
|
* we switch to slow polling mode. As soon as we get a controlvm
|
|
|
|
* message, we switch back to fast polling mode.
|
|
|
|
*/
|
2014-03-04 13:58:07 +00:00
|
|
|
#define MIN_IDLE_SECONDS 10
|
|
|
|
|
2015-05-05 22:36:14 +00:00
|
|
|
struct parser_context {
|
|
|
|
unsigned long allocbytes;
|
|
|
|
unsigned long param_bytes;
|
|
|
|
u8 *curr;
|
|
|
|
unsigned long bytes_remaining;
|
|
|
|
bool byte_stream;
|
|
|
|
char data[0];
|
|
|
|
};
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
struct visorchipset_device {
|
|
|
|
struct acpi_device *acpi_device;
|
|
|
|
unsigned long poll_jiffies;
|
|
|
|
/* when we got our last controlvm message */
|
|
|
|
unsigned long most_recent_message_jiffies;
|
|
|
|
struct delayed_work periodic_controlvm_work;
|
|
|
|
struct visorchannel *controlvm_channel;
|
|
|
|
unsigned long controlvm_payload_bytes_buffered;
|
|
|
|
/*
|
|
|
|
* The following variables are used to handle the scenario where we are
|
|
|
|
* unable to offload the payload from a controlvm message due to memory
|
|
|
|
* requirements. In this scenario, we simply stash the controlvm
|
|
|
|
* message, then attempt to process it again the next time
|
|
|
|
* controlvm_periodic_work() runs.
|
|
|
|
*/
|
|
|
|
struct controlvm_message controlvm_pending_msg;
|
|
|
|
bool controlvm_pending_msg_valid;
|
|
|
|
};
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
static struct visorchipset_device *chipset_dev;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
struct parahotplug_request {
|
|
|
|
struct list_head list;
|
|
|
|
int id;
|
|
|
|
unsigned long expiration;
|
2014-10-23 18:30:31 +00:00
|
|
|
struct controlvm_message msg;
|
2014-03-04 13:58:07 +00:00
|
|
|
};
|
|
|
|
|
2014-07-22 13:56:25 +00:00
|
|
|
/* prototypes for attributes */
|
|
|
|
static ssize_t toolaction_show(struct device *dev,
|
2016-09-19 21:09:29 +00:00
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
u8 tool_action = 0;
|
2017-03-28 13:34:23 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = visorchannel_read(chipset_dev->controlvm_channel,
|
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
tool_action),
|
|
|
|
&tool_action, sizeof(u8));
|
|
|
|
if (err)
|
|
|
|
return err;
|
2016-09-19 21:09:29 +00:00
|
|
|
|
2017-01-03 21:01:15 +00:00
|
|
|
return sprintf(buf, "%u\n", tool_action);
|
2016-09-19 21:09:29 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:56:25 +00:00
|
|
|
static ssize_t toolaction_store(struct device *dev,
|
2015-03-16 17:58:52 +00:00
|
|
|
struct device_attribute *attr,
|
2016-09-19 21:09:29 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u8 tool_action;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (kstrtou8(buf, 10, &tool_action))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = visorchannel_write
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:29 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
tool_action),
|
|
|
|
&tool_action, sizeof(u8));
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return count;
|
|
|
|
}
|
2014-07-22 13:56:25 +00:00
|
|
|
static DEVICE_ATTR_RW(toolaction);
|
|
|
|
|
2014-07-22 13:56:26 +00:00
|
|
|
static ssize_t boottotool_show(struct device *dev,
|
2016-09-19 21:09:30 +00:00
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct efi_spar_indication efi_spar_indication;
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
visorchannel_read(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:30 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
efi_spar_ind), &efi_spar_indication,
|
|
|
|
sizeof(struct efi_spar_indication));
|
2017-01-03 21:01:15 +00:00
|
|
|
return sprintf(buf, "%u\n", efi_spar_indication.boot_to_tool);
|
2016-09-19 21:09:30 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:56:26 +00:00
|
|
|
static ssize_t boottotool_store(struct device *dev,
|
2016-09-19 21:09:30 +00:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int val, ret;
|
|
|
|
struct efi_spar_indication efi_spar_indication;
|
|
|
|
|
|
|
|
if (kstrtoint(buf, 10, &val))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
efi_spar_indication.boot_to_tool = val;
|
|
|
|
ret = visorchannel_write
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:30 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
efi_spar_ind), &(efi_spar_indication),
|
|
|
|
sizeof(struct efi_spar_indication));
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return count;
|
|
|
|
}
|
2014-07-22 13:56:26 +00:00
|
|
|
static DEVICE_ATTR_RW(boottotool);
|
|
|
|
|
2014-07-24 18:08:42 +00:00
|
|
|
static ssize_t error_show(struct device *dev, struct device_attribute *attr,
|
2016-09-19 21:09:31 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
u32 error = 0;
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
visorchannel_read(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:31 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_error),
|
|
|
|
&error, sizeof(u32));
|
2017-01-03 21:01:15 +00:00
|
|
|
return sprintf(buf, "%i\n", error);
|
2016-09-19 21:09:31 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 18:08:42 +00:00
|
|
|
static ssize_t error_store(struct device *dev, struct device_attribute *attr,
|
2016-09-19 21:09:31 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 error;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (kstrtou32(buf, 10, &error))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = visorchannel_write
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:31 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_error),
|
|
|
|
&error, sizeof(u32));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return count;
|
|
|
|
}
|
2014-07-24 18:08:42 +00:00
|
|
|
static DEVICE_ATTR_RW(error);
|
|
|
|
|
|
|
|
static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
|
2016-09-19 21:09:32 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
u32 text_id = 0;
|
|
|
|
|
|
|
|
visorchannel_read
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:32 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_text_id),
|
|
|
|
&text_id, sizeof(u32));
|
2017-01-03 21:01:15 +00:00
|
|
|
return sprintf(buf, "%i\n", text_id);
|
2016-09-19 21:09:32 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 18:08:42 +00:00
|
|
|
static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
|
2016-09-19 21:09:32 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 text_id;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (kstrtou32(buf, 10, &text_id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = visorchannel_write
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:32 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_text_id),
|
|
|
|
&text_id, sizeof(u32));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return count;
|
|
|
|
}
|
2014-07-24 18:08:42 +00:00
|
|
|
static DEVICE_ATTR_RW(textid);
|
|
|
|
|
|
|
|
static ssize_t remaining_steps_show(struct device *dev,
|
2016-09-19 21:09:33 +00:00
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
u16 remaining_steps = 0;
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
visorchannel_read(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:33 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_remaining_steps),
|
|
|
|
&remaining_steps, sizeof(u16));
|
2017-01-03 21:01:15 +00:00
|
|
|
return sprintf(buf, "%hu\n", remaining_steps);
|
2016-09-19 21:09:33 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 18:08:42 +00:00
|
|
|
static ssize_t remaining_steps_store(struct device *dev,
|
2015-03-16 17:58:52 +00:00
|
|
|
struct device_attribute *attr,
|
2016-09-19 21:09:33 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u16 remaining_steps;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (kstrtou16(buf, 10, &remaining_steps))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = visorchannel_write
|
2017-02-21 17:53:29 +00:00
|
|
|
(chipset_dev->controlvm_channel,
|
2016-09-19 21:09:33 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
installation_remaining_steps),
|
|
|
|
&remaining_steps, sizeof(u16));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return count;
|
|
|
|
}
|
2014-07-24 18:08:42 +00:00
|
|
|
static DEVICE_ATTR_RW(remaining_steps);
|
|
|
|
|
2015-05-05 22:37:12 +00:00
|
|
|
static uuid_le
|
2015-05-05 22:36:14 +00:00
|
|
|
parser_id_get(struct parser_context *ctx)
|
|
|
|
{
|
|
|
|
struct spar_controlvm_parameters_header *phdr = NULL;
|
|
|
|
|
|
|
|
phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
|
|
|
|
return phdr->id;
|
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:12 +00:00
|
|
|
static void parser_done(struct parser_context *ctx)
|
2015-05-05 22:36:14 +00:00
|
|
|
{
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev->controlvm_payload_bytes_buffered -= ctx->param_bytes;
|
2015-05-05 22:36:14 +00:00
|
|
|
kfree(ctx);
|
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:12 +00:00
|
|
|
static void *
|
2015-05-05 22:36:14 +00:00
|
|
|
parser_string_get(struct parser_context *ctx)
|
|
|
|
{
|
|
|
|
u8 *pscan;
|
|
|
|
unsigned long nscan;
|
|
|
|
int value_length = -1;
|
|
|
|
void *value = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pscan = ctx->curr;
|
|
|
|
nscan = ctx->bytes_remaining;
|
|
|
|
if (nscan == 0)
|
|
|
|
return NULL;
|
|
|
|
if (!pscan)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0, value_length = -1; i < nscan; i++)
|
|
|
|
if (pscan[i] == '\0') {
|
|
|
|
value_length = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value_length < 0) /* '\0' was not included in the length */
|
|
|
|
value_length = nscan;
|
2016-02-08 15:41:45 +00:00
|
|
|
value = kmalloc(value_length + 1, GFP_KERNEL | __GFP_NORETRY);
|
2016-02-08 15:41:46 +00:00
|
|
|
if (!value)
|
2015-05-05 22:36:14 +00:00
|
|
|
return NULL;
|
|
|
|
if (value_length > 0)
|
|
|
|
memcpy(value, pscan, value_length);
|
2016-02-08 15:41:48 +00:00
|
|
|
((u8 *)(value))[value_length] = '\0';
|
2015-05-05 22:36:14 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-01-09 18:02:23 +00:00
|
|
|
static void *
|
|
|
|
parser_name_get(struct parser_context *ctx)
|
|
|
|
{
|
|
|
|
struct spar_controlvm_parameters_header *phdr = NULL;
|
|
|
|
|
|
|
|
phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
|
2017-02-01 22:38:55 +00:00
|
|
|
|
|
|
|
if (phdr->name_offset + phdr->name_length > ctx->param_bytes)
|
|
|
|
return NULL;
|
|
|
|
|
2017-01-09 18:02:23 +00:00
|
|
|
ctx->curr = ctx->data + phdr->name_offset;
|
|
|
|
ctx->bytes_remaining = phdr->name_length;
|
|
|
|
return parser_string_get(ctx);
|
|
|
|
}
|
|
|
|
|
2015-05-13 17:22:19 +00:00
|
|
|
struct visor_busdev {
|
|
|
|
u32 bus_no;
|
|
|
|
u32 dev_no;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int match_visorbus_dev_by_id(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct visor_device *vdev = to_visor_device(dev);
|
2015-10-14 19:28:23 +00:00
|
|
|
struct visor_busdev *id = data;
|
2015-05-13 17:22:19 +00:00
|
|
|
u32 bus_no = id->bus_no;
|
|
|
|
u32 dev_no = id->dev_no;
|
|
|
|
|
2015-06-04 13:22:40 +00:00
|
|
|
if ((vdev->chipset_bus_no == bus_no) &&
|
|
|
|
(vdev->chipset_dev_no == dev_no))
|
2015-05-13 17:22:19 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-08 15:41:47 +00:00
|
|
|
|
2015-05-13 17:22:19 +00:00
|
|
|
struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
|
|
|
|
struct visor_device *from)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
struct device *dev_start = NULL;
|
|
|
|
struct visor_device *vdev = NULL;
|
|
|
|
struct visor_busdev id = {
|
|
|
|
.bus_no = bus_no,
|
|
|
|
.dev_no = dev_no
|
|
|
|
};
|
|
|
|
|
|
|
|
if (from)
|
|
|
|
dev_start = &from->device;
|
|
|
|
dev = bus_find_device(&visorbus_type, dev_start, (void *)&id,
|
|
|
|
match_visorbus_dev_by_id);
|
|
|
|
if (dev)
|
|
|
|
vdev = to_visor_device(dev);
|
|
|
|
return vdev;
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:09:26 +00:00
|
|
|
static void
|
|
|
|
controlvm_init_response(struct controlvm_message *msg,
|
|
|
|
struct controlvm_message_header *msg_hdr, int response)
|
|
|
|
{
|
|
|
|
memset(msg, 0, sizeof(struct controlvm_message));
|
|
|
|
memcpy(&msg->hdr, msg_hdr, sizeof(struct controlvm_message_header));
|
|
|
|
msg->hdr.payload_bytes = 0;
|
|
|
|
msg->hdr.payload_vm_offset = 0;
|
|
|
|
msg->hdr.payload_max_bytes = 0;
|
|
|
|
if (response < 0) {
|
|
|
|
msg->hdr.flags.failed = 1;
|
|
|
|
msg->hdr.completion_status = (u32)(-response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:44 +00:00
|
|
|
static int
|
2016-09-19 21:09:26 +00:00
|
|
|
controlvm_respond_chipset_init(struct controlvm_message_header *msg_hdr,
|
|
|
|
int response,
|
|
|
|
enum ultra_chipset_feature features)
|
|
|
|
{
|
|
|
|
struct controlvm_message outmsg;
|
|
|
|
|
|
|
|
controlvm_init_response(&outmsg, msg_hdr, response);
|
|
|
|
outmsg.cmd.init_chipset.features = features;
|
2017-02-21 17:53:29 +00:00
|
|
|
return visorchannel_signalinsert(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:44 +00:00
|
|
|
CONTROLVM_QUEUE_REQUEST, &outmsg);
|
2016-09-19 21:09:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:45 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
chipset_init(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
|
|
|
static int chipset_inited;
|
2014-10-23 18:30:24 +00:00
|
|
|
enum ultra_chipset_feature features = 0;
|
2014-03-04 13:58:07 +00:00
|
|
|
int rc = CONTROLVM_RESP_SUCCESS;
|
2016-11-21 17:15:45 +00:00
|
|
|
int res = 0;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CHIPSET_INIT_ENTRY_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
if (chipset_inited) {
|
2016-12-22 16:08:58 +00:00
|
|
|
rc = -CONTROLVM_RESP_ALREADY_DONE;
|
2016-11-21 17:15:45 +00:00
|
|
|
res = -EIO;
|
2016-03-11 22:01:41 +00:00
|
|
|
goto out_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
chipset_inited = 1;
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CHIPSET_INIT_EXIT_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-06-11 01:48:18 +00:00
|
|
|
/*
|
|
|
|
* Set features to indicate we support parahotplug (if Command
|
2016-02-08 15:41:44 +00:00
|
|
|
* also supports it).
|
|
|
|
*/
|
2016-11-03 15:44:28 +00:00
|
|
|
features = inmsg->cmd.init_chipset.features &
|
|
|
|
ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-06-11 01:48:18 +00:00
|
|
|
/*
|
|
|
|
* Set the "reply" bit so Command knows this is a
|
2016-02-08 15:41:44 +00:00
|
|
|
* features-aware driver.
|
|
|
|
*/
|
2014-03-04 13:58:07 +00:00
|
|
|
features |= ULTRA_CHIPSET_FEATURE_REPLY;
|
|
|
|
|
2016-03-11 22:01:41 +00:00
|
|
|
out_respond:
|
2014-10-23 18:30:26 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected)
|
2016-11-21 17:15:45 +00:00
|
|
|
res = controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
|
|
|
|
|
|
|
|
return res;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:46 +00:00
|
|
|
static int
|
2015-03-16 17:58:46 +00:00
|
|
|
controlvm_respond(struct controlvm_message_header *msg_hdr, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:31 +00:00
|
|
|
struct controlvm_message outmsg;
|
2014-08-18 13:34:53 +00:00
|
|
|
|
2015-03-16 17:58:46 +00:00
|
|
|
controlvm_init_response(&outmsg, msg_hdr, response);
|
2015-03-04 17:14:22 +00:00
|
|
|
if (outmsg.hdr.flags.test_message == 1)
|
2016-11-21 17:15:46 +00:00
|
|
|
return -EINVAL;
|
2015-03-04 17:14:22 +00:00
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
return visorchannel_signalinsert(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:46 +00:00
|
|
|
CONTROLVM_QUEUE_REQUEST, &outmsg);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:47 +00:00
|
|
|
static int controlvm_respond_physdev_changestate(
|
2015-03-16 17:58:46 +00:00
|
|
|
struct controlvm_message_header *msg_hdr, int response,
|
2014-10-23 18:30:26 +00:00
|
|
|
struct spar_segment_state state)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:31 +00:00
|
|
|
struct controlvm_message outmsg;
|
2014-08-18 13:34:53 +00:00
|
|
|
|
2015-03-16 17:58:46 +00:00
|
|
|
controlvm_init_response(&outmsg, msg_hdr, response);
|
2014-10-23 18:30:25 +00:00
|
|
|
outmsg.cmd.device_change_state.state = state;
|
|
|
|
outmsg.cmd.device_change_state.flags.phys_device = 1;
|
2017-02-21 17:53:29 +00:00
|
|
|
return visorchannel_signalinsert(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:47 +00:00
|
|
|
CONTROLVM_QUEUE_REQUEST, &outmsg);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:36:16 +00:00
|
|
|
enum crash_obj_type {
|
|
|
|
CRASH_DEV,
|
|
|
|
CRASH_BUS,
|
|
|
|
};
|
|
|
|
|
2016-11-21 17:15:48 +00:00
|
|
|
static int
|
2016-03-02 00:45:04 +00:00
|
|
|
save_crash_message(struct controlvm_message *msg, enum crash_obj_type typ)
|
|
|
|
{
|
|
|
|
u32 local_crash_msg_offset;
|
|
|
|
u16 local_crash_msg_count;
|
2016-11-21 17:15:48 +00:00
|
|
|
int err;
|
2016-03-02 00:45:04 +00:00
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
err = visorchannel_read(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:48 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
saved_crash_message_count),
|
|
|
|
&local_crash_msg_count, sizeof(u16));
|
|
|
|
if (err) {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_CTRL_RD_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:48 +00:00
|
|
|
return err;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_COUNT_FAILURE_PC, 0,
|
|
|
|
local_crash_msg_count,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:48 +00:00
|
|
|
return -EIO;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
err = visorchannel_read(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:48 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
saved_crash_message_offset),
|
|
|
|
&local_crash_msg_offset, sizeof(u32));
|
|
|
|
if (err) {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_CTRL_RD_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:48 +00:00
|
|
|
return err;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:08:59 +00:00
|
|
|
switch (typ) {
|
|
|
|
case CRASH_DEV:
|
|
|
|
local_crash_msg_offset += sizeof(struct controlvm_message);
|
2017-02-21 17:53:29 +00:00
|
|
|
err = visorchannel_write(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:48 +00:00
|
|
|
local_crash_msg_offset,
|
|
|
|
msg,
|
2016-12-22 16:08:59 +00:00
|
|
|
sizeof(struct controlvm_message));
|
2016-11-21 17:15:48 +00:00
|
|
|
if (err) {
|
2016-12-22 16:08:59 +00:00
|
|
|
POSTCODE_LINUX(SAVE_MSG_DEV_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:48 +00:00
|
|
|
return err;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
2016-12-22 16:08:59 +00:00
|
|
|
break;
|
|
|
|
case CRASH_BUS:
|
2017-02-21 17:53:29 +00:00
|
|
|
err = visorchannel_write(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:48 +00:00
|
|
|
local_crash_msg_offset,
|
|
|
|
msg,
|
|
|
|
sizeof(struct controlvm_message));
|
|
|
|
if (err) {
|
2016-12-22 16:08:59 +00:00
|
|
|
POSTCODE_LINUX(SAVE_MSG_BUS_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:48 +00:00
|
|
|
return err;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
2016-12-22 16:08:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_info("Invalid crash_obj_type\n");
|
|
|
|
break;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
2016-11-21 17:15:48 +00:00
|
|
|
return 0;
|
2016-03-02 00:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:49 +00:00
|
|
|
static int
|
2015-06-01 17:00:27 +00:00
|
|
|
bus_responder(enum controlvm_id cmd_id,
|
|
|
|
struct controlvm_message_header *pending_msg_hdr,
|
2015-05-13 17:22:24 +00:00
|
|
|
int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2016-02-08 15:41:46 +00:00
|
|
|
if (!pending_msg_hdr)
|
2016-11-21 17:15:49 +00:00
|
|
|
return -EIO;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-01 17:00:27 +00:00
|
|
|
if (pending_msg_hdr->id != (u32)cmd_id)
|
2016-11-21 17:15:49 +00:00
|
|
|
return -EINVAL;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2016-11-21 17:15:49 +00:00
|
|
|
return controlvm_respond(pending_msg_hdr, response);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:50 +00:00
|
|
|
static int
|
2015-03-16 17:58:16 +00:00
|
|
|
device_changestate_responder(enum controlvm_id cmd_id,
|
2015-06-04 13:22:42 +00:00
|
|
|
struct visor_device *p, int response,
|
2015-03-16 17:58:16 +00:00
|
|
|
struct spar_segment_state response_state)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:31 +00:00
|
|
|
struct controlvm_message outmsg;
|
2015-06-04 13:22:42 +00:00
|
|
|
u32 bus_no = p->chipset_bus_no;
|
|
|
|
u32 dev_no = p->chipset_dev_no;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-02-08 15:41:46 +00:00
|
|
|
if (!p->pending_msg_hdr)
|
2016-11-21 17:15:50 +00:00
|
|
|
return -EIO;
|
2015-06-01 17:00:27 +00:00
|
|
|
if (p->pending_msg_hdr->id != cmd_id)
|
2016-11-21 17:15:50 +00:00
|
|
|
return -EINVAL;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-01 17:00:27 +00:00
|
|
|
controlvm_init_response(&outmsg, p->pending_msg_hdr, response);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-03-16 17:58:16 +00:00
|
|
|
outmsg.cmd.device_change_state.bus_no = bus_no;
|
|
|
|
outmsg.cmd.device_change_state.dev_no = dev_no;
|
|
|
|
outmsg.cmd.device_change_state.state = response_state;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
return visorchannel_signalinsert(chipset_dev->controlvm_channel,
|
2016-11-21 17:15:50 +00:00
|
|
|
CONTROLVM_QUEUE_REQUEST, &outmsg);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:51 +00:00
|
|
|
static int
|
2015-06-01 17:00:27 +00:00
|
|
|
device_responder(enum controlvm_id cmd_id,
|
|
|
|
struct controlvm_message_header *pending_msg_hdr,
|
2015-05-13 17:22:25 +00:00
|
|
|
int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2016-02-08 15:41:46 +00:00
|
|
|
if (!pending_msg_hdr)
|
2016-11-21 17:15:51 +00:00
|
|
|
return -EIO;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2015-06-01 17:00:27 +00:00
|
|
|
if (pending_msg_hdr->id != (u32)cmd_id)
|
2016-11-21 17:15:51 +00:00
|
|
|
return -EINVAL;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2016-11-21 17:15:51 +00:00
|
|
|
return controlvm_respond(pending_msg_hdr, response);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 15:44:22 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
bus_create(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2016-11-03 15:44:19 +00:00
|
|
|
struct controlvm_message_header *pmsg_hdr = NULL;
|
2015-04-13 14:28:41 +00:00
|
|
|
u32 bus_no = cmd->create_bus.bus_no;
|
2015-06-04 13:22:41 +00:00
|
|
|
struct visor_device *bus_info;
|
2015-06-01 17:00:26 +00:00
|
|
|
struct visorchannel *visorchannel;
|
2016-11-03 15:44:22 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
|
2015-03-16 17:58:20 +00:00
|
|
|
if (bus_info && (bus_info->state.created == 1)) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CREATE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-03 15:44:22 +00:00
|
|
|
err = -EEXIST;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2016-11-03 15:44:22 +00:00
|
|
|
|
2015-03-16 17:58:20 +00:00
|
|
|
bus_info = kzalloc(sizeof(*bus_info), GFP_KERNEL);
|
|
|
|
if (!bus_info) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CREATE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-03 15:44:22 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 13:22:49 +00:00
|
|
|
INIT_LIST_HEAD(&bus_info->list_all);
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_info->chipset_bus_no = bus_no;
|
|
|
|
bus_info->chipset_dev_no = BUS_ROOT_DEVICE;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(BUS_CREATE_ENTRY_PC, 0, bus_no, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-12-22 16:09:05 +00:00
|
|
|
if (uuid_le_cmp(cmd->create_bus.bus_inst_uuid, spar_siovm_uuid) == 0) {
|
|
|
|
err = save_crash_message(inmsg, CRASH_BUS);
|
|
|
|
if (err)
|
|
|
|
goto err_free_bus_info;
|
|
|
|
}
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-11-03 15:44:19 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1) {
|
|
|
|
pmsg_hdr = kzalloc(sizeof(*pmsg_hdr),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pmsg_hdr) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(MALLOC_FAILURE_PC, cmd,
|
|
|
|
bus_info->chipset_bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-03 15:44:22 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_bus_info;
|
2016-11-03 15:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pmsg_hdr, &inmsg->hdr,
|
|
|
|
sizeof(struct controlvm_message_header));
|
|
|
|
bus_info->pending_msg_hdr = pmsg_hdr;
|
|
|
|
}
|
|
|
|
|
2016-11-03 15:44:22 +00:00
|
|
|
visorchannel = visorchannel_create(cmd->create_bus.channel_addr,
|
|
|
|
cmd->create_bus.channel_bytes,
|
|
|
|
GFP_KERNEL,
|
|
|
|
cmd->create_bus.bus_data_type_uuid);
|
|
|
|
|
|
|
|
if (!visorchannel) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CREATE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-03 15:44:22 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_pending_msg;
|
|
|
|
}
|
|
|
|
bus_info->visorchannel = visorchannel;
|
|
|
|
|
|
|
|
/* Response will be handled by chipset_bus_create */
|
2016-11-03 15:44:19 +00:00
|
|
|
chipset_bus_create(bus_info);
|
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(BUS_CREATE_EXIT_PC, 0, bus_no, DIAG_SEVERITY_PRINT);
|
2016-11-03 15:44:22 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free_pending_msg:
|
|
|
|
kfree(bus_info->pending_msg_hdr);
|
2016-11-03 15:44:19 +00:00
|
|
|
|
2016-11-03 15:44:22 +00:00
|
|
|
err_free_bus_info:
|
2016-11-03 15:44:19 +00:00
|
|
|
kfree(bus_info);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-11-03 15:44:22 +00:00
|
|
|
err_respond:
|
2016-11-03 15:44:19 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-11-03 15:44:22 +00:00
|
|
|
bus_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 15:44:21 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
bus_destroy(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2016-11-03 15:44:20 +00:00
|
|
|
struct controlvm_message_header *pmsg_hdr = NULL;
|
2015-04-13 14:28:41 +00:00
|
|
|
u32 bus_no = cmd->destroy_bus.bus_no;
|
2015-06-04 13:22:41 +00:00
|
|
|
struct visor_device *bus_info;
|
2016-11-03 15:44:21 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
|
2016-11-03 15:44:20 +00:00
|
|
|
if (!bus_info) {
|
2016-11-03 15:44:21 +00:00
|
|
|
err = -ENODEV;
|
|
|
|
goto err_respond;
|
2016-11-03 15:44:20 +00:00
|
|
|
}
|
|
|
|
if (bus_info->state.created == 0) {
|
2016-11-03 15:44:21 +00:00
|
|
|
err = -ENOENT;
|
|
|
|
goto err_respond;
|
2016-11-03 15:44:20 +00:00
|
|
|
}
|
|
|
|
if (bus_info->pending_msg_hdr) {
|
|
|
|
/* only non-NULL if dev is still waiting on a response */
|
2016-11-03 15:44:21 +00:00
|
|
|
err = -EEXIST;
|
|
|
|
goto err_respond;
|
2016-11-03 15:44:20 +00:00
|
|
|
}
|
|
|
|
if (inmsg->hdr.flags.response_expected == 1) {
|
|
|
|
pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
|
|
|
|
if (!pmsg_hdr) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(MALLOC_FAILURE_PC, cmd,
|
|
|
|
bus_info->chipset_bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-03 15:44:21 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_respond;
|
2016-11-03 15:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pmsg_hdr, &inmsg->hdr,
|
|
|
|
sizeof(struct controlvm_message_header));
|
|
|
|
bus_info->pending_msg_hdr = pmsg_hdr;
|
|
|
|
}
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-11-03 15:44:20 +00:00
|
|
|
/* Response will be handled by chipset_bus_destroy */
|
|
|
|
chipset_bus_destroy(bus_info);
|
2016-11-03 15:44:21 +00:00
|
|
|
return 0;
|
2016-11-03 15:44:20 +00:00
|
|
|
|
2016-11-03 15:44:21 +00:00
|
|
|
err_respond:
|
2016-11-03 15:44:20 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-11-03 15:44:21 +00:00
|
|
|
bus_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:15:53 +00:00
|
|
|
static int
|
2015-03-16 17:57:51 +00:00
|
|
|
bus_configure(struct controlvm_message *inmsg,
|
|
|
|
struct parser_context *parser_ctx)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2015-05-05 22:35:45 +00:00
|
|
|
u32 bus_no;
|
2015-06-04 13:22:41 +00:00
|
|
|
struct visor_device *bus_info;
|
2016-11-21 17:15:53 +00:00
|
|
|
int err = 0;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-03-16 17:58:22 +00:00
|
|
|
bus_no = cmd->configure_bus.bus_no;
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CONFIGURE_ENTRY_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
|
2015-03-16 17:58:22 +00:00
|
|
|
if (!bus_info) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CONFIGURE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:53 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
goto err_respond;
|
2015-03-16 17:58:22 +00:00
|
|
|
} else if (bus_info->state.created == 0) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CONFIGURE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:53 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
goto err_respond;
|
2016-02-08 15:41:46 +00:00
|
|
|
} else if (bus_info->pending_msg_hdr) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CONFIGURE_FAILURE_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-11-21 17:15:53 +00:00
|
|
|
err = -EIO;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2016-11-21 17:15:53 +00:00
|
|
|
|
|
|
|
err = visorchannel_set_clientpartition
|
|
|
|
(bus_info->visorchannel,
|
|
|
|
cmd->configure_bus.guest_handle);
|
|
|
|
if (err)
|
|
|
|
goto err_respond;
|
|
|
|
|
2017-01-09 18:02:23 +00:00
|
|
|
if (parser_ctx) {
|
|
|
|
bus_info->partition_uuid = parser_id_get(parser_ctx);
|
|
|
|
bus_info->name = parser_name_get(parser_ctx);
|
|
|
|
}
|
2016-11-21 17:15:53 +00:00
|
|
|
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(BUS_CONFIGURE_EXIT_PC, 0, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_PRINT);
|
2016-11-21 17:15:53 +00:00
|
|
|
|
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
|
|
|
bus_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_respond:
|
2016-11-03 15:44:23 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-11-21 17:15:53 +00:00
|
|
|
bus_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:09:04 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
my_device_create(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2016-11-03 15:44:24 +00:00
|
|
|
struct controlvm_message_header *pmsg_hdr = NULL;
|
2015-04-13 14:28:41 +00:00
|
|
|
u32 bus_no = cmd->create_device.bus_no;
|
|
|
|
u32 dev_no = cmd->create_device.dev_no;
|
2015-06-04 13:22:42 +00:00
|
|
|
struct visor_device *dev_info = NULL;
|
2015-06-04 13:22:41 +00:00
|
|
|
struct visor_device *bus_info;
|
2015-06-01 17:00:26 +00:00
|
|
|
struct visorchannel *visorchannel;
|
2016-12-22 16:09:04 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:42 +00:00
|
|
|
bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
|
|
|
|
if (!bus_info) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -ENODEV;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2015-06-04 13:22:42 +00:00
|
|
|
|
|
|
|
if (bus_info->state.created == 0) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2015-06-04 13:22:42 +00:00
|
|
|
|
|
|
|
dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
|
|
|
|
if (dev_info && (dev_info->state.created == 1)) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -EEXIST;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2015-06-04 13:22:42 +00:00
|
|
|
|
2015-03-16 17:58:23 +00:00
|
|
|
dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
|
|
|
|
if (!dev_info) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2014-03-14 02:20:06 +00:00
|
|
|
|
2015-06-04 13:22:42 +00:00
|
|
|
dev_info->chipset_bus_no = bus_no;
|
|
|
|
dev_info->chipset_dev_no = dev_no;
|
|
|
|
dev_info->inst = cmd->create_device.dev_inst_uuid;
|
|
|
|
|
|
|
|
/* not sure where the best place to set the 'parent' */
|
|
|
|
dev_info->device.parent = &bus_info->device;
|
|
|
|
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-07-14 18:43:29 +00:00
|
|
|
visorchannel =
|
|
|
|
visorchannel_create_with_lock(cmd->create_device.channel_addr,
|
|
|
|
cmd->create_device.channel_bytes,
|
|
|
|
GFP_KERNEL,
|
|
|
|
cmd->create_device.data_type_uuid);
|
2015-06-01 17:00:26 +00:00
|
|
|
|
|
|
|
if (!visorchannel) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_dev_info;
|
2015-06-01 17:00:26 +00:00
|
|
|
}
|
|
|
|
dev_info->visorchannel = visorchannel;
|
|
|
|
dev_info->channel_type_guid = cmd->create_device.data_type_uuid;
|
2016-03-02 00:45:04 +00:00
|
|
|
if (uuid_le_cmp(cmd->create_device.data_type_uuid,
|
2016-12-22 16:09:04 +00:00
|
|
|
spar_vhba_channel_protocol_uuid) == 0) {
|
|
|
|
err = save_crash_message(inmsg, CRASH_DEV);
|
|
|
|
if (err)
|
|
|
|
goto err_free_dev_info;
|
|
|
|
}
|
2016-03-02 00:45:04 +00:00
|
|
|
|
2016-11-03 15:44:24 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1) {
|
|
|
|
pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
|
|
|
|
if (!pmsg_hdr) {
|
2016-12-22 16:09:04 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_dev_info;
|
2016-11-03 15:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pmsg_hdr, &inmsg->hdr,
|
|
|
|
sizeof(struct controlvm_message_header));
|
|
|
|
dev_info->pending_msg_hdr = pmsg_hdr;
|
|
|
|
}
|
|
|
|
/* Chipset_device_create will send response */
|
|
|
|
chipset_device_create(dev_info);
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_PRINT);
|
2016-12-22 16:09:04 +00:00
|
|
|
return 0;
|
2016-11-03 15:44:24 +00:00
|
|
|
|
2016-12-22 16:09:04 +00:00
|
|
|
err_free_dev_info:
|
2016-11-03 15:44:24 +00:00
|
|
|
kfree(dev_info);
|
|
|
|
|
2016-12-22 16:09:04 +00:00
|
|
|
err_respond:
|
2016-11-03 15:44:24 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-12-22 16:09:04 +00:00
|
|
|
device_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:09:06 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
my_device_changestate(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2016-11-03 15:44:26 +00:00
|
|
|
struct controlvm_message_header *pmsg_hdr = NULL;
|
2015-04-13 14:28:41 +00:00
|
|
|
u32 bus_no = cmd->device_change_state.bus_no;
|
|
|
|
u32 dev_no = cmd->device_change_state.dev_no;
|
2014-10-23 18:30:25 +00:00
|
|
|
struct spar_segment_state state = cmd->device_change_state.state;
|
2015-06-04 13:22:42 +00:00
|
|
|
struct visor_device *dev_info;
|
2016-12-22 16:09:06 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:42 +00:00
|
|
|
dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
|
2015-03-16 17:58:24 +00:00
|
|
|
if (!dev_info) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:06 +00:00
|
|
|
err = -ENODEV;
|
2016-11-03 15:44:25 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
if (dev_info->state.created == 0) {
|
2016-12-01 06:31:09 +00:00
|
|
|
POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2016-12-22 16:09:06 +00:00
|
|
|
err = -EINVAL;
|
2016-11-03 15:44:25 +00:00
|
|
|
goto err_respond;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2016-11-03 15:44:26 +00:00
|
|
|
if (dev_info->pending_msg_hdr) {
|
|
|
|
/* only non-NULL if dev is still waiting on a response */
|
2016-12-22 16:09:06 +00:00
|
|
|
err = -EIO;
|
2016-11-03 15:44:26 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
if (inmsg->hdr.flags.response_expected == 1) {
|
|
|
|
pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
|
|
|
|
if (!pmsg_hdr) {
|
2016-12-22 16:09:06 +00:00
|
|
|
err = -ENOMEM;
|
2016-11-03 15:44:26 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pmsg_hdr, &inmsg->hdr,
|
|
|
|
sizeof(struct controlvm_message_header));
|
|
|
|
dev_info->pending_msg_hdr = pmsg_hdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.alive == segment_state_running.alive &&
|
|
|
|
state.operating == segment_state_running.operating)
|
|
|
|
/* Response will be sent from chipset_device_resume */
|
|
|
|
chipset_device_resume(dev_info);
|
|
|
|
/* ServerNotReady / ServerLost / SegmentStateStandby */
|
|
|
|
else if (state.alive == segment_state_standby.alive &&
|
|
|
|
state.operating == segment_state_standby.operating)
|
|
|
|
/*
|
|
|
|
* technically this is standby case where server is lost.
|
|
|
|
* Response will be sent from chipset_device_pause.
|
|
|
|
*/
|
|
|
|
chipset_device_pause(dev_info);
|
2016-12-22 16:09:06 +00:00
|
|
|
return 0;
|
2016-11-03 15:44:25 +00:00
|
|
|
|
|
|
|
err_respond:
|
2016-11-03 15:44:26 +00:00
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-12-22 16:09:06 +00:00
|
|
|
device_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:09:07 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
my_device_destroy(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2014-10-23 18:30:25 +00:00
|
|
|
struct controlvm_message_packet *cmd = &inmsg->cmd;
|
2016-11-03 15:44:27 +00:00
|
|
|
struct controlvm_message_header *pmsg_hdr = NULL;
|
2015-04-13 14:28:41 +00:00
|
|
|
u32 bus_no = cmd->destroy_device.bus_no;
|
|
|
|
u32 dev_no = cmd->destroy_device.dev_no;
|
2015-06-04 13:22:42 +00:00
|
|
|
struct visor_device *dev_info;
|
2016-12-22 16:09:07 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-06-04 13:22:42 +00:00
|
|
|
dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
|
2016-11-03 15:44:27 +00:00
|
|
|
if (!dev_info) {
|
2016-12-22 16:09:07 +00:00
|
|
|
err = -ENODEV;
|
2016-11-03 15:44:27 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
if (dev_info->state.created == 0) {
|
2016-12-22 16:09:07 +00:00
|
|
|
err = -EINVAL;
|
2016-11-03 15:44:27 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-11-03 15:44:27 +00:00
|
|
|
if (dev_info->pending_msg_hdr) {
|
|
|
|
/* only non-NULL if dev is still waiting on a response */
|
2016-12-22 16:09:07 +00:00
|
|
|
err = -EIO;
|
2016-11-03 15:44:27 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
if (inmsg->hdr.flags.response_expected == 1) {
|
|
|
|
pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
|
|
|
|
if (!pmsg_hdr) {
|
2016-12-22 16:09:07 +00:00
|
|
|
err = -ENOMEM;
|
2016-11-03 15:44:27 +00:00
|
|
|
goto err_respond;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pmsg_hdr, &inmsg->hdr,
|
|
|
|
sizeof(struct controlvm_message_header));
|
|
|
|
dev_info->pending_msg_hdr = pmsg_hdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
chipset_device_destroy(dev_info);
|
2016-12-22 16:09:07 +00:00
|
|
|
return 0;
|
2016-11-03 15:44:27 +00:00
|
|
|
|
|
|
|
err_respond:
|
|
|
|
if (inmsg->hdr.flags.response_expected == 1)
|
2016-12-22 16:09:07 +00:00
|
|
|
device_responder(inmsg->hdr.id, &inmsg->hdr, err);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-12-22 16:09:02 +00:00
|
|
|
* The general parahotplug flow works as follows. The visorchipset receives
|
|
|
|
* a DEVICE_CHANGESTATE message from Command specifying a physical device
|
|
|
|
* to enable or disable. The CONTROLVM message handler calls
|
|
|
|
* parahotplug_process_message, which then adds the message to a global list
|
|
|
|
* and kicks off a udev event which causes a user level script to enable or
|
|
|
|
* disable the specified device. The udev script then writes to
|
|
|
|
* /sys/devices/platform/visorchipset/parahotplug, which causes the
|
|
|
|
* parahotplug store functions to get called, at which point the
|
|
|
|
* appropriate CONTROLVM message is retrieved from the list and responded
|
|
|
|
* to.
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define PARAHOTPLUG_TIMEOUT_MS 2000
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-12-22 16:09:02 +00:00
|
|
|
* parahotplug_next_id() - generate unique int to match an outstanding
|
|
|
|
* CONTROLVM message with a udev script /sys
|
|
|
|
* response
|
2016-06-11 01:48:18 +00:00
|
|
|
*
|
|
|
|
* Return: a unique integer value
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
parahotplug_next_id(void)
|
|
|
|
{
|
|
|
|
static atomic_t id = ATOMIC_INIT(0);
|
2014-08-18 13:34:53 +00:00
|
|
|
|
2014-03-04 13:58:07 +00:00
|
|
|
return atomic_inc_return(&id);
|
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-06-11 01:48:18 +00:00
|
|
|
* parahotplug_next_expiration() - returns the time (in jiffies) when a
|
|
|
|
* CONTROLVM message on the list should expire
|
|
|
|
* -- PARAHOTPLUG_TIMEOUT_MS in the future
|
|
|
|
*
|
|
|
|
* Return: expected expiration time (in jiffies)
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
static unsigned long
|
|
|
|
parahotplug_next_expiration(void)
|
|
|
|
{
|
2015-01-31 11:02:08 +00:00
|
|
|
return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-06-11 01:48:18 +00:00
|
|
|
* parahotplug_request_create() - create a parahotplug_request, which is
|
|
|
|
* basically a wrapper for a CONTROLVM_MESSAGE
|
|
|
|
* that we can stick on a list
|
|
|
|
* @msg: the message to insert in the request
|
|
|
|
*
|
|
|
|
* Return: the request containing the provided message
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
static struct parahotplug_request *
|
2014-10-23 18:30:31 +00:00
|
|
|
parahotplug_request_create(struct controlvm_message *msg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-02-10 14:12:07 +00:00
|
|
|
struct parahotplug_request *req;
|
|
|
|
|
2015-03-16 17:58:30 +00:00
|
|
|
req = kmalloc(sizeof(*req), GFP_KERNEL | __GFP_NORETRY);
|
2015-03-16 17:58:13 +00:00
|
|
|
if (!req)
|
2014-03-04 13:58:07 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
req->id = parahotplug_next_id();
|
|
|
|
req->expiration = parahotplug_next_expiration();
|
|
|
|
req->msg = *msg;
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-06-11 01:48:18 +00:00
|
|
|
* parahotplug_request_destroy() - free a parahotplug_request
|
|
|
|
* @req: the request to deallocate
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
parahotplug_request_destroy(struct parahotplug_request *req)
|
|
|
|
{
|
|
|
|
kfree(req);
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:09:37 +00:00
|
|
|
static LIST_HEAD(parahotplug_request_list);
|
|
|
|
static DEFINE_SPINLOCK(parahotplug_request_list_lock); /* lock for above */
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-06-11 01:48:18 +00:00
|
|
|
* parahotplug_request_complete() - mark request as complete
|
|
|
|
* @id: the id of the request
|
|
|
|
* @active: indicates whether the request is assigned to active partition
|
|
|
|
*
|
2016-12-22 16:09:02 +00:00
|
|
|
* Called from the /sys handler, which means the user script has
|
2016-06-11 01:48:18 +00:00
|
|
|
* finished the enable/disable. Find the matching identifier, and
|
2014-03-04 13:58:07 +00:00
|
|
|
* respond to the CONTROLVM message with success.
|
2016-06-11 01:48:18 +00:00
|
|
|
*
|
|
|
|
* Return: 0 on success or -EINVAL on failure
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
|
|
|
static int
|
2014-07-31 16:00:49 +00:00
|
|
|
parahotplug_request_complete(int id, u16 active)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-05-05 22:35:45 +00:00
|
|
|
struct list_head *pos;
|
|
|
|
struct list_head *tmp;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-03-16 17:58:41 +00:00
|
|
|
spin_lock(¶hotplug_request_list_lock);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
/* Look for a request matching "id". */
|
2015-03-16 17:58:41 +00:00
|
|
|
list_for_each_safe(pos, tmp, ¶hotplug_request_list) {
|
2014-03-04 13:58:07 +00:00
|
|
|
struct parahotplug_request *req =
|
|
|
|
list_entry(pos, struct parahotplug_request, list);
|
|
|
|
if (req->id == id) {
|
2016-06-11 01:48:18 +00:00
|
|
|
/*
|
|
|
|
* Found a match. Remove it from the list and
|
2014-03-04 13:58:07 +00:00
|
|
|
* respond.
|
|
|
|
*/
|
|
|
|
list_del(pos);
|
2015-03-16 17:58:41 +00:00
|
|
|
spin_unlock(¶hotplug_request_list_lock);
|
2014-10-23 18:30:25 +00:00
|
|
|
req->msg.cmd.device_change_state.state.active = active;
|
2014-10-23 18:30:26 +00:00
|
|
|
if (req->msg.hdr.flags.response_expected)
|
2014-03-04 13:58:07 +00:00
|
|
|
controlvm_respond_physdev_changestate(
|
|
|
|
&req->msg.hdr, CONTROLVM_RESP_SUCCESS,
|
2014-10-23 18:30:25 +00:00
|
|
|
req->msg.cmd.device_change_state.state);
|
2014-03-04 13:58:07 +00:00
|
|
|
parahotplug_request_destroy(req);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:58:41 +00:00
|
|
|
spin_unlock(¶hotplug_request_list_lock);
|
2016-05-14 03:17:20 +00:00
|
|
|
return -EINVAL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:34 +00:00
|
|
|
* devicedisabled_store() - disables the hotplug device
|
|
|
|
* @dev: sysfs interface variable not utilized in this function
|
|
|
|
* @attr: sysfs interface variable not utilized in this function
|
|
|
|
* @buf: buffer containing the device id
|
|
|
|
* @count: the size of the buffer
|
|
|
|
*
|
|
|
|
* The parahotplug/devicedisabled interface gets called by our support script
|
|
|
|
* when an SR-IOV device has been shut down. The ID is passed to the script
|
|
|
|
* and then passed back when the device has been removed.
|
|
|
|
*
|
|
|
|
* Return: the size of the buffer for success or negative for error
|
|
|
|
*/
|
|
|
|
static ssize_t devicedisabled_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned int id;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (kstrtouint(buf, 10, &id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = parahotplug_request_complete(id, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_WO(devicedisabled);
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:34 +00:00
|
|
|
* deviceenabled_store() - enables the hotplug device
|
|
|
|
* @dev: sysfs interface variable not utilized in this function
|
|
|
|
* @attr: sysfs interface variable not utilized in this function
|
|
|
|
* @buf: buffer containing the device id
|
|
|
|
* @count: the size of the buffer
|
|
|
|
*
|
|
|
|
* The parahotplug/deviceenabled interface gets called by our support script
|
|
|
|
* when an SR-IOV device has been recovered. The ID is passed to the script
|
|
|
|
* and then passed back when the device has been brought back up.
|
|
|
|
*
|
|
|
|
* Return: the size of the buffer for success or negative for error
|
|
|
|
*/
|
|
|
|
static ssize_t deviceenabled_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
if (kstrtouint(buf, 10, &id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
parahotplug_request_complete(id, 1);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_WO(deviceenabled);
|
|
|
|
|
|
|
|
static struct attribute *visorchipset_install_attrs[] = {
|
|
|
|
&dev_attr_toolaction.attr,
|
|
|
|
&dev_attr_boottotool.attr,
|
|
|
|
&dev_attr_error.attr,
|
|
|
|
&dev_attr_textid.attr,
|
|
|
|
&dev_attr_remaining_steps.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-10-15 22:41:14 +00:00
|
|
|
static const struct attribute_group visorchipset_install_group = {
|
2016-09-19 21:09:34 +00:00
|
|
|
.name = "install",
|
|
|
|
.attrs = visorchipset_install_attrs
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *visorchipset_parahotplug_attrs[] = {
|
|
|
|
&dev_attr_devicedisabled.attr,
|
|
|
|
&dev_attr_deviceenabled.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group visorchipset_parahotplug_group = {
|
|
|
|
.name = "parahotplug",
|
|
|
|
.attrs = visorchipset_parahotplug_attrs
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group *visorchipset_dev_groups[] = {
|
|
|
|
&visorchipset_install_group,
|
|
|
|
&visorchipset_parahotplug_group,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:34 +00:00
|
|
|
* parahotplug_request_kickoff() - initiate parahotplug request
|
|
|
|
* @req: the request to initiate
|
|
|
|
*
|
|
|
|
* Cause uevent to run the user level script to do the disable/enable specified
|
|
|
|
* in the parahotplug_request.
|
|
|
|
*/
|
2017-03-28 13:34:21 +00:00
|
|
|
static int
|
2016-09-19 21:09:34 +00:00
|
|
|
parahotplug_request_kickoff(struct parahotplug_request *req)
|
|
|
|
{
|
|
|
|
struct controlvm_message_packet *cmd = &req->msg.cmd;
|
|
|
|
char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
|
|
|
|
env_func[40];
|
|
|
|
char *envp[] = {
|
|
|
|
env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
sprintf(env_cmd, "SPAR_PARAHOTPLUG=1");
|
|
|
|
sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id);
|
|
|
|
sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d",
|
|
|
|
cmd->device_change_state.state.active);
|
|
|
|
sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d",
|
|
|
|
cmd->device_change_state.bus_no);
|
|
|
|
sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d",
|
|
|
|
cmd->device_change_state.dev_no >> 3);
|
|
|
|
sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d",
|
|
|
|
cmd->device_change_state.dev_no & 0x7);
|
|
|
|
|
2017-03-28 13:34:21 +00:00
|
|
|
return kobject_uevent_env(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
KOBJ_CHANGE, envp);
|
2016-09-19 21:09:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-06-11 01:48:18 +00:00
|
|
|
* parahotplug_process_message() - enables or disables a PCI device by kicking
|
|
|
|
* off a udev script
|
|
|
|
* @inmsg: the message indicating whether to enable or disable
|
2014-03-04 13:58:07 +00:00
|
|
|
*/
|
2017-03-28 13:34:18 +00:00
|
|
|
static int
|
2014-10-23 18:30:31 +00:00
|
|
|
parahotplug_process_message(struct controlvm_message *inmsg)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
|
|
|
struct parahotplug_request *req;
|
2017-03-28 13:34:21 +00:00
|
|
|
int err;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
req = parahotplug_request_create(inmsg);
|
|
|
|
|
2015-03-16 17:58:13 +00:00
|
|
|
if (!req)
|
2017-03-28 13:34:18 +00:00
|
|
|
return -ENOMEM;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2014-10-23 18:30:25 +00:00
|
|
|
if (inmsg->cmd.device_change_state.state.active) {
|
2016-06-11 01:48:18 +00:00
|
|
|
/*
|
|
|
|
* For enable messages, just respond with success
|
|
|
|
* right away. This is a bit of a hack, but there are
|
|
|
|
* issues with the early enable messages we get (with
|
|
|
|
* either the udev script not detecting that the device
|
|
|
|
* is up, or not getting called at all). Fortunately
|
|
|
|
* the messages that get lost don't matter anyway, as
|
|
|
|
*
|
|
|
|
* devices are automatically enabled at
|
|
|
|
* initialization.
|
2017-01-16 22:32:58 +00:00
|
|
|
*/
|
2017-03-28 13:34:21 +00:00
|
|
|
err = parahotplug_request_kickoff(req);
|
|
|
|
if (err)
|
|
|
|
goto err_respond;
|
2016-04-05 03:31:12 +00:00
|
|
|
controlvm_respond_physdev_changestate
|
|
|
|
(&inmsg->hdr,
|
|
|
|
CONTROLVM_RESP_SUCCESS,
|
|
|
|
inmsg->cmd.device_change_state.state);
|
2014-03-04 13:58:07 +00:00
|
|
|
parahotplug_request_destroy(req);
|
2017-03-28 13:34:21 +00:00
|
|
|
return 0;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
2017-03-28 13:34:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For disable messages, add the request to the
|
|
|
|
* request list before kicking off the udev script. It
|
|
|
|
* won't get responded to until the script has
|
|
|
|
* indicated it's done.
|
|
|
|
*/
|
|
|
|
spin_lock(¶hotplug_request_list_lock);
|
|
|
|
list_add_tail(&req->list, ¶hotplug_request_list);
|
|
|
|
spin_unlock(¶hotplug_request_list_lock);
|
|
|
|
|
|
|
|
err = parahotplug_request_kickoff(req);
|
|
|
|
if (err)
|
|
|
|
goto err_respond;
|
2017-03-28 13:34:18 +00:00
|
|
|
return 0;
|
2017-03-28 13:34:21 +00:00
|
|
|
|
|
|
|
err_respond:
|
|
|
|
controlvm_respond_physdev_changestate
|
|
|
|
(&inmsg->hdr, err,
|
|
|
|
inmsg->cmd.device_change_state.state);
|
|
|
|
return err;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 22:38:56 +00:00
|
|
|
/*
|
|
|
|
* chipset_ready_uevent() - sends chipset_ready action
|
2016-09-19 21:09:34 +00:00
|
|
|
*
|
|
|
|
* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
|
|
|
|
*
|
2017-02-01 22:38:56 +00:00
|
|
|
* Return: 0 on success, negative on failure
|
2016-09-19 21:09:34 +00:00
|
|
|
*/
|
|
|
|
static int
|
2017-02-01 22:38:56 +00:00
|
|
|
chipset_ready_uevent(struct controlvm_message_header *msg_hdr)
|
2016-09-19 21:09:34 +00:00
|
|
|
{
|
2017-03-28 13:34:22 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = kobject_uevent(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
KOBJ_ONLINE);
|
2017-02-01 22:38:56 +00:00
|
|
|
|
|
|
|
if (msg_hdr->flags.response_expected)
|
2017-03-28 13:34:22 +00:00
|
|
|
controlvm_respond(msg_hdr, res);
|
2017-02-01 22:38:56 +00:00
|
|
|
|
2017-03-28 13:34:22 +00:00
|
|
|
return res;
|
2016-09-19 21:09:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 22:38:56 +00:00
|
|
|
/*
|
|
|
|
* chipset_selftest_uevent() - sends chipset_selftest action
|
|
|
|
*
|
|
|
|
* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative on failure
|
|
|
|
*/
|
2016-09-19 21:09:34 +00:00
|
|
|
static int
|
2017-02-01 22:38:56 +00:00
|
|
|
chipset_selftest_uevent(struct controlvm_message_header *msg_hdr)
|
2016-09-19 21:09:34 +00:00
|
|
|
{
|
|
|
|
char env_selftest[20];
|
|
|
|
char *envp[] = { env_selftest, NULL };
|
2017-03-28 13:34:22 +00:00
|
|
|
int res;
|
2016-09-19 21:09:34 +00:00
|
|
|
|
|
|
|
sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
|
2017-03-28 13:34:22 +00:00
|
|
|
res = kobject_uevent_env(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
KOBJ_CHANGE, envp);
|
2017-02-01 22:38:56 +00:00
|
|
|
|
|
|
|
if (msg_hdr->flags.response_expected)
|
2017-03-28 13:34:22 +00:00
|
|
|
controlvm_respond(msg_hdr, res);
|
2017-02-01 22:38:56 +00:00
|
|
|
|
2017-03-28 13:34:22 +00:00
|
|
|
return res;
|
2016-09-19 21:09:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 22:38:56 +00:00
|
|
|
/*
|
|
|
|
* chipset_notready_uevent() - sends chipset_notready action
|
2016-09-19 21:09:34 +00:00
|
|
|
*
|
|
|
|
* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
|
|
|
|
*
|
2017-02-01 22:38:56 +00:00
|
|
|
* Return: 0 on success, negative on failure
|
2016-09-19 21:09:34 +00:00
|
|
|
*/
|
|
|
|
static int
|
2017-02-01 22:38:56 +00:00
|
|
|
chipset_notready_uevent(struct controlvm_message_header *msg_hdr)
|
2016-09-19 21:09:34 +00:00
|
|
|
{
|
2017-03-28 13:34:22 +00:00
|
|
|
int res;
|
2016-09-19 21:09:34 +00:00
|
|
|
|
2017-03-28 13:34:22 +00:00
|
|
|
res = kobject_uevent(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
KOBJ_OFFLINE);
|
2016-09-19 21:09:34 +00:00
|
|
|
if (msg_hdr->flags.response_expected)
|
2017-03-28 13:34:22 +00:00
|
|
|
controlvm_respond(msg_hdr, res);
|
2016-09-19 21:09:34 +00:00
|
|
|
|
2017-03-28 13:34:22 +00:00
|
|
|
return res;
|
2016-09-19 21:09:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 15:26:59 +00:00
|
|
|
static unsigned int
|
2015-05-13 17:22:10 +00:00
|
|
|
issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes)
|
|
|
|
{
|
|
|
|
struct vmcall_io_controlvm_addr_params params;
|
|
|
|
int result = VMCALL_SUCCESS;
|
|
|
|
u64 physaddr;
|
|
|
|
|
|
|
|
physaddr = virt_to_phys(¶ms);
|
2017-03-17 15:27:04 +00:00
|
|
|
ISSUE_IO_VMCALL(VMCALL_CONTROLVM_ADDR, physaddr, result);
|
2015-05-13 17:22:10 +00:00
|
|
|
if (VMCALL_SUCCESSFUL(result)) {
|
|
|
|
*control_addr = params.address;
|
|
|
|
*control_bytes = params.channel_bytes;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
static u64 controlvm_get_channel_address(void)
|
2014-07-17 16:39:57 +00:00
|
|
|
{
|
2014-07-31 16:00:51 +00:00
|
|
|
u64 addr = 0;
|
2014-07-31 16:00:50 +00:00
|
|
|
u32 size = 0;
|
2014-07-17 16:39:57 +00:00
|
|
|
|
2015-03-04 17:14:25 +00:00
|
|
|
if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size)))
|
2014-07-17 16:39:57 +00:00
|
|
|
return 0;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2014-07-17 16:39:57 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2014-03-04 13:58:07 +00:00
|
|
|
static void
|
|
|
|
setup_crash_devices_work_queue(struct work_struct *work)
|
|
|
|
{
|
2015-03-16 17:58:33 +00:00
|
|
|
struct controlvm_message local_crash_bus_msg;
|
|
|
|
struct controlvm_message local_crash_dev_msg;
|
2014-10-23 18:30:31 +00:00
|
|
|
struct controlvm_message msg;
|
2015-03-16 17:58:33 +00:00
|
|
|
u32 local_crash_msg_offset;
|
|
|
|
u16 local_crash_msg_count;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_ENTRY_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
/* send init chipset msg */
|
2014-10-23 18:30:26 +00:00
|
|
|
msg.hdr.id = CONTROLVM_CHIPSET_INIT;
|
2014-10-23 18:30:25 +00:00
|
|
|
msg.cmd.init_chipset.bus_count = 23;
|
|
|
|
msg.cmd.init_chipset.switch_count = 0;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
chipset_init(&msg);
|
|
|
|
|
|
|
|
/* get saved message count */
|
2017-02-21 17:53:29 +00:00
|
|
|
if (visorchannel_read(chipset_dev->controlvm_channel,
|
2014-10-23 18:30:34 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
saved_crash_message_count),
|
2015-03-16 17:58:33 +00:00
|
|
|
&local_crash_msg_count, sizeof(u16)) < 0) {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_CTRL_RD_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:58:33 +00:00
|
|
|
if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
|
2016-12-01 06:31:08 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_COUNT_FAILURE_PC, 0,
|
|
|
|
local_crash_msg_count,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get saved crash message offset */
|
2017-02-21 17:53:29 +00:00
|
|
|
if (visorchannel_read(chipset_dev->controlvm_channel,
|
2014-10-23 18:30:34 +00:00
|
|
|
offsetof(struct spar_controlvm_channel_protocol,
|
|
|
|
saved_crash_message_offset),
|
2015-03-16 17:58:33 +00:00
|
|
|
&local_crash_msg_offset, sizeof(u32)) < 0) {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_CTRL_RD_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read create device message for storage bus offset */
|
2017-02-21 17:53:29 +00:00
|
|
|
if (visorchannel_read(chipset_dev->controlvm_channel,
|
2015-03-16 17:58:33 +00:00
|
|
|
local_crash_msg_offset,
|
|
|
|
&local_crash_bus_msg,
|
2014-10-23 18:30:31 +00:00
|
|
|
sizeof(struct controlvm_message)) < 0) {
|
2016-12-01 06:31:12 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_RD_BUS_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read create device message for storage device */
|
2017-02-21 17:53:29 +00:00
|
|
|
if (visorchannel_read(chipset_dev->controlvm_channel,
|
2015-03-16 17:58:33 +00:00
|
|
|
local_crash_msg_offset +
|
2014-10-23 18:30:31 +00:00
|
|
|
sizeof(struct controlvm_message),
|
2015-03-16 17:58:33 +00:00
|
|
|
&local_crash_dev_msg,
|
2014-10-23 18:30:31 +00:00
|
|
|
sizeof(struct controlvm_message)) < 0) {
|
2016-12-01 06:31:12 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_RD_DEV_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reuse IOVM create bus message */
|
2015-05-05 22:35:57 +00:00
|
|
|
if (local_crash_bus_msg.cmd.create_bus.channel_addr) {
|
2015-03-16 17:58:33 +00:00
|
|
|
bus_create(&local_crash_bus_msg);
|
2015-03-16 17:58:19 +00:00
|
|
|
} else {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_BUS_NULL_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reuse create device message for storage device */
|
2015-05-05 22:35:57 +00:00
|
|
|
if (local_crash_dev_msg.cmd.create_device.channel_addr) {
|
2015-03-16 17:58:33 +00:00
|
|
|
my_device_create(&local_crash_dev_msg);
|
2015-03-16 17:58:19 +00:00
|
|
|
} else {
|
2016-12-01 06:31:07 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_DEV_NULL_FAILURE_PC, 0, 0,
|
2016-12-01 06:31:13 +00:00
|
|
|
DIAG_SEVERITY_ERR);
|
2014-03-04 13:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CRASH_DEV_EXIT_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_create_response(struct visor_device *bus_info, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-06-13 15:40:48 +00:00
|
|
|
if (response >= 0)
|
2015-06-01 17:00:27 +00:00
|
|
|
bus_info->state.created = 1;
|
|
|
|
|
|
|
|
bus_responder(CONTROLVM_BUS_CREATE, bus_info->pending_msg_hdr,
|
|
|
|
response);
|
|
|
|
|
|
|
|
kfree(bus_info->pending_msg_hdr);
|
|
|
|
bus_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2015-06-04 13:22:41 +00:00
|
|
|
bus_destroy_response(struct visor_device *bus_info, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-06-01 17:00:27 +00:00
|
|
|
bus_responder(CONTROLVM_BUS_DESTROY, bus_info->pending_msg_hdr,
|
|
|
|
response);
|
|
|
|
|
|
|
|
kfree(bus_info->pending_msg_hdr);
|
|
|
|
bus_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2015-06-04 13:22:42 +00:00
|
|
|
device_create_response(struct visor_device *dev_info, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-06-01 17:00:27 +00:00
|
|
|
if (response >= 0)
|
|
|
|
dev_info->state.created = 1;
|
|
|
|
|
|
|
|
device_responder(CONTROLVM_DEVICE_CREATE, dev_info->pending_msg_hdr,
|
|
|
|
response);
|
|
|
|
|
|
|
|
kfree(dev_info->pending_msg_hdr);
|
2015-07-09 17:27:41 +00:00
|
|
|
dev_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2015-06-04 13:22:42 +00:00
|
|
|
device_destroy_response(struct visor_device *dev_info, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2015-06-01 17:00:27 +00:00
|
|
|
device_responder(CONTROLVM_DEVICE_DESTROY, dev_info->pending_msg_hdr,
|
|
|
|
response);
|
|
|
|
|
|
|
|
kfree(dev_info->pending_msg_hdr);
|
|
|
|
dev_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2016-06-11 01:48:22 +00:00
|
|
|
device_pause_response(struct visor_device *dev_info,
|
|
|
|
int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
|
|
|
device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
|
2015-05-13 17:22:25 +00:00
|
|
|
dev_info, response,
|
2014-10-23 18:30:13 +00:00
|
|
|
segment_state_standby);
|
2015-06-01 17:00:27 +00:00
|
|
|
|
|
|
|
kfree(dev_info->pending_msg_hdr);
|
|
|
|
dev_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 01:48:21 +00:00
|
|
|
void
|
2015-06-04 13:22:42 +00:00
|
|
|
device_resume_response(struct visor_device *dev_info, int response)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
|
|
|
device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
|
2015-05-13 17:22:25 +00:00
|
|
|
dev_info, response,
|
2014-10-23 18:30:13 +00:00
|
|
|
segment_state_running);
|
2015-06-01 17:00:27 +00:00
|
|
|
|
|
|
|
kfree(dev_info->pending_msg_hdr);
|
|
|
|
dev_info->pending_msg_hdr = NULL;
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:09:22 +00:00
|
|
|
static struct parser_context *
|
|
|
|
parser_init_byte_stream(u64 addr, u32 bytes, bool local, bool *retry)
|
|
|
|
{
|
|
|
|
int allocbytes = sizeof(struct parser_context) + bytes;
|
|
|
|
struct parser_context *ctx;
|
|
|
|
|
2016-12-22 16:09:00 +00:00
|
|
|
*retry = false;
|
2016-09-19 21:09:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* alloc an 0 extra byte to ensure payload is
|
|
|
|
* '\0'-terminated
|
|
|
|
*/
|
|
|
|
allocbytes++;
|
2017-02-21 17:53:29 +00:00
|
|
|
if ((chipset_dev->controlvm_payload_bytes_buffered + bytes)
|
2016-09-19 21:09:22 +00:00
|
|
|
> MAX_CONTROLVM_PAYLOAD_BYTES) {
|
2016-12-22 16:09:00 +00:00
|
|
|
*retry = true;
|
2016-09-19 21:09:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ctx = kzalloc(allocbytes, GFP_KERNEL | __GFP_NORETRY);
|
|
|
|
if (!ctx) {
|
2016-12-22 16:09:00 +00:00
|
|
|
*retry = true;
|
2016-09-19 21:09:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->allocbytes = allocbytes;
|
|
|
|
ctx->param_bytes = bytes;
|
|
|
|
ctx->curr = NULL;
|
|
|
|
ctx->bytes_remaining = 0;
|
|
|
|
ctx->byte_stream = false;
|
|
|
|
if (local) {
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
if (addr > virt_to_phys(high_memory - 1))
|
|
|
|
goto err_finish_ctx;
|
|
|
|
p = __va((unsigned long)(addr));
|
|
|
|
memcpy(ctx->data, p, bytes);
|
|
|
|
} else {
|
|
|
|
void *mapping = memremap(addr, bytes, MEMREMAP_WB);
|
|
|
|
|
|
|
|
if (!mapping)
|
|
|
|
goto err_finish_ctx;
|
|
|
|
memcpy(ctx->data, mapping, bytes);
|
|
|
|
memunmap(mapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->byte_stream = true;
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev->controlvm_payload_bytes_buffered += ctx->param_bytes;
|
2016-09-19 21:09:22 +00:00
|
|
|
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
err_finish_ctx:
|
|
|
|
parser_done(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:21 +00:00
|
|
|
* handle_command() - process a controlvm message
|
|
|
|
* @inmsg: the message to process
|
|
|
|
* @channel_addr: address of the controlvm channel
|
|
|
|
*
|
|
|
|
* Return:
|
2017-03-28 13:34:19 +00:00
|
|
|
* 0 - Successfully processed the message
|
|
|
|
* -EAGAIN - ControlVM message was not processed and should be retried
|
|
|
|
* reading the next controlvm message; a scenario where this can
|
|
|
|
* occur is when we need to throttle the allocation of memory in
|
|
|
|
* which to copy out controlvm payload data.
|
|
|
|
* < 0 - error: ControlVM message was processed but an error occurred.
|
2016-09-19 21:09:21 +00:00
|
|
|
*/
|
2017-03-28 13:34:19 +00:00
|
|
|
static int
|
2016-09-19 21:09:21 +00:00
|
|
|
handle_command(struct controlvm_message inmsg, u64 channel_addr)
|
|
|
|
{
|
|
|
|
struct controlvm_message_packet *cmd = &inmsg.cmd;
|
|
|
|
u64 parm_addr;
|
|
|
|
u32 parm_bytes;
|
|
|
|
struct parser_context *parser_ctx = NULL;
|
|
|
|
bool local_addr;
|
|
|
|
struct controlvm_message ackmsg;
|
2017-03-28 13:34:19 +00:00
|
|
|
int err = 0;
|
2016-09-19 21:09:21 +00:00
|
|
|
|
|
|
|
/* create parsing context if necessary */
|
|
|
|
local_addr = (inmsg.hdr.flags.test_message == 1);
|
|
|
|
if (channel_addr == 0)
|
2017-03-28 13:34:19 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-09-19 21:09:21 +00:00
|
|
|
parm_addr = channel_addr + inmsg.hdr.payload_vm_offset;
|
|
|
|
parm_bytes = inmsg.hdr.payload_bytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parameter and channel addresses within test messages actually lie
|
|
|
|
* within our OS-controlled memory. We need to know that, because it
|
|
|
|
* makes a difference in how we compute the virtual address.
|
|
|
|
*/
|
|
|
|
if (parm_addr && parm_bytes) {
|
|
|
|
bool retry = false;
|
|
|
|
|
|
|
|
parser_ctx =
|
|
|
|
parser_init_byte_stream(parm_addr, parm_bytes,
|
|
|
|
local_addr, &retry);
|
|
|
|
if (!parser_ctx && retry)
|
2017-03-28 13:34:19 +00:00
|
|
|
return -EAGAIN;
|
2016-09-19 21:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!local_addr) {
|
|
|
|
controlvm_init_response(&ackmsg, &inmsg.hdr,
|
|
|
|
CONTROLVM_RESP_SUCCESS);
|
2017-03-28 13:34:19 +00:00
|
|
|
err = visorchannel_signalinsert(chipset_dev->controlvm_channel,
|
|
|
|
CONTROLVM_QUEUE_ACK,
|
|
|
|
&ackmsg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2016-09-19 21:09:21 +00:00
|
|
|
}
|
|
|
|
switch (inmsg.hdr.id) {
|
|
|
|
case CONTROLVM_CHIPSET_INIT:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = chipset_init(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_BUS_CREATE:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = bus_create(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_BUS_DESTROY:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = bus_destroy(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_BUS_CONFIGURE:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = bus_configure(&inmsg, parser_ctx);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_DEVICE_CREATE:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = my_device_create(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_DEVICE_CHANGESTATE:
|
|
|
|
if (cmd->device_change_state.flags.phys_device) {
|
2017-03-28 13:34:19 +00:00
|
|
|
err = parahotplug_process_message(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* save the hdr and cmd structures for later use
|
|
|
|
* when sending back the response to Command
|
|
|
|
*/
|
2017-03-28 13:34:19 +00:00
|
|
|
err = my_device_changestate(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTROLVM_DEVICE_DESTROY:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = my_device_destroy(&inmsg);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_DEVICE_CONFIGURE:
|
2017-03-28 13:34:19 +00:00
|
|
|
/* no op just send a respond that we passed */
|
2016-09-19 21:09:21 +00:00
|
|
|
if (inmsg.hdr.flags.response_expected)
|
|
|
|
controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
|
|
|
|
break;
|
|
|
|
case CONTROLVM_CHIPSET_READY:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = chipset_ready_uevent(&inmsg.hdr);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_CHIPSET_SELFTEST:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = chipset_selftest_uevent(&inmsg.hdr);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
case CONTROLVM_CHIPSET_STOP:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = chipset_notready_uevent(&inmsg.hdr);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-28 13:34:19 +00:00
|
|
|
err = -ENOMSG;
|
2016-09-19 21:09:21 +00:00
|
|
|
if (inmsg.hdr.flags.response_expected)
|
2017-03-28 13:34:19 +00:00
|
|
|
controlvm_respond(&inmsg.hdr,
|
|
|
|
-CONTROLVM_RESP_ID_UNKNOWN);
|
2016-09-19 21:09:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser_ctx) {
|
|
|
|
parser_done(parser_ctx);
|
|
|
|
parser_ctx = NULL;
|
|
|
|
}
|
2017-03-28 13:34:19 +00:00
|
|
|
return err;
|
2016-09-19 21:09:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:23 +00:00
|
|
|
* read_controlvm_event() - retreives the next message from the
|
|
|
|
* CONTROLVM_QUEUE_EVENT queue in the controlvm
|
|
|
|
* channel
|
|
|
|
* @msg: pointer to the retrieved message
|
|
|
|
*
|
2017-03-28 13:34:19 +00:00
|
|
|
* Return: 0 if valid message was retrieved or -error
|
2016-09-19 21:09:23 +00:00
|
|
|
*/
|
2017-03-28 13:34:19 +00:00
|
|
|
static int
|
2016-09-19 21:09:23 +00:00
|
|
|
read_controlvm_event(struct controlvm_message *msg)
|
|
|
|
{
|
2017-03-28 13:34:19 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = visorchannel_signalremove(chipset_dev->controlvm_channel,
|
|
|
|
CONTROLVM_QUEUE_EVENT, msg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* got a message */
|
|
|
|
if (msg->hdr.flags.test_message == 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
2016-09-19 21:09:23 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:25 +00:00
|
|
|
/*
|
2016-09-19 21:09:24 +00:00
|
|
|
* parahotplug_process_list() - remove any request from the list that's been on
|
|
|
|
* there too long and respond with an error
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
parahotplug_process_list(void)
|
|
|
|
{
|
|
|
|
struct list_head *pos;
|
|
|
|
struct list_head *tmp;
|
|
|
|
|
|
|
|
spin_lock(¶hotplug_request_list_lock);
|
|
|
|
|
|
|
|
list_for_each_safe(pos, tmp, ¶hotplug_request_list) {
|
|
|
|
struct parahotplug_request *req =
|
|
|
|
list_entry(pos, struct parahotplug_request, list);
|
|
|
|
|
|
|
|
if (!time_after_eq(jiffies, req->expiration))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(pos);
|
|
|
|
if (req->msg.hdr.flags.response_expected)
|
|
|
|
controlvm_respond_physdev_changestate(
|
|
|
|
&req->msg.hdr,
|
2016-12-22 16:08:58 +00:00
|
|
|
CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT,
|
2016-09-19 21:09:24 +00:00
|
|
|
req->msg.cmd.device_change_state.state);
|
|
|
|
parahotplug_request_destroy(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(¶hotplug_request_list_lock);
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:09:20 +00:00
|
|
|
static void
|
|
|
|
controlvm_periodic_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct controlvm_message inmsg;
|
2017-03-28 13:34:20 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Drain the RESPONSE queue make it empty */
|
|
|
|
do {
|
|
|
|
err = visorchannel_signalremove(chipset_dev->controlvm_channel,
|
|
|
|
CONTROLVM_QUEUE_RESPONSE,
|
|
|
|
&inmsg);
|
|
|
|
} while (!err);
|
|
|
|
|
|
|
|
if (err != -EAGAIN)
|
|
|
|
goto schedule_out;
|
|
|
|
|
|
|
|
if (chipset_dev->controlvm_pending_msg_valid) {
|
|
|
|
/*
|
|
|
|
* we throttled processing of a prior
|
|
|
|
* msg, so try to process it again
|
|
|
|
* rather than reading a new one
|
|
|
|
*/
|
|
|
|
inmsg = chipset_dev->controlvm_pending_msg;
|
|
|
|
chipset_dev->controlvm_pending_msg_valid = false;
|
|
|
|
err = 0;
|
|
|
|
} else {
|
|
|
|
err = read_controlvm_event(&inmsg);
|
2016-09-19 21:09:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 13:34:20 +00:00
|
|
|
while (!err) {
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev->most_recent_message_jiffies = jiffies;
|
2017-03-28 13:34:20 +00:00
|
|
|
err = handle_command(inmsg,
|
|
|
|
visorchannel_get_physaddr
|
|
|
|
(chipset_dev->controlvm_channel));
|
|
|
|
if (err == -EAGAIN) {
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev->controlvm_pending_msg = inmsg;
|
|
|
|
chipset_dev->controlvm_pending_msg_valid = true;
|
2017-03-28 13:34:20 +00:00
|
|
|
break;
|
2016-09-19 21:09:20 +00:00
|
|
|
}
|
2017-03-28 13:34:20 +00:00
|
|
|
|
|
|
|
err = read_controlvm_event(&inmsg);
|
2016-09-19 21:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* parahotplug_worker */
|
|
|
|
parahotplug_process_list();
|
|
|
|
|
2017-03-28 13:34:20 +00:00
|
|
|
schedule_out:
|
2017-02-21 17:53:29 +00:00
|
|
|
if (time_after(jiffies, chipset_dev->most_recent_message_jiffies +
|
|
|
|
(HZ * MIN_IDLE_SECONDS))) {
|
2016-09-19 21:09:20 +00:00
|
|
|
/*
|
|
|
|
* it's been longer than MIN_IDLE_SECONDS since we
|
|
|
|
* processed our last controlvm message; slow down the
|
|
|
|
* polling
|
|
|
|
*/
|
2017-02-21 17:53:29 +00:00
|
|
|
if (chipset_dev->poll_jiffies !=
|
|
|
|
POLLJIFFIES_CONTROLVMCHANNEL_SLOW)
|
|
|
|
chipset_dev->poll_jiffies =
|
|
|
|
POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
|
2016-09-19 21:09:20 +00:00
|
|
|
} else {
|
2017-02-21 17:53:29 +00:00
|
|
|
if (chipset_dev->poll_jiffies !=
|
|
|
|
POLLJIFFIES_CONTROLVMCHANNEL_FAST)
|
|
|
|
chipset_dev->poll_jiffies =
|
|
|
|
POLLJIFFIES_CONTROLVMCHANNEL_FAST;
|
2016-09-19 21:09:20 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
schedule_delayed_work(&chipset_dev->periodic_controlvm_work,
|
|
|
|
chipset_dev->poll_jiffies);
|
2016-09-19 21:09:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:02 +00:00
|
|
|
static int
|
|
|
|
visorchipset_init(struct acpi_device *acpi_device)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2016-04-05 03:31:37 +00:00
|
|
|
int err = -ENODEV;
|
2015-05-05 22:37:04 +00:00
|
|
|
u64 addr;
|
2015-05-13 17:21:57 +00:00
|
|
|
uuid_le uuid = SPAR_CONTROLVM_CHANNEL_PROTOCOL_UUID;
|
2017-02-21 17:53:29 +00:00
|
|
|
struct visorchannel *controlvm_channel;
|
2015-05-13 17:21:57 +00:00
|
|
|
|
|
|
|
addr = controlvm_get_channel_address();
|
|
|
|
if (!addr)
|
2016-04-05 03:31:37 +00:00
|
|
|
goto error;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev = kzalloc(sizeof(*chipset_dev), GFP_KERNEL);
|
|
|
|
if (!chipset_dev)
|
2016-04-05 03:31:37 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
acpi_device->driver_data = chipset_dev;
|
|
|
|
|
|
|
|
chipset_dev->acpi_device = acpi_device;
|
|
|
|
chipset_dev->poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
|
|
|
|
controlvm_channel = visorchannel_create_with_lock(addr,
|
|
|
|
0, GFP_KERNEL, uuid);
|
|
|
|
|
|
|
|
if (!controlvm_channel)
|
|
|
|
goto error_free_chipset_dev;
|
|
|
|
|
|
|
|
chipset_dev->controlvm_channel = controlvm_channel;
|
2017-02-21 17:53:31 +00:00
|
|
|
|
|
|
|
err = sysfs_create_groups(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
visorchipset_dev_groups);
|
|
|
|
if (err < 0)
|
|
|
|
goto error_destroy_channel;
|
|
|
|
|
2017-02-01 22:39:00 +00:00
|
|
|
if (!SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
|
|
|
|
visorchannel_get_header(controlvm_channel)))
|
2017-02-21 17:53:31 +00:00
|
|
|
goto error_delete_groups;
|
2014-07-17 16:39:58 +00:00
|
|
|
|
2015-05-05 22:36:39 +00:00
|
|
|
/* if booting in a crash kernel */
|
|
|
|
if (is_kdump_kernel())
|
2017-02-21 17:53:29 +00:00
|
|
|
INIT_DELAYED_WORK(&chipset_dev->periodic_controlvm_work,
|
2015-05-05 22:36:39 +00:00
|
|
|
setup_crash_devices_work_queue);
|
|
|
|
else
|
2017-02-21 17:53:29 +00:00
|
|
|
INIT_DELAYED_WORK(&chipset_dev->periodic_controlvm_work,
|
2015-05-05 22:36:39 +00:00
|
|
|
controlvm_periodic_work);
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
chipset_dev->most_recent_message_jiffies = jiffies;
|
|
|
|
chipset_dev->poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
|
|
|
|
schedule_delayed_work(&chipset_dev->periodic_controlvm_work,
|
|
|
|
chipset_dev->poll_jiffies);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CHIPSET_INIT_SUCCESS_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2015-05-05 22:36:15 +00:00
|
|
|
|
2016-04-05 03:31:37 +00:00
|
|
|
err = visorbus_init();
|
|
|
|
if (err < 0)
|
2017-02-21 17:53:31 +00:00
|
|
|
goto error_cancel_work;
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2016-04-05 03:31:37 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_cancel_work:
|
2017-02-21 17:53:29 +00:00
|
|
|
cancel_delayed_work_sync(&chipset_dev->periodic_controlvm_work);
|
2016-04-05 03:31:37 +00:00
|
|
|
|
2017-02-21 17:53:31 +00:00
|
|
|
error_delete_groups:
|
|
|
|
sysfs_remove_groups(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
visorchipset_dev_groups);
|
|
|
|
|
2016-04-05 03:31:37 +00:00
|
|
|
error_destroy_channel:
|
2017-02-21 17:53:29 +00:00
|
|
|
visorchannel_destroy(chipset_dev->controlvm_channel);
|
|
|
|
|
|
|
|
error_free_chipset_dev:
|
|
|
|
kfree(chipset_dev);
|
2016-04-05 03:31:37 +00:00
|
|
|
|
|
|
|
error:
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(CHIPSET_INIT_FAILURE_PC, 0, err, DIAG_SEVERITY_ERR);
|
2016-04-05 03:31:37 +00:00
|
|
|
return err;
|
2015-05-05 22:36:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:02 +00:00
|
|
|
static int
|
|
|
|
visorchipset_exit(struct acpi_device *acpi_device)
|
2014-03-04 13:58:07 +00:00
|
|
|
{
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(DRIVER_EXIT_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
2015-05-05 22:36:15 +00:00
|
|
|
visorbus_exit();
|
2017-02-21 17:53:29 +00:00
|
|
|
cancel_delayed_work_sync(&chipset_dev->periodic_controlvm_work);
|
2017-02-21 17:53:31 +00:00
|
|
|
sysfs_remove_groups(&chipset_dev->acpi_device->dev.kobj,
|
|
|
|
visorchipset_dev_groups);
|
|
|
|
|
2017-02-21 17:53:29 +00:00
|
|
|
visorchannel_destroy(chipset_dev->controlvm_channel);
|
|
|
|
kfree(chipset_dev);
|
|
|
|
|
2016-12-01 06:31:13 +00:00
|
|
|
POSTCODE_LINUX(DRIVER_EXIT_PC, 0, 0, DIAG_SEVERITY_PRINT);
|
2015-05-05 22:37:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct acpi_device_id unisys_device_ids[] = {
|
|
|
|
{"PNP0A07", 0},
|
|
|
|
{"", 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct acpi_driver unisys_acpi_driver = {
|
|
|
|
.name = "unisys_acpi",
|
|
|
|
.class = "unisys_acpi_class",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.ids = unisys_device_ids,
|
|
|
|
.ops = {
|
|
|
|
.add = visorchipset_init,
|
|
|
|
.remove = visorchipset_exit,
|
|
|
|
},
|
|
|
|
};
|
2015-07-09 17:27:53 +00:00
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(acpi, unisys_device_ids);
|
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
static __init uint32_t visorutil_spar_detect(void)
|
|
|
|
{
|
|
|
|
unsigned int eax, ebx, ecx, edx;
|
|
|
|
|
2016-03-29 15:41:55 +00:00
|
|
|
if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
|
2015-05-05 22:37:04 +00:00
|
|
|
/* check the ID */
|
|
|
|
cpuid(UNISYS_SPAR_LEAF_ID, &eax, &ebx, &ecx, &edx);
|
|
|
|
return (ebx == UNISYS_SPAR_ID_EBX) &&
|
|
|
|
(ecx == UNISYS_SPAR_ID_ECX) &&
|
|
|
|
(edx == UNISYS_SPAR_ID_EDX);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-05-05 22:37:02 +00:00
|
|
|
|
|
|
|
static int init_unisys(void)
|
|
|
|
{
|
|
|
|
int result;
|
2015-06-13 15:40:49 +00:00
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
if (!visorutil_spar_detect())
|
2015-05-05 22:37:02 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
result = acpi_bus_register_driver(&unisys_acpi_driver);
|
|
|
|
if (result)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pr_info("Unisys Visorchipset Driver Loaded.\n");
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void exit_unisys(void)
|
|
|
|
{
|
|
|
|
acpi_bus_unregister_driver(&unisys_acpi_driver);
|
2014-03-04 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:02 +00:00
|
|
|
module_init(init_unisys);
|
|
|
|
module_exit(exit_unisys);
|
2014-03-04 13:58:07 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Unisys");
|
|
|
|
MODULE_LICENSE("GPL");
|
2016-09-26 15:03:46 +00:00
|
|
|
MODULE_DESCRIPTION("s-Par visorbus driver for virtual device buses");
|