aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/hardware/avm/b1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/hardware/avm/b1.c')
-rw-r--r--drivers/isdn/hardware/avm/b1.c814
1 files changed, 814 insertions, 0 deletions
diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
new file mode 100644
index 000000000000..0c7061d55027
--- /dev/null
+++ b/drivers/isdn/hardware/avm/b1.c
@@ -0,0 +1,814 @@
1/* $Id: b1.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
2 *
3 * Common module for AVM B1 cards.
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
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/pci.h>
15#include <linux/skbuff.h>
16#include <linux/delay.h>
17#include <linux/mm.h>
18#include <linux/interrupt.h>
19#include <linux/ioport.h>
20#include <linux/capi.h>
21#include <linux/kernelcapi.h>
22#include <asm/io.h>
23#include <linux/init.h>
24#include <asm/uaccess.h>
25#include <linux/netdevice.h>
26#include <linux/isdn/capilli.h>
27#include "avmcard.h"
28#include <linux/isdn/capicmd.h>
29#include <linux/isdn/capiutil.h>
30
31static char *revision = "$Revision: 1.1.2.2 $";
32
33/* ------------------------------------------------------------- */
34
35MODULE_DESCRIPTION("CAPI4Linux: Common support for active AVM cards");
36MODULE_AUTHOR("Carsten Paeth");
37MODULE_LICENSE("GPL");
38
39/* ------------------------------------------------------------- */
40
41int b1_irq_table[16] =
42{0,
43 0,
44 0,
45 192, /* irq 3 */
46 32, /* irq 4 */
47 160, /* irq 5 */
48 96, /* irq 6 */
49 224, /* irq 7 */
50 0,
51 64, /* irq 9 */
52 80, /* irq 10 */
53 208, /* irq 11 */
54 48, /* irq 12 */
55 0,
56 0,
57 112, /* irq 15 */
58};
59
60/* ------------------------------------------------------------- */
61
62avmcard *b1_alloc_card(int nr_controllers)
63{
64 avmcard *card;
65 avmctrl_info *cinfo;
66 int i;
67
68 card = kmalloc(sizeof(*card), GFP_KERNEL);
69 if (!card)
70 return NULL;
71
72 memset(card, 0, sizeof(*card));
73
74 cinfo = kmalloc(sizeof(*cinfo) * nr_controllers, GFP_KERNEL);
75 if (!cinfo) {
76 kfree(card);
77 return NULL;
78 }
79 memset(cinfo, 0, sizeof(*cinfo) * nr_controllers);
80
81 card->ctrlinfo = cinfo;
82 for (i = 0; i < nr_controllers; i++) {
83 INIT_LIST_HEAD(&cinfo[i].ncci_head);
84 cinfo[i].card = card;
85 }
86 spin_lock_init(&card->lock);
87 card->nr_controllers = nr_controllers;
88
89 return card;
90}
91
92/* ------------------------------------------------------------- */
93
94void b1_free_card(avmcard *card)
95{
96 kfree(card->ctrlinfo);
97 kfree(card);
98}
99
100/* ------------------------------------------------------------- */
101
102int b1_detect(unsigned int base, enum avmcardtype cardtype)
103{
104 int onoff, i;
105
106 /*
107 * Statusregister 0000 00xx
108 */
109 if ((inb(base + B1_INSTAT) & 0xfc)
110 || (inb(base + B1_OUTSTAT) & 0xfc))
111 return 1;
112 /*
113 * Statusregister 0000 001x
114 */
115 b1outp(base, B1_INSTAT, 0x2); /* enable irq */
116 /* b1outp(base, B1_OUTSTAT, 0x2); */
117 if ((inb(base + B1_INSTAT) & 0xfe) != 0x2
118 /* || (inb(base + B1_OUTSTAT) & 0xfe) != 0x2 */)
119 return 2;
120 /*
121 * Statusregister 0000 000x
122 */
123 b1outp(base, B1_INSTAT, 0x0); /* disable irq */
124 b1outp(base, B1_OUTSTAT, 0x0);
125 if ((inb(base + B1_INSTAT) & 0xfe)
126 || (inb(base + B1_OUTSTAT) & 0xfe))
127 return 3;
128
129 for (onoff = !0, i= 0; i < 10 ; i++) {
130 b1_set_test_bit(base, cardtype, onoff);
131 if (b1_get_test_bit(base, cardtype) != onoff)
132 return 4;
133 onoff = !onoff;
134 }
135
136 if (cardtype == avm_m1)
137 return 0;
138
139 if ((b1_rd_reg(base, B1_STAT1(cardtype)) & 0x0f) != 0x01)
140 return 5;
141
142 return 0;
143}
144
145void b1_getrevision(avmcard *card)
146{
147 card->class = inb(card->port + B1_ANALYSE);
148 card->revision = inb(card->port + B1_REVISION);
149}
150
151#define FWBUF_SIZE 256
152int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
153{
154 unsigned char buf[FWBUF_SIZE];
155 unsigned char *dp;
156 int i, left;
157 unsigned int base = card->port;
158
159 dp = t4file->data;
160 left = t4file->len;
161 while (left > FWBUF_SIZE) {
162 if (t4file->user) {
163 if (copy_from_user(buf, dp, FWBUF_SIZE))
164 return -EFAULT;
165 } else {
166 memcpy(buf, dp, FWBUF_SIZE);
167 }
168 for (i = 0; i < FWBUF_SIZE; i++)
169 if (b1_save_put_byte(base, buf[i]) < 0) {
170 printk(KERN_ERR "%s: corrupted firmware file ?\n",
171 card->name);
172 return -EIO;
173 }
174 left -= FWBUF_SIZE;
175 dp += FWBUF_SIZE;
176 }
177 if (left) {
178 if (t4file->user) {
179 if (copy_from_user(buf, dp, left))
180 return -EFAULT;
181 } else {
182 memcpy(buf, dp, left);
183 }
184 for (i = 0; i < left; i++)
185 if (b1_save_put_byte(base, buf[i]) < 0) {
186 printk(KERN_ERR "%s: corrupted firmware file ?\n",
187 card->name);
188 return -EIO;
189 }
190 }
191 return 0;
192}
193
194int b1_load_config(avmcard *card, capiloaddatapart * config)
195{
196 unsigned char buf[FWBUF_SIZE];
197 unsigned char *dp;
198 unsigned int base = card->port;
199 int i, j, left;
200
201 dp = config->data;
202 left = config->len;
203 if (left) {
204 b1_put_byte(base, SEND_CONFIG);
205 b1_put_word(base, 1);
206 b1_put_byte(base, SEND_CONFIG);
207 b1_put_word(base, left);
208 }
209 while (left > FWBUF_SIZE) {
210 if (config->user) {
211 if (copy_from_user(buf, dp, FWBUF_SIZE))
212 return -EFAULT;
213 } else {
214 memcpy(buf, dp, FWBUF_SIZE);
215 }
216 for (i = 0; i < FWBUF_SIZE; ) {
217 b1_put_byte(base, SEND_CONFIG);
218 for (j=0; j < 4; j++) {
219 b1_put_byte(base, buf[i++]);
220 }
221 }
222 left -= FWBUF_SIZE;
223 dp += FWBUF_SIZE;
224 }
225 if (left) {
226 if (config->user) {
227 if (copy_from_user(buf, dp, left))
228 return -EFAULT;
229 } else {
230 memcpy(buf, dp, left);
231 }
232 for (i = 0; i < left; ) {
233 b1_put_byte(base, SEND_CONFIG);
234 for (j=0; j < 4; j++) {
235 if (i < left)
236 b1_put_byte(base, buf[i++]);
237 else
238 b1_put_byte(base, 0);
239 }
240 }
241 }
242 return 0;
243}
244
245int b1_loaded(avmcard *card)
246{
247 unsigned int base = card->port;
248 unsigned long stop;
249 unsigned char ans;
250 unsigned long tout = 2;
251
252 for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) {
253 if (b1_tx_empty(base))
254 break;
255 }
256 if (!b1_tx_empty(base)) {
257 printk(KERN_ERR "%s: b1_loaded: tx err, corrupted t4 file ?\n",
258 card->name);
259 return 0;
260 }
261 b1_put_byte(base, SEND_POLL);
262 for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) {
263 if (b1_rx_full(base)) {
264 if ((ans = b1_get_byte(base)) == RECEIVE_POLL) {
265 return 1;
266 }
267 printk(KERN_ERR "%s: b1_loaded: got 0x%x, firmware not running\n",
268 card->name, ans);
269 return 0;
270 }
271 }
272 printk(KERN_ERR "%s: b1_loaded: firmware not running\n", card->name);
273 return 0;
274}
275
276/* ------------------------------------------------------------- */
277
278int b1_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
279{
280 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
281 avmcard *card = cinfo->card;
282 unsigned int port = card->port;
283 unsigned long flags;
284 int retval;
285
286 b1_reset(port);
287
288 if ((retval = b1_load_t4file(card, &data->firmware))) {
289 b1_reset(port);
290 printk(KERN_ERR "%s: failed to load t4file!!\n",
291 card->name);
292 return retval;
293 }
294
295 b1_disable_irq(port);
296
297 if (data->configuration.len > 0 && data->configuration.data) {
298 if ((retval = b1_load_config(card, &data->configuration))) {
299 b1_reset(port);
300 printk(KERN_ERR "%s: failed to load config!!\n",
301 card->name);
302 return retval;
303 }
304 }
305
306 if (!b1_loaded(card)) {
307 printk(KERN_ERR "%s: failed to load t4file.\n", card->name);
308 return -EIO;
309 }
310
311 spin_lock_irqsave(&card->lock, flags);
312 b1_setinterrupt(port, card->irq, card->cardtype);
313 b1_put_byte(port, SEND_INIT);
314 b1_put_word(port, CAPI_MAXAPPL);
315 b1_put_word(port, AVM_NCCI_PER_CHANNEL*2);
316 b1_put_word(port, ctrl->cnr - 1);
317 spin_unlock_irqrestore(&card->lock, flags);
318
319 return 0;
320}
321
322void b1_reset_ctr(struct capi_ctr *ctrl)
323{
324 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
325 avmcard *card = cinfo->card;
326 unsigned int port = card->port;
327
328 b1_reset(port);
329 b1_reset(port);
330
331 memset(cinfo->version, 0, sizeof(cinfo->version));
332 capilib_release(&cinfo->ncci_head);
333 capi_ctr_reseted(ctrl);
334}
335
336void b1_register_appl(struct capi_ctr *ctrl,
337 u16 appl,
338 capi_register_params *rp)
339{
340 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
341 avmcard *card = cinfo->card;
342 unsigned int port = card->port;
343 unsigned long flags;
344 int nconn, want = rp->level3cnt;
345
346 if (want > 0) nconn = want;
347 else nconn = ctrl->profile.nbchannel * -want;
348 if (nconn == 0) nconn = ctrl->profile.nbchannel;
349
350 spin_lock_irqsave(&card->lock, flags);
351 b1_put_byte(port, SEND_REGISTER);
352 b1_put_word(port, appl);
353 b1_put_word(port, 1024 * (nconn+1));
354 b1_put_word(port, nconn);
355 b1_put_word(port, rp->datablkcnt);
356 b1_put_word(port, rp->datablklen);
357 spin_unlock_irqrestore(&card->lock, flags);
358}
359
360void b1_release_appl(struct capi_ctr *ctrl, u16 appl)
361{
362 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
363 avmcard *card = cinfo->card;
364 unsigned int port = card->port;
365 unsigned long flags;
366
367 capilib_release_appl(&cinfo->ncci_head, appl);
368
369 spin_lock_irqsave(&card->lock, flags);
370 b1_put_byte(port, SEND_RELEASE);
371 b1_put_word(port, appl);
372 spin_unlock_irqrestore(&card->lock, flags);
373}
374
375u16 b1_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
376{
377 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
378 avmcard *card = cinfo->card;
379 unsigned int port = card->port;
380 unsigned long flags;
381 u16 len = CAPIMSG_LEN(skb->data);
382 u8 cmd = CAPIMSG_COMMAND(skb->data);
383 u8 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
384 u16 dlen, retval;
385
386 if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
387 retval = capilib_data_b3_req(&cinfo->ncci_head,
388 CAPIMSG_APPID(skb->data),
389 CAPIMSG_NCCI(skb->data),
390 CAPIMSG_MSGID(skb->data));
391 if (retval != CAPI_NOERROR)
392 return retval;
393
394 dlen = CAPIMSG_DATALEN(skb->data);
395
396 spin_lock_irqsave(&card->lock, flags);
397 b1_put_byte(port, SEND_DATA_B3_REQ);
398 b1_put_slice(port, skb->data, len);
399 b1_put_slice(port, skb->data + len, dlen);
400 spin_unlock_irqrestore(&card->lock, flags);
401 } else {
402 spin_lock_irqsave(&card->lock, flags);
403 b1_put_byte(port, SEND_MESSAGE);
404 b1_put_slice(port, skb->data, len);
405 spin_unlock_irqrestore(&card->lock, flags);
406 }
407
408 dev_kfree_skb_any(skb);
409 return CAPI_NOERROR;
410}
411
412/* ------------------------------------------------------------- */
413
414void b1_parse_version(avmctrl_info *cinfo)
415{
416 struct capi_ctr *ctrl = &cinfo->capi_ctrl;
417 avmcard *card = cinfo->card;
418 capi_profile *profp;
419 u8 *dversion;
420 u8 flag;
421 int i, j;
422
423 for (j = 0; j < AVM_MAXVERSION; j++)
424 cinfo->version[j] = "\0\0" + 1;
425 for (i = 0, j = 0;
426 j < AVM_MAXVERSION && i < cinfo->versionlen;
427 j++, i += cinfo->versionbuf[i] + 1)
428 cinfo->version[j] = &cinfo->versionbuf[i + 1];
429
430 strlcpy(ctrl->serial, cinfo->version[VER_SERIAL], sizeof(ctrl->serial));
431 memcpy(&ctrl->profile, cinfo->version[VER_PROFILE],sizeof(capi_profile));
432 strlcpy(ctrl->manu, "AVM GmbH", sizeof(ctrl->manu));
433 dversion = cinfo->version[VER_DRIVER];
434 ctrl->version.majorversion = 2;
435 ctrl->version.minorversion = 0;
436 ctrl->version.majormanuversion = (((dversion[0] - '0') & 0xf) << 4);
437 ctrl->version.majormanuversion |= ((dversion[2] - '0') & 0xf);
438 ctrl->version.minormanuversion = (dversion[3] - '0') << 4;
439 ctrl->version.minormanuversion |=
440 (dversion[5] - '0') * 10 + ((dversion[6] - '0') & 0xf);
441
442 profp = &ctrl->profile;
443
444 flag = ((u8 *)(profp->manu))[1];
445 switch (flag) {
446 case 0: if (cinfo->version[VER_CARDTYPE])
447 strcpy(cinfo->cardname, cinfo->version[VER_CARDTYPE]);
448 else strcpy(cinfo->cardname, "B1");
449 break;
450 case 3: strcpy(cinfo->cardname,"PCMCIA B"); break;
451 case 4: strcpy(cinfo->cardname,"PCMCIA M1"); break;
452 case 5: strcpy(cinfo->cardname,"PCMCIA M2"); break;
453 case 6: strcpy(cinfo->cardname,"B1 V3.0"); break;
454 case 7: strcpy(cinfo->cardname,"B1 PCI"); break;
455 default: sprintf(cinfo->cardname, "AVM?%u", (unsigned int)flag); break;
456 }
457 printk(KERN_NOTICE "%s: card %d \"%s\" ready.\n",
458 card->name, ctrl->cnr, cinfo->cardname);
459
460 flag = ((u8 *)(profp->manu))[3];
461 if (flag)
462 printk(KERN_NOTICE "%s: card %d Protocol:%s%s%s%s%s%s%s\n",
463 card->name,
464 ctrl->cnr,
465 (flag & 0x01) ? " DSS1" : "",
466 (flag & 0x02) ? " CT1" : "",
467 (flag & 0x04) ? " VN3" : "",
468 (flag & 0x08) ? " NI1" : "",
469 (flag & 0x10) ? " AUSTEL" : "",
470 (flag & 0x20) ? " ESS" : "",
471 (flag & 0x40) ? " 1TR6" : ""
472 );
473
474 flag = ((u8 *)(profp->manu))[5];
475 if (flag)
476 printk(KERN_NOTICE "%s: card %d Linetype:%s%s%s%s\n",
477 card->name,
478 ctrl->cnr,
479 (flag & 0x01) ? " point to point" : "",
480 (flag & 0x02) ? " point to multipoint" : "",
481 (flag & 0x08) ? " leased line without D-channel" : "",
482 (flag & 0x04) ? " leased line with D-channel" : ""
483 );
484}
485
486/* ------------------------------------------------------------- */
487
488irqreturn_t b1_interrupt(int interrupt, void *devptr, struct pt_regs *regs)
489{
490 avmcard *card = devptr;
491 avmctrl_info *cinfo = &card->ctrlinfo[0];
492 struct capi_ctr *ctrl = &cinfo->capi_ctrl;
493 unsigned char b1cmd;
494 struct sk_buff *skb;
495
496 unsigned ApplId;
497 unsigned MsgLen;
498 unsigned DataB3Len;
499 unsigned NCCI;
500 unsigned WindowSize;
501 unsigned long flags;
502
503 spin_lock_irqsave(&card->lock, flags);
504
505 if (!b1_rx_full(card->port)) {
506 spin_unlock_irqrestore(&card->lock, flags);
507 return IRQ_NONE;
508 }
509
510 b1cmd = b1_get_byte(card->port);
511
512 switch (b1cmd) {
513
514 case RECEIVE_DATA_B3_IND:
515
516 ApplId = (unsigned) b1_get_word(card->port);
517 MsgLen = b1_get_slice(card->port, card->msgbuf);
518 DataB3Len = b1_get_slice(card->port, card->databuf);
519 spin_unlock_irqrestore(&card->lock, flags);
520
521 if (MsgLen < 30) { /* not CAPI 64Bit */
522 memset(card->msgbuf+MsgLen, 0, 30-MsgLen);
523 MsgLen = 30;
524 CAPIMSG_SETLEN(card->msgbuf, 30);
525 }
526 if (!(skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC))) {
527 printk(KERN_ERR "%s: incoming packet dropped\n",
528 card->name);
529 } else {
530 memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
531 memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len);
532 capi_ctr_handle_message(ctrl, ApplId, skb);
533 }
534 break;
535
536 case RECEIVE_MESSAGE:
537
538 ApplId = (unsigned) b1_get_word(card->port);
539 MsgLen = b1_get_slice(card->port, card->msgbuf);
540 spin_unlock_irqrestore(&card->lock, flags);
541 if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) {
542 printk(KERN_ERR "%s: incoming packet dropped\n",
543 card->name);
544 } else {
545 memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
546 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF)
547 capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
548 CAPIMSG_NCCI(skb->data),
549 CAPIMSG_MSGID(skb->data));
550
551 capi_ctr_handle_message(ctrl, ApplId, skb);
552 }
553 break;
554
555 case RECEIVE_NEW_NCCI:
556
557 ApplId = b1_get_word(card->port);
558 NCCI = b1_get_word(card->port);
559 WindowSize = b1_get_word(card->port);
560 spin_unlock_irqrestore(&card->lock, flags);
561
562 capilib_new_ncci(&cinfo->ncci_head, ApplId, NCCI, WindowSize);
563
564 break;
565
566 case RECEIVE_FREE_NCCI:
567
568 ApplId = b1_get_word(card->port);
569 NCCI = b1_get_word(card->port);
570 spin_unlock_irqrestore(&card->lock, flags);
571
572 if (NCCI != 0xffffffff)
573 capilib_free_ncci(&cinfo->ncci_head, ApplId, NCCI);
574
575 break;
576
577 case RECEIVE_START:
578 /* b1_put_byte(card->port, SEND_POLLACK); */
579 spin_unlock_irqrestore(&card->lock, flags);
580 capi_ctr_resume_output(ctrl);
581 break;
582
583 case RECEIVE_STOP:
584 spin_unlock_irqrestore(&card->lock, flags);
585 capi_ctr_suspend_output(ctrl);
586 break;
587
588 case RECEIVE_INIT:
589
590 cinfo->versionlen = b1_get_slice(card->port, cinfo->versionbuf);
591 spin_unlock_irqrestore(&card->lock, flags);
592 b1_parse_version(cinfo);
593 printk(KERN_INFO "%s: %s-card (%s) now active\n",
594 card->name,
595 cinfo->version[VER_CARDTYPE],
596 cinfo->version[VER_DRIVER]);
597 capi_ctr_ready(ctrl);
598 break;
599
600 case RECEIVE_TASK_READY:
601 ApplId = (unsigned) b1_get_word(card->port);
602 MsgLen = b1_get_slice(card->port, card->msgbuf);
603 spin_unlock_irqrestore(&card->lock, flags);
604 card->msgbuf[MsgLen] = 0;
605 while ( MsgLen > 0
606 && ( card->msgbuf[MsgLen-1] == '\n'
607 || card->msgbuf[MsgLen-1] == '\r')) {
608 card->msgbuf[MsgLen-1] = 0;
609 MsgLen--;
610 }
611 printk(KERN_INFO "%s: task %d \"%s\" ready.\n",
612 card->name, ApplId, card->msgbuf);
613 break;
614
615 case RECEIVE_DEBUGMSG:
616 MsgLen = b1_get_slice(card->port, card->msgbuf);
617 spin_unlock_irqrestore(&card->lock, flags);
618 card->msgbuf[MsgLen] = 0;
619 while ( MsgLen > 0
620 && ( card->msgbuf[MsgLen-1] == '\n'
621 || card->msgbuf[MsgLen-1] == '\r')) {
622 card->msgbuf[MsgLen-1] = 0;
623 MsgLen--;
624 }
625 printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf);
626 break;
627
628 case 0xff:
629 spin_unlock_irqrestore(&card->lock, flags);
630 printk(KERN_ERR "%s: card removed ?\n", card->name);
631 return IRQ_NONE;
632 default:
633 spin_unlock_irqrestore(&card->lock, flags);
634 printk(KERN_ERR "%s: b1_interrupt: 0x%x ???\n",
635 card->name, b1cmd);
636 return IRQ_HANDLED;
637 }
638 return IRQ_HANDLED;
639}
640
641/* ------------------------------------------------------------- */
642int b1ctl_read_proc(char *page, char **start, off_t off,
643 int count, int *eof, struct capi_ctr *ctrl)
644{
645 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
646 avmcard *card = cinfo->card;
647 u8 flag;
648 int len = 0;
649 char *s;
650
651 len += sprintf(page+len, "%-16s %s\n", "name", card->name);
652 len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port);
653 len += sprintf(page+len, "%-16s %d\n", "irq", card->irq);
654 switch (card->cardtype) {
655 case avm_b1isa: s = "B1 ISA"; break;
656 case avm_b1pci: s = "B1 PCI"; break;
657 case avm_b1pcmcia: s = "B1 PCMCIA"; break;
658 case avm_m1: s = "M1"; break;
659 case avm_m2: s = "M2"; break;
660 case avm_t1isa: s = "T1 ISA (HEMA)"; break;
661 case avm_t1pci: s = "T1 PCI"; break;
662 case avm_c4: s = "C4"; break;
663 case avm_c2: s = "C2"; break;
664 default: s = "???"; break;
665 }
666 len += sprintf(page+len, "%-16s %s\n", "type", s);
667 if (card->cardtype == avm_t1isa)
668 len += sprintf(page+len, "%-16s %d\n", "cardnr", card->cardnr);
669 if ((s = cinfo->version[VER_DRIVER]) != 0)
670 len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);
671 if ((s = cinfo->version[VER_CARDTYPE]) != 0)
672 len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s);
673 if ((s = cinfo->version[VER_SERIAL]) != 0)
674 len += sprintf(page+len, "%-16s %s\n", "ver_serial", s);
675
676 if (card->cardtype != avm_m1) {
677 flag = ((u8 *)(ctrl->profile.manu))[3];
678 if (flag)
679 len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n",
680 "protocol",
681 (flag & 0x01) ? " DSS1" : "",
682 (flag & 0x02) ? " CT1" : "",
683 (flag & 0x04) ? " VN3" : "",
684 (flag & 0x08) ? " NI1" : "",
685 (flag & 0x10) ? " AUSTEL" : "",
686 (flag & 0x20) ? " ESS" : "",
687 (flag & 0x40) ? " 1TR6" : ""
688 );
689 }
690 if (card->cardtype != avm_m1) {
691 flag = ((u8 *)(ctrl->profile.manu))[5];
692 if (flag)
693 len += sprintf(page+len, "%-16s%s%s%s%s\n",
694 "linetype",
695 (flag & 0x01) ? " point to point" : "",
696 (flag & 0x02) ? " point to multipoint" : "",
697 (flag & 0x08) ? " leased line without D-channel" : "",
698 (flag & 0x04) ? " leased line with D-channel" : ""
699 );
700 }
701 len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname);
702
703 if (off+count >= len)
704 *eof = 1;
705 if (len < off)
706 return 0;
707 *start = page + off;
708 return ((count < len-off) ? count : len-off);
709}
710
711/* ------------------------------------------------------------- */
712
713#ifdef CONFIG_PCI
714
715avmcard_dmainfo *
716avmcard_dma_alloc(char *name, struct pci_dev *pdev, long rsize, long ssize)
717{
718 avmcard_dmainfo *p;
719 void *buf;
720
721 p = kmalloc(sizeof(avmcard_dmainfo), GFP_KERNEL);
722 if (!p) {
723 printk(KERN_WARNING "%s: no memory.\n", name);
724 goto err;
725 }
726 memset(p, 0, sizeof(avmcard_dmainfo));
727
728 p->recvbuf.size = rsize;
729 buf = pci_alloc_consistent(pdev, rsize, &p->recvbuf.dmaaddr);
730 if (!buf) {
731 printk(KERN_WARNING "%s: allocation of receive dma buffer failed.\n", name);
732 goto err_kfree;
733 }
734 p->recvbuf.dmabuf = buf;
735
736 p->sendbuf.size = ssize;
737 buf = pci_alloc_consistent(pdev, ssize, &p->sendbuf.dmaaddr);
738 if (!buf) {
739 printk(KERN_WARNING "%s: allocation of send dma buffer failed.\n", name);
740 goto err_free_consistent;
741 }
742
743 p->sendbuf.dmabuf = buf;
744 skb_queue_head_init(&p->send_queue);
745
746 return p;
747
748 err_free_consistent:
749 pci_free_consistent(p->pcidev, p->recvbuf.size,
750 p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
751 err_kfree:
752 kfree(p);
753 err:
754 return NULL;
755}
756
757void avmcard_dma_free(avmcard_dmainfo *p)
758{
759 pci_free_consistent(p->pcidev, p->recvbuf.size,
760 p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
761 pci_free_consistent(p->pcidev, p->sendbuf.size,
762 p->sendbuf.dmabuf, p->sendbuf.dmaaddr);
763 skb_queue_purge(&p->send_queue);
764 kfree(p);
765}
766
767EXPORT_SYMBOL(avmcard_dma_alloc);
768EXPORT_SYMBOL(avmcard_dma_free);
769
770#endif
771
772EXPORT_SYMBOL(b1_irq_table);
773
774EXPORT_SYMBOL(b1_alloc_card);
775EXPORT_SYMBOL(b1_free_card);
776EXPORT_SYMBOL(b1_detect);
777EXPORT_SYMBOL(b1_getrevision);
778EXPORT_SYMBOL(b1_load_t4file);
779EXPORT_SYMBOL(b1_load_config);
780EXPORT_SYMBOL(b1_loaded);
781EXPORT_SYMBOL(b1_load_firmware);
782EXPORT_SYMBOL(b1_reset_ctr);
783EXPORT_SYMBOL(b1_register_appl);
784EXPORT_SYMBOL(b1_release_appl);
785EXPORT_SYMBOL(b1_send_message);
786
787EXPORT_SYMBOL(b1_parse_version);
788EXPORT_SYMBOL(b1_interrupt);
789
790EXPORT_SYMBOL(b1ctl_read_proc);
791
792static int __init b1_init(void)
793{
794 char *p;
795 char rev[32];
796
797 if ((p = strchr(revision, ':')) != 0 && p[1]) {
798 strlcpy(rev, p + 2, 32);
799 if ((p = strchr(rev, '$')) != 0 && p > rev)
800 *(p-1) = 0;
801 } else
802 strcpy(rev, "1.0");
803
804 printk(KERN_INFO "b1: revision %s\n", rev);
805
806 return 0;
807}
808
809static void __exit b1_exit(void)
810{
811}
812
813module_init(b1_init);
814module_exit(b1_exit);