Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: interrupt.c,v 1.4.8.3 2001/09/23 22:24:59 kai Exp $ |
| 2 | * |
| 3 | * Copyright (C) 1996 SpellCaster Telecommunications Inc. |
| 4 | * |
| 5 | * This software may be used and distributed according to the terms |
| 6 | * of the GNU General Public License, incorporated herein by reference. |
| 7 | * |
| 8 | * For more information, please contact gpl-info@spellcast.com or write: |
| 9 | * |
| 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 |
| 16 | */ |
| 17 | |
| 18 | #include "includes.h" |
| 19 | #include "hardware.h" |
| 20 | #include "message.h" |
| 21 | #include "card.h" |
| 22 | #include <linux/interrupt.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 25 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ |
Jeff Garzik | 080eb42 | 2007-10-19 19:31:27 -0400 | [diff] [blame] | 27 | irqreturn_t interrupt_handler(int dummy, void *card_inst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | |
| 30 | RspMessage rcvmsg; |
| 31 | int channel; |
Jeff Garzik | 080eb42 | 2007-10-19 19:31:27 -0400 | [diff] [blame] | 32 | int card = (int)(unsigned long) card_inst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 34 | if (!IS_VALID_CARD(card)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | pr_debug("Invalid param: %d is not a valid card id\n", card); |
| 36 | return IRQ_NONE; |
| 37 | } |
| 38 | |
| 39 | pr_debug("%s: Entered Interrupt handler\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 40 | sc_adapter[card]->devicename); |
| 41 | |
| 42 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * Pull all of the waiting messages off the response queue |
| 44 | */ |
| 45 | while (!receivemessage(card, &rcvmsg)) { |
| 46 | /* |
| 47 | * Push the message to the adapter structure for |
| 48 | * send_and_receive to snoop |
| 49 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 50 | if (sc_adapter[card]->want_async_messages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | memcpy(&(sc_adapter[card]->async_msg), |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 52 | &rcvmsg, sizeof(RspMessage)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | channel = (unsigned int) rcvmsg.phy_link_no; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Trap Invalid request messages |
| 58 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 59 | if (IS_CM_MESSAGE(rcvmsg, 0, 0, Invalid)) { |
| 60 | pr_debug("%s: Invalid request Message, rsp_status = %d\n", |
| 61 | sc_adapter[card]->devicename, |
| 62 | rcvmsg.rsp_status); |
| 63 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Check for a linkRead message |
| 68 | */ |
| 69 | if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Read)) |
| 70 | { |
Andrew Morton | 3879b6b | 2006-10-03 01:16:15 -0700 | [diff] [blame] | 71 | pr_debug("%s: Received packet 0x%x bytes long at 0x%lx\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | sc_adapter[card]->devicename, |
| 73 | rcvmsg.msg_data.response.msg_len, |
| 74 | rcvmsg.msg_data.response.buff_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | rcvpkt(card, &rcvmsg); |
| 76 | continue; |
| 77 | |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Handle a write acknoledgement |
| 82 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 83 | if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Write)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | pr_debug("%s: Packet Send ACK on channel %d\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 85 | sc_adapter[card]->devicename, |
| 86 | rcvmsg.phy_link_no); |
| 87 | sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].free_sendbufs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | continue; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Handle a connection message |
| 93 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 94 | if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Connect)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | unsigned int callid; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 97 | setup_parm setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | pr_debug("%s: Connect message: line %d: status %d: cause 0x%x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 99 | sc_adapter[card]->devicename, |
| 100 | rcvmsg.phy_link_no, |
| 101 | rcvmsg.rsp_status, |
| 102 | rcvmsg.msg_data.byte_array[2]); |
| 103 | |
| 104 | memcpy(&callid, rcvmsg.msg_data.byte_array, sizeof(int)); |
| 105 | if (callid >= 0x8000 && callid <= 0xFFFF) |
| 106 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | pr_debug("%s: Got Dial-Out Rsp\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 108 | sc_adapter[card]->devicename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | indicate_status(card, ISDN_STAT_DCONN, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 110 | (unsigned long)rcvmsg.phy_link_no - 1, NULL); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 113 | else if (callid >= 0x0000 && callid <= 0x7FFF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Dan Carpenter | b530fb6 | 2010-10-08 10:21:22 -0700 | [diff] [blame] | 115 | int len; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | pr_debug("%s: Got Incoming Call\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 118 | sc_adapter[card]->devicename); |
Dan Carpenter | b530fb6 | 2010-10-08 10:21:22 -0700 | [diff] [blame] | 119 | len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]), |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 120 | sizeof(setup.phone)); |
Dan Carpenter | b530fb6 | 2010-10-08 10:21:22 -0700 | [diff] [blame] | 121 | if (len >= sizeof(setup.phone)) |
| 122 | continue; |
| 123 | len = strlcpy(setup.eazmsn, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 124 | sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn, |
| 125 | sizeof(setup.eazmsn)); |
Dan Carpenter | b530fb6 | 2010-10-08 10:21:22 -0700 | [diff] [blame] | 126 | if (len >= sizeof(setup.eazmsn)) |
| 127 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | setup.si1 = 7; |
| 129 | setup.si2 = 0; |
| 130 | setup.plan = 0; |
| 131 | setup.screen = 0; |
| 132 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 133 | indicate_status(card, ISDN_STAT_ICALL, (unsigned long)rcvmsg.phy_link_no - 1, (char *)&setup); |
| 134 | indicate_status(card, ISDN_STAT_DCONN, (unsigned long)rcvmsg.phy_link_no - 1, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Handle a disconnection message |
| 141 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 142 | if (IS_CE_MESSAGE(rcvmsg, Phy, 1, Disconnect)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | pr_debug("%s: disconnect message: line %d: status %d: cause 0x%x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 145 | sc_adapter[card]->devicename, |
| 146 | rcvmsg.phy_link_no, |
| 147 | rcvmsg.rsp_status, |
| 148 | rcvmsg.msg_data.byte_array[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 150 | indicate_status(card, ISDN_STAT_BHUP, (unsigned long)rcvmsg.phy_link_no - 1, NULL); |
| 151 | indicate_status(card, ISDN_STAT_DHUP, (unsigned long)rcvmsg.phy_link_no - 1, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | continue; |
| 153 | |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Handle a startProc engine up message |
| 158 | */ |
| 159 | if (IS_CM_MESSAGE(rcvmsg, 5, 0, MiscEngineUp)) { |
| 160 | pr_debug("%s: Received EngineUp message\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 161 | sc_adapter[card]->devicename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | sc_adapter[card]->EngineUp = 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 163 | sendmessage(card, CEPID, ceReqTypeCall, ceReqClass0, ceReqCallGetMyNumber, 1, 0, NULL); |
| 164 | sendmessage(card, CEPID, ceReqTypeCall, ceReqClass0, ceReqCallGetMyNumber, 2, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | init_timer(&sc_adapter[card]->stat_timer); |
| 166 | sc_adapter[card]->stat_timer.function = check_phystat; |
| 167 | sc_adapter[card]->stat_timer.data = card; |
| 168 | sc_adapter[card]->stat_timer.expires = jiffies + CHECKSTAT_TIME; |
| 169 | add_timer(&sc_adapter[card]->stat_timer); |
| 170 | continue; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Start proc response |
| 175 | */ |
| 176 | if (IS_CM_MESSAGE(rcvmsg, 2, 0, StartProc)) { |
| 177 | pr_debug("%s: StartProc Response Status %d\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 178 | sc_adapter[card]->devicename, |
| 179 | rcvmsg.rsp_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | continue; |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Handle a GetMyNumber Rsp |
| 185 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 186 | if (IS_CE_MESSAGE(rcvmsg, Call, 0, GetMyNumber)) { |
Dan Carpenter | b530fb6 | 2010-10-08 10:21:22 -0700 | [diff] [blame] | 187 | strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn, |
| 188 | rcvmsg.msg_data.byte_array, |
| 189 | sizeof(rcvmsg.msg_data.byte_array)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | continue; |
| 191 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /* |
| 194 | * PhyStatus response |
| 195 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 196 | if (IS_CE_MESSAGE(rcvmsg, Phy, 2, Status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | unsigned int b1stat, b2stat; |
| 198 | |
| 199 | /* |
| 200 | * Covert the message data to the adapter->phystat code |
| 201 | */ |
| 202 | b1stat = (unsigned int) rcvmsg.msg_data.byte_array[0]; |
| 203 | b2stat = (unsigned int) rcvmsg.msg_data.byte_array[1]; |
| 204 | |
| 205 | sc_adapter[card]->nphystat = (b2stat >> 8) | b1stat; /* endian?? */ |
| 206 | pr_debug("%s: PhyStat is 0x%2x\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 207 | sc_adapter[card]->devicename, |
| 208 | sc_adapter[card]->nphystat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | continue; |
| 210 | } |
| 211 | |
| 212 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 213 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * Handle a GetFramFormat |
| 215 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 216 | if (IS_CE_MESSAGE(rcvmsg, Call, 0, GetFrameFormat)) { |
| 217 | if (rcvmsg.msg_data.byte_array[0] != HDLC_PROTO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | unsigned int proto = HDLC_PROTO; |
| 219 | /* |
| 220 | * Set board format to HDLC if it wasn't already |
| 221 | */ |
| 222 | pr_debug("%s: current frame format: 0x%x, will change to HDLC\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 223 | sc_adapter[card]->devicename, |
| 224 | rcvmsg.msg_data.byte_array[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | sendmessage(card, CEPID, ceReqTypeCall, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 226 | ceReqClass0, |
| 227 | ceReqCallSetFrameFormat, |
| 228 | (unsigned char)channel + 1, |
| 229 | 1, &proto); |
| 230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | continue; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Hmm... |
| 236 | */ |
| 237 | pr_debug("%s: Received unhandled message (%d,%d,%d) link %d\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 238 | sc_adapter[card]->devicename, |
| 239 | rcvmsg.type, rcvmsg.class, rcvmsg.code, |
| 240 | rcvmsg.phy_link_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | } /* while */ |
| 243 | |
| 244 | pr_debug("%s: Exiting Interrupt Handler\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 245 | sc_adapter[card]->devicename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return IRQ_HANDLED; |
| 247 | } |