⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 if_de.c

📁 国产CPU-龙芯(loongson)BIOS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			  TULIP_GP_EM100_INIT,			  TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION			      |TULIP_CMD_FULLDUPLEX);    } else {	TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);	sc->tulip_media = TULIP_MEDIA_100BASETX;	tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,			  TULIP_GP_EM100_INIT,			  TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION			      |TULIP_CMD_SCRAMBLER);	tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,			  TULIP_GP_EM100_INIT,			  TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION			      |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);    }}static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {    TULIP_21140_COGENT_EM100,    tulip_21140_cogent_em100_media_probe,    tulip_media_select,    tulip_null_media_poll,    tulip_2114x_media_preset};static voidtulip_2114x_media_probe(    tulip_softc_t * const sc){    sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE	|TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;}static const tulip_boardsw_t tulip_2114x_isv_boardsw = {    TULIP_21140_ISV,    tulip_2114x_media_probe,    tulip_media_select,    tulip_media_poll,    tulip_2114x_media_preset,};/* * ******** END of chip-specific handlers. *********** *//* * Code the read the SROM and MII bit streams (I2C) */static voidtulip_delay_300ns(    tulip_softc_t * const sc){    delay(1);}#define EMIT    do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)static voidtulip_srom_idle(    tulip_softc_t * const sc){    unsigned bit, csr;        csr  = SROMSEL ; EMIT;    csr  = SROMSEL | SROMRD; EMIT;      csr ^= SROMCS; EMIT;    csr ^= SROMCLKON; EMIT;    /*     * Write 25 cycles of 0 which will force the SROM to be idle.     */    for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {        csr ^= SROMCLKOFF; EMIT;    /* clock low; data not valid */        csr ^= SROMCLKON; EMIT;     /* clock high; data valid */    }    csr ^= SROMCLKOFF; EMIT;    csr ^= SROMCS; EMIT;    csr  = 0; EMIT;}     static voidtulip_srom_read(    tulip_softc_t * const sc){       unsigned idx; #ifdef SBS_SROM_BRAINDAMAGE    const unsigned bitwidth = SROM_BITWIDTH+1;#else    const unsigned bitwidth = SROM_BITWIDTH;#endif    const unsigned cmdmask = (SROMCMD_RD << bitwidth);    const unsigned msb = 1 << (bitwidth + 3 - 1);    unsigned lastidx = (1 << bitwidth) - 1;    tulip_srom_idle(sc);    for (idx = 0; idx <= lastidx; idx++) {        unsigned lastbit, data, bits, bit, csr;	csr  = SROMSEL ;	        EMIT;        csr  = SROMSEL | SROMRD;        EMIT;        csr ^= SROMCSON;                EMIT;        csr ^=            SROMCLKON;    EMIT;            lastbit = 0;        for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {            const unsigned thisbit = bits & msb;            csr ^= SROMCLKOFF; EMIT;    /* clock low; data not valid */            if (thisbit != lastbit) {                csr ^= SROMDOUT; EMIT;  /* clock low; invert data */            } else {		EMIT;	    }            csr ^= SROMCLKON; EMIT;     /* clock high; data valid */            lastbit = thisbit;        }        csr ^= SROMCLKOFF; EMIT;        for (data = 0, bits = 0; bits < 16; bits++) {            data <<= 1;            csr ^= SROMCLKON; EMIT;     /* clock high; data valid */             data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;            csr ^= SROMCLKOFF; EMIT;    /* clock low; data not valid */        }#ifdef SBS_SROM_BRAINDAMAGE	sc->tulip_rombuf[idx] = data >> 8;#else	sc->tulip_rombuf[idx*2] = data & 0xFF;	sc->tulip_rombuf[idx*2+1] = data >> 8;#endif	csr  = SROMSEL | SROMRD; EMIT;	csr  = 0; EMIT;    }    tulip_srom_idle(sc);}#define MII_EMIT    do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)static voidtulip_mii_writebits(    tulip_softc_t * const sc,    unsigned data,    unsigned bits){    unsigned msb = 1 << (bits - 1);    unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);    unsigned lastbit = (csr & MII_DOUT) ? msb : 0;    csr |= MII_WR; MII_EMIT;  		/* clock low; assert write */    for (; bits > 0; bits--, data <<= 1) {	const unsigned thisbit = data & msb;	if (thisbit != lastbit) {	    csr ^= MII_DOUT; MII_EMIT;  /* clock low; invert data */	}	csr ^= MII_CLKON; MII_EMIT;     /* clock high; data valid */	lastbit = thisbit;	csr ^= MII_CLKOFF; MII_EMIT;    /* clock low; data not valid */    }}static voidtulip_mii_turnaround(    tulip_softc_t * const sc,    unsigned cmd){    unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);    if (cmd == MII_WRCMD) {	csr |= MII_DOUT; MII_EMIT;	/* clock low; change data */	csr ^= MII_CLKON; MII_EMIT;	/* clock high; data valid */	csr ^= MII_CLKOFF; MII_EMIT;	/* clock low; data not valid */	csr ^= MII_DOUT; MII_EMIT;	/* clock low; change data */    } else {	csr |= MII_RD; MII_EMIT;	/* clock low; switch to read */    }    csr ^= MII_CLKON; MII_EMIT;		/* clock high; data valid */    csr ^= MII_CLKOFF; MII_EMIT;	/* clock low; data not valid */}static unsignedtulip_mii_readbits(    tulip_softc_t * const sc){    unsigned data;    unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);    int idx;    for (idx = 0, data = 0; idx < 16; idx++) {	data <<= 1;	/* this is NOOP on the first pass through */	csr ^= MII_CLKON; MII_EMIT;	/* clock high; data valid */	if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)	    data |= 1;	csr ^= MII_CLKOFF; MII_EMIT;	/* clock low; data not valid */    }    csr ^= MII_RD; MII_EMIT;		/* clock low; turn off read */    return data;}static unsignedtulip_mii_readreg(    tulip_softc_t * const sc,    unsigned devaddr,    unsigned regno){    unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);    unsigned data;    csr &= ~(MII_RD|MII_CLK); MII_EMIT;    tulip_mii_writebits(sc, MII_PREAMBLE, 32);    tulip_mii_writebits(sc, MII_RDCMD, 8);    tulip_mii_writebits(sc, devaddr, 5);    tulip_mii_writebits(sc, regno, 5);    tulip_mii_turnaround(sc, MII_RDCMD);    data = tulip_mii_readbits(sc);#if defined(TULIP_DEBUG)    sc->tulip_dbg.dbg_phyregs[regno][0] = data;    sc->tulip_dbg.dbg_phyregs[regno][1]++;#endif    return data;}static voidtulip_mii_writereg(    tulip_softc_t * const sc,    unsigned devaddr,    unsigned regno,    unsigned data){    unsigned csr;    csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);    csr &= ~(MII_RD|MII_CLK); MII_EMIT;    tulip_mii_writebits(sc, MII_PREAMBLE, 32);    tulip_mii_writebits(sc, MII_WRCMD, 8);    tulip_mii_writebits(sc, devaddr, 5);    tulip_mii_writebits(sc, regno, 5);    tulip_mii_turnaround(sc, MII_WRCMD);    tulip_mii_writebits(sc, data, 16);#if defined(TULIP_DEBUG)    sc->tulip_dbg.dbg_phyregs[regno][2] = data;    sc->tulip_dbg.dbg_phyregs[regno][3]++;#endif}#define	tulip_mchash(mca)	(tulip_crc32(mca, 6) & 0x1FF)#define	tulip_srom_crcok(databuf)	( \    ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \     ((databuf)[126] | ((databuf)[127] << 8)))static unsignedtulip_crc32(    const unsigned char *databuf,    size_t datalen){    u_int idx, crc = 0xFFFFFFFFUL;    static const u_int crctab[] = {	0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,	0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,	0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,	0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c    };    for (idx = 0; idx < datalen; idx++) {	crc ^= *databuf++;	crc = (crc >> 4) ^ crctab[crc & 0xf];	crc = (crc >> 4) ^ crctab[crc & 0xf];    }    return crc;}static voidtulip_identify_dec_nic(    tulip_softc_t * const sc){    strcpy(sc->tulip_boardid, "DEC ");#define D0	4    if (sc->tulip_chipid <= TULIP_DE425)	return;    if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0	|| bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {	bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);	sc->tulip_boardid[D0+8] = ' ';    }#undef D0}static voidtulip_identify_smc_nic(    tulip_softc_t * const sc){    u_int32_t id1, id2, ei;    int auibnc = 0, utp = 0;    char *cp;    strcpy(sc->tulip_boardid, "SMC ");    if (sc->tulip_chipid == TULIP_21041)	return;    if (sc->tulip_chipid != TULIP_21040) {	if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {	    strcpy(&sc->tulip_boardid[4], "9332DST ");	    sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;	} else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {	    strcpy(&sc->tulip_boardid[4], "9334BDT ");	} else {	    strcpy(&sc->tulip_boardid[4], "9332BDT ");	}	return;    }    id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);    id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);    ei  = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);    strcpy(&sc->tulip_boardid[4], "8432");    cp = &sc->tulip_boardid[8];    if ((id1 & 1) == 0)	*cp++ = 'B', auibnc = 1;    if ((id1 & 0xFF) > 0x32)	*cp++ = 'T', utp = 1;    if ((id1 & 0x4000) == 0)	*cp++ = 'A', auibnc = 1;    if (id2 == 0x15) {	sc->tulip_boardid[7] = '4';	*cp++ = '-';	*cp++ = 'C';	*cp++ = 'H';	*cp++ = (ei ? '2' : '1');    }    *cp++ = ' ';    *cp = '\0';    if (utp && !auibnc)	sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;    else if (!utp && auibnc)	sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;}static voidtulip_identify_cogent_nic(    tulip_softc_t * const sc){    strcpy(sc->tulip_boardid, "Cogent ");    if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {	if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {	    strcat(sc->tulip_boardid, "EM100TX ");	    sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;#if defined(TULIP_COGENT_EM110TX_ID)	} else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {	    strcat(sc->tulip_boardid, "EM110TX ");	    sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;#endif	} else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {	    strcat(sc->tulip_boardid, "EM100FX ");	    sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;	}	/*	 * Magic number (0x24001109U) is the SubVendor (0x2400) and	 * SubDevId (0x1109) for the ANA6944TX (EM440TX).	 */	if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U		&& (sc->tulip_features & TULIP_HAVE_BASEROM)) {	    /*	     * Cogent (Adaptec) is still mapping all INTs to INTA of	     * first 21140.  Dumb!  Dumb!	     */	    strcat(sc->tulip_boardid, "EM440TX ");	    sc->tulip_features |= TULIP_HAVE_SHAREDINTR;	}    } else if (sc->tulip_chipid == TULIP_21040) {	sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;    }}static voidtulip_identify_accton_nic(    tulip_softc_t * const sc){    strcpy(sc->tulip_boardid, "ACCTON ");    switch (sc->tulip_chipid) {	case TULIP_21140A:	    strcat(sc->tulip_boardid, "EN1207 ");	    if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)		sc->tulip_boardsw = &tulip_21140_accton_boardsw;	    break;	case TULIP_21140:	    strcat(sc->tulip_boardid, "EN1207TX ");	    if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)		sc->tulip_boardsw = &tulip_21140_eb_boardsw;            break;        case TULIP_21040:	    strcat(sc->tulip_boardid, "EN1203 ");            sc->tulip_boardsw = &tulip_21040_boardsw;            break;        case TULIP_21041:	    strcat(sc->tulip_boardid, "EN1203 ");            sc->tulip_boardsw = &tulip_21041_boardsw;            break;	default:            sc->tulip_boardsw = &tulip_2114x_isv_boardsw;            break;    }}static voidtulip_identify_asante_nic(    tulip_softc_t * const sc){    strcpy(sc->tulip_boardid, "Asante ");    if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)	    && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {	tulip_media_info_t *mi = sc->tulip_mediainfo;	int idx;	/*	 * The Asante Fast Ethernet doesn't always ship with a valid	 * new format SROM.  So if isn't in the new format, we cheat	 * set it up as if we had.	 */	sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;	sc->tulip_gpdata = 0;	TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);	TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);	DELAY(100);	TULIP_CSR_WRITE(sc, csr_gp, 0);	mi->mi_type = TULIP_MEDIAINFO_MII;	mi->mi_gpr_length = 0;	mi->mi_gpr_offset = 0;	mi->mi_reset_length = 0;	mi->mi_reset_of

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -