Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / unisys / include / uisqueue.h
1 /* uisqueue.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 IO Virtualization header NOTE: This file contains only Linux
20  * specific structs.  All OS-independent structs are in iochannel.h.xx
21  */
22
23 #ifndef __UISQUEUE_H__
24 #define __UISQUEUE_H__
25
26 #include "linux/version.h"
27 #include "iochannel.h"
28 #include <linux/atomic.h>
29 #include <linux/semaphore.h>
30 #include <linux/uuid.h>
31
32 #include "controlvmchannel.h"
33 #include "controlvmcompletionstatus.h"
34
35 struct uisqueue_info {
36         struct channel_header __iomem *chan;
37         /* channel containing queues in which scsi commands &
38          * responses are queued
39          */
40         u64 packets_sent;
41         u64 packets_received;
42         u64 interrupts_sent;
43         u64 interrupts_received;
44         u64 max_not_empty_cnt;
45         u64 total_wakeup_cnt;
46         u64 non_empty_wakeup_cnt;
47
48         struct {
49                 struct signal_queue_header reserved1;   /*  */
50                 struct signal_queue_header reserved2;   /*  */
51         } safe_uis_queue;
52         unsigned int (*send_int_if_needed)(struct uisqueue_info *info,
53                                            unsigned int whichcqueue,
54                                            unsigned char issue_irq_if_empty,
55                                            u64 irq_handle,
56                                            unsigned char io_termination);
57 };
58
59 /* uisqueue_put_cmdrsp_with_lock_client queues a commmand or response
60  * to the specified queue, at the tail if the queue is full but
61  * oktowait == 0, then it return 0 indicating failure.  otherwise it
62  * wait for the queue to become non-full. If command is queued, return
63  * 1 for success.
64  */
65 #define DONT_ISSUE_INTERRUPT 0
66 #define ISSUE_INTERRUPT          1
67
68 #define DONT_WAIT                        0
69 #define OK_TO_WAIT                       1
70 #define UISLIB_LOCK_PREFIX \
71                 ".section .smp_locks,\"a\"\n"   \
72                 _ASM_ALIGN "\n"                 \
73                 _ASM_PTR "661f\n" /* address */ \
74                 ".previous\n"                   \
75                 "661:\n\tlock; "
76
77 unsigned long long uisqueue_interlocked_or(unsigned long long __iomem *tgt,
78                                            unsigned long long set);
79 unsigned long long uisqueue_interlocked_and(unsigned long long __iomem *tgt,
80                                             unsigned long long set);
81
82 int uisqueue_put_cmdrsp_with_lock_client(struct uisqueue_info *queueinfo,
83                                          struct uiscmdrsp *cmdrsp,
84                                          unsigned int queue,
85                                          void *insertlock,
86                                          unsigned char issue_irq_if_empty,
87                                          u64 irq_handle,
88                                          char oktowait,
89                                          u8 *channel_id);
90
91 /* uisqueue_get_cmdrsp gets the cmdrsp entry at the head of the queue
92  * and copies it to the area pointed by cmdrsp param.
93  * returns 0 if queue is empty, 1 otherwise
94  */
95 int
96
97 uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo, void *cmdrsp,
98                     unsigned int queue);
99
100 #define MAX_NAME_SIZE_UISQUEUE 64
101
102 struct extport_info {
103         u8 valid:1;
104         /* if 1, indicates this extport slot is occupied
105          * if 0, indicates that extport slot is unoccupied */
106
107         u32 num_devs_using;
108         /* When extport is added, this is set to 0.  For exports
109         * located in NETWORK switches:
110         * Each time a VNIC, i.e., intport, is added to the switch this
111         * is used to assign a pref_pnic for the VNIC and when assigned
112         * to a VNIC this counter is incremented. When a VNIC is
113         * deleted, the extport corresponding to the VNIC's pref_pnic
114         * is located and its num_devs_using is decremented. For VNICs,
115         * num_devs_using is basically used to load-balance transmit
116         * traffic from VNICs.
117         */
118
119         struct switch_info *swtch;
120         struct pci_id pci_id;
121         char name[MAX_NAME_SIZE_UISQUEUE];
122         union {
123                 struct vhba_wwnn wwnn;
124                 unsigned char macaddr[MAX_MACADDR_LEN];
125         };
126 };
127
128 struct device_info {
129         void __iomem *chanptr;
130         u64 channel_addr;
131         u64 channel_bytes;
132         uuid_le channel_uuid;
133         uuid_le instance_uuid;
134         struct irq_info intr;
135         struct switch_info *swtch;
136         char devid[30];         /* "vbus<busno>:dev<devno>" */
137         u16 polling;
138         struct semaphore interrupt_callback_lock;
139         u32 bus_no;
140         u32 dev_no;
141         int (*interrupt)(void *);
142         void *interrupt_context;
143         void *private_data;
144         struct list_head list_polling_device_channels;
145         unsigned long long moved_to_tail_cnt;
146         unsigned long long first_busy_cnt;
147         unsigned long long last_on_list_cnt;
148 };
149
150 enum switch_type {
151         RECOVERY_LAN = 1,
152         IB_LAN = 2
153 };
154
155 struct bus_info {
156         u32 bus_no, device_count;
157         struct device_info **device;
158         u64 guest_handle, recv_bus_irq_handle;
159         uuid_le bus_inst_uuid;
160         struct ultra_vbus_channel_protocol __iomem *bus_channel;
161         int bus_channel_bytes;
162         struct proc_dir_entry *proc_dir;        /* proc/uislib/vbus/<x> */
163         struct proc_dir_entry *proc_info;       /* proc/uislib/vbus/<x>/info */
164         char name[25];
165         char partition_name[99];
166         struct bus_info *next;
167         u8 local_vnic;          /* 1 if local vnic created internally
168                                  * by IOVM; 0 otherwise... */
169 };
170
171 struct sn_list_entry {
172         struct uisscsi_dest pdest;      /* scsi bus, target, lun for
173                                          * phys disk */
174         u8 sernum[MAX_SERIAL_NUM];      /* serial num of physical
175                                          * disk.. The length is always
176                                          * MAX_SERIAL_NUM, padded with
177                                          * spaces */
178         struct sn_list_entry *next;
179 };
180
181 /*
182  * IO messages sent to UisnicControlChanFunc & UissdControlChanFunc by
183  * code that processes the ControlVm channel messages.
184  */
185
186 enum iopart_msg_type {
187         IOPART_ADD_VNIC,
188         IOPART_DEL_VNIC,
189         IOPART_DEL_ALL_VNICS,
190         IOPART_ADD_VHBA,
191         IOPART_ADD_VDISK,
192         IOPART_DEL_VHBA,
193         IOPART_DEL_VDISK,
194         IOPART_DEL_ALL_VDISKS_FOR_VHBA,
195         IOPART_DEL_ALL_VHBAS,
196         IOPART_ATTACH_PHBA,
197         IOPART_DETACH_PHBA,     /* 10 */
198         IOPART_ATTACH_PNIC,
199         IOPART_DETACH_PNIC,
200         IOPART_DETACH_VHBA,
201         IOPART_DETACH_VNIC,
202         IOPART_PAUSE_VDISK,
203         IOPART_RESUME_VDISK,
204         IOPART_ADD_DEVICE,      /* add generic device */
205         IOPART_DEL_DEVICE,      /* del generic device */
206 };
207
208 struct add_virt_iopart {
209         void *chanptr;          /* pointer to data channel */
210         u64 guest_handle;       /* used to convert guest physical
211                                  * address to real physical address
212                                  * for DMA, for ex. */
213         u64 recv_bus_irq_handle;        /* used to register to receive
214                                          * bus level interrupts. */
215         struct irq_info intr;   /* contains recv & send
216                                          * interrupt info */
217         /* recvInterruptHandle is used to register to receive
218         * interrupts on the data channel. Used by GuestLinux/Windows
219         * IO drivers to connect to interrupt.  sendInterruptHandle is
220         * used by IOPart drivers as parameter to
221         * Issue_VMCALL_IO_QUEUE_TRANSITION to interrupt thread in
222         * guest linux/windows IO drivers when data channel queue for
223         * vhba/vnic goes from EMPTY to NON-EMPTY. */
224         struct switch_info *swtch;      /* pointer to the virtual
225                                          * switch to which the vnic is
226                                          * connected */
227
228         u8 use_g2g_copy;        /* Used to determine if a virtual HBA
229                                  * needs to use G2G copy. */
230         u8 filler[7];
231
232         u32 bus_no;
233         u32 dev_no;
234         char *params;
235         ulong params_bytes;
236
237 };
238
239 struct add_vdisk_iopart {
240         void *chanptr;                /* pointer to data channel */
241         int implicit;
242         struct uisscsi_dest vdest;    /* scsi bus, target, lun for virt disk */
243         struct uisscsi_dest pdest;    /* scsi bus, target, lun for phys disk */
244         u8 sernum[MAX_SERIAL_NUM];    /* serial num of physical disk */
245         u32 serlen;                   /* length of serial num */
246 };
247
248 struct del_vdisk_iopart {
249         void *chanptr;               /* pointer to data channel */
250         struct uisscsi_dest vdest;   /* scsi bus, target, lun for virt disk */
251 };
252
253 struct del_virt_iopart {
254         void *chanptr;               /* pointer to data channel */
255 };
256
257 struct det_virt_iopart {             /* detach internal port */
258         void *chanptr;               /* pointer to data channel */
259         struct switch_info *swtch;
260 };
261
262 struct paures_vdisk_iopart {
263         void *chanptr;               /* pointer to data channel */
264         struct uisscsi_dest vdest;   /* scsi bus, target, lun for virt disk */
265 };
266
267 struct add_switch_iopart {           /* add switch */
268         struct switch_info *swtch;
269         char *params;
270         ulong params_bytes;
271 };
272
273 struct del_switch_iopart {           /* destroy switch */
274         struct switch_info *swtch;
275 };
276
277 struct io_msgs {
278         enum iopart_msg_type msgtype;
279
280         /* additional params needed by some messages */
281         union {
282                 struct add_virt_iopart add_vhba;
283                 struct add_virt_iopart add_vnic;
284                 struct add_vdisk_iopart add_vdisk;
285                 struct del_virt_iopart del_vhba;
286                 struct del_virt_iopart del_vnic;
287                 struct det_virt_iopart det_vhba;
288                 struct det_virt_iopart det_vnic;
289                 struct del_vdisk_iopart del_vdisk;
290                 struct del_virt_iopart del_all_vdisks_for_vhba;
291                 struct add_virt_iopart add_device;
292                 struct del_virt_iopart del_device;
293                 struct det_virt_iopart det_intport;
294                 struct add_switch_iopart add_switch;
295                 struct del_switch_iopart del_switch;
296                 struct extport_info *ext_port;  /* for attach or detach
297                                                  * pnic/generic delete all
298                                                  * vhbas/allvnics need no
299                                                  * parameters */
300                 struct paures_vdisk_iopart paures_vdisk;
301         };
302 };
303
304 /*
305 * Guest messages sent to VirtControlChanFunc by code that processes
306 * the ControlVm channel messages.
307 */
308
309 enum guestpart_msg_type {
310         GUEST_ADD_VBUS,
311         GUEST_ADD_VHBA,
312         GUEST_ADD_VNIC,
313         GUEST_DEL_VBUS,
314         GUEST_DEL_VHBA,
315         GUEST_DEL_VNIC,
316         GUEST_DEL_ALL_VHBAS,
317         GUEST_DEL_ALL_VNICS,
318         GUEST_DEL_ALL_VBUSES,   /* deletes all vhbas & vnics on all
319                                  * buses and deletes all buses */
320         GUEST_PAUSE_VHBA,
321         GUEST_PAUSE_VNIC,
322         GUEST_RESUME_VHBA,
323         GUEST_RESUME_VNIC
324 };
325
326 struct add_vbus_guestpart {
327         void __iomem *chanptr;          /* pointer to data channel for bus -
328                                          * NOT YET USED */
329         u32 bus_no;             /* bus number to be created/deleted */
330         u32 dev_count;  /* max num of devices on bus */
331         uuid_le bus_uuid;       /* indicates type of bus */
332         uuid_le instance_uuid;  /* instance guid for device */
333 };
334
335 struct del_vbus_guestpart {
336         u32 bus_no;             /* bus number to be deleted */
337         /* once we start using the bus's channel, add can dump busNo
338         * into the channel header and then delete will need only one
339         * parameter, chanptr. */
340 };
341
342 struct add_virt_guestpart {
343         void __iomem *chanptr;          /* pointer to data channel */
344         u32 bus_no;             /* bus number for the operation */
345         u32 device_no;          /* number of device on the bus */
346         uuid_le instance_uuid;  /* instance guid for device */
347         struct irq_info intr;   /* recv/send interrupt info */
348         /* recvInterruptHandle contains info needed in order to
349          * register to receive interrupts on the data channel.
350          * sendInterruptHandle contains handle which is provided to
351          * monitor VMCALL that will cause an interrupt to be generated
352          * for the other end.
353          */
354 };
355
356 struct pause_virt_guestpart {
357         void __iomem *chanptr;          /* pointer to data channel */
358 };
359
360 struct resume_virt_guestpart {
361         void __iomem *chanptr;          /* pointer to data channel */
362 };
363
364 struct del_virt_guestpart {
365         void __iomem *chanptr;          /* pointer to data channel */
366 };
367
368 struct init_chipset_guestpart {
369         u32 bus_count;          /* indicates the max number of busses */
370         u32 switch_count;       /* indicates the max number of switches */
371 };
372
373 struct guest_msgs {
374         enum guestpart_msg_type msgtype;
375
376         /* additional params needed by messages */
377         union {
378                 struct add_vbus_guestpart add_vbus;
379                 struct add_virt_guestpart add_vhba;
380                 struct add_virt_guestpart add_vnic;
381                 struct pause_virt_guestpart pause_vhba;
382                 struct pause_virt_guestpart pause_vnic;
383                 struct resume_virt_guestpart resume_vhba;
384                 struct resume_virt_guestpart resume_vnic;
385                 struct del_vbus_guestpart del_vbus;
386                 struct del_virt_guestpart del_vhba;
387                 struct del_virt_guestpart del_vnic;
388                 struct del_vbus_guestpart del_all_vhbas;
389                 struct del_vbus_guestpart del_all_vnics;
390                 /* del_all_vbuses needs no parameters */
391         };
392         struct init_chipset_guestpart init_chipset;
393
394 };
395
396 #endif                          /* __UISQUEUE_H__ */