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 IO Virtualization header NOTE: This file contains only Linux
20 * specific structs. All OS-independent structs are in iochannel.h.xx
23 #ifndef __UISQUEUE_H__
24 #define __UISQUEUE_H__
26 #include "linux/version.h"
27 #include "iochannel.h"
29 #include <linux/atomic.h>
30 #include <linux/semaphore.h>
31 #include <linux/uuid.h>
33 #include "controlvmchannel.h"
34 #include "controlvmcompletionstatus.h"
36 struct uisqueue_info {
38 CHANNEL_HEADER __iomem *chan;
39 /* channel containing queues in which scsi commands &
40 * responses are queued
45 U64 interrupts_received;
46 U64 max_not_empty_cnt;
48 U64 non_empty_wakeup_cnt;
51 SIGNAL_QUEUE_HEADER Reserved1; /* */
52 SIGNAL_QUEUE_HEADER Reserved2; /* */
54 unsigned int (*send_int_if_needed)(struct uisqueue_info *info,
55 unsigned int whichcqueue,
56 unsigned char issueInterruptIfEmpty,
58 unsigned char io_termination);
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
67 #define DONT_ISSUE_INTERRUPT 0
68 #define ISSUE_INTERRUPT 1
72 #define UISLIB_LOCK_PREFIX \
73 ".section .smp_locks,\"a\"\n" \
75 _ASM_PTR "661f\n" /* address */ \
79 unsigned long long uisqueue_InterlockedOr(unsigned long long __iomem *Target,
80 unsigned long long Set);
81 unsigned long long uisqueue_InterlockedAnd(unsigned long long __iomem *Target,
82 unsigned long long Set);
84 unsigned int uisqueue_send_int_if_needed(struct uisqueue_info *pqueueinfo,
85 unsigned int whichqueue,
86 unsigned char issueInterruptIfEmpty,
88 unsigned char io_termination);
90 int uisqueue_put_cmdrsp_with_lock_client(struct uisqueue_info *queueinfo,
91 struct uiscmdrsp *cmdrsp,
94 unsigned char issueInterruptIfEmpty,
99 /* uisqueue_get_cmdrsp gets the cmdrsp entry at the head of the queue
100 * and copies it to the area pointed by cmdrsp param.
101 * returns 0 if queue is empty, 1 otherwise
105 uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo, void *cmdrsp,
108 #define MAX_NAME_SIZE_UISQUEUE 64
110 struct extport_info {
112 /* if 1, indicates this extport slot is occupied
113 * if 0, indicates that extport slot is unoccupied */
116 /* When extport is added, this is set to 0. For exports
117 * located in NETWORK switches:
118 * Each time a VNIC, i.e., intport, is added to the switch this
119 * is used to assign a pref_pnic for the VNIC and when assigned
120 * to a VNIC this counter is incremented. When a VNIC is
121 * deleted, the extport corresponding to the VNIC's pref_pnic
122 * is located and its num_devs_using is decremented. For VNICs,
123 * num_devs_using is basically used to load-balance transmit
124 * traffic from VNICs.
127 struct switch_info *swtch;
129 char name[MAX_NAME_SIZE_UISQUEUE];
131 struct vhba_wwnn wwnn;
132 unsigned char macaddr[MAX_MACADDR_LEN];
137 void __iomem *chanptr;
140 uuid_le channelTypeGuid;
142 struct InterruptInfo intr;
143 struct switch_info *swtch;
144 char devid[30]; /* "vbus<busno>:dev<devno>" */
146 struct semaphore interrupt_callback_lock;
149 int (*interrupt)(void *);
150 void *interrupt_context;
152 struct list_head list_polling_device_channels;
153 unsigned long long moved_to_tail_cnt;
154 unsigned long long first_busy_cnt;
155 unsigned long long last_on_list_cnt;
164 U32 busNo, deviceCount;
165 struct device_info **device;
166 U64 guestHandle, recvBusInterruptHandle;
168 ULTRA_VBUS_CHANNEL_PROTOCOL __iomem *pBusChannel;
170 struct proc_dir_entry *proc_dir; /* proc/uislib/vbus/<x> */
171 struct proc_dir_entry *proc_info; /* proc/uislib/vbus/<x>/info */
173 char partitionName[99];
174 struct bus_info *next;
175 U8 localVnic; /* 1 if local vnic created internally
176 * by IOVM; 0 otherwise... */
179 #define DEDICATED_SWITCH(pSwitch) ((pSwitch->extPortCount == 1) && \
180 (pSwitch->intPortCount == 1))
182 struct sn_list_entry {
183 struct uisscsi_dest pdest; /* scsi bus, target, lun for
185 U8 sernum[MAX_SERIAL_NUM]; /* serial num of physical
186 * disk.. The length is always
187 * MAX_SERIAL_NUM, padded with
189 struct sn_list_entry *next;
192 struct networkPolicy {
195 U32 peerforwarding:1;
203 * IO messages sent to UisnicControlChanFunc & UissdControlChanFunc by
204 * code that processes the ControlVm channel messages.
211 IOPART_DEL_ALL_VNICS,
216 IOPART_DEL_ALL_VDISKS_FOR_VHBA,
217 IOPART_DEL_ALL_VHBAS,
219 IOPART_DETACH_PHBA, /* 10 */
226 IOPART_ADD_DEVICE, /* add generic device */
227 IOPART_DEL_DEVICE, /* del generic device */
230 struct add_virt_iopart {
231 void *chanptr; /* pointer to data channel */
232 U64 guestHandle; /* used to convert guest physical
233 * address to real physical address
234 * for DMA, for ex. */
235 U64 recvBusInterruptHandle; /* used to register to receive
236 * bus level interrupts. */
237 struct InterruptInfo intr; /* contains recv & send
239 /* recvInterruptHandle is used to register to receive
240 * interrupts on the data channel. Used by GuestLinux/Windows
241 * IO drivers to connect to interrupt. sendInterruptHandle is
242 * used by IOPart drivers as parameter to
243 * Issue_VMCALL_IO_QUEUE_TRANSITION to interrupt thread in
244 * guest linux/windows IO drivers when data channel queue for
245 * vhba/vnic goes from EMPTY to NON-EMPTY. */
246 struct switch_info *swtch; /* pointer to the virtual
247 * switch to which the vnic is
250 U8 useG2GCopy; /* Used to determine if a virtual HBA
251 * needs to use G2G copy. */
261 struct add_vdisk_iopart {
262 void *chanptr; /* pointer to data channel */
264 struct uisscsi_dest vdest; /* scsi bus, target, lun for virt disk */
265 struct uisscsi_dest pdest; /* scsi bus, target, lun for phys disk */
266 U8 sernum[MAX_SERIAL_NUM]; /* serial num of physical disk */
267 U32 serlen; /* length of serial num */
272 struct del_vdisk_iopart {
273 void *chanptr; /* pointer to data channel */
274 struct uisscsi_dest vdest; /* scsi bus, target, lun for virt disk */
279 struct del_virt_iopart {
280 void *chanptr; /* pointer to data channel */
285 struct det_virt_iopart { /* detach internal port */
286 void *chanptr; /* pointer to data channel */
287 struct switch_info *swtch;
290 struct paures_vdisk_iopart {
291 void *chanptr; /* pointer to data channel */
292 struct uisscsi_dest vdest; /* scsi bus, target, lun for virt disk */
295 struct add_switch_iopart { /* add switch */
296 struct switch_info *swtch;
301 struct del_switch_iopart { /* destroy switch */
302 struct switch_info *swtch;
307 IOPART_MSG_TYPE msgtype;
309 /* additional params needed by some messages */
311 struct add_virt_iopart add_vhba;
312 struct add_virt_iopart add_vnic;
313 struct add_vdisk_iopart add_vdisk;
314 struct del_virt_iopart del_vhba;
315 struct del_virt_iopart del_vnic;
316 struct det_virt_iopart det_vhba;
317 struct det_virt_iopart det_vnic;
318 struct del_vdisk_iopart del_vdisk;
319 struct del_virt_iopart del_all_vdisks_for_vhba;
320 struct add_virt_iopart add_device;
321 struct del_virt_iopart del_device;
322 struct det_virt_iopart det_intport;
323 struct add_switch_iopart add_switch;
324 struct del_switch_iopart del_switch;
325 struct extport_info *extPort; /* for attach or detach
326 * pnic/generic delete all
327 * vhbas/allvnics need no
329 struct paures_vdisk_iopart paures_vdisk;
334 * Guest messages sent to VirtControlChanFunc by code that processes
335 * the ControlVm channel messages.
347 GUEST_DEL_ALL_VBUSES, /* deletes all vhbas & vnics on all
348 * buses and deletes all buses */
353 } GUESTPART_MSG_TYPE;
355 struct add_vbus_guestpart {
356 void __iomem *chanptr; /* pointer to data channel for bus -
358 U32 busNo; /* bus number to be created/deleted */
359 U32 deviceCount; /* max num of devices on bus */
360 uuid_le busTypeGuid; /* indicates type of bus */
361 uuid_le busInstGuid; /* instance guid for device */
364 struct del_vbus_guestpart {
365 U32 busNo; /* bus number to be deleted */
366 /* once we start using the bus's channel, add can dump busNo
367 * into the channel header and then delete will need only one
368 * parameter, chanptr. */
371 struct add_virt_guestpart {
372 void __iomem *chanptr; /* pointer to data channel */
373 U32 busNo; /* bus number for the operation */
374 U32 deviceNo; /* number of device on the bus */
375 uuid_le devInstGuid; /* instance guid for device */
376 struct InterruptInfo intr; /* recv/send interrupt info */
377 /* recvInterruptHandle contains info needed in order to
378 * register to receive interrupts on the data channel.
379 * sendInterruptHandle contains handle which is provided to
380 * monitor VMCALL that will cause an interrupt to be generated
385 struct pause_virt_guestpart {
386 void __iomem *chanptr; /* pointer to data channel */
389 struct resume_virt_guestpart {
390 void __iomem *chanptr; /* pointer to data channel */
393 struct del_virt_guestpart {
394 void __iomem *chanptr; /* pointer to data channel */
397 struct init_chipset_guestpart {
398 U32 busCount; /* indicates the max number of busses */
399 U32 switchCount; /* indicates the max number of switches */
404 GUESTPART_MSG_TYPE msgtype;
406 /* additional params needed by messages */
408 struct add_vbus_guestpart add_vbus;
409 struct add_virt_guestpart add_vhba;
410 struct add_virt_guestpart add_vnic;
411 struct pause_virt_guestpart pause_vhba;
412 struct pause_virt_guestpart pause_vnic;
413 struct resume_virt_guestpart resume_vhba;
414 struct resume_virt_guestpart resume_vnic;
415 struct del_vbus_guestpart del_vbus;
416 struct del_virt_guestpart del_vhba;
417 struct del_virt_guestpart del_vnic;
418 struct del_vbus_guestpart del_all_vhbas;
419 struct del_vbus_guestpart del_all_vnics;
420 /* del_all_vbuses needs no parameters */
422 struct init_chipset_guestpart init_chipset;
427 #define __xg(x) ((volatile long *)(x))
431 * Below code is a copy of Linux kernel's cmpxchg function located at
433 * http://tcsxeon:8080/source/xref/00trunk-AppOS-linux/include/asm-x86/cmpxchg_64.h#84
434 * Reason for creating our own version of cmpxchg along with
435 * UISLIB_LOCK_PREFIX is to make the operation atomic even for non SMP
439 #define uislibcmpxchg64(p, o, n, s) cmpxchg(p, o, n)
441 #endif /* __UISQUEUE_H__ */