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