Merge branch 'for-3.17/drivers' of git://git.kernel.dk/linux-block
[firefly-linux-kernel-4.4.55.git] / drivers / staging / unisys / visorchipset / visorchipset.h
1 /* visorchipset.h
2  *
3  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4  * All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at
9  * your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14  * NON INFRINGEMENT.  See the GNU General Public License for more
15  * details.
16  */
17
18 #ifndef __VISORCHIPSET_H__
19 #define __VISORCHIPSET_H__
20
21 #include <linux/uuid.h>
22
23 #include "timskmod.h"
24 #include "channel.h"
25 #include "controlvmchannel.h"
26 #include "parser.h"
27 #include "procobjecttree.h"
28 #include "vbusdeviceinfo.h"
29 #include "vbushelper.h"
30
31 /** Describes the state from the perspective of which controlvm messages have
32  *  been received for a bus or device.
33  */
34 typedef struct {
35         u32 created:1;
36         u32 attached:1;
37         u32 configured:1;
38         u32 running:1;
39         /* Add new fields above. */
40         /* Remaining bits in this 32-bit word are unused. */
41 } VISORCHIPSET_STATE;
42
43 typedef enum {
44         /** address is guest physical, but outside of the physical memory
45          *  region that is controlled by the running OS (this is the normal
46          *  address type for Supervisor channels)
47          */
48         ADDRTYPE_localPhysical,
49
50         /** address is guest physical, and withIN the confines of the
51          *  physical memory controlled by the running OS.
52          */
53         ADDRTYPE_localTest,
54 } VISORCHIPSET_ADDRESSTYPE;
55
56 typedef enum {
57         CRASH_dev,
58         CRASH_bus,
59 } CRASH_OBJ_TYPE;
60
61 /** Attributes for a particular Supervisor channel.
62  */
63 typedef struct {
64         VISORCHIPSET_ADDRESSTYPE addrType;
65         HOSTADDRESS channelAddr;
66         struct InterruptInfo intr;
67         u64 nChannelBytes;
68         uuid_le channelTypeGuid;
69         uuid_le channelInstGuid;
70
71 } VISORCHIPSET_CHANNEL_INFO;
72
73 /** Attributes for a particular Supervisor device.
74  *  Any visorchipset client can query these attributes using
75  *  visorchipset_get_client_device_info() or
76  *  visorchipset_get_server_device_info().
77  */
78 typedef struct {
79         struct list_head entry;
80         u32 busNo;
81         u32 devNo;
82         uuid_le devInstGuid;
83         VISORCHIPSET_STATE state;
84         VISORCHIPSET_CHANNEL_INFO chanInfo;
85         u32 Reserved1;          /* CONTROLVM_ID */
86         u64 Reserved2;
87         u32 switchNo;           /* when devState.attached==1 */
88         u32 internalPortNo;     /* when devState.attached==1 */
89         CONTROLVM_MESSAGE_HEADER pendingMsgHdr; /* CONTROLVM_MESSAGE */
90         /** For private use by the bus driver */
91         void *bus_driver_context;
92
93 } VISORCHIPSET_DEVICE_INFO;
94
95 static inline VISORCHIPSET_DEVICE_INFO *
96 finddevice(struct list_head *list, u32 busNo, u32 devNo)
97 {
98         VISORCHIPSET_DEVICE_INFO *p;
99
100         list_for_each_entry(p, list, entry) {
101                 if (p->busNo == busNo && p->devNo == devNo)
102                         return p;
103         }
104         return NULL;
105 }
106
107 static inline void delbusdevices(struct list_head *list, u32 busNo)
108 {
109         VISORCHIPSET_DEVICE_INFO *p, *tmp;
110
111         list_for_each_entry_safe(p, tmp, list, entry) {
112                 if (p->busNo == busNo) {
113                         list_del(&p->entry);
114                         kfree(p);
115                 }
116         }
117 }
118
119 /** Attributes for a particular Supervisor bus.
120  *  (For a service partition acting as the server for buses/devices, there
121  *  is a 1-to-1 relationship between busses and guest partitions.)
122  *  Any visorchipset client can query these attributes using
123  *  visorchipset_get_client_bus_info() or visorchipset_get_bus_info().
124  */
125 typedef struct {
126         struct list_head entry;
127         u32 busNo;
128         VISORCHIPSET_STATE state;
129         VISORCHIPSET_CHANNEL_INFO chanInfo;
130         uuid_le partitionGuid;
131         u64 partitionHandle;
132         u8 *name;               /* UTF8 */
133         u8 *description;        /* UTF8 */
134         u64 Reserved1;
135         u32 Reserved2;
136         MYPROCOBJECT *procObject;
137         struct {
138                 u32 server:1;
139                 /* Add new fields above. */
140                 /* Remaining bits in this 32-bit word are unused. */
141         } flags;
142         CONTROLVM_MESSAGE_HEADER pendingMsgHdr; /* CONTROLVM MsgHdr */
143         /** For private use by the bus driver */
144         void *bus_driver_context;
145         u64 devNo;
146
147 } VISORCHIPSET_BUS_INFO;
148
149 static inline VISORCHIPSET_BUS_INFO *
150 findbus(struct list_head *list, u32 busNo)
151 {
152         VISORCHIPSET_BUS_INFO *p;
153
154         list_for_each_entry(p, list, entry) {
155                 if (p->busNo == busNo)
156                         return p;
157         }
158         return NULL;
159 }
160
161 /** Attributes for a particular Supervisor switch.
162  */
163 typedef struct {
164         u32 switchNo;
165         VISORCHIPSET_STATE state;
166         uuid_le switchTypeGuid;
167         u8 *authService1;
168         u8 *authService2;
169         u8 *authService3;
170         u8 *securityContext;
171         u64 Reserved;
172         u32 Reserved2;          /* CONTROLVM_ID */
173         struct device dev;
174         BOOL dev_exists;
175         CONTROLVM_MESSAGE_HEADER pendingMsgHdr;
176
177 } VISORCHIPSET_SWITCH_INFO;
178
179 /** Attributes for a particular Supervisor external port, which is connected
180  *  to a specific switch.
181  */
182 typedef struct {
183         u32 switchNo;
184         u32 externalPortNo;
185         VISORCHIPSET_STATE state;
186         uuid_le networkZoneGuid;
187         int pdPort;
188         u8 *ip;
189         u8 *ipNetmask;
190         u8 *ipBroadcast;
191         u8 *ipNetwork;
192         u8 *ipGateway;
193         u8 *ipDNS;
194         u64 Reserved1;
195         u32 Reserved2;          /* CONTROLVM_ID */
196         struct device dev;
197         BOOL dev_exists;
198         CONTROLVM_MESSAGE_HEADER pendingMsgHdr;
199
200 } VISORCHIPSET_EXTERNALPORT_INFO;
201
202 /** Attributes for a particular Supervisor internal port, which is how a
203  *  device connects to a particular switch.
204  */
205 typedef struct {
206         u32 switchNo;
207         u32 internalPortNo;
208         VISORCHIPSET_STATE state;
209         u32 busNo;              /* valid only when state.attached == 1 */
210         u32 devNo;              /* valid only when state.attached == 1 */
211         u64 Reserved1;
212         u32 Reserved2;          /* CONTROLVM_ID */
213         CONTROLVM_MESSAGE_HEADER pendingMsgHdr;
214         MYPROCOBJECT *procObject;
215
216 } VISORCHIPSET_INTERNALPORT_INFO;
217
218 /*  These functions will be called from within visorchipset when certain
219  *  events happen.  (The implementation of these functions is outside of
220  *  visorchipset.)
221  */
222 typedef struct {
223         void (*bus_create)(ulong busNo);
224         void (*bus_destroy)(ulong busNo);
225         void (*device_create)(ulong busNo, ulong devNo);
226         void (*device_destroy)(ulong busNo, ulong devNo);
227         void (*device_pause)(ulong busNo, ulong devNo);
228         void (*device_resume)(ulong busNo, ulong devNo);
229         int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
230                                  ulong *maxSize);
231 } VISORCHIPSET_BUSDEV_NOTIFIERS;
232
233 /*  These functions live inside visorchipset, and will be called to indicate
234  *  responses to specific events (by code outside of visorchipset).
235  *  For now, the value for each response is simply either:
236  *       0 = it worked
237  *      -1 = it failed
238  */
239 typedef struct {
240         void (*bus_create)(ulong busNo, int response);
241         void (*bus_destroy)(ulong busNo, int response);
242         void (*device_create)(ulong busNo, ulong devNo, int response);
243         void (*device_destroy)(ulong busNo, ulong devNo, int response);
244         void (*device_pause)(ulong busNo, ulong devNo, int response);
245         void (*device_resume)(ulong busNo, ulong devNo, int response);
246 } VISORCHIPSET_BUSDEV_RESPONDERS;
247
248 /** Register functions (in the bus driver) to get called by visorchipset
249  *  whenever a bus or device appears for which this service partition is
250  *  to be the server for.  visorchipset will fill in <responders>, to
251  *  indicate functions the bus driver should call to indicate message
252  *  responses.
253  */
254 void
255 visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
256                                     VISORCHIPSET_BUSDEV_RESPONDERS *responders,
257                                     ULTRA_VBUS_DEVICEINFO *driverInfo);
258
259 /** Register functions (in the bus driver) to get called by visorchipset
260  *  whenever a bus or device appears for which this service partition is
261  *  to be the client for.  visorchipset will fill in <responders>, to
262  *  indicate functions the bus driver should call to indicate message
263  *  responses.
264  */
265 void
266 visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
267                                     VISORCHIPSET_BUSDEV_RESPONDERS *responders,
268                                     ULTRA_VBUS_DEVICEINFO *driverInfo);
269
270 typedef void (*SPARREPORTEVENT_COMPLETE_FUNC) (CONTROLVM_MESSAGE *msg,
271                                                int status);
272
273 void visorchipset_device_pause_response(ulong busNo, ulong devNo, int response);
274
275 BOOL visorchipset_get_bus_info(ulong busNo, VISORCHIPSET_BUS_INFO *busInfo);
276 BOOL visorchipset_get_device_info(ulong busNo, ulong devNo,
277                                   VISORCHIPSET_DEVICE_INFO *devInfo);
278 BOOL visorchipset_get_switch_info(ulong switchNo,
279                                   VISORCHIPSET_SWITCH_INFO *switchInfo);
280 BOOL visorchipset_get_externalport_info(ulong switchNo, ulong externalPortNo,
281                                         VISORCHIPSET_EXTERNALPORT_INFO
282                                         *externalPortInfo);
283 BOOL visorchipset_set_bus_context(ulong busNo, void *context);
284 BOOL visorchipset_set_device_context(ulong busNo, ulong devNo, void *context);
285 int visorchipset_chipset_ready(void);
286 int visorchipset_chipset_selftest(void);
287 int visorchipset_chipset_notready(void);
288 void visorchipset_controlvm_respond_reportEvent(CONTROLVM_MESSAGE *msg,
289                                                 void *payload);
290 void visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type);
291 void *visorchipset_cache_alloc(struct kmem_cache *pool,
292                                BOOL ok_to_block, char *fn, int ln);
293 void visorchipset_cache_free(struct kmem_cache *pool, void *p,
294                              char *fn, int ln);
295
296 #if defined(TRANSMITFILE_DEBUG) || defined(DEBUG)
297 #define DBG_GETFILE_PAYLOAD(msg, controlvm_header)      \
298         LOGINF(msg,                                     \
299                (ulong)controlvm_header.PayloadVmOffset, \
300                (ulong)controlvm_header.PayloadMaxBytes)
301 #define DBG_GETFILE(fmt, ...)  LOGINF(fmt, ##__VA_ARGS__)
302 #define DBG_PUTFILE(fmt, ...)  LOGINF(fmt, ##__VA_ARGS__)
303 #else
304 #define DBG_GETFILE_PAYLOAD(msg, controlvm_header)
305 #define DBG_GETFILE(fmt, ...)
306 #define DBG_PUTFILE(fmt, ...)
307 #endif
308
309 #endif