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
15 * +1 (416) 297-6433 Facsimile
22 #include <linux/interrupt.h>
24 static int get_card_from_irq(int irq)
28 for(i = 0 ; i < cinst ; i++) {
29 if(sc_adapter[i]->interrupt == irq)
38 irqreturn_t interrupt_handler(int interrupt, void *cardptr)
45 card = get_card_from_irq(interrupt);
47 if(!IS_VALID_CARD(card)) {
48 pr_debug("Invalid param: %d is not a valid card id\n", card);
52 pr_debug("%s: Entered Interrupt handler\n",
53 sc_adapter[card]->devicename);
56 * Pull all of the waiting messages off the response queue
58 while (!receivemessage(card, &rcvmsg)) {
60 * Push the message to the adapter structure for
61 * send_and_receive to snoop
63 if(sc_adapter[card]->want_async_messages)
64 memcpy(&(sc_adapter[card]->async_msg),
65 &rcvmsg, sizeof(RspMessage));
67 channel = (unsigned int) rcvmsg.phy_link_no;
70 * Trap Invalid request messages
72 if(IS_CM_MESSAGE(rcvmsg, 0, 0, Invalid)) {
73 pr_debug("%s: Invalid request Message, rsp_status = %d\n",
74 sc_adapter[card]->devicename,
80 * Check for a linkRead message
82 if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Read))
84 pr_debug("%s: Received packet 0x%x bytes long at 0x%lx\n",
85 sc_adapter[card]->devicename,
86 rcvmsg.msg_data.response.msg_len,
87 rcvmsg.msg_data.response.buff_offset);
88 rcvpkt(card, &rcvmsg);
94 * Handle a write acknoledgement
96 if(IS_CE_MESSAGE(rcvmsg, Lnk, 1, Write)) {
97 pr_debug("%s: Packet Send ACK on channel %d\n",
98 sc_adapter[card]->devicename,
100 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].free_sendbufs++;
105 * Handle a connection message
107 if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Connect))
111 pr_debug("%s: Connect message: line %d: status %d: cause 0x%x\n",
112 sc_adapter[card]->devicename,
115 rcvmsg.msg_data.byte_array[2]);
117 memcpy(&callid,rcvmsg.msg_data.byte_array,sizeof(int));
118 if(callid>=0x8000 && callid<=0xFFFF)
120 pr_debug("%s: Got Dial-Out Rsp\n",
121 sc_adapter[card]->devicename);
122 indicate_status(card, ISDN_STAT_DCONN,
123 (unsigned long)rcvmsg.phy_link_no-1,NULL);
126 else if(callid>=0x0000 && callid<=0x7FFF)
128 pr_debug("%s: Got Incoming Call\n",
129 sc_adapter[card]->devicename);
130 strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
132 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
138 indicate_status(card, ISDN_STAT_ICALL,(unsigned long)rcvmsg.phy_link_no-1,(char *)&setup);
139 indicate_status(card, ISDN_STAT_DCONN,(unsigned long)rcvmsg.phy_link_no-1,NULL);
145 * Handle a disconnection message
147 if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Disconnect))
149 pr_debug("%s: disconnect message: line %d: status %d: cause 0x%x\n",
150 sc_adapter[card]->devicename,
153 rcvmsg.msg_data.byte_array[2]);
155 indicate_status(card, ISDN_STAT_BHUP,(unsigned long)rcvmsg.phy_link_no-1,NULL);
156 indicate_status(card, ISDN_STAT_DHUP,(unsigned long)rcvmsg.phy_link_no-1,NULL);
162 * Handle a startProc engine up message
164 if (IS_CM_MESSAGE(rcvmsg, 5, 0, MiscEngineUp)) {
165 pr_debug("%s: Received EngineUp message\n",
166 sc_adapter[card]->devicename);
167 sc_adapter[card]->EngineUp = 1;
168 sendmessage(card, CEPID,ceReqTypeCall,ceReqClass0,ceReqCallGetMyNumber,1,0,NULL);
169 sendmessage(card, CEPID,ceReqTypeCall,ceReqClass0,ceReqCallGetMyNumber,2,0,NULL);
170 init_timer(&sc_adapter[card]->stat_timer);
171 sc_adapter[card]->stat_timer.function = check_phystat;
172 sc_adapter[card]->stat_timer.data = card;
173 sc_adapter[card]->stat_timer.expires = jiffies + CHECKSTAT_TIME;
174 add_timer(&sc_adapter[card]->stat_timer);
179 * Start proc response
181 if (IS_CM_MESSAGE(rcvmsg, 2, 0, StartProc)) {
182 pr_debug("%s: StartProc Response Status %d\n",
183 sc_adapter[card]->devicename,
189 * Handle a GetMyNumber Rsp
191 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
192 strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
199 if(IS_CE_MESSAGE(rcvmsg, Phy, 2, Status)) {
200 unsigned int b1stat, b2stat;
203 * Covert the message data to the adapter->phystat code
205 b1stat = (unsigned int) rcvmsg.msg_data.byte_array[0];
206 b2stat = (unsigned int) rcvmsg.msg_data.byte_array[1];
208 sc_adapter[card]->nphystat = (b2stat >> 8) | b1stat; /* endian?? */
209 pr_debug("%s: PhyStat is 0x%2x\n",
210 sc_adapter[card]->devicename,
211 sc_adapter[card]->nphystat);
217 * Handle a GetFramFormat
219 if(IS_CE_MESSAGE(rcvmsg, Call, 0, GetFrameFormat)) {
220 if(rcvmsg.msg_data.byte_array[0] != HDLC_PROTO) {
221 unsigned int proto = HDLC_PROTO;
223 * Set board format to HDLC if it wasn't already
225 pr_debug("%s: current frame format: 0x%x, will change to HDLC\n",
226 sc_adapter[card]->devicename,
227 rcvmsg.msg_data.byte_array[0]);
228 sendmessage(card, CEPID, ceReqTypeCall,
230 ceReqCallSetFrameFormat,
231 (unsigned char) channel +1,
240 pr_debug("%s: Received unhandled message (%d,%d,%d) link %d\n",
241 sc_adapter[card]->devicename,
242 rcvmsg.type, rcvmsg.class, rcvmsg.code,
247 pr_debug("%s: Exiting Interrupt Handler\n",
248 sc_adapter[card]->devicename);