GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / unisys / include / channel.h
1 /*
2  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13  * NON INFRINGEMENT.  See the GNU General Public License for more
14  * details.
15  */
16
17 #ifndef __CHANNEL_H__
18 #define __CHANNEL_H__
19
20 #include <linux/types.h>
21 #include <linux/io.h>
22 #include <linux/uuid.h>
23
24 #define SIGNATURE_16(A, B) ((A) | ((B) << 8))
25 #define SIGNATURE_32(A, B, C, D) \
26         (SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16))
27 #define VISOR_CHANNEL_SIGNATURE SIGNATURE_32('E', 'C', 'N', 'L')
28
29 /*
30  * enum channel_serverstate
31  * @CHANNELSRV_UNINITIALIZED: Channel is in an undefined state.
32  * @CHANNELSRV_READY:         Channel has been initialized by server.
33  */
34 enum channel_serverstate {
35         CHANNELSRV_UNINITIALIZED = 0,
36         CHANNELSRV_READY = 1
37 };
38
39 /*
40  * enum channel_clientstate
41  * @CHANNELCLI_DETACHED:
42  * @CHANNELCLI_DISABLED:  Client can see channel but is NOT allowed to use it
43  *                        unless given TBD* explicit request
44  *                        (should actually be < DETACHED).
45  * @CHANNELCLI_ATTACHING: Legacy EFI client request for EFI server to attach.
46  * @CHANNELCLI_ATTACHED:  Idle, but client may want to use channel any time.
47  * @CHANNELCLI_BUSY:      Client either wants to use or is using channel.
48  * @CHANNELCLI_OWNED:     "No worries" state - client can access channel
49  *                        anytime.
50  */
51 enum channel_clientstate {
52         CHANNELCLI_DETACHED = 0,
53         CHANNELCLI_DISABLED = 1,
54         CHANNELCLI_ATTACHING = 2,
55         CHANNELCLI_ATTACHED = 3,
56         CHANNELCLI_BUSY = 4,
57         CHANNELCLI_OWNED = 5
58 };
59
60 /*
61  * Values for VISOR_CHANNEL_PROTOCOL.Features: This define exists so that
62  * a guest can look at the FeatureFlags in the io channel, and configure the
63  * driver to use interrupts or not based on this setting. All feature bits for
64  * all channels should be defined here. The io channel feature bits are defined
65  * below.
66  */
67 #define VISOR_DRIVER_ENABLES_INTS (0x1ULL << 1)
68 #define VISOR_CHANNEL_IS_POLLING (0x1ULL << 3)
69 #define VISOR_IOVM_OK_DRIVER_DISABLING_INTS (0x1ULL << 4)
70 #define VISOR_DRIVER_DISABLES_INTS (0x1ULL << 5)
71 #define VISOR_DRIVER_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6)
72
73 /*
74  * struct channel_header - Common Channel Header
75  * @signature:         Signature.
76  * @legacy_state:      DEPRECATED - being replaced by.
77  * @header_size:       sizeof(struct channel_header).
78  * @size:              Total size of this channel in bytes.
79  * @features:          Flags to modify behavior.
80  * @chtype:            Channel type: data, bus, control, etc..
81  * @partition_handle:  ID of guest partition.
82  * @handle:            Device number of this channel in client.
83  * @ch_space_offset:   Offset in bytes to channel specific area.
84  * @version_id:        Struct channel_header Version ID.
85  * @partition_index:   Index of guest partition.
86  * @zone_uuid:         Guid of Channel's zone.
87  * @cli_str_offset:    Offset from channel header to null-terminated
88  *                     ClientString (0 if ClientString not present).
89  * @cli_state_boot:    CHANNEL_CLIENTSTATE of pre-boot EFI client of this
90  *                     channel.
91  * @cmd_state_cli:     CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
92  *                     ServerStateUp, ServerStateDown, etc).
93  * @cli_state_os:      CHANNEL_CLIENTSTATE of Guest OS client of this channel.
94  * @ch_characteristic: CHANNEL_CHARACTERISTIC_<xxx>.
95  * @cmd_state_srv:     CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
96  *                     ServerStateUp, ServerStateDown, etc).
97  * @srv_state:         CHANNEL_SERVERSTATE.
98  * @cli_error_boot:    Bits to indicate err states for boot clients, so err
99  *                     messages can be throttled.
100  * @cli_error_os:      Bits to indicate err states for OS clients, so err
101  *                     messages can be throttled.
102  * @filler:            Pad out to 128 byte cacheline.
103  * @recover_channel:   Please add all new single-byte values below here.
104  */
105 struct channel_header {
106         u64 signature;
107         u32 legacy_state;
108         /* SrvState, CliStateBoot, and CliStateOS below */
109         u32 header_size;
110         u64 size;
111         u64 features;
112         guid_t chtype;
113         u64 partition_handle;
114         u64 handle;
115         u64 ch_space_offset;
116         u32 version_id;
117         u32 partition_index;
118         guid_t zone_guid;
119         u32 cli_str_offset;
120         u32 cli_state_boot;
121         u32 cmd_state_cli;
122         u32 cli_state_os;
123         u32 ch_characteristic;
124         u32 cmd_state_srv;
125         u32 srv_state;
126         u8 cli_error_boot;
127         u8 cli_error_os;
128         u8 filler[1];
129         u8 recover_channel;
130 } __packed;
131
132 #define VISOR_CHANNEL_ENABLE_INTS (0x1ULL << 0)
133
134 /*
135  * struct signal_queue_header - Subheader for the Signal Type variation of the
136  *                              Common Channel.
137  * @version:          SIGNAL_QUEUE_HEADER Version ID.
138  * @chtype:           Queue type: storage, network.
139  * @size:             Total size of this queue in bytes.
140  * @sig_base_offset:  Offset to signal queue area.
141  * @features:         Flags to modify behavior.
142  * @num_sent:         Total # of signals placed in this queue.
143  * @num_overflows:    Total # of inserts failed due to full queue.
144  * @signal_size:      Total size of a signal for this queue.
145  * @max_slots:        Max # of slots in queue, 1 slot is always empty.
146  * @max_signals:      Max # of signals in queue (MaxSignalSlots-1).
147  * @head:             Queue head signal #.
148  * @num_received:     Total # of signals removed from this queue.
149  * @tail:             Queue tail signal.
150  * @reserved1:        Reserved field.
151  * @reserved2:        Reserved field.
152  * @client_queue:
153  * @num_irq_received: Total # of Interrupts received. This is incremented by the
154  *                    ISR in the guest windows driver.
155  * @num_empty:        Number of times that visor_signal_remove is called and
156  *                    returned Empty Status.
157  * @errorflags:       Error bits set during SignalReinit to denote trouble with
158  *                    client's fields.
159  * @filler:           Pad out to 64 byte cacheline.
160  */
161 struct signal_queue_header {
162         /* 1st cache line */
163         u32 version;
164         u32 chtype;
165         u64 size;
166         u64 sig_base_offset;
167         u64 features;
168         u64 num_sent;
169         u64 num_overflows;
170         u32 signal_size;
171         u32 max_slots;
172         u32 max_signals;
173         u32 head;
174         /* 2nd cache line */
175         u64 num_received;
176         u32 tail;
177         u32 reserved1;
178         u64 reserved2;
179         u64 client_queue;
180         u64 num_irq_received;
181         u64 num_empty;
182         u32 errorflags;
183         u8 filler[12];
184 } __packed;
185
186 /* CHANNEL Guids */
187 /* {414815ed-c58c-11da-95a9-00e08161165f} */
188 #define VISOR_VHBA_CHANNEL_GUID \
189         GUID_INIT(0x414815ed, 0xc58c, 0x11da, \
190                   0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
191 #define VISOR_VHBA_CHANNEL_GUID_STR \
192         "414815ed-c58c-11da-95a9-00e08161165f"
193 #endif