staging: unisys: Remove appos_subsystems.h
[firefly-linux-kernel-4.4.55.git] / drivers / staging / unisys / include / uisutils.h
1 /* uisutils.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 /*
19  * Unisys Virtual HBA utilities header
20  */
21
22 #ifndef __UISUTILS__H__
23 #define __UISUTILS__H__
24 #include <linux/string.h>
25 #include <linux/io.h>
26 #include <linux/sched.h>
27 #include <linux/gfp.h>
28 #include <linux/uuid.h>
29 #include <linux/if_ether.h>
30
31 #include "vmcallinterface.h"
32 #include "channel.h"
33 #include "uisthread.h"
34 #include "uisqueue.h"
35 #include "vbusdeviceinfo.h"
36 #include <linux/atomic.h>
37
38 /* This is the MAGIC number stuffed by virthba in host->this_id. Used to
39  * identify virtual hbas.
40  */
41 #define UIS_MAGIC_VHBA 707
42
43 /* global function pointers that act as callback functions into
44  * uisnicmod, uissdmod, and virtpcimod
45  */
46 extern int (*uisnic_control_chan_func)(struct io_msgs *);
47 extern int (*uissd_control_chan_func)(struct io_msgs *);
48 extern int (*virt_control_chan_func)(struct guest_msgs *);
49
50 /* Return values of above callback functions: */
51 #define CCF_ERROR        0      /* completed and failed */
52 #define CCF_OK           1      /* completed successfully */
53 #define CCF_PENDING      2      /* operation still pending */
54 extern atomic_t uisutils_registered_services;
55
56 struct req_handler_info {
57         uuid_le switch_uuid;
58         int (*controlfunc)(struct io_msgs *);
59         unsigned long min_channel_bytes;
60         int (*server_channel_ok)(unsigned long channel_bytes);
61         int (*server_channel_init)(void *x, unsigned char *client_str,
62                                    u32 client_str_len, u64 bytes);
63         char switch_type_name[99];
64         struct list_head list_link;     /* links into ReqHandlerInfo_list */
65 };
66
67 struct req_handler_info *req_handler_find(uuid_le switch_uuid);
68
69 #define uislib_ioremap_cache(addr, size) \
70         dbg_ioremap_cache(addr, size, __FILE__, __LINE__)
71
72 static inline void __iomem *
73 dbg_ioremap_cache(u64 addr, unsigned long size, char *file, int line)
74 {
75         void __iomem *new;
76
77         new = ioremap_cache(addr, size);
78         return new;
79 }
80
81 #define uislib_ioremap(addr, size) dbg_ioremap(addr, size, __FILE__, __LINE__)
82
83 static inline void *
84 dbg_ioremap(u64 addr, unsigned long size, char *file, int line)
85 {
86         void *new;
87
88         new = ioremap(addr, size);
89         return new;
90 }
91
92 #define uislib_iounmap(addr) dbg_iounmap(addr, __FILE__, __LINE__)
93
94 static inline void
95 dbg_iounmap(void __iomem *addr, char *file, int line)
96 {
97         iounmap(addr);
98 }
99
100 #define PROC_READ_BUFFER_SIZE 131072    /* size of the buffer to allocate to
101                                          * hold all of /proc/XXX/info */
102 int uisutil_add_proc_line_ex(int *total, char **buffer, int *buffer_remaining,
103                              char *format, ...);
104
105 int uisctrl_register_req_handler(int type, void *fptr,
106                         struct ultra_vbus_deviceinfo *chipset_driver_info);
107
108 unsigned char *util_map_virt(struct phys_info *sg);
109 void util_unmap_virt(struct phys_info *sg);
110 unsigned char *util_map_virt_atomic(struct phys_info *sg);
111 void util_unmap_virt_atomic(void *buf);
112 int uislib_client_inject_add_bus(u32 bus_no, uuid_le inst_uuid,
113                                  u64 channel_addr, ulong n_channel_bytes);
114 int  uislib_client_inject_del_bus(u32 bus_no);
115
116 int uislib_client_inject_add_vhba(u32 bus_no, u32 dev_no,
117                                   u64 phys_chan_addr, u32 chan_bytes,
118                                   int is_test_addr, uuid_le inst_uuid,
119                                   struct irq_info *intr);
120 int  uislib_client_inject_pause_vhba(u32 bus_no, u32 dev_no);
121 int  uislib_client_inject_resume_vhba(u32 bus_no, u32 dev_no);
122 int uislib_client_inject_del_vhba(u32 bus_no, u32 dev_no);
123 int uislib_client_inject_add_vnic(u32 bus_no, u32 dev_no,
124                                   u64 phys_chan_addr, u32 chan_bytes,
125                                   int is_test_addr, uuid_le inst_uuid,
126                                   struct irq_info *intr);
127 int uislib_client_inject_pause_vnic(u32 bus_no, u32 dev_no);
128 int uislib_client_inject_resume_vnic(u32 bus_no, u32 dev_no);
129 int uislib_client_inject_del_vnic(u32 bus_no, u32 dev_no);
130 #ifdef STORAGE_CHANNEL
131 u64 uislib_storage_channel(int client_id);
132 #endif
133 int uislib_get_owned_pdest(struct uisscsi_dest *pdest);
134
135 int uislib_send_event(enum controlvm_id id,
136                       struct controlvm_message_packet *event);
137
138 /* structure used by vhba & vnic to keep track of queue & thread info */
139 struct chaninfo {
140         struct uisqueue_info *queueinfo;
141         /* this specifies the queue structures for a channel */
142         /* ALLOCATED BY THE OTHER END - WE JUST GET A POINTER TO THE MEMORY */
143         spinlock_t insertlock;
144         /* currently used only in virtnic when sending data to uisnic */
145         /* to synchronize the inserts into the signal queue */
146         struct uisthread_info threadinfo;
147         /* this specifies the thread structures used by the thread that */
148         /* handles this channel */
149 };
150
151 /* this is the wait code for all the threads - it is used to get
152 * something from a queue choices: wait_for_completion_interruptible,
153 * _timeout, interruptible_timeout
154 */
155 #define UIS_THREAD_WAIT_MSEC(x) { \
156         set_current_state(TASK_INTERRUPTIBLE); \
157         schedule_timeout(msecs_to_jiffies(x)); \
158 }
159
160 #define UIS_THREAD_WAIT_USEC(x) { \
161         set_current_state(TASK_INTERRUPTIBLE); \
162         schedule_timeout(usecs_to_jiffies(x)); \
163 }
164
165 #define UIS_THREAD_WAIT UIS_THREAD_WAIT_MSEC(5)
166
167 #define UIS_THREAD_WAIT_SEC(x) { \
168         set_current_state(TASK_INTERRUPTIBLE); \
169         schedule_timeout((x)*HZ); \
170 }
171
172 /* This is a hack until we fix IOVM to initialize the channel header
173  * correctly at DEVICE_CREATE time, INSTEAD OF waiting until
174  * DEVICE_CONFIGURE time.
175  */
176 static inline void
177 wait_for_valid_guid(uuid_le __iomem *guid)
178 {
179         uuid_le tmpguid;
180
181         while (1) {
182                 memcpy_fromio((void *)&tmpguid,
183                               (void __iomem *)guid, sizeof(uuid_le));
184                 if (uuid_le_cmp(tmpguid, NULL_UUID_LE) != 0)
185                         break;
186                 UIS_THREAD_WAIT_SEC(5);
187         }
188 }
189
190 static inline unsigned int
191 issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes)
192 {
193         struct vmcall_io_controlvm_addr_params params;
194         int result = VMCALL_SUCCESS;
195         u64 physaddr;
196
197         physaddr = virt_to_phys(&params);
198         ISSUE_IO_VMCALL(VMCALL_IO_CONTROLVM_ADDR, physaddr, result);
199         if (VMCALL_SUCCESSFUL(result)) {
200                 *control_addr = params.address;
201                 *control_bytes = params.channel_bytes;
202         }
203         return result;
204 }
205
206 static inline unsigned int issue_vmcall_io_diag_addr(u64 *diag_channel_addr)
207 {
208         struct vmcall_io_diag_addr_params params;
209         int result = VMCALL_SUCCESS;
210         u64 physaddr;
211
212         physaddr = virt_to_phys(&params);
213         ISSUE_IO_VMCALL(VMCALL_IO_DIAG_ADDR, physaddr, result);
214         if (VMCALL_SUCCESSFUL(result))
215                 *diag_channel_addr = params.address;
216         return result;
217 }
218
219 static inline unsigned int issue_vmcall_io_visorserial_addr(u64 *channel_addr)
220 {
221         struct vmcall_io_visorserial_addr_params params;
222         int result = VMCALL_SUCCESS;
223         u64 physaddr;
224
225         physaddr = virt_to_phys(&params);
226         ISSUE_IO_VMCALL(VMCALL_IO_VISORSERIAL_ADDR, physaddr, result);
227         if (VMCALL_SUCCESSFUL(result))
228                 *channel_addr = params.address;
229         return result;
230 }
231
232 static inline s64 issue_vmcall_query_guest_virtual_time_offset(void)
233 {
234         u64 result = VMCALL_SUCCESS;
235         u64 physaddr = 0;
236
237         ISSUE_IO_VMCALL(VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET, physaddr,
238                         result);
239         return result;
240 }
241
242 struct log_info_t {
243         unsigned long long last_cycles;
244         unsigned long long delta_sum[64];
245         unsigned long long delta_cnt[64];
246         unsigned long long max_delta[64];
247         unsigned long long min_delta[64];
248 };
249
250 static inline int issue_vmcall_update_physical_time(u64 adjustment)
251 {
252         int result = VMCALL_SUCCESS;
253
254         ISSUE_IO_VMCALL(VMCALL_UPDATE_PHYSICAL_TIME, adjustment, result);
255         return result;
256 }
257
258 static inline unsigned int issue_vmcall_channel_mismatch(const char *chname,
259                               const char *item_name, u32 line_no,
260                               const char *path_n_fn)
261 {
262         struct vmcall_channel_version_mismatch_params params;
263         int result = VMCALL_SUCCESS;
264         u64 physaddr;
265         char *last_slash = NULL;
266
267         strlcpy(params.chname, chname, sizeof(params.chname));
268         strlcpy(params.item_name, item_name, sizeof(params.item_name));
269         params.line_no = line_no;
270
271         last_slash = strrchr(path_n_fn, '/');
272         if (last_slash != NULL) {
273                 last_slash++;
274                 strlcpy(params.file_name, last_slash, sizeof(params.file_name));
275         } else
276                 strlcpy(params.file_name,
277                         "Cannot determine source filename",
278                         sizeof(params.file_name));
279
280         physaddr = virt_to_phys(&params);
281         ISSUE_IO_VMCALL(VMCALL_CHANNEL_VERSION_MISMATCH, physaddr, result);
282         return result;
283 }
284
285 #define UIS_DAEMONIZE(nam)
286
287 void uislib_enable_channel_interrupts(u32 bus_no, u32 dev_no,
288                                       int (*interrupt)(void *),
289                                       void *interrupt_context);
290 void uislib_disable_channel_interrupts(u32 bus_no, u32 dev_no);
291 void uislib_force_channel_interrupt(u32 bus_no, u32 dev_no);
292
293 #endif /* __UISUTILS__H__ */