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 "vbusdeviceinfo.h"
36 #include <linux/atomic.h>
38 /* This is the MAGIC number stuffed by virthba in host->this_id. Used to
39 * identify virtual hbas.
41 #define UIS_MAGIC_VHBA 707
43 /* global function pointers that act as callback functions into
44 * uisnicmod, uissdmod, and virtpcimod
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 *);
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;
56 struct req_handler_info {
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 */
67 struct req_handler_info *req_handler_find(uuid_le switch_uuid);
69 #define uislib_ioremap_cache(addr, size) \
70 dbg_ioremap_cache(addr, size, __FILE__, __LINE__)
72 static inline void __iomem *
73 dbg_ioremap_cache(u64 addr, unsigned long size, char *file, int line)
77 new = ioremap_cache(addr, size);
81 #define uislib_ioremap(addr, size) dbg_ioremap(addr, size, __FILE__, __LINE__)
84 dbg_ioremap(u64 addr, unsigned long size, char *file, int line)
88 new = ioremap(addr, size);
92 #define uislib_iounmap(addr) dbg_iounmap(addr, __FILE__, __LINE__)
95 dbg_iounmap(void __iomem *addr, char *file, int line)
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,
105 int uisctrl_register_req_handler(int type, void *fptr,
106 struct ultra_vbus_deviceinfo *chipset_driver_info);
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);
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);
133 int uislib_get_owned_pdest(struct uisscsi_dest *pdest);
135 int uislib_send_event(enum controlvm_id id,
136 struct controlvm_message_packet *event);
138 /* structure used by vhba & vnic to keep track of queue & thread info */
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 */
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
155 #define UIS_THREAD_WAIT_MSEC(x) { \
156 set_current_state(TASK_INTERRUPTIBLE); \
157 schedule_timeout(msecs_to_jiffies(x)); \
160 #define UIS_THREAD_WAIT_USEC(x) { \
161 set_current_state(TASK_INTERRUPTIBLE); \
162 schedule_timeout(usecs_to_jiffies(x)); \
165 #define UIS_THREAD_WAIT UIS_THREAD_WAIT_MSEC(5)
167 #define UIS_THREAD_WAIT_SEC(x) { \
168 set_current_state(TASK_INTERRUPTIBLE); \
169 schedule_timeout((x)*HZ); \
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.
177 wait_for_valid_guid(uuid_le __iomem *guid)
182 memcpy_fromio((void *)&tmpguid,
183 (void __iomem *)guid, sizeof(uuid_le));
184 if (uuid_le_cmp(tmpguid, NULL_UUID_LE) != 0)
186 UIS_THREAD_WAIT_SEC(5);
190 static inline unsigned int
191 issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes)
193 struct vmcall_io_controlvm_addr_params params;
194 int result = VMCALL_SUCCESS;
197 physaddr = virt_to_phys(¶ms);
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;
206 static inline unsigned int issue_vmcall_io_diag_addr(u64 *diag_channel_addr)
208 struct vmcall_io_diag_addr_params params;
209 int result = VMCALL_SUCCESS;
212 physaddr = virt_to_phys(¶ms);
213 ISSUE_IO_VMCALL(VMCALL_IO_DIAG_ADDR, physaddr, result);
214 if (VMCALL_SUCCESSFUL(result))
215 *diag_channel_addr = params.address;
219 static inline unsigned int issue_vmcall_io_visorserial_addr(u64 *channel_addr)
221 struct vmcall_io_visorserial_addr_params params;
222 int result = VMCALL_SUCCESS;
225 physaddr = virt_to_phys(¶ms);
226 ISSUE_IO_VMCALL(VMCALL_IO_VISORSERIAL_ADDR, physaddr, result);
227 if (VMCALL_SUCCESSFUL(result))
228 *channel_addr = params.address;
232 static inline s64 issue_vmcall_query_guest_virtual_time_offset(void)
234 u64 result = VMCALL_SUCCESS;
237 ISSUE_IO_VMCALL(VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET, physaddr,
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];
250 static inline int issue_vmcall_update_physical_time(u64 adjustment)
252 int result = VMCALL_SUCCESS;
254 ISSUE_IO_VMCALL(VMCALL_UPDATE_PHYSICAL_TIME, adjustment, result);
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)
262 struct vmcall_channel_version_mismatch_params params;
263 int result = VMCALL_SUCCESS;
265 char *last_slash = NULL;
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;
271 last_slash = strrchr(path_n_fn, '/');
272 if (last_slash != NULL) {
274 strlcpy(params.file_name, last_slash, sizeof(params.file_name));
276 strlcpy(params.file_name,
277 "Cannot determine source filename",
278 sizeof(params.file_name));
280 physaddr = virt_to_phys(¶ms);
281 ISSUE_IO_VMCALL(VMCALL_CHANNEL_VERSION_MISMATCH, physaddr, result);
285 #define UIS_DAEMONIZE(nam)
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);
293 #endif /* __UISUTILS__H__ */