blob: 2a3eb38f0ebb34b84da227a339ab5d78755a2187 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: c4.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
2 *
3 * Module for AVM C4 & C2 card.
4 *
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/skbuff.h>
15#include <linux/delay.h>
16#include <linux/mm.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
19#include <linux/pci.h>
20#include <linux/capi.h>
21#include <linux/kernelcapi.h>
22#include <linux/init.h>
23#include <asm/io.h>
24#include <asm/uaccess.h>
25#include <linux/netdevice.h>
26#include <linux/isdn/capicmd.h>
27#include <linux/isdn/capiutil.h>
28#include <linux/isdn/capilli.h>
29#include "avmcard.h"
30
31#undef CONFIG_C4_DEBUG
32#undef CONFIG_C4_POLLDEBUG
33
34/* ------------------------------------------------------------- */
35
36static char *revision = "$Revision: 1.1.2.2 $";
37
38/* ------------------------------------------------------------- */
39
40static int suppress_pollack;
41
42static struct pci_device_id c4_pci_tbl[] = {
43 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C4, 0, 0, (unsigned long)4 },
44 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C2, 0, 0, (unsigned long)2 },
45 { } /* Terminating entry */
46};
47
48MODULE_DEVICE_TABLE(pci, c4_pci_tbl);
49MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM C2/C4 cards");
50MODULE_AUTHOR("Carsten Paeth");
51MODULE_LICENSE("GPL");
Rusty Russell8d3b33f2006-03-25 03:07:05 -080052module_param(suppress_pollack, bool, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/* ------------------------------------------------------------- */
55
56static void c4_dispatch_tx(avmcard *card);
57
58/* ------------------------------------------------------------- */
59
60#define DC21285_DRAM_A0MR 0x40000000
61#define DC21285_DRAM_A1MR 0x40004000
62#define DC21285_DRAM_A2MR 0x40008000
63#define DC21285_DRAM_A3MR 0x4000C000
64
65#define CAS_OFFSET 0x88
66
67#define DC21285_ARMCSR_BASE 0x42000000
68
69#define PCI_OUT_INT_STATUS 0x30
70#define PCI_OUT_INT_MASK 0x34
71#define MAILBOX_0 0x50
72#define MAILBOX_1 0x54
73#define MAILBOX_2 0x58
74#define MAILBOX_3 0x5C
75#define DOORBELL 0x60
76#define DOORBELL_SETUP 0x64
77
78#define CHAN_1_CONTROL 0x90
79#define CHAN_2_CONTROL 0xB0
80#define DRAM_TIMING 0x10C
81#define DRAM_ADDR_SIZE_0 0x110
82#define DRAM_ADDR_SIZE_1 0x114
83#define DRAM_ADDR_SIZE_2 0x118
84#define DRAM_ADDR_SIZE_3 0x11C
85#define SA_CONTROL 0x13C
86#define XBUS_CYCLE 0x148
87#define XBUS_STROBE 0x14C
88#define DBELL_PCI_MASK 0x150
89#define DBELL_SA_MASK 0x154
90
91#define SDRAM_SIZE 0x1000000
92
93/* ------------------------------------------------------------- */
94
95#define MBOX_PEEK_POKE MAILBOX_0
96
97#define DBELL_ADDR 0x01
98#define DBELL_DATA 0x02
99#define DBELL_RNWR 0x40
100#define DBELL_INIT 0x80
101
102/* ------------------------------------------------------------- */
103
104#define MBOX_UP_ADDR MAILBOX_0
105#define MBOX_UP_LEN MAILBOX_1
106#define MBOX_DOWN_ADDR MAILBOX_2
107#define MBOX_DOWN_LEN MAILBOX_3
108
109#define DBELL_UP_HOST 0x00000100
110#define DBELL_UP_ARM 0x00000200
111#define DBELL_DOWN_HOST 0x00000400
112#define DBELL_DOWN_ARM 0x00000800
113#define DBELL_RESET_HOST 0x40000000
114#define DBELL_RESET_ARM 0x80000000
115
116/* ------------------------------------------------------------- */
117
118#define DRAM_TIMING_DEF 0x001A01A5
119#define DRAM_AD_SZ_DEF0 0x00000045
120#define DRAM_AD_SZ_NULL 0x00000000
121
122#define SA_CTL_ALLRIGHT 0x64AA0271
123
124#define INIT_XBUS_CYCLE 0x100016DB
125#define INIT_XBUS_STROBE 0xF1F1F1F1
126
127/* ------------------------------------------------------------- */
128
129#define RESET_TIMEOUT (15*HZ) /* 15 sec */
130#define PEEK_POKE_TIMEOUT (HZ/10) /* 0.1 sec */
131
132/* ------------------------------------------------------------- */
133
134#define c4outmeml(addr, value) writel(value, addr)
135#define c4inmeml(addr) readl(addr)
136#define c4outmemw(addr, value) writew(value, addr)
137#define c4inmemw(addr) readw(addr)
138#define c4outmemb(addr, value) writeb(value, addr)
139#define c4inmemb(addr) readb(addr)
140
141/* ------------------------------------------------------------- */
142
143static inline int wait_for_doorbell(avmcard *card, unsigned long t)
144{
145 unsigned long stop;
146
147 stop = jiffies + t;
148 while (c4inmeml(card->mbase+DOORBELL) != 0xffffffff) {
149 if (!time_before(jiffies, stop))
150 return -1;
151 mb();
152 }
153 return 0;
154}
155
156static int c4_poke(avmcard *card, unsigned long off, unsigned long value)
157{
158
159 if (wait_for_doorbell(card, HZ/10) < 0)
160 return -1;
161
162 c4outmeml(card->mbase+MBOX_PEEK_POKE, off);
163 c4outmeml(card->mbase+DOORBELL, DBELL_ADDR);
164
165 if (wait_for_doorbell(card, HZ/10) < 0)
166 return -1;
167
168 c4outmeml(card->mbase+MBOX_PEEK_POKE, value);
169 c4outmeml(card->mbase+DOORBELL, DBELL_DATA | DBELL_ADDR);
170
171 return 0;
172}
173
174static int c4_peek(avmcard *card, unsigned long off, unsigned long *valuep)
175{
176 if (wait_for_doorbell(card, HZ/10) < 0)
177 return -1;
178
179 c4outmeml(card->mbase+MBOX_PEEK_POKE, off);
180 c4outmeml(card->mbase+DOORBELL, DBELL_RNWR | DBELL_ADDR);
181
182 if (wait_for_doorbell(card, HZ/10) < 0)
183 return -1;
184
185 *valuep = c4inmeml(card->mbase+MBOX_PEEK_POKE);
186
187 return 0;
188}
189
190/* ------------------------------------------------------------- */
191
192static int c4_load_t4file(avmcard *card, capiloaddatapart * t4file)
193{
194 u32 val;
195 unsigned char *dp;
196 u_int left;
197 u32 loadoff = 0;
198
199 dp = t4file->data;
200 left = t4file->len;
201 while (left >= sizeof(u32)) {
202 if (t4file->user) {
203 if (copy_from_user(&val, dp, sizeof(val)))
204 return -EFAULT;
205 } else {
206 memcpy(&val, dp, sizeof(val));
207 }
208 if (c4_poke(card, loadoff, val)) {
209 printk(KERN_ERR "%s: corrupted firmware file ?\n",
210 card->name);
211 return -EIO;
212 }
213 left -= sizeof(u32);
214 dp += sizeof(u32);
215 loadoff += sizeof(u32);
216 }
217 if (left) {
218 val = 0;
219 if (t4file->user) {
220 if (copy_from_user(&val, dp, left))
221 return -EFAULT;
222 } else {
223 memcpy(&val, dp, left);
224 }
225 if (c4_poke(card, loadoff, val)) {
226 printk(KERN_ERR "%s: corrupted firmware file ?\n",
227 card->name);
228 return -EIO;
229 }
230 }
231 return 0;
232}
233
234/* ------------------------------------------------------------- */
235
236static inline void _put_byte(void **pp, u8 val)
237{
238 u8 *s = *pp;
239 *s++ = val;
240 *pp = s;
241}
242
243static inline void _put_word(void **pp, u32 val)
244{
245 u8 *s = *pp;
246 *s++ = val & 0xff;
247 *s++ = (val >> 8) & 0xff;
248 *s++ = (val >> 16) & 0xff;
249 *s++ = (val >> 24) & 0xff;
250 *pp = s;
251}
252
253static inline void _put_slice(void **pp, unsigned char *dp, unsigned int len)
254{
255 unsigned i = len;
256 _put_word(pp, i);
257 while (i-- > 0)
258 _put_byte(pp, *dp++);
259}
260
261static inline u8 _get_byte(void **pp)
262{
263 u8 *s = *pp;
264 u8 val;
265 val = *s++;
266 *pp = s;
267 return val;
268}
269
270static inline u32 _get_word(void **pp)
271{
272 u8 *s = *pp;
273 u32 val;
274 val = *s++;
275 val |= (*s++ << 8);
276 val |= (*s++ << 16);
277 val |= (*s++ << 24);
278 *pp = s;
279 return val;
280}
281
282static inline u32 _get_slice(void **pp, unsigned char *dp)
283{
284 unsigned int len, i;
285
286 len = i = _get_word(pp);
287 while (i-- > 0) *dp++ = _get_byte(pp);
288 return len;
289}
290
291/* ------------------------------------------------------------- */
292
293static void c4_reset(avmcard *card)
294{
295 unsigned long stop;
296
297 c4outmeml(card->mbase+DOORBELL, DBELL_RESET_ARM);
298
299 stop = jiffies + HZ*10;
300 while (c4inmeml(card->mbase+DOORBELL) != 0xffffffff) {
301 if (!time_before(jiffies, stop))
302 return;
303 c4outmeml(card->mbase+DOORBELL, DBELL_ADDR);
304 mb();
305 }
306
307 c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0);
308 c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0);
309}
310
311/* ------------------------------------------------------------- */
312
313static int c4_detect(avmcard *card)
314{
315 unsigned long stop, dummy;
316
317 c4outmeml(card->mbase+PCI_OUT_INT_MASK, 0x0c);
318 if (c4inmeml(card->mbase+PCI_OUT_INT_MASK) != 0x0c)
319 return 1;
320
321 c4outmeml(card->mbase+DOORBELL, DBELL_RESET_ARM);
322
323 stop = jiffies + HZ*10;
324 while (c4inmeml(card->mbase+DOORBELL) != 0xffffffff) {
325 if (!time_before(jiffies, stop))
326 return 2;
327 c4outmeml(card->mbase+DOORBELL, DBELL_ADDR);
328 mb();
329 }
330
331 c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0);
332 c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0);
333
334 c4outmeml(card->mbase+MAILBOX_0, 0x55aa55aa);
335 if (c4inmeml(card->mbase+MAILBOX_0) != 0x55aa55aa) return 3;
336
337 c4outmeml(card->mbase+MAILBOX_0, 0xaa55aa55);
338 if (c4inmeml(card->mbase+MAILBOX_0) != 0xaa55aa55) return 4;
339
340 if (c4_poke(card, DC21285_ARMCSR_BASE+DBELL_SA_MASK, 0)) return 5;
341 if (c4_poke(card, DC21285_ARMCSR_BASE+DBELL_PCI_MASK, 0)) return 6;
342 if (c4_poke(card, DC21285_ARMCSR_BASE+SA_CONTROL, SA_CTL_ALLRIGHT))
343 return 7;
344 if (c4_poke(card, DC21285_ARMCSR_BASE+XBUS_CYCLE, INIT_XBUS_CYCLE))
345 return 8;
346 if (c4_poke(card, DC21285_ARMCSR_BASE+XBUS_STROBE, INIT_XBUS_STROBE))
347 return 8;
348 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_TIMING, 0)) return 9;
349
350 mdelay(1);
351
352 if (c4_peek(card, DC21285_DRAM_A0MR, &dummy)) return 10;
353 if (c4_peek(card, DC21285_DRAM_A1MR, &dummy)) return 11;
354 if (c4_peek(card, DC21285_DRAM_A2MR, &dummy)) return 12;
355 if (c4_peek(card, DC21285_DRAM_A3MR, &dummy)) return 13;
356
357 if (c4_poke(card, DC21285_DRAM_A0MR+CAS_OFFSET, 0)) return 14;
358 if (c4_poke(card, DC21285_DRAM_A1MR+CAS_OFFSET, 0)) return 15;
359 if (c4_poke(card, DC21285_DRAM_A2MR+CAS_OFFSET, 0)) return 16;
360 if (c4_poke(card, DC21285_DRAM_A3MR+CAS_OFFSET, 0)) return 17;
361
362 mdelay(1);
363
364 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_TIMING, DRAM_TIMING_DEF))
365 return 18;
366
367 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_ADDR_SIZE_0,DRAM_AD_SZ_DEF0))
368 return 19;
369 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_ADDR_SIZE_1,DRAM_AD_SZ_NULL))
370 return 20;
371 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_ADDR_SIZE_2,DRAM_AD_SZ_NULL))
372 return 21;
373 if (c4_poke(card, DC21285_ARMCSR_BASE+DRAM_ADDR_SIZE_3,DRAM_AD_SZ_NULL))
374 return 22;
375
376 /* Transputer test */
377
378 if ( c4_poke(card, 0x000000, 0x11111111)
379 || c4_poke(card, 0x400000, 0x22222222)
380 || c4_poke(card, 0x800000, 0x33333333)
381 || c4_poke(card, 0xC00000, 0x44444444))
382 return 23;
383
384 if ( c4_peek(card, 0x000000, &dummy) || dummy != 0x11111111
385 || c4_peek(card, 0x400000, &dummy) || dummy != 0x22222222
386 || c4_peek(card, 0x800000, &dummy) || dummy != 0x33333333
387 || c4_peek(card, 0xC00000, &dummy) || dummy != 0x44444444)
388 return 24;
389
390 if ( c4_poke(card, 0x000000, 0x55555555)
391 || c4_poke(card, 0x400000, 0x66666666)
392 || c4_poke(card, 0x800000, 0x77777777)
393 || c4_poke(card, 0xC00000, 0x88888888))
394 return 25;
395
396 if ( c4_peek(card, 0x000000, &dummy) || dummy != 0x55555555
397 || c4_peek(card, 0x400000, &dummy) || dummy != 0x66666666
398 || c4_peek(card, 0x800000, &dummy) || dummy != 0x77777777
399 || c4_peek(card, 0xC00000, &dummy) || dummy != 0x88888888)
400 return 26;
401
402 return 0;
403}
404
405/* ------------------------------------------------------------- */
406
407static void c4_dispatch_tx(avmcard *card)
408{
409 avmcard_dmainfo *dma = card->dma;
410 struct sk_buff *skb;
411 u8 cmd, subcmd;
412 u16 len;
413 u32 txlen;
414 void *p;
415
416
417 if (card->csr & DBELL_DOWN_ARM) { /* tx busy */
418 return;
419 }
420
421 skb = skb_dequeue(&dma->send_queue);
422 if (!skb) {
423#ifdef CONFIG_C4_DEBUG
424 printk(KERN_DEBUG "%s: tx underrun\n", card->name);
425#endif
426 return;
427 }
428
429 len = CAPIMSG_LEN(skb->data);
430
431 if (len) {
432 cmd = CAPIMSG_COMMAND(skb->data);
433 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
434
435 p = dma->sendbuf.dmabuf;
436
437 if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
438 u16 dlen = CAPIMSG_DATALEN(skb->data);
439 _put_byte(&p, SEND_DATA_B3_REQ);
440 _put_slice(&p, skb->data, len);
441 _put_slice(&p, skb->data + len, dlen);
442 } else {
443 _put_byte(&p, SEND_MESSAGE);
444 _put_slice(&p, skb->data, len);
445 }
446 txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf;
447#ifdef CONFIG_C4_DEBUG
448 printk(KERN_DEBUG "%s: tx put msg len=%d\n", card->name, txlen);
449#endif
450 } else {
451 txlen = skb->len-2;
452#ifdef CONFIG_C4_POLLDEBUG
453 if (skb->data[2] == SEND_POLLACK)
454 printk(KERN_INFO "%s: ack to c4\n", card->name);
455#endif
456#ifdef CONFIG_C4_DEBUG
457 printk(KERN_DEBUG "%s: tx put 0x%x len=%d\n",
458 card->name, skb->data[2], txlen);
459#endif
460 memcpy(dma->sendbuf.dmabuf, skb->data+2, skb->len-2);
461 }
462 txlen = (txlen + 3) & ~3;
463
464 c4outmeml(card->mbase+MBOX_DOWN_ADDR, dma->sendbuf.dmaaddr);
465 c4outmeml(card->mbase+MBOX_DOWN_LEN, txlen);
466
467 card->csr |= DBELL_DOWN_ARM;
468
469 c4outmeml(card->mbase+DOORBELL, DBELL_DOWN_ARM);
470
471 dev_kfree_skb_any(skb);
472}
473
474/* ------------------------------------------------------------- */
475
476static void queue_pollack(avmcard *card)
477{
478 struct sk_buff *skb;
479 void *p;
480
481 skb = alloc_skb(3, GFP_ATOMIC);
482 if (!skb) {
483 printk(KERN_CRIT "%s: no memory, lost poll ack\n",
484 card->name);
485 return;
486 }
487 p = skb->data;
488 _put_byte(&p, 0);
489 _put_byte(&p, 0);
490 _put_byte(&p, SEND_POLLACK);
491 skb_put(skb, (u8 *)p - (u8 *)skb->data);
492
493 skb_queue_tail(&card->dma->send_queue, skb);
494 c4_dispatch_tx(card);
495}
496
497/* ------------------------------------------------------------- */
498
499static void c4_handle_rx(avmcard *card)
500{
501 avmcard_dmainfo *dma = card->dma;
502 struct capi_ctr *ctrl;
503 avmctrl_info *cinfo;
504 struct sk_buff *skb;
505 void *p = dma->recvbuf.dmabuf;
506 u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize;
507 u8 b1cmd = _get_byte(&p);
508 u32 cidx;
509
510
511#ifdef CONFIG_C4_DEBUG
512 printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name,
513 b1cmd, (unsigned long)dma->recvlen);
514#endif
515
516 switch (b1cmd) {
517 case RECEIVE_DATA_B3_IND:
518
519 ApplId = (unsigned) _get_word(&p);
520 MsgLen = _get_slice(&p, card->msgbuf);
521 DataB3Len = _get_slice(&p, card->databuf);
522 cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr;
523 if (cidx >= card->nlogcontr) cidx = 0;
524 ctrl = &card->ctrlinfo[cidx].capi_ctrl;
525
526 if (MsgLen < 30) { /* not CAPI 64Bit */
527 memset(card->msgbuf+MsgLen, 0, 30-MsgLen);
528 MsgLen = 30;
529 CAPIMSG_SETLEN(card->msgbuf, 30);
530 }
531 if (!(skb = alloc_skb(DataB3Len+MsgLen, GFP_ATOMIC))) {
532 printk(KERN_ERR "%s: incoming packet dropped\n",
533 card->name);
534 } else {
535 memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
536 memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len);
537 capi_ctr_handle_message(ctrl, ApplId, skb);
538 }
539 break;
540
541 case RECEIVE_MESSAGE:
542
543 ApplId = (unsigned) _get_word(&p);
544 MsgLen = _get_slice(&p, card->msgbuf);
545 cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr;
546 if (cidx >= card->nlogcontr) cidx = 0;
547 cinfo = &card->ctrlinfo[cidx];
548 ctrl = &card->ctrlinfo[cidx].capi_ctrl;
549
550 if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) {
551 printk(KERN_ERR "%s: incoming packet dropped\n",
552 card->name);
553 } else {
554 memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
555 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF)
556 capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
557 CAPIMSG_NCCI(skb->data),
558 CAPIMSG_MSGID(skb->data));
559
560 capi_ctr_handle_message(ctrl, ApplId, skb);
561 }
562 break;
563
564 case RECEIVE_NEW_NCCI:
565
566 ApplId = _get_word(&p);
567 NCCI = _get_word(&p);
568 WindowSize = _get_word(&p);
569 cidx = (NCCI&0x7f) - card->cardnr;
570 if (cidx >= card->nlogcontr) cidx = 0;
571
572 capilib_new_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI, WindowSize);
573
574 break;
575
576 case RECEIVE_FREE_NCCI:
577
578 ApplId = _get_word(&p);
579 NCCI = _get_word(&p);
580
581 if (NCCI != 0xffffffff) {
582 cidx = (NCCI&0x7f) - card->cardnr;
583 if (cidx >= card->nlogcontr) cidx = 0;
584 capilib_free_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI);
585 }
586 break;
587
588 case RECEIVE_START:
589#ifdef CONFIG_C4_POLLDEBUG
590 printk(KERN_INFO "%s: poll from c4\n", card->name);
591#endif
592 if (!suppress_pollack)
593 queue_pollack(card);
594 for (cidx=0; cidx < card->nr_controllers; cidx++) {
595 ctrl = &card->ctrlinfo[cidx].capi_ctrl;
596 capi_ctr_resume_output(ctrl);
597 }
598 break;
599
600 case RECEIVE_STOP:
601 for (cidx=0; cidx < card->nr_controllers; cidx++) {
602 ctrl = &card->ctrlinfo[cidx].capi_ctrl;
603 capi_ctr_suspend_output(ctrl);
604 }
605 break;
606
607 case RECEIVE_INIT:
608
609 cidx = card->nlogcontr;
610 if (cidx >= card->nr_controllers) {
611 printk(KERN_ERR "%s: card with %d controllers ??\n",
612 card->name, cidx+1);
613 break;
614 }
615 card->nlogcontr++;
616 cinfo = &card->ctrlinfo[cidx];
617 ctrl = &cinfo->capi_ctrl;
618 cinfo->versionlen = _get_slice(&p, cinfo->versionbuf);
619 b1_parse_version(cinfo);
620 printk(KERN_INFO "%s: %s-card (%s) now active\n",
621 card->name,
622 cinfo->version[VER_CARDTYPE],
623 cinfo->version[VER_DRIVER]);
624 capi_ctr_ready(&cinfo->capi_ctrl);
625 break;
626
627 case RECEIVE_TASK_READY:
628 ApplId = (unsigned) _get_word(&p);
629 MsgLen = _get_slice(&p, card->msgbuf);
630 card->msgbuf[MsgLen] = 0;
631 while ( MsgLen > 0
632 && ( card->msgbuf[MsgLen-1] == '\n'
633 || card->msgbuf[MsgLen-1] == '\r')) {
634 card->msgbuf[MsgLen-1] = 0;
635 MsgLen--;
636 }
637 printk(KERN_INFO "%s: task %d \"%s\" ready.\n",
638 card->name, ApplId, card->msgbuf);
639 break;
640
641 case RECEIVE_DEBUGMSG:
642 MsgLen = _get_slice(&p, card->msgbuf);
643 card->msgbuf[MsgLen] = 0;
644 while ( MsgLen > 0
645 && ( card->msgbuf[MsgLen-1] == '\n'
646 || card->msgbuf[MsgLen-1] == '\r')) {
647 card->msgbuf[MsgLen-1] = 0;
648 MsgLen--;
649 }
650 printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf);
651 break;
652
653 default:
654 printk(KERN_ERR "%s: c4_interrupt: 0x%x ???\n",
655 card->name, b1cmd);
656 return;
657 }
658}
659
660/* ------------------------------------------------------------- */
661
662static irqreturn_t c4_handle_interrupt(avmcard *card)
663{
664 unsigned long flags;
665 u32 status;
666
667 spin_lock_irqsave(&card->lock, flags);
668 status = c4inmeml(card->mbase+DOORBELL);
669
670 if (status & DBELL_RESET_HOST) {
671 u_int i;
672 c4outmeml(card->mbase+PCI_OUT_INT_MASK, 0x0c);
673 spin_unlock_irqrestore(&card->lock, flags);
674 if (card->nlogcontr == 0)
675 return IRQ_HANDLED;
676 printk(KERN_ERR "%s: unexpected reset\n", card->name);
677 for (i=0; i < card->nr_controllers; i++) {
678 avmctrl_info *cinfo = &card->ctrlinfo[i];
679 memset(cinfo->version, 0, sizeof(cinfo->version));
680 capilib_release(&cinfo->ncci_head);
681 capi_ctr_reseted(&cinfo->capi_ctrl);
682 }
683 card->nlogcontr = 0;
684 return IRQ_HANDLED;
685 }
686
687 status &= (DBELL_UP_HOST | DBELL_DOWN_HOST);
688 if (!status) {
689 spin_unlock_irqrestore(&card->lock, flags);
690 return IRQ_HANDLED;
691 }
692 c4outmeml(card->mbase+DOORBELL, status);
693
694 if ((status & DBELL_UP_HOST) != 0) {
695 card->dma->recvlen = c4inmeml(card->mbase+MBOX_UP_LEN);
696 c4outmeml(card->mbase+MBOX_UP_LEN, 0);
697 c4_handle_rx(card);
698 card->dma->recvlen = 0;
699 c4outmeml(card->mbase+MBOX_UP_LEN, card->dma->recvbuf.size);
700 c4outmeml(card->mbase+DOORBELL, DBELL_UP_ARM);
701 }
702
703 if ((status & DBELL_DOWN_HOST) != 0) {
704 card->csr &= ~DBELL_DOWN_ARM;
705 c4_dispatch_tx(card);
706 } else if (card->csr & DBELL_DOWN_HOST) {
707 if (c4inmeml(card->mbase+MBOX_DOWN_LEN) == 0) {
708 card->csr &= ~DBELL_DOWN_ARM;
709 c4_dispatch_tx(card);
710 }
711 }
712 spin_unlock_irqrestore(&card->lock, flags);
713 return IRQ_HANDLED;
714}
715
David Howells7d12e782006-10-05 14:55:46 +0100716static irqreturn_t c4_interrupt(int interrupt, void *devptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
718 avmcard *card = devptr;
719
720 return c4_handle_interrupt(card);
721}
722
723/* ------------------------------------------------------------- */
724
725static void c4_send_init(avmcard *card)
726{
727 struct sk_buff *skb;
728 void *p;
729
730 skb = alloc_skb(15, GFP_ATOMIC);
731 if (!skb) {
732 printk(KERN_CRIT "%s: no memory, lost register appl.\n",
733 card->name);
734 return;
735 }
736 p = skb->data;
737 _put_byte(&p, 0);
738 _put_byte(&p, 0);
739 _put_byte(&p, SEND_INIT);
740 _put_word(&p, CAPI_MAXAPPL);
741 _put_word(&p, AVM_NCCI_PER_CHANNEL*30);
742 _put_word(&p, card->cardnr - 1);
743 skb_put(skb, (u8 *)p - (u8 *)skb->data);
744
745 skb_queue_tail(&card->dma->send_queue, skb);
746 c4_dispatch_tx(card);
747}
748
749static int queue_sendconfigword(avmcard *card, u32 val)
750{
751 struct sk_buff *skb;
752 void *p;
753
754 skb = alloc_skb(3+4, GFP_ATOMIC);
755 if (!skb) {
756 printk(KERN_CRIT "%s: no memory, send config\n",
757 card->name);
758 return -ENOMEM;
759 }
760 p = skb->data;
761 _put_byte(&p, 0);
762 _put_byte(&p, 0);
763 _put_byte(&p, SEND_CONFIG);
764 _put_word(&p, val);
765 skb_put(skb, (u8 *)p - (u8 *)skb->data);
766
767 skb_queue_tail(&card->dma->send_queue, skb);
768 c4_dispatch_tx(card);
769 return 0;
770}
771
772static int queue_sendconfig(avmcard *card, char cval[4])
773{
774 struct sk_buff *skb;
775 unsigned long flags;
776 void *p;
777
778 skb = alloc_skb(3+4, GFP_ATOMIC);
779 if (!skb) {
780 printk(KERN_CRIT "%s: no memory, send config\n",
781 card->name);
782 return -ENOMEM;
783 }
784 p = skb->data;
785 _put_byte(&p, 0);
786 _put_byte(&p, 0);
787 _put_byte(&p, SEND_CONFIG);
788 _put_byte(&p, cval[0]);
789 _put_byte(&p, cval[1]);
790 _put_byte(&p, cval[2]);
791 _put_byte(&p, cval[3]);
792 skb_put(skb, (u8 *)p - (u8 *)skb->data);
793
794 skb_queue_tail(&card->dma->send_queue, skb);
795
796 spin_lock_irqsave(&card->lock, flags);
797 c4_dispatch_tx(card);
798 spin_unlock_irqrestore(&card->lock, flags);
799 return 0;
800}
801
802static int c4_send_config(avmcard *card, capiloaddatapart * config)
803{
804 u8 val[4];
805 unsigned char *dp;
806 u_int left;
807 int retval;
808
809 if ((retval = queue_sendconfigword(card, 1)) != 0)
810 return retval;
811 if ((retval = queue_sendconfigword(card, config->len)) != 0)
812 return retval;
813
814 dp = config->data;
815 left = config->len;
816 while (left >= sizeof(u32)) {
817 if (config->user) {
818 if (copy_from_user(val, dp, sizeof(val)))
819 return -EFAULT;
820 } else {
821 memcpy(val, dp, sizeof(val));
822 }
823 if ((retval = queue_sendconfig(card, val)) != 0)
824 return retval;
825 left -= sizeof(val);
826 dp += sizeof(val);
827 }
828 if (left) {
829 memset(val, 0, sizeof(val));
830 if (config->user) {
831 if (copy_from_user(&val, dp, left))
832 return -EFAULT;
833 } else {
834 memcpy(&val, dp, left);
835 }
836 if ((retval = queue_sendconfig(card, val)) != 0)
837 return retval;
838 }
839
840 return 0;
841}
842
843static int c4_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
844{
845 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
846 avmcard *card = cinfo->card;
847 int retval;
848
849 if ((retval = c4_load_t4file(card, &data->firmware))) {
850 printk(KERN_ERR "%s: failed to load t4file!!\n",
851 card->name);
852 c4_reset(card);
853 return retval;
854 }
855
856 card->csr = 0;
857 c4outmeml(card->mbase+MBOX_UP_LEN, 0);
858 c4outmeml(card->mbase+MBOX_DOWN_LEN, 0);
859 c4outmeml(card->mbase+DOORBELL, DBELL_INIT);
860 mdelay(1);
861 c4outmeml(card->mbase+DOORBELL,
862 DBELL_UP_HOST | DBELL_DOWN_HOST | DBELL_RESET_HOST);
863
864 c4outmeml(card->mbase+PCI_OUT_INT_MASK, 0x08);
865
866 card->dma->recvlen = 0;
867 c4outmeml(card->mbase+MBOX_UP_ADDR, card->dma->recvbuf.dmaaddr);
868 c4outmeml(card->mbase+MBOX_UP_LEN, card->dma->recvbuf.size);
869 c4outmeml(card->mbase+DOORBELL, DBELL_UP_ARM);
870
871 if (data->configuration.len > 0 && data->configuration.data) {
872 retval = c4_send_config(card, &data->configuration);
873 if (retval) {
874 printk(KERN_ERR "%s: failed to set config!!\n",
875 card->name);
876 c4_reset(card);
877 return retval;
878 }
879 }
880
881 c4_send_init(card);
882
883 return 0;
884}
885
886
Adrian Bunk08e51532005-06-25 14:58:37 -0700887static void c4_reset_ctr(struct capi_ctr *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
889 avmcard *card = ((avmctrl_info *)(ctrl->driverdata))->card;
890 avmctrl_info *cinfo;
891 u_int i;
892 unsigned long flags;
893
894 spin_lock_irqsave(&card->lock, flags);
895
896 c4_reset(card);
897
898 spin_unlock_irqrestore(&card->lock, flags);
899
900 for (i=0; i < card->nr_controllers; i++) {
901 cinfo = &card->ctrlinfo[i];
902 memset(cinfo->version, 0, sizeof(cinfo->version));
903 capi_ctr_reseted(&cinfo->capi_ctrl);
904 }
905 card->nlogcontr = 0;
906}
907
908static void c4_remove(struct pci_dev *pdev)
909{
910 avmcard *card = pci_get_drvdata(pdev);
911 avmctrl_info *cinfo;
912 u_int i;
913
914 if (!card)
915 return;
916
917 c4_reset(card);
918
919 for (i=0; i < card->nr_controllers; i++) {
920 cinfo = &card->ctrlinfo[i];
921 detach_capi_ctr(&cinfo->capi_ctrl);
922 }
923
924 free_irq(card->irq, card);
925 iounmap(card->mbase);
926 release_region(card->port, AVMB1_PORTLEN);
927 avmcard_dma_free(card->dma);
928 pci_set_drvdata(pdev, NULL);
929 b1_free_card(card);
930}
931
932/* ------------------------------------------------------------- */
933
934
Adrian Bunk08e51532005-06-25 14:58:37 -0700935static void c4_register_appl(struct capi_ctr *ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 u16 appl,
937 capi_register_params *rp)
938{
939 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
940 avmcard *card = cinfo->card;
941 struct sk_buff *skb;
942 int want = rp->level3cnt;
943 unsigned long flags;
944 int nconn;
945 void *p;
946
947 if (ctrl->cnr == card->cardnr) {
948
949 if (want > 0) nconn = want;
950 else nconn = ctrl->profile.nbchannel * 4 * -want;
951 if (nconn == 0) nconn = ctrl->profile.nbchannel * 4;
952
953 skb = alloc_skb(23, GFP_ATOMIC);
954 if (!skb) {
955 printk(KERN_CRIT "%s: no memory, lost register appl.\n",
956 card->name);
957 return;
958 }
959 p = skb->data;
960 _put_byte(&p, 0);
961 _put_byte(&p, 0);
962 _put_byte(&p, SEND_REGISTER);
963 _put_word(&p, appl);
964 _put_word(&p, 1024 * (nconn+1));
965 _put_word(&p, nconn);
966 _put_word(&p, rp->datablkcnt);
967 _put_word(&p, rp->datablklen);
968 skb_put(skb, (u8 *)p - (u8 *)skb->data);
969
970 skb_queue_tail(&card->dma->send_queue, skb);
971
972 spin_lock_irqsave(&card->lock, flags);
973 c4_dispatch_tx(card);
974 spin_unlock_irqrestore(&card->lock, flags);
975 }
976}
977
978/* ------------------------------------------------------------- */
979
Adrian Bunk08e51532005-06-25 14:58:37 -0700980static void c4_release_appl(struct capi_ctr *ctrl, u16 appl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
982 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
983 avmcard *card = cinfo->card;
984 unsigned long flags;
985 struct sk_buff *skb;
986 void *p;
987
988 capilib_release_appl(&cinfo->ncci_head, appl);
989
990 if (ctrl->cnr == card->cardnr) {
991 skb = alloc_skb(7, GFP_ATOMIC);
992 if (!skb) {
993 printk(KERN_CRIT "%s: no memory, lost release appl.\n",
994 card->name);
995 return;
996 }
997 p = skb->data;
998 _put_byte(&p, 0);
999 _put_byte(&p, 0);
1000 _put_byte(&p, SEND_RELEASE);
1001 _put_word(&p, appl);
1002
1003 skb_put(skb, (u8 *)p - (u8 *)skb->data);
1004 skb_queue_tail(&card->dma->send_queue, skb);
1005 spin_lock_irqsave(&card->lock, flags);
1006 c4_dispatch_tx(card);
1007 spin_unlock_irqrestore(&card->lock, flags);
1008 }
1009}
1010
1011/* ------------------------------------------------------------- */
1012
1013
1014static u16 c4_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
1015{
1016 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
1017 avmcard *card = cinfo->card;
1018 u16 retval = CAPI_NOERROR;
1019 unsigned long flags;
1020
1021 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
1022 retval = capilib_data_b3_req(&cinfo->ncci_head,
1023 CAPIMSG_APPID(skb->data),
1024 CAPIMSG_NCCI(skb->data),
1025 CAPIMSG_MSGID(skb->data));
1026 }
1027 if (retval == CAPI_NOERROR) {
1028 skb_queue_tail(&card->dma->send_queue, skb);
1029 spin_lock_irqsave(&card->lock, flags);
1030 c4_dispatch_tx(card);
1031 spin_unlock_irqrestore(&card->lock, flags);
1032 }
1033 return retval;
1034}
1035
1036/* ------------------------------------------------------------- */
1037
1038static char *c4_procinfo(struct capi_ctr *ctrl)
1039{
1040 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
1041
1042 if (!cinfo)
1043 return "";
1044 sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx",
1045 cinfo->cardname[0] ? cinfo->cardname : "-",
1046 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
1047 cinfo->card ? cinfo->card->port : 0x0,
1048 cinfo->card ? cinfo->card->irq : 0,
1049 cinfo->card ? cinfo->card->membase : 0
1050 );
1051 return cinfo->infobuf;
1052}
1053
1054static int c4_read_proc(char *page, char **start, off_t off,
1055 int count, int *eof, struct capi_ctr *ctrl)
1056{
1057 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
1058 avmcard *card = cinfo->card;
1059 u8 flag;
1060 int len = 0;
1061 char *s;
1062
1063 len += sprintf(page+len, "%-16s %s\n", "name", card->name);
1064 len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port);
1065 len += sprintf(page+len, "%-16s %d\n", "irq", card->irq);
1066 len += sprintf(page+len, "%-16s 0x%lx\n", "membase", card->membase);
1067 switch (card->cardtype) {
1068 case avm_b1isa: s = "B1 ISA"; break;
1069 case avm_b1pci: s = "B1 PCI"; break;
1070 case avm_b1pcmcia: s = "B1 PCMCIA"; break;
1071 case avm_m1: s = "M1"; break;
1072 case avm_m2: s = "M2"; break;
1073 case avm_t1isa: s = "T1 ISA (HEMA)"; break;
1074 case avm_t1pci: s = "T1 PCI"; break;
1075 case avm_c4: s = "C4"; break;
1076 case avm_c2: s = "C2"; break;
1077 default: s = "???"; break;
1078 }
1079 len += sprintf(page+len, "%-16s %s\n", "type", s);
1080 if ((s = cinfo->version[VER_DRIVER]) != 0)
1081 len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);
1082 if ((s = cinfo->version[VER_CARDTYPE]) != 0)
1083 len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s);
1084 if ((s = cinfo->version[VER_SERIAL]) != 0)
1085 len += sprintf(page+len, "%-16s %s\n", "ver_serial", s);
1086
1087 if (card->cardtype != avm_m1) {
1088 flag = ((u8 *)(ctrl->profile.manu))[3];
1089 if (flag)
1090 len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n",
1091 "protocol",
1092 (flag & 0x01) ? " DSS1" : "",
1093 (flag & 0x02) ? " CT1" : "",
1094 (flag & 0x04) ? " VN3" : "",
1095 (flag & 0x08) ? " NI1" : "",
1096 (flag & 0x10) ? " AUSTEL" : "",
1097 (flag & 0x20) ? " ESS" : "",
1098 (flag & 0x40) ? " 1TR6" : ""
1099 );
1100 }
1101 if (card->cardtype != avm_m1) {
1102 flag = ((u8 *)(ctrl->profile.manu))[5];
1103 if (flag)
1104 len += sprintf(page+len, "%-16s%s%s%s%s\n",
1105 "linetype",
1106 (flag & 0x01) ? " point to point" : "",
1107 (flag & 0x02) ? " point to multipoint" : "",
1108 (flag & 0x08) ? " leased line without D-channel" : "",
1109 (flag & 0x04) ? " leased line with D-channel" : ""
1110 );
1111 }
1112 len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname);
1113
1114 if (off+count >= len)
1115 *eof = 1;
1116 if (len < off)
1117 return 0;
1118 *start = page + off;
1119 return ((count < len-off) ? count : len-off);
1120}
1121
1122/* ------------------------------------------------------------- */
1123
1124static int c4_add_card(struct capicardparams *p, struct pci_dev *dev,
1125 int nr_controllers)
1126{
1127 avmcard *card;
1128 avmctrl_info *cinfo;
1129 int retval;
1130 int i;
1131
1132 card = b1_alloc_card(nr_controllers);
1133 if (!card) {
1134 printk(KERN_WARNING "c4: no memory.\n");
1135 retval = -ENOMEM;
1136 goto err;
1137 }
1138 card->dma = avmcard_dma_alloc("c4", dev, 2048+128, 2048+128);
1139 if (!card->dma) {
1140 printk(KERN_WARNING "c4: no memory.\n");
1141 retval = -ENOMEM;
1142 goto err_free;
1143 }
1144
1145 sprintf(card->name, "c%d-%x", nr_controllers, p->port);
1146 card->port = p->port;
1147 card->irq = p->irq;
1148 card->membase = p->membase;
1149 card->cardtype = (nr_controllers == 4) ? avm_c4 : avm_c2;
1150
1151 if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
1152 printk(KERN_WARNING "c4: ports 0x%03x-0x%03x in use.\n",
1153 card->port, card->port + AVMB1_PORTLEN);
1154 retval = -EBUSY;
1155 goto err_free_dma;
1156 }
1157
1158 card->mbase = ioremap(card->membase, 128);
1159 if (card->mbase == 0) {
1160 printk(KERN_NOTICE "c4: can't remap memory at 0x%lx\n",
1161 card->membase);
1162 retval = -EIO;
1163 goto err_release_region;
1164 }
1165
1166 retval = c4_detect(card);
1167 if (retval != 0) {
1168 printk(KERN_NOTICE "c4: NO card at 0x%x error(%d)\n",
1169 card->port, retval);
1170 retval = -EIO;
1171 goto err_unmap;
1172 }
1173 c4_reset(card);
1174
Thomas Gleixner9ba02be2006-07-01 19:29:36 -07001175 retval = request_irq(card->irq, c4_interrupt, IRQF_SHARED, card->name, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (retval) {
1177 printk(KERN_ERR "c4: unable to get IRQ %d.\n",card->irq);
1178 retval = -EBUSY;
1179 goto err_unmap;
1180 }
1181
1182 for (i=0; i < nr_controllers ; i++) {
1183 cinfo = &card->ctrlinfo[i];
1184 cinfo->capi_ctrl.owner = THIS_MODULE;
1185 cinfo->capi_ctrl.driver_name = "c4";
1186 cinfo->capi_ctrl.driverdata = cinfo;
1187 cinfo->capi_ctrl.register_appl = c4_register_appl;
1188 cinfo->capi_ctrl.release_appl = c4_release_appl;
1189 cinfo->capi_ctrl.send_message = c4_send_message;
1190 cinfo->capi_ctrl.load_firmware = c4_load_firmware;
1191 cinfo->capi_ctrl.reset_ctr = c4_reset_ctr;
1192 cinfo->capi_ctrl.procinfo = c4_procinfo;
1193 cinfo->capi_ctrl.ctr_read_proc = c4_read_proc;
1194 strcpy(cinfo->capi_ctrl.name, card->name);
1195
1196 retval = attach_capi_ctr(&cinfo->capi_ctrl);
1197 if (retval) {
1198 printk(KERN_ERR "c4: attach controller failed (%d).\n", i);
1199 for (i--; i >= 0; i--) {
1200 cinfo = &card->ctrlinfo[i];
1201 detach_capi_ctr(&cinfo->capi_ctrl);
1202 }
1203 goto err_free_irq;
1204 }
1205 if (i == 0)
1206 card->cardnr = cinfo->capi_ctrl.cnr;
1207 }
1208
1209 printk(KERN_INFO "c4: AVM C%d at i/o %#x, irq %d, mem %#lx\n",
1210 nr_controllers, card->port, card->irq,
1211 card->membase);
1212 pci_set_drvdata(dev, card);
1213 return 0;
1214
1215 err_free_irq:
1216 free_irq(card->irq, card);
1217 err_unmap:
1218 iounmap(card->mbase);
1219 err_release_region:
1220 release_region(card->port, AVMB1_PORTLEN);
1221 err_free_dma:
1222 avmcard_dma_free(card->dma);
1223 err_free:
1224 b1_free_card(card);
1225 err:
1226 return retval;
1227}
1228
1229/* ------------------------------------------------------------- */
1230
1231static int __devinit c4_probe(struct pci_dev *dev,
1232 const struct pci_device_id *ent)
1233{
1234 int nr = ent->driver_data;
1235 int retval = 0;
1236 struct capicardparams param;
1237
1238 if (pci_enable_device(dev) < 0) {
1239 printk(KERN_ERR "c4: failed to enable AVM-C%d\n", nr);
1240 return -ENODEV;
1241 }
1242 pci_set_master(dev);
1243
1244 param.port = pci_resource_start(dev, 1);
1245 param.irq = dev->irq;
1246 param.membase = pci_resource_start(dev, 0);
1247
1248 printk(KERN_INFO "c4: PCI BIOS reports AVM-C%d at i/o %#x, irq %d, mem %#x\n",
1249 nr, param.port, param.irq, param.membase);
1250
1251 retval = c4_add_card(&param, dev, nr);
1252 if (retval != 0) {
1253 printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n",
1254 nr, param.port, param.irq, param.membase);
1255 return -ENODEV;
1256 }
1257 return 0;
1258}
1259
1260static struct pci_driver c4_pci_driver = {
1261 .name = "c4",
1262 .id_table = c4_pci_tbl,
1263 .probe = c4_probe,
1264 .remove = c4_remove,
1265};
1266
1267static struct capi_driver capi_driver_c2 = {
1268 .name = "c2",
1269 .revision = "1.0",
1270};
1271
1272static struct capi_driver capi_driver_c4 = {
1273 .name = "c4",
1274 .revision = "1.0",
1275};
1276
1277static int __init c4_init(void)
1278{
1279 char *p;
1280 char rev[32];
1281 int err;
1282
1283 if ((p = strchr(revision, ':')) != 0 && p[1]) {
1284 strlcpy(rev, p + 2, 32);
1285 if ((p = strchr(rev, '$')) != 0 && p > rev)
1286 *(p-1) = 0;
1287 } else
1288 strcpy(rev, "1.0");
1289
1290 err = pci_register_driver(&c4_pci_driver);
1291 if (!err) {
1292 strlcpy(capi_driver_c2.revision, rev, 32);
1293 register_capi_driver(&capi_driver_c2);
1294 strlcpy(capi_driver_c4.revision, rev, 32);
1295 register_capi_driver(&capi_driver_c4);
1296 printk(KERN_INFO "c4: revision %s\n", rev);
1297 }
1298 return err;
1299}
1300
1301static void __exit c4_exit(void)
1302{
1303 unregister_capi_driver(&capi_driver_c2);
1304 unregister_capi_driver(&capi_driver_c4);
1305 pci_unregister_driver(&c4_pci_driver);
1306}
1307
1308module_init(c4_init);
1309module_exit(c4_exit);