[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / net / irda / iriap_event.c
bloba73607450de1b9142d03904a3d60a6eb8c7a89d1
1 /*********************************************************************
3 * Filename: iriap_event.c
4 * Version: 0.1
5 * Description: IAP Finite State Machine
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Thu Aug 21 00:02:07 1997
9 * Modified at: Wed Mar 1 11:28:34 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1997, 1999-2000 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * Neither Dag Brattli nor University of Tromsø admit liability nor
22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge.
25 ********************************************************************/
27 #include <net/irda/irda.h>
28 #include <net/irda/irlmp.h>
29 #include <net/irda/iriap.h>
30 #include <net/irda/iriap_event.h>
32 static void state_s_disconnect (struct iriap_cb *self, IRIAP_EVENT event,
33 struct sk_buff *skb);
34 static void state_s_connecting (struct iriap_cb *self, IRIAP_EVENT event,
35 struct sk_buff *skb);
36 static void state_s_call (struct iriap_cb *self, IRIAP_EVENT event,
37 struct sk_buff *skb);
39 static void state_s_make_call (struct iriap_cb *self, IRIAP_EVENT event,
40 struct sk_buff *skb);
41 static void state_s_calling (struct iriap_cb *self, IRIAP_EVENT event,
42 struct sk_buff *skb);
43 static void state_s_outstanding (struct iriap_cb *self, IRIAP_EVENT event,
44 struct sk_buff *skb);
45 static void state_s_replying (struct iriap_cb *self, IRIAP_EVENT event,
46 struct sk_buff *skb);
47 static void state_s_wait_for_call(struct iriap_cb *self, IRIAP_EVENT event,
48 struct sk_buff *skb);
49 static void state_s_wait_active (struct iriap_cb *self, IRIAP_EVENT event,
50 struct sk_buff *skb);
52 static void state_r_disconnect (struct iriap_cb *self, IRIAP_EVENT event,
53 struct sk_buff *skb);
54 static void state_r_call (struct iriap_cb *self, IRIAP_EVENT event,
55 struct sk_buff *skb);
56 static void state_r_waiting (struct iriap_cb *self, IRIAP_EVENT event,
57 struct sk_buff *skb);
58 static void state_r_wait_active (struct iriap_cb *self, IRIAP_EVENT event,
59 struct sk_buff *skb);
60 static void state_r_receiving (struct iriap_cb *self, IRIAP_EVENT event,
61 struct sk_buff *skb);
62 static void state_r_execute (struct iriap_cb *self, IRIAP_EVENT event,
63 struct sk_buff *skb);
64 static void state_r_returning (struct iriap_cb *self, IRIAP_EVENT event,
65 struct sk_buff *skb);
67 static void (*iriap_state[])(struct iriap_cb *self, IRIAP_EVENT event,
68 struct sk_buff *skb) = {
69 /* Client FSM */
70 state_s_disconnect,
71 state_s_connecting,
72 state_s_call,
74 /* S-Call FSM */
75 state_s_make_call,
76 state_s_calling,
77 state_s_outstanding,
78 state_s_replying,
79 state_s_wait_for_call,
80 state_s_wait_active,
82 /* Server FSM */
83 state_r_disconnect,
84 state_r_call,
86 /* R-Connect FSM */
87 state_r_waiting,
88 state_r_wait_active,
89 state_r_receiving,
90 state_r_execute,
91 state_r_returning,
94 void iriap_next_client_state(struct iriap_cb *self, IRIAP_STATE state)
96 IRDA_ASSERT(self != NULL, return;);
97 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
99 self->client_state = state;
102 void iriap_next_call_state(struct iriap_cb *self, IRIAP_STATE state)
104 IRDA_ASSERT(self != NULL, return;);
105 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
107 self->call_state = state;
110 void iriap_next_server_state(struct iriap_cb *self, IRIAP_STATE state)
112 IRDA_ASSERT(self != NULL, return;);
113 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
115 self->server_state = state;
118 void iriap_next_r_connect_state(struct iriap_cb *self, IRIAP_STATE state)
120 IRDA_ASSERT(self != NULL, return;);
121 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
123 self->r_connect_state = state;
126 void iriap_do_client_event(struct iriap_cb *self, IRIAP_EVENT event,
127 struct sk_buff *skb)
129 IRDA_ASSERT(self != NULL, return;);
130 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
132 (*iriap_state[ self->client_state]) (self, event, skb);
135 void iriap_do_call_event(struct iriap_cb *self, IRIAP_EVENT event,
136 struct sk_buff *skb)
138 IRDA_ASSERT(self != NULL, return;);
139 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
141 (*iriap_state[ self->call_state]) (self, event, skb);
144 void iriap_do_server_event(struct iriap_cb *self, IRIAP_EVENT event,
145 struct sk_buff *skb)
147 IRDA_ASSERT(self != NULL, return;);
148 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
150 (*iriap_state[ self->server_state]) (self, event, skb);
153 void iriap_do_r_connect_event(struct iriap_cb *self, IRIAP_EVENT event,
154 struct sk_buff *skb)
156 IRDA_ASSERT(self != NULL, return;);
157 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
159 (*iriap_state[ self->r_connect_state]) (self, event, skb);
164 * Function state_s_disconnect (event, skb)
166 * S-Disconnect, The device has no LSAP connection to a particular
167 * remote device.
169 static void state_s_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
170 struct sk_buff *skb)
172 IRDA_ASSERT(self != NULL, return;);
173 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
175 switch (event) {
176 case IAP_CALL_REQUEST_GVBC:
177 iriap_next_client_state(self, S_CONNECTING);
178 IRDA_ASSERT(self->request_skb == NULL, return;);
179 /* Don't forget to refcount it -
180 * see iriap_getvaluebyclass_request(). */
181 skb_get(skb);
182 self->request_skb = skb;
183 iriap_connect_request(self);
184 break;
185 case IAP_LM_DISCONNECT_INDICATION:
186 break;
187 default:
188 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
189 break;
194 * Function state_s_connecting (self, event, skb)
196 * S-Connecting
199 static void state_s_connecting(struct iriap_cb *self, IRIAP_EVENT event,
200 struct sk_buff *skb)
202 IRDA_ASSERT(self != NULL, return;);
203 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
205 switch (event) {
206 case IAP_LM_CONNECT_CONFIRM:
208 * Jump to S-Call FSM
210 iriap_do_call_event(self, IAP_CALL_REQUEST, skb);
211 /* iriap_call_request(self, 0,0,0); */
212 iriap_next_client_state(self, S_CALL);
213 break;
214 case IAP_LM_DISCONNECT_INDICATION:
215 /* Abort calls */
216 iriap_next_call_state(self, S_MAKE_CALL);
217 iriap_next_client_state(self, S_DISCONNECT);
218 break;
219 default:
220 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
221 break;
226 * Function state_s_call (self, event, skb)
228 * S-Call, The device can process calls to a specific remote
229 * device. Whenever the LSAP connection is disconnected, this state
230 * catches that event and clears up
232 static void state_s_call(struct iriap_cb *self, IRIAP_EVENT event,
233 struct sk_buff *skb)
235 IRDA_ASSERT(self != NULL, return;);
237 switch (event) {
238 case IAP_LM_DISCONNECT_INDICATION:
239 /* Abort calls */
240 iriap_next_call_state(self, S_MAKE_CALL);
241 iriap_next_client_state(self, S_DISCONNECT);
242 break;
243 default:
244 IRDA_DEBUG(0, "state_s_call: Unknown event %d\n", event);
245 break;
250 * Function state_s_make_call (event, skb)
252 * S-Make-Call
255 static void state_s_make_call(struct iriap_cb *self, IRIAP_EVENT event,
256 struct sk_buff *skb)
258 struct sk_buff *tx_skb;
260 IRDA_ASSERT(self != NULL, return;);
262 switch (event) {
263 case IAP_CALL_REQUEST:
264 /* Already refcounted - see state_s_disconnect() */
265 tx_skb = self->request_skb;
266 self->request_skb = NULL;
268 irlmp_data_request(self->lsap, tx_skb);
269 iriap_next_call_state(self, S_OUTSTANDING);
270 break;
271 default:
272 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
273 break;
278 * Function state_s_calling (event, skb)
280 * S-Calling
283 static void state_s_calling(struct iriap_cb *self, IRIAP_EVENT event,
284 struct sk_buff *skb)
286 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
290 * Function state_s_outstanding (event, skb)
292 * S-Outstanding, The device is waiting for a response to a command
295 static void state_s_outstanding(struct iriap_cb *self, IRIAP_EVENT event,
296 struct sk_buff *skb)
298 IRDA_ASSERT(self != NULL, return;);
300 switch (event) {
301 case IAP_RECV_F_LST:
302 /*iriap_send_ack(self);*/
303 /*LM_Idle_request(idle); */
305 iriap_next_call_state(self, S_WAIT_FOR_CALL);
306 break;
307 default:
308 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__, event);
309 break;
314 * Function state_s_replying (event, skb)
316 * S-Replying, The device is collecting a multiple part response
318 static void state_s_replying(struct iriap_cb *self, IRIAP_EVENT event,
319 struct sk_buff *skb)
321 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
325 * Function state_s_wait_for_call (event, skb)
327 * S-Wait-for-Call
330 static void state_s_wait_for_call(struct iriap_cb *self, IRIAP_EVENT event,
331 struct sk_buff *skb)
333 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
338 * Function state_s_wait_active (event, skb)
340 * S-Wait-Active
343 static void state_s_wait_active(struct iriap_cb *self, IRIAP_EVENT event,
344 struct sk_buff *skb)
346 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
349 /**************************************************************************
351 * Server FSM
353 **************************************************************************/
356 * Function state_r_disconnect (self, event, skb)
358 * LM-IAS server is disconnected (not processing any requests!)
361 static void state_r_disconnect(struct iriap_cb *self, IRIAP_EVENT event,
362 struct sk_buff *skb)
364 struct sk_buff *tx_skb;
366 switch (event) {
367 case IAP_LM_CONNECT_INDICATION:
368 tx_skb = dev_alloc_skb(64);
369 if (tx_skb == NULL) {
370 IRDA_WARNING("%s: unable to malloc!\n", __FUNCTION__);
371 return;
374 /* Reserve space for MUX_CONTROL and LAP header */
375 skb_reserve(tx_skb, LMP_MAX_HEADER);
377 irlmp_connect_response(self->lsap, tx_skb);
378 /*LM_Idle_request(idle); */
380 iriap_next_server_state(self, R_CALL);
383 * Jump to R-Connect FSM, we skip R-Waiting since we do not
384 * care about LM_Idle_request()!
386 iriap_next_r_connect_state(self, R_RECEIVING);
387 break;
388 default:
389 IRDA_DEBUG(0, "%s(), unknown event %d\n", __FUNCTION__, event);
390 break;
395 * Function state_r_call (self, event, skb)
397 static void state_r_call(struct iriap_cb *self, IRIAP_EVENT event,
398 struct sk_buff *skb)
400 IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
402 switch (event) {
403 case IAP_LM_DISCONNECT_INDICATION:
404 /* Abort call */
405 iriap_next_server_state(self, R_DISCONNECT);
406 iriap_next_r_connect_state(self, R_WAITING);
407 break;
408 default:
409 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
410 break;
415 * R-Connect FSM
419 * Function state_r_waiting (self, event, skb)
421 static void state_r_waiting(struct iriap_cb *self, IRIAP_EVENT event,
422 struct sk_buff *skb)
424 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
427 static void state_r_wait_active(struct iriap_cb *self, IRIAP_EVENT event,
428 struct sk_buff *skb)
430 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__);
434 * Function state_r_receiving (self, event, skb)
436 * We are receiving a command
439 static void state_r_receiving(struct iriap_cb *self, IRIAP_EVENT event,
440 struct sk_buff *skb)
442 IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
444 switch (event) {
445 case IAP_RECV_F_LST:
446 iriap_next_r_connect_state(self, R_EXECUTE);
448 iriap_call_indication(self, skb);
449 break;
450 default:
451 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
452 break;
457 * Function state_r_execute (self, event, skb)
459 * The server is processing the request
462 static void state_r_execute(struct iriap_cb *self, IRIAP_EVENT event,
463 struct sk_buff *skb)
465 IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
467 IRDA_ASSERT(skb != NULL, return;);
468 IRDA_ASSERT(self != NULL, return;);
469 IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
471 switch (event) {
472 case IAP_CALL_RESPONSE:
474 * Since we don't implement the Waiting state, we return
475 * to state Receiving instead, DB.
477 iriap_next_r_connect_state(self, R_RECEIVING);
479 /* Don't forget to refcount it - see
480 * iriap_getvaluebyclass_response(). */
481 skb_get(skb);
483 irlmp_data_request(self->lsap, skb);
484 break;
485 default:
486 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__);
487 break;
491 static void state_r_returning(struct iriap_cb *self, IRIAP_EVENT event,
492 struct sk_buff *skb)
494 IRDA_DEBUG(0, "%s(), event=%d\n", __FUNCTION__, event);
496 switch (event) {
497 case IAP_RECV_F_LST:
498 break;
499 default:
500 break;