1 /* $Id: eicon_pci.c,v 1.10 1999/08/22 20:26:49 calle Exp $
3 * ISDN low-level module for Eicon.Diehl active ISDN-Cards.
4 * Hardware-specific code for PCI cards.
6 * Copyright 1998,99 by Armin Schindler (mac@melware.de)
7 * Copyright 1999 Cytronics & Melware (info@melware.de)
9 * Thanks to Eicon Technology Diehl GmbH & Co. oHG for
10 * documents, informations and hardware.
12 * Deutsche Telekom AG for S2M support.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * $Log: eicon_pci.c,v $
29 * Revision 1.10 1999/08/22 20:26:49 calle
30 * backported changes from kernel 2.3.14:
31 * - several #include "config.h" gone, others come.
32 * - "struct device" changed to "struct net_device" in 2.3.14, added a
33 * define in isdn_compat.h for older kernel versions.
35 * Revision 1.9 1999/08/11 21:01:11 keil
38 * Revision 1.8 1999/08/10 16:02:20 calle
39 * struct pci_dev changed in 2.3.13. Made the necessary changes.
41 * Revision 1.7 1999/06/09 19:31:29 armin
42 * Wrong PLX size for request_region() corrected.
43 * Added first MCA code from Erik Weber.
45 * Revision 1.6 1999/04/01 12:48:37 armin
46 * Changed some log outputs.
48 * Revision 1.5 1999/03/29 11:19:49 armin
49 * I/O stuff now in seperate file (eicon_io.c)
50 * Old ISA type cards (S,SX,SCOM,Quadro,S2M) implemented.
52 * Revision 1.4 1999/03/02 12:37:48 armin
53 * Added some important checks.
54 * Analog Modem with DSP.
55 * Channels will be added to Link-Level after loading firmware.
57 * Revision 1.3 1999/01/24 20:14:24 armin
58 * Changed and added debug stuff.
59 * Better data sending. (still problems with tty's flip buffer)
61 * Revision 1.2 1999/01/10 18:46:06 armin
62 * Bug with wrong values in HLC fixed.
63 * Bytes to send are counted and limited now.
65 * Revision 1.1 1999/01/01 18:09:45 armin
66 * First checkin of new eicon driver.
67 * DIVA-Server BRI/PCI and PRI/PCI are supported.
68 * Old diehl code is obsolete.
73 #include <linux/config.h>
74 #include <linux/pci.h>
77 #include "eicon_pci.h"
80 char *eicon_pci_revision
= "$Revision: 1.10 $";
82 #if CONFIG_PCI /* intire stuff is only for PCI */
84 #undef EICON_PCI_DEBUG
86 int eicon_pci_find_card(char *ID
)
89 struct pci_dev
*pdev
= NULL
;
90 int pci_nextindex
=0, pci_cards
=0, pci_akt
=0;
91 int pci_type
= PCI_MAESTRA
;
92 int NoMorePCICards
= FALSE
;
93 char *ram
, *reg
, *cfg
;
94 unsigned int pram
=0, preg
=0, pcfg
=0;
96 eicon_pci_card
*aparms
;
98 if (!(aparms
= (eicon_pci_card
*) kmalloc(sizeof(eicon_pci_card
), GFP_KERNEL
))) {
100 "eicon_pci: Could not allocate card-struct.\n");
104 for (pci_cards
= 0; pci_cards
< 0x0f; pci_cards
++)
107 if ((pdev
= pci_find_device(PCI_VENDOR_EICON
,
116 switch (pci_type
) /* switch to next card type */
119 pci_type
= PCI_MAESTRAQ
; break;
121 pci_type
= PCI_MAESTRAQ_U
; break;
123 pci_type
= PCI_MAESTRAP
; break;
126 NoMorePCICards
= TRUE
;
130 while (!NoMorePCICards
);
134 printk(KERN_INFO
"Eicon: No supported PCI cards found.\n");
140 printk(KERN_INFO
"Eicon: %d PCI card%s registered.\n",
141 pci_cards
, (pci_cards
> 1) ? "s":"");
151 printk(KERN_INFO
"Eicon: DIVA Server BRI/PCI detected !\n");
152 aparms
->type
= EICON_CTYPE_MAESTRA
;
154 aparms
->irq
= pdev
->irq
;
155 preg
= get_pcibase(pdev
, 2) & 0xfffffffc;
156 pcfg
= get_pcibase(pdev
, 1) & 0xffffff80;
158 #ifdef EICON_PCI_DEBUG
159 printk(KERN_DEBUG
"eicon_pci: irq=%d\n", aparms
->irq
);
160 printk(KERN_DEBUG
"eicon_pci: reg=0x%x\n", preg
);
161 printk(KERN_DEBUG
"eicon_pci: cfg=0x%x\n", pcfg
);
168 printk(KERN_ERR
"Eicon: DIVA Server 4BRI/PCI detected but not supported !\n");
174 printk(KERN_INFO
"Eicon: DIVA Server PRI/PCI detected !\n");
175 aparms
->type
= EICON_CTYPE_MAESTRAP
; /*includes 9M,30M*/
176 aparms
->irq
= pdev
->irq
;
177 pram
= get_pcibase(pdev
, 0) & 0xfffff000;
178 preg
= get_pcibase(pdev
, 2) & 0xfffff000;
179 pcfg
= get_pcibase(pdev
, 4) & 0xfffff000;
181 #ifdef EICON_PCI_DEBUG
182 printk(KERN_DEBUG
"eicon_pci: irq=%d\n", aparms
->irq
);
183 printk(KERN_DEBUG
"eicon_pci: ram=0x%x\n",
185 printk(KERN_DEBUG
"eicon_pci: reg=0x%x\n",
187 printk(KERN_DEBUG
"eicon_pci: cfg=0x%x\n",
193 printk(KERN_ERR
"eicon_pci: Unknown PCI card detected !\n");
200 /* remapping memory */
204 aparms
->PCIreg
= (unsigned int) preg
;
205 aparms
->PCIcfg
= (unsigned int) pcfg
;
206 if (check_region((aparms
->PCIreg
), 0x20)) {
207 printk(KERN_WARNING
"eicon_pci: reg port already in use !\n");
211 request_region(aparms
->PCIreg
, 0x20, "eicon reg");
213 if (check_region((aparms
->PCIcfg
), 0x80)) {
214 printk(KERN_WARNING
"eicon_pci: cfg port already in use !\n");
216 release_region(aparms
->PCIreg
, 0x20);
219 request_region(aparms
->PCIcfg
, 0x80, "eicon cfg");
225 aparms
->shmem
= (eicon_pci_shmem
*) ioremap(pram
, 0x10000);
226 ram
= (u8
*) ((u32
)aparms
->shmem
+ MP_SHARED_RAM_OFFSET
);
227 reg
= ioremap(preg
, 0x4000);
228 cfg
= ioremap(pcfg
, 0x1000);
229 aparms
->PCIram
= (unsigned int) ram
;
230 aparms
->PCIreg
= (unsigned int) reg
;
231 aparms
->PCIcfg
= (unsigned int) cfg
;
234 if ((!aparms
->PCIreg
) || (!aparms
->PCIcfg
)) {
235 printk(KERN_ERR
"eicon_pci: Card could not be added !\n");
240 sprintf(did
, "%s%d", (strlen(ID
) < 1) ? "eicon":ID
, pci_cards
);
242 printk(KERN_INFO
"%s: DriverID: '%s'\n",eicon_ctype_name
[aparms
->type
] , did
);
244 if (!(eicon_addcard(aparms
->type
, (int) aparms
, aparms
->irq
, did
))) {
245 printk(KERN_ERR
"eicon_pci: Card could not be added !\n");
253 printk(KERN_ERR
"eicon_pci: Kernel compiled with PCI but no PCI-bios found !\n");
258 * Checks protocol file id for "F#xxxx" string fragment to
259 * extract the features, supported by this protocol version.
260 * binary representation of the feature string value is returned
261 * in *value. The function returns 0 if feature string was not
262 * found or has a wrong format, else 1.
264 static int GetProtFeatureValue(char *sw_id
, int *value
)
270 if ((sw_id
[0] == 'F') && (sw_id
[1] == '#'))
273 for (i
=0, *value
=0; i
<4; i
++, sw_id
++)
275 if ((*sw_id
>= '0') && (*sw_id
<= '9'))
279 else if ((*sw_id
>= 'A') && (*sw_id
<= 'F'))
283 else if ((*sw_id
>= 'a') && (*sw_id
<= 'f'))
291 *value
|= (*sw_id
- offset
) << (4*(3-i
));
305 eicon_pci_printpar(eicon_pci_card
*card
) {
306 switch (card
->type
) {
307 case EICON_CTYPE_MAESTRA
:
308 printk(KERN_INFO
"%s at 0x%x / 0x%x, irq %d\n",
309 eicon_ctype_name
[card
->type
],
310 (unsigned int)card
->PCIreg
,
311 (unsigned int)card
->PCIcfg
,
314 case EICON_CTYPE_MAESTRAQ
:
315 case EICON_CTYPE_MAESTRAQ_U
:
316 case EICON_CTYPE_MAESTRAP
:
317 printk(KERN_INFO
"%s at 0x%x, irq %d\n",
318 eicon_ctype_name
[card
->type
],
319 (unsigned int)card
->shmem
,
321 #ifdef EICON_PCI_DEBUG
322 printk(KERN_INFO
"eicon_pci: remapped ram= 0x%x\n",(unsigned int)card
->PCIram
);
323 printk(KERN_INFO
"eicon_pci: remapped reg= 0x%x\n",(unsigned int)card
->PCIreg
);
324 printk(KERN_INFO
"eicon_pci: remapped cfg= 0x%x\n",(unsigned int)card
->PCIcfg
);
332 eicon_pci_release_shmem(eicon_pci_card
*card
) {
336 switch (card
->type
) {
337 case EICON_CTYPE_MAESTRA
:
339 outb(0, card
->PCIcfg
+ 0x4c); /* disable interrupts from PLX */
340 outb(0, card
->PCIreg
+ M_RESET
);
342 outb(0, card
->PCIreg
+ M_ADDRH
);
343 outw(0, card
->PCIreg
+ M_ADDR
);
344 outw(0, card
->PCIreg
+ M_DATA
);
346 release_region(card
->PCIreg
, 0x20);
347 release_region(card
->PCIcfg
, 0x80);
349 case EICON_CTYPE_MAESTRAQ
:
350 case EICON_CTYPE_MAESTRAQ_U
:
351 case EICON_CTYPE_MAESTRAP
:
353 writeb(_MP_RISC_RESET
| _MP_LED1
| _MP_LED2
, card
->PCIreg
+ MP_RESET
);
355 writeb(0, card
->PCIreg
+ MP_RESET
);
358 iounmap((void *)card
->shmem
);
359 iounmap((void *)card
->PCIreg
);
360 iounmap((void *)card
->PCIcfg
);
368 eicon_pci_release_irq(eicon_pci_card
*card
) {
372 free_irq(card
->irq
, card
);
377 eicon_pci_release(eicon_pci_card
*card
) {
378 eicon_pci_release_irq(card
);
379 eicon_pci_release_shmem(card
);
383 * Upload buffer content to adapters shared memory
384 * on verify error, 1 is returned and a message is printed on screen
386 * Can serve IO-Type and Memory type adapters
388 int eicon_upload(t_dsp_download_space
*p_para
,
389 __u16 length
, /* byte count */
393 __u32 i
, dwdata
= 0, val
= 0, timeout
;
395 eicon_pci_boot
*boot
= 0;
397 switch (p_para
->type
) /* actions depend on type of union */
399 case DL_PARA_IO_TYPE
:
400 for (i
=0; i
<length
; i
+=2)
402 outb ((u8
) ((p_para
->dat
.io
.r3addr
+ i
) >> 16), p_para
->dat
.io
.ioADDRH
);
403 outw ((u16
) (p_para
->dat
.io
.r3addr
+ i
), p_para
->dat
.io
.ioADDR
);
404 /* outw (((u16 *)code)[i >> 1], p_para->dat.io.ioDATA); */
405 outw (*(u16
*)&buffer
[i
], p_para
->dat
.io
.ioDATA
);
407 if (verify
) /* check written block */
409 for (i
=0; i
<length
; i
+=2)
411 outb ((u8
) ((p_para
->dat
.io
.r3addr
+ i
) >> 16), p_para
->dat
.io
.ioADDRH
);
412 outw ((u16
) (p_para
->dat
.io
.r3addr
+ i
), p_para
->dat
.io
.ioADDR
);
413 data
= inw(p_para
->dat
.io
.ioDATA
);
414 if (data
!= *(u16
*)&buffer
[i
])
416 p_para
->dat
.io
.r3addr
+= i
;
417 p_para
->dat
.io
.BadData
= data
;
418 p_para
->dat
.io
.GoodData
= *(u16
*)&buffer
[i
];
425 case DL_PARA_MEM_TYPE
:
426 boot
= p_para
->dat
.mem
.boot
;
427 writel(p_para
->dat
.mem
.r3addr
, &boot
->addr
);
428 for (i
=0; i
<length
; i
+=4)
430 writel(((u32
*)buffer
)[i
>> 2], &boot
->data
[i
]);
432 if (verify
) /* check written block */
434 for (i
=0; i
<length
; i
+=4)
436 dwdata
= readl(&boot
->data
[i
]);
437 if (((u32
*)buffer
)[i
>> 2] != dwdata
)
439 p_para
->dat
.mem
.r3addr
+= i
;
440 p_para
->dat
.mem
.BadData
= dwdata
;
441 p_para
->dat
.mem
.GoodData
= ((u32
*)buffer
)[i
>> 2];
446 writel(((length
+ 3) / 4), &boot
->len
); /* len in dwords */
447 writel(2, &boot
->cmd
);
449 timeout
= jiffies
+ 20;
450 while (timeout
> jiffies
) {
451 val
= readl(&boot
->cmd
);
457 p_para
->dat
.mem
.timeout
= 1;
466 /* show header information of code file */
468 int eicon_pci_print_hdr(unsigned char *code
, int offset
)
470 unsigned char hdr
[80];
474 while ((i
< (sizeof(hdr
) -1))
475 && (code
[offset
+ i
] != '\0')
476 && (code
[offset
+ i
] != '\r')
477 && (code
[offset
+ i
] != '\n'))
479 hdr
[i
] = code
[offset
+ i
];
483 printk(KERN_DEBUG
"Eicon: loading %s\n", hdr
);
484 if (GetProtFeatureValue(hdr
, &fvalue
)) return(fvalue
);
490 * Configure a card, download code into BRI card,
491 * check if we get interrupts and return 0 on succes.
492 * Return -ERRNO on failure.
495 eicon_pci_load_bri(eicon_pci_card
*card
, eicon_pci_codebuf
*cb
) {
498 unsigned int offset
, offp
=0, size
, length
;
500 int FeatureValue
= 0;
501 eicon_pci_codebuf cbuf
;
502 t_dsp_download_space dl_para
;
503 t_dsp_download_desc dsp_download_table
;
508 if (copy_from_user(&cbuf
, cb
, sizeof(eicon_pci_codebuf
)))
515 outb(0, reg
+ M_RESET
);
517 outb(0, reg
+ M_ADDRH
);
518 outw(0, reg
+ M_ADDR
);
519 outw(0, reg
+ M_DATA
);
521 #ifdef EICON_PCI_DEBUG
522 printk(KERN_DEBUG
"eicon_pci: reset card\n");
525 /* clear shared memory */
526 outb(0xff, reg
+ M_ADDRH
);
527 outw(0, reg
+ M_ADDR
);
528 for(i
= 0; i
< 0xffff; i
++) outw(0, reg
+ M_DATA
);
531 #ifdef EICON_PCI_DEBUG
532 printk(KERN_DEBUG
"eicon_pci: clear shared memory\n");
535 /* download protocol and dsp file */
537 #ifdef EICON_PCI_DEBUG
538 printk(KERN_DEBUG
"eicon_pci: downloading firmware...\n");
541 /* Allocate code-buffer */
542 if (!(code
= kmalloc(400, GFP_KERNEL
))) {
543 printk(KERN_WARNING
"eicon_pci_boot: Couldn't allocate code buffer\n");
547 /* prepare protocol upload */
548 dl_para
.type
= DL_PARA_IO_TYPE
;
549 dl_para
.dat
.io
.ioADDR
= reg
+ M_ADDR
;
550 dl_para
.dat
.io
.ioADDRH
= reg
+ M_ADDRH
;
551 dl_para
.dat
.io
.ioDATA
= reg
+ M_DATA
;
553 for (j
= 0; j
<= cbuf
.dsp_code_num
; j
++)
555 if (j
== 0) size
= cbuf
.protocol_len
;
556 else size
= cbuf
.dsp_code_len
[j
];
560 if (j
== 0) dl_para
.dat
.io
.r3addr
= 0;
561 if (j
== 1) dl_para
.dat
.io
.r3addr
= M_DSP_CODE_BASE
+
562 ((sizeof(__u32
) + (sizeof(dsp_download_table
) * 35) + 3) &0xfffffffc);
563 if (j
== 2) dl_para
.dat
.io
.r3addr
= M_DSP_CODE_BASE
;
564 if (j
== 3) dl_para
.dat
.io
.r3addr
= M_DSP_CODE_BASE
+ sizeof(__u32
);
566 do /* download block of up to 400 bytes */
568 length
= ((size
- offset
) >= 400) ? 400 : (size
- offset
);
570 if (copy_from_user(code
, (&cb
->code
) + offp
+ offset
, length
)) {
575 if ((offset
== 0) && (j
< 2)) {
576 FeatureValue
= eicon_pci_print_hdr(code
, j
? 0x00 : 0x80);
577 #ifdef EICON_PCI_DEBUG
578 if (FeatureValue
) printk(KERN_DEBUG
"eicon_pci: Feature Value : 0x%04x.\n", FeatureValue
);
580 if ((j
==0) && (!(FeatureValue
& PROTCAP_TELINDUS
))) {
581 printk(KERN_ERR
"eicon_pci: Protocol Code cannot handle Telindus\n");
585 ((eicon_card
*)card
->card
)->Feature
= FeatureValue
;
588 if (eicon_upload(&dl_para
, length
, code
, 1))
590 printk(KERN_ERR
"eicon_pci: code block check failed at 0x%x !\n",dl_para
.dat
.io
.r3addr
);
594 /* move onto next block */
596 dl_para
.dat
.io
.r3addr
+= length
;
597 } while (offset
< size
);
599 #ifdef EICON_PCI_DEBUG
600 printk(KERN_DEBUG
"Eicon: %d bytes loaded.\n", offset
);
606 /* clear signature */
607 outb(0xff, reg
+ M_ADDRH
);
608 outw(0x1e, reg
+ M_ADDR
);
609 outw(0, reg
+ M_DATA
);
611 #ifdef EICON_PCI_DEBUG
612 printk(KERN_DEBUG
"eicon_pci: copy configuration data into shared memory...\n");
614 /* copy configuration data into shared memory */
615 outw(8, reg
+ M_ADDR
); outb(cbuf
.tei
, reg
+ M_DATA
);
616 outw(9, reg
+ M_ADDR
); outb(cbuf
.nt2
, reg
+ M_DATA
);
617 outw(10,reg
+ M_ADDR
); outb(0, reg
+ M_DATA
);
618 outw(11,reg
+ M_ADDR
); outb(cbuf
.WatchDog
, reg
+ M_DATA
);
619 outw(12,reg
+ M_ADDR
); outb(cbuf
.Permanent
, reg
+ M_DATA
);
620 outw(13,reg
+ M_ADDR
); outb(0, reg
+ M_DATA
); /* XInterface */
621 outw(14,reg
+ M_ADDR
); outb(cbuf
.StableL2
, reg
+ M_DATA
);
622 outw(15,reg
+ M_ADDR
); outb(cbuf
.NoOrderCheck
, reg
+ M_DATA
);
623 outw(16,reg
+ M_ADDR
); outb(0, reg
+ M_DATA
); /* HandsetType */
624 outw(17,reg
+ M_ADDR
); outb(0, reg
+ M_DATA
); /* SigFlags */
625 outw(18,reg
+ M_ADDR
); outb(cbuf
.LowChannel
, reg
+ M_DATA
);
626 outw(19,reg
+ M_ADDR
); outb(cbuf
.ProtVersion
, reg
+ M_DATA
);
627 outw(20,reg
+ M_ADDR
); outb(cbuf
.Crc4
, reg
+ M_DATA
);
628 outw(21,reg
+ M_ADDR
); outb((cbuf
.Loopback
) ? 2:0, reg
+ M_DATA
);
632 outw( 32+i
, reg
+ M_ADDR
); outb(cbuf
.l
[0].oad
[i
], reg
+ M_DATA
);
633 outw( 64+i
, reg
+ M_ADDR
); outb(cbuf
.l
[0].osa
[i
], reg
+ M_DATA
);
634 outw( 96+i
, reg
+ M_ADDR
); outb(cbuf
.l
[0].spid
[i
], reg
+ M_DATA
);
635 outw(128+i
, reg
+ M_ADDR
); outb(cbuf
.l
[1].oad
[i
], reg
+ M_DATA
);
636 outw(160+i
, reg
+ M_ADDR
); outb(cbuf
.l
[1].osa
[i
], reg
+ M_DATA
);
637 outw(192+i
, reg
+ M_ADDR
); outb(cbuf
.l
[1].spid
[i
], reg
+ M_DATA
);
640 #ifdef EICON_PCI_DEBUG
641 printk(KERN_ERR
"eicon_pci: starting CPU...\n");
643 /* let the CPU run */
644 outw(0x08, reg
+ M_RESET
);
646 timeout
= jiffies
+ (5*HZ
);
647 while (timeout
> jiffies
) {
648 outw(0x1e, reg
+ M_ADDR
);
649 signature
= inw(reg
+ M_DATA
);
650 if (signature
== DIVAS_SIGNATURE
) break;
653 if (signature
!= DIVAS_SIGNATURE
)
655 #ifdef EICON_PCI_DEBUG
656 printk(KERN_ERR
"eicon_pci: signature 0x%x expected 0x%x\n",signature
,DIVAS_SIGNATURE
);
658 printk(KERN_ERR
"eicon_pci: Timeout, protocol code not running !\n");
661 #ifdef EICON_PCI_DEBUG
662 printk(KERN_DEBUG
"eicon_pci: Protocol code running, signature OK\n");
665 /* get serial number and number of channels supported by card */
666 outb(0xff, reg
+ M_ADDRH
);
667 outw(0x3f6, reg
+ M_ADDR
);
668 card
->channels
= inw(reg
+ M_DATA
);
669 card
->serial
= (u32
)inw(cfg
+ 0x22) << 16 | (u32
)inw(cfg
+ 0x26);
670 printk(KERN_INFO
"Eicon: Supported channels : %d\n", card
->channels
);
671 printk(KERN_INFO
"Eicon: Card serial no. = %lu\n", card
->serial
);
677 if (request_irq(card
->irq
, &eicon_irq
, 0, "Eicon PCI ISDN", card
->card
))
679 printk(KERN_ERR
"eicon_pci: Couldn't request irq %d\n", card
->irq
);
685 #ifdef EICON_PCI_DEBUG
686 printk(KERN_DEBUG
"eicon_pci: testing interrupt\n");
688 /* Trigger an interrupt and check if it is delivered */
689 outb(0x41, cfg
+ 0x4c); /* enable PLX for interrupts */
690 outb(0x89, reg
+ M_RESET
); /* place int request */
692 timeout
= jiffies
+ 20;
693 while (timeout
> jiffies
) {
694 if (card
->irqprobe
!= 1) break;
697 if (card
->irqprobe
== 1) {
698 free_irq(card
->irq
, card
);
700 printk(KERN_ERR
"eicon_pci: Getting no interrupts !\n");
704 /* initializing some variables */
705 ((eicon_card
*)card
->card
)->ReadyInt
= 0;
706 for(j
=0; j
<256; j
++) ((eicon_card
*)card
->card
)->IdTable
[j
] = NULL
;
707 for(j
=0; j
< (card
->channels
+ 1); j
++) {
708 ((eicon_card
*)card
->card
)->bch
[j
].e
.busy
= 0;
709 ((eicon_card
*)card
->card
)->bch
[j
].e
.D3Id
= 0;
710 ((eicon_card
*)card
->card
)->bch
[j
].e
.B2Id
= 0;
711 ((eicon_card
*)card
->card
)->bch
[j
].e
.ref
= 0;
712 ((eicon_card
*)card
->card
)->bch
[j
].e
.Req
= 0;
713 ((eicon_card
*)card
->card
)->bch
[j
].e
.complete
= 1;
714 ((eicon_card
*)card
->card
)->bch
[j
].fsm_state
= EICON_STATE_NULL
;
717 printk(KERN_INFO
"Eicon: Card successfully started\n");
724 * Configure a card, download code into PRI card,
725 * check if we get interrupts and return 0 on succes.
726 * Return -ERRNO on failure.
729 eicon_pci_load_pri(eicon_pci_card
*card
, eicon_pci_codebuf
*cb
) {
730 eicon_pci_boot
*boot
;
734 int FeatureValue
= 0;
735 unsigned int offset
, offp
=0, size
, length
;
736 unsigned long int signature
= 0;
737 t_dsp_download_space dl_para
;
738 t_dsp_download_desc dsp_download_table
;
739 eicon_pci_codebuf cbuf
;
741 unsigned char req_int
;
742 char *ram
, *reg
, *cfg
;
744 if (copy_from_user(&cbuf
, cb
, sizeof(eicon_pci_codebuf
)))
747 boot
= &card
->shmem
->boot
;
748 ram
= (char *)card
->PCIram
;
749 reg
= (char *)card
->PCIreg
;
750 cfg
= (char *)card
->PCIcfg
;
751 prram
= (eicon_pr_ram
*)ram
;
754 writeb(_MP_RISC_RESET
| _MP_LED1
| _MP_LED2
, card
->PCIreg
+ MP_RESET
);
756 writeb(0, card
->PCIreg
+ MP_RESET
);
759 /* set command count to 0 */
760 writel(0, &boot
->reserved
);
762 /* check if CPU increments the life word */
763 i
= readw(&boot
->live
);
765 if (i
== readw(&boot
->live
)) {
766 printk(KERN_ERR
"eicon_pci: card is reset, but CPU not running !\n");
769 #ifdef EICON_PCI_DEBUG
770 printk(KERN_DEBUG
"eicon_pci: reset card OK (CPU running)\n");
773 /* download firmware : DSP and Protocol */
774 #ifdef EICON_PCI_DEBUG
775 printk(KERN_DEBUG
"eicon_pci: downloading firmware...\n");
778 /* Allocate code-buffer */
779 if (!(code
= kmalloc(400, GFP_KERNEL
))) {
780 printk(KERN_WARNING
"eicon_pci_boot: Couldn't allocate code buffer\n");
784 /* prepare protocol upload */
785 dl_para
.type
= DL_PARA_MEM_TYPE
;
786 dl_para
.dat
.mem
.boot
= boot
;
788 for (j
= 0; j
<= cbuf
.dsp_code_num
; j
++)
790 if (j
==0) size
= cbuf
.protocol_len
;
791 else size
= cbuf
.dsp_code_len
[j
];
793 if (j
==1) writel(MP_DSP_ADDR
, &boot
->addr
); /* DSP code entry point */
795 if (j
== 0) dl_para
.dat
.io
.r3addr
= MP_PROTOCOL_ADDR
;
796 if (j
== 1) dl_para
.dat
.io
.r3addr
= MP_DSP_CODE_BASE
+
797 ((sizeof(__u32
) + (sizeof(dsp_download_table
) * 35) + 3) &0xfffffffc);
798 if (j
== 2) dl_para
.dat
.io
.r3addr
= MP_DSP_CODE_BASE
;
799 if (j
== 3) dl_para
.dat
.io
.r3addr
= MP_DSP_CODE_BASE
+ sizeof(__u32
);
802 do /* download block of up to 400 bytes */
804 length
= ((size
- offset
) >= 400) ? 400 : (size
- offset
);
806 if (copy_from_user(code
, (&cb
->code
) + offp
+ offset
, length
)) {
811 if ((offset
== 0) && (j
< 2)) {
812 FeatureValue
= eicon_pci_print_hdr(code
, j
? 0x00 : 0x80);
813 #ifdef EICON_PCI_DEBUG
814 if (FeatureValue
) printk(KERN_DEBUG
"eicon_pci: Feature Value : 0x%x.\n", FeatureValue
);
816 if ((j
==0) && (!(FeatureValue
& PROTCAP_TELINDUS
))) {
817 printk(KERN_ERR
"eicon_pci: Protocol Code cannot handle Telindus\n");
821 ((eicon_card
*)card
->card
)->Feature
= FeatureValue
;
824 if (eicon_upload(&dl_para
, length
, code
, 1))
826 if (dl_para
.dat
.mem
.timeout
== 0)
827 printk(KERN_ERR
"eicon_pci: code block check failed at 0x%x !\n",dl_para
.dat
.io
.r3addr
);
829 printk(KERN_ERR
"eicon_pci: timeout, no ACK to load !\n");
834 /* move onto next block */
836 dl_para
.dat
.mem
.r3addr
+= length
;
837 } while (offset
< size
);
838 #ifdef EICON_PCI_DEBUG
839 printk(KERN_DEBUG
"eicon_pci: %d bytes loaded.\n", offset
);
845 /* initialize the adapter data structure */
846 #ifdef EICON_PCI_DEBUG
847 printk(KERN_DEBUG
"eicon_pci: copy configuration data into shared memory...\n");
849 /* clear out config space */
850 for (i
= 0; i
< 256; i
++) writeb(0, &ram
[i
]);
852 /* copy configuration down to the card */
853 writeb(cbuf
.tei
, &ram
[8]);
854 writeb(cbuf
.nt2
, &ram
[9]);
856 writeb(cbuf
.WatchDog
, &ram
[11]);
857 writeb(cbuf
.Permanent
, &ram
[12]);
858 writeb(cbuf
.XInterface
, &ram
[13]);
859 writeb(cbuf
.StableL2
, &ram
[14]);
860 writeb(cbuf
.NoOrderCheck
, &ram
[15]);
861 writeb(cbuf
.HandsetType
, &ram
[16]);
863 writeb(cbuf
.LowChannel
, &ram
[18]);
864 writeb(cbuf
.ProtVersion
, &ram
[19]);
865 writeb(cbuf
.Crc4
, &ram
[20]);
866 for (i
= 0; i
< 32; i
++)
868 writeb(cbuf
.l
[0].oad
[i
], &ram
[32 + i
]);
869 writeb(cbuf
.l
[0].osa
[i
], &ram
[64 + i
]);
870 writeb(cbuf
.l
[0].spid
[i
], &ram
[96 + i
]);
871 writeb(cbuf
.l
[1].oad
[i
], &ram
[128 + i
]);
872 writeb(cbuf
.l
[1].osa
[i
], &ram
[160 + i
]);
873 writeb(cbuf
.l
[1].spid
[i
], &ram
[192 + i
]);
875 #ifdef EICON_PCI_DEBUG
876 printk(KERN_DEBUG
"eicon_pci: configured card OK\n");
880 #ifdef EICON_PCI_DEBUG
881 printk(KERN_DEBUG
"eicon_pci: tell card to start...\n");
883 writel(MP_PROTOCOL_ADDR
, &boot
->addr
); /* RISC code entry point */
884 writel(3, &boot
->cmd
); /* DIVAS_START_CMD */
886 /* wait till card ACKs */
887 timeout
= jiffies
+ (5*HZ
);
888 while (timeout
> jiffies
) {
889 signature
= readl(&boot
->signature
);
890 if ((signature
>> 16) == DIVAS_SIGNATURE
) break;
893 if ((signature
>> 16) != DIVAS_SIGNATURE
)
895 #ifdef EICON_PCI_DEBUG
896 printk(KERN_ERR
"eicon_pci: signature 0x%lx expected 0x%x\n",(signature
>> 16),DIVAS_SIGNATURE
);
898 printk(KERN_ERR
"eicon_pci: timeout, protocol code not running !\n");
901 #ifdef EICON_PCI_DEBUG
902 printk(KERN_DEBUG
"eicon_pci: Protocol code running, signature OK\n");
905 /* get serial number and number of channels supported by card */
906 card
->channels
= readb(&ram
[0x3f6]);
907 card
->serial
= readl(&ram
[0x3f0]);
908 printk(KERN_INFO
"Eicon: Supported channels : %d\n", card
->channels
);
909 printk(KERN_INFO
"Eicon: Card serial no. = %lu\n", card
->serial
);
913 writeb(0, &ram
[0x3fe]); /* reset any pending interrupt */
916 writew(MP_IRQ_RESET_VAL
, &cfg
[MP_IRQ_RESET
]);
917 writew(0, &cfg
[MP_IRQ_RESET
+ 2]);
922 if (request_irq(card
->irq
, &eicon_irq
, 0, "Eicon PCI ISDN", card
->card
))
924 printk(KERN_ERR
"eicon_pci: Couldn't request irq %d\n", card
->irq
);
930 req_int
= readb(&prram
->ReadyInt
);
931 #ifdef EICON_PCI_DEBUG
932 printk(KERN_DEBUG
"eicon_pci: testing interrupt\n");
935 /* Trigger an interrupt and check if it is delivered */
936 writeb(req_int
, &prram
->ReadyInt
);
938 timeout
= jiffies
+ 20;
939 while (timeout
> jiffies
) {
940 if (card
->irqprobe
!= 1) break;
943 if (card
->irqprobe
== 1) {
944 free_irq(card
->irq
, card
);
946 printk(KERN_ERR
"eicon_pci: Getting no interrupts !\n");
950 /* initializing some variables */
951 ((eicon_card
*)card
->card
)->ReadyInt
= 0;
952 for(j
=0; j
<256; j
++) ((eicon_card
*)card
->card
)->IdTable
[j
] = NULL
;
953 for(j
=0; j
< (card
->channels
+ 1); j
++) {
954 ((eicon_card
*)card
->card
)->bch
[j
].e
.busy
= 0;
955 ((eicon_card
*)card
->card
)->bch
[j
].e
.D3Id
= 0;
956 ((eicon_card
*)card
->card
)->bch
[j
].e
.B2Id
= 0;
957 ((eicon_card
*)card
->card
)->bch
[j
].e
.ref
= 0;
958 ((eicon_card
*)card
->card
)->bch
[j
].e
.Req
= 0;
959 ((eicon_card
*)card
->card
)->bch
[j
].e
.complete
= 1;
960 ((eicon_card
*)card
->card
)->bch
[j
].fsm_state
= EICON_STATE_NULL
;
963 printk(KERN_INFO
"Eicon: Card successfully started\n");
968 #endif /* CONFIG_PCI */