1 /* $Id: os_bri.c,v 1.21 2004/03/21 17:26:01 armin Exp $ */
14 #include "xdi_adapter.h"
24 extern void prepare_maestra_functions(PISDN_ADAPTER IoAdapter
);
25 extern void diva_xdi_display_adapter_features(int card
);
26 extern int diva_card_read_xlog(diva_os_xdi_adapter_t
* a
);
31 static int bri_bar_length
[3] = {
36 static int diva_bri_cleanup_adapter(diva_os_xdi_adapter_t
* a
);
37 static dword
diva_bri_get_serial_number(diva_os_xdi_adapter_t
* a
);
38 static int diva_bri_cmd_card_proc(struct _diva_os_xdi_adapter
*a
,
39 diva_xdi_um_cfg_cmd_t
* cmd
, int length
);
40 static int diva_bri_reregister_io(diva_os_xdi_adapter_t
* a
);
41 static int diva_bri_reset_adapter(PISDN_ADAPTER IoAdapter
);
42 static int diva_bri_write_sdram_block(PISDN_ADAPTER IoAdapter
,
44 const byte
* data
, dword length
);
45 static int diva_bri_start_adapter(PISDN_ADAPTER IoAdapter
,
46 dword start_address
, dword features
);
47 static int diva_bri_stop_adapter(diva_os_xdi_adapter_t
* a
);
49 static void diva_bri_set_addresses(diva_os_xdi_adapter_t
* a
)
51 a
->resources
.pci
.mem_type_id
[MEM_TYPE_RAM
] = 0;
52 a
->resources
.pci
.mem_type_id
[MEM_TYPE_CFG
] = 1;
53 a
->resources
.pci
.mem_type_id
[MEM_TYPE_ADDRESS
] = 2;
54 a
->resources
.pci
.mem_type_id
[MEM_TYPE_RESET
] = 1;
55 a
->resources
.pci
.mem_type_id
[MEM_TYPE_PORT
] = 2;
56 a
->resources
.pci
.mem_type_id
[MEM_TYPE_CTLREG
] = 2;
58 a
->xdi_adapter
.ram
= a
->resources
.pci
.addr
[0];
59 a
->xdi_adapter
.cfg
= a
->resources
.pci
.addr
[1];
60 a
->xdi_adapter
.Address
= a
->resources
.pci
.addr
[2];
62 a
->xdi_adapter
.reset
= a
->xdi_adapter
.cfg
;
63 a
->xdi_adapter
.port
= a
->xdi_adapter
.Address
;
65 a
->xdi_adapter
.ctlReg
= a
->xdi_adapter
.port
+ M_PCI_RESET
;
67 a
->xdi_adapter
.reset
+= 0x4C; /* PLX 9050 !! */
71 ** BAR0 - MEM Addr - 0x80 - NOT USED
72 ** BAR1 - I/O Addr - 0x80
73 ** BAR2 - I/O Addr - 0x20
75 int diva_bri_init_card(diva_os_xdi_adapter_t
* a
)
78 dword bar2
= 0, bar2_length
= 0xffffffff;
79 word cmd
= 0, cmd_org
;
87 a
->xdi_adapter
.Properties
= CardProperties
[a
->CardOrdinal
];
88 DBG_LOG(("Load %s", a
->xdi_adapter
.Properties
.Name
))
93 for (bar
= 0; bar
< 3; bar
++) {
94 a
->resources
.pci
.bar
[bar
] =
95 divasa_get_pci_bar(a
->resources
.pci
.bus
,
96 a
->resources
.pci
.func
, bar
,
97 a
->resources
.pci
.hdev
);
98 if (!a
->resources
.pci
.bar
[bar
]) {
99 DBG_ERR(("A: can't get BAR[%d]", bar
))
104 a
->resources
.pci
.irq
=
105 (byte
) divasa_get_pci_irq(a
->resources
.pci
.bus
,
106 a
->resources
.pci
.func
,
107 a
->resources
.pci
.hdev
);
108 if (!a
->resources
.pci
.irq
) {
109 DBG_ERR(("A: invalid irq"));
114 Get length of I/O bar 2 - it is different by older
117 Bus
= a
->resources
.pci
.bus
;
118 Slot
= a
->resources
.pci
.func
;
119 hdev
= a
->resources
.pci
.hdev
;
122 Get plain original values of the BAR2 CDM registers
124 PCIread(Bus
, Slot
, 0x18, &bar2
, sizeof(bar2
), hdev
);
125 PCIread(Bus
, Slot
, 0x04, &cmd_org
, sizeof(cmd_org
), hdev
);
127 Disable device and get BAR2 length
129 PCIwrite(Bus
, Slot
, 0x04, &cmd
, sizeof(cmd
), hdev
);
130 PCIwrite(Bus
, Slot
, 0x18, &bar2_length
, sizeof(bar2_length
), hdev
);
131 PCIread(Bus
, Slot
, 0x18, &bar2_length
, sizeof(bar2_length
), hdev
);
133 Restore BAR2 and CMD registers
135 PCIwrite(Bus
, Slot
, 0x18, &bar2
, sizeof(bar2
), hdev
);
136 PCIwrite(Bus
, Slot
, 0x04, &cmd_org
, sizeof(cmd_org
), hdev
);
139 Calculate BAR2 length
141 bar2_length
= (~(bar2_length
& ~7)) + 1;
142 DBG_LOG(("BAR[2] length=%lx", bar2_length
))
145 Map and register resources
147 if (!(a
->resources
.pci
.addr
[0] =
148 divasa_remap_pci_bar(a
, 0, a
->resources
.pci
.bar
[0],
149 bri_bar_length
[0]))) {
150 DBG_ERR(("A: BRI, can't map BAR[0]"))
151 diva_bri_cleanup_adapter(a
);
155 sprintf(&a
->port_name
[0], "BRI %02x:%02x",
156 a
->resources
.pci
.bus
, a
->resources
.pci
.func
);
158 if (diva_os_register_io_port(a
, 1, a
->resources
.pci
.bar
[1],
159 bri_bar_length
[1], &a
->port_name
[0], 1)) {
160 DBG_ERR(("A: BRI, can't register BAR[1]"))
161 diva_bri_cleanup_adapter(a
);
164 a
->resources
.pci
.addr
[1] = (void *) (unsigned long) a
->resources
.pci
.bar
[1];
165 a
->resources
.pci
.length
[1] = bri_bar_length
[1];
167 if (diva_os_register_io_port(a
, 1, a
->resources
.pci
.bar
[2],
168 bar2_length
, &a
->port_name
[0], 2)) {
169 DBG_ERR(("A: BRI, can't register BAR[2]"))
170 diva_bri_cleanup_adapter(a
);
173 a
->resources
.pci
.addr
[2] = (void *) (unsigned long) a
->resources
.pci
.bar
[2];
174 a
->resources
.pci
.length
[2] = bar2_length
;
179 diva_bri_set_addresses(a
);
184 a
->xdi_adapter
.serialNo
= diva_bri_get_serial_number(a
);
187 Register I/O ports with correct name now
189 if (diva_bri_reregister_io(a
)) {
190 diva_bri_cleanup_adapter(a
);
195 Initialize OS dependent objects
197 if (diva_os_initialize_spin_lock
198 (&a
->xdi_adapter
.isr_spin_lock
, "isr")) {
199 diva_bri_cleanup_adapter(a
);
202 if (diva_os_initialize_spin_lock
203 (&a
->xdi_adapter
.data_spin_lock
, "data")) {
204 diva_bri_cleanup_adapter(a
);
208 strcpy(a
->xdi_adapter
.req_soft_isr
.dpc_thread_name
, "kdivasbrid");
210 if (diva_os_initialize_soft_isr(&a
->xdi_adapter
.req_soft_isr
,
211 DIDpcRoutine
, &a
->xdi_adapter
)) {
212 diva_bri_cleanup_adapter(a
);
216 Do not initialize second DPC - only one thread will be created
218 a
->xdi_adapter
.isr_soft_isr
.object
= a
->xdi_adapter
.req_soft_isr
.object
;
223 a
->xdi_adapter
.Channels
= CardProperties
[a
->CardOrdinal
].Channels
;
224 a
->xdi_adapter
.e_max
= CardProperties
[a
->CardOrdinal
].E_info
;
225 a
->xdi_adapter
.e_tbl
= diva_os_malloc(0, a
->xdi_adapter
.e_max
* sizeof(E_INFO
));
226 if (!a
->xdi_adapter
.e_tbl
) {
227 diva_bri_cleanup_adapter(a
);
230 memset(a
->xdi_adapter
.e_tbl
, 0x00, a
->xdi_adapter
.e_max
* sizeof(E_INFO
));
235 a
->xdi_adapter
.a
.io
= &a
->xdi_adapter
;
236 a
->xdi_adapter
.DIRequest
= request
;
237 a
->interface
.cleanup_adapter_proc
= diva_bri_cleanup_adapter
;
238 a
->interface
.cmd_proc
= diva_bri_cmd_card_proc
;
240 p
= DIVA_OS_MEM_ATTACH_RESET(&a
->xdi_adapter
);
242 DIVA_OS_MEM_DETACH_RESET(&a
->xdi_adapter
, p
);
244 prepare_maestra_functions(&a
->xdi_adapter
);
246 a
->dsp_mask
= 0x00000003;
251 a
->xdi_adapter
.irq_info
.irq_nr
= a
->resources
.pci
.irq
;
252 sprintf(a
->xdi_adapter
.irq_info
.irq_name
, "DIVA BRI %ld",
253 (long) a
->xdi_adapter
.serialNo
);
254 if (diva_os_register_irq(a
, a
->xdi_adapter
.irq_info
.irq_nr
,
255 a
->xdi_adapter
.irq_info
.irq_name
)) {
256 diva_bri_cleanup_adapter(a
);
259 a
->xdi_adapter
.irq_info
.registered
= 1;
261 diva_log_info("%s IRQ:%d SerNo:%d", a
->xdi_adapter
.Properties
.Name
,
262 a
->resources
.pci
.irq
, a
->xdi_adapter
.serialNo
);
268 static int diva_bri_cleanup_adapter(diva_os_xdi_adapter_t
* a
)
272 if (a
->xdi_adapter
.Initialized
) {
273 diva_bri_stop_adapter(a
);
279 if (a
->xdi_adapter
.irq_info
.registered
) {
280 diva_os_remove_irq(a
, a
->xdi_adapter
.irq_info
.irq_nr
);
282 a
->xdi_adapter
.irq_info
.registered
= 0;
284 if (a
->resources
.pci
.addr
[0] && a
->resources
.pci
.bar
[0]) {
285 divasa_unmap_pci_bar(a
->resources
.pci
.addr
[0]);
286 a
->resources
.pci
.addr
[0] = NULL
;
287 a
->resources
.pci
.bar
[0] = 0;
290 for (i
= 1; i
< 3; i
++) {
291 if (a
->resources
.pci
.addr
[i
] && a
->resources
.pci
.bar
[i
]) {
292 diva_os_register_io_port(a
, 0,
293 a
->resources
.pci
.bar
[i
],
296 &a
->port_name
[0], i
);
297 a
->resources
.pci
.addr
[i
] = NULL
;
298 a
->resources
.pci
.bar
[i
] = 0;
305 diva_os_cancel_soft_isr(&a
->xdi_adapter
.req_soft_isr
);
306 diva_os_cancel_soft_isr(&a
->xdi_adapter
.isr_soft_isr
);
308 diva_os_remove_soft_isr(&a
->xdi_adapter
.req_soft_isr
);
309 a
->xdi_adapter
.isr_soft_isr
.object
= NULL
;
311 diva_os_destroy_spin_lock(&a
->xdi_adapter
.isr_spin_lock
, "rm");
312 diva_os_destroy_spin_lock(&a
->xdi_adapter
.data_spin_lock
, "rm");
317 if (a
->xdi_adapter
.e_tbl
) {
318 diva_os_free(0, a
->xdi_adapter
.e_tbl
);
319 a
->xdi_adapter
.e_tbl
= NULL
;
325 void diva_os_prepare_maestra_functions(PISDN_ADAPTER IoAdapter
)
332 static dword
diva_bri_get_serial_number(diva_os_xdi_adapter_t
* a
)
335 byte __iomem
*confIO
;
337 word __iomem
*confMem
;
339 confIO
= DIVA_OS_MEM_ATTACH_CFG(&a
->xdi_adapter
);
340 serHi
= (word
) (inppw(&confIO
[0x22]) & 0x0FFF);
341 serLo
= (word
) (inppw(&confIO
[0x26]) & 0x0FFF);
342 serNo
= ((dword
) serHi
<< 16) | (dword
) serLo
;
343 DIVA_OS_MEM_DETACH_CFG(&a
->xdi_adapter
, confIO
);
345 if ((serNo
== 0) || (serNo
== 0xFFFFFFFF)) {
346 DBG_FTL(("W: BRI use BAR[0] to get card serial number"))
348 confMem
= (word __iomem
*)DIVA_OS_MEM_ATTACH_RAM(&a
->xdi_adapter
);
349 serHi
= (word
) (READ_WORD(&confMem
[0x11]) & 0x0FFF);
350 serLo
= (word
) (READ_WORD(&confMem
[0x13]) & 0x0FFF);
351 serNo
= (((dword
) serHi
) << 16) | ((dword
) serLo
);
352 DIVA_OS_MEM_DETACH_RAM(&a
->xdi_adapter
, confMem
);
355 DBG_LOG(("Serial Number=%ld", serNo
))
361 ** Unregister I/O and register it with new name,
362 ** based on Serial Number
364 static int diva_bri_reregister_io(diva_os_xdi_adapter_t
* a
)
368 for (i
= 1; i
< 3; i
++) {
369 diva_os_register_io_port(a
, 0, a
->resources
.pci
.bar
[i
],
370 a
->resources
.pci
.length
[i
],
371 &a
->port_name
[0], i
);
372 a
->resources
.pci
.addr
[i
] = NULL
;
375 sprintf(a
->port_name
, "DIVA BRI %ld",
376 (long) a
->xdi_adapter
.serialNo
);
378 for (i
= 1; i
< 3; i
++) {
379 if (diva_os_register_io_port(a
, 1, a
->resources
.pci
.bar
[i
],
380 a
->resources
.pci
.length
[i
],
381 &a
->port_name
[0], i
)) {
382 DBG_ERR(("A: failed to reregister BAR[%d]", i
))
385 a
->resources
.pci
.addr
[i
] =
386 (void *) (unsigned long) a
->resources
.pci
.bar
[i
];
393 ** Process command from user mode
396 diva_bri_cmd_card_proc(struct _diva_os_xdi_adapter
*a
,
397 diva_xdi_um_cfg_cmd_t
* cmd
, int length
)
401 if (cmd
->adapter
!= a
->controller
) {
402 DBG_ERR(("A: pri_cmd, invalid controller=%d != %d",
403 cmd
->adapter
, a
->controller
))
407 switch (cmd
->command
) {
408 case DIVA_XDI_UM_CMD_GET_CARD_ORDINAL
:
409 a
->xdi_mbox
.data_length
= sizeof(dword
);
411 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
412 if (a
->xdi_mbox
.data
) {
413 *(dword
*) a
->xdi_mbox
.data
=
414 (dword
) a
->CardOrdinal
;
415 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
420 case DIVA_XDI_UM_CMD_GET_SERIAL_NR
:
421 a
->xdi_mbox
.data_length
= sizeof(dword
);
423 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
424 if (a
->xdi_mbox
.data
) {
425 *(dword
*) a
->xdi_mbox
.data
=
426 (dword
) a
->xdi_adapter
.serialNo
;
427 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
432 case DIVA_XDI_UM_CMD_GET_PCI_HW_CONFIG
:
433 a
->xdi_mbox
.data_length
= sizeof(dword
) * 9;
435 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
436 if (a
->xdi_mbox
.data
) {
438 dword
*data
= (dword
*) a
->xdi_mbox
.data
;
440 for (i
= 0; i
< 8; i
++) {
441 *data
++ = a
->resources
.pci
.bar
[i
];
443 *data
++ = (dword
) a
->resources
.pci
.irq
;
444 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
449 case DIVA_XDI_UM_CMD_GET_CARD_STATE
:
450 a
->xdi_mbox
.data_length
= sizeof(dword
);
452 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
453 if (a
->xdi_mbox
.data
) {
454 dword
*data
= (dword
*) a
->xdi_mbox
.data
;
455 if (!a
->xdi_adapter
.port
) {
457 } else if (a
->xdi_adapter
.trapped
) {
459 } else if (a
->xdi_adapter
.Initialized
) {
464 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
469 case DIVA_XDI_UM_CMD_RESET_ADAPTER
:
470 ret
= diva_bri_reset_adapter(&a
->xdi_adapter
);
473 case DIVA_XDI_UM_CMD_WRITE_SDRAM_BLOCK
:
474 ret
= diva_bri_write_sdram_block(&a
->xdi_adapter
,
482 case DIVA_XDI_UM_CMD_START_ADAPTER
:
483 ret
= diva_bri_start_adapter(&a
->xdi_adapter
,
484 cmd
->command_data
.start
.
486 cmd
->command_data
.start
.
490 case DIVA_XDI_UM_CMD_SET_PROTOCOL_FEATURES
:
491 a
->xdi_adapter
.features
=
492 cmd
->command_data
.features
.features
;
493 a
->xdi_adapter
.a
.protocol_capabilities
=
494 a
->xdi_adapter
.features
;
496 ("Set raw protocol features (%08x)",
497 a
->xdi_adapter
.features
)) ret
= 0;
500 case DIVA_XDI_UM_CMD_STOP_ADAPTER
:
501 ret
= diva_bri_stop_adapter(a
);
504 case DIVA_XDI_UM_CMD_READ_XLOG_ENTRY
:
505 ret
= diva_card_read_xlog(a
);
510 ("A: A(%d) invalid cmd=%d", a
->controller
,
516 static int diva_bri_reset_adapter(PISDN_ADAPTER IoAdapter
)
518 byte __iomem
*addrHi
, *addrLo
, *ioaddr
;
522 if (!IoAdapter
->port
) {
525 if (IoAdapter
->Initialized
) {
526 DBG_ERR(("A: A(%d) can't reset BRI adapter - please stop first",
527 IoAdapter
->ANum
)) return (-1);
529 (*(IoAdapter
->rstFnc
)) (IoAdapter
);
531 Port
= DIVA_OS_MEM_ATTACH_PORT(IoAdapter
);
533 ((IoAdapter
->Properties
.Bus
== BUS_PCI
) ? M_PCI_ADDRH
: ADDRH
);
534 addrLo
= Port
+ ADDR
;
535 ioaddr
= Port
+ DATA
;
539 outpp(addrHi
, (byte
) 0);
540 outppw(addrLo
, (word
) 0);
541 outppw(ioaddr
, (word
) 0);
547 (IoAdapter
->MemoryBase
+ IoAdapter
->MemorySize
-
548 BRI_SHARED_RAM_SIZE
) >> 16));
550 for (i
= 0; i
< 0x8000; outppw(ioaddr
, 0), ++i
);
558 (IoAdapter
->MemoryBase
+ IoAdapter
->MemorySize
-
559 BRI_SHARED_RAM_SIZE
) >> 16));
560 outppw(addrLo
, 0x1e);
564 outpp(addrHi
, (byte
) 0);
565 outppw(addrLo
, (word
) 0);
566 outppw(ioaddr
, (word
) 0);
568 DIVA_OS_MEM_DETACH_PORT(IoAdapter
, Port
);
571 Forget all outstanding entities
573 IoAdapter
->e_count
= 0;
574 if (IoAdapter
->e_tbl
) {
575 memset(IoAdapter
->e_tbl
, 0x00,
576 IoAdapter
->e_max
* sizeof(E_INFO
));
580 IoAdapter
->assign
= 0;
581 IoAdapter
->trapped
= 0;
583 memset(&IoAdapter
->a
.IdTable
[0], 0x00,
584 sizeof(IoAdapter
->a
.IdTable
));
585 memset(&IoAdapter
->a
.IdTypeTable
[0], 0x00,
586 sizeof(IoAdapter
->a
.IdTypeTable
));
587 memset(&IoAdapter
->a
.FlowControlIdTable
[0], 0x00,
588 sizeof(IoAdapter
->a
.FlowControlIdTable
));
589 memset(&IoAdapter
->a
.FlowControlSkipTable
[0], 0x00,
590 sizeof(IoAdapter
->a
.FlowControlSkipTable
));
591 memset(&IoAdapter
->a
.misc_flags_table
[0], 0x00,
592 sizeof(IoAdapter
->a
.misc_flags_table
));
593 memset(&IoAdapter
->a
.rx_stream
[0], 0x00,
594 sizeof(IoAdapter
->a
.rx_stream
));
595 memset(&IoAdapter
->a
.tx_stream
[0], 0x00,
596 sizeof(IoAdapter
->a
.tx_stream
));
597 memset(&IoAdapter
->a
.tx_pos
[0], 0x00, sizeof(IoAdapter
->a
.tx_pos
));
598 memset(&IoAdapter
->a
.rx_pos
[0], 0x00, sizeof(IoAdapter
->a
.rx_pos
));
604 diva_bri_write_sdram_block(PISDN_ADAPTER IoAdapter
,
605 dword address
, const byte
* data
, dword length
)
607 byte __iomem
*addrHi
, *addrLo
, *ioaddr
;
610 if (!IoAdapter
->port
) {
614 Port
= DIVA_OS_MEM_ATTACH_PORT(IoAdapter
);
616 ((IoAdapter
->Properties
.Bus
== BUS_PCI
) ? M_PCI_ADDRH
: ADDRH
);
617 addrLo
= Port
+ ADDR
;
618 ioaddr
= Port
+ DATA
;
621 outpp(addrHi
, (word
) (address
>> 16));
622 outppw(addrLo
, (word
) (address
& 0x0000ffff));
623 outpp(ioaddr
, *data
++);
627 DIVA_OS_MEM_DETACH_PORT(IoAdapter
, Port
);
632 diva_bri_start_adapter(PISDN_ADAPTER IoAdapter
,
633 dword start_address
, dword features
)
637 byte __iomem
*addrHi
, *addrLo
, *ioaddr
;
639 ADAPTER
*a
= &IoAdapter
->a
;
641 if (IoAdapter
->Initialized
) {
643 ("A: A(%d) bri_start_adapter, adapter already running",
644 IoAdapter
->ANum
)) return (-1);
646 if (!IoAdapter
->port
) {
647 DBG_ERR(("A: A(%d) bri_start_adapter, adapter not mapped",
648 IoAdapter
->ANum
)) return (-1);
651 sprintf(IoAdapter
->Name
, "A(%d)", (int) IoAdapter
->ANum
);
652 DBG_LOG(("A(%d) start BRI", IoAdapter
->ANum
))
654 Port
= DIVA_OS_MEM_ATTACH_PORT(IoAdapter
);
656 ((IoAdapter
->Properties
.Bus
== BUS_PCI
) ? M_PCI_ADDRH
: ADDRH
);
657 addrLo
= Port
+ ADDR
;
658 ioaddr
= Port
+ DATA
;
662 (IoAdapter
->MemoryBase
+ IoAdapter
->MemorySize
-
663 BRI_SHARED_RAM_SIZE
) >> 16));
664 outppw(addrLo
, 0x1e);
665 outppw(ioaddr
, 0x00);
666 DIVA_OS_MEM_DETACH_PORT(IoAdapter
, Port
);
669 start the protocol code
671 Port
= DIVA_OS_MEM_ATTACH_CTLREG(IoAdapter
);
673 DIVA_OS_MEM_DETACH_CTLREG(IoAdapter
, Port
);
675 Port
= DIVA_OS_MEM_ATTACH_PORT(IoAdapter
);
677 ((IoAdapter
->Properties
.Bus
== BUS_PCI
) ? M_PCI_ADDRH
: ADDRH
);
678 addrLo
= Port
+ ADDR
;
679 ioaddr
= Port
+ DATA
;
681 wait for signature (max. 3 seconds)
683 for (i
= 0; i
< 300; ++i
) {
687 (IoAdapter
->MemoryBase
+
688 IoAdapter
->MemorySize
-
689 BRI_SHARED_RAM_SIZE
) >> 16));
690 outppw(addrLo
, 0x1e);
691 test
= (dword
) inppw(ioaddr
);
692 if (test
== 0x4447) {
694 ("Protocol startup time %d.%02d seconds",
695 (i
/ 100), (i
% 100)))
700 DIVA_OS_MEM_DETACH_PORT(IoAdapter
, Port
);
703 DBG_FTL(("A: A(%d) %s: Adapter selftest failed 0x%04X",
704 IoAdapter
->ANum
, IoAdapter
->Properties
.Name
,
706 (*(IoAdapter
->trapFnc
)) (IoAdapter
);
710 IoAdapter
->Initialized
= 1;
715 IoAdapter
->IrqCount
= 0;
718 if (IoAdapter
->reset
) {
719 Port
= DIVA_OS_MEM_ATTACH_RESET(IoAdapter
);
721 DIVA_OS_MEM_DETACH_RESET(IoAdapter
, Port
);
724 a
->ram_out(a
, &PR_RAM
->ReadyInt
, 1);
725 for (i
= 0; ((!IoAdapter
->IrqCount
) && (i
< 100)); i
++) {
728 if (!IoAdapter
->IrqCount
) {
730 ("A: A(%d) interrupt test failed",
732 IoAdapter
->Initialized
= 0;
733 IoAdapter
->stop(IoAdapter
);
737 IoAdapter
->Properties
.Features
= (word
) features
;
738 diva_xdi_display_adapter_features(IoAdapter
->ANum
);
739 DBG_LOG(("A(%d) BRI adapter successfull started", IoAdapter
->ANum
))
743 diva_xdi_didd_register_adapter(IoAdapter
->ANum
);
748 static void diva_bri_clear_interrupts(diva_os_xdi_adapter_t
* a
)
750 PISDN_ADAPTER IoAdapter
= &a
->xdi_adapter
;
753 clear any pending interrupt
755 IoAdapter
->disIrq(IoAdapter
);
757 IoAdapter
->tst_irq(&IoAdapter
->a
);
758 IoAdapter
->clr_irq(&IoAdapter
->a
);
759 IoAdapter
->tst_irq(&IoAdapter
->a
);
764 diva_os_cancel_soft_isr(&IoAdapter
->req_soft_isr
);
765 diva_os_cancel_soft_isr(&IoAdapter
->isr_soft_isr
);
771 static int diva_bri_stop_adapter(diva_os_xdi_adapter_t
* a
)
773 PISDN_ADAPTER IoAdapter
= &a
->xdi_adapter
;
776 if (!IoAdapter
->port
) {
779 if (!IoAdapter
->Initialized
) {
780 DBG_ERR(("A: A(%d) can't stop BRI adapter - not running",
782 return (-1); /* nothing to stop */
784 IoAdapter
->Initialized
= 0;
787 Disconnect Adapter from DIDD
789 diva_xdi_didd_remove_adapter(IoAdapter
->ANum
);
794 a
->clear_interrupts_proc
= diva_bri_clear_interrupts
;
795 IoAdapter
->a
.ReadyInt
= 1;
796 IoAdapter
->a
.ram_inc(&IoAdapter
->a
, &PR_RAM
->ReadyInt
);
799 } while (i
-- && a
->clear_interrupts_proc
);
800 if (a
->clear_interrupts_proc
) {
801 diva_bri_clear_interrupts(a
);
802 a
->clear_interrupts_proc
= NULL
;
803 DBG_ERR(("A: A(%d) no final interrupt from BRI adapter",
806 IoAdapter
->a
.ReadyInt
= 0;
809 Stop and reset adapter
811 IoAdapter
->stop(IoAdapter
);