Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | /* * $Id: b1dma.c,v 1.3 2000/02/26 01:00:53 keil Exp $ * * Common module for AVM B1 cards that support dma with AMCC * * (c) Copyright 2000 by Carsten Paeth (calle@calle.in-berlin.de) * * $Log: b1dma.c,v $ * Revision 1.3 2000/02/26 01:00:53 keil * changes from 2.3.47 * * Revision 1.2 2000/01/25 14:44:47 calle * typo in b1pciv4_detect(). * * Revision 1.1 2000/01/25 14:36:43 calle * common function for T1 PCI and B1 PCI V4. * * */ #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/skbuff.h> #include <linux/delay.h> #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/capi.h> #include <asm/io.h> #include <asm/uaccess.h> #include "capilli.h" #include "avmcard.h" #include "capicmd.h" #include "capiutil.h" static char *revision = "$Revision: 1.3 $"; /* ------------------------------------------------------------- */ MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>"); static int suppress_pollack = 0; MODULE_PARM(suppress_pollack, "0-1i"); /* ------------------------------------------------------------- */ static void b1dma_dispatch_tx(avmcard *card); /* ------------------------------------------------------------- */ /* S5933 */ #define AMCC_RXPTR 0x24 #define AMCC_RXLEN 0x28 #define AMCC_TXPTR 0x2c #define AMCC_TXLEN 0x30 #define AMCC_INTCSR 0x38 # define EN_READ_TC_INT 0x00008000L # define EN_WRITE_TC_INT 0x00004000L # define EN_TX_TC_INT EN_READ_TC_INT # define EN_RX_TC_INT EN_WRITE_TC_INT # define AVM_FLAG 0x30000000L # define ANY_S5933_INT 0x00800000L # define READ_TC_INT 0x00080000L # define WRITE_TC_INT 0x00040000L # define TX_TC_INT READ_TC_INT # define RX_TC_INT WRITE_TC_INT # define MASTER_ABORT_INT 0x00100000L # define TARGET_ABORT_INT 0x00200000L # define BUS_MASTER_INT 0x00200000L # define ALL_INT 0x000C0000L #define AMCC_MCSR 0x3c # define A2P_HI_PRIORITY 0x00000100L # define EN_A2P_TRANSFERS 0x00000400L # define P2A_HI_PRIORITY 0x00001000L # define EN_P2A_TRANSFERS 0x00004000L # define RESET_A2P_FLAGS 0x04000000L # define RESET_P2A_FLAGS 0x02000000L /* ------------------------------------------------------------- */ #define b1dmaoutmeml(addr, value) writel(value, addr) #define b1dmainmeml(addr) readl(addr) #define b1dmaoutmemw(addr, value) writew(value, addr) #define b1dmainmemw(addr) readw(addr) #define b1dmaoutmemb(addr, value) writeb(value, addr) #define b1dmainmemb(addr) readb(addr) /* ------------------------------------------------------------- */ static inline int b1dma_tx_empty(unsigned int port) { return inb(port + 0x03) & 0x1; } static inline int b1dma_rx_full(unsigned int port) { return inb(port + 0x02) & 0x1; } static int b1dma_tolink(avmcard *card, void *buf, unsigned int len) { unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */ unsigned char *s = (unsigned char *)buf; while (len--) { while ( !b1dma_tx_empty(card->port) && time_before(jiffies, stop)); if (!b1dma_tx_empty(card->port)) return -1; t1outp(card->port, 0x01, *s++); } return 0; } static int b1dma_fromlink(avmcard *card, void *buf, unsigned int len) { unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */ unsigned char *s = (unsigned char *)buf; while (len--) { while ( !b1dma_rx_full(card->port) && time_before(jiffies, stop)); if (!b1dma_rx_full(card->port)) return -1; *s++ = t1inp(card->port, 0x00); } return 0; } static int WriteReg(avmcard *card, __u32 reg, __u8 val) { __u8 cmd = 0x00; if ( b1dma_tolink(card, &cmd, 1) == 0 && b1dma_tolink(card, ®, 4) == 0) { __u32 tmp = val; return b1dma_tolink(card, &tmp, 4); } return -1; } static __u8 ReadReg(avmcard *card, __u32 reg) { __u8 cmd = 0x01; if ( b1dma_tolink(card, &cmd, 1) == 0 && b1dma_tolink(card, ®, 4) == 0) { __u32 tmp; if (b1dma_fromlink(card, &tmp, 4) == 0) return (__u8)tmp; } return 0xff; } /* ------------------------------------------------------------- */ static inline void _put_byte(void **pp, __u8 val) { __u8 *s = *pp; *s++ = val; *pp = s; } static inline void _put_word(void **pp, __u32 val) { __u8 *s = *pp; *s++ = val & 0xff; *s++ = (val >> 8) & 0xff; *s++ = (val >> 16) & 0xff; *s++ = (val >> 24) & 0xff; *pp = s; } static inline void _put_slice(void **pp, unsigned char *dp, unsigned int len) { unsigned i = len; _put_word(pp, i); while (i-- > 0) _put_byte(pp, *dp++); } static inline __u8 _get_byte(void **pp) { __u8 *s = *pp; __u8 val; val = *s++; *pp = s; return val; } static inline __u32 _get_word(void **pp) { __u8 *s = *pp; __u32 val; val = *s++; val |= (*s++ << 8); val |= (*s++ << 16); val |= (*s++ << 24); *pp = s; return val; } static inline __u32 _get_slice(void **pp, unsigned char *dp) { unsigned int len, i; len = i = _get_word(pp); while (i-- > 0) *dp++ = _get_byte(pp); return len; } /* ------------------------------------------------------------- */ void b1dma_reset(avmcard *card) { unsigned long flags; save_flags(flags); cli(); card->csr = 0x0; b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0); b1dmaoutmeml(card->mbase+AMCC_RXLEN, 0); b1dmaoutmeml(card->mbase+AMCC_TXLEN, 0); t1outp(card->port, 0x10, 0x00); t1outp(card->port, 0x07, 0x00); restore_flags(flags); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0); udelay(10 * 1000); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0x0f000000); /* reset all */ udelay(10 * 1000); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0); if (card->cardtype == avm_t1pci) udelay(42 * 1000); else udelay(10 * 1000); } /* ------------------------------------------------------------- */ int b1dma_detect(avmcard *card) { b1dmaoutmeml(card->mbase+AMCC_MCSR, 0); udelay(10 * 1000); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0x0f000000); /* reset all */ udelay(10 * 1000); b1dmaoutmeml(card->mbase+AMCC_MCSR, 0); udelay(42 * 1000); b1dmaoutmeml(card->mbase+AMCC_RXLEN, 0); b1dmaoutmeml(card->mbase+AMCC_TXLEN, 0); card->csr = 0x0; b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); if (b1dmainmeml(card->mbase+AMCC_MCSR) != 0x000000E6) return 1; b1dmaoutmeml(card->mbase+AMCC_RXPTR, 0xffffffff); b1dmaoutmeml(card->mbase+AMCC_TXPTR, 0xffffffff); if ( b1dmainmeml(card->mbase+AMCC_RXPTR) != 0xfffffffc || b1dmainmeml(card->mbase+AMCC_TXPTR) != 0xfffffffc) return 2; b1dmaoutmeml(card->mbase+AMCC_RXPTR, 0x0); b1dmaoutmeml(card->mbase+AMCC_TXPTR, 0x0); if ( b1dmainmeml(card->mbase+AMCC_RXPTR) != 0x0 || b1dmainmeml(card->mbase+AMCC_TXPTR) != 0x0) return 3; t1outp(card->port, 0x10, 0x00); t1outp(card->port, 0x07, 0x00); t1outp(card->port, 0x02, 0x02); t1outp(card->port, 0x03, 0x02); if ( (t1inp(card->port, 0x02) & 0xFE) != 0x02 || t1inp(card->port, 0x3) != 0x03) return 4; t1outp(card->port, 0x02, 0x00); t1outp(card->port, 0x03, 0x00); if ( (t1inp(card->port, 0x02) & 0xFE) != 0x00 || t1inp(card->port, 0x3) != 0x01) return 5; return 0; } int t1pci_detect(avmcard *card) { int ret; if ((ret = b1dma_detect(card)) != 0) return ret; /* Transputer test */ if ( WriteReg(card, 0x80001000, 0x11) != 0 || WriteReg(card, 0x80101000, 0x22) != 0 || WriteReg(card, 0x80201000, 0x33) != 0 || WriteReg(card, 0x80301000, 0x44) != 0) return 6; if ( ReadReg(card, 0x80001000) != 0x11 || ReadReg(card, 0x80101000) != 0x22 || ReadReg(card, 0x80201000) != 0x33 || ReadReg(card, 0x80301000) != 0x44) return 7; if ( WriteReg(card, 0x80001000, 0x55) != 0 || WriteReg(card, 0x80101000, 0x66) != 0 || WriteReg(card, 0x80201000, 0x77) != 0 || WriteReg(card, 0x80301000, 0x88) != 0) return 8; if ( ReadReg(card, 0x80001000) != 0x55 || ReadReg(card, 0x80101000) != 0x66 || ReadReg(card, 0x80201000) != 0x77 || ReadReg(card, 0x80301000) != 0x88) return 9; return 0; } int b1pciv4_detect(avmcard *card) { int ret, i; if ((ret = b1dma_detect(card)) != 0) return ret; for (i=0; i < 5 ; i++) { if (WriteReg(card, 0x80A00000, 0x21) != 0) return 6; if ((ReadReg(card, 0x80A00000) & 0x01) != 0x01) return 7; } for (i=0; i < 5 ; i++) { if (WriteReg(card, 0x80A00000, 0x20) != 0) return 8; if ((ReadReg(card, 0x80A00000) & 0x01) != 0x00) return 9; } return 0; } /* ------------------------------------------------------------- */ static void b1dma_dispatch_tx(avmcard *card) { avmcard_dmainfo *dma = card->dma; unsigned long flags; struct sk_buff *skb; __u8 cmd, subcmd; __u16 len; __u32 txlen; int inint; void *p; save_flags(flags); cli(); inint = card->interrupt; if (card->csr & EN_TX_TC_INT) { /* tx busy */ restore_flags(flags); return; } skb = skb_dequeue(&dma->send_queue); if (!skb) { #ifdef CONFIG_B1DMA_DEBUG printk(KERN_DEBUG "tx(%d): underrun\n", inint); #endif restore_flags(flags); return; } len = CAPIMSG_LEN(skb->data); if (len) { cmd = CAPIMSG_COMMAND(skb->data); subcmd = CAPIMSG_SUBCOMMAND(skb->data); p = dma->sendbuf; if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) { __u16 dlen = CAPIMSG_DATALEN(skb->data); _put_byte(&p, SEND_DATA_B3_REQ); _put_slice(&p, skb->data, len); _put_slice(&p, skb->data + len, dlen); } else { _put_byte(&p, SEND_MESSAGE); _put_slice(&p, skb->data, len); } txlen = (__u8 *)p - (__u8 *)dma->sendbuf; #ifdef CONFIG_B1DMA_DEBUG printk(KERN_DEBUG "tx(%d): put msg len=%d\n", inint, txlen); #endif } else { txlen = skb->len-2; #ifdef CONFIG_B1DMA_POLLDEBUG if (skb->data[2] == SEND_POLLACK) printk(KERN_INFO "%s: send ack\n", card->name); #endif #ifdef CONFIG_B1DMA_DEBUG printk(KERN_DEBUG "tx(%d): put 0x%x len=%d\n", inint, skb->data[2], txlen); #endif memcpy(dma->sendbuf, skb->data+2, skb->len-2); } txlen = (txlen + 3) & ~3; b1dmaoutmeml(card->mbase+AMCC_TXPTR, virt_to_phys(dma->sendbuf)); b1dmaoutmeml(card->mbase+AMCC_TXLEN, txlen); card->csr |= EN_TX_TC_INT; if (!inint) b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); restore_flags(flags); dev_kfree_skb(skb); } /* ------------------------------------------------------------- */ static void queue_pollack(avmcard *card) { struct sk_buff *skb; void *p; skb = alloc_skb(3, GFP_ATOMIC); if (!skb) { printk(KERN_CRIT "%s: no memory, lost poll ack\n", card->name); return; } p = skb->data; _put_byte(&p, 0); _put_byte(&p, 0); _put_byte(&p, SEND_POLLACK); skb_put(skb, (__u8 *)p - (__u8 *)skb->data); skb_queue_tail(&card->dma->send_queue, skb); b1dma_dispatch_tx(card); } /* ------------------------------------------------------------- */ static void b1dma_handle_rx(avmcard *card) { avmctrl_info *cinfo = &card->ctrlinfo[0]; avmcard_dmainfo *dma = card->dma; struct capi_ctr *ctrl = cinfo->capi_ctrl; struct sk_buff *skb; void *p = dma->recvbuf+4; __u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; __u8 b1cmd = _get_byte(&p); #ifdef CONFIG_B1DMA_DEBUG printk(KERN_DEBUG "rx: 0x%x %lu\n", b1cmd, (unsigned long)dma->recvlen); #endif switch (b1cmd) { case RECEIVE_DATA_B3_IND: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); DataB3Len = _get_slice(&p, card->databuf); if (MsgLen < 30) { /* not CAPI 64Bit */ memset(card->msgbuf+MsgLen, 0, 30-MsgLen); MsgLen = 30; CAPIMSG_SETLEN(card->msgbuf, 30); } if (!(skb = alloc_skb(DataB3Len+MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len); ctrl->handle_capimsg(ctrl, ApplId, skb); } break; case RECEIVE_MESSAGE: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); ctrl->handle_capimsg(ctrl, ApplId, skb); } break; case RECEIVE_NEW_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); WindowSize = _get_word(&p); ctrl->new_ncci(ctrl, ApplId, NCCI, WindowSize); break; case RECEIVE_FREE_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); if (NCCI != 0xffffffff) ctrl->free_ncci(ctrl, ApplId, NCCI); else ctrl->appl_released(ctrl, ApplId); break; case RECEIVE_START: #ifdef CONFIG_B1DMA_POLLDEBUG printk(KERN_INFO "%s: receive poll\n", card->name); #endif if (!suppress_pollack) queue_pollack(card); ctrl->resume_output(ctrl); break; case RECEIVE_STOP: ctrl->suspend_output(ctrl); break; case RECEIVE_INIT: cinfo->versionlen = _get_slice(&p, cinfo->versionbuf); b1_parse_version(cinfo); printk(KERN_INFO "%s: %s-card (%s) now active\n", card->name, cinfo->version[VER_CARDTYPE], cinfo->version[VER_DRIVER]); ctrl->ready(ctrl); break; case RECEIVE_TASK_READY: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen--] = 0; while ( MsgLen >= 0 && ( card->msgbuf[MsgLen] == '\n' || card->msgbuf[MsgLen] == '\r')) card->msgbuf[MsgLen--] = 0; printk(KERN_INFO "%s: task %d \"%s\" ready.\n", card->name, ApplId, card->msgbuf); break; case RECEIVE_DEBUGMSG: MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen--] = 0; while ( MsgLen >= 0 && ( card->msgbuf[MsgLen] == '\n' || card->msgbuf[MsgLen] == '\r')) card->msgbuf[MsgLen--] = 0; printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf); break; default: printk(KERN_ERR "%s: b1dma_interrupt: 0x%x ???\n", card->name, b1cmd); return; } } /* ------------------------------------------------------------- */ static void b1dma_handle_interrupt(avmcard *card) { __u32 status = b1dmainmeml(card->mbase+AMCC_INTCSR); __u32 newcsr; if ((status & ANY_S5933_INT) == 0) return; newcsr = card->csr | (status & ALL_INT); if (status & TX_TC_INT) newcsr &= ~EN_TX_TC_INT; if (status & RX_TC_INT) newcsr &= ~EN_RX_TC_INT; b1dmaoutmeml(card->mbase+AMCC_INTCSR, newcsr); if ((status & RX_TC_INT) != 0) { __u8 *recvbuf = card->dma->recvbuf; __u32 rxlen; if (card->dma->recvlen == 0) { card->dma->recvlen = *((__u32 *)recvbuf); rxlen = (card->dma->recvlen + 3) & ~3; b1dmaoutmeml(card->mbase+AMCC_RXPTR, virt_to_phys(recvbuf+4)); b1dmaoutmeml(card->mbase+AMCC_RXLEN, rxlen); } else { b1dma_handle_rx(card); card->dma->recvlen = 0; b1dmaoutmeml(card->mbase+AMCC_RXPTR, virt_to_phys(recvbuf)); b1dmaoutmeml(card->mbase+AMCC_RXLEN, 4); } } if ((status & TX_TC_INT) != 0) { card->csr &= ~EN_TX_TC_INT; b1dma_dispatch_tx(card); } else if (card->csr & EN_TX_TC_INT) { if (b1dmainmeml(card->mbase+AMCC_TXLEN) == 0) { card->csr &= ~EN_TX_TC_INT; b1dma_dispatch_tx(card); } } b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); } void b1dma_interrupt(int interrupt, void *devptr, struct pt_regs *regs) { avmcard *card; card = (avmcard *) devptr; if (!card) { printk(KERN_WARNING "b1dma: interrupt: wrong device\n"); return; } if (card->interrupt) { printk(KERN_ERR "%s: reentering interrupt hander\n", card->name); return; } card->interrupt = 1; b1dma_handle_interrupt(card); card->interrupt = 0; } /* ------------------------------------------------------------- */ static int b1dma_loaded(avmcard *card) { unsigned long stop; unsigned char ans; unsigned long tout = 2; unsigned int base = card->port; for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) { if (b1_tx_empty(base)) break; } if (!b1_tx_empty(base)) { printk(KERN_ERR "%s: b1dma_loaded: tx err, corrupted t4 file ?\n", card->name); return 0; } b1_put_byte(base, SEND_POLLACK); for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) { if (b1_rx_full(base)) { if ((ans = b1_get_byte(base)) == RECEIVE_POLLDWORD) { return 1; } printk(KERN_ERR "%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card->name, ans); return 0; } } printk(KERN_ERR "%s: b1dma_loaded: firmware not running\n", card->name); return 0; } /* ------------------------------------------------------------- */ static void b1dma_send_init(avmcard *card) { struct sk_buff *skb; void *p; skb = alloc_skb(15, GFP_ATOMIC); if (!skb) { printk(KERN_CRIT "%s: no memory, lost register appl.\n", card->name); return; } p = skb->data; _put_byte(&p, 0); _put_byte(&p, 0); _put_byte(&p, SEND_INIT); _put_word(&p, AVM_NAPPS); _put_word(&p, AVM_NCCI_PER_CHANNEL*30); _put_word(&p, card->cardnr - 1); skb_put(skb, (__u8 *)p - (__u8 *)skb->data); skb_queue_tail(&card->dma->send_queue, skb); b1dma_dispatch_tx(card); } int b1dma_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; unsigned long flags; int retval; b1dma_reset(card); if ((retval = b1_load_t4file(card, &data->firmware))) { b1dma_reset(card); printk(KERN_ERR "%s: failed to load t4file!!\n", card->name); return retval; } if (data->configuration.len > 0 && data->configuration.data) { if ((retval = b1_load_config(card, &data->configuration))) { b1dma_reset(card); printk(KERN_ERR "%s: failed to load config!!\n", card->name); return retval; } } if (!b1dma_loaded(card)) { b1dma_reset(card); printk(KERN_ERR "%s: failed to load t4file.\n", card->name); return -EIO; } save_flags(flags); cli(); card->csr = AVM_FLAG; b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); b1dmaoutmeml(card->mbase+AMCC_MCSR, EN_A2P_TRANSFERS|EN_P2A_TRANSFERS |A2P_HI_PRIORITY|P2A_HI_PRIORITY |RESET_A2P_FLAGS|RESET_P2A_FLAGS); t1outp(card->port, 0x07, 0x30); t1outp(card->port, 0x10, 0xF0); card->dma->recvlen = 0; b1dmaoutmeml(card->mbase+AMCC_RXPTR, virt_to_phys(card->dma->recvbuf)); b1dmaoutmeml(card->mbase+AMCC_RXLEN, 4); card->csr |= EN_RX_TC_INT; b1dmaoutmeml(card->mbase+AMCC_INTCSR, card->csr); restore_flags(flags); b1dma_send_init(card); return 0; } void b1dma_reset_ctr(struct capi_ctr *ctrl) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; b1dma_reset(card); memset(cinfo->version, 0, sizeof(cinfo->version)); ctrl->reseted(ctrl); } /* ------------------------------------------------------------- */ void b1dma_register_appl(struct capi_ctr *ctrl, __u16 appl, capi_register_params *rp) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; struct sk_buff *skb; int want = rp->level3cnt; int nconn; void *p; if (want > 0) nconn = want; else nconn = ctrl->profile.nbchannel * -want; if (nconn == 0) nconn = ctrl->profile.nbchannel; skb = alloc_skb(23, GFP_ATOMIC); if (!skb) { printk(KERN_CRIT "%s: no memory, lost register appl.\n", card->name); return; } p = skb->data; _put_byte(&p, 0); _put_byte(&p, 0); _put_byte(&p, SEND_REGISTER); _put_word(&p, appl); _put_word(&p, 1024 * (nconn+1)); _put_word(&p, nconn); _put_word(&p, rp->datablkcnt); _put_word(&p, rp->datablklen); skb_put(skb, (__u8 *)p - (__u8 *)skb->data); skb_queue_tail(&card->dma->send_queue, skb); b1dma_dispatch_tx(card); ctrl->appl_registered(ctrl, appl); } /* ------------------------------------------------------------- */ void b1dma_release_appl(struct capi_ctr *ctrl, __u16 appl) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; struct sk_buff *skb; void *p; skb = alloc_skb(7, GFP_ATOMIC); if (!skb) { printk(KERN_CRIT "%s: no memory, lost release appl.\n", card->name); return; } p = skb->data; _put_byte(&p, 0); _put_byte(&p, 0); _put_byte(&p, SEND_RELEASE); _put_word(&p, appl); skb_put(skb, (__u8 *)p - (__u8 *)skb->data); skb_queue_tail(&card->dma->send_queue, skb); b1dma_dispatch_tx(card); } /* ------------------------------------------------------------- */ void b1dma_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; skb_queue_tail(&card->dma->send_queue, skb); b1dma_dispatch_tx(card); } /* ------------------------------------------------------------- */ int b1dmactl_read_proc(char *page, char **start, off_t off, int count, int *eof, struct capi_ctr *ctrl) { avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; unsigned long flags; __u8 flag; int len = 0; char *s; __u32 txaddr, txlen, rxaddr, rxlen, csr; len += sprintf(page+len, "%-16s %s\n", "name", card->name); len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port); len += sprintf(page+len, "%-16s %d\n", "irq", card->irq); len += sprintf(page+len, "%-16s 0x%lx\n", "membase", card->membase); switch (card->cardtype) { case avm_b1isa: s = "B1 ISA"; break; case avm_b1pci: s = "B1 PCI"; break; case avm_b1pcmcia: s = "B1 PCMCIA"; break; case avm_m1: s = "M1"; break; case avm_m2: s = "M2"; break; case avm_t1isa: s = "T1 ISA (HEMA)"; break; case avm_t1pci: s = "T1 PCI"; break; case avm_c4: s = "C4"; break; default: s = "???"; break; } len += sprintf(page+len, "%-16s %s\n", "type", s); if ((s = cinfo->version[VER_DRIVER]) != 0) len += sprintf(page+len, "%-16s %s\n", "ver_driver", s); if ((s = cinfo->version[VER_CARDTYPE]) != 0) len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s); if ((s = cinfo->version[VER_SERIAL]) != 0) len += sprintf(page+len, "%-16s %s\n", "ver_serial", s); if (card->cardtype != avm_m1) { flag = ((__u8 *)(ctrl->profile.manu))[3]; if (flag) len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n", "protocol", (flag & 0x01) ? " DSS1" : "", (flag & 0x02) ? " CT1" : "", (flag & 0x04) ? " VN3" : "", (flag & 0x08) ? " NI1" : "", (flag & 0x10) ? " AUSTEL" : "", (flag & 0x20) ? " ESS" : "", (flag & 0x40) ? " 1TR6" : "" ); } if (card->cardtype != avm_m1) { flag = ((__u8 *)(ctrl->profile.manu))[5]; if (flag) len += sprintf(page+len, "%-16s%s%s%s%s\n", "linetype", (flag & 0x01) ? " point to point" : "", (flag & 0x02) ? " point to multipoint" : "", (flag & 0x08) ? " leased line without D-channel" : "", (flag & 0x04) ? " leased line with D-channel" : "" ); } len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname); save_flags(flags); cli(); txaddr = (__u32)phys_to_virt(b1dmainmeml(card->mbase+0x2c)); txaddr -= (__u32)card->dma->sendbuf; txlen = b1dmainmeml(card->mbase+0x30); rxaddr = (__u32)phys_to_virt(b1dmainmeml(card->mbase+0x24)); rxaddr -= (__u32)card->dma->recvbuf; rxlen = b1dmainmeml(card->mbase+0x28); csr = b1dmainmeml(card->mbase+AMCC_INTCSR); restore_flags(flags); len += sprintf(page+len, "%-16s 0x%lx\n", "csr (cached)", (unsigned long)card->csr); len += sprintf(page+len, "%-16s 0x%lx\n", "csr", (unsigned long)csr); len += sprintf(page+len, "%-16s %lu\n", "txoff", (unsigned long)txaddr); len += sprintf(page+len, "%-16s %lu\n", "txlen", (unsigned long)txlen); len += sprintf(page+len, "%-16s %lu\n", "rxoff", (unsigned long)rxaddr); len += sprintf(page+len, "%-16s %lu\n", "rxlen", (unsigned long)rxlen); if (off+count >= len) *eof = 1; if (len < off) return 0; *start = page + off; return ((count < len-off) ? count : len-off); } /* ------------------------------------------------------------- */ EXPORT_SYMBOL(b1dma_reset); EXPORT_SYMBOL(t1pci_detect); EXPORT_SYMBOL(b1pciv4_detect); EXPORT_SYMBOL(b1dma_interrupt); EXPORT_SYMBOL(b1dma_load_firmware); EXPORT_SYMBOL(b1dma_reset_ctr); EXPORT_SYMBOL(b1dma_register_appl); EXPORT_SYMBOL(b1dma_release_appl); EXPORT_SYMBOL(b1dma_send_message); EXPORT_SYMBOL(b1dmactl_read_proc); #ifdef MODULE #define b1dma_init init_module void cleanup_module(void); #endif int b1dma_init(void) { char *p; char rev[10]; if ((p = strchr(revision, ':'))) { strncpy(rev, p + 1, sizeof(rev)); p = strchr(rev, '$'); *p = 0; } else strcpy(rev, "1.0"); printk(KERN_INFO "b1dma: revision %s\n", rev); return 0; } #ifdef MODULE void cleanup_module(void) { } #endif |