require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&__IF_SANDRV_H)) {
    eval 'sub __IF_SANDRV_H () {1;}' unless defined(&__IF_SANDRV_H);
    if(defined(&__SDLADRV__)) {
	eval 'sub EXTERN () {1;}' unless defined(&EXTERN);
    } else {
	eval 'sub EXTERN () { &extern;}' unless defined(&EXTERN);
    }
    eval 'sub WAN_MAILBOX_SIZE () {16;}' unless defined(&WAN_MAILBOX_SIZE);
    eval 'sub WAN_MAX_DATA_SIZE () {2032;}' unless defined(&WAN_MAX_DATA_SIZE);
    eval 'sub wan_cmd_opp_flag () { ($wan_cmd_u->{wan_p_cmd}->{opp_flag});}' unless defined(&wan_cmd_opp_flag);
    eval 'sub wan_cmd_command () { ($wan_cmd_u->{wan_p_cmd}->{command});}' unless defined(&wan_cmd_command);
    eval 'sub wan_cmd_data_len () { ($wan_cmd_u->{wan_p_cmd}->{data_len});}' unless defined(&wan_cmd_data_len);
    eval 'sub wan_cmd_return_code () { ($wan_cmd_u->{wan_p_cmd}->{return_code});}' unless defined(&wan_cmd_return_code);
    eval 'sub wan_opp_flag () { ($wan_cmd->{wan_cmd_opp_flag});}' unless defined(&wan_opp_flag);
    eval 'sub wan_command () { ($wan_cmd->{wan_cmd_command});}' unless defined(&wan_command);
    eval 'sub wan_data_len () { ($wan_cmd->{wan_cmd_data_len});}' unless defined(&wan_data_len);
    eval 'sub wan_return_code () { ($wan_cmd->{wan_cmd_return_code});}' unless defined(&wan_return_code);
    eval 'sub WAN_MBOX_INIT {
        my($mbox) = @_;
	    eval q( &memset($mbox, 0, $sizeof{ &wan_cmd_t}););
    }' unless defined(&WAN_MBOX_INIT);
    if(defined( &_KERNEL)) {
	eval 'sub SDLADRV_MAJOR_VER () {2;}' unless defined(&SDLADRV_MAJOR_VER);
	eval 'sub SDLADRV_MINOR_VER () {1;}' unless defined(&SDLADRV_MINOR_VER);
	eval 'sub SDLA_WINDOWSIZE () {0x2000;}' unless defined(&SDLA_WINDOWSIZE);
	eval 'sub SDLA_S508 () {5080;}' unless defined(&SDLA_S508);
	eval 'sub SDLA_S514 () {5140;}' unless defined(&SDLA_S514);
	eval 'sub SDLA_ADSL () {6000;}' unless defined(&SDLA_ADSL);
	eval 'sub SDLA_AFT () {7000;}' unless defined(&SDLA_AFT);
	eval 'sub SDLA_PRI_PORT () {1;}' unless defined(&SDLA_PRI_PORT);
	eval 'sub SDLA_SEC_PORT () {2;}' unless defined(&SDLA_SEC_PORT);
	eval 'sub SFM_VERSION () {2;}' unless defined(&SFM_VERSION);
	eval 'sub SFM_SIGNATURE () {"SFM - Sangoma SDLA Firmware Module";}' unless defined(&SFM_SIGNATURE);
	eval 'sub SFM_IMAGE_SIZE () {0x8000;}' unless defined(&SFM_IMAGE_SIZE);
	eval 'sub SFM_DESCR_LEN () {256;}' unless defined(&SFM_DESCR_LEN);
	eval 'sub SFM_MAX_SDLA () {16;}' unless defined(&SFM_MAX_SDLA);
	eval 'sub SFID_HDLC502 () {4200;}' unless defined(&SFID_HDLC502);
	eval 'sub SFID_HDLC508 () {4800;}' unless defined(&SFID_HDLC508);
	eval 'sub SFID_CHDLC508 () {8800;}' unless defined(&SFID_CHDLC508);
	eval 'sub SFID_CHDLC514 () {8140;}' unless defined(&SFID_CHDLC514);
	eval 'sub SFID_AFT () {30000;}' unless defined(&SFID_AFT);
	eval 'sub SDLA_MEMBASE () {0x1;}' unless defined(&SDLA_MEMBASE);
	eval 'sub SDLA_MEMEND () {0x2;}' unless defined(&SDLA_MEMEND);
	eval 'sub SDLA_MEMSIZE () {0x3;}' unless defined(&SDLA_MEMSIZE);
	eval 'sub SDLA_MEMORY () {0x5;}' unless defined(&SDLA_MEMORY);
	eval 'sub SDLA_BASEADDR () {0x6;}' unless defined(&SDLA_BASEADDR);
	eval 'sub SDLA_DMATAG () {0x4;}' unless defined(&SDLA_DMATAG);
	eval 'sub SDLA_IRQ () {0x7;}' unless defined(&SDLA_IRQ);
	eval 'sub SDLA_BUS () {0x8;}' unless defined(&SDLA_BUS);
	eval 'sub SDLA_CPU () {0xa;}' unless defined(&SDLA_CPU);
	eval 'sub SDLA_SLOT () {0xb;}' unless defined(&SDLA_SLOT);
	eval 'sub SDLA_ADAPTERTYPE () {0xc;}' unless defined(&SDLA_ADAPTERTYPE);
	eval 'sub SDLA_CARDTYPE () {0xd;}' unless defined(&SDLA_CARDTYPE);
	eval 'sub SDLA_PCIEXTRAVER () {0xe;}' unless defined(&SDLA_PCIEXTRAVER);
	eval 'sub SDLA_MAX_CPUS () {2;}' unless defined(&SDLA_MAX_CPUS);
	eval 'sub S514_CPU_A () {ord(\'A\');}' unless defined(&S514_CPU_A);
	eval 'sub S514_CPU_B () {ord(\'B\');}' unless defined(&S514_CPU_B);
	eval 'sub SDLA_CPU_A () {1;}' unless defined(&SDLA_CPU_A);
	eval 'sub SDLA_CPU_B () {2;}' unless defined(&SDLA_CPU_B);
	eval 'sub SDLA_GET_CPU {
	    my($cpu_no) = @_;
    	    eval q(($cpu_no== &SDLA_CPU_A)? &S514_CPU_A: &S514_CPU_B);
	}' unless defined(&SDLA_GET_CPU);
	eval 'sub AFT_CORE_ID_MASK () {0xff;}' unless defined(&AFT_CORE_ID_MASK);
	eval 'sub AFT_CORE_REV_MASK () {0xff00;}' unless defined(&AFT_CORE_REV_MASK);
	eval 'sub AFT_HDLC_CORE_ID () {0x;}' unless defined(&AFT_HDLC_CORE_ID);
	eval 'sub AFT_ATM_CORE_ID () {0x1;}' unless defined(&AFT_ATM_CORE_ID);
	eval 'sub AFT_SS7_CORE_ID () {0x2;}' unless defined(&AFT_SS7_CORE_ID);
	eval 'sub XILINX_PCI_MEM_SIZE () {0x2ff;}' unless defined(&XILINX_PCI_MEM_SIZE);
	eval 'sub XILINX_PCI_LATENCY () {0xff00;}' unless defined(&XILINX_PCI_LATENCY);
	eval 'sub XILINX_PCI_CMD_REG () {0x4;}' unless defined(&XILINX_PCI_CMD_REG);
	eval 'sub XILINX_PCI_LATENCY_REG () {0xc;}' unless defined(&XILINX_PCI_LATENCY_REG);
	if(0) {
	    eval 'sub PCI_VENDOR_ID_WORD () {0x;}' unless defined(&PCI_VENDOR_ID_WORD);
	    eval 'sub PCI_DEVICE_ID_WORD () {0x2;}' unless defined(&PCI_DEVICE_ID_WORD);
	    eval 'sub PCI_SUBCLASS_ID_BYTE () {0xa;}' unless defined(&PCI_SUBCLASS_ID_BYTE);
	}
	eval 'sub PCI_IO_BASE_DWORD () {0x10;}' unless defined(&PCI_IO_BASE_DWORD);
	eval 'sub PCI_MEM_BASE0_DWORD () {0x14;}' unless defined(&PCI_MEM_BASE0_DWORD);
	eval 'sub PCI_MEM_BASE1_DWORD () {0x18;}' unless defined(&PCI_MEM_BASE1_DWORD);
	if(0) {
	    eval 'sub PCI_SUBSYS_VENDOR_WORD () {0x2c;}' unless defined(&PCI_SUBSYS_VENDOR_WORD);
	    eval 'sub PCI_SUBSYS_ID_WORD () {0x2e;}' unless defined(&PCI_SUBSYS_ID_WORD);
	    eval 'sub PCI_INT_LINE_BYTE () {0x3c;}' unless defined(&PCI_INT_LINE_BYTE);
	    eval 'sub PCI_INT_PIN_BYTE () {0x3d;}' unless defined(&PCI_INT_PIN_BYTE);
	}
	eval 'sub PCI_MAP0_DWORD () {0x40;}' unless defined(&PCI_MAP0_DWORD);
	eval 'sub PCI_MAP1_DWORD () {0x44;}' unless defined(&PCI_MAP1_DWORD);
	eval 'sub PCI_INT_STATUS () {0x48;}' unless defined(&PCI_INT_STATUS);
	eval 'sub PCI_INT_CONFIG () {0x4c;}' unless defined(&PCI_INT_CONFIG);
	eval 'sub PCI_DEV_SLOT_MASK () {0x1f;}' unless defined(&PCI_DEV_SLOT_MASK);
	eval 'sub PCI_IRQ_NOT_ALLOCATED () {0xff;}' unless defined(&PCI_IRQ_NOT_ALLOCATED);
	eval 'sub PCI_MEMORY_ENABLE () {0x3;}' unless defined(&PCI_MEMORY_ENABLE);
	eval 'sub PCI_CPU_A_MEM_DISABLE () {0x2;}' unless defined(&PCI_CPU_A_MEM_DISABLE);
	eval 'sub PCI_CPU_B_MEM_DISABLE () {0x100002;}' unless defined(&PCI_CPU_B_MEM_DISABLE);
	eval 'sub PCI_ENABLE_IRQ_CPU_A () {0x5a0004;}' unless defined(&PCI_ENABLE_IRQ_CPU_A);
	eval 'sub PCI_ENABLE_IRQ_CPU_B () {0x5a0008;}' unless defined(&PCI_ENABLE_IRQ_CPU_B);
	eval 'sub PCI_ENABLE_IRQ_DMA0 () {0x1000000;}' unless defined(&PCI_ENABLE_IRQ_DMA0);
	eval 'sub PCI_ENABLE_IRQ_DMA1 () {0x2000000;}' unless defined(&PCI_ENABLE_IRQ_DMA1);
	eval 'sub PCI_DISABLE_IRQ_CPU_A () {0x4;}' unless defined(&PCI_DISABLE_IRQ_CPU_A);
	eval 'sub PCI_DISABLE_IRQ_CPU_B () {0x8;}' unless defined(&PCI_DISABLE_IRQ_CPU_B);
	eval 'sub PCI_DISABLE_IRQ_DMA0 () {0x1000000;}' unless defined(&PCI_DISABLE_IRQ_DMA0);
	eval 'sub PCI_DISABLE_IRQ_DMA1 () {0x2000000;}' unless defined(&PCI_DISABLE_IRQ_DMA1);
	eval 'sub IRQ_DMA0 () {0x1000000;}' unless defined(&IRQ_DMA0);
	eval 'sub IRQ_DMA1 () {0x2000000;}' unless defined(&IRQ_DMA1);
	eval 'sub IRQ_LOCAL_CPU_A () {0x4;}' unless defined(&IRQ_LOCAL_CPU_A);
	eval 'sub IRQ_LOCAL_CPU_B () {0x8;}' unless defined(&IRQ_LOCAL_CPU_B);
	eval 'sub IRQ_CPU_A () {0x4;}' unless defined(&IRQ_CPU_A);
	eval 'sub IRQ_CPU_B () {0x8;}' unless defined(&IRQ_CPU_B);
	eval 'sub MAX_SIZEOF_S514_MEMORY () {(256* 1024);}' unless defined(&MAX_SIZEOF_S514_MEMORY);
	eval 'sub S514_CTRL_REG_BYTE () {0x80000;}' unless defined(&S514_CTRL_REG_BYTE);
	eval 'sub S514_CPU_HALT () {0x;}' unless defined(&S514_CPU_HALT);
	eval 'sub S514_CPU_START () {0x1;}' unless defined(&S514_CPU_START);
	eval 'sub MAX_S514_CARDS () {20;}' unless defined(&MAX_S514_CARDS);
	eval 'sub WAN_CMD_OK () {0;}' unless defined(&WAN_CMD_OK);
	eval 'sub WAN_CMD_TIMEOUT () {0xff;}' unless defined(&WAN_CMD_TIMEOUT);
	eval 'sub SDLAHW_MAGIC () {0x414c4453;}' unless defined(&SDLAHW_MAGIC);
	eval 'sub AFT_CORE_ID_DECODE {
	    my($core_id) = @_;
    	    eval q(($core_id ==  &AFT_HDLC_CORE_ID) ? \\"HDLC\\" : ($core_id ==  &AFT_ATM_CORE_ID) ? \\"ATM\\" : ($core_id ==  &AFT_SS7_CORE_ID) ? \\"SS7\\" : \\"Unknown\\");
	}' unless defined(&AFT_CORE_ID_DECODE);
	eval 'sub WAN_ASSERT {
	    my($val) = @_;
    	    eval q( &if ($val){  &log( &LOG_INFO, \\"********** ASSERT FAILED **********\\\\n\\");  &log( &LOG_INFO, \\"%s:%d - Critical error\\\\n\\",  &__FILE__, &__LINE__);  &return - &EINVAL; });
	}' unless defined(&WAN_ASSERT);
	eval 'sub WAN_ASSERT1 {
	    my($val) = @_;
    	    eval q( &if ($val){  &log( &LOG_INFO, \\"********** ASSERT FAILED **********\\\\n\\");  &log( &LOG_INFO, \\"%s:%d - Critical error\\\\n\\",  &__FILE__, &__LINE__);  &return; });
	}' unless defined(&WAN_ASSERT1);
	eval 'sub WAN_ASSERT2 {
	    my($val, $ret) = @_;
    	    eval q( &if ($val){  &log( &LOG_INFO, \\"********** ASSERT FAILED **********\\\\n\\");  &log( &LOG_INFO, \\"%s:%d - Critical error\\\\n\\",  &__FILE__, &__LINE__);  &return $ret; });
	}' unless defined(&WAN_ASSERT2);
	eval 'sub SDLA_MAGIC {
	    my($hw) = @_;
    	    eval q( &WAN_ASSERT(($hw)-> &magic !=  &SDLAHW_MAGIC));
	}' unless defined(&SDLA_MAGIC);
    }
    undef(&EXTERN) if defined(&EXTERN);
}
1;
