1 /* $Id: act2000_isa.c,v 1.11.6.3 2001/09/23 22:24:32 kai Exp $
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000 (ISA-Version).
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Thanks to Friedemann Baitinger and IBM Germany
16 #include "act2000_isa.h"
20 * Reset Controller, then try to read the Card's signature.
22 * 1 = Signature found.
23 * 0 = Signature not found.
26 act2000_isa_reset(unsigned short portbase)
34 if ((reg = inb(portbase + ISA_COR)) != 0xff) {
35 outb(reg | ISA_COR_RESET, portbase + ISA_COR);
37 outb(reg, portbase + ISA_COR);
40 for (i = 0; i < 16; i++) {
41 if (inb(portbase + ISA_ISR) & ISA_ISR_SERIAL)
45 if (serial == ISA_SER_ID)
52 act2000_isa_detect(unsigned short portbase)
56 if (request_region(portbase, ACT2000_PORTLEN, "act2000isa")) {
57 ret = act2000_isa_reset(portbase);
58 release_region(portbase, ISA_REGION);
64 act2000_isa_interrupt(int dummy, void *dev_id)
66 act2000_card *card = dev_id;
69 istatus = (inb(ISA_PORT_ISR) & 0x07);
70 if (istatus & ISA_ISR_OUT) {
71 /* RX fifo has data */
72 istatus &= ISA_ISR_OUT_MASK;
73 outb(0, ISA_PORT_SIS);
74 act2000_isa_receive(card);
75 outb(ISA_SIS_INT, ISA_PORT_SIS);
77 if (istatus & ISA_ISR_ERR) {
79 istatus &= ISA_ISR_ERR_MASK;
80 printk(KERN_WARNING "act2000: errIRQ\n");
83 printk(KERN_DEBUG "act2000: ?IRQ %d %02x\n", card->irq, istatus);
88 act2000_isa_select_irq(act2000_card * card)
92 reg = (inb(ISA_PORT_COR) & ~ISA_COR_IRQOFF) | ISA_COR_PERR;
116 outb(reg, ISA_PORT_COR);
120 act2000_isa_enable_irq(act2000_card * card)
122 act2000_isa_select_irq(card);
123 /* Enable READ irq */
124 outb(ISA_SIS_INT, ISA_PORT_SIS);
128 * Install interrupt handler, enable irq on card.
129 * If irq is -1, choose next free irq, else irq is given explicitly.
132 act2000_isa_config_irq(act2000_card * card, short irq)
136 if (card->flags & ACT2000_FLAGS_IVALID) {
137 free_irq(card->irq, card);
139 card->flags &= ~ACT2000_FLAGS_IVALID;
140 outb(ISA_COR_IRQOFF, ISA_PORT_COR);
146 if (request_irq(irq, &act2000_isa_interrupt, 0, card->regname, card)) {
148 card->flags |= ACT2000_FLAGS_IVALID;
150 "act2000: Could not request irq %d\n",irq);
153 act2000_isa_select_irq(card);
154 /* Disable READ and WRITE irq */
155 outb(0, ISA_PORT_SIS);
156 outb(0, ISA_PORT_SOS);
162 act2000_isa_config_port(act2000_card * card, unsigned short portbase)
164 if (card->flags & ACT2000_FLAGS_PVALID) {
165 release_region(card->port, ISA_REGION);
166 card->flags &= ~ACT2000_FLAGS_PVALID;
168 if (request_region(portbase, ACT2000_PORTLEN, card->regname) == NULL)
171 card->port = portbase;
172 card->flags |= ACT2000_FLAGS_PVALID;
178 * Release ressources, used by an adaptor.
181 act2000_isa_release(act2000_card * card)
185 spin_lock_irqsave(&card->lock, flags);
186 if (card->flags & ACT2000_FLAGS_IVALID)
187 free_irq(card->irq, card);
189 card->flags &= ~ACT2000_FLAGS_IVALID;
190 if (card->flags & ACT2000_FLAGS_PVALID)
191 release_region(card->port, ISA_REGION);
192 card->flags &= ~ACT2000_FLAGS_PVALID;
193 spin_unlock_irqrestore(&card->lock, flags);
197 act2000_isa_writeb(act2000_card * card, u_char data)
202 if (inb(ISA_PORT_SOS) & ISA_SOS_READY) {
203 outb(data, ISA_PORT_SDO);
214 act2000_isa_readb(act2000_card * card, u_char * data)
219 if (inb(ISA_PORT_SIS) & ISA_SIS_READY) {
220 *data = inb(ISA_PORT_SDI);
231 act2000_isa_receive(act2000_card *card)
235 if (test_and_set_bit(ACT2000_LOCK_RX, (void *) &card->ilock) != 0)
237 while (!act2000_isa_readb(card, &c)) {
238 if (card->idat.isa.rcvidx < 8) {
239 card->idat.isa.rcvhdr[card->idat.isa.rcvidx++] = c;
240 if (card->idat.isa.rcvidx == 8) {
241 int valid = actcapi_chkhdr(card, (actcapi_msghdr *)&card->idat.isa.rcvhdr);
244 card->idat.isa.rcvlen = ((actcapi_msghdr *)&card->idat.isa.rcvhdr)->len;
245 card->idat.isa.rcvskb = dev_alloc_skb(card->idat.isa.rcvlen);
246 if (card->idat.isa.rcvskb == NULL) {
247 card->idat.isa.rcvignore = 1;
249 "act2000_isa_receive: no memory\n");
250 test_and_clear_bit(ACT2000_LOCK_RX, (void *) &card->ilock);
253 memcpy(skb_put(card->idat.isa.rcvskb, 8), card->idat.isa.rcvhdr, 8);
254 card->idat.isa.rcvptr = skb_put(card->idat.isa.rcvskb, card->idat.isa.rcvlen - 8);
256 card->idat.isa.rcvidx = 0;
258 "act2000_isa_receive: Invalid CAPI msg\n");
260 int i; __u8 *p; __u8 *c; __u8 tmp[30];
261 for (i = 0, p = (__u8 *)&card->idat.isa.rcvhdr, c = tmp; i < 8; i++)
262 c += sprintf(c, "%02x ", *(p++));
263 printk(KERN_WARNING "act2000_isa_receive: %s\n", tmp);
268 if (!card->idat.isa.rcvignore)
269 *card->idat.isa.rcvptr++ = c;
270 if (++card->idat.isa.rcvidx >= card->idat.isa.rcvlen) {
271 if (!card->idat.isa.rcvignore) {
272 skb_queue_tail(&card->rcvq, card->idat.isa.rcvskb);
273 act2000_schedule_rx(card);
275 card->idat.isa.rcvidx = 0;
276 card->idat.isa.rcvlen = 8;
277 card->idat.isa.rcvignore = 0;
278 card->idat.isa.rcvskb = NULL;
279 card->idat.isa.rcvptr = card->idat.isa.rcvhdr;
283 if (!(card->flags & ACT2000_FLAGS_IVALID)) {
284 /* In polling mode, schedule myself */
285 if ((card->idat.isa.rcvidx) &&
286 (card->idat.isa.rcvignore ||
287 (card->idat.isa.rcvidx < card->idat.isa.rcvlen)))
288 act2000_schedule_poll(card);
290 test_and_clear_bit(ACT2000_LOCK_RX, (void *) &card->ilock);
294 act2000_isa_send(act2000_card * card)
301 if (test_and_set_bit(ACT2000_LOCK_TX, (void *) &card->ilock) != 0)
304 spin_lock_irqsave(&card->lock, flags);
306 if ((card->sbuf = skb_dequeue(&card->sndq))) {
307 card->ack_msg = card->sbuf->data;
308 msg = (actcapi_msg *)card->sbuf->data;
309 if ((msg->hdr.cmd.cmd == 0x86) &&
310 (msg->hdr.cmd.subcmd == 0) ) {
311 /* Save flags in message */
312 card->need_b3ack = msg->msg.data_b3_req.flags;
313 msg->msg.data_b3_req.flags = 0;
317 spin_unlock_irqrestore(&card->lock, flags);
319 /* No more data to send */
320 test_and_clear_bit(ACT2000_LOCK_TX, (void *) &card->ilock);
326 if (act2000_isa_writeb(card, *(skb->data))) {
327 /* Fifo is full, but more data to send */
328 test_and_clear_bit(ACT2000_LOCK_TX, (void *) &card->ilock);
329 /* Schedule myself */
330 act2000_schedule_tx(card);
336 msg = (actcapi_msg *)card->ack_msg;
337 if ((msg->hdr.cmd.cmd == 0x86) &&
338 (msg->hdr.cmd.subcmd == 0) ) {
340 * If it's user data, reset data-ptr
341 * and put skb into ackq.
343 skb->data = card->ack_msg;
344 /* Restore flags in message */
345 msg->msg.data_b3_req.flags = card->need_b3ack;
346 skb_queue_tail(&card->ackq, skb);
354 * Get firmware ID, check for 'ISDN' signature.
357 act2000_isa_getid(act2000_card * card)
361 u_char *p = (u_char *) & fid;
367 if (act2000_isa_readb(card, p++))
372 printk(KERN_WARNING "act2000: No Firmware-ID!\n");
376 fid.revlen[0] = '\0';
377 if (strcmp(fid.isdn, "ISDN")) {
378 printk(KERN_WARNING "act2000: Wrong Firmware-ID!\n");
381 if ((p = strchr(fid.revision, '\n')))
383 printk(KERN_INFO "act2000: Firmware-ID: %s\n", fid.revision);
384 if (card->flags & ACT2000_FLAGS_IVALID) {
385 printk(KERN_DEBUG "Enabling Interrupts ...\n");
386 act2000_isa_enable_irq(card);
392 * Download microcode into card, check Firmware signature.
395 act2000_isa_download(act2000_card * card, act2000_ddef __user * cb)
406 if (!act2000_isa_reset(card->port))
408 msleep_interruptible(500);
409 if (copy_from_user(&cblock, cb, sizeof(cblock)))
411 length = cblock.length;
413 if (!access_ok(VERIFY_READ, p, length))
415 buf = kmalloc(1024, GFP_KERNEL);
420 l = (length > 1024) ? 1024 : length;
423 if (copy_from_user(buf, p, l)) {
428 if (act2000_isa_writeb(card, *b++)) {
430 "act2000: loader timed out"
431 " len=%d c=%d\n", length, c);
441 msleep_interruptible(500);
442 return (act2000_isa_getid(card));