3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
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.
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
19 * Unisys Virtual HBA utilities header
22 #ifndef __UISUTILS__H__
23 #define __UISUTILS__H__
24 #include <linux/string.h>
26 #include <linux/sched.h>
27 #include <linux/gfp.h>
28 #include <linux/uuid.h>
29 #include <linux/if_ether.h>
31 #include "vmcallinterface.h"
33 #include "uisthread.h"
35 #include "diagnostics/appos_subsystems.h"
36 #include "vbusdeviceinfo.h"
37 #include <linux/atomic.h>
39 /* This is the MAGIC number stuffed by virthba in host->this_id. Used to
40 * identify virtual hbas.
42 #define UIS_MAGIC_VHBA 707
44 /* global function pointers that act as callback functions into
45 * uisnicmod, uissdmod, and virtpcimod
47 extern int (*uisnic_control_chan_func)(struct io_msgs *);
48 extern int (*uissd_control_chan_func)(struct io_msgs *);
49 extern int (*virt_control_chan_func)(struct guest_msgs *);
51 /* Return values of above callback functions: */
52 #define CCF_ERROR 0 /* completed and failed */
53 #define CCF_OK 1 /* completed successfully */
54 #define CCF_PENDING 2 /* operation still pending */
55 extern atomic_t uisutils_registered_services;
57 struct req_handler_info {
59 int (*controlfunc)(struct io_msgs *);
60 unsigned long min_channel_bytes;
61 int (*server_channel_ok)(unsigned long channel_bytes);
62 int (*server_channel_init)(void *x, unsigned char *client_str,
63 u32 client_str_len, u64 bytes);
64 char switch_type_name[99];
65 struct list_head list_link; /* links into ReqHandlerInfo_list */
68 struct req_handler_info *req_handler_find(uuid_le switch_uuid);
70 #define uislib_ioremap_cache(addr, size) \
71 dbg_ioremap_cache(addr, size, __FILE__, __LINE__)
73 static inline void __iomem *
74 dbg_ioremap_cache(u64 addr, unsigned long size, char *file, int line)
78 new = ioremap_cache(addr, size);
82 #define uislib_ioremap(addr, size) dbg_ioremap(addr, size, __FILE__, __LINE__)
85 dbg_ioremap(u64 addr, unsigned long size, char *file, int line)
89 new = ioremap(addr, size);
93 #define uislib_iounmap(addr) dbg_iounmap(addr, __FILE__, __LINE__)
96 dbg_iounmap(void __iomem *addr, char *file, int line)
101 #define PROC_READ_BUFFER_SIZE 131072 /* size of the buffer to allocate to
102 * hold all of /proc/XXX/info */
103 int uisutil_add_proc_line_ex(int *total, char **buffer, int *buffer_remaining,
106 int uisctrl_register_req_handler(int type, void *fptr,
107 struct ultra_vbus_deviceinfo *chipset_driver_info);
109 unsigned char *util_map_virt(struct phys_info *sg);
110 void util_unmap_virt(struct phys_info *sg);
111 unsigned char *util_map_virt_atomic(struct phys_info *sg);
112 void util_unmap_virt_atomic(void *buf);
113 int uislib_client_inject_add_bus(u32 bus_no, uuid_le inst_uuid,
114 u64 channel_addr, ulong n_channel_bytes);
115 int uislib_client_inject_del_bus(u32 bus_no);
117 int uislib_client_inject_add_vhba(u32 bus_no, u32 dev_no,
118 u64 phys_chan_addr, u32 chan_bytes,
119 int is_test_addr, uuid_le inst_uuid,
120 struct irq_info *intr);
121 int uislib_client_inject_pause_vhba(u32 bus_no, u32 dev_no);
122 int uislib_client_inject_resume_vhba(u32 bus_no, u32 dev_no);
123 int uislib_client_inject_del_vhba(u32 bus_no, u32 dev_no);
124 int uislib_client_inject_add_vnic(u32 bus_no, u32 dev_no,
125 u64 phys_chan_addr, u32 chan_bytes,
126 int is_test_addr, uuid_le inst_uuid,
127 struct irq_info *intr);
128 int uislib_client_inject_pause_vnic(u32 bus_no, u32 dev_no);
129 int uislib_client_inject_resume_vnic(u32 bus_no, u32 dev_no);
130 int uislib_client_inject_del_vnic(u32 bus_no, u32 dev_no);
131 #ifdef STORAGE_CHANNEL
132 u64 uislib_storage_channel(int client_id);
134 int uislib_get_owned_pdest(struct uisscsi_dest *pdest);
136 int uislib_send_event(enum controlvm_id id,
137 struct controlvm_message_packet *event);
139 /* structure used by vhba & vnic to keep track of queue & thread info */
141 struct uisqueue_info *queueinfo;
142 /* this specifies the queue structures for a channel */
143 /* ALLOCATED BY THE OTHER END - WE JUST GET A POINTER TO THE MEMORY */
144 spinlock_t insertlock;
145 /* currently used only in virtnic when sending data to uisnic */
146 /* to synchronize the inserts into the signal queue */
147 struct uisthread_info threadinfo;
148 /* this specifies the thread structures used by the thread that */
149 /* handles this channel */
152 /* this is the wait code for all the threads - it is used to get
153 * something from a queue choices: wait_for_completion_interruptible,
154 * _timeout, interruptible_timeout
156 #define UIS_THREAD_WAIT_MSEC(x) { \
157 set_current_state(TASK_INTERRUPTIBLE); \
158 schedule_timeout(msecs_to_jiffies(x)); \
161 #define UIS_THREAD_WAIT_USEC(x) { \
162 set_current_state(TASK_INTERRUPTIBLE); \
163 schedule_timeout(usecs_to_jiffies(x)); \
166 #define UIS_THREAD_WAIT UIS_THREAD_WAIT_MSEC(5)
168 #define UIS_THREAD_WAIT_SEC(x) { \
169 set_current_state(TASK_INTERRUPTIBLE); \
170 schedule_timeout((x)*HZ); \
173 /* This is a hack until we fix IOVM to initialize the channel header
174 * correctly at DEVICE_CREATE time, INSTEAD OF waiting until
175 * DEVICE_CONFIGURE time.
178 wait_for_valid_guid(uuid_le __iomem *guid)
183 memcpy_fromio((void *)&tmpguid,
184 (void __iomem *)guid, sizeof(uuid_le));
185 if (uuid_le_cmp(tmpguid, NULL_UUID_LE) != 0)
187 UIS_THREAD_WAIT_SEC(5);
191 static inline unsigned int
192 issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes)
194 struct vmcall_io_controlvm_addr_params params;
195 int result = VMCALL_SUCCESS;
198 physaddr = virt_to_phys(¶ms);
199 ISSUE_IO_VMCALL(VMCALL_IO_CONTROLVM_ADDR, physaddr, result);
200 if (VMCALL_SUCCESSFUL(result)) {
201 *control_addr = params.address;
202 *control_bytes = params.channel_bytes;
207 static inline unsigned int issue_vmcall_io_diag_addr(u64 *diag_channel_addr)
209 struct vmcall_io_diag_addr_params params;
210 int result = VMCALL_SUCCESS;
213 physaddr = virt_to_phys(¶ms);
214 ISSUE_IO_VMCALL(VMCALL_IO_DIAG_ADDR, physaddr, result);
215 if (VMCALL_SUCCESSFUL(result))
216 *diag_channel_addr = params.address;
220 static inline unsigned int issue_vmcall_io_visorserial_addr(u64 *channel_addr)
222 struct vmcall_io_visorserial_addr_params params;
223 int result = VMCALL_SUCCESS;
226 physaddr = virt_to_phys(¶ms);
227 ISSUE_IO_VMCALL(VMCALL_IO_VISORSERIAL_ADDR, physaddr, result);
228 if (VMCALL_SUCCESSFUL(result))
229 *channel_addr = params.address;
233 static inline s64 issue_vmcall_query_guest_virtual_time_offset(void)
235 u64 result = VMCALL_SUCCESS;
238 ISSUE_IO_VMCALL(VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET, physaddr,
244 unsigned long long last_cycles;
245 unsigned long long delta_sum[64];
246 unsigned long long delta_cnt[64];
247 unsigned long long max_delta[64];
248 unsigned long long min_delta[64];
251 static inline int issue_vmcall_update_physical_time(u64 adjustment)
253 int result = VMCALL_SUCCESS;
255 ISSUE_IO_VMCALL(VMCALL_UPDATE_PHYSICAL_TIME, adjustment, result);
259 static inline unsigned int issue_vmcall_channel_mismatch(const char *chname,
260 const char *item_name, u32 line_no,
261 const char *path_n_fn)
263 struct vmcall_channel_version_mismatch_params params;
264 int result = VMCALL_SUCCESS;
266 char *last_slash = NULL;
268 strlcpy(params.chname, chname, sizeof(params.chname));
269 strlcpy(params.item_name, item_name, sizeof(params.item_name));
270 params.line_no = line_no;
272 last_slash = strrchr(path_n_fn, '/');
273 if (last_slash != NULL) {
275 strlcpy(params.file_name, last_slash, sizeof(params.file_name));
277 strlcpy(params.file_name,
278 "Cannot determine source filename",
279 sizeof(params.file_name));
281 physaddr = virt_to_phys(¶ms);
282 ISSUE_IO_VMCALL(VMCALL_CHANNEL_VERSION_MISMATCH, physaddr, result);
286 #define UIS_DAEMONIZE(nam)
287 void *uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln);
288 #define UISCACHEALLOC(cur_pool) uislib_cache_alloc(cur_pool, __FILE__, __LINE__)
289 void uislib_cache_free(struct kmem_cache *cur_pool, void *p, char *fn, int ln);
290 #define UISCACHEFREE(cur_pool, p) \
291 uislib_cache_free(cur_pool, p, __FILE__, __LINE__)
293 void uislib_enable_channel_interrupts(u32 bus_no, u32 dev_no,
294 int (*interrupt)(void *),
295 void *interrupt_context);
296 void uislib_disable_channel_interrupts(u32 bus_no, u32 dev_no);
297 void uislib_force_channel_interrupt(u32 bus_no, u32 dev_no);
299 #endif /* __UISUTILS__H__ */