2014-03-04 13:58:06 +00:00
|
|
|
/* visorchannel_funcs.c
|
|
|
|
*
|
2014-04-23 18:58:34 +00:00
|
|
|
* Copyright (C) 2010 - 2013 UNISYS CORPORATION
|
2014-03-04 13:58:06 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This provides Supervisor channel communication primitives, which are
|
|
|
|
* independent of the mechanism used to access the channel data. All channel
|
|
|
|
* data is accessed using the memregion abstraction. (memregion has both
|
|
|
|
* a CM2 implementation and a direct memory implementation.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
#include "visorchannel.h"
|
2014-05-06 13:58:23 +00:00
|
|
|
#include <linux/uuid.h>
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
#define MYDRVNAME "visorchannel"
|
|
|
|
|
|
|
|
struct VISORCHANNEL_Tag {
|
2014-03-05 20:52:25 +00:00
|
|
|
MEMREGION *memregion; /* from visor_memregion_create() */
|
2014-10-23 18:29:55 +00:00
|
|
|
struct channel_header chan_hdr;
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le guid;
|
2014-03-04 13:58:06 +00:00
|
|
|
ulong size;
|
|
|
|
BOOL needs_lock;
|
|
|
|
spinlock_t insert_lock;
|
|
|
|
spinlock_t remove_lock;
|
|
|
|
|
|
|
|
struct {
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header req_queue;
|
|
|
|
struct signal_queue_header rsp_queue;
|
|
|
|
struct signal_queue_header event_queue;
|
|
|
|
struct signal_queue_header ack_queue;
|
2014-03-04 13:58:06 +00:00
|
|
|
} safe_uis_queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Creates the VISORCHANNEL abstraction for a data area in memory, but does
|
|
|
|
* NOT modify this data area.
|
|
|
|
*/
|
|
|
|
static VISORCHANNEL *
|
|
|
|
visorchannel_create_guts(HOSTADDRESS physaddr, ulong channelBytes,
|
2014-05-06 13:58:23 +00:00
|
|
|
VISORCHANNEL *parent, ulong off, uuid_le guid,
|
2014-03-04 13:58:06 +00:00
|
|
|
BOOL needs_lock)
|
|
|
|
{
|
|
|
|
VISORCHANNEL *p = NULL;
|
|
|
|
void *rc = NULL;
|
|
|
|
|
|
|
|
p = kmalloc(sizeof(VISORCHANNEL), GFP_KERNEL|__GFP_NORETRY);
|
2014-03-19 18:06:24 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
ERRDRV("allocation failed: (status=0)\n");
|
|
|
|
rc = NULL;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
p->memregion = NULL;
|
|
|
|
p->needs_lock = needs_lock;
|
|
|
|
spin_lock_init(&p->insert_lock);
|
|
|
|
spin_lock_init(&p->remove_lock);
|
|
|
|
|
|
|
|
/* prepare chan_hdr (abstraction to read/write channel memory) */
|
|
|
|
if (parent == NULL)
|
|
|
|
p->memregion =
|
2014-10-23 18:29:55 +00:00
|
|
|
visor_memregion_create(physaddr,
|
|
|
|
sizeof(struct channel_header));
|
2014-03-04 13:58:06 +00:00
|
|
|
else
|
|
|
|
p->memregion =
|
2014-03-05 20:52:25 +00:00
|
|
|
visor_memregion_create_overlapped(parent->memregion,
|
2014-10-23 18:29:55 +00:00
|
|
|
off, sizeof(struct channel_header));
|
2014-03-19 18:06:24 +00:00
|
|
|
if (p->memregion == NULL) {
|
|
|
|
ERRDRV("visor_memregion_create failed failed: (status=0)\n");
|
|
|
|
rc = NULL;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-05 20:52:25 +00:00
|
|
|
if (visor_memregion_read(p->memregion, 0, &p->chan_hdr,
|
2014-10-23 18:29:55 +00:00
|
|
|
sizeof(struct channel_header)) < 0) {
|
2014-03-19 18:06:24 +00:00
|
|
|
ERRDRV("visor_memregion_read failed: (status=0)\n");
|
|
|
|
rc = NULL;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
if (channelBytes == 0)
|
|
|
|
/* we had better be a CLIENT of this channel */
|
2014-10-23 18:29:56 +00:00
|
|
|
channelBytes = (ulong) p->chan_hdr.size;
|
2014-05-06 13:58:23 +00:00
|
|
|
if (uuid_le_cmp(guid, NULL_UUID_LE) == 0)
|
2014-03-04 13:58:06 +00:00
|
|
|
/* we had better be a CLIENT of this channel */
|
2014-10-23 18:29:56 +00:00
|
|
|
guid = p->chan_hdr.chtype;
|
2014-03-19 18:06:24 +00:00
|
|
|
if (visor_memregion_resize(p->memregion, channelBytes) < 0) {
|
|
|
|
ERRDRV("visor_memregion_resize failed: (status=0)\n");
|
|
|
|
rc = NULL;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
p->size = channelBytes;
|
|
|
|
p->guid = guid;
|
|
|
|
|
2014-03-19 18:06:22 +00:00
|
|
|
rc = p;
|
2014-03-04 13:58:06 +00:00
|
|
|
Away:
|
|
|
|
|
|
|
|
if (rc == NULL) {
|
|
|
|
if (p != NULL) {
|
|
|
|
visorchannel_destroy(p);
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
VISORCHANNEL *
|
2014-05-06 13:58:23 +00:00
|
|
|
visorchannel_create(HOSTADDRESS physaddr, ulong channelBytes, uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return visorchannel_create_guts(physaddr, channelBytes, NULL, 0, guid,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create);
|
|
|
|
|
|
|
|
VISORCHANNEL *
|
|
|
|
visorchannel_create_with_lock(HOSTADDRESS physaddr, ulong channelBytes,
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return visorchannel_create_guts(physaddr, channelBytes, NULL, 0, guid,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create_with_lock);
|
|
|
|
|
|
|
|
VISORCHANNEL *
|
|
|
|
visorchannel_create_overlapped(ulong channelBytes,
|
2014-05-06 13:58:23 +00:00
|
|
|
VISORCHANNEL *parent, ulong off, uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return visorchannel_create_guts(0, channelBytes, parent, off, guid,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create_overlapped);
|
|
|
|
|
|
|
|
VISORCHANNEL *
|
|
|
|
visorchannel_create_overlapped_with_lock(ulong channelBytes,
|
|
|
|
VISORCHANNEL *parent, ulong off,
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return visorchannel_create_guts(0, channelBytes, parent, off, guid,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create_overlapped_with_lock);
|
|
|
|
|
|
|
|
void
|
|
|
|
visorchannel_destroy(VISORCHANNEL *channel)
|
|
|
|
{
|
|
|
|
if (channel == NULL)
|
|
|
|
return;
|
|
|
|
if (channel->memregion != NULL) {
|
2014-03-05 20:52:25 +00:00
|
|
|
visor_memregion_destroy(channel->memregion);
|
2014-03-04 13:58:06 +00:00
|
|
|
channel->memregion = NULL;
|
|
|
|
}
|
|
|
|
kfree(channel);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_destroy);
|
|
|
|
|
|
|
|
HOSTADDRESS
|
|
|
|
visorchannel_get_physaddr(VISORCHANNEL *channel)
|
|
|
|
{
|
2014-03-05 20:52:25 +00:00
|
|
|
return visor_memregion_get_physaddr(channel->memregion);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_physaddr);
|
|
|
|
|
|
|
|
ulong
|
|
|
|
visorchannel_get_nbytes(VISORCHANNEL *channel)
|
|
|
|
{
|
|
|
|
return channel->size;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_nbytes);
|
|
|
|
|
|
|
|
char *
|
2014-05-06 13:58:23 +00:00
|
|
|
visorchannel_uuid_id(uuid_le *guid, char *s)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-05-06 13:58:23 +00:00
|
|
|
sprintf(s, "%pUL", guid);
|
|
|
|
return s;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
2014-05-06 13:58:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_uuid_id);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
visorchannel_id(VISORCHANNEL *channel, char *s)
|
|
|
|
{
|
2014-05-06 13:58:23 +00:00
|
|
|
return visorchannel_uuid_id(&channel->guid, s);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_id);
|
|
|
|
|
|
|
|
char *
|
|
|
|
visorchannel_zoneid(VISORCHANNEL *channel, char *s)
|
|
|
|
{
|
2014-10-23 18:29:56 +00:00
|
|
|
return visorchannel_uuid_id(&channel->chan_hdr.zone_uuid, s);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_zoneid);
|
|
|
|
|
|
|
|
HOSTADDRESS
|
|
|
|
visorchannel_get_clientpartition(VISORCHANNEL *channel)
|
|
|
|
{
|
2014-10-23 18:29:56 +00:00
|
|
|
return channel->chan_hdr.partition_handle;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_clientpartition);
|
|
|
|
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le
|
|
|
|
visorchannel_get_uuid(VISORCHANNEL *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return channel->guid;
|
|
|
|
}
|
2014-05-06 13:58:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_uuid);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
MEMREGION *
|
|
|
|
visorchannel_get_memregion(VISORCHANNEL *channel)
|
|
|
|
{
|
|
|
|
return channel->memregion;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_memregion);
|
|
|
|
|
|
|
|
int
|
|
|
|
visorchannel_read(VISORCHANNEL *channel, ulong offset,
|
|
|
|
void *local, ulong nbytes)
|
|
|
|
{
|
2014-03-05 20:52:25 +00:00
|
|
|
int rc = visor_memregion_read(channel->memregion, offset,
|
|
|
|
local, nbytes);
|
2014-10-23 18:29:55 +00:00
|
|
|
if ((rc >= 0) && (offset == 0) &&
|
|
|
|
(nbytes >= sizeof(struct channel_header))) {
|
|
|
|
memcpy(&channel->chan_hdr, local,
|
|
|
|
sizeof(struct channel_header));
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_read);
|
|
|
|
|
|
|
|
int
|
|
|
|
visorchannel_write(VISORCHANNEL *channel, ulong offset,
|
|
|
|
void *local, ulong nbytes)
|
|
|
|
{
|
2014-10-23 18:29:55 +00:00
|
|
|
if (offset == 0 && nbytes >= sizeof(struct channel_header))
|
|
|
|
memcpy(&channel->chan_hdr, local,
|
|
|
|
sizeof(struct channel_header));
|
2014-03-05 20:52:25 +00:00
|
|
|
return visor_memregion_write(channel->memregion, offset, local, nbytes);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_write);
|
|
|
|
|
|
|
|
int
|
2014-07-29 19:09:40 +00:00
|
|
|
visorchannel_clear(VISORCHANNEL *channel, ulong offset, u8 ch, ulong nbytes)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
int bufsize = 65536;
|
|
|
|
int written = 0;
|
2014-07-29 19:09:40 +00:00
|
|
|
u8 *buf = vmalloc(bufsize);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
if (buf == NULL) {
|
|
|
|
ERRDRV("%s failed memory allocation", __func__);
|
2014-03-19 18:06:25 +00:00
|
|
|
goto Away;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
memset(buf, ch, bufsize);
|
|
|
|
while (nbytes > 0) {
|
|
|
|
ulong thisbytes = bufsize;
|
|
|
|
int x = -1;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
if (nbytes < thisbytes)
|
|
|
|
thisbytes = nbytes;
|
2014-03-05 20:52:25 +00:00
|
|
|
x = visor_memregion_write(channel->memregion, offset + written,
|
|
|
|
buf, thisbytes);
|
2014-03-19 18:06:25 +00:00
|
|
|
if (x < 0) {
|
|
|
|
rc = x;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
written += thisbytes;
|
|
|
|
nbytes -= thisbytes;
|
|
|
|
}
|
2014-03-19 18:06:25 +00:00
|
|
|
rc = 0;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
Away:
|
|
|
|
if (buf != NULL) {
|
|
|
|
vfree(buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_clear);
|
|
|
|
|
2014-05-22 17:31:09 +00:00
|
|
|
void __iomem *
|
2014-03-04 13:58:06 +00:00
|
|
|
visorchannel_get_header(VISORCHANNEL *channel)
|
|
|
|
{
|
2014-05-22 17:31:09 +00:00
|
|
|
return (void __iomem *) &(channel->chan_hdr);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_header);
|
|
|
|
|
|
|
|
/** Return offset of a specific SIGNAL_QUEUE_HEADER from the beginning of a
|
|
|
|
* channel header
|
|
|
|
*/
|
|
|
|
#define SIG_QUEUE_OFFSET(chan_hdr, q) \
|
2014-10-23 18:30:03 +00:00
|
|
|
((chan_hdr)->ch_space_offset + \
|
|
|
|
((q) * sizeof(struct signal_queue_header)))
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/** Return offset of a specific queue entry (data) from the beginning of a
|
|
|
|
* channel header
|
|
|
|
*/
|
|
|
|
#define SIG_DATA_OFFSET(chan_hdr, q, sig_hdr, slot) \
|
|
|
|
(SIG_QUEUE_OFFSET(chan_hdr, q) + (sig_hdr)->oSignalBase + \
|
|
|
|
((slot) * (sig_hdr)->SignalSize))
|
|
|
|
|
|
|
|
/** Write the contents of a specific field within a SIGNAL_QUEUE_HEADER back
|
|
|
|
* into host memory
|
|
|
|
*/
|
2014-03-05 20:52:25 +00:00
|
|
|
#define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD) \
|
|
|
|
(visor_memregion_write(channel->memregion, \
|
|
|
|
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)+ \
|
2014-10-23 18:30:03 +00:00
|
|
|
offsetof(struct signal_queue_header, FIELD),\
|
2014-03-05 20:52:25 +00:00
|
|
|
&((sig_hdr)->FIELD), \
|
|
|
|
sizeof((sig_hdr)->FIELD)) >= 0)
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
static BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
sig_read_header(VISORCHANNEL *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
2014-10-23 18:29:56 +00:00
|
|
|
if (channel->chan_hdr.ch_space_offset < sizeof(struct channel_header)) {
|
2014-03-19 18:06:24 +00:00
|
|
|
ERRDRV("oChannelSpace too small: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */
|
|
|
|
|
2014-03-05 20:52:25 +00:00
|
|
|
if (visor_memregion_read(channel->memregion,
|
|
|
|
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue),
|
2014-10-23 18:30:03 +00:00
|
|
|
sig_hdr,
|
|
|
|
sizeof(struct signal_queue_header)) < 0) {
|
2014-03-04 13:58:06 +00:00
|
|
|
ERRDRV("queue=%d SIG_QUEUE_OFFSET=%d",
|
|
|
|
queue, (int)SIG_QUEUE_OFFSET(&channel->chan_hdr, queue));
|
2014-03-19 18:06:24 +00:00
|
|
|
ERRDRV("visor_memregion_read of signal queue failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
2014-03-19 18:06:21 +00:00
|
|
|
rc = TRUE;
|
2014-03-04 13:58:06 +00:00
|
|
|
Away:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
sig_do_data(VISORCHANNEL *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr, u32 slot, void *data,
|
|
|
|
BOOL is_write)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
|
|
|
|
sig_hdr, slot);
|
|
|
|
if (is_write) {
|
2014-03-05 20:52:25 +00:00
|
|
|
if (visor_memregion_write(channel->memregion,
|
|
|
|
signal_data_offset,
|
2014-03-19 18:06:24 +00:00
|
|
|
data, sig_hdr->SignalSize) < 0) {
|
|
|
|
ERRDRV("visor_memregion_write of signal data failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
} else {
|
2014-03-05 20:52:25 +00:00
|
|
|
if (visor_memregion_read(channel->memregion, signal_data_offset,
|
2014-03-19 18:06:24 +00:00
|
|
|
data, sig_hdr->SignalSize) < 0) {
|
|
|
|
ERRDRV("visor_memregion_read of signal data failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
2014-03-19 18:06:21 +00:00
|
|
|
rc = TRUE;
|
2014-03-04 13:58:06 +00:00
|
|
|
Away:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
sig_read_data(VISORCHANNEL *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr, u32 slot, void *data)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return sig_do_data(channel, queue, sig_hdr, slot, data, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
sig_write_data(VISORCHANNEL *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr, u32 slot, void *data)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return sig_do_data(channel, queue, sig_hdr, slot, data, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char
|
2014-10-23 18:30:03 +00:00
|
|
|
safe_sig_queue_validate(struct signal_queue_header *psafe_sqh,
|
|
|
|
struct signal_queue_header *punsafe_sqh,
|
2014-07-31 16:00:50 +00:00
|
|
|
u32 *phead, u32 *ptail)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
if ((*phead >= psafe_sqh->MaxSignalSlots)
|
|
|
|
|| (*ptail >= psafe_sqh->MaxSignalSlots)) {
|
|
|
|
/* Choose 0 or max, maybe based on current tail value */
|
|
|
|
*phead = 0;
|
|
|
|
*ptail = 0;
|
|
|
|
|
|
|
|
/* Sync with client as necessary */
|
|
|
|
punsafe_sqh->Head = *phead;
|
|
|
|
punsafe_sqh->Tail = *ptail;
|
|
|
|
|
|
|
|
ERRDRV("safe_sig_queue_validate: head = 0x%x, tail = 0x%x, MaxSlots = 0x%x",
|
|
|
|
*phead, *ptail, psafe_sqh->MaxSignalSlots);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} /* end safe_sig_queue_validate */
|
|
|
|
|
|
|
|
BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
visorchannel_signalremove(VISORCHANNEL *channel, u32 queue, void *msg)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
if (channel->needs_lock)
|
|
|
|
spin_lock(&channel->remove_lock);
|
|
|
|
|
2014-03-19 18:06:21 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr)) {
|
|
|
|
rc = FALSE;
|
|
|
|
goto Away;
|
|
|
|
}
|
|
|
|
if (sig_hdr.Head == sig_hdr.Tail) {
|
|
|
|
rc = FALSE; /* no signals to remove */
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
sig_hdr.Tail = (sig_hdr.Tail + 1) % sig_hdr.MaxSignalSlots;
|
2014-03-19 18:06:24 +00:00
|
|
|
if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.Tail, msg)) {
|
|
|
|
ERRDRV("sig_read_data failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
sig_hdr.NumSignalsReceived++;
|
|
|
|
|
|
|
|
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
|
|
|
|
* update host memory.
|
|
|
|
*/
|
2014-08-03 02:03:38 +00:00
|
|
|
mb(); /* required for channel synch */
|
2014-03-19 18:06:24 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Tail)) {
|
|
|
|
ERRDRV("visor_memregion_write of Tail failed: (status=%d)\n",
|
|
|
|
rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsReceived)) {
|
|
|
|
ERRDRV("visor_memregion_write of NumSignalsReceived failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-19 18:06:21 +00:00
|
|
|
rc = TRUE;
|
2014-03-04 13:58:06 +00:00
|
|
|
Away:
|
|
|
|
if (channel->needs_lock)
|
|
|
|
spin_unlock(&channel->remove_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalremove);
|
|
|
|
|
|
|
|
BOOL
|
2014-07-31 16:00:50 +00:00
|
|
|
visorchannel_signalinsert(VISORCHANNEL *channel, u32 queue, void *msg)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
if (channel->needs_lock)
|
|
|
|
spin_lock(&channel->insert_lock);
|
|
|
|
|
2014-03-19 18:06:21 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr)) {
|
|
|
|
rc = FALSE;
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
sig_hdr.Head = ((sig_hdr.Head + 1) % sig_hdr.MaxSignalSlots);
|
|
|
|
if (sig_hdr.Head == sig_hdr.Tail) {
|
|
|
|
sig_hdr.NumOverflows++;
|
2014-03-19 18:06:24 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumOverflows)) {
|
|
|
|
ERRDRV("visor_memregion_write of NumOverflows failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-19 18:06:21 +00:00
|
|
|
rc = FALSE;
|
|
|
|
goto Away;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 18:06:24 +00:00
|
|
|
if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.Head, msg)) {
|
|
|
|
ERRDRV("sig_write_data failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
sig_hdr.NumSignalsSent++;
|
|
|
|
|
|
|
|
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
|
|
|
|
* update host memory.
|
|
|
|
*/
|
2014-08-03 02:03:38 +00:00
|
|
|
mb(); /* required for channel synch */
|
2014-03-19 18:06:24 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Head)) {
|
|
|
|
ERRDRV("visor_memregion_write of Head failed: (status=%d)\n",
|
|
|
|
rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsSent)) {
|
|
|
|
ERRDRV("visor_memregion_write of NumSignalsSent failed: (status=%d)\n", rc);
|
|
|
|
goto Away;
|
|
|
|
}
|
2014-03-19 18:06:21 +00:00
|
|
|
rc = TRUE;
|
2014-03-04 13:58:06 +00:00
|
|
|
Away:
|
|
|
|
if (channel->needs_lock)
|
|
|
|
spin_unlock(&channel->insert_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalinsert);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2014-07-31 16:00:50 +00:00
|
|
|
visorchannel_signalqueue_slots_avail(VISORCHANNEL *channel, u32 queue)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-07-31 16:00:50 +00:00
|
|
|
u32 slots_avail, slots_used;
|
|
|
|
u32 head, tail;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
|
|
|
return 0;
|
|
|
|
head = sig_hdr.Head;
|
|
|
|
tail = sig_hdr.Tail;
|
|
|
|
if (head < tail)
|
|
|
|
head = head + sig_hdr.MaxSignalSlots;
|
|
|
|
slots_used = (head - tail);
|
|
|
|
slots_avail = sig_hdr.MaxSignals - slots_used;
|
|
|
|
return (int) slots_avail;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_slots_avail);
|
|
|
|
|
|
|
|
int
|
2014-07-31 16:00:50 +00:00
|
|
|
visorchannel_signalqueue_max_slots(VISORCHANNEL *channel, u32 queue)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
|
|
|
return 0;
|
|
|
|
return (int) sig_hdr.MaxSignals;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_max_slots);
|
|
|
|
|
|
|
|
static void
|
2014-10-23 18:30:03 +00:00
|
|
|
sigqueue_debug(struct signal_queue_header *q, int which, struct seq_file *seq)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
seq_printf(seq, "Signal Queue #%d\n", which);
|
|
|
|
seq_printf(seq, " VersionId = %lu\n", (ulong) q->VersionId);
|
|
|
|
seq_printf(seq, " Type = %lu\n", (ulong) q->Type);
|
|
|
|
seq_printf(seq, " oSignalBase = %llu\n",
|
|
|
|
(long long) q->oSignalBase);
|
|
|
|
seq_printf(seq, " SignalSize = %lu\n", (ulong) q->SignalSize);
|
|
|
|
seq_printf(seq, " MaxSignalSlots = %lu\n",
|
|
|
|
(ulong) q->MaxSignalSlots);
|
|
|
|
seq_printf(seq, " MaxSignals = %lu\n", (ulong) q->MaxSignals);
|
|
|
|
seq_printf(seq, " FeatureFlags = %-16.16Lx\n",
|
|
|
|
(long long) q->FeatureFlags);
|
|
|
|
seq_printf(seq, " NumSignalsSent = %llu\n",
|
|
|
|
(long long) q->NumSignalsSent);
|
|
|
|
seq_printf(seq, " NumSignalsReceived = %llu\n",
|
|
|
|
(long long) q->NumSignalsReceived);
|
|
|
|
seq_printf(seq, " NumOverflows = %llu\n",
|
|
|
|
(long long) q->NumOverflows);
|
|
|
|
seq_printf(seq, " Head = %lu\n", (ulong) q->Head);
|
|
|
|
seq_printf(seq, " Tail = %lu\n", (ulong) q->Tail);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
visorchannel_debug(VISORCHANNEL *channel, int nQueues,
|
2014-07-31 16:00:50 +00:00
|
|
|
struct seq_file *seq, u32 off)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
HOSTADDRESS addr = 0;
|
|
|
|
ulong nbytes = 0, nbytes_region = 0;
|
|
|
|
MEMREGION *memregion = NULL;
|
2014-10-23 18:29:55 +00:00
|
|
|
struct channel_header hdr;
|
|
|
|
struct channel_header *phdr = &hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
int i = 0;
|
|
|
|
int errcode = 0;
|
|
|
|
|
|
|
|
if (channel == NULL) {
|
|
|
|
ERRDRV("%s no channel", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memregion = channel->memregion;
|
|
|
|
if (memregion == NULL) {
|
|
|
|
ERRDRV("%s no memregion", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 20:52:25 +00:00
|
|
|
addr = visor_memregion_get_physaddr(memregion);
|
|
|
|
nbytes_region = visor_memregion_get_nbytes(memregion);
|
2014-03-04 13:58:06 +00:00
|
|
|
errcode = visorchannel_read(channel, off,
|
2014-10-23 18:29:55 +00:00
|
|
|
phdr, sizeof(struct channel_header));
|
2014-03-04 13:58:06 +00:00
|
|
|
if (errcode < 0) {
|
|
|
|
seq_printf(seq,
|
|
|
|
"Read of channel header failed with errcode=%d)\n",
|
|
|
|
errcode);
|
|
|
|
if (off == 0) {
|
|
|
|
phdr = &channel->chan_hdr;
|
|
|
|
seq_puts(seq, "(following data may be stale)\n");
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 18:29:56 +00:00
|
|
|
nbytes = (ulong) (phdr->size);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n",
|
|
|
|
addr + off, nbytes, nbytes_region);
|
2014-10-23 18:29:56 +00:00
|
|
|
seq_printf(seq, "Type = %pUL\n", &phdr->chtype);
|
|
|
|
seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->zone_uuid);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Signature = 0x%-16.16Lx\n",
|
2014-10-23 18:29:56 +00:00
|
|
|
(long long) phdr->signature);
|
|
|
|
seq_printf(seq, "LegacyState = %lu\n", (ulong)phdr->legacy_state);
|
|
|
|
seq_printf(seq, "SrvState = %lu\n", (ulong)phdr->srv_state);
|
|
|
|
seq_printf(seq, "CliStateBoot = %lu\n", (ulong)phdr->cli_state_boot);
|
|
|
|
seq_printf(seq, "CliStateOS = %lu\n", (ulong)phdr->cli_state_os);
|
|
|
|
seq_printf(seq, "HeaderSize = %lu\n", (ulong)phdr->header_size);
|
|
|
|
seq_printf(seq, "Size = %llu\n", (long long)phdr->size);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Features = 0x%-16.16llx\n",
|
2014-10-23 18:29:56 +00:00
|
|
|
(long long) phdr->features);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n",
|
2014-10-23 18:29:56 +00:00
|
|
|
(long long) phdr->partition_handle);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Handle = 0x%-16.16llx\n",
|
2014-10-23 18:29:56 +00:00
|
|
|
(long long) phdr->handle);
|
|
|
|
seq_printf(seq, "VersionId = %lu\n", (ulong) phdr->version_id);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "oChannelSpace = %llu\n",
|
2014-10-23 18:29:56 +00:00
|
|
|
(long long) phdr->ch_space_offset);
|
|
|
|
if ((phdr->ch_space_offset == 0) || (errcode < 0))
|
2014-03-04 13:58:06 +00:00
|
|
|
;
|
|
|
|
else
|
|
|
|
for (i = 0; i < nQueues; i++) {
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header q;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
errcode = visorchannel_read(channel,
|
2014-10-23 18:29:56 +00:00
|
|
|
off + phdr->ch_space_offset +
|
|
|
|
(i * sizeof(q)),
|
|
|
|
&q, sizeof(q));
|
2014-03-04 13:58:06 +00:00
|
|
|
if (errcode < 0) {
|
|
|
|
seq_printf(seq,
|
|
|
|
"failed to read signal queue #%d from channel @0x%-16.16Lx errcode=%d\n",
|
|
|
|
i, addr, errcode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sigqueue_debug(&q, i, seq);
|
|
|
|
}
|
|
|
|
seq_printf(seq, "--- End channel @0x%-16.16Lx for 0x%lx bytes ---\n",
|
|
|
|
addr + off, nbytes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_debug);
|
|
|
|
|
|
|
|
void
|
|
|
|
visorchannel_dump_section(VISORCHANNEL *chan, char *s,
|
|
|
|
int off, int len, struct seq_file *seq)
|
|
|
|
{
|
2014-03-17 15:37:11 +00:00
|
|
|
char *buf, *tbuf, *fmtbuf;
|
2014-03-04 13:58:06 +00:00
|
|
|
int fmtbufsize = 0;
|
2014-03-17 15:37:11 +00:00
|
|
|
int i;
|
2014-03-04 13:58:06 +00:00
|
|
|
int errcode = 0;
|
|
|
|
|
|
|
|
fmtbufsize = 100 * COVQ(len, 16);
|
|
|
|
buf = kmalloc(len, GFP_KERNEL|__GFP_NORETRY);
|
|
|
|
fmtbuf = kmalloc(fmtbufsize, GFP_KERNEL|__GFP_NORETRY);
|
|
|
|
if (buf == NULL || fmtbuf == NULL)
|
|
|
|
goto Away;
|
|
|
|
|
|
|
|
errcode = visorchannel_read(chan, off, buf, len);
|
|
|
|
if (errcode < 0) {
|
|
|
|
ERRDRV("%s failed to read %s from channel errcode=%d",
|
|
|
|
s, __func__, errcode);
|
|
|
|
goto Away;
|
|
|
|
}
|
|
|
|
seq_printf(seq, "channel %s:\n", s);
|
2014-03-17 15:37:11 +00:00
|
|
|
tbuf = buf;
|
|
|
|
while (len > 0) {
|
|
|
|
i = (len < 16) ? len : 16;
|
|
|
|
hex_dump_to_buffer(tbuf, i, 16, 1, fmtbuf, fmtbufsize, TRUE);
|
|
|
|
seq_printf(seq, "%s\n", fmtbuf);
|
|
|
|
tbuf += 16;
|
|
|
|
len -= 16;
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
Away:
|
|
|
|
if (buf != NULL) {
|
|
|
|
kfree(buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
if (fmtbuf != NULL) {
|
|
|
|
kfree(fmtbuf);
|
|
|
|
fmtbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_dump_section);
|