blob: 0d3c153d1d0beaccdb7c8e54167b4e255b5387d1 [file] [log] [blame]
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Dean Nelson45d9ca42008-04-22 14:46:56 -05006 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07007 */
8
Dean Nelson89eb8eb2005-03-23 19:50:00 -07009/*
10 * Cross Partition Communication (XPC) channel support.
11 *
12 * This is the part of XPC that manages the channels and
13 * sends/receives messages across them to/from other partitions.
14 *
15 */
16
Dean Nelson89eb8eb2005-03-23 19:50:00 -070017#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/sched.h>
20#include <linux/cache.h>
21#include <linux/interrupt.h>
Jes Sorensenf9e505a2006-01-17 12:52:21 -050022#include <linux/mutex.h>
23#include <linux/completion.h>
Dean Nelson89eb8eb2005-03-23 19:50:00 -070024#include <asm/sn/sn_sal.h>
Dean Nelson45d9ca42008-04-22 14:46:56 -050025#include "xpc.h"
Dean Nelson89eb8eb2005-03-23 19:50:00 -070026
Dean Nelson89eb8eb2005-03-23 19:50:00 -070027/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050028 * Guarantee that the kzalloc'd memory is cacheline aligned.
29 */
Dean Nelsone17d4162008-07-29 22:34:06 -070030void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050031xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
32{
33 /* see if kzalloc will give us cachline aligned memory by default */
34 *base = kzalloc(size, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050035 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050036 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050037
38 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050039 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050040
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050041 kfree(*base);
42
43 /* nope, we'll have to do it ourselves */
44 *base = kzalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050045 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050046 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050047
Dean Nelson35190502008-04-22 14:48:55 -050048 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050049}
50
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050051/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070052 * Allocate the local message queue and the notify queue.
53 */
Dean Nelson65c17b82008-05-12 14:02:02 -070054static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -070055xpc_allocate_local_msgqueue(struct xpc_channel *ch)
56{
57 unsigned long irq_flags;
58 int nentries;
59 size_t nbytes;
60
Dean Nelson89eb8eb2005-03-23 19:50:00 -070061 for (nentries = ch->local_nentries; nentries > 0; nentries--) {
62
63 nbytes = nentries * ch->msg_size;
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050064 ch->local_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
Dean Nelson35190502008-04-22 14:48:55 -050065 GFP_KERNEL,
Dean Nelson2c2b94f2008-04-22 14:50:17 -050066 &ch->local_msgqueue_base);
67 if (ch->local_msgqueue == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070068 continue;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070069
70 nbytes = nentries * sizeof(struct xpc_notify);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050071 ch->notify_queue = kzalloc(nbytes, GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -070072 if (ch->notify_queue == NULL) {
73 kfree(ch->local_msgqueue_base);
74 ch->local_msgqueue = NULL;
75 continue;
76 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -070077
78 spin_lock_irqsave(&ch->lock, irq_flags);
79 if (nentries < ch->local_nentries) {
80 dev_dbg(xpc_chan, "nentries=%d local_nentries=%d, "
81 "partid=%d, channel=%d\n", nentries,
82 ch->local_nentries, ch->partid, ch->number);
83
84 ch->local_nentries = nentries;
85 }
86 spin_unlock_irqrestore(&ch->lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -070087 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070088 }
89
90 dev_dbg(xpc_chan, "can't get memory for local message queue and notify "
91 "queue, partid=%d, channel=%d\n", ch->partid, ch->number);
Dean Nelson65c17b82008-05-12 14:02:02 -070092 return xpNoMemory;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070093}
94
Dean Nelson89eb8eb2005-03-23 19:50:00 -070095/*
96 * Allocate the cached remote message queue.
97 */
Dean Nelson65c17b82008-05-12 14:02:02 -070098static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -070099xpc_allocate_remote_msgqueue(struct xpc_channel *ch)
100{
101 unsigned long irq_flags;
102 int nentries;
103 size_t nbytes;
104
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700105 DBUG_ON(ch->remote_nentries <= 0);
106
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700107 for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
108
109 nbytes = nentries * ch->msg_size;
Jes Sorensen7aa6ba42006-02-17 05:18:43 -0500110 ch->remote_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
Dean Nelson35190502008-04-22 14:48:55 -0500111 GFP_KERNEL,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500112 &ch->remote_msgqueue_base);
113 if (ch->remote_msgqueue == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700114 continue;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700115
116 spin_lock_irqsave(&ch->lock, irq_flags);
117 if (nentries < ch->remote_nentries) {
118 dev_dbg(xpc_chan, "nentries=%d remote_nentries=%d, "
119 "partid=%d, channel=%d\n", nentries,
120 ch->remote_nentries, ch->partid, ch->number);
121
122 ch->remote_nentries = nentries;
123 }
124 spin_unlock_irqrestore(&ch->lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700125 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700126 }
127
128 dev_dbg(xpc_chan, "can't get memory for cached remote message queue, "
129 "partid=%d, channel=%d\n", ch->partid, ch->number);
Dean Nelson65c17b82008-05-12 14:02:02 -0700130 return xpNoMemory;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700131}
132
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700133/*
134 * Allocate message queues and other stuff associated with a channel.
135 *
136 * Note: Assumes all of the channel sizes are filled in.
137 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700138static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700139xpc_allocate_msgqueues(struct xpc_channel *ch)
140{
141 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700142 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700143
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700144 DBUG_ON(ch->flags & XPC_C_SETUP);
145
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500146 ret = xpc_allocate_local_msgqueue(ch);
Dean Nelson65c17b82008-05-12 14:02:02 -0700147 if (ret != xpSuccess)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700148 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700149
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500150 ret = xpc_allocate_remote_msgqueue(ch);
Dean Nelson65c17b82008-05-12 14:02:02 -0700151 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700152 kfree(ch->local_msgqueue_base);
153 ch->local_msgqueue = NULL;
154 kfree(ch->notify_queue);
155 ch->notify_queue = NULL;
156 return ret;
157 }
158
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700159 spin_lock_irqsave(&ch->lock, irq_flags);
160 ch->flags |= XPC_C_SETUP;
161 spin_unlock_irqrestore(&ch->lock, irq_flags);
162
Dean Nelson65c17b82008-05-12 14:02:02 -0700163 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700164}
165
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700166/*
167 * Process a connect message from a remote partition.
168 *
169 * Note: xpc_process_connect() is expecting to be called with the
170 * spin_lock_irqsave held and will leave it locked upon return.
171 */
172static void
173xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
174{
Dean Nelson65c17b82008-05-12 14:02:02 -0700175 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700176
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700177 DBUG_ON(!spin_is_locked(&ch->lock));
178
179 if (!(ch->flags & XPC_C_OPENREQUEST) ||
Dean Nelson35190502008-04-22 14:48:55 -0500180 !(ch->flags & XPC_C_ROPENREQUEST)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700181 /* nothing more to do for now */
182 return;
183 }
184 DBUG_ON(!(ch->flags & XPC_C_CONNECTING));
185
186 if (!(ch->flags & XPC_C_SETUP)) {
187 spin_unlock_irqrestore(&ch->lock, *irq_flags);
188 ret = xpc_allocate_msgqueues(ch);
189 spin_lock_irqsave(&ch->lock, *irq_flags);
190
Dean Nelson65c17b82008-05-12 14:02:02 -0700191 if (ret != xpSuccess)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700192 XPC_DISCONNECT_CHANNEL(ch, ret, irq_flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500193
194 if (ch->flags & (XPC_C_CONNECTED | XPC_C_DISCONNECTING))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700195 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700196
197 DBUG_ON(!(ch->flags & XPC_C_SETUP));
198 DBUG_ON(ch->local_msgqueue == NULL);
199 DBUG_ON(ch->remote_msgqueue == NULL);
200 }
201
202 if (!(ch->flags & XPC_C_OPENREPLY)) {
203 ch->flags |= XPC_C_OPENREPLY;
Dean Nelson7fb5e592008-07-29 22:34:10 -0700204 xpc_send_chctl_openreply(ch, irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700205 }
206
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500207 if (!(ch->flags & XPC_C_ROPENREPLY))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700208 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700209
210 DBUG_ON(ch->remote_msgqueue_pa == 0);
211
212 ch->flags = (XPC_C_CONNECTED | XPC_C_SETUP); /* clear all else */
213
214 dev_info(xpc_chan, "channel %d to partition %d connected\n",
Dean Nelson35190502008-04-22 14:48:55 -0500215 ch->number, ch->partid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700216
217 spin_unlock_irqrestore(&ch->lock, *irq_flags);
Dean Nelsona460ef82006-11-22 08:25:00 -0600218 xpc_create_kthreads(ch, 1, 0);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700219 spin_lock_irqsave(&ch->lock, *irq_flags);
220}
221
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700222/*
223 * Free up message queues and other stuff that were allocated for the specified
224 * channel.
225 *
226 * Note: ch->reason and ch->reason_line are left set for debugging purposes,
227 * they're cleared when XPC_C_DISCONNECTED is cleared.
228 */
229static void
230xpc_free_msgqueues(struct xpc_channel *ch)
231{
Dean Nelsona47d5da2008-07-29 22:34:09 -0700232 struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
233
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700234 DBUG_ON(!spin_is_locked(&ch->lock));
235 DBUG_ON(atomic_read(&ch->n_to_notify) != 0);
236
237 ch->remote_msgqueue_pa = 0;
238 ch->func = NULL;
239 ch->key = NULL;
240 ch->msg_size = 0;
241 ch->local_nentries = 0;
242 ch->remote_nentries = 0;
243 ch->kthreads_assigned_limit = 0;
244 ch->kthreads_idle_limit = 0;
245
Dean Nelsona47d5da2008-07-29 22:34:09 -0700246 ch_sn2->local_GP->get = 0;
247 ch_sn2->local_GP->put = 0;
248 ch_sn2->remote_GP.get = 0;
249 ch_sn2->remote_GP.put = 0;
250 ch_sn2->w_local_GP.get = 0;
251 ch_sn2->w_local_GP.put = 0;
252 ch_sn2->w_remote_GP.get = 0;
253 ch_sn2->w_remote_GP.put = 0;
254 ch_sn2->next_msg_to_pull = 0;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700255
256 if (ch->flags & XPC_C_SETUP) {
257 ch->flags &= ~XPC_C_SETUP;
258
259 dev_dbg(xpc_chan, "ch->flags=0x%x, partid=%d, channel=%d\n",
260 ch->flags, ch->partid, ch->number);
261
262 kfree(ch->local_msgqueue_base);
263 ch->local_msgqueue = NULL;
264 kfree(ch->remote_msgqueue_base);
265 ch->remote_msgqueue = NULL;
266 kfree(ch->notify_queue);
267 ch->notify_queue = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700268 }
269}
270
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700271/*
272 * spin_lock_irqsave() is expected to be held on entry.
273 */
274static void
275xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
276{
277 struct xpc_partition *part = &xpc_partitions[ch->partid];
Dean Nelsona607c382005-09-01 14:01:37 -0500278 u32 channel_was_connected = (ch->flags & XPC_C_WASCONNECTED);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700279
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700280 DBUG_ON(!spin_is_locked(&ch->lock));
281
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500282 if (!(ch->flags & XPC_C_DISCONNECTING))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700283 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700284
285 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST));
286
287 /* make sure all activity has settled down first */
288
Dean Nelsona460ef82006-11-22 08:25:00 -0600289 if (atomic_read(&ch->kthreads_assigned) > 0 ||
Dean Nelson35190502008-04-22 14:48:55 -0500290 atomic_read(&ch->references) > 0) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700291 return;
292 }
Dean Nelsona460ef82006-11-22 08:25:00 -0600293 DBUG_ON((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
Dean Nelson35190502008-04-22 14:48:55 -0500294 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700295
Dean Nelsona607c382005-09-01 14:01:37 -0500296 if (part->act_state == XPC_P_DEACTIVATING) {
297 /* can't proceed until the other side disengages from us */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700298 if (xpc_partition_engaged(ch->partid))
Dean Nelsona607c382005-09-01 14:01:37 -0500299 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700300
Dean Nelsona607c382005-09-01 14:01:37 -0500301 } else {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700302
303 /* as long as the other side is up do the full protocol */
304
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500305 if (!(ch->flags & XPC_C_RCLOSEREQUEST))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700306 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700307
308 if (!(ch->flags & XPC_C_CLOSEREPLY)) {
309 ch->flags |= XPC_C_CLOSEREPLY;
Dean Nelson7fb5e592008-07-29 22:34:10 -0700310 xpc_send_chctl_closereply(ch, irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700311 }
312
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500313 if (!(ch->flags & XPC_C_RCLOSEREPLY))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700314 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700315 }
316
Dean Nelsona607c382005-09-01 14:01:37 -0500317 /* wake those waiting for notify completion */
318 if (atomic_read(&ch->n_to_notify) > 0) {
319 /* >>> we do callout while holding ch->lock */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700320 xpc_notify_senders_of_disconnect(ch);
Dean Nelsona607c382005-09-01 14:01:37 -0500321 }
322
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700323 /* both sides are disconnected now */
324
Dean Nelson4c2cd962006-02-15 08:02:21 -0600325 if (ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE) {
Dean Nelson246c7e32005-12-22 14:32:56 -0600326 spin_unlock_irqrestore(&ch->lock, *irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700327 xpc_disconnect_callout(ch, xpDisconnected);
Dean Nelson246c7e32005-12-22 14:32:56 -0600328 spin_lock_irqsave(&ch->lock, *irq_flags);
329 }
330
Dean Nelsona607c382005-09-01 14:01:37 -0500331 /* it's now safe to free the channel's message queues */
332 xpc_free_msgqueues(ch);
333
334 /* mark disconnected, clear all other flags except XPC_C_WDISCONNECT */
335 ch->flags = (XPC_C_DISCONNECTED | (ch->flags & XPC_C_WDISCONNECT));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700336
337 atomic_dec(&part->nchannels_active);
338
Dean Nelsona607c382005-09-01 14:01:37 -0500339 if (channel_was_connected) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700340 dev_info(xpc_chan, "channel %d to partition %d disconnected, "
Dean Nelson35190502008-04-22 14:48:55 -0500341 "reason=%d\n", ch->number, ch->partid, ch->reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700342 }
Dean Nelsona607c382005-09-01 14:01:37 -0500343
Dean Nelsona607c382005-09-01 14:01:37 -0500344 if (ch->flags & XPC_C_WDISCONNECT) {
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500345 /* we won't lose the CPU since we're holding ch->lock */
346 complete(&ch->wdisconnect_wait);
Dean Nelson7fb5e592008-07-29 22:34:10 -0700347 } else if (ch->delayed_chctl_flags) {
Dean Nelsone54af722005-10-25 14:07:43 -0500348 if (part->act_state != XPC_P_DEACTIVATING) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700349 /* time to take action on any delayed chctl flags */
350 spin_lock(&part->chctl_lock);
351 part->chctl.flags[ch->number] |=
352 ch->delayed_chctl_flags;
353 spin_unlock(&part->chctl_lock);
Dean Nelsone54af722005-10-25 14:07:43 -0500354 }
Dean Nelson7fb5e592008-07-29 22:34:10 -0700355 ch->delayed_chctl_flags = 0;
Dean Nelsona607c382005-09-01 14:01:37 -0500356 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700357}
358
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700359/*
360 * Process a change in the channel's remote connection state.
361 */
362static void
Dean Nelson7fb5e592008-07-29 22:34:10 -0700363xpc_process_openclose_chctl_flags(struct xpc_partition *part, int ch_number,
364 u8 chctl_flags)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700365{
366 unsigned long irq_flags;
367 struct xpc_openclose_args *args =
Dean Nelson35190502008-04-22 14:48:55 -0500368 &part->remote_openclose_args[ch_number];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700369 struct xpc_channel *ch = &part->channels[ch_number];
Dean Nelson65c17b82008-05-12 14:02:02 -0700370 enum xp_retval reason;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700371
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700372 spin_lock_irqsave(&ch->lock, irq_flags);
373
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500374again:
Dean Nelsone54af722005-10-25 14:07:43 -0500375
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500376 if ((ch->flags & XPC_C_DISCONNECTED) &&
377 (ch->flags & XPC_C_WDISCONNECT)) {
Dean Nelsone54af722005-10-25 14:07:43 -0500378 /*
Dean Nelson7fb5e592008-07-29 22:34:10 -0700379 * Delay processing chctl flags until thread waiting disconnect
Dean Nelsone54af722005-10-25 14:07:43 -0500380 * has had a chance to see that the channel is disconnected.
381 */
Dean Nelson7fb5e592008-07-29 22:34:10 -0700382 ch->delayed_chctl_flags |= chctl_flags;
Dean Nelsone54af722005-10-25 14:07:43 -0500383 spin_unlock_irqrestore(&ch->lock, irq_flags);
384 return;
385 }
386
Dean Nelson7fb5e592008-07-29 22:34:10 -0700387 if (chctl_flags & XPC_CHCTL_CLOSEREQUEST) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700388
Dean Nelson7fb5e592008-07-29 22:34:10 -0700389 dev_dbg(xpc_chan, "XPC_CHCTL_CLOSEREQUEST (reason=%d) received "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700390 "from partid=%d, channel=%d\n", args->reason,
391 ch->partid, ch->number);
392
393 /*
394 * If RCLOSEREQUEST is set, we're probably waiting for
395 * RCLOSEREPLY. We should find it and a ROPENREQUEST packed
Dean Nelson7fb5e592008-07-29 22:34:10 -0700396 * with this RCLOSEREQUEST in the chctl_flags.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700397 */
398
399 if (ch->flags & XPC_C_RCLOSEREQUEST) {
400 DBUG_ON(!(ch->flags & XPC_C_DISCONNECTING));
401 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST));
402 DBUG_ON(!(ch->flags & XPC_C_CLOSEREPLY));
403 DBUG_ON(ch->flags & XPC_C_RCLOSEREPLY);
404
Dean Nelson7fb5e592008-07-29 22:34:10 -0700405 DBUG_ON(!(chctl_flags & XPC_CHCTL_CLOSEREPLY));
406 chctl_flags &= ~XPC_CHCTL_CLOSEREPLY;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700407 ch->flags |= XPC_C_RCLOSEREPLY;
408
409 /* both sides have finished disconnecting */
410 xpc_process_disconnect(ch, &irq_flags);
Dean Nelsone54af722005-10-25 14:07:43 -0500411 DBUG_ON(!(ch->flags & XPC_C_DISCONNECTED));
412 goto again;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700413 }
414
415 if (ch->flags & XPC_C_DISCONNECTED) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700416 if (!(chctl_flags & XPC_CHCTL_OPENREQUEST)) {
417 if (part->chctl.flags[ch_number] &
418 XPC_CHCTL_OPENREQUEST) {
Dean Nelsone54af722005-10-25 14:07:43 -0500419
Dean Nelson7fb5e592008-07-29 22:34:10 -0700420 DBUG_ON(ch->delayed_chctl_flags != 0);
421 spin_lock(&part->chctl_lock);
422 part->chctl.flags[ch_number] |=
423 XPC_CHCTL_CLOSEREQUEST;
424 spin_unlock(&part->chctl_lock);
Dean Nelsone54af722005-10-25 14:07:43 -0500425 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700426 spin_unlock_irqrestore(&ch->lock, irq_flags);
427 return;
428 }
429
430 XPC_SET_REASON(ch, 0, 0);
431 ch->flags &= ~XPC_C_DISCONNECTED;
432
433 atomic_inc(&part->nchannels_active);
434 ch->flags |= (XPC_C_CONNECTING | XPC_C_ROPENREQUEST);
435 }
436
Dean Nelson7fb5e592008-07-29 22:34:10 -0700437 chctl_flags &= ~(XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700438
439 /*
440 * The meaningful CLOSEREQUEST connection state fields are:
441 * reason = reason connection is to be closed
442 */
443
444 ch->flags |= XPC_C_RCLOSEREQUEST;
445
446 if (!(ch->flags & XPC_C_DISCONNECTING)) {
447 reason = args->reason;
Dean Nelson65c17b82008-05-12 14:02:02 -0700448 if (reason <= xpSuccess || reason > xpUnknownReason)
449 reason = xpUnknownReason;
450 else if (reason == xpUnregistering)
451 reason = xpOtherUnregistering;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700452
453 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags);
Dean Nelsone54af722005-10-25 14:07:43 -0500454
Dean Nelson7fb5e592008-07-29 22:34:10 -0700455 DBUG_ON(chctl_flags & XPC_CHCTL_CLOSEREPLY);
Dean Nelsone54af722005-10-25 14:07:43 -0500456 spin_unlock_irqrestore(&ch->lock, irq_flags);
457 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700458 }
Dean Nelsone54af722005-10-25 14:07:43 -0500459
460 xpc_process_disconnect(ch, &irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700461 }
462
Dean Nelson7fb5e592008-07-29 22:34:10 -0700463 if (chctl_flags & XPC_CHCTL_CLOSEREPLY) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700464
Dean Nelson7fb5e592008-07-29 22:34:10 -0700465 dev_dbg(xpc_chan, "XPC_CHCTL_CLOSEREPLY received from partid="
466 "%d, channel=%d\n", ch->partid, ch->number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700467
468 if (ch->flags & XPC_C_DISCONNECTED) {
469 DBUG_ON(part->act_state != XPC_P_DEACTIVATING);
470 spin_unlock_irqrestore(&ch->lock, irq_flags);
471 return;
472 }
473
474 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST));
Dean Nelsone54af722005-10-25 14:07:43 -0500475
476 if (!(ch->flags & XPC_C_RCLOSEREQUEST)) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700477 if (part->chctl.flags[ch_number] &
478 XPC_CHCTL_CLOSEREQUEST) {
Dean Nelsone54af722005-10-25 14:07:43 -0500479
Dean Nelson7fb5e592008-07-29 22:34:10 -0700480 DBUG_ON(ch->delayed_chctl_flags != 0);
481 spin_lock(&part->chctl_lock);
482 part->chctl.flags[ch_number] |=
483 XPC_CHCTL_CLOSEREPLY;
484 spin_unlock(&part->chctl_lock);
Dean Nelsone54af722005-10-25 14:07:43 -0500485 }
486 spin_unlock_irqrestore(&ch->lock, irq_flags);
487 return;
488 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700489
490 ch->flags |= XPC_C_RCLOSEREPLY;
491
492 if (ch->flags & XPC_C_CLOSEREPLY) {
493 /* both sides have finished disconnecting */
494 xpc_process_disconnect(ch, &irq_flags);
495 }
496 }
497
Dean Nelson7fb5e592008-07-29 22:34:10 -0700498 if (chctl_flags & XPC_CHCTL_OPENREQUEST) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700499
Dean Nelson7fb5e592008-07-29 22:34:10 -0700500 dev_dbg(xpc_chan, "XPC_CHCTL_OPENREQUEST (msg_size=%d, "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700501 "local_nentries=%d) received from partid=%d, "
502 "channel=%d\n", args->msg_size, args->local_nentries,
503 ch->partid, ch->number);
504
Dean Nelsone54af722005-10-25 14:07:43 -0500505 if (part->act_state == XPC_P_DEACTIVATING ||
Dean Nelson35190502008-04-22 14:48:55 -0500506 (ch->flags & XPC_C_ROPENREQUEST)) {
Dean Nelsone54af722005-10-25 14:07:43 -0500507 spin_unlock_irqrestore(&ch->lock, irq_flags);
508 return;
509 }
510
511 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_WDISCONNECT)) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700512 ch->delayed_chctl_flags |= XPC_CHCTL_OPENREQUEST;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700513 spin_unlock_irqrestore(&ch->lock, irq_flags);
514 return;
515 }
516 DBUG_ON(!(ch->flags & (XPC_C_DISCONNECTED |
Dean Nelson35190502008-04-22 14:48:55 -0500517 XPC_C_OPENREQUEST)));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700518 DBUG_ON(ch->flags & (XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY |
Dean Nelson35190502008-04-22 14:48:55 -0500519 XPC_C_OPENREPLY | XPC_C_CONNECTED));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700520
521 /*
522 * The meaningful OPENREQUEST connection state fields are:
523 * msg_size = size of channel's messages in bytes
524 * local_nentries = remote partition's local_nentries
525 */
Dean Nelsone54af722005-10-25 14:07:43 -0500526 if (args->msg_size == 0 || args->local_nentries == 0) {
527 /* assume OPENREQUEST was delayed by mistake */
528 spin_unlock_irqrestore(&ch->lock, irq_flags);
529 return;
530 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700531
532 ch->flags |= (XPC_C_ROPENREQUEST | XPC_C_CONNECTING);
533 ch->remote_nentries = args->local_nentries;
534
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700535 if (ch->flags & XPC_C_OPENREQUEST) {
536 if (args->msg_size != ch->msg_size) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700537 XPC_DISCONNECT_CHANNEL(ch, xpUnequalMsgSizes,
Dean Nelson35190502008-04-22 14:48:55 -0500538 &irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700539 spin_unlock_irqrestore(&ch->lock, irq_flags);
540 return;
541 }
542 } else {
543 ch->msg_size = args->msg_size;
544
545 XPC_SET_REASON(ch, 0, 0);
546 ch->flags &= ~XPC_C_DISCONNECTED;
547
548 atomic_inc(&part->nchannels_active);
549 }
550
551 xpc_process_connect(ch, &irq_flags);
552 }
553
Dean Nelson7fb5e592008-07-29 22:34:10 -0700554 if (chctl_flags & XPC_CHCTL_OPENREPLY) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700555
Dean Nelson7fb5e592008-07-29 22:34:10 -0700556 dev_dbg(xpc_chan, "XPC_CHCTL_OPENREPLY (local_msgqueue_pa="
557 "0x%lx, local_nentries=%d, remote_nentries=%d) "
558 "received from partid=%d, channel=%d\n",
559 args->local_msgqueue_pa, args->local_nentries,
560 args->remote_nentries, ch->partid, ch->number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700561
562 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED)) {
563 spin_unlock_irqrestore(&ch->lock, irq_flags);
564 return;
565 }
Dean Nelsone54af722005-10-25 14:07:43 -0500566 if (!(ch->flags & XPC_C_OPENREQUEST)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700567 XPC_DISCONNECT_CHANNEL(ch, xpOpenCloseError,
Dean Nelson35190502008-04-22 14:48:55 -0500568 &irq_flags);
Dean Nelsone54af722005-10-25 14:07:43 -0500569 spin_unlock_irqrestore(&ch->lock, irq_flags);
570 return;
571 }
572
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700573 DBUG_ON(!(ch->flags & XPC_C_ROPENREQUEST));
574 DBUG_ON(ch->flags & XPC_C_CONNECTED);
575
576 /*
577 * The meaningful OPENREPLY connection state fields are:
578 * local_msgqueue_pa = physical address of remote
Dean Nelson35190502008-04-22 14:48:55 -0500579 * partition's local_msgqueue
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700580 * local_nentries = remote partition's local_nentries
581 * remote_nentries = remote partition's remote_nentries
582 */
583 DBUG_ON(args->local_msgqueue_pa == 0);
584 DBUG_ON(args->local_nentries == 0);
585 DBUG_ON(args->remote_nentries == 0);
586
587 ch->flags |= XPC_C_ROPENREPLY;
588 ch->remote_msgqueue_pa = args->local_msgqueue_pa;
589
590 if (args->local_nentries < ch->remote_nentries) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700591 dev_dbg(xpc_chan, "XPC_CHCTL_OPENREPLY: new "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700592 "remote_nentries=%d, old remote_nentries=%d, "
593 "partid=%d, channel=%d\n",
594 args->local_nentries, ch->remote_nentries,
595 ch->partid, ch->number);
596
597 ch->remote_nentries = args->local_nentries;
598 }
599 if (args->remote_nentries < ch->local_nentries) {
Dean Nelson7fb5e592008-07-29 22:34:10 -0700600 dev_dbg(xpc_chan, "XPC_CHCTL_OPENREPLY: new "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700601 "local_nentries=%d, old local_nentries=%d, "
602 "partid=%d, channel=%d\n",
603 args->remote_nentries, ch->local_nentries,
604 ch->partid, ch->number);
605
606 ch->local_nentries = args->remote_nentries;
607 }
608
609 xpc_process_connect(ch, &irq_flags);
610 }
611
612 spin_unlock_irqrestore(&ch->lock, irq_flags);
613}
614
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700615/*
616 * Attempt to establish a channel connection to a remote partition.
617 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700618static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700619xpc_connect_channel(struct xpc_channel *ch)
620{
621 unsigned long irq_flags;
622 struct xpc_registration *registration = &xpc_registrations[ch->number];
623
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500624 if (mutex_trylock(&registration->mutex) == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700625 return xpRetry;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700626
627 if (!XPC_CHANNEL_REGISTERED(ch->number)) {
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500628 mutex_unlock(&registration->mutex);
Dean Nelson65c17b82008-05-12 14:02:02 -0700629 return xpUnregistered;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700630 }
631
632 spin_lock_irqsave(&ch->lock, irq_flags);
633
634 DBUG_ON(ch->flags & XPC_C_CONNECTED);
635 DBUG_ON(ch->flags & XPC_C_OPENREQUEST);
636
637 if (ch->flags & XPC_C_DISCONNECTING) {
638 spin_unlock_irqrestore(&ch->lock, irq_flags);
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500639 mutex_unlock(&registration->mutex);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700640 return ch->reason;
641 }
642
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700643 /* add info from the channel connect registration to the channel */
644
645 ch->kthreads_assigned_limit = registration->assigned_limit;
646 ch->kthreads_idle_limit = registration->idle_limit;
647 DBUG_ON(atomic_read(&ch->kthreads_assigned) != 0);
648 DBUG_ON(atomic_read(&ch->kthreads_idle) != 0);
649 DBUG_ON(atomic_read(&ch->kthreads_active) != 0);
650
651 ch->func = registration->func;
652 DBUG_ON(registration->func == NULL);
653 ch->key = registration->key;
654
655 ch->local_nentries = registration->nentries;
656
657 if (ch->flags & XPC_C_ROPENREQUEST) {
658 if (registration->msg_size != ch->msg_size) {
659 /* the local and remote sides aren't the same */
660
661 /*
662 * Because XPC_DISCONNECT_CHANNEL() can block we're
663 * forced to up the registration sema before we unlock
664 * the channel lock. But that's okay here because we're
665 * done with the part that required the registration
666 * sema. XPC_DISCONNECT_CHANNEL() requires that the
667 * channel lock be locked and will unlock and relock
668 * the channel lock as needed.
669 */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500670 mutex_unlock(&registration->mutex);
Dean Nelson65c17b82008-05-12 14:02:02 -0700671 XPC_DISCONNECT_CHANNEL(ch, xpUnequalMsgSizes,
Dean Nelson35190502008-04-22 14:48:55 -0500672 &irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700673 spin_unlock_irqrestore(&ch->lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700674 return xpUnequalMsgSizes;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700675 }
676 } else {
677 ch->msg_size = registration->msg_size;
678
679 XPC_SET_REASON(ch, 0, 0);
680 ch->flags &= ~XPC_C_DISCONNECTED;
681
682 atomic_inc(&xpc_partitions[ch->partid].nchannels_active);
683 }
684
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500685 mutex_unlock(&registration->mutex);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700686
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700687 /* initiate the connection */
688
689 ch->flags |= (XPC_C_OPENREQUEST | XPC_C_CONNECTING);
Dean Nelson7fb5e592008-07-29 22:34:10 -0700690 xpc_send_chctl_openrequest(ch, &irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700691
692 xpc_process_connect(ch, &irq_flags);
693
694 spin_unlock_irqrestore(&ch->lock, irq_flags);
695
Dean Nelson65c17b82008-05-12 14:02:02 -0700696 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700697}
698
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700699void
Dean Nelson7fb5e592008-07-29 22:34:10 -0700700xpc_process_sent_chctl_flags(struct xpc_partition *part)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700701{
702 unsigned long irq_flags;
Dean Nelson7fb5e592008-07-29 22:34:10 -0700703 union xpc_channel_ctl_flags chctl;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700704 struct xpc_channel *ch;
705 int ch_number;
Dean Nelsona607c382005-09-01 14:01:37 -0500706 u32 ch_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700707
Dean Nelson7fb5e592008-07-29 22:34:10 -0700708 chctl.all_flags = xpc_get_chctl_all_flags(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700709
710 /*
711 * Initiate channel connections for registered channels.
712 *
713 * For each connected channel that has pending messages activate idle
714 * kthreads and/or create new kthreads as needed.
715 */
716
717 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
718 ch = &part->channels[ch_number];
719
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700720 /*
Dean Nelson7fb5e592008-07-29 22:34:10 -0700721 * Process any open or close related chctl flags, and then deal
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700722 * with connecting or disconnecting the channel as required.
723 */
724
Dean Nelson7fb5e592008-07-29 22:34:10 -0700725 if (chctl.flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS) {
726 xpc_process_openclose_chctl_flags(part, ch_number,
727 chctl.flags[ch_number]);
728 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700729
Dean Nelsona607c382005-09-01 14:01:37 -0500730 ch_flags = ch->flags; /* need an atomic snapshot of flags */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700731
Dean Nelsona607c382005-09-01 14:01:37 -0500732 if (ch_flags & XPC_C_DISCONNECTING) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700733 spin_lock_irqsave(&ch->lock, irq_flags);
734 xpc_process_disconnect(ch, &irq_flags);
735 spin_unlock_irqrestore(&ch->lock, irq_flags);
736 continue;
737 }
738
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500739 if (part->act_state == XPC_P_DEACTIVATING)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700740 continue;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700741
Dean Nelsona607c382005-09-01 14:01:37 -0500742 if (!(ch_flags & XPC_C_CONNECTED)) {
743 if (!(ch_flags & XPC_C_OPENREQUEST)) {
744 DBUG_ON(ch_flags & XPC_C_SETUP);
Dean Nelson35190502008-04-22 14:48:55 -0500745 (void)xpc_connect_channel(ch);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700746 } else {
747 spin_lock_irqsave(&ch->lock, irq_flags);
748 xpc_process_connect(ch, &irq_flags);
749 spin_unlock_irqrestore(&ch->lock, irq_flags);
750 }
751 continue;
752 }
753
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700754 /*
Dean Nelson7fb5e592008-07-29 22:34:10 -0700755 * Process any message related chctl flags, this may involve
756 * the activation of kthreads to deliver any pending messages
757 * sent from the other partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700758 */
759
Dean Nelson7fb5e592008-07-29 22:34:10 -0700760 if (chctl.flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
761 xpc_process_msg_chctl_flags(part, ch_number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700762 }
763}
764
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700765/*
Dean Nelsona607c382005-09-01 14:01:37 -0500766 * XPC's heartbeat code calls this function to inform XPC that a partition is
767 * going down. XPC responds by tearing down the XPartition Communication
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700768 * infrastructure used for the just downed partition.
769 *
770 * XPC's heartbeat code will never call this function and xpc_partition_up()
771 * at the same time. Nor will it ever make multiple calls to either function
772 * at the same time.
773 */
774void
Dean Nelson65c17b82008-05-12 14:02:02 -0700775xpc_partition_going_down(struct xpc_partition *part, enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700776{
777 unsigned long irq_flags;
778 int ch_number;
779 struct xpc_channel *ch;
780
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700781 dev_dbg(xpc_chan, "deactivating partition %d, reason=%d\n",
782 XPC_PARTID(part), reason);
783
784 if (!xpc_part_ref(part)) {
785 /* infrastructure for this partition isn't currently set up */
786 return;
787 }
788
Dean Nelsona607c382005-09-01 14:01:37 -0500789 /* disconnect channels associated with the partition going down */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700790
791 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
792 ch = &part->channels[ch_number];
793
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700794 xpc_msgqueue_ref(ch);
795 spin_lock_irqsave(&ch->lock, irq_flags);
796
797 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags);
798
799 spin_unlock_irqrestore(&ch->lock, irq_flags);
800 xpc_msgqueue_deref(ch);
801 }
802
803 xpc_wakeup_channel_mgr(part);
804
805 xpc_part_deref(part);
806}
807
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700808/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700809 * Called by XP at the time of channel connection registration to cause
810 * XPC to establish connections to all currently active partitions.
811 */
812void
813xpc_initiate_connect(int ch_number)
814{
Dean Nelson64d032b2008-05-12 14:02:03 -0700815 short partid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700816 struct xpc_partition *part;
817 struct xpc_channel *ch;
818
Dean Nelsonbc63d382008-07-29 22:34:04 -0700819 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700820
Dean Nelsonbc63d382008-07-29 22:34:04 -0700821 for (partid = 0; partid < xp_max_npartitions; partid++) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700822 part = &xpc_partitions[partid];
823
824 if (xpc_part_ref(part)) {
825 ch = &part->channels[ch_number];
826
Dean Nelsone54af722005-10-25 14:07:43 -0500827 /*
828 * Initiate the establishment of a connection on the
829 * newly registered channel to the remote partition.
830 */
831 xpc_wakeup_channel_mgr(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700832 xpc_part_deref(part);
833 }
834 }
835}
836
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700837void
838xpc_connected_callout(struct xpc_channel *ch)
839{
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700840 /* let the registerer know that a connection has been established */
841
842 if (ch->func != NULL) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700843 dev_dbg(xpc_chan, "ch->func() called, reason=xpConnected, "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700844 "partid=%d, channel=%d\n", ch->partid, ch->number);
845
Dean Nelson65c17b82008-05-12 14:02:02 -0700846 ch->func(xpConnected, ch->partid, ch->number,
Dean Nelson35190502008-04-22 14:48:55 -0500847 (void *)(u64)ch->local_nentries, ch->key);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700848
Dean Nelson65c17b82008-05-12 14:02:02 -0700849 dev_dbg(xpc_chan, "ch->func() returned, reason=xpConnected, "
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700850 "partid=%d, channel=%d\n", ch->partid, ch->number);
851 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700852}
853
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700854/*
855 * Called by XP at the time of channel connection unregistration to cause
856 * XPC to teardown all current connections for the specified channel.
857 *
858 * Before returning xpc_initiate_disconnect() will wait until all connections
859 * on the specified channel have been closed/torndown. So the caller can be
860 * assured that they will not be receiving any more callouts from XPC to the
861 * function they registered via xpc_connect().
862 *
863 * Arguments:
864 *
865 * ch_number - channel # to unregister.
866 */
867void
868xpc_initiate_disconnect(int ch_number)
869{
870 unsigned long irq_flags;
Dean Nelson64d032b2008-05-12 14:02:03 -0700871 short partid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700872 struct xpc_partition *part;
873 struct xpc_channel *ch;
874
Dean Nelsonbc63d382008-07-29 22:34:04 -0700875 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700876
877 /* initiate the channel disconnect for every active partition */
Dean Nelsonbc63d382008-07-29 22:34:04 -0700878 for (partid = 0; partid < xp_max_npartitions; partid++) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700879 part = &xpc_partitions[partid];
880
881 if (xpc_part_ref(part)) {
882 ch = &part->channels[ch_number];
883 xpc_msgqueue_ref(ch);
884
885 spin_lock_irqsave(&ch->lock, irq_flags);
886
Dean Nelsona607c382005-09-01 14:01:37 -0500887 if (!(ch->flags & XPC_C_DISCONNECTED)) {
888 ch->flags |= XPC_C_WDISCONNECT;
889
Dean Nelson65c17b82008-05-12 14:02:02 -0700890 XPC_DISCONNECT_CHANNEL(ch, xpUnregistering,
Dean Nelson35190502008-04-22 14:48:55 -0500891 &irq_flags);
Dean Nelsona607c382005-09-01 14:01:37 -0500892 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700893
894 spin_unlock_irqrestore(&ch->lock, irq_flags);
895
896 xpc_msgqueue_deref(ch);
897 xpc_part_deref(part);
898 }
899 }
900
901 xpc_disconnect_wait(ch_number);
902}
903
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700904/*
905 * To disconnect a channel, and reflect it back to all who may be waiting.
906 *
Dean Nelsona607c382005-09-01 14:01:37 -0500907 * An OPEN is not allowed until XPC_C_DISCONNECTING is cleared by
908 * xpc_process_disconnect(), and if set, XPC_C_WDISCONNECT is cleared by
909 * xpc_disconnect_wait().
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700910 *
911 * THE CHANNEL IS TO BE LOCKED BY THE CALLER AND WILL REMAIN LOCKED UPON RETURN.
912 */
913void
914xpc_disconnect_channel(const int line, struct xpc_channel *ch,
Dean Nelson65c17b82008-05-12 14:02:02 -0700915 enum xp_retval reason, unsigned long *irq_flags)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700916{
Dean Nelsona607c382005-09-01 14:01:37 -0500917 u32 channel_was_connected = (ch->flags & XPC_C_CONNECTED);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700918
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700919 DBUG_ON(!spin_is_locked(&ch->lock));
920
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500921 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700922 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500923
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700924 DBUG_ON(!(ch->flags & (XPC_C_CONNECTING | XPC_C_CONNECTED)));
925
926 dev_dbg(xpc_chan, "reason=%d, line=%d, partid=%d, channel=%d\n",
927 reason, line, ch->partid, ch->number);
928
929 XPC_SET_REASON(ch, reason, line);
930
Dean Nelsona607c382005-09-01 14:01:37 -0500931 ch->flags |= (XPC_C_CLOSEREQUEST | XPC_C_DISCONNECTING);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700932 /* some of these may not have been set */
933 ch->flags &= ~(XPC_C_OPENREQUEST | XPC_C_OPENREPLY |
Dean Nelson35190502008-04-22 14:48:55 -0500934 XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY |
935 XPC_C_CONNECTING | XPC_C_CONNECTED);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700936
Dean Nelson7fb5e592008-07-29 22:34:10 -0700937 xpc_send_chctl_closerequest(ch, irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700938
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500939 if (channel_was_connected)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700940 ch->flags |= XPC_C_WASCONNECTED;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700941
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700942 spin_unlock_irqrestore(&ch->lock, *irq_flags);
943
Dean Nelsona607c382005-09-01 14:01:37 -0500944 /* wake all idle kthreads so they can exit */
945 if (atomic_read(&ch->kthreads_idle) > 0) {
946 wake_up_all(&ch->idle_wq);
Dean Nelsona460ef82006-11-22 08:25:00 -0600947
948 } else if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
Dean Nelson35190502008-04-22 14:48:55 -0500949 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700950 /* start a kthread that will do the xpDisconnecting callout */
Dean Nelsona460ef82006-11-22 08:25:00 -0600951 xpc_create_kthreads(ch, 1, 1);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700952 }
953
Dean Nelsona607c382005-09-01 14:01:37 -0500954 /* wake those waiting to allocate an entry from the local msg queue */
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500955 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
Dean Nelsona607c382005-09-01 14:01:37 -0500956 wake_up(&ch->msg_allocate_wq);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700957
958 spin_lock_irqsave(&ch->lock, *irq_flags);
959}
960
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700961void
Dean Nelson65c17b82008-05-12 14:02:02 -0700962xpc_disconnect_callout(struct xpc_channel *ch, enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700963{
964 /*
Dean Nelsona607c382005-09-01 14:01:37 -0500965 * Let the channel's registerer know that the channel is being
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700966 * disconnected. We don't want to do this if the registerer was never
Dean Nelsona607c382005-09-01 14:01:37 -0500967 * informed of a connection being made.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700968 */
969
970 if (ch->func != NULL) {
Dean Nelson246c7e32005-12-22 14:32:56 -0600971 dev_dbg(xpc_chan, "ch->func() called, reason=%d, partid=%d, "
972 "channel=%d\n", reason, ch->partid, ch->number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700973
Dean Nelson246c7e32005-12-22 14:32:56 -0600974 ch->func(reason, ch->partid, ch->number, NULL, ch->key);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700975
Dean Nelson246c7e32005-12-22 14:32:56 -0600976 dev_dbg(xpc_chan, "ch->func() returned, reason=%d, partid=%d, "
977 "channel=%d\n", reason, ch->partid, ch->number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700978 }
979}
980
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700981/*
982 * Wait for a message entry to become available for the specified channel,
983 * but don't wait any longer than 1 jiffy.
984 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700985enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700986xpc_allocate_msg_wait(struct xpc_channel *ch)
987{
Dean Nelson65c17b82008-05-12 14:02:02 -0700988 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700989
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700990 if (ch->flags & XPC_C_DISCONNECTING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700991 DBUG_ON(ch->reason == xpInterrupted);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700992 return ch->reason;
993 }
994
995 atomic_inc(&ch->n_on_msg_allocate_wq);
996 ret = interruptible_sleep_on_timeout(&ch->msg_allocate_wq, 1);
997 atomic_dec(&ch->n_on_msg_allocate_wq);
998
999 if (ch->flags & XPC_C_DISCONNECTING) {
1000 ret = ch->reason;
Dean Nelson65c17b82008-05-12 14:02:02 -07001001 DBUG_ON(ch->reason == xpInterrupted);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001002 } else if (ret == 0) {
Dean Nelson65c17b82008-05-12 14:02:02 -07001003 ret = xpTimeout;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001004 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -07001005 ret = xpInterrupted;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001006 }
1007
1008 return ret;
1009}
1010
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001011/*
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001012 * Send a message that contains the user's payload on the specified channel
1013 * connected to the specified partition.
1014 *
1015 * NOTE that this routine can sleep waiting for a message entry to become
1016 * available. To not sleep, pass in the XPC_NOWAIT flag.
1017 *
1018 * Once sent, this routine will not wait for the message to be received, nor
1019 * will notification be given when it does happen.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001020 *
1021 * Arguments:
1022 *
1023 * partid - ID of partition to which the channel is connected.
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001024 * ch_number - channel # to send message on.
1025 * flags - see xp.h for valid flags.
1026 * payload - pointer to the payload which is to be sent.
1027 * payload_size - size of the payload in bytes.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001028 */
Dean Nelson65c17b82008-05-12 14:02:02 -07001029enum xp_retval
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001030xpc_initiate_send(short partid, int ch_number, u32 flags, void *payload,
1031 u16 payload_size)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001032{
1033 struct xpc_partition *part = &xpc_partitions[partid];
Dean Nelson65c17b82008-05-12 14:02:02 -07001034 enum xp_retval ret = xpUnknownReason;
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001035
1036 dev_dbg(xpc_chan, "payload=0x%p, partid=%d, channel=%d\n", payload,
1037 partid, ch_number);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001038
Dean Nelsonbc63d382008-07-29 22:34:04 -07001039 DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001040 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001041 DBUG_ON(payload == NULL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001042
1043 if (xpc_part_ref(part)) {
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001044 ret = xpc_send_msg(&part->channels[ch_number], flags, payload,
1045 payload_size, 0, NULL, NULL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001046 xpc_part_deref(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001047 }
1048
1049 return ret;
1050}
1051
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001052/*
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001053 * Send a message that contains the user's payload on the specified channel
1054 * connected to the specified partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001055 *
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001056 * NOTE that this routine can sleep waiting for a message entry to become
1057 * available. To not sleep, pass in the XPC_NOWAIT flag.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001058 *
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001059 * This routine will not wait for the message to be sent or received.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001060 *
1061 * Once the remote end of the channel has received the message, the function
1062 * passed as an argument to xpc_initiate_send_notify() will be called. This
1063 * allows the sender to free up or re-use any buffers referenced by the
1064 * message, but does NOT mean the message has been processed at the remote
1065 * end by a receiver.
1066 *
1067 * If this routine returns an error, the caller's function will NOT be called.
1068 *
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001069 * Arguments:
1070 *
1071 * partid - ID of partition to which the channel is connected.
1072 * ch_number - channel # to send message on.
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001073 * flags - see xp.h for valid flags.
1074 * payload - pointer to the payload which is to be sent.
1075 * payload_size - size of the payload in bytes.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001076 * func - function to call with asynchronous notification of message
1077 * receipt. THIS FUNCTION MUST BE NON-BLOCKING.
1078 * key - user-defined key to be passed to the function when it's called.
1079 */
Dean Nelson65c17b82008-05-12 14:02:02 -07001080enum xp_retval
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001081xpc_initiate_send_notify(short partid, int ch_number, u32 flags, void *payload,
1082 u16 payload_size, xpc_notify_func func, void *key)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001083{
1084 struct xpc_partition *part = &xpc_partitions[partid];
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001085 enum xp_retval ret = xpUnknownReason;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001086
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001087 dev_dbg(xpc_chan, "payload=0x%p, partid=%d, channel=%d\n", payload,
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001088 partid, ch_number);
1089
Dean Nelsonbc63d382008-07-29 22:34:04 -07001090 DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001091 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001092 DBUG_ON(payload == NULL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001093 DBUG_ON(func == NULL);
1094
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001095 if (xpc_part_ref(part)) {
1096 ret = xpc_send_msg(&part->channels[ch_number], flags, payload,
1097 payload_size, XPC_N_CALL, func, key);
1098 xpc_part_deref(part);
1099 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001100 return ret;
1101}
1102
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001103/*
1104 * Deliver a message to its intended recipient.
1105 */
1106void
1107xpc_deliver_msg(struct xpc_channel *ch)
1108{
1109 struct xpc_msg *msg;
1110
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001111 msg = xpc_get_deliverable_msg(ch);
1112 if (msg != NULL) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001113
1114 /*
1115 * This ref is taken to protect the payload itself from being
1116 * freed before the user is finished with it, which the user
1117 * indicates by calling xpc_initiate_received().
1118 */
1119 xpc_msgqueue_ref(ch);
1120
1121 atomic_inc(&ch->kthreads_active);
1122
1123 if (ch->func != NULL) {
1124 dev_dbg(xpc_chan, "ch->func() called, msg=0x%p, "
1125 "msg_number=%ld, partid=%d, channel=%d\n",
Dean Nelson35190502008-04-22 14:48:55 -05001126 (void *)msg, msg->number, ch->partid,
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001127 ch->number);
1128
1129 /* deliver the message to its intended recipient */
Dean Nelson65c17b82008-05-12 14:02:02 -07001130 ch->func(xpMsgReceived, ch->partid, ch->number,
Dean Nelson35190502008-04-22 14:48:55 -05001131 &msg->payload, ch->key);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001132
1133 dev_dbg(xpc_chan, "ch->func() returned, msg=0x%p, "
1134 "msg_number=%ld, partid=%d, channel=%d\n",
Dean Nelson35190502008-04-22 14:48:55 -05001135 (void *)msg, msg->number, ch->partid,
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001136 ch->number);
1137 }
1138
1139 atomic_dec(&ch->kthreads_active);
1140 }
1141}
1142
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001143/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001144 * Acknowledge receipt of a delivered message.
1145 *
1146 * If a message has XPC_M_INTERRUPT set, send an interrupt to the partition
1147 * that sent the message.
1148 *
1149 * This function, although called by users, does not call xpc_part_ref() to
1150 * ensure that the partition infrastructure is in place. It relies on the
1151 * fact that we called xpc_msgqueue_ref() in xpc_deliver_msg().
1152 *
1153 * Arguments:
1154 *
1155 * partid - ID of partition to which the channel is connected.
1156 * ch_number - channel # message received on.
1157 * payload - pointer to the payload area allocated via
Dean Nelson97bf1aa2008-07-29 22:34:08 -07001158 * xpc_initiate_send() or xpc_initiate_send_notify().
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001159 */
1160void
Dean Nelson64d032b2008-05-12 14:02:03 -07001161xpc_initiate_received(short partid, int ch_number, void *payload)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001162{
1163 struct xpc_partition *part = &xpc_partitions[partid];
1164 struct xpc_channel *ch;
1165 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001166
Dean Nelsonbc63d382008-07-29 22:34:04 -07001167 DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001168 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
1169
1170 ch = &part->channels[ch_number];
Dean Nelson33ba3c72008-07-29 22:34:07 -07001171 xpc_received_msg(ch, msg);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001172
1173 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_msg() */
1174 xpc_msgqueue_deref(ch);
1175}