linux/drivers/staging/isdn/avm/b1.c
<<
>>
Prefs
   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/proc_fs.h>
  16#include <linux/seq_file.h>
  17#include <linux/skbuff.h>
  18#include <linux/delay.h>
  19#include <linux/mm.h>
  20#include <linux/interrupt.h>
  21#include <linux/ioport.h>
  22#include <linux/capi.h>
  23#include <linux/kernelcapi.h>
  24#include <linux/slab.h>
  25#include <asm/io.h>
  26#include <linux/init.h>
  27#include <linux/uaccess.h>
  28#include <linux/netdevice.h>
  29#include <linux/isdn/capilli.h>
  30#include "avmcard.h"
  31#include <linux/isdn/capicmd.h>
  32#include <linux/isdn/capiutil.h>
  33
  34static char *revision = "$Revision: 1.1.2.2 $";
  35
  36/* ------------------------------------------------------------- */
  37
  38MODULE_DESCRIPTION("CAPI4Linux: Common support for active AVM cards");
  39MODULE_AUTHOR("Carsten Paeth");
  40MODULE_LICENSE("GPL");
  41
  42/* ------------------------------------------------------------- */
  43
  44int b1_irq_table[16] =
  45{0,
  46 0,
  47 0,
  48 192,                           /* irq 3 */
  49 32,                            /* irq 4 */
  50 160,                           /* irq 5 */
  51 96,                            /* irq 6 */
  52 224,                           /* irq 7 */
  53 0,
  54 64,                            /* irq 9 */
  55 80,                            /* irq 10 */
  56 208,                           /* irq 11 */
  57 48,                            /* irq 12 */
  58 0,
  59 0,
  60 112,                           /* irq 15 */
  61};
  62
  63/* ------------------------------------------------------------- */
  64
  65avmcard *b1_alloc_card(int nr_controllers)
  66{
  67        avmcard *card;
  68        avmctrl_info *cinfo;
  69        int i;
  70
  71        card = kzalloc(sizeof(*card), GFP_KERNEL);
  72        if (!card)
  73                return NULL;
  74
  75        cinfo = kcalloc(nr_controllers, sizeof(*cinfo), GFP_KERNEL);
  76        if (!cinfo) {
  77                kfree(card);
  78                return NULL;
  79        }
  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                        ans = b1_get_byte(base);
 265                        if (ans == RECEIVE_POLL)
 266                                return 1;
 267
 268                        printk(KERN_ERR "%s: b1_loaded: got 0x%x, firmware not running\n",
 269                               card->name, ans);
 270                        return 0;
 271                }
 272        }
 273        printk(KERN_ERR "%s: b1_loaded: firmware not running\n", card->name);
 274        return 0;
 275}
 276
 277/* ------------------------------------------------------------- */
 278
 279int b1_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
 280{
 281        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 282        avmcard *card = cinfo->card;
 283        unsigned int port = card->port;
 284        unsigned long flags;
 285        int retval;
 286
 287        b1_reset(port);
 288        retval = b1_load_t4file(card, &data->firmware);
 289
 290        if (retval) {
 291                b1_reset(port);
 292                printk(KERN_ERR "%s: failed to load t4file!!\n",
 293                       card->name);
 294                return retval;
 295        }
 296
 297        b1_disable_irq(port);
 298
 299        if (data->configuration.len > 0 && data->configuration.data) {
 300                retval = b1_load_config(card, &data->configuration);
 301                if (retval) {
 302                        b1_reset(port);
 303                        printk(KERN_ERR "%s: failed to load config!!\n",
 304                               card->name);
 305                        return retval;
 306                }
 307        }
 308
 309        if (!b1_loaded(card)) {
 310                printk(KERN_ERR "%s: failed to load t4file.\n", card->name);
 311                return -EIO;
 312        }
 313
 314        spin_lock_irqsave(&card->lock, flags);
 315        b1_setinterrupt(port, card->irq, card->cardtype);
 316        b1_put_byte(port, SEND_INIT);
 317        b1_put_word(port, CAPI_MAXAPPL);
 318        b1_put_word(port, AVM_NCCI_PER_CHANNEL * 2);
 319        b1_put_word(port, ctrl->cnr - 1);
 320        spin_unlock_irqrestore(&card->lock, flags);
 321
 322        return 0;
 323}
 324
 325void b1_reset_ctr(struct capi_ctr *ctrl)
 326{
 327        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 328        avmcard *card = cinfo->card;
 329        unsigned int port = card->port;
 330        unsigned long flags;
 331
 332        b1_reset(port);
 333        b1_reset(port);
 334
 335        memset(cinfo->version, 0, sizeof(cinfo->version));
 336        spin_lock_irqsave(&card->lock, flags);
 337        capilib_release(&cinfo->ncci_head);
 338        spin_unlock_irqrestore(&card->lock, flags);
 339        capi_ctr_down(ctrl);
 340}
 341
 342void b1_register_appl(struct capi_ctr *ctrl,
 343                      u16 appl,
 344                      capi_register_params *rp)
 345{
 346        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 347        avmcard *card = cinfo->card;
 348        unsigned int port = card->port;
 349        unsigned long flags;
 350        int nconn, want = rp->level3cnt;
 351
 352        if (want > 0) nconn = want;
 353        else nconn = ctrl->profile.nbchannel * -want;
 354        if (nconn == 0) nconn = ctrl->profile.nbchannel;
 355
 356        spin_lock_irqsave(&card->lock, flags);
 357        b1_put_byte(port, SEND_REGISTER);
 358        b1_put_word(port, appl);
 359        b1_put_word(port, 1024 * (nconn + 1));
 360        b1_put_word(port, nconn);
 361        b1_put_word(port, rp->datablkcnt);
 362        b1_put_word(port, rp->datablklen);
 363        spin_unlock_irqrestore(&card->lock, flags);
 364}
 365
 366void b1_release_appl(struct capi_ctr *ctrl, u16 appl)
 367{
 368        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 369        avmcard *card = cinfo->card;
 370        unsigned int port = card->port;
 371        unsigned long flags;
 372
 373        spin_lock_irqsave(&card->lock, flags);
 374        capilib_release_appl(&cinfo->ncci_head, appl);
 375        b1_put_byte(port, SEND_RELEASE);
 376        b1_put_word(port, appl);
 377        spin_unlock_irqrestore(&card->lock, flags);
 378}
 379
 380u16 b1_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
 381{
 382        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 383        avmcard *card = cinfo->card;
 384        unsigned int port = card->port;
 385        unsigned long flags;
 386        u16 len = CAPIMSG_LEN(skb->data);
 387        u8 cmd = CAPIMSG_COMMAND(skb->data);
 388        u8 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
 389        u16 dlen, retval;
 390
 391        spin_lock_irqsave(&card->lock, flags);
 392        if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
 393                retval = capilib_data_b3_req(&cinfo->ncci_head,
 394                                             CAPIMSG_APPID(skb->data),
 395                                             CAPIMSG_NCCI(skb->data),
 396                                             CAPIMSG_MSGID(skb->data));
 397                if (retval != CAPI_NOERROR) {
 398                        spin_unlock_irqrestore(&card->lock, flags);
 399                        return retval;
 400                }
 401
 402                dlen = CAPIMSG_DATALEN(skb->data);
 403
 404                b1_put_byte(port, SEND_DATA_B3_REQ);
 405                b1_put_slice(port, skb->data, len);
 406                b1_put_slice(port, skb->data + len, dlen);
 407        } else {
 408                b1_put_byte(port, SEND_MESSAGE);
 409                b1_put_slice(port, skb->data, len);
 410        }
 411        spin_unlock_irqrestore(&card->lock, flags);
 412
 413        dev_kfree_skb_any(skb);
 414        return CAPI_NOERROR;
 415}
 416
 417/* ------------------------------------------------------------- */
 418
 419void b1_parse_version(avmctrl_info *cinfo)
 420{
 421        struct capi_ctr *ctrl = &cinfo->capi_ctrl;
 422        avmcard *card = cinfo->card;
 423        capi_profile *profp;
 424        u8 *dversion;
 425        u8 flag;
 426        int i, j;
 427
 428        for (j = 0; j < AVM_MAXVERSION; j++)
 429                cinfo->version[j] = "";
 430        for (i = 0, j = 0;
 431             j < AVM_MAXVERSION && i < cinfo->versionlen;
 432             j++, i += cinfo->versionbuf[i] + 1)
 433                cinfo->version[j] = &cinfo->versionbuf[i + 1];
 434
 435        strlcpy(ctrl->serial, cinfo->version[VER_SERIAL], sizeof(ctrl->serial));
 436        memcpy(&ctrl->profile, cinfo->version[VER_PROFILE], sizeof(capi_profile));
 437        strlcpy(ctrl->manu, "AVM GmbH", sizeof(ctrl->manu));
 438        dversion = cinfo->version[VER_DRIVER];
 439        ctrl->version.majorversion = 2;
 440        ctrl->version.minorversion = 0;
 441        ctrl->version.majormanuversion = (((dversion[0] - '0') & 0xf) << 4);
 442        ctrl->version.majormanuversion |= ((dversion[2] - '0') & 0xf);
 443        ctrl->version.minormanuversion = (dversion[3] - '0') << 4;
 444        ctrl->version.minormanuversion |=
 445                (dversion[5] - '0') * 10 + ((dversion[6] - '0') & 0xf);
 446
 447        profp = &ctrl->profile;
 448
 449        flag = ((u8 *)(profp->manu))[1];
 450        switch (flag) {
 451        case 0: if (cinfo->version[VER_CARDTYPE])
 452                        strcpy(cinfo->cardname, cinfo->version[VER_CARDTYPE]);
 453                else strcpy(cinfo->cardname, "B1");
 454                break;
 455        case 3: strcpy(cinfo->cardname, "PCMCIA B"); break;
 456        case 4: strcpy(cinfo->cardname, "PCMCIA M1"); break;
 457        case 5: strcpy(cinfo->cardname, "PCMCIA M2"); break;
 458        case 6: strcpy(cinfo->cardname, "B1 V3.0"); break;
 459        case 7: strcpy(cinfo->cardname, "B1 PCI"); break;
 460        default: sprintf(cinfo->cardname, "AVM?%u", (unsigned int)flag); break;
 461        }
 462        printk(KERN_NOTICE "%s: card %d \"%s\" ready.\n",
 463               card->name, ctrl->cnr, cinfo->cardname);
 464
 465        flag = ((u8 *)(profp->manu))[3];
 466        if (flag)
 467                printk(KERN_NOTICE "%s: card %d Protocol:%s%s%s%s%s%s%s\n",
 468                       card->name,
 469                       ctrl->cnr,
 470                       (flag & 0x01) ? " DSS1" : "",
 471                       (flag & 0x02) ? " CT1" : "",
 472                       (flag & 0x04) ? " VN3" : "",
 473                       (flag & 0x08) ? " NI1" : "",
 474                       (flag & 0x10) ? " AUSTEL" : "",
 475                       (flag & 0x20) ? " ESS" : "",
 476                       (flag & 0x40) ? " 1TR6" : ""
 477                        );
 478
 479        flag = ((u8 *)(profp->manu))[5];
 480        if (flag)
 481                printk(KERN_NOTICE "%s: card %d Linetype:%s%s%s%s\n",
 482                       card->name,
 483                       ctrl->cnr,
 484                       (flag & 0x01) ? " point to point" : "",
 485                       (flag & 0x02) ? " point to multipoint" : "",
 486                       (flag & 0x08) ? " leased line without D-channel" : "",
 487                       (flag & 0x04) ? " leased line with D-channel" : ""
 488                        );
 489}
 490
 491/* ------------------------------------------------------------- */
 492
 493irqreturn_t b1_interrupt(int interrupt, void *devptr)
 494{
 495        avmcard *card = devptr;
 496        avmctrl_info *cinfo = &card->ctrlinfo[0];
 497        struct capi_ctr *ctrl = &cinfo->capi_ctrl;
 498        unsigned char b1cmd;
 499        struct sk_buff *skb;
 500
 501        unsigned ApplId;
 502        unsigned MsgLen;
 503        unsigned DataB3Len;
 504        unsigned NCCI;
 505        unsigned WindowSize;
 506        unsigned long flags;
 507
 508        spin_lock_irqsave(&card->lock, flags);
 509
 510        if (!b1_rx_full(card->port)) {
 511                spin_unlock_irqrestore(&card->lock, flags);
 512                return IRQ_NONE;
 513        }
 514
 515        b1cmd = b1_get_byte(card->port);
 516
 517        switch (b1cmd) {
 518
 519        case RECEIVE_DATA_B3_IND:
 520
 521                ApplId = (unsigned) b1_get_word(card->port);
 522                MsgLen = b1_get_slice(card->port, card->msgbuf);
 523                DataB3Len = b1_get_slice(card->port, card->databuf);
 524                spin_unlock_irqrestore(&card->lock, flags);
 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
 532                skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC);
 533                if (!skb) {
 534                        printk(KERN_ERR "%s: incoming packet dropped\n",
 535                               card->name);
 536                } else {
 537                        skb_put_data(skb, card->msgbuf, MsgLen);
 538                        skb_put_data(skb, card->databuf, DataB3Len);
 539                        capi_ctr_handle_message(ctrl, ApplId, skb);
 540                }
 541                break;
 542
 543        case RECEIVE_MESSAGE:
 544
 545                ApplId = (unsigned) b1_get_word(card->port);
 546                MsgLen = b1_get_slice(card->port, card->msgbuf);
 547                skb = alloc_skb(MsgLen, GFP_ATOMIC);
 548
 549                if (!skb) {
 550                        printk(KERN_ERR "%s: incoming packet dropped\n",
 551                               card->name);
 552                        spin_unlock_irqrestore(&card->lock, flags);
 553                } else {
 554                        skb_put_data(skb, 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                        spin_unlock_irqrestore(&card->lock, flags);
 560                        capi_ctr_handle_message(ctrl, ApplId, skb);
 561                }
 562                break;
 563
 564        case RECEIVE_NEW_NCCI:
 565
 566                ApplId = b1_get_word(card->port);
 567                NCCI = b1_get_word(card->port);
 568                WindowSize = b1_get_word(card->port);
 569                capilib_new_ncci(&cinfo->ncci_head, ApplId, NCCI, WindowSize);
 570                spin_unlock_irqrestore(&card->lock, flags);
 571                break;
 572
 573        case RECEIVE_FREE_NCCI:
 574
 575                ApplId = b1_get_word(card->port);
 576                NCCI = b1_get_word(card->port);
 577                if (NCCI != 0xffffffff)
 578                        capilib_free_ncci(&cinfo->ncci_head, ApplId, NCCI);
 579                spin_unlock_irqrestore(&card->lock, flags);
 580                break;
 581
 582        case RECEIVE_START:
 583                /* b1_put_byte(card->port, SEND_POLLACK); */
 584                spin_unlock_irqrestore(&card->lock, flags);
 585                capi_ctr_resume_output(ctrl);
 586                break;
 587
 588        case RECEIVE_STOP:
 589                spin_unlock_irqrestore(&card->lock, flags);
 590                capi_ctr_suspend_output(ctrl);
 591                break;
 592
 593        case RECEIVE_INIT:
 594
 595                cinfo->versionlen = b1_get_slice(card->port, cinfo->versionbuf);
 596                spin_unlock_irqrestore(&card->lock, flags);
 597                b1_parse_version(cinfo);
 598                printk(KERN_INFO "%s: %s-card (%s) now active\n",
 599                       card->name,
 600                       cinfo->version[VER_CARDTYPE],
 601                       cinfo->version[VER_DRIVER]);
 602                capi_ctr_ready(ctrl);
 603                break;
 604
 605        case RECEIVE_TASK_READY:
 606                ApplId = (unsigned) b1_get_word(card->port);
 607                MsgLen = b1_get_slice(card->port, card->msgbuf);
 608                spin_unlock_irqrestore(&card->lock, flags);
 609                card->msgbuf[MsgLen] = 0;
 610                while (MsgLen > 0
 611                       && (card->msgbuf[MsgLen - 1] == '\n'
 612                           || card->msgbuf[MsgLen - 1] == '\r')) {
 613                        card->msgbuf[MsgLen - 1] = 0;
 614                        MsgLen--;
 615                }
 616                printk(KERN_INFO "%s: task %d \"%s\" ready.\n",
 617                       card->name, ApplId, card->msgbuf);
 618                break;
 619
 620        case RECEIVE_DEBUGMSG:
 621                MsgLen = b1_get_slice(card->port, card->msgbuf);
 622                spin_unlock_irqrestore(&card->lock, flags);
 623                card->msgbuf[MsgLen] = 0;
 624                while (MsgLen > 0
 625                       && (card->msgbuf[MsgLen - 1] == '\n'
 626                           || card->msgbuf[MsgLen - 1] == '\r')) {
 627                        card->msgbuf[MsgLen - 1] = 0;
 628                        MsgLen--;
 629                }
 630                printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf);
 631                break;
 632
 633        case 0xff:
 634                spin_unlock_irqrestore(&card->lock, flags);
 635                printk(KERN_ERR "%s: card removed ?\n", card->name);
 636                return IRQ_NONE;
 637        default:
 638                spin_unlock_irqrestore(&card->lock, flags);
 639                printk(KERN_ERR "%s: b1_interrupt: 0x%x ???\n",
 640                       card->name, b1cmd);
 641                return IRQ_HANDLED;
 642        }
 643        return IRQ_HANDLED;
 644}
 645
 646/* ------------------------------------------------------------- */
 647int b1_proc_show(struct seq_file *m, void *v)
 648{
 649        struct capi_ctr *ctrl = m->private;
 650        avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
 651        avmcard *card = cinfo->card;
 652        u8 flag;
 653        char *s;
 654
 655        seq_printf(m, "%-16s %s\n", "name", card->name);
 656        seq_printf(m, "%-16s 0x%x\n", "io", card->port);
 657        seq_printf(m, "%-16s %d\n", "irq", card->irq);
 658        switch (card->cardtype) {
 659        case avm_b1isa: s = "B1 ISA"; break;
 660        case avm_b1pci: s = "B1 PCI"; break;
 661        case avm_b1pcmcia: s = "B1 PCMCIA"; break;
 662        case avm_m1: s = "M1"; break;
 663        case avm_m2: s = "M2"; break;
 664        case avm_t1isa: s = "T1 ISA (HEMA)"; break;
 665        case avm_t1pci: s = "T1 PCI"; break;
 666        case avm_c4: s = "C4"; break;
 667        case avm_c2: s = "C2"; break;
 668        default: s = "???"; break;
 669        }
 670        seq_printf(m, "%-16s %s\n", "type", s);
 671        if (card->cardtype == avm_t1isa)
 672                seq_printf(m, "%-16s %d\n", "cardnr", card->cardnr);
 673
 674        s = cinfo->version[VER_DRIVER];
 675        if (s)
 676                seq_printf(m, "%-16s %s\n", "ver_driver", s);
 677
 678        s = cinfo->version[VER_CARDTYPE];
 679        if (s)
 680                seq_printf(m, "%-16s %s\n", "ver_cardtype", s);
 681
 682        s = cinfo->version[VER_SERIAL];
 683        if (s)
 684                seq_printf(m, "%-16s %s\n", "ver_serial", s);
 685
 686        if (card->cardtype != avm_m1) {
 687                flag = ((u8 *)(ctrl->profile.manu))[3];
 688                if (flag)
 689                        seq_printf(m, "%-16s%s%s%s%s%s%s%s\n",
 690                                   "protocol",
 691                                   (flag & 0x01) ? " DSS1" : "",
 692                                   (flag & 0x02) ? " CT1" : "",
 693                                   (flag & 0x04) ? " VN3" : "",
 694                                   (flag & 0x08) ? " NI1" : "",
 695                                   (flag & 0x10) ? " AUSTEL" : "",
 696                                   (flag & 0x20) ? " ESS" : "",
 697                                   (flag & 0x40) ? " 1TR6" : ""
 698                                );
 699        }
 700        if (card->cardtype != avm_m1) {
 701                flag = ((u8 *)(ctrl->profile.manu))[5];
 702                if (flag)
 703                        seq_printf(m, "%-16s%s%s%s%s\n",
 704                                   "linetype",
 705                                   (flag & 0x01) ? " point to point" : "",
 706                                   (flag & 0x02) ? " point to multipoint" : "",
 707                                   (flag & 0x08) ? " leased line without D-channel" : "",
 708                                   (flag & 0x04) ? " leased line with D-channel" : ""
 709                                );
 710        }
 711        seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname);
 712
 713        return 0;
 714}
 715EXPORT_SYMBOL(b1_proc_show);
 716
 717/* ------------------------------------------------------------- */
 718
 719#ifdef CONFIG_PCI
 720
 721avmcard_dmainfo *
 722avmcard_dma_alloc(char *name, struct pci_dev *pdev, long rsize, long ssize)
 723{
 724        avmcard_dmainfo *p;
 725        void *buf;
 726
 727        p = kzalloc(sizeof(avmcard_dmainfo), GFP_KERNEL);
 728        if (!p) {
 729                printk(KERN_WARNING "%s: no memory.\n", name);
 730                goto err;
 731        }
 732
 733        p->recvbuf.size = rsize;
 734        buf = pci_alloc_consistent(pdev, rsize, &p->recvbuf.dmaaddr);
 735        if (!buf) {
 736                printk(KERN_WARNING "%s: allocation of receive dma buffer failed.\n", name);
 737                goto err_kfree;
 738        }
 739        p->recvbuf.dmabuf = buf;
 740
 741        p->sendbuf.size = ssize;
 742        buf = pci_alloc_consistent(pdev, ssize, &p->sendbuf.dmaaddr);
 743        if (!buf) {
 744                printk(KERN_WARNING "%s: allocation of send dma buffer failed.\n", name);
 745                goto err_free_consistent;
 746        }
 747
 748        p->sendbuf.dmabuf = buf;
 749        skb_queue_head_init(&p->send_queue);
 750
 751        return p;
 752
 753err_free_consistent:
 754        pci_free_consistent(p->pcidev, p->recvbuf.size,
 755                            p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
 756err_kfree:
 757        kfree(p);
 758err:
 759        return NULL;
 760}
 761
 762void avmcard_dma_free(avmcard_dmainfo *p)
 763{
 764        pci_free_consistent(p->pcidev, p->recvbuf.size,
 765                            p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
 766        pci_free_consistent(p->pcidev, p->sendbuf.size,
 767                            p->sendbuf.dmabuf, p->sendbuf.dmaaddr);
 768        skb_queue_purge(&p->send_queue);
 769        kfree(p);
 770}
 771
 772EXPORT_SYMBOL(avmcard_dma_alloc);
 773EXPORT_SYMBOL(avmcard_dma_free);
 774
 775#endif
 776
 777EXPORT_SYMBOL(b1_irq_table);
 778
 779EXPORT_SYMBOL(b1_alloc_card);
 780EXPORT_SYMBOL(b1_free_card);
 781EXPORT_SYMBOL(b1_detect);
 782EXPORT_SYMBOL(b1_getrevision);
 783EXPORT_SYMBOL(b1_load_t4file);
 784EXPORT_SYMBOL(b1_load_config);
 785EXPORT_SYMBOL(b1_loaded);
 786EXPORT_SYMBOL(b1_load_firmware);
 787EXPORT_SYMBOL(b1_reset_ctr);
 788EXPORT_SYMBOL(b1_register_appl);
 789EXPORT_SYMBOL(b1_release_appl);
 790EXPORT_SYMBOL(b1_send_message);
 791
 792EXPORT_SYMBOL(b1_parse_version);
 793EXPORT_SYMBOL(b1_interrupt);
 794
 795static int __init b1_init(void)
 796{
 797        char *p;
 798        char rev[32];
 799
 800        p = strchr(revision, ':');
 801        if (p && p[1]) {
 802                strlcpy(rev, p + 2, 32);
 803                p = strchr(rev, '$');
 804                if (p && p > rev)
 805                        *(p - 1) = 0;
 806        } else {
 807                strcpy(rev, "1.0");
 808        }
 809        printk(KERN_INFO "b1: revision %s\n", rev);
 810
 811        return 0;
 812}
 813
 814static void __exit b1_exit(void)
 815{
 816}
 817
 818module_init(b1_init);
 819module_exit(b1_exit);
 820