1 /* $Id: os_pri.c,v 1.1.2.3 2001/02/14 21:10:19 armin Exp $ */
15 #include "xdi_adapter.h"
23 /* --------------------------------------------------------------------------
24 OS Dependent part of XDI driver for DIVA PRI Adapter
26 DSP detection/validation by Anthony Booth (Eicon Networks, www.eicon.com)
27 -------------------------------------------------------------------------- */
29 #define DIVA_PRI_NO_PCI_BIOS_WORKAROUND 1
31 extern int diva_card_read_xlog(diva_os_xdi_adapter_t
* a
);
36 extern void prepare_pri_functions(PISDN_ADAPTER IoAdapter
);
37 extern void prepare_pri2_functions(PISDN_ADAPTER IoAdapter
);
38 extern void diva_xdi_display_adapter_features(int card
);
40 static int diva_pri_cleanup_adapter(diva_os_xdi_adapter_t
* a
);
41 static int diva_pri_cmd_card_proc(struct _diva_os_xdi_adapter
*a
,
42 diva_xdi_um_cfg_cmd_t
* cmd
, int length
);
43 static int pri_get_serial_number(diva_os_xdi_adapter_t
* a
);
44 static int diva_pri_stop_adapter(diva_os_xdi_adapter_t
* a
);
45 static dword
diva_pri_detect_dsps(diva_os_xdi_adapter_t
* a
);
48 ** Check card revision
50 static int pri_is_rev_2_card(int card_ordinal
)
52 switch (card_ordinal
) {
53 case CARDTYPE_DIVASRV_P_30M_V2_PCI
:
54 case CARDTYPE_DIVASRV_VOICE_P_30M_V2_PCI
:
61 ** BAR0 - SDRAM, MP_MEMORY_SIZE, MP2_MEMORY_SIZE by Rev.2
62 ** BAR1 - DEVICES, 0x1000
63 ** BAR2 - CONTROL (REG), 0x2000
64 ** BAR3 - FLASH (REG), 0x8000
65 ** BAR4 - CONFIG (CFG), 0x1000
67 int diva_pri_init_card(diva_os_xdi_adapter_t
* a
)
71 unsigned long bar_length
[5] = {
79 pri_rev_2
= pri_is_rev_2_card(a
->CardOrdinal
);
82 bar_length
[0] = MP2_MEMORY_SIZE
;
87 a
->xdi_adapter
.Properties
= CardProperties
[a
->CardOrdinal
];
88 DBG_LOG(("Load %s", a
->xdi_adapter
.Properties
.Name
))
91 First initialization step: get and check hardware resoures.
92 Do not map resources and do not acecess card at this step
94 for (bar
= 0; bar
< 5; bar
++) {
95 a
->resources
.pci
.bar
[bar
] =
96 divasa_get_pci_bar(a
->resources
.pci
.bus
,
97 a
->resources
.pci
.func
, bar
,
98 a
->resources
.pci
.hdev
);
99 if (!a
->resources
.pci
.bar
[bar
]
100 || (a
->resources
.pci
.bar
[bar
] == 0xFFFFFFF0)) {
101 DBG_ERR(("A: invalid bar[%d]=%08x", bar
,
102 a
->resources
.pci
.bar
[bar
]))
106 a
->resources
.pci
.irq
=
107 (byte
) divasa_get_pci_irq(a
->resources
.pci
.bus
,
108 a
->resources
.pci
.func
,
109 a
->resources
.pci
.hdev
);
110 if (!a
->resources
.pci
.irq
) {
111 DBG_ERR(("A: invalid irq"));
118 for (bar
= 0; bar
< 5; bar
++) {
119 a
->resources
.pci
.addr
[bar
] =
120 divasa_remap_pci_bar(a
->resources
.pci
.bar
[bar
],
122 if (!a
->resources
.pci
.addr
[bar
]) {
123 DBG_ERR(("A: A(%d), can't map bar[%d]",
125 diva_pri_cleanup_adapter(a
);
131 Get Serial Number of this adapter
133 if (pri_get_serial_number(a
)) {
135 serNo
= a
->resources
.pci
.bar
[1] & 0xffff0000;
136 serNo
|= ((dword
) a
->resources
.pci
.bus
) << 8;
137 serNo
+= (a
->resources
.pci
.func
+ a
->controller
+ 1);
138 a
->xdi_adapter
.serialNo
= serNo
& ~0xFF000000;
139 DBG_ERR(("A: A(%d) can't get Serial Number, generated serNo=%ld",
140 a
->controller
, a
->xdi_adapter
.serialNo
))
145 Initialize os objects
147 if (diva_os_initialize_spin_lock(&a
->xdi_adapter
.isr_spin_lock
, "isr")) {
148 diva_pri_cleanup_adapter(a
);
151 if (diva_os_initialize_spin_lock
152 (&a
->xdi_adapter
.data_spin_lock
, "data")) {
153 diva_pri_cleanup_adapter(a
);
157 strcpy(a
->xdi_adapter
.req_soft_isr
.dpc_thread_name
, "kdivasprid");
159 if (diva_os_initialize_soft_isr(&a
->xdi_adapter
.req_soft_isr
,
160 DIDpcRoutine
, &a
->xdi_adapter
)) {
161 diva_pri_cleanup_adapter(a
);
166 Do not initialize second DPC - only one thread will be created
168 a
->xdi_adapter
.isr_soft_isr
.object
=
169 a
->xdi_adapter
.req_soft_isr
.object
;
172 Next step of card initialization:
173 set up all interface pointers
175 a
->xdi_adapter
.Channels
= CardProperties
[a
->CardOrdinal
].Channels
;
176 a
->xdi_adapter
.e_max
= CardProperties
[a
->CardOrdinal
].E_info
;
178 a
->xdi_adapter
.e_tbl
=
179 diva_os_malloc(0, a
->xdi_adapter
.e_max
* sizeof(E_INFO
));
180 if (!a
->xdi_adapter
.e_tbl
) {
181 diva_pri_cleanup_adapter(a
);
184 memset(a
->xdi_adapter
.e_tbl
, 0x00, a
->xdi_adapter
.e_max
* sizeof(E_INFO
));
186 a
->xdi_adapter
.a
.io
= &a
->xdi_adapter
;
187 a
->xdi_adapter
.DIRequest
= request
;
188 a
->interface
.cleanup_adapter_proc
= diva_pri_cleanup_adapter
;
189 a
->interface
.cmd_proc
= diva_pri_cmd_card_proc
;
192 prepare_pri2_functions(&a
->xdi_adapter
);
194 prepare_pri_functions(&a
->xdi_adapter
);
200 a
->xdi_adapter
.Address
= a
->resources
.pci
.addr
[0];
201 a
->xdi_adapter
.sdram_bar
= a
->resources
.pci
.bar
[0];
202 a
->xdi_adapter
.ram
= a
->resources
.pci
.addr
[0];
203 a
->xdi_adapter
.ram
+= MP_SHARED_RAM_OFFSET
;
205 a
->xdi_adapter
.reset
= a
->resources
.pci
.addr
[2];
206 a
->xdi_adapter
.reset
+= MP_RESET
;
208 a
->xdi_adapter
.prom
=
209 (byte
*) (unsigned long) a
->resources
.pci
.bar
[3];
211 a
->xdi_adapter
.cfg
= a
->resources
.pci
.addr
[4];
212 a
->xdi_adapter
.cfg
+= MP_IRQ_RESET
;
214 a
->dsp_mask
= diva_pri_detect_dsps(a
);
220 diva_init_dma_map(a
->resources
.pci
.hdev
,
221 (struct _diva_dma_map_entry
**) &a
->xdi_adapter
.dma_map
, 32);
227 a
->xdi_adapter
.irq_info
.irq_nr
= a
->resources
.pci
.irq
;
228 sprintf(a
->xdi_adapter
.irq_info
.irq_name
,
229 "DIVA PRI %ld", (long) a
->xdi_adapter
.serialNo
);
231 if (diva_os_register_irq(a
, a
->xdi_adapter
.irq_info
.irq_nr
,
232 a
->xdi_adapter
.irq_info
.irq_name
)) {
233 diva_pri_cleanup_adapter(a
);
236 a
->xdi_adapter
.irq_info
.registered
= 1;
238 diva_log_info("%s IRQ:%d SerNo:%d", a
->xdi_adapter
.Properties
.Name
,
239 a
->resources
.pci
.irq
, a
->xdi_adapter
.serialNo
);
244 static int diva_pri_cleanup_adapter(diva_os_xdi_adapter_t
* a
)
249 Stop Adapter if adapter is running
251 if (a
->xdi_adapter
.Initialized
) {
252 diva_pri_stop_adapter(a
);
258 if (a
->xdi_adapter
.irq_info
.registered
) {
259 diva_os_remove_irq(a
, a
->xdi_adapter
.irq_info
.irq_nr
);
261 a
->xdi_adapter
.irq_info
.registered
= 0;
264 Step 1: unmap all BAR's, if any was mapped
266 for (bar
= 0; bar
< 5; bar
++) {
267 if (a
->resources
.pci
.bar
[bar
]
268 && a
->resources
.pci
.addr
[bar
]) {
269 divasa_unmap_pci_bar(a
->resources
.pci
.addr
[bar
]);
270 a
->resources
.pci
.bar
[bar
] = 0;
271 a
->resources
.pci
.addr
[bar
] = 0;
278 diva_os_cancel_soft_isr(&a
->xdi_adapter
.isr_soft_isr
);
279 diva_os_cancel_soft_isr(&a
->xdi_adapter
.req_soft_isr
);
281 diva_os_remove_soft_isr(&a
->xdi_adapter
.req_soft_isr
);
282 a
->xdi_adapter
.isr_soft_isr
.object
= 0;
284 diva_os_destroy_spin_lock(&a
->xdi_adapter
.isr_spin_lock
, "rm");
285 diva_os_destroy_spin_lock(&a
->xdi_adapter
.data_spin_lock
, "rm");
288 Free memory accupied by XDI adapter
290 if (a
->xdi_adapter
.e_tbl
) {
291 diva_os_free(0, a
->xdi_adapter
.e_tbl
);
292 a
->xdi_adapter
.e_tbl
= 0;
294 a
->xdi_adapter
.Channels
= 0;
295 a
->xdi_adapter
.e_max
= 0;
301 diva_free_dma_map(a
->resources
.pci
.hdev
,
302 (struct _diva_dma_map_entry
*) a
->xdi_adapter
.
304 a
->xdi_adapter
.dma_map
= 0;
308 Detach this adapter from debug driver
315 ** Activate On Board Boot Loader
317 static int diva_pri_reset_adapter(PISDN_ADAPTER IoAdapter
)
320 struct mp_load
*boot
= (struct mp_load
*) IoAdapter
->Address
;
322 if (!IoAdapter
->Address
|| !IoAdapter
->reset
) {
325 if (IoAdapter
->Initialized
) {
326 DBG_ERR(("A: A(%d) can't reset PRI adapter - please stop first",
331 WRITE_DWORD(&boot
->err
, 0);
332 IoAdapter
->rstFnc(IoAdapter
);
334 i
= READ_DWORD(&boot
->live
);
336 if (i
== READ_DWORD(&boot
->live
)) {
337 DBG_ERR(("A: A(%d) CPU on PRI %ld is not alive!",
338 IoAdapter
->ANum
, IoAdapter
->serialNo
))
341 if (READ_DWORD(&boot
->err
)) {
342 DBG_ERR(("A: A(%d) PRI %ld Board Selftest failed, error=%08lx",
343 IoAdapter
->ANum
, IoAdapter
->serialNo
,
344 READ_DWORD(&boot
->err
)))
349 Forget all outstanding entities
351 IoAdapter
->e_count
= 0;
352 if (IoAdapter
->e_tbl
) {
353 memset(IoAdapter
->e_tbl
, 0x00,
354 IoAdapter
->e_max
* sizeof(E_INFO
));
358 IoAdapter
->assign
= 0;
359 IoAdapter
->trapped
= 0;
361 memset(&IoAdapter
->a
.IdTable
[0], 0x00,
362 sizeof(IoAdapter
->a
.IdTable
));
363 memset(&IoAdapter
->a
.IdTypeTable
[0], 0x00,
364 sizeof(IoAdapter
->a
.IdTypeTable
));
365 memset(&IoAdapter
->a
.FlowControlIdTable
[0], 0x00,
366 sizeof(IoAdapter
->a
.FlowControlIdTable
));
367 memset(&IoAdapter
->a
.FlowControlSkipTable
[0], 0x00,
368 sizeof(IoAdapter
->a
.FlowControlSkipTable
));
369 memset(&IoAdapter
->a
.misc_flags_table
[0], 0x00,
370 sizeof(IoAdapter
->a
.misc_flags_table
));
371 memset(&IoAdapter
->a
.rx_stream
[0], 0x00,
372 sizeof(IoAdapter
->a
.rx_stream
));
373 memset(&IoAdapter
->a
.tx_stream
[0], 0x00,
374 sizeof(IoAdapter
->a
.tx_stream
));
375 memset(&IoAdapter
->a
.tx_pos
[0], 0x00, sizeof(IoAdapter
->a
.tx_pos
));
376 memset(&IoAdapter
->a
.rx_pos
[0], 0x00, sizeof(IoAdapter
->a
.rx_pos
));
382 diva_pri_write_sdram_block(PISDN_ADAPTER IoAdapter
,
384 const byte
* data
, dword length
, dword limit
)
386 byte
*mem
= IoAdapter
->Address
;
388 if (((address
+ length
) >= limit
) || !mem
) {
389 DBG_ERR(("A: A(%d) write PRI address=0x%08lx",
390 IoAdapter
->ANum
, address
+ length
))
403 diva_pri_start_adapter(PISDN_ADAPTER IoAdapter
,
404 dword start_address
, dword features
)
408 struct mp_load
*boot
= (struct mp_load
*) IoAdapter
->Address
;
409 ADAPTER
*a
= &IoAdapter
->a
;
411 if (IoAdapter
->Initialized
) {
412 DBG_ERR(("A: A(%d) pri_start_adapter, adapter already running",
417 DBG_ERR(("A: PRI %ld can't start, adapter not mapped",
418 IoAdapter
->serialNo
))
422 sprintf(IoAdapter
->Name
, "A(%d)", (int) IoAdapter
->ANum
);
423 DBG_LOG(("A(%d) start PRI at 0x%08lx", IoAdapter
->ANum
,
426 WRITE_DWORD(&boot
->addr
, start_address
);
427 WRITE_DWORD(&boot
->cmd
, 3);
429 for (i
= 0; i
< 300; ++i
) {
431 if ((READ_DWORD(&boot
->signature
) >> 16) == 0x4447) {
432 DBG_LOG(("A(%d) Protocol startup time %d.%02d seconds",
433 IoAdapter
->ANum
, (i
/ 100), (i
% 100)))
440 dword TrapId
= READ_DWORD(&IoAdapter
->Address
[0x80]);
441 dword debug
= READ_DWORD(&IoAdapter
->Address
[0x1c]);
442 DBG_ERR(("A(%d) Adapter start failed 0x%08lx, TrapId=%08lx, debug=%08lx",
443 IoAdapter
->ANum
, READ_DWORD(&boot
->signature
),
445 if (IoAdapter
->trapFnc
) {
446 (*(IoAdapter
->trapFnc
)) (IoAdapter
);
448 IoAdapter
->stop(IoAdapter
);
452 IoAdapter
->Initialized
= TRUE
;
457 IoAdapter
->IrqCount
= 0;
458 WRITE_DWORD(((dword
volatile *) IoAdapter
->cfg
),
459 (dword
) ~ 0x03E00000);
461 a
->ram_out(a
, &PR_RAM
->ReadyInt
, 1);
463 for (i
= 100; !IoAdapter
->IrqCount
&& (i
-- > 0); diva_os_wait(10));
465 if (!IoAdapter
->IrqCount
) {
466 DBG_ERR(("A: A(%d) interrupt test failed",
468 IoAdapter
->Initialized
= FALSE
;
469 IoAdapter
->stop(IoAdapter
);
473 IoAdapter
->Properties
.Features
= (word
) features
;
475 diva_xdi_display_adapter_features(IoAdapter
->ANum
);
477 DBG_LOG(("A(%d) PRI adapter successfull started", IoAdapter
->ANum
))
481 diva_xdi_didd_register_adapter(IoAdapter
->ANum
);
486 static void diva_pri_clear_interrupts(diva_os_xdi_adapter_t
* a
)
488 PISDN_ADAPTER IoAdapter
= &a
->xdi_adapter
;
491 clear any pending interrupt
493 IoAdapter
->disIrq(IoAdapter
);
495 IoAdapter
->tst_irq(&IoAdapter
->a
);
496 IoAdapter
->clr_irq(&IoAdapter
->a
);
497 IoAdapter
->tst_irq(&IoAdapter
->a
);
502 diva_os_cancel_soft_isr(&IoAdapter
->req_soft_isr
);
503 diva_os_cancel_soft_isr(&IoAdapter
->isr_soft_isr
);
507 ** Stop Adapter, but do not unmap/unregister - adapter
508 ** will be restarted later
510 static int diva_pri_stop_adapter(diva_os_xdi_adapter_t
* a
)
512 PISDN_ADAPTER IoAdapter
= &a
->xdi_adapter
;
515 if (!IoAdapter
->ram
) {
518 if (!IoAdapter
->Initialized
) {
519 DBG_ERR(("A: A(%d) can't stop PRI adapter - not running",
521 return (-1); /* nothing to stop */
523 IoAdapter
->Initialized
= 0;
526 Disconnect Adapter from DIDD
528 diva_xdi_didd_remove_adapter(IoAdapter
->ANum
);
533 a
->clear_interrupts_proc
= diva_pri_clear_interrupts
;
534 IoAdapter
->a
.ReadyInt
= 1;
535 IoAdapter
->a
.ram_inc(&IoAdapter
->a
, &PR_RAM
->ReadyInt
);
538 } while (i
-- && a
->clear_interrupts_proc
);
540 if (a
->clear_interrupts_proc
) {
541 diva_pri_clear_interrupts(a
);
542 a
->clear_interrupts_proc
= 0;
543 DBG_ERR(("A: A(%d) no final interrupt from PRI adapter",
546 IoAdapter
->a
.ReadyInt
= 0;
549 Stop and reset adapter
551 IoAdapter
->stop(IoAdapter
);
557 ** Process commands form configuration/download framework and from
560 ** return 0 on success
563 diva_pri_cmd_card_proc(struct _diva_os_xdi_adapter
*a
,
564 diva_xdi_um_cfg_cmd_t
* cmd
, int length
)
568 if (cmd
->adapter
!= a
->controller
) {
569 DBG_ERR(("A: pri_cmd, invalid controller=%d != %d",
570 cmd
->adapter
, a
->controller
))
574 switch (cmd
->command
) {
575 case DIVA_XDI_UM_CMD_GET_CARD_ORDINAL
:
576 a
->xdi_mbox
.data_length
= sizeof(dword
);
578 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
579 if (a
->xdi_mbox
.data
) {
580 *(dword
*) a
->xdi_mbox
.data
=
581 (dword
) a
->CardOrdinal
;
582 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
587 case DIVA_XDI_UM_CMD_GET_SERIAL_NR
:
588 a
->xdi_mbox
.data_length
= sizeof(dword
);
590 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
591 if (a
->xdi_mbox
.data
) {
592 *(dword
*) a
->xdi_mbox
.data
=
593 (dword
) a
->xdi_adapter
.serialNo
;
594 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
599 case DIVA_XDI_UM_CMD_GET_PCI_HW_CONFIG
:
600 a
->xdi_mbox
.data_length
= sizeof(dword
) * 9;
602 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
603 if (a
->xdi_mbox
.data
) {
605 dword
*data
= (dword
*) a
->xdi_mbox
.data
;
607 for (i
= 0; i
< 8; i
++) {
608 *data
++ = a
->resources
.pci
.bar
[i
];
610 *data
++ = (dword
) a
->resources
.pci
.irq
;
611 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
616 case DIVA_XDI_UM_CMD_RESET_ADAPTER
:
617 ret
= diva_pri_reset_adapter(&a
->xdi_adapter
);
620 case DIVA_XDI_UM_CMD_WRITE_SDRAM_BLOCK
:
621 ret
= diva_pri_write_sdram_block(&a
->xdi_adapter
,
627 pri_is_rev_2_card(a
->
633 case DIVA_XDI_UM_CMD_STOP_ADAPTER
:
634 ret
= diva_pri_stop_adapter(a
);
637 case DIVA_XDI_UM_CMD_START_ADAPTER
:
638 ret
= diva_pri_start_adapter(&a
->xdi_adapter
,
639 cmd
->command_data
.start
.
641 cmd
->command_data
.start
.
645 case DIVA_XDI_UM_CMD_SET_PROTOCOL_FEATURES
:
646 a
->xdi_adapter
.features
=
647 cmd
->command_data
.features
.features
;
648 a
->xdi_adapter
.a
.protocol_capabilities
=
649 a
->xdi_adapter
.features
;
650 DBG_TRC(("Set raw protocol features (%08x)",
651 a
->xdi_adapter
.features
))
655 case DIVA_XDI_UM_CMD_GET_CARD_STATE
:
656 a
->xdi_mbox
.data_length
= sizeof(dword
);
658 diva_os_malloc(0, a
->xdi_mbox
.data_length
);
659 if (a
->xdi_mbox
.data
) {
660 dword
*data
= (dword
*) a
->xdi_mbox
.data
;
661 if (!a
->xdi_adapter
.ram
|| !a
->xdi_adapter
.reset
||
662 !a
->xdi_adapter
.cfg
) {
664 } else if (a
->xdi_adapter
.trapped
) {
666 } else if (a
->xdi_adapter
.Initialized
) {
671 a
->xdi_mbox
.status
= DIVA_XDI_MBOX_BUSY
;
676 case DIVA_XDI_UM_CMD_READ_XLOG_ENTRY
:
677 ret
= diva_card_read_xlog(a
);
680 case DIVA_XDI_UM_CMD_READ_SDRAM
:
681 if (a
->xdi_adapter
.Address
) {
683 (a
->xdi_mbox
.data_length
=
684 cmd
->command_data
.read_sdram
.length
)) {
686 (a
->xdi_mbox
.data_length
+
687 cmd
->command_data
.read_sdram
.offset
) <
688 a
->xdi_adapter
.MemorySize
) {
693 if (a
->xdi_mbox
.data
) {
695 a
->xdi_adapter
.Address
;
719 DBG_ERR(("A: A(%d) invalid cmd=%d", a
->controller
,
729 static int pri_get_serial_number(diva_os_xdi_adapter_t
* a
)
733 dword len
= sizeof(data
);
734 volatile byte
*config
= (byte
*) a
->resources
.pci
.addr
[4];
735 volatile byte
*flash
= (byte
*) a
->resources
.pci
.addr
[3];
738 * First set some GT6401x config registers before accessing the BOOT-ROM
740 if (!(config
[0xc3c] & 0x08)) {
741 config
[0xc3c] |= 0x08; /* Base Address enable register */
743 config
[LOW_BOOTCS_DREG
] = 0x00;
744 config
[HI_BOOTCS_DREG
] = 0xFF;
746 * Read only the last 64 bytes of manufacturing data
748 memset(data
, '\0', len
);
749 for (i
= 0; i
< len
; i
++) {
750 data
[i
] = flash
[0x8000 - len
+ i
];
753 config
[LOW_BOOTCS_DREG
] = 0xFC; /* Disable FLASH EPROM access */
754 config
[HI_BOOTCS_DREG
] = 0xFF;
756 if (memcmp(&data
[48], "DIVAserverPR", 12)) {
757 #if !defined(DIVA_PRI_NO_PCI_BIOS_WORKAROUND) /* { */
758 word cmd
= 0, cmd_org
;
760 dword addr1
, addr3
, addr4
;
763 addr4
= a
->resources
.pci
.bar
[4];
764 addr3
= a
->resources
.pci
.bar
[3]; /* flash */
765 addr1
= a
->resources
.pci
.bar
[1]; /* unused */
767 DBG_ERR(("A: apply Compaq BIOS workaround"))
768 DBG_LOG(("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
769 data
[0], data
[1], data
[2], data
[3],
770 data
[4], data
[5], data
[6], data
[7]))
772 Bus
= a
->resources
.pci
.bus
;
773 Slot
= a
->resources
.pci
.func
;
774 hdev
= a
->resources
.pci
.hdev
;
775 PCIread(Bus
, Slot
, 0x04, &cmd_org
, sizeof(cmd_org
), hdev
);
776 PCIwrite(Bus
, Slot
, 0x04, &cmd
, sizeof(cmd
), hdev
);
778 PCIwrite(Bus
, Slot
, 0x14, &addr4
, sizeof(addr4
), hdev
);
779 PCIwrite(Bus
, Slot
, 0x20, &addr1
, sizeof(addr1
), hdev
);
781 PCIwrite(Bus
, Slot
, 0x04, &cmd_org
, sizeof(cmd_org
), hdev
);
783 addr
= a
->resources
.pci
.addr
[1];
784 a
->resources
.pci
.addr
[1] = a
->resources
.pci
.addr
[4];
785 a
->resources
.pci
.addr
[4] = addr
;
787 addr1
= a
->resources
.pci
.bar
[1];
788 a
->resources
.pci
.bar
[1] = a
->resources
.pci
.bar
[4];
789 a
->resources
.pci
.bar
[4] = addr1
;
792 Try to read Flash again
794 config
= (byte
*) a
->resources
.pci
.addr
[4];
795 flash
= (byte
*) a
->resources
.pci
.addr
[3];
798 if (!(config
[0xc3c] & 0x08)) {
799 config
[0xc3c] |= 0x08; /* Base Address enable register */
801 config
[LOW_BOOTCS_DREG
] = 0x00;
802 config
[HI_BOOTCS_DREG
] = 0xFF;
804 memset(data
, '\0', len
);
805 for (i
= 0; i
< len
; i
++) {
806 data
[i
] = flash
[0x8000 - len
+ i
];
808 config
[LOW_BOOTCS_DREG
] = 0xFC;
809 config
[HI_BOOTCS_DREG
] = 0xFF;
811 if (memcmp(&data
[48], "DIVAserverPR", 12)) {
812 DBG_ERR(("A: failed to read serial number"))
813 DBG_LOG(("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
814 data
[0], data
[1], data
[2], data
[3],
815 data
[4], data
[5], data
[6], data
[7]))
819 DBG_ERR(("A: failed to read DIVA signature word"))
820 DBG_LOG(("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
821 data
[0], data
[1], data
[2], data
[3],
822 data
[4], data
[5], data
[6], data
[7]))
823 DBG_LOG(("%02x:%02x:%02x:%02x", data
[47], data
[46],
828 a
->xdi_adapter
.serialNo
=
829 (data
[47] << 24) | (data
[46] << 16) | (data
[45] << 8) |
831 if (!a
->xdi_adapter
.serialNo
832 || (a
->xdi_adapter
.serialNo
== 0xffffffff)) {
833 a
->xdi_adapter
.serialNo
= 0;
834 DBG_ERR(("A: failed to read serial number"))
838 DBG_LOG(("Serial No. : %ld", a
->xdi_adapter
.serialNo
))
839 DBG_TRC(("Board Revision : %d.%02d", (int) data
[41],
841 DBG_TRC(("PLD revision : %d.%02d", (int) data
[33],
843 DBG_TRC(("Boot loader version : %d.%02d", (int) data
[37],
846 DBG_TRC(("Manufacturing Date : %d/%02d/%02d (yyyy/mm/dd)",
847 (int) ((data
[28] > 90) ? 1900 : 2000) +
848 (int) data
[28], (int) data
[29], (int) data
[30]))
853 void diva_os_prepare_pri2_functions(PISDN_ADAPTER IoAdapter
)
857 void diva_os_prepare_pri_functions(PISDN_ADAPTER IoAdapter
)
862 ** Checks presence of DSP on board
865 dsp_check_presence(volatile byte
* addr
, volatile byte
* data
, int dsp
)
869 WRITE_WORD(addr
, 0x4000);
870 WRITE_WORD(data
, DSP_SIGNATURE_PROBE_WORD
);
872 WRITE_WORD(addr
, 0x4000);
873 pattern
= READ_WORD(data
);
875 if (pattern
!= DSP_SIGNATURE_PROBE_WORD
) {
876 DBG_TRC(("W: DSP[%d] %04x(is) != %04x(should)",
877 dsp
, pattern
, DSP_SIGNATURE_PROBE_WORD
))
881 WRITE_WORD(addr
, 0x4000);
882 WRITE_WORD(data
, ~DSP_SIGNATURE_PROBE_WORD
);
884 WRITE_WORD(addr
, 0x4000);
885 pattern
= READ_WORD(data
);
887 if (pattern
!= (word
) ~ DSP_SIGNATURE_PROBE_WORD
) {
888 DBG_ERR(("A: DSP[%d] %04x(is) != %04x(should)",
889 dsp
, pattern
, (word
) ~ DSP_SIGNATURE_PROBE_WORD
))
893 DBG_TRC(("DSP[%d] present", dsp
))
900 ** Check if DSP's are present and operating
901 ** Information about detected DSP's is returned as bit mask
908 static dword
diva_pri_detect_dsps(diva_os_xdi_adapter_t
* a
)
910 byte
*base
= a
->resources
.pci
.addr
[2];
912 dword row_offset
[7] = {
914 0x00000800, /* 1 - ROW 1 */
915 0x00000840, /* 2 - ROW 2 */
916 0x00001000, /* 3 - ROW 3 */
917 0x00001040, /* 4 - ROW 4 */
918 0x00000000 /* 5 - ROW 0 */
921 byte
*dsp_addr_port
, *dsp_data_port
, row_state
;
922 int dsp_row
= 0, dsp_index
, dsp_num
;
924 if (!base
|| !a
->xdi_adapter
.reset
) {
928 *(volatile byte
*) (a
->xdi_adapter
.reset
) =
929 _MP_RISC_RESET
| _MP_DSP_RESET
;
932 for (dsp_num
= 0; dsp_num
< 30; dsp_num
++) {
933 dsp_row
= dsp_num
/ 7 + 1;
934 dsp_index
= dsp_num
% 7;
936 dsp_data_port
= base
;
937 dsp_addr_port
= base
;
939 dsp_data_port
+= row_offset
[dsp_row
];
940 dsp_addr_port
+= row_offset
[dsp_row
];
942 dsp_data_port
+= (dsp_index
* 8);
943 dsp_addr_port
+= (dsp_index
* 8) + 0x80;
945 if (!dsp_check_presence
946 (dsp_addr_port
, dsp_data_port
, dsp_num
+ 1)) {
947 ret
|= (1 << dsp_num
);
951 *(volatile byte
*) (a
->xdi_adapter
.reset
) =
952 _MP_RISC_RESET
| _MP_LED1
| _MP_LED2
;
958 for (dsp_row
= 0; dsp_row
< 4; dsp_row
++) {
959 row_state
= ((ret
>> (dsp_row
* 7)) & 0x7F);
960 if (row_state
&& (row_state
!= 0x7F)) {
961 for (dsp_index
= 0; dsp_index
< 7; dsp_index
++) {
962 if (!(row_state
& (1 << dsp_index
))) {
963 DBG_ERR(("A: MODULE[%d]-DSP[%d] failed",
971 if (!(ret
& 0x10000000)) {
972 DBG_ERR(("A: ON BOARD-DSP[1] failed"))
974 if (!(ret
& 0x20000000)) {
975 DBG_ERR(("A: ON BOARD-DSP[2] failed"))
979 Print module population now
981 DBG_LOG(("+-----------------------+"))
982 DBG_LOG(("| DSP MODULE POPULATION |"))
983 DBG_LOG(("+-----------------------+"))
984 DBG_LOG(("| 1 | 2 | 3 | 4 |"))
985 DBG_LOG(("+-----------------------+"))
986 DBG_LOG(("| %s | %s | %s | %s |",
987 ((ret
>> (0 * 7)) & 0x7F) ? "Y" : "N",
988 ((ret
>> (1 * 7)) & 0x7F) ? "Y" : "N",
989 ((ret
>> (2 * 7)) & 0x7F) ? "Y" : "N",
990 ((ret
>> (3 * 7)) & 0x7F) ? "Y" : "N"))
991 DBG_LOG(("+-----------------------+"))
993 DBG_LOG(("DSP's(present-absent):%08x-%08x", ret
,