Linux-2.6.12-rc2
[linux-2.6/kvm.git] / drivers / isdn / sc / interrupt.c
blobe5e164aca7faf7d46aa9f05291e715da334adbe6
1 /* $Id: interrupt.c,v 1.4.8.3 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * For more information, please contact gpl-info@spellcast.com or write:
10 * SpellCaster Telecommunications Inc.
11 * 5621 Finch Avenue East, Unit #3
12 * Scarborough, Ontario Canada
13 * M1B 2T9
14 * +1 (416) 297-8565
15 * +1 (416) 297-6433 Facsimile
18 #include "includes.h"
19 #include "hardware.h"
20 #include "message.h"
21 #include "card.h"
22 #include <linux/interrupt.h>
24 extern int indicate_status(int, int, ulong, char *);
25 extern void check_phystat(unsigned long);
26 extern int receivemessage(int, RspMessage *);
27 extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
28 unsigned int, unsigned int, unsigned int, unsigned int *);
29 extern void rcvpkt(int, RspMessage *);
31 extern int cinst;
32 extern board *sc_adapter[];
34 int get_card_from_irq(int irq)
36 int i;
38 for(i = 0 ; i < cinst ; i++) {
39 if(sc_adapter[i]->interrupt == irq)
40 return i;
42 return -1;
48 irqreturn_t interrupt_handler(int interrupt, void *cardptr, struct pt_regs *regs)
51 RspMessage rcvmsg;
52 int channel;
53 int card;
55 card = get_card_from_irq(interrupt);
57 if(!IS_VALID_CARD(card)) {
58 pr_debug("Invalid param: %d is not a valid card id\n", card);
59 return IRQ_NONE;
62 pr_debug("%s: Entered Interrupt handler\n",
63 sc_adapter[card]->devicename);
66 * Pull all of the waiting messages off the response queue
68 while (!receivemessage(card, &rcvmsg)) {
70 * Push the message to the adapter structure for
71 * send_and_receive to snoop
73 if(sc_adapter[card]->want_async_messages)
74 memcpy(&(sc_adapter[card]->async_msg),
75 &rcvmsg, sizeof(RspMessage));
77 channel = (unsigned int) rcvmsg.phy_link_no;
80 * Trap Invalid request messages
82 if(IS_CM_MESSAGE(rcvmsg, 0, 0, Invalid)) {
83 pr_debug("%s: Invalid request Message, rsp_status = %d\n",
84 sc_adapter[card]->devicename,
85 rcvmsg.rsp_status);
86 break;
90 * Check for a linkRead message
92 if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Read))
94 pr_debug("%s: Received packet 0x%x bytes long at 0x%x\n",
95 sc_adapter[card]->devicename,
96 rcvmsg.msg_data.response.msg_len,
97 rcvmsg.msg_data.response.buff_offset);
98 rcvpkt(card, &rcvmsg);
99 continue;
104 * Handle a write acknoledgement
106 if(IS_CE_MESSAGE(rcvmsg, Lnk, 1, Write)) {
107 pr_debug("%s: Packet Send ACK on channel %d\n",
108 sc_adapter[card]->devicename,
109 rcvmsg.phy_link_no);
110 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].free_sendbufs++;
111 continue;
115 * Handle a connection message
117 if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Connect))
119 unsigned int callid;
120 setup_parm setup;
121 pr_debug("%s: Connect message: line %d: status %d: cause 0x%x\n",
122 sc_adapter[card]->devicename,
123 rcvmsg.phy_link_no,
124 rcvmsg.rsp_status,
125 rcvmsg.msg_data.byte_array[2]);
127 memcpy(&callid,rcvmsg.msg_data.byte_array,sizeof(int));
128 if(callid>=0x8000 && callid<=0xFFFF)
130 pr_debug("%s: Got Dial-Out Rsp\n",
131 sc_adapter[card]->devicename);
132 indicate_status(card, ISDN_STAT_DCONN,
133 (unsigned long)rcvmsg.phy_link_no-1,NULL);
136 else if(callid>=0x0000 && callid<=0x7FFF)
138 pr_debug("%s: Got Incoming Call\n",
139 sc_adapter[card]->devicename);
140 strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
141 strcpy(setup.eazmsn,
142 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
143 setup.si1 = 7;
144 setup.si2 = 0;
145 setup.plan = 0;
146 setup.screen = 0;
148 indicate_status(card, ISDN_STAT_ICALL,(unsigned long)rcvmsg.phy_link_no-1,(char *)&setup);
149 indicate_status(card, ISDN_STAT_DCONN,(unsigned long)rcvmsg.phy_link_no-1,NULL);
151 continue;
155 * Handle a disconnection message
157 if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Disconnect))
159 pr_debug("%s: disconnect message: line %d: status %d: cause 0x%x\n",
160 sc_adapter[card]->devicename,
161 rcvmsg.phy_link_no,
162 rcvmsg.rsp_status,
163 rcvmsg.msg_data.byte_array[2]);
165 indicate_status(card, ISDN_STAT_BHUP,(unsigned long)rcvmsg.phy_link_no-1,NULL);
166 indicate_status(card, ISDN_STAT_DHUP,(unsigned long)rcvmsg.phy_link_no-1,NULL);
167 continue;
172 * Handle a startProc engine up message
174 if (IS_CM_MESSAGE(rcvmsg, 5, 0, MiscEngineUp)) {
175 pr_debug("%s: Received EngineUp message\n",
176 sc_adapter[card]->devicename);
177 sc_adapter[card]->EngineUp = 1;
178 sendmessage(card, CEPID,ceReqTypeCall,ceReqClass0,ceReqCallGetMyNumber,1,0,NULL);
179 sendmessage(card, CEPID,ceReqTypeCall,ceReqClass0,ceReqCallGetMyNumber,2,0,NULL);
180 init_timer(&sc_adapter[card]->stat_timer);
181 sc_adapter[card]->stat_timer.function = check_phystat;
182 sc_adapter[card]->stat_timer.data = card;
183 sc_adapter[card]->stat_timer.expires = jiffies + CHECKSTAT_TIME;
184 add_timer(&sc_adapter[card]->stat_timer);
185 continue;
189 * Start proc response
191 if (IS_CM_MESSAGE(rcvmsg, 2, 0, StartProc)) {
192 pr_debug("%s: StartProc Response Status %d\n",
193 sc_adapter[card]->devicename,
194 rcvmsg.rsp_status);
195 continue;
199 * Handle a GetMyNumber Rsp
201 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
202 strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
203 continue;
207 * PhyStatus response
209 if(IS_CE_MESSAGE(rcvmsg, Phy, 2, Status)) {
210 unsigned int b1stat, b2stat;
213 * Covert the message data to the adapter->phystat code
215 b1stat = (unsigned int) rcvmsg.msg_data.byte_array[0];
216 b2stat = (unsigned int) rcvmsg.msg_data.byte_array[1];
218 sc_adapter[card]->nphystat = (b2stat >> 8) | b1stat; /* endian?? */
219 pr_debug("%s: PhyStat is 0x%2x\n",
220 sc_adapter[card]->devicename,
221 sc_adapter[card]->nphystat);
222 continue;
227 * Handle a GetFramFormat
229 if(IS_CE_MESSAGE(rcvmsg, Call, 0, GetFrameFormat)) {
230 if(rcvmsg.msg_data.byte_array[0] != HDLC_PROTO) {
231 unsigned int proto = HDLC_PROTO;
233 * Set board format to HDLC if it wasn't already
235 pr_debug("%s: current frame format: 0x%x, will change to HDLC\n",
236 sc_adapter[card]->devicename,
237 rcvmsg.msg_data.byte_array[0]);
238 sendmessage(card, CEPID, ceReqTypeCall,
239 ceReqClass0,
240 ceReqCallSetFrameFormat,
241 (unsigned char) channel +1,
242 1,&proto);
244 continue;
248 * Hmm...
250 pr_debug("%s: Received unhandled message (%d,%d,%d) link %d\n",
251 sc_adapter[card]->devicename,
252 rcvmsg.type, rcvmsg.class, rcvmsg.code,
253 rcvmsg.phy_link_no);
255 } /* while */
257 pr_debug("%s: Exiting Interrupt Handler\n",
258 sc_adapter[card]->devicename);
259 return IRQ_HANDLED;