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 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 *);
32 extern board *sc_adapter[];
34 static int get_card_from_irq(int irq)
38 for(i = 0 ; i < cinst ; i++) {
39 if(sc_adapter[i]->interrupt == irq)
48 irqreturn_t interrupt_handler(int interrupt, void *cardptr, struct pt_regs *regs)
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);
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,
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);
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,
110 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].free_sendbufs++;
115 * Handle a connection message
117 if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Connect))
121 pr_debug("%s: Connect message: line %d: status %d: cause 0x%x\n",
122 sc_adapter[card]->devicename,
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]));
142 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
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);
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,
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);
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);
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,
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);
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);
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,
240 ceReqCallSetFrameFormat,
241 (unsigned char) channel +1,
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,
257 pr_debug("%s: Exiting Interrupt Handler\n",
258 sc_adapter[card]->devicename);