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 #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 CHECK_CACHE_ALIGN 0
33 /*****************************************************/
34 /* Exported functions */
35 /*****************************************************/
37 uisqueue_interlocked_or(unsigned long long __iomem *tgt,
38 unsigned long long set)
46 j = cmpxchg((__force unsigned long long *)tgt, i, i | set);
52 EXPORT_SYMBOL_GPL(uisqueue_interlocked_or);
55 uisqueue_interlocked_and(unsigned long long __iomem *tgt,
56 unsigned long long set)
64 j = cmpxchg((__force unsigned long long *)tgt, i, i & set);
70 EXPORT_SYMBOL_GPL(uisqueue_interlocked_and);
73 do_locked_client_insert(struct uisqueue_info *queueinfo,
74 unsigned int whichqueue,
77 unsigned char issueInterruptIfEmpty,
78 u64 interruptHandle, u8 *channelId)
83 spin_lock_irqsave(lock, flags);
84 if (!spar_channel_client_acquire_os(queueinfo->chan, channelId))
86 if (spar_signal_insert(queueinfo->chan, whichqueue, pSignal)) {
87 queueinfo->packets_sent++;
90 spar_channel_client_release_os(queueinfo->chan, channelId);
92 spin_unlock_irqrestore((spinlock_t *)lock, flags);
97 uisqueue_put_cmdrsp_with_lock_client(struct uisqueue_info *queueinfo,
98 struct uiscmdrsp *cmdrsp,
99 unsigned int whichqueue,
101 unsigned char issue_irq_if_empty,
103 char oktowait, u8 *channel_id)
105 while (!do_locked_client_insert(queueinfo, whichqueue, cmdrsp,
106 (spinlock_t *) insertlock,
108 irq_handle, channel_id)) {
109 if (oktowait != OK_TO_WAIT) {
110 LOGERR("****FAILED visor_signal_insert failed; cannot wait; insert aborted\n");
111 return 0; /* failed to queue */
114 LOGERR("****FAILED visor_signal_insert failed; waiting to try again\n");
115 set_current_state(TASK_INTERRUPTIBLE);
116 schedule_timeout(msecs_to_jiffies(10));
120 EXPORT_SYMBOL_GPL(uisqueue_put_cmdrsp_with_lock_client);
122 /* uisqueue_get_cmdrsp gets the cmdrsp entry at the head of the queue
123 * returns NULL if queue is empty */
125 uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo,
126 void *cmdrsp, unsigned int whichqueue)
128 if (!spar_signal_remove(queueinfo->chan, whichqueue, cmdrsp))
131 queueinfo->packets_received++;
133 return 1; /* Success */
135 EXPORT_SYMBOL_GPL(uisqueue_get_cmdrsp);