Benjamin Romer | f6d0c1e | 2014-04-23 14:58:34 -0400 | [diff] [blame] | 1 | /* Copyright (C) 2010 - 2013 UNISYS CORPORATION |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 2 | * All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or (at |
| 7 | * your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 12 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 13 | * details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __CHANNEL_H__ |
| 17 | #define __CHANNEL_H__ |
| 18 | |
Benjamin Romer | 1d2def9 | 2014-08-02 22:03:43 -0400 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | #include <linux/io.h> |
Benjamin Romer | 90addb0 | 2014-05-06 09:58:23 -0400 | [diff] [blame] | 21 | #include <linux/uuid.h> |
| 22 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 23 | /* |
| 24 | * Whenever this file is changed a corresponding change must be made in |
| 25 | * the Console/ServicePart/visordiag_early/supervisor_channel.h file |
| 26 | * which is needed for Linux kernel compiles. These two files must be |
| 27 | * in sync. |
| 28 | */ |
| 29 | |
| 30 | /* define the following to prevent include nesting in kernel header |
Masanari Iida | fb90c60 | 2014-04-15 01:56:33 +0900 | [diff] [blame] | 31 | * files of similar abbreviated content |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 32 | */ |
| 33 | #define __SUPERVISOR_CHANNEL_H__ |
| 34 | |
David Kershner | 54bf4d4 | 2015-10-12 15:19:40 -0400 | [diff] [blame] | 35 | #define SIGNATURE_16(A, B) ((A) | (B << 8)) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 36 | #define SIGNATURE_32(A, B, C, D) \ |
| 37 | (SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16)) |
| 38 | #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ |
Benjamin Romer | 5fc0229 | 2014-07-31 12:00:51 -0400 | [diff] [blame] | 39 | (SIGNATURE_32(A, B, C, D) | ((u64)(SIGNATURE_32(E, F, G, H)) << 32)) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 40 | |
| 41 | #ifndef lengthof |
| 42 | #define lengthof(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER)) |
| 43 | #endif |
| 44 | #ifndef COVERQ |
David Kershner | 54bf4d4 | 2015-10-12 15:19:40 -0400 | [diff] [blame] | 45 | #define COVERQ(v, d) (((v) + (d) - 1) / (d)) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 46 | #endif |
| 47 | #ifndef COVER |
David Kershner | 54bf4d4 | 2015-10-12 15:19:40 -0400 | [diff] [blame] | 48 | #define COVER(v, d) ((d) * COVERQ(v, d)) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 49 | #endif |
| 50 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 51 | #define ULTRA_CHANNEL_PROTOCOL_SIGNATURE SIGNATURE_32('E', 'C', 'N', 'L') |
| 52 | |
Benjamin Romer | 1e73f4b | 2014-10-23 14:29:51 -0400 | [diff] [blame] | 53 | enum channel_serverstate { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 54 | CHANNELSRV_UNINITIALIZED = 0, /* channel is in an undefined state */ |
| 55 | CHANNELSRV_READY = 1 /* channel has been initialized by server */ |
Benjamin Romer | 1e73f4b | 2014-10-23 14:29:51 -0400 | [diff] [blame] | 56 | }; |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 57 | |
Benjamin Romer | 9831a29 | 2014-10-23 14:29:52 -0400 | [diff] [blame] | 58 | enum channel_clientstate { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 59 | CHANNELCLI_DETACHED = 0, |
| 60 | CHANNELCLI_DISABLED = 1, /* client can see channel but is NOT |
| 61 | * allowed to use it unless given TBD |
| 62 | * explicit request (should actually be |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 63 | * < DETACHED) |
| 64 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 65 | CHANNELCLI_ATTACHING = 2, /* legacy EFI client request |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 66 | * for EFI server to attach |
| 67 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 68 | CHANNELCLI_ATTACHED = 3, /* idle, but client may want |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 69 | * to use channel any time |
| 70 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 71 | CHANNELCLI_BUSY = 4, /* client either wants to use or is |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 72 | * using channel |
| 73 | */ |
| 74 | CHANNELCLI_OWNED = 5 /* "no worries" state - client can */ |
| 75 | /* access channel anytime */ |
Benjamin Romer | 9831a29 | 2014-10-23 14:29:52 -0400 | [diff] [blame] | 76 | }; |
Benjamin Romer | 09a5073 | 2014-10-23 14:29:53 -0400 | [diff] [blame] | 77 | |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 78 | static inline const u8 * |
Alexander Curtin | 85d83cd | 2016-03-23 22:15:53 -0400 | [diff] [blame] | 79 | ULTRA_CHANNELCLI_STRING(u32 state) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 80 | { |
Alexander Curtin | 85d83cd | 2016-03-23 22:15:53 -0400 | [diff] [blame] | 81 | switch (state) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 82 | case CHANNELCLI_DETACHED: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 83 | return (const u8 *)("DETACHED"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 84 | case CHANNELCLI_DISABLED: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 85 | return (const u8 *)("DISABLED"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 86 | case CHANNELCLI_ATTACHING: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 87 | return (const u8 *)("ATTACHING"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 88 | case CHANNELCLI_ATTACHED: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 89 | return (const u8 *)("ATTACHED"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 90 | case CHANNELCLI_BUSY: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 91 | return (const u8 *)("BUSY"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 92 | case CHANNELCLI_OWNED: |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 93 | return (const u8 *)("OWNED"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 94 | default: |
| 95 | break; |
| 96 | } |
Benjamin Romer | 82d72be | 2014-10-23 14:29:54 -0400 | [diff] [blame] | 97 | return (const u8 *)("?"); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 98 | } |
| 99 | |
Benjamin Romer | 10b133c | 2014-10-23 14:29:57 -0400 | [diff] [blame] | 100 | #define SPAR_CHANNEL_SERVER_READY(ch) \ |
| 101 | (readl(&(ch)->srv_state) == CHANNELSRV_READY) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 102 | |
| 103 | #define ULTRA_VALID_CHANNELCLI_TRANSITION(o, n) \ |
| 104 | (((((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_DISABLED)) || \ |
| 105 | (((o) == CHANNELCLI_ATTACHING) && ((n) == CHANNELCLI_DISABLED)) || \ |
| 106 | (((o) == CHANNELCLI_ATTACHED) && ((n) == CHANNELCLI_DISABLED)) || \ |
| 107 | (((o) == CHANNELCLI_ATTACHING) && ((n) == CHANNELCLI_DETACHED)) || \ |
| 108 | (((o) == CHANNELCLI_ATTACHED) && ((n) == CHANNELCLI_DETACHED)) || \ |
| 109 | (((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_ATTACHING)) || \ |
| 110 | (((o) == CHANNELCLI_ATTACHING) && ((n) == CHANNELCLI_ATTACHED)) || \ |
| 111 | (((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_ATTACHED)) || \ |
| 112 | (((o) == CHANNELCLI_BUSY) && ((n) == CHANNELCLI_ATTACHED)) || \ |
| 113 | (((o) == CHANNELCLI_ATTACHED) && ((n) == CHANNELCLI_BUSY)) || \ |
| 114 | (((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_OWNED)) || \ |
| 115 | (((o) == CHANNELCLI_DISABLED) && ((n) == CHANNELCLI_OWNED)) || \ |
| 116 | (((o) == CHANNELCLI_ATTACHING) && ((n) == CHANNELCLI_OWNED)) || \ |
| 117 | (((o) == CHANNELCLI_ATTACHED) && ((n) == CHANNELCLI_OWNED)) || \ |
| 118 | (((o) == CHANNELCLI_BUSY) && ((n) == CHANNELCLI_OWNED)) || (0)) \ |
| 119 | ? (1) : (0)) |
| 120 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 121 | /* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorBoot: */ |
| 122 | /* throttling invalid boot channel statetransition error due to client |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 123 | * disabled |
| 124 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 125 | #define ULTRA_CLIERRORBOOT_THROTTLEMSG_DISABLED 0x01 |
| 126 | |
| 127 | /* throttling invalid boot channel statetransition error due to client |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 128 | * not attached |
| 129 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 130 | #define ULTRA_CLIERRORBOOT_THROTTLEMSG_NOTATTACHED 0x02 |
| 131 | |
| 132 | /* throttling invalid boot channel statetransition error due to busy channel */ |
| 133 | #define ULTRA_CLIERRORBOOT_THROTTLEMSG_BUSY 0x04 |
| 134 | |
| 135 | /* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorOS: */ |
| 136 | /* throttling invalid guest OS channel statetransition error due to |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 137 | * client disabled |
| 138 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 139 | #define ULTRA_CLIERROROS_THROTTLEMSG_DISABLED 0x01 |
| 140 | |
| 141 | /* throttling invalid guest OS channel statetransition error due to |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 142 | * client not attached |
| 143 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 144 | #define ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED 0x02 |
| 145 | |
| 146 | /* throttling invalid guest OS channel statetransition error due to |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 147 | * busy channel |
| 148 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 149 | #define ULTRA_CLIERROROS_THROTTLEMSG_BUSY 0x04 |
| 150 | |
| 151 | /* Values for ULTRA_CHANNEL_PROTOCOL.Features: This define exists so |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 152 | * that windows guest can look at the FeatureFlags in the io channel, |
| 153 | * and configure the windows driver to use interrupts or not based on |
| 154 | * this setting. This flag is set in uislib after the |
| 155 | * ULTRA_VHBA_init_channel is called. All feature bits for all |
| 156 | * channels should be defined here. The io channel feature bits are |
| 157 | * defined right here |
| 158 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 159 | #define ULTRA_IO_DRIVER_ENABLES_INTS (0x1ULL << 1) |
| 160 | #define ULTRA_IO_CHANNEL_IS_POLLING (0x1ULL << 3) |
| 161 | #define ULTRA_IO_IOVM_IS_OK_WITH_DRIVER_DISABLING_INTS (0x1ULL << 4) |
| 162 | #define ULTRA_IO_DRIVER_DISABLES_INTS (0x1ULL << 5) |
| 163 | #define ULTRA_IO_DRIVER_SUPPORTS_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6) |
| 164 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 165 | /* Common Channel Header */ |
Benjamin Romer | 9fd1b95 | 2014-10-23 14:29:55 -0400 | [diff] [blame] | 166 | struct channel_header { |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 167 | u64 signature; /* Signature */ |
| 168 | u32 legacy_state; /* DEPRECATED - being replaced by */ |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 169 | /* SrvState, CliStateBoot, and CliStateOS below */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 170 | u32 header_size; /* sizeof(struct channel_header) */ |
| 171 | u64 size; /* Total size of this channel in bytes */ |
| 172 | u64 features; /* Flags to modify behavior */ |
| 173 | uuid_le chtype; /* Channel type: data, bus, control, etc. */ |
| 174 | u64 partition_handle; /* ID of guest partition */ |
| 175 | u64 handle; /* Device number of this channel in client */ |
| 176 | u64 ch_space_offset; /* Offset in bytes to channel specific area */ |
| 177 | u32 version_id; /* struct channel_header Version ID */ |
| 178 | u32 partition_index; /* Index of guest partition */ |
| 179 | uuid_le zone_uuid; /* Guid of Channel's zone */ |
| 180 | u32 cli_str_offset; /* offset from channel header to |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 181 | * nul-terminated ClientString (0 if |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 182 | * ClientString not present) |
| 183 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 184 | u32 cli_state_boot; /* CHANNEL_CLIENTSTATE of pre-boot |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 185 | * EFI client of this channel |
| 186 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 187 | u32 cmd_state_cli; /* CHANNEL_COMMANDSTATE (overloaded in |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 188 | * Windows drivers, see ServerStateUp, |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 189 | * ServerStateDown, etc) |
| 190 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 191 | u32 cli_state_os; /* CHANNEL_CLIENTSTATE of Guest OS |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 192 | * client of this channel |
| 193 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 194 | u32 ch_characteristic; /* CHANNEL_CHARACTERISTIC_<xxx> */ |
| 195 | u32 cmd_state_srv; /* CHANNEL_COMMANDSTATE (overloaded in |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 196 | * Windows drivers, see ServerStateUp, |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 197 | * ServerStateDown, etc) |
| 198 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 199 | u32 srv_state; /* CHANNEL_SERVERSTATE */ |
| 200 | u8 cli_error_boot; /* bits to indicate err states for |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 201 | * boot clients, so err messages can |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 202 | * be throttled |
| 203 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 204 | u8 cli_error_os; /* bits to indicate err states for OS |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 205 | * clients, so err messages can be |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 206 | * throttled |
| 207 | */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 208 | u8 filler[1]; /* Pad out to 128 byte cacheline */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 209 | /* Please add all new single-byte values below here */ |
Benjamin Romer | a8a31f6 | 2014-10-23 14:29:56 -0400 | [diff] [blame] | 210 | u8 recover_channel; |
David Kershner | 9f00be7 | 2015-10-12 15:19:39 -0400 | [diff] [blame] | 211 | } __packed; |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 212 | |
| 213 | #define ULTRA_CHANNEL_ENABLE_INTS (0x1ULL << 0) |
| 214 | |
| 215 | /* Subheader for the Signal Type variation of the Common Channel */ |
Benjamin Romer | e0fed86 | 2014-10-23 14:30:03 -0400 | [diff] [blame] | 216 | struct signal_queue_header { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 217 | /* 1st cache line */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 218 | u32 version; /* SIGNAL_QUEUE_HEADER Version ID */ |
| 219 | u32 chtype; /* Queue type: storage, network */ |
| 220 | u64 size; /* Total size of this queue in bytes */ |
| 221 | u64 sig_base_offset; /* Offset to signal queue area */ |
| 222 | u64 features; /* Flags to modify behavior */ |
| 223 | u64 num_sent; /* Total # of signals placed in this queue */ |
| 224 | u64 num_overflows; /* Total # of inserts failed due to |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 225 | * full queue |
| 226 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 227 | u32 signal_size; /* Total size of a signal for this queue */ |
| 228 | u32 max_slots; /* Max # of slots in queue, 1 slot is |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 229 | * always empty |
| 230 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 231 | u32 max_signals; /* Max # of signals in queue |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 232 | * (MaxSignalSlots-1) |
| 233 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 234 | u32 head; /* Queue head signal # */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 235 | /* 2nd cache line */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 236 | u64 num_received; /* Total # of signals removed from this queue */ |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 237 | u32 tail; /* Queue tail signal */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 238 | u32 reserved1; /* Reserved field */ |
| 239 | u64 reserved2; /* Reserved field */ |
| 240 | u64 client_queue; |
| 241 | u64 num_irq_received; /* Total # of Interrupts received. This |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 242 | * is incremented by the ISR in the |
| 243 | * guest windows driver |
| 244 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 245 | u64 num_empty; /* Number of times that visor_signal_remove |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 246 | * is called and returned Empty Status. |
| 247 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 248 | u32 errorflags; /* Error bits set during SignalReinit |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 249 | * to denote trouble with client's |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 250 | * fields |
| 251 | */ |
Benjamin Romer | 153cf71 | 2014-10-23 14:30:04 -0400 | [diff] [blame] | 252 | u8 filler[12]; /* Pad out to 64 byte cacheline */ |
David Kershner | 9f00be7 | 2015-10-12 15:19:39 -0400 | [diff] [blame] | 253 | } __packed; |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 254 | |
Benjamin Romer | 29fe22b | 2014-10-23 14:30:09 -0400 | [diff] [blame] | 255 | #define spar_signal_init(chan, QHDRFLD, QDATAFLD, QDATATYPE, ver, typ) \ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 256 | do { \ |
Benjamin Romer | 30de72d | 2014-07-31 12:00:59 -0400 | [diff] [blame] | 257 | memset(&chan->QHDRFLD, 0, sizeof(chan->QHDRFLD)); \ |
Benjamin Romer | 29fe22b | 2014-10-23 14:30:09 -0400 | [diff] [blame] | 258 | chan->QHDRFLD.version = ver; \ |
| 259 | chan->QHDRFLD.chtype = typ; \ |
| 260 | chan->QHDRFLD.size = sizeof(chan->QDATAFLD); \ |
| 261 | chan->QHDRFLD.signal_size = sizeof(QDATATYPE); \ |
David Kershner | 54bf4d4 | 2015-10-12 15:19:40 -0400 | [diff] [blame] | 262 | chan->QHDRFLD.sig_base_offset = (u64)(chan->QDATAFLD) - \ |
Benjamin Romer | 90f3b50 | 2014-07-31 12:00:58 -0400 | [diff] [blame] | 263 | (u64)(&chan->QHDRFLD); \ |
Benjamin Romer | 29fe22b | 2014-10-23 14:30:09 -0400 | [diff] [blame] | 264 | chan->QHDRFLD.max_slots = \ |
David Kershner | 54bf4d4 | 2015-10-12 15:19:40 -0400 | [diff] [blame] | 265 | sizeof(chan->QDATAFLD) / sizeof(QDATATYPE); \ |
| 266 | chan->QHDRFLD.max_signals = chan->QHDRFLD.max_slots - 1;\ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 267 | } while (0) |
| 268 | |
| 269 | /* Generic function useful for validating any type of channel when it is |
| 270 | * received by the client that will be accessing the channel. |
| 271 | * Note that <logCtx> is only needed for callers in the EFI environment, and |
| 272 | * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages. |
| 273 | */ |
| 274 | static inline int |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 275 | spar_check_channel_client(void __iomem *ch, |
| 276 | uuid_le expected_uuid, |
| 277 | char *chname, |
| 278 | u64 expected_min_bytes, |
| 279 | u32 expected_version, |
| 280 | u64 expected_signature) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 281 | { |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 282 | if (uuid_le_cmp(expected_uuid, NULL_UUID_LE) != 0) { |
Luke Hart | 635ecc5 | 2014-09-12 10:48:33 +0100 | [diff] [blame] | 283 | uuid_le guid; |
| 284 | |
Benjamin Romer | 35b8117 | 2014-09-22 13:45:03 -0400 | [diff] [blame] | 285 | memcpy_fromio(&guid, |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 286 | &((struct channel_header __iomem *)(ch))->chtype, |
| 287 | sizeof(guid)); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 288 | /* caller wants us to verify type GUID */ |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 289 | if (uuid_le_cmp(guid, expected_uuid) != 0) { |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 290 | pr_err("Channel mismatch on channel=%s(%pUL) field=type expected=%pUL actual=%pUL\n", |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 291 | chname, &expected_uuid, |
| 292 | &expected_uuid, &guid); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 293 | return 0; |
| 294 | } |
Luke Hart | 635ecc5 | 2014-09-12 10:48:33 +0100 | [diff] [blame] | 295 | } |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 296 | if (expected_min_bytes > 0) { /* verify channel size */ |
Benjamin Romer | 9fd1b95 | 2014-10-23 14:29:55 -0400 | [diff] [blame] | 297 | unsigned long long bytes = |
| 298 | readq(&((struct channel_header __iomem *) |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 299 | (ch))->size); |
| 300 | if (bytes < expected_min_bytes) { |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 301 | pr_err("Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8Lx actual=0x%-8.8Lx\n", |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 302 | chname, &expected_uuid, |
| 303 | (unsigned long long)expected_min_bytes, bytes); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 304 | return 0; |
| 305 | } |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 306 | } |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 307 | if (expected_version > 0) { /* verify channel version */ |
Benjamin Romer | 9fd1b95 | 2014-10-23 14:29:55 -0400 | [diff] [blame] | 308 | unsigned long ver = readl(&((struct channel_header __iomem *) |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 309 | (ch))->version_id); |
| 310 | if (ver != expected_version) { |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 311 | pr_err("Channel mismatch on channel=%s(%pUL) field=version expected=0x%-8.8lx actual=0x%-8.8lx\n", |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 312 | chname, &expected_uuid, |
| 313 | (unsigned long)expected_version, ver); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 314 | return 0; |
| 315 | } |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 316 | } |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 317 | if (expected_signature > 0) { /* verify channel signature */ |
Benjamin Romer | 9fd1b95 | 2014-10-23 14:29:55 -0400 | [diff] [blame] | 318 | unsigned long long sig = |
| 319 | readq(&((struct channel_header __iomem *) |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 320 | (ch))->signature); |
| 321 | if (sig != expected_signature) { |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 322 | pr_err("Channel mismatch on channel=%s(%pUL) field=signature expected=0x%-8.8llx actual=0x%-8.8llx\n", |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 323 | chname, &expected_uuid, |
| 324 | expected_signature, sig); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 325 | return 0; |
| 326 | } |
Benjamin Romer | e270669 | 2014-10-23 14:29:49 -0400 | [diff] [blame] | 327 | } |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 328 | return 1; |
| 329 | } |
| 330 | |
Benjamin Romer | 10c5ef6 | 2014-10-23 14:30:11 -0400 | [diff] [blame] | 331 | /* Generic function useful for validating any type of channel when it is about |
| 332 | * to be initialized by the server of the channel. |
| 333 | * Note that <logCtx> is only needed for callers in the EFI environment, and |
| 334 | * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages. |
| 335 | */ |
| 336 | static inline int spar_check_channel_server(uuid_le typeuuid, char *name, |
| 337 | u64 expected_min_bytes, |
| 338 | u64 actual_bytes) |
| 339 | { |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 340 | if (expected_min_bytes > 0) /* verify channel size */ |
Benjamin Romer | 10c5ef6 | 2014-10-23 14:30:11 -0400 | [diff] [blame] | 341 | if (actual_bytes < expected_min_bytes) { |
| 342 | pr_err("Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8llx actual=0x%-8.8llx\n", |
| 343 | name, &typeuuid, expected_min_bytes, |
| 344 | actual_bytes); |
| 345 | return 0; |
| 346 | } |
| 347 | return 1; |
| 348 | } |
| 349 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 350 | /* Given a file pathname <s> (with '/' or '\' separating directory nodes), |
| 351 | * returns a pointer to the beginning of a node within that pathname such |
| 352 | * that the number of nodes from that pointer to the end of the string is |
| 353 | * NOT more than <n>. Note that if the pathname has less than <n> nodes |
| 354 | * in it, the return pointer will be to the beginning of the string. |
| 355 | */ |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 356 | static inline u8 * |
Benjamin Romer | 8800bfb | 2014-10-23 14:29:59 -0400 | [diff] [blame] | 357 | pathname_last_n_nodes(u8 *s, unsigned int n) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 358 | { |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 359 | u8 *p = s; |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 360 | unsigned int node_count = 0; |
Melike Yurtoglu | aff6de0 | 2014-10-02 11:13:53 +0300 | [diff] [blame] | 361 | |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 362 | while (*p != '\0') { |
| 363 | if ((*p == '/') || (*p == '\\')) |
| 364 | node_count++; |
| 365 | p++; |
| 366 | } |
| 367 | if (node_count <= n) |
| 368 | return s; |
| 369 | while (n > 0) { |
| 370 | p--; |
| 371 | if (p == s) |
| 372 | break; /* should never happen, unless someone |
| 373 | * is changing the string while we are |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 374 | * looking at it!! |
| 375 | */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 376 | if ((*p == '/') || (*p == '\\')) |
| 377 | n--; |
| 378 | } |
| 379 | return p + 1; |
| 380 | } |
| 381 | |
| 382 | static inline int |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 383 | spar_channel_client_acquire_os(void __iomem *ch, u8 *id) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 384 | { |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 385 | struct channel_header __iomem *hdr = ch; |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 386 | |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 387 | if (readl(&hdr->cli_state_os) == CHANNELCLI_DISABLED) { |
| 388 | if ((readb(&hdr->cli_error_os) |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 389 | & ULTRA_CLIERROROS_THROTTLEMSG_DISABLED) == 0) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 390 | /* we are NOT throttling this message */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 391 | writeb(readb(&hdr->cli_error_os) | |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 392 | ULTRA_CLIERROROS_THROTTLEMSG_DISABLED, |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 393 | &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 394 | /* throttle until acquire successful */ |
| 395 | |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 396 | pr_info("%s Channel StateTransition INVALID! - acquire failed because OS client DISABLED\n", |
| 397 | id); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 398 | } |
| 399 | return 0; |
| 400 | } |
Benjamin Romer | bac9e37 | 2014-10-23 14:30:08 -0400 | [diff] [blame] | 401 | if ((readl(&hdr->cli_state_os) != CHANNELCLI_OWNED) && |
| 402 | (readl(&hdr->cli_state_boot) == CHANNELCLI_DISABLED)) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 403 | /* Our competitor is DISABLED, so we can transition to OWNED */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 404 | pr_info("%s Channel StateTransition (%s) %s(%d)-->%s(%d)\n", |
| 405 | id, "cli_state_os", |
| 406 | ULTRA_CHANNELCLI_STRING(readl(&hdr->cli_state_os)), |
| 407 | readl(&hdr->cli_state_os), |
Benjamin Romer | ddb38ae | 2014-10-23 14:29:50 -0400 | [diff] [blame] | 408 | ULTRA_CHANNELCLI_STRING(CHANNELCLI_OWNED), |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 409 | CHANNELCLI_OWNED); |
| 410 | writel(CHANNELCLI_OWNED, &hdr->cli_state_os); |
Benjamin Romer | e87cfde | 2014-08-02 22:03:38 -0400 | [diff] [blame] | 411 | mb(); /* required for channel synch */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 412 | } |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 413 | if (readl(&hdr->cli_state_os) == CHANNELCLI_OWNED) { |
Erik Arfvidson | 800aecc | 2016-03-24 09:18:09 -0400 | [diff] [blame] | 414 | if (readb(&hdr->cli_error_os)) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 415 | /* we are in an error msg throttling state; |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 416 | * come out of it |
| 417 | */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 418 | pr_info("%s Channel OS client acquire now successful\n", |
| 419 | id); |
| 420 | writeb(0, &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 421 | } |
| 422 | return 1; |
| 423 | } |
| 424 | |
| 425 | /* We have to do it the "hard way". We transition to BUSY, |
Erik Arfvidson | 180e276 | 2015-11-17 13:34:57 -0500 | [diff] [blame] | 426 | * and can use the channel iff our competitor has not also |
| 427 | * transitioned to BUSY. |
| 428 | */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 429 | if (readl(&hdr->cli_state_os) != CHANNELCLI_ATTACHED) { |
| 430 | if ((readb(&hdr->cli_error_os) |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 431 | & ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED) == 0) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 432 | /* we are NOT throttling this message */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 433 | writeb(readb(&hdr->cli_error_os) | |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 434 | ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED, |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 435 | &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 436 | /* throttle until acquire successful */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 437 | pr_info("%s Channel StateTransition INVALID! - acquire failed because OS client NOT ATTACHED (state=%s(%d))\n", |
| 438 | id, ULTRA_CHANNELCLI_STRING( |
| 439 | readl(&hdr->cli_state_os)), |
| 440 | readl(&hdr->cli_state_os)); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 441 | } |
| 442 | return 0; |
| 443 | } |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 444 | writel(CHANNELCLI_BUSY, &hdr->cli_state_os); |
Benjamin Romer | e87cfde | 2014-08-02 22:03:38 -0400 | [diff] [blame] | 445 | mb(); /* required for channel synch */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 446 | if (readl(&hdr->cli_state_boot) == CHANNELCLI_BUSY) { |
| 447 | if ((readb(&hdr->cli_error_os) |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 448 | & ULTRA_CLIERROROS_THROTTLEMSG_BUSY) == 0) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 449 | /* we are NOT throttling this message */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 450 | writeb(readb(&hdr->cli_error_os) | |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 451 | ULTRA_CLIERROROS_THROTTLEMSG_BUSY, |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 452 | &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 453 | /* throttle until acquire successful */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 454 | pr_info("%s Channel StateTransition failed - host OS acquire failed because boot BUSY\n", |
| 455 | id); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 456 | } |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 457 | /* reset busy */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 458 | writel(CHANNELCLI_ATTACHED, &hdr->cli_state_os); |
Benjamin Romer | e87cfde | 2014-08-02 22:03:38 -0400 | [diff] [blame] | 459 | mb(); /* required for channel synch */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 460 | return 0; |
| 461 | } |
Erik Arfvidson | 800aecc | 2016-03-24 09:18:09 -0400 | [diff] [blame] | 462 | if (readb(&hdr->cli_error_os)) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 463 | /* we are in an error msg throttling state; come out of it */ |
Benjamin Romer | 9f16930 | 2014-10-23 14:30:01 -0400 | [diff] [blame] | 464 | pr_info("%s Channel OS client acquire now successful\n", id); |
| 465 | writeb(0, &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 466 | } |
| 467 | return 1; |
| 468 | } |
| 469 | |
| 470 | static inline void |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 471 | spar_channel_client_release_os(void __iomem *ch, u8 *id) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 472 | { |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 473 | struct channel_header __iomem *hdr = ch; |
Melike Yurtoglu | aff6de0 | 2014-10-02 11:13:53 +0300 | [diff] [blame] | 474 | |
Erik Arfvidson | 800aecc | 2016-03-24 09:18:09 -0400 | [diff] [blame] | 475 | if (readb(&hdr->cli_error_os)) { |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 476 | /* we are in an error msg throttling state; come out of it */ |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 477 | pr_info("%s Channel OS client error state cleared\n", id); |
| 478 | writeb(0, &hdr->cli_error_os); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 479 | } |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 480 | if (readl(&hdr->cli_state_os) == CHANNELCLI_OWNED) |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 481 | return; |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 482 | if (readl(&hdr->cli_state_os) != CHANNELCLI_BUSY) { |
| 483 | pr_info("%s Channel StateTransition INVALID! - release failed because OS client NOT BUSY (state=%s(%d))\n", |
| 484 | id, ULTRA_CHANNELCLI_STRING( |
| 485 | readl(&hdr->cli_state_os)), |
| 486 | readl(&hdr->cli_state_os)); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 487 | /* return; */ |
| 488 | } |
Benjamin Romer | 0859891 | 2014-10-23 14:30:02 -0400 | [diff] [blame] | 489 | writel(CHANNELCLI_ATTACHED, &hdr->cli_state_os); /* release busy */ |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /* |
| 493 | * Routine Description: |
| 494 | * Tries to insert the prebuilt signal pointed to by pSignal into the nth |
| 495 | * Queue of the Channel pointed to by pChannel |
| 496 | * |
| 497 | * Parameters: |
| 498 | * pChannel: (IN) points to the IO Channel |
| 499 | * Queue: (IN) nth Queue of the IO Channel |
| 500 | * pSignal: (IN) pointer to the signal |
| 501 | * |
| 502 | * Assumptions: |
| 503 | * - pChannel, Queue and pSignal are valid. |
| 504 | * - If insertion fails due to a full queue, the caller will determine the |
| 505 | * retry policy (e.g. wait & try again, report an error, etc.). |
| 506 | * |
| 507 | * Return value: 1 if the insertion succeeds, 0 if the queue was |
| 508 | * full. |
| 509 | */ |
| 510 | |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 511 | unsigned char spar_signal_insert(struct channel_header __iomem *ch, u32 queue, |
| 512 | void *sig); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 513 | |
| 514 | /* |
| 515 | * Routine Description: |
| 516 | * Removes one signal from Channel pChannel's nth Queue at the |
| 517 | * time of the call and copies it into the memory pointed to by |
| 518 | * pSignal. |
| 519 | * |
| 520 | * Parameters: |
| 521 | * pChannel: (IN) points to the IO Channel |
| 522 | * Queue: (IN) nth Queue of the IO Channel |
| 523 | * pSignal: (IN) pointer to where the signals are to be copied |
| 524 | * |
| 525 | * Assumptions: |
| 526 | * - pChannel and Queue are valid. |
| 527 | * - pSignal points to a memory area large enough to hold queue's SignalSize |
| 528 | * |
| 529 | * Return value: 1 if the removal succeeds, 0 if the queue was |
| 530 | * empty. |
| 531 | */ |
| 532 | |
Benjamin Romer | 3f12c5f | 2014-10-23 14:30:06 -0400 | [diff] [blame] | 533 | unsigned char spar_signal_remove(struct channel_header __iomem *ch, u32 queue, |
| 534 | void *sig); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 535 | |
| 536 | /* |
| 537 | * Routine Description: |
| 538 | * Removes all signals present in Channel pChannel's nth Queue at the |
| 539 | * time of the call and copies them into the memory pointed to by |
| 540 | * pSignal. Returns the # of signals copied as the value of the routine. |
| 541 | * |
| 542 | * Parameters: |
| 543 | * pChannel: (IN) points to the IO Channel |
| 544 | * Queue: (IN) nth Queue of the IO Channel |
| 545 | * pSignal: (IN) pointer to where the signals are to be copied |
| 546 | * |
| 547 | * Assumptions: |
| 548 | * - pChannel and Queue are valid. |
| 549 | * - pSignal points to a memory area large enough to hold Queue's MaxSignals |
| 550 | * # of signals, each of which is Queue's SignalSize. |
| 551 | * |
| 552 | * Return value: |
| 553 | * # of signals copied. |
| 554 | */ |
Benjamin Romer | c11cf5f | 2014-10-23 14:30:10 -0400 | [diff] [blame] | 555 | unsigned int spar_signal_remove_all(struct channel_header *ch, u32 queue, |
| 556 | void *sig); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 557 | |
| 558 | /* |
| 559 | * Routine Description: |
| 560 | * Determine whether a signal queue is empty. |
| 561 | * |
| 562 | * Parameters: |
| 563 | * pChannel: (IN) points to the IO Channel |
| 564 | * Queue: (IN) nth Queue of the IO Channel |
| 565 | * |
| 566 | * Return value: |
| 567 | * 1 if the signal queue is empty, 0 otherwise. |
| 568 | */ |
Benjamin Romer | a17f5b4 | 2014-10-23 14:30:07 -0400 | [diff] [blame] | 569 | unsigned char spar_signalqueue_empty(struct channel_header __iomem *ch, |
| 570 | u32 queue); |
Ken Cox | e423812 | 2014-03-04 07:58:06 -0600 | [diff] [blame] | 571 | |
| 572 | #endif |