require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_IF_CASVAR_H)) {
    eval 'sub _IF_CASVAR_H () {1;}' unless defined(&_IF_CASVAR_H);
    require 'sys/queue.ph';
    require 'sys/timeout.ph';
    eval 'sub CAS_NTXSEGS () {16;}' unless defined(&CAS_NTXSEGS);
    eval 'sub CAS_TXQUEUELEN () {64;}' unless defined(&CAS_TXQUEUELEN);
    eval 'sub CAS_NTXDESC () {( &CAS_TXQUEUELEN *  &CAS_NTXSEGS);}' unless defined(&CAS_NTXDESC);
    eval 'sub CAS_NTXDESC_MASK () {( &CAS_NTXDESC - 1);}' unless defined(&CAS_NTXDESC_MASK);
    eval 'sub CAS_NEXTTX {
        my($x) = @_;
	    eval q((($x + 1) &  &CAS_NTXDESC_MASK));
    }' unless defined(&CAS_NEXTTX);
    eval 'sub CAS_NRXDESC () {128;}' unless defined(&CAS_NRXDESC);
    eval 'sub CAS_NRXDESC_MASK () {( &CAS_NRXDESC - 1);}' unless defined(&CAS_NRXDESC_MASK);
    eval 'sub CAS_NRXCOMP () {256;}' unless defined(&CAS_NRXCOMP);
    eval 'sub CAS_NRXCOMP_MASK () {( &CAS_NRXCOMP - 1);}' unless defined(&CAS_NRXCOMP_MASK);
    eval 'sub CAS_NEXTRX {
        my($x) = @_;
	    eval q((($x + 1) &  &CAS_NRXCOMP_MASK));
    }' unless defined(&CAS_NEXTRX);
    eval 'sub CAS_CDOFF {
        my($x) = @_;
	    eval q( &offsetof(\'struct cas_control_data\', $x));
    }' unless defined(&CAS_CDOFF);
    eval 'sub CAS_CDTXOFF {
        my($x) = @_;
	    eval q( &CAS_CDOFF( $ccd_txdescs[($x)]));
    }' unless defined(&CAS_CDTXOFF);
    eval 'sub CAS_CDRXOFF {
        my($x) = @_;
	    eval q( &CAS_CDOFF( $ccd_rxdescs[($x)]));
    }' unless defined(&CAS_CDRXOFF);
    eval 'sub CAS_CDRXCOFF {
        my($x) = @_;
	    eval q( &CAS_CDOFF( $ccd_rxcomps[($x)]));
    }' unless defined(&CAS_CDRXCOFF);
    eval 'sub sc_media () { ($sc_mii->{mii_media});}' unless defined(&sc_media);
    eval 'sub sc_cddma () { ($sc_cddmamap->{dm_segs[0]}->{ds_addr});}' unless defined(&sc_cddma);
    eval 'sub sc_txdescs () { ($sc_control_data->{ccd_txdescs});}' unless defined(&sc_txdescs);
    eval 'sub sc_rxdescs () { ($sc_control_data->{ccd_rxdescs});}' unless defined(&sc_rxdescs);
    eval 'sub sc_rxcomps () { ($sc_control_data->{ccd_rxcomps});}' unless defined(&sc_rxcomps);
    eval 'sub CAS_DMA_READ {
        my($v) = @_;
	    eval q( &letoh64($v));
    }' unless defined(&CAS_DMA_READ);
    eval 'sub CAS_DMA_WRITE {
        my($v) = @_;
	    eval q( &htole64($v));
    }' unless defined(&CAS_DMA_WRITE);
    eval 'sub CAS_CURRENT_MEDIA {
        my($sc) = @_;
	    eval q(( &IFM_SUBTYPE(($sc)-> ($sc_mii->{mii_media}->{ifm_cur}->{ifm_media})) !=  &IFM_AUTO ? ($sc)-> ($sc_mii->{mii_media}->{ifm_cur}) : ($sc)-> &sc_nway_active));
    }' unless defined(&CAS_CURRENT_MEDIA);
    eval 'sub CAS_MEDIA_NEEDSRESET {
        my($sc, $newbits) = @_;
	    eval q(((($sc)-> &sc_opmode &  &OPMODE_MEDIA_BITS) != (($newbits) &  &OPMODE_MEDIA_BITS)));
    }' unless defined(&CAS_MEDIA_NEEDSRESET);
    eval 'sub CAS_CDTXADDR {
        my($sc, $x) = @_;
	    eval q((($sc)-> &sc_cddma +  &CAS_CDTXOFF(($x))));
    }' unless defined(&CAS_CDTXADDR);
    eval 'sub CAS_CDRXADDR {
        my($sc, $x) = @_;
	    eval q((($sc)-> &sc_cddma +  &CAS_CDRXOFF(($x))));
    }' unless defined(&CAS_CDRXADDR);
    eval 'sub CAS_CDRXCADDR {
        my($sc, $x) = @_;
	    eval q((($sc)-> &sc_cddma +  &CAS_CDRXCOFF(($x))));
    }' unless defined(&CAS_CDRXCADDR);
    eval 'sub CAS_CDTXSYNC {
        my($sc, $x, $n, $ops) = @_;
	    eval q( &do { \'int\'  &__x,  &__n;  &__x = ($x);  &__n = ($n);  &if (( &__x +  &__n) >  &CAS_NTXDESC) {  &bus_dmamap_sync(($sc)-> &sc_dmatag, ($sc)-> &sc_cddmamap,  &CAS_CDTXOFF( &__x), $sizeof{\'struct cas_desc\'} * ( &CAS_NTXDESC -  &__x), ($ops));  &__n -= ( &CAS_NTXDESC -  &__x);  &__x = 0; }  &bus_dmamap_sync(($sc)-> &sc_dmatag, ($sc)-> &sc_cddmamap,  &CAS_CDTXOFF( &__x), $sizeof{\'struct cas_desc\'} *  &__n, ($ops)); }  &while (0));
    }' unless defined(&CAS_CDTXSYNC);
    eval 'sub CAS_CDRXSYNC {
        my($sc, $x, $ops) = @_;
	    eval q( &bus_dmamap_sync(($sc)-> &sc_dmatag, ($sc)-> &sc_cddmamap,  &CAS_CDRXOFF(($x)), $sizeof{\'struct cas_desc\'}, ($ops)));
    }' unless defined(&CAS_CDRXSYNC);
    eval 'sub CAS_CDRXCSYNC {
        my($sc, $x, $ops) = @_;
	    eval q( &bus_dmamap_sync(($sc)-> &sc_dmatag, ($sc)-> &sc_cddmamap,  &CAS_CDRXCOFF(($x)), $sizeof{\'struct cas_desc\'}, ($ops)));
    }' unless defined(&CAS_CDRXCSYNC);
    eval 'sub CAS_INIT_RXDESC {
        my($sc, $d, $s) = @_;
	    eval q( &do { \'struct cas_rxsoft\' * &__rxs =  ($sc->{sc_rxsoft[&(s)]}); \'struct cas_desc\' * &__rxd =  ($sc->{sc_rxdescs[&(d)]});  ($__rxd->{c$d_addr}) =  &CAS_DMA_WRITE( ($__rxs->{rxs_dmamap}->{dm_segs[0]}->{d$s_addr}));  ($__rxd->{c$d_flags}) =  &CAS_DMA_WRITE(($s));  &CAS_CDRXSYNC(($sc), ($d),  &BUS_DMASYNC_PREREAD| &BUS_DMASYNC_PREWRITE); }  &while (0));
    }' unless defined(&CAS_INIT_RXDESC);
}
1;
