Revert "[PATCH] paravirt: Add startup infrastructure for paravirtualization"
[pv_ops_mirror.git] / drivers / isdn / pcbit / edss1.c
blob37e9626cebf6ccdd3d5013aee3a4f8d8be10c385
1 /*
2 * DSS.1 Finite State Machine
3 * base: ITU-T Rec Q.931
5 * Copyright (C) 1996 Universidade de Lisboa
6 *
7 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
9 * This software may be used and distributed according to the terms of
10 * the GNU General Public License, incorporated herein by reference.
14 * TODO: complete the FSM
15 * move state/event descriptions to a user space logger
18 #include <linux/string.h>
19 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/slab.h>
23 #include <linux/mm.h>
24 #include <linux/skbuff.h>
26 #include <linux/timer.h>
27 #include <asm/io.h>
29 #include <linux/isdnif.h>
31 #include "pcbit.h"
32 #include "edss1.h"
33 #include "layer2.h"
34 #include "callbacks.h"
37 char * isdn_state_table[] = {
38 "Closed",
39 "Call initiated",
40 "Overlap sending",
41 "Outgoing call proceeding",
42 "NOT DEFINED",
43 "Call delivered",
44 "Call present",
45 "Call received",
46 "Connect request",
47 "Incoming call proceeding",
48 "Active",
49 "Disconnect request",
50 "Disconnect indication",
51 "NOT DEFINED",
52 "NOT DEFINED",
53 "Suspend request",
54 "NOT DEFINED",
55 "Resume request",
56 "NOT DEFINED",
57 "Release Request",
58 "NOT DEFINED",
59 "NOT DEFINED",
60 "NOT DEFINED",
61 "NOT DEFINED",
62 "NOT DEFINED",
63 "Overlap receiving",
64 "Select protocol on B-Channel",
65 "Activate B-channel protocol"
68 #ifdef DEBUG_ERRS
69 static
70 struct CauseValue {
71 byte nr;
72 char *descr;
73 } cvlist[]={
74 {0x01,"Unallocated (unassigned) number"},
75 {0x02,"No route to specified transit network"},
76 {0x03,"No route to destination"},
77 {0x04,"Send special information tone"},
78 {0x05,"Misdialled trunk prefix"},
79 {0x06,"Channel unacceptable"},
80 {0x07,"Channel awarded and being delivered in an established channel"},
81 {0x08,"Preemption"},
82 {0x09,"Preemption - circuit reserved for reuse"},
83 {0x10,"Normal call clearing"},
84 {0x11,"User busy"},
85 {0x12,"No user responding"},
86 {0x13,"No answer from user (user alerted)"},
87 {0x14,"Subscriber absent"},
88 {0x15,"Call rejected"},
89 {0x16,"Number changed"},
90 {0x1a,"non-selected user clearing"},
91 {0x1b,"Destination out of order"},
92 {0x1c,"Invalid number format (address incomplete)"},
93 {0x1d,"Facility rejected"},
94 {0x1e,"Response to Status enquiry"},
95 {0x1f,"Normal, unspecified"},
96 {0x22,"No circuit/channel available"},
97 {0x26,"Network out of order"},
98 {0x27,"Permanent frame mode connection out-of-service"},
99 {0x28,"Permanent frame mode connection operational"},
100 {0x29,"Temporary failure"},
101 {0x2a,"Switching equipment congestion"},
102 {0x2b,"Access information discarded"},
103 {0x2c,"Requested circuit/channel not available"},
104 {0x2e,"Precedence call blocked"},
105 {0x2f,"Resource unavailable, unspecified"},
106 {0x31,"Quality of service unavailable"},
107 {0x32,"Requested facility not subscribed"},
108 {0x35,"Outgoing calls barred within CUG"},
109 {0x37,"Incoming calls barred within CUG"},
110 {0x39,"Bearer capability not authorized"},
111 {0x3a,"Bearer capability not presently available"},
112 {0x3e,"Inconsistency in designated outgoing access information and subscriber class"},
113 {0x3f,"Service or option not available, unspecified"},
114 {0x41,"Bearer capability not implemented"},
115 {0x42,"Channel type not implemented"},
116 {0x43,"Requested facility not implemented"},
117 {0x44,"Only restricted digital information bearer capability is available"},
118 {0x4f,"Service or option not implemented"},
119 {0x51,"Invalid call reference value"},
120 {0x52,"Identified channel does not exist"},
121 {0x53,"A suspended call exists, but this call identity does not"},
122 {0x54,"Call identity in use"},
123 {0x55,"No call suspended"},
124 {0x56,"Call having the requested call identity has been cleared"},
125 {0x57,"User not member of CUG"},
126 {0x58,"Incompatible destination"},
127 {0x5a,"Non-existent CUG"},
128 {0x5b,"Invalid transit network selection"},
129 {0x5f,"Invalid message, unspecified"},
130 {0x60,"Mandatory information element is missing"},
131 {0x61,"Message type non-existent or not implemented"},
132 {0x62,"Message not compatible with call state or message type non-existent or not implemented"},
133 {0x63,"Information element/parameter non-existent or not implemented"},
134 {0x64,"Invalid information element contents"},
135 {0x65,"Message not compatible with call state"},
136 {0x66,"Recovery on timer expiry"},
137 {0x67,"Parameter non-existent or not implemented - passed on"},
138 {0x6e,"Message with unrecognized parameter discarded"},
139 {0x6f,"Protocol error, unspecified"},
140 {0x7f,"Interworking, unspecified"}
143 #endif
145 static struct isdn_event_desc {
146 unsigned short ev;
147 char * desc;
148 } isdn_event_table [] = {
149 {EV_USR_SETUP_REQ, "CC->L3: Setup Request"},
150 {EV_USR_SETUP_RESP, "CC->L3: Setup Response"},
151 {EV_USR_PROCED_REQ, "CC->L3: Proceeding Request"},
152 {EV_USR_RELEASE_REQ, "CC->L3: Release Request"},
154 {EV_NET_SETUP, "NET->TE: setup "},
155 {EV_NET_CALL_PROC, "NET->TE: call proceeding"},
156 {EV_NET_SETUP_ACK, "NET->TE: setup acknowledge (more info needed)"},
157 {EV_NET_CONN, "NET->TE: connect"},
158 {EV_NET_CONN_ACK, "NET->TE: connect acknowledge"},
159 {EV_NET_DISC, "NET->TE: disconnect indication"},
160 {EV_NET_RELEASE, "NET->TE: release"},
161 {EV_NET_RELEASE_COMP, "NET->TE: release complete"},
162 {EV_NET_SELP_RESP, "Board: Select B-channel protocol ack"},
163 {EV_NET_ACTV_RESP, "Board: Activate B-channel protocol ack"},
164 {EV_TIMER, "Timeout"},
165 {0, "NULL"}
168 char * strisdnevent(ushort ev)
170 struct isdn_event_desc * entry;
172 for (entry = isdn_event_table; entry->ev; entry++)
173 if (entry->ev == ev)
174 break;
176 return entry->desc;
180 * Euro ISDN finite state machine
183 static struct fsm_timer_entry fsm_timers[] = {
184 {ST_CALL_PROC, 10},
185 {ST_DISC_REQ, 2},
186 {ST_ACTIVE_SELP, 5},
187 {ST_ACTIVE_ACTV, 5},
188 {ST_INCM_PROC, 10},
189 {ST_CONN_REQ, 2},
190 {0xff, 0}
193 static struct fsm_entry fsm_table[] = {
194 /* Connect Phase */
195 /* Outgoing */
196 {ST_NULL, ST_CALL_INIT, EV_USR_SETUP_REQ, cb_out_1},
198 {ST_CALL_INIT, ST_OVER_SEND, EV_NET_SETUP_ACK, cb_notdone},
199 {ST_CALL_INIT, ST_CALL_PROC, EV_NET_CALL_PROC, NULL},
200 {ST_CALL_INIT, ST_NULL, EV_NET_DISC, cb_out_2},
202 {ST_CALL_PROC, ST_ACTIVE_SELP, EV_NET_CONN, cb_out_2},
203 {ST_CALL_PROC, ST_NULL, EV_NET_DISC, cb_disc_1},
204 {ST_CALL_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
206 /* Incoming */
207 {ST_NULL, ST_CALL_PRES, EV_NET_SETUP, NULL},
209 {ST_CALL_PRES, ST_INCM_PROC, EV_USR_PROCED_REQ, cb_in_1},
210 {ST_CALL_PRES, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
212 {ST_INCM_PROC, ST_CONN_REQ, EV_USR_SETUP_RESP, cb_in_2},
213 {ST_INCM_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
215 {ST_CONN_REQ, ST_ACTIVE_SELP, EV_NET_CONN_ACK, cb_in_3},
217 /* Active */
218 {ST_ACTIVE, ST_NULL, EV_NET_DISC, cb_disc_1},
219 {ST_ACTIVE, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
220 {ST_ACTIVE, ST_NULL, EV_NET_RELEASE, cb_disc_3},
222 /* Disconnect */
224 {ST_DISC_REQ, ST_NULL, EV_NET_DISC, cb_disc_1},
225 {ST_DISC_REQ, ST_NULL, EV_NET_RELEASE, cb_disc_3},
227 /* protocol selection */
228 {ST_ACTIVE_SELP, ST_ACTIVE_ACTV, EV_NET_SELP_RESP, cb_selp_1},
229 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
231 {ST_ACTIVE_ACTV, ST_ACTIVE, EV_NET_ACTV_RESP, cb_open},
232 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
234 /* Timers */
235 {ST_CALL_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
236 {ST_DISC_REQ, ST_NULL, EV_TIMER, cb_disc_3},
237 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_TIMER, cb_disc_2},
238 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_TIMER, cb_disc_2},
239 {ST_INCM_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
240 {ST_CONN_REQ, ST_CONN_REQ, EV_TIMER, cb_in_2},
242 {0xff, 0, 0, NULL}
246 static void pcbit_fsm_timer(unsigned long data)
248 struct pcbit_dev *dev;
249 struct pcbit_chan *chan;
251 chan = (struct pcbit_chan *) data;
253 del_timer(&chan->fsm_timer);
254 chan->fsm_timer.function = NULL;
256 dev = chan2dev(chan);
258 if (dev == NULL) {
259 printk(KERN_WARNING "pcbit: timer for unknown device\n");
260 return;
263 pcbit_fsm_event(dev, chan, EV_TIMER, NULL);
267 void pcbit_fsm_event(struct pcbit_dev *dev, struct pcbit_chan *chan,
268 unsigned short event, struct callb_data *data)
270 struct fsm_entry * action;
271 struct fsm_timer_entry *tentry;
272 unsigned long flags;
274 spin_lock_irqsave(&dev->lock, flags);
276 for (action = fsm_table; action->init != 0xff; action++)
277 if (action->init == chan->fsm_state && action->event == event)
278 break;
280 if (action->init == 0xff) {
282 spin_unlock_irqrestore(&dev->lock, flags);
283 printk(KERN_DEBUG "fsm error: event %x on state %x\n",
284 event, chan->fsm_state);
285 return;
288 if (chan->fsm_timer.function) {
289 del_timer(&chan->fsm_timer);
290 chan->fsm_timer.function = NULL;
293 chan->fsm_state = action->final;
295 pcbit_state_change(dev, chan, action->init, event, action->final);
297 for (tentry = fsm_timers; tentry->init != 0xff; tentry++)
298 if (tentry->init == chan->fsm_state)
299 break;
301 if (tentry->init != 0xff) {
302 init_timer(&chan->fsm_timer);
303 chan->fsm_timer.function = &pcbit_fsm_timer;
304 chan->fsm_timer.data = (ulong) chan;
305 chan->fsm_timer.expires = jiffies + tentry->timeout * HZ;
306 add_timer(&chan->fsm_timer);
309 spin_unlock_irqrestore(&dev->lock, flags);
311 if (action->callb)
312 action->callb(dev, chan, data);