3 * Copyright © 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 #include <linux/kernel.h>
20 #include <linux/module.h>
26 /* this is shorter than using __FILE__ (full path name) in
27 * debug/info/error messages */
28 #define CURRENT_FILE_PC UISLIB_PC_uisqueue_c
29 #define __MYFILE__ "uisqueue.c"
31 #define RETVOID do { goto Away; } while (0)
32 #define RETINT(x) do { rc = (x); goto Away; } while (0)
33 #define RETPTR(x) do { rc = (x); goto Away; } while (0)
35 #define CHECK_CACHE_ALIGN 0
37 /*****************************************************/
38 /* Exported functions */
39 /*****************************************************/
41 uisqueue_InterlockedOr(unsigned long long __iomem *Target,
42 unsigned long long Set)
50 j = uislibcmpxchg64((__force unsigned long long *)Target,
51 i, i | Set, sizeof(*(Target)));
57 EXPORT_SYMBOL_GPL(uisqueue_InterlockedOr);
60 uisqueue_InterlockedAnd(unsigned long long __iomem *Target,
61 unsigned long long Set)
69 j = uislibcmpxchg64((__force unsigned long long *)Target,
70 i, i & Set, sizeof(*(Target)));
76 EXPORT_SYMBOL_GPL(uisqueue_InterlockedAnd);
79 do_locked_client_insert(struct uisqueue_info *queueinfo,
80 unsigned int whichqueue,
83 unsigned char issueInterruptIfEmpty,
84 U64 interruptHandle, U8 *channelId)
87 unsigned char queueWasEmpty;
88 unsigned int locked = 0;
89 unsigned int acquired = 0;
92 spin_lock_irqsave(lock, flags);
95 if (!ULTRA_CHANNEL_CLIENT_ACQUIRE_OS(queueinfo->chan, channelId, NULL))
100 queueWasEmpty = visor_signalqueue_empty(queueinfo->chan, whichqueue);
101 if (!visor_signal_insert(queueinfo->chan, whichqueue, pSignal))
103 ULTRA_CHANNEL_CLIENT_RELEASE_OS(queueinfo->chan, channelId, NULL);
105 spin_unlock_irqrestore(lock, flags);
108 queueinfo->packets_sent++;
114 ULTRA_CHANNEL_CLIENT_RELEASE_OS(queueinfo->chan, channelId,
119 spin_unlock_irqrestore((spinlock_t *) lock, flags);
127 uisqueue_put_cmdrsp_with_lock_client(struct uisqueue_info *queueinfo,
128 struct uiscmdrsp *cmdrsp,
129 unsigned int whichqueue,
131 unsigned char issueInterruptIfEmpty,
133 char oktowait, U8 *channelId)
135 while (!do_locked_client_insert(queueinfo, whichqueue, cmdrsp,
136 (spinlock_t *) insertlock,
137 issueInterruptIfEmpty,
138 interruptHandle, channelId)) {
139 if (oktowait != OK_TO_WAIT) {
140 LOGERR("****FAILED visor_signal_insert failed; cannot wait; insert aborted\n");
141 return 0; /* failed to queue */
144 LOGERR("****FAILED visor_signal_insert failed; waiting to try again\n");
145 set_current_state(TASK_INTERRUPTIBLE);
146 schedule_timeout(msecs_to_jiffies(10));
150 EXPORT_SYMBOL_GPL(uisqueue_put_cmdrsp_with_lock_client);
152 /* uisqueue_get_cmdrsp gets the cmdrsp entry at the head of the queue
153 * returns NULL if queue is empty */
155 uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo,
156 void *cmdrsp, unsigned int whichqueue)
158 if (!visor_signal_remove(queueinfo->chan, whichqueue, cmdrsp))
161 queueinfo->packets_received++;
163 return 1; /* Success */
165 EXPORT_SYMBOL_GPL(uisqueue_get_cmdrsp);