aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/sgi-xp/xpc_channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/sgi-xp/xpc_channel.c')
-rw-r--r--drivers/misc/sgi-xp/xpc_channel.c138
1 files changed, 79 insertions, 59 deletions
diff --git a/drivers/misc/sgi-xp/xpc_channel.c b/drivers/misc/sgi-xp/xpc_channel.c
index 99a2534c38a..652593fc486 100644
--- a/drivers/misc/sgi-xp/xpc_channel.c
+++ b/drivers/misc/sgi-xp/xpc_channel.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9/* 9/*
@@ -39,34 +39,38 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
39 39
40 if (!(ch->flags & XPC_C_SETUP)) { 40 if (!(ch->flags & XPC_C_SETUP)) {
41 spin_unlock_irqrestore(&ch->lock, *irq_flags); 41 spin_unlock_irqrestore(&ch->lock, *irq_flags);
42 ret = xpc_setup_msg_structures(ch); 42 ret = xpc_arch_ops.setup_msg_structures(ch);
43 spin_lock_irqsave(&ch->lock, *irq_flags); 43 spin_lock_irqsave(&ch->lock, *irq_flags);
44 44
45 if (ret != xpSuccess) 45 if (ret != xpSuccess)
46 XPC_DISCONNECT_CHANNEL(ch, ret, irq_flags); 46 XPC_DISCONNECT_CHANNEL(ch, ret, irq_flags);
47 else
48 ch->flags |= XPC_C_SETUP;
47 49
48 ch->flags |= XPC_C_SETUP; 50 if (ch->flags & XPC_C_DISCONNECTING)
49
50 if (ch->flags & (XPC_C_CONNECTED | XPC_C_DISCONNECTING))
51 return; 51 return;
52 } 52 }
53 53
54 if (!(ch->flags & XPC_C_OPENREPLY)) { 54 if (!(ch->flags & XPC_C_OPENREPLY)) {
55 ch->flags |= XPC_C_OPENREPLY; 55 ch->flags |= XPC_C_OPENREPLY;
56 xpc_send_chctl_openreply(ch, irq_flags); 56 xpc_arch_ops.send_chctl_openreply(ch, irq_flags);
57 } 57 }
58 58
59 if (!(ch->flags & XPC_C_ROPENREPLY)) 59 if (!(ch->flags & XPC_C_ROPENREPLY))
60 return; 60 return;
61 61
62 ch->flags = (XPC_C_CONNECTED | XPC_C_SETUP); /* clear all else */ 62 if (!(ch->flags & XPC_C_OPENCOMPLETE)) {
63 ch->flags |= (XPC_C_OPENCOMPLETE | XPC_C_CONNECTED);
64 xpc_arch_ops.send_chctl_opencomplete(ch, irq_flags);
65 }
66
67 if (!(ch->flags & XPC_C_ROPENCOMPLETE))
68 return;
63 69
64 dev_info(xpc_chan, "channel %d to partition %d connected\n", 70 dev_info(xpc_chan, "channel %d to partition %d connected\n",
65 ch->number, ch->partid); 71 ch->number, ch->partid);
66 72
67 spin_unlock_irqrestore(&ch->lock, *irq_flags); 73 ch->flags = (XPC_C_CONNECTED | XPC_C_SETUP); /* clear all else */
68 xpc_create_kthreads(ch, 1, 0);
69 spin_lock_irqsave(&ch->lock, *irq_flags);
70} 74}
71 75
72/* 76/*
@@ -96,7 +100,7 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
96 100
97 if (part->act_state == XPC_P_AS_DEACTIVATING) { 101 if (part->act_state == XPC_P_AS_DEACTIVATING) {
98 /* can't proceed until the other side disengages from us */ 102 /* can't proceed until the other side disengages from us */
99 if (xpc_partition_engaged(ch->partid)) 103 if (xpc_arch_ops.partition_engaged(ch->partid))
100 return; 104 return;
101 105
102 } else { 106 } else {
@@ -108,7 +112,7 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
108 112
109 if (!(ch->flags & XPC_C_CLOSEREPLY)) { 113 if (!(ch->flags & XPC_C_CLOSEREPLY)) {
110 ch->flags |= XPC_C_CLOSEREPLY; 114 ch->flags |= XPC_C_CLOSEREPLY;
111 xpc_send_chctl_closereply(ch, irq_flags); 115 xpc_arch_ops.send_chctl_closereply(ch, irq_flags);
112 } 116 }
113 117
114 if (!(ch->flags & XPC_C_RCLOSEREPLY)) 118 if (!(ch->flags & XPC_C_RCLOSEREPLY))
@@ -118,7 +122,7 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
118 /* wake those waiting for notify completion */ 122 /* wake those waiting for notify completion */
119 if (atomic_read(&ch->n_to_notify) > 0) { 123 if (atomic_read(&ch->n_to_notify) > 0) {
120 /* we do callout while holding ch->lock, callout can't block */ 124 /* we do callout while holding ch->lock, callout can't block */
121 xpc_notify_senders_of_disconnect(ch); 125 xpc_arch_ops.notify_senders_of_disconnect(ch);
122 } 126 }
123 127
124 /* both sides are disconnected now */ 128 /* both sides are disconnected now */
@@ -132,7 +136,7 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
132 DBUG_ON(atomic_read(&ch->n_to_notify) != 0); 136 DBUG_ON(atomic_read(&ch->n_to_notify) != 0);
133 137
134 /* it's now safe to free the channel's message queues */ 138 /* it's now safe to free the channel's message queues */
135 xpc_teardown_msg_structures(ch); 139 xpc_arch_ops.teardown_msg_structures(ch);
136 140
137 ch->func = NULL; 141 ch->func = NULL;
138 ch->key = NULL; 142 ch->key = NULL;
@@ -144,8 +148,9 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
144 148
145 /* 149 /*
146 * Mark the channel disconnected and clear all other flags, including 150 * Mark the channel disconnected and clear all other flags, including
147 * XPC_C_SETUP (because of call to xpc_teardown_msg_structures()) but 151 * XPC_C_SETUP (because of call to
148 * not including XPC_C_WDISCONNECT (if it was set). 152 * xpc_arch_ops.teardown_msg_structures()) but not including
153 * XPC_C_WDISCONNECT (if it was set).
149 */ 154 */
150 ch->flags = (XPC_C_DISCONNECTED | (ch->flags & XPC_C_WDISCONNECT)); 155 ch->flags = (XPC_C_DISCONNECTED | (ch->flags & XPC_C_WDISCONNECT));
151 156
@@ -184,6 +189,7 @@ xpc_process_openclose_chctl_flags(struct xpc_partition *part, int ch_number,
184 struct xpc_channel *ch = &part->channels[ch_number]; 189 struct xpc_channel *ch = &part->channels[ch_number];
185 enum xp_retval reason; 190 enum xp_retval reason;
186 enum xp_retval ret; 191 enum xp_retval ret;
192 int create_kthread = 0;
187 193
188 spin_lock_irqsave(&ch->lock, irq_flags); 194 spin_lock_irqsave(&ch->lock, irq_flags);
189 195
@@ -196,8 +202,7 @@ again:
196 * has had a chance to see that the channel is disconnected. 202 * has had a chance to see that the channel is disconnected.
197 */ 203 */
198 ch->delayed_chctl_flags |= chctl_flags; 204 ch->delayed_chctl_flags |= chctl_flags;
199 spin_unlock_irqrestore(&ch->lock, irq_flags); 205 goto out;
200 return;
201 } 206 }
202 207
203 if (chctl_flags & XPC_CHCTL_CLOSEREQUEST) { 208 if (chctl_flags & XPC_CHCTL_CLOSEREQUEST) {
@@ -239,8 +244,7 @@ again:
239 XPC_CHCTL_CLOSEREQUEST; 244 XPC_CHCTL_CLOSEREQUEST;
240 spin_unlock(&part->chctl_lock); 245 spin_unlock(&part->chctl_lock);
241 } 246 }
242 spin_unlock_irqrestore(&ch->lock, irq_flags); 247 goto out;
243 return;
244 } 248 }
245 249
246 XPC_SET_REASON(ch, 0, 0); 250 XPC_SET_REASON(ch, 0, 0);
@@ -250,7 +254,8 @@ again:
250 ch->flags |= (XPC_C_CONNECTING | XPC_C_ROPENREQUEST); 254 ch->flags |= (XPC_C_CONNECTING | XPC_C_ROPENREQUEST);
251 } 255 }
252 256
253 chctl_flags &= ~(XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY); 257 chctl_flags &= ~(XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY |
258 XPC_CHCTL_OPENCOMPLETE);
254 259
255 /* 260 /*
256 * The meaningful CLOSEREQUEST connection state fields are: 261 * The meaningful CLOSEREQUEST connection state fields are:
@@ -269,8 +274,7 @@ again:
269 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags); 274 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags);
270 275
271 DBUG_ON(chctl_flags & XPC_CHCTL_CLOSEREPLY); 276 DBUG_ON(chctl_flags & XPC_CHCTL_CLOSEREPLY);
272 spin_unlock_irqrestore(&ch->lock, irq_flags); 277 goto out;
273 return;
274 } 278 }
275 279
276 xpc_process_disconnect(ch, &irq_flags); 280 xpc_process_disconnect(ch, &irq_flags);
@@ -283,8 +287,7 @@ again:
283 287
284 if (ch->flags & XPC_C_DISCONNECTED) { 288 if (ch->flags & XPC_C_DISCONNECTED) {
285 DBUG_ON(part->act_state != XPC_P_AS_DEACTIVATING); 289 DBUG_ON(part->act_state != XPC_P_AS_DEACTIVATING);
286 spin_unlock_irqrestore(&ch->lock, irq_flags); 290 goto out;
287 return;
288 } 291 }
289 292
290 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST)); 293 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST));
@@ -299,8 +302,7 @@ again:
299 XPC_CHCTL_CLOSEREPLY; 302 XPC_CHCTL_CLOSEREPLY;
300 spin_unlock(&part->chctl_lock); 303 spin_unlock(&part->chctl_lock);
301 } 304 }
302 spin_unlock_irqrestore(&ch->lock, irq_flags); 305 goto out;
303 return;
304 } 306 }
305 307
306 ch->flags |= XPC_C_RCLOSEREPLY; 308 ch->flags |= XPC_C_RCLOSEREPLY;
@@ -320,14 +322,12 @@ again:
320 322
321 if (part->act_state == XPC_P_AS_DEACTIVATING || 323 if (part->act_state == XPC_P_AS_DEACTIVATING ||
322 (ch->flags & XPC_C_ROPENREQUEST)) { 324 (ch->flags & XPC_C_ROPENREQUEST)) {
323 spin_unlock_irqrestore(&ch->lock, irq_flags); 325 goto out;
324 return;
325 } 326 }
326 327
327 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_WDISCONNECT)) { 328 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_WDISCONNECT)) {
328 ch->delayed_chctl_flags |= XPC_CHCTL_OPENREQUEST; 329 ch->delayed_chctl_flags |= XPC_CHCTL_OPENREQUEST;
329 spin_unlock_irqrestore(&ch->lock, irq_flags); 330 goto out;
330 return;
331 } 331 }
332 DBUG_ON(!(ch->flags & (XPC_C_DISCONNECTED | 332 DBUG_ON(!(ch->flags & (XPC_C_DISCONNECTED |
333 XPC_C_OPENREQUEST))); 333 XPC_C_OPENREQUEST)));
@@ -341,8 +341,7 @@ again:
341 */ 341 */
342 if (args->entry_size == 0 || args->local_nentries == 0) { 342 if (args->entry_size == 0 || args->local_nentries == 0) {
343 /* assume OPENREQUEST was delayed by mistake */ 343 /* assume OPENREQUEST was delayed by mistake */
344 spin_unlock_irqrestore(&ch->lock, irq_flags); 344 goto out;
345 return;
346 } 345 }
347 346
348 ch->flags |= (XPC_C_ROPENREQUEST | XPC_C_CONNECTING); 347 ch->flags |= (XPC_C_ROPENREQUEST | XPC_C_CONNECTING);
@@ -352,8 +351,7 @@ again:
352 if (args->entry_size != ch->entry_size) { 351 if (args->entry_size != ch->entry_size) {
353 XPC_DISCONNECT_CHANNEL(ch, xpUnequalMsgSizes, 352 XPC_DISCONNECT_CHANNEL(ch, xpUnequalMsgSizes,
354 &irq_flags); 353 &irq_flags);
355 spin_unlock_irqrestore(&ch->lock, irq_flags); 354 goto out;
356 return;
357 } 355 }
358 } else { 356 } else {
359 ch->entry_size = args->entry_size; 357 ch->entry_size = args->entry_size;
@@ -375,15 +373,13 @@ again:
375 args->local_msgqueue_pa, args->local_nentries, 373 args->local_msgqueue_pa, args->local_nentries,
376 args->remote_nentries, ch->partid, ch->number); 374 args->remote_nentries, ch->partid, ch->number);
377 375
378 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED)) { 376 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED))
379 spin_unlock_irqrestore(&ch->lock, irq_flags); 377 goto out;
380 return; 378
381 }
382 if (!(ch->flags & XPC_C_OPENREQUEST)) { 379 if (!(ch->flags & XPC_C_OPENREQUEST)) {
383 XPC_DISCONNECT_CHANNEL(ch, xpOpenCloseError, 380 XPC_DISCONNECT_CHANNEL(ch, xpOpenCloseError,
384 &irq_flags); 381 &irq_flags);
385 spin_unlock_irqrestore(&ch->lock, irq_flags); 382 goto out;
386 return;
387 } 383 }
388 384
389 DBUG_ON(!(ch->flags & XPC_C_ROPENREQUEST)); 385 DBUG_ON(!(ch->flags & XPC_C_ROPENREQUEST));
@@ -400,11 +396,11 @@ again:
400 DBUG_ON(args->local_nentries == 0); 396 DBUG_ON(args->local_nentries == 0);
401 DBUG_ON(args->remote_nentries == 0); 397 DBUG_ON(args->remote_nentries == 0);
402 398
403 ret = xpc_save_remote_msgqueue_pa(ch, args->local_msgqueue_pa); 399 ret = xpc_arch_ops.save_remote_msgqueue_pa(ch,
400 args->local_msgqueue_pa);
404 if (ret != xpSuccess) { 401 if (ret != xpSuccess) {
405 XPC_DISCONNECT_CHANNEL(ch, ret, &irq_flags); 402 XPC_DISCONNECT_CHANNEL(ch, ret, &irq_flags);
406 spin_unlock_irqrestore(&ch->lock, irq_flags); 403 goto out;
407 return;
408 } 404 }
409 ch->flags |= XPC_C_ROPENREPLY; 405 ch->flags |= XPC_C_ROPENREPLY;
410 406
@@ -430,7 +426,36 @@ again:
430 xpc_process_connect(ch, &irq_flags); 426 xpc_process_connect(ch, &irq_flags);
431 } 427 }
432 428
429 if (chctl_flags & XPC_CHCTL_OPENCOMPLETE) {
430
431 dev_dbg(xpc_chan, "XPC_CHCTL_OPENCOMPLETE received from "
432 "partid=%d, channel=%d\n", ch->partid, ch->number);
433
434 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED))
435 goto out;
436
437 if (!(ch->flags & XPC_C_OPENREQUEST) ||
438 !(ch->flags & XPC_C_OPENREPLY)) {
439 XPC_DISCONNECT_CHANNEL(ch, xpOpenCloseError,
440 &irq_flags);
441 goto out;
442 }
443
444 DBUG_ON(!(ch->flags & XPC_C_ROPENREQUEST));
445 DBUG_ON(!(ch->flags & XPC_C_ROPENREPLY));
446 DBUG_ON(!(ch->flags & XPC_C_CONNECTED));
447
448 ch->flags |= XPC_C_ROPENCOMPLETE;
449
450 xpc_process_connect(ch, &irq_flags);
451 create_kthread = 1;
452 }
453
454out:
433 spin_unlock_irqrestore(&ch->lock, irq_flags); 455 spin_unlock_irqrestore(&ch->lock, irq_flags);
456
457 if (create_kthread)
458 xpc_create_kthreads(ch, 1, 0);
434} 459}
435 460
436/* 461/*
@@ -508,7 +533,7 @@ xpc_connect_channel(struct xpc_channel *ch)
508 /* initiate the connection */ 533 /* initiate the connection */
509 534
510 ch->flags |= (XPC_C_OPENREQUEST | XPC_C_CONNECTING); 535 ch->flags |= (XPC_C_OPENREQUEST | XPC_C_CONNECTING);
511 xpc_send_chctl_openrequest(ch, &irq_flags); 536 xpc_arch_ops.send_chctl_openrequest(ch, &irq_flags);
512 537
513 xpc_process_connect(ch, &irq_flags); 538 xpc_process_connect(ch, &irq_flags);
514 539
@@ -526,7 +551,7 @@ xpc_process_sent_chctl_flags(struct xpc_partition *part)
526 int ch_number; 551 int ch_number;
527 u32 ch_flags; 552 u32 ch_flags;
528 553
529 chctl.all_flags = xpc_get_chctl_all_flags(part); 554 chctl.all_flags = xpc_arch_ops.get_chctl_all_flags(part);
530 555
531 /* 556 /*
532 * Initiate channel connections for registered channels. 557 * Initiate channel connections for registered channels.
@@ -564,10 +589,6 @@ xpc_process_sent_chctl_flags(struct xpc_partition *part)
564 if (!(ch_flags & XPC_C_OPENREQUEST)) { 589 if (!(ch_flags & XPC_C_OPENREQUEST)) {
565 DBUG_ON(ch_flags & XPC_C_SETUP); 590 DBUG_ON(ch_flags & XPC_C_SETUP);
566 (void)xpc_connect_channel(ch); 591 (void)xpc_connect_channel(ch);
567 } else {
568 spin_lock_irqsave(&ch->lock, irq_flags);
569 xpc_process_connect(ch, &irq_flags);
570 spin_unlock_irqrestore(&ch->lock, irq_flags);
571 } 592 }
572 continue; 593 continue;
573 } 594 }
@@ -579,7 +600,7 @@ xpc_process_sent_chctl_flags(struct xpc_partition *part)
579 */ 600 */
580 601
581 if (chctl.flags[ch_number] & XPC_MSG_CHCTL_FLAGS) 602 if (chctl.flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
582 xpc_process_msg_chctl_flags(part, ch_number); 603 xpc_arch_ops.process_msg_chctl_flags(part, ch_number);
583 } 604 }
584} 605}
585 606
@@ -755,7 +776,7 @@ xpc_disconnect_channel(const int line, struct xpc_channel *ch,
755 XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY | 776 XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY |
756 XPC_C_CONNECTING | XPC_C_CONNECTED); 777 XPC_C_CONNECTING | XPC_C_CONNECTED);
757 778
758 xpc_send_chctl_closerequest(ch, irq_flags); 779 xpc_arch_ops.send_chctl_closerequest(ch, irq_flags);
759 780
760 if (channel_was_connected) 781 if (channel_was_connected)
761 ch->flags |= XPC_C_WASCONNECTED; 782 ch->flags |= XPC_C_WASCONNECTED;
@@ -862,8 +883,8 @@ xpc_initiate_send(short partid, int ch_number, u32 flags, void *payload,
862 DBUG_ON(payload == NULL); 883 DBUG_ON(payload == NULL);
863 884
864 if (xpc_part_ref(part)) { 885 if (xpc_part_ref(part)) {
865 ret = xpc_send_payload(&part->channels[ch_number], flags, 886 ret = xpc_arch_ops.send_payload(&part->channels[ch_number],
866 payload, payload_size, 0, NULL, NULL); 887 flags, payload, payload_size, 0, NULL, NULL);
867 xpc_part_deref(part); 888 xpc_part_deref(part);
868 } 889 }
869 890
@@ -914,9 +935,8 @@ xpc_initiate_send_notify(short partid, int ch_number, u32 flags, void *payload,
914 DBUG_ON(func == NULL); 935 DBUG_ON(func == NULL);
915 936
916 if (xpc_part_ref(part)) { 937 if (xpc_part_ref(part)) {
917 ret = xpc_send_payload(&part->channels[ch_number], flags, 938 ret = xpc_arch_ops.send_payload(&part->channels[ch_number],
918 payload, payload_size, XPC_N_CALL, func, 939 flags, payload, payload_size, XPC_N_CALL, func, key);
919 key);
920 xpc_part_deref(part); 940 xpc_part_deref(part);
921 } 941 }
922 return ret; 942 return ret;
@@ -930,7 +950,7 @@ xpc_deliver_payload(struct xpc_channel *ch)
930{ 950{
931 void *payload; 951 void *payload;
932 952
933 payload = xpc_get_deliverable_payload(ch); 953 payload = xpc_arch_ops.get_deliverable_payload(ch);
934 if (payload != NULL) { 954 if (payload != NULL) {
935 955
936 /* 956 /*
@@ -984,7 +1004,7 @@ xpc_initiate_received(short partid, int ch_number, void *payload)
984 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels); 1004 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
985 1005
986 ch = &part->channels[ch_number]; 1006 ch = &part->channels[ch_number];
987 xpc_received_payload(ch, payload); 1007 xpc_arch_ops.received_payload(ch, payload);
988 1008
989 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_payload() */ 1009 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_payload() */
990 xpc_msgqueue_deref(ch); 1010 xpc_msgqueue_deref(ch);