require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_ISP_TPUBLIC_H)) {
    eval 'sub _ISP_TPUBLIC_H () {1;}' unless defined(&_ISP_TPUBLIC_H);
    eval("sub QOUT_HBA_REG () { 0; }") unless defined(&QOUT_HBA_REG);
    eval("sub QOUT_ENABLE () { 1; }") unless defined(&QOUT_ENABLE);
    eval("sub QOUT_DISABLE () { 2; }") unless defined(&QOUT_DISABLE);
    eval("sub QOUT_TMD_START () { 3; }") unless defined(&QOUT_TMD_START);
    eval("sub QOUT_TMD_DONE () { 4; }") unless defined(&QOUT_TMD_DONE);
    eval("sub QOUT_NOTIFY () { 5; }") unless defined(&QOUT_NOTIFY);
    eval("sub QOUT_HBA_UNREG () { 6; }") unless defined(&QOUT_HBA_UNREG);
    eval("sub QIN_HBA_REG () { 99; }") unless defined(&QIN_HBA_REG);
    eval("sub QIN_GETINFO () { 100; }") unless defined(&QIN_GETINFO);
    eval("sub QIN_SETINFO () { 101; }") unless defined(&QIN_SETINFO);
    eval("sub QIN_GETDLIST () { 102; }") unless defined(&QIN_GETDLIST);
    eval("sub QIN_ENABLE () { 103; }") unless defined(&QIN_ENABLE);
    eval("sub QIN_DISABLE () { 104; }") unless defined(&QIN_DISABLE);
    eval("sub QIN_TMD_CONT () { 105; }") unless defined(&QIN_TMD_CONT);
    eval("sub QIN_TMD_FIN () { 106; }") unless defined(&QIN_TMD_FIN);
    eval("sub QIN_NOTIFY_ACK () { 107; }") unless defined(&QIN_NOTIFY_ACK);
    eval("sub QIN_HBA_UNREG () { 108; }") unless defined(&QIN_HBA_UNREG);
    eval 'sub QR_VERSION () {16;}' unless defined(&QR_VERSION);
    eval("sub R_FC () { 0; }") unless defined(&R_FC);
    eval("sub R_SPI () { 1; }") unless defined(&R_SPI);
    eval("sub I_FC () { 0; }") unless defined(&I_FC);
    eval("sub I_SPI () { 1; }") unless defined(&I_SPI);
    eval("sub NT_ABORT_TASK () { 0x1000; }") unless defined(&NT_ABORT_TASK);
    eval("sub NT_ABORT_TASK_SET () { 1; }") unless defined(&NT_ABORT_TASK_SET);
    eval("sub NT_CLEAR_ACA () { 2; }") unless defined(&NT_CLEAR_ACA);
    eval("sub NT_CLEAR_TASK_SET () { 3; }") unless defined(&NT_CLEAR_TASK_SET);
    eval("sub NT_LUN_RESET () { 4; }") unless defined(&NT_LUN_RESET);
    eval("sub NT_TARGET_RESET () { 5; }") unless defined(&NT_TARGET_RESET);
    eval("sub NT_BUS_RESET () { 6; }") unless defined(&NT_BUS_RESET);
    eval("sub NT_LIP_RESET () { 7; }") unless defined(&NT_LIP_RESET);
    eval("sub NT_LINK_UP () { 8; }") unless defined(&NT_LINK_UP);
    eval("sub NT_LINK_DOWN () { 9; }") unless defined(&NT_LINK_DOWN);
    eval("sub NT_LOGOUT () { 10; }") unless defined(&NT_LOGOUT);
    eval("sub NT_HBA_RESET () { 11; }") unless defined(&NT_HBA_RESET);
    eval 'sub LUN_ANY () {0xffff;}' unless defined(&LUN_ANY);
    eval 'sub TGT_ANY () {(( &u_int64_t) -1);}' unless defined(&TGT_ANY);
    eval 'sub INI_ANY () {(( &u_int64_t) -1);}' unless defined(&INI_ANY);
    eval 'sub TAG_ANY () {(( &u_int64_t) 0);}' unless defined(&TAG_ANY);
    eval 'sub MATCH_TMD {
        my($tmd, $iid, $lun, $tag) = @_;
	    eval q(( ($tmd)  && ($iid ==  &INI_ANY || $iid ==  ($tmd->{cd_iid}))  && ($lun ==  &LUN_ANY || $lun ==  ($tmd->{cd_lun}))  && ($tag ==  &TAG_ANY || $tag ==  ($tmd->{cd_tagval})) ));
    }' unless defined(&MATCH_TMD);
    unless(defined(&TMD_CDBLEN)) {
	eval 'sub TMD_CDBLEN () {16;}' unless defined(&TMD_CDBLEN);
    }
    unless(defined(&TMD_SENSELEN)) {
	eval 'sub TMD_SENSELEN () {18;}' unless defined(&TMD_SENSELEN);
    }
    unless(defined(&QCDS)) {
	eval 'sub QCDS () {($sizeof{ &void });}' unless defined(&QCDS);
    }
    eval 'sub CD_UNTAGGED () {0;}' unless defined(&CD_UNTAGGED);
    eval 'sub CD_SIMPLE_TAG () {1;}' unless defined(&CD_SIMPLE_TAG);
    eval 'sub CD_ORDERED_TAG () {2;}' unless defined(&CD_ORDERED_TAG);
    eval 'sub CD_HEAD_TAG () {3;}' unless defined(&CD_HEAD_TAG);
    eval 'sub CD_ACA_TAG () {4;}' unless defined(&CD_ACA_TAG);
    unless(defined(&TMD_SIZE)) {
	eval 'sub TMD_SIZE () {($sizeof{ &tmd_cmd_t});}' unless defined(&TMD_SIZE);
    }
    eval 'sub L0LUN_TO_FLATLUN {
        my($lptr) = @_;
	    eval q((((($lptr)[0] & 0x3f) << 8) | (($lptr)[1])));
    }' unless defined(&L0LUN_TO_FLATLUN);
    eval 'sub FLATLUN_TO_L0LUN {
        my($lptr, $lun) = @_;
	    eval q(($lptr)[1] = $lun & 0xff;  &if ($sizeof{$lun} == 1) { ($lptr)[0] = 0; }  &else {  &u_int16_t  &nl = $lun;  &if ( &nl ==  &LUN_ANY) { ($lptr)[0] = ( &nl >> 8) & 0xff; }  &else  &if ( &nl < 256) { ($lptr)[0] = 0; }  &else { ($lptr)[0] = 0x40 | (( &nl >> 8) & 0x3f); } }  &memset(($lptr)[2], 0, 6));
    }' unless defined(&FLATLUN_TO_L0LUN);
    eval 'sub CDFL_SNSVALID () {0x1;}' unless defined(&CDFL_SNSVALID);
    eval 'sub CDFL_SENTSTATUS () {0x2;}' unless defined(&CDFL_SENTSTATUS);
    eval 'sub CDFL_DATA_IN () {0x4;}' unless defined(&CDFL_DATA_IN);
    eval 'sub CDFL_DATA_OUT () {0x8;}' unless defined(&CDFL_DATA_OUT);
    eval 'sub CDFL_BIDIR () {0xc;}' unless defined(&CDFL_BIDIR);
    eval 'sub CDFL_ERROR () {0x10;}' unless defined(&CDFL_ERROR);
    eval 'sub CDFL_NODISC () {0x20;}' unless defined(&CDFL_NODISC);
    eval 'sub CDFL_SENTSENSE () {0x40;}' unless defined(&CDFL_SENTSENSE);
    eval 'sub CDFL_BUSY () {0x80;}' unless defined(&CDFL_BUSY);
    eval 'sub CDFL_PRIVATE () {0xff000000;}' unless defined(&CDFL_PRIVATE);
    eval 'sub CDFH_SNSVALID () {0x1;}' unless defined(&CDFH_SNSVALID);
    eval 'sub CDFH_STSVALID () {0x2;}' unless defined(&CDFH_STSVALID);
    eval 'sub CDFH_DATA_IN () {0x4;}' unless defined(&CDFH_DATA_IN);
    eval 'sub CDFH_DATA_OUT () {0x8;}' unless defined(&CDFH_DATA_OUT);
    eval 'sub CDFH_DATA_MASK () {0xc;}' unless defined(&CDFH_DATA_MASK);
    eval 'sub CDFH_PRIVATE () {0xff000000;}' unless defined(&CDFH_PRIVATE);
}
1;
