Index: arch/acorn32/podulebus/if_ne_pbus.c =================================================================== RCS file: /cvsroot/src/sys/arch/acorn32/podulebus/if_ne_pbus.c,v retrieving revision 1.15 diff -u -r1.15 if_ne_pbus.c --- arch/acorn32/podulebus/if_ne_pbus.c 28 Apr 2008 20:23:10 -0000 1.15 +++ arch/acorn32/podulebus/if_ne_pbus.c 24 Feb 2010 16:17:16 -0000 @@ -393,6 +393,9 @@ case NE2000_TYPE_DL10022: aprint_normal("DL10022"); break; + case NE2000_TYPE_RTL8019: + aprint_normal("NE2000 (RTL8019)"); + break; default: printf("??"); }; Index: arch/x68k/dev/if_ne_intio.c =================================================================== RCS file: /cvsroot/src/sys/arch/x68k/dev/if_ne_intio.c,v retrieving revision 1.15 diff -u -r1.15 if_ne_intio.c --- arch/x68k/dev/if_ne_intio.c 19 Jan 2010 22:06:23 -0000 1.15 +++ arch/x68k/dev/if_ne_intio.c 24 Feb 2010 16:17:16 -0000 @@ -74,8 +74,6 @@ #include #include #include -#include -#include #include @@ -187,21 +185,10 @@ case NE2000_TYPE_NE2000: typestr = "NE2000"; - /* - * Check for a Realtek 8019. - */ - bus_space_write_1(iot, ioh, ED_P0_CR, - ED_CR_PAGE_0 | ED_CR_STP); - if (bus_space_read_1(iot, ioh, NERTL_RTL0_8019ID0) == - RTL0_8019ID0 && - bus_space_read_1(iot, ioh, NERTL_RTL0_8019ID1) == - RTL0_8019ID1) { - typestr = "NE2000 (RTL8019)"; - dsc->sc_mediachange = rtl80x9_mediachange; - dsc->sc_mediastatus = rtl80x9_mediastatus; - dsc->init_card = rtl80x9_init_card; - dsc->sc_media_init = rtl80x9_media_init; - } + break; + + case NE2000_TYPE_RTL8019: + typestr = "NE2000 (RTL8019)"; break; default: Index: arch/x68k/dev/if_ne_neptune.c =================================================================== RCS file: /cvsroot/src/sys/arch/x68k/dev/if_ne_neptune.c,v retrieving revision 1.19 diff -u -r1.19 if_ne_neptune.c --- arch/x68k/dev/if_ne_neptune.c 19 Jan 2010 22:06:23 -0000 1.19 +++ arch/x68k/dev/if_ne_neptune.c 24 Feb 2010 16:17:16 -0000 @@ -72,9 +72,6 @@ #include #include -#include -#include - #include static int ne_neptune_match(device_t, cfdata_t, void *); @@ -165,21 +162,10 @@ case NE2000_TYPE_NE2000: typestr = "NE2000"; - /* - * Check for a Realtek 8019. - */ - bus_space_write_1(nict, nich, ED_P0_CR, - ED_CR_PAGE_0 | ED_CR_STP); - if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == - RTL0_8019ID0 && - bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == - RTL0_8019ID1) { - typestr = "NE2000 (RTL8019)"; - dsc->sc_mediachange = rtl80x9_mediachange; - dsc->sc_mediastatus = rtl80x9_mediastatus; - dsc->init_card = rtl80x9_init_card; - dsc->sc_media_init = rtl80x9_media_init; - } + break; + + case NE2000_TYPE_RTL8019: + typestr = "NE2000 (RTL8019)"; break; default: Index: dev/ic/ne2000.c =================================================================== RCS file: /cvsroot/src/sys/dev/ic/ne2000.c,v retrieving revision 1.66 diff -u -r1.66 ne2000.c --- dev/ic/ne2000.c 24 Feb 2010 15:18:15 -0000 1.66 +++ dev/ic/ne2000.c 24 Feb 2010 16:17:16 -0000 @@ -85,6 +85,9 @@ #include #include +#include +#include + #include int ne2000_write_mbuf(struct dp8390_softc *, struct mbuf *, int); @@ -110,8 +113,8 @@ bus_space_handle_t nich = dsc->sc_regh; bus_space_tag_t asict = nsc->sc_asict; bus_space_handle_t asich = nsc->sc_asich; - u_int8_t romdata[16]; - int memsize, i, useword, dmawidth; + u_int8_t romdata[32]; + int memstart, memsize, i, useword; /* * Detect it again unless caller specified it; this gives us @@ -130,30 +133,39 @@ aprint_error_dev(dsc->sc_dev, "where did the card go?\n"); return (1); case NE2000_TYPE_NE1000: + memstart = 8192; memsize = 8192; useword = 0; - dmawidth = NE2000_DMAWIDTH_8BIT; break; case NE2000_TYPE_NE2000: case NE2000_TYPE_AX88190: /* XXX really? */ case NE2000_TYPE_AX88790: - memsize = 8192 * 2; + case NE2000_TYPE_RTL8019: + memstart = 16384; + memsize = 16384; useword = 1; - dmawidth = NE2000_DMAWIDTH_16BIT; + if ((nsc->sc_quirk & NE2000_QUIRK_8BIT) != 0) { + /* in 8 bit mode, only 8KB memory can be used */ + memsize = 8192; + useword = 0; + } break; case NE2000_TYPE_DL10019: case NE2000_TYPE_DL10022: + memstart = 8192 * 3; memsize = 8192 * 3; useword = 1; - dmawidth = NE2000_DMAWIDTH_16BIT; break; } nsc->sc_useword = useword; - if (nsc->sc_dmawidth == NE2000_DMAWIDTH_UNKNOWN) - nsc->sc_dmawidth = dmawidth; - else - dmawidth = nsc->sc_dmawidth; +printf("useword = %d\n", useword); + if (nsc->sc_type == NE2000_TYPE_RTL8019) { + dsc->init_card = rtl80x9_init_card; + dsc->sc_media_init = rtl80x9_media_init; + dsc->sc_mediachange = rtl80x9_mediachange; + dsc->sc_mediastatus = rtl80x9_mediastatus; + } dsc->cr_proto = ED_CR_RD2; if (nsc->sc_type == NE2000_TYPE_AX88190 || @@ -171,8 +183,7 @@ * * NE1000 gets byte-wide DMA, NE2000 gets word-wide DMA. */ - dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS | - ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0); + dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS | (useword ? ED_DCR_WTS : 0); dsc->test_mem = ne2000_test_mem; dsc->ring_copy = ne2000_ring_copy; @@ -186,16 +197,14 @@ /* * NIC memory doens't start at zero on an NE board. * The start address is tied to the bus width. - * (It happens to be computed the same way as mem size.) */ - dsc->mem_start = memsize; - #ifdef GWETHER { - int x, mstart = 0; + int x; int8_t pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE], tbuf[ED_PAGE_SIZE]; + memstart = 0; for (i = 0; i < ED_PAGE_SIZE; i++) pbuf0[i] = 0; @@ -215,14 +224,14 @@ x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword); if (memcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) { - mstart = x << ED_PAGE_SHIFT; + memstart = x << ED_PAGE_SHIFT; memsize = ED_PAGE_SIZE; break; } } } - if (mstart == 0) { + if (memstart == 0) { aprint_error_dev(&dsc->sc_dev, "cannot find start of RAM\n"); return (1); } @@ -251,11 +260,10 @@ } printf("%s: RAM start 0x%x, size %d\n", - device_xname(&dsc->sc_dev), mstart, memsize); - - dsc->mem_start = mstart; + device_xname(&dsc->sc_dev), memstart, memsize); } #endif /* GWETHER */ + dsc->mem_start = memstart; dsc->mem_size = memsize; @@ -270,17 +278,30 @@ NIC_BARRIER(nict, nich); /* Select word transfer. */ bus_space_write_1(nict, nich, ED_P0_DCR, - ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0)); + useword ? ED_DCR_WTS : 0); NIC_BARRIER(nict, nich); ne2000_readmem(nict, nich, asict, asich, AX88190_NODEID_OFFSET, dsc->sc_enaddr, ETHER_ADDR_LEN, useword); } else { + bool ne1000 = (nsc->sc_type == NE2000_TYPE_NE1000); + ne2000_readmem(nict, nich, asict, asich, 0, romdata, sizeof(romdata), useword); for (i = 0; i < ETHER_ADDR_LEN; i++) dsc->sc_enaddr[i] = - romdata[i * (useword ? 2 : 1)]; + romdata[i * (ne1000 ? 1 : 2)]; +#if 1 +{ + for (i = 0; i < sizeof(romdata); i++) { + if (i % 16 == 0) + printf("rom 0x%04x: ", i); + printf("%02x ", romdata[i]); + if (i % 16 == 16 - 1) + printf("\n"); + } +} +#endif } } else memcpy(dsc->sc_enaddr, myea, sizeof(dsc->sc_enaddr)); @@ -310,9 +331,8 @@ static u_int8_t test_pattern[32] = "THIS is A memory TEST pattern"; u_int8_t test_buffer[32], tmp; int i, rv = NE2000_TYPE_UNKNOWN; - int dmawidth = NE2000_DMAWIDTH_16BIT; + int useword; - restart: /* Reset the board. */ #ifdef GWETHER bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0); @@ -426,45 +446,53 @@ ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer, sizeof(test_buffer), 0); - if (memcmp(test_pattern, test_buffer, sizeof(test_pattern))) { - /* not an NE1000 - try NE2000 */ - bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS - | ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0)); - bus_space_write_1(nict, nich, ED_P0_PSTART, - 16384 >> ED_PAGE_SHIFT); - bus_space_write_1(nict, nich, ED_P0_PSTOP, - 32768 >> ED_PAGE_SHIFT); - - /* - * Write the test pattern in word mode. If this also fails, - * then we don't know what this board is. - */ - ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384, - sizeof(test_pattern), 1, 0); - ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer, - sizeof(test_buffer), 1); - - if (memcmp(test_pattern, test_buffer, sizeof(test_pattern))) { - if (dmawidth == NE2000_DMAWIDTH_16BIT) { - /* try 8bit dma */ - dmawidth = NE2000_DMAWIDTH_8BIT; - goto restart; - } - goto out; /* not an NE2000 either */ - } - - rv = NE2000_TYPE_NE2000; - } else { + if (memcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) { /* We're an NE1000. */ rv = NE2000_TYPE_NE1000; - dmawidth = NE2000_DMAWIDTH_8BIT; + goto out; + } + + /* not an NE1000 - try NE2000 */ + + /* try 16 bit mode first */ + useword = 1; + again: + bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS | + (useword ? ED_DCR_WTS : 0)); + bus_space_write_1(nict, nich, ED_P0_PSTART, 16384 >> ED_PAGE_SHIFT); + bus_space_write_1(nict, nich, ED_P0_PSTOP, 32768 >> ED_PAGE_SHIFT); + + /* + * Write the test pattern in word mode. If this also fails, + * then we don't know what this board is. + */ + ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384, + sizeof(test_pattern), useword, 0); + ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer, + sizeof(test_buffer), useword); + + if (memcmp(test_pattern, test_buffer, sizeof(test_pattern)) != 0) { + if (useword == 1) { + /* try 8 bit mode */ + useword = 0; + goto again; + } + return NE2000_TYPE_UNKNOWN; /* not an NE2000 either */ } + rv = NE2000_TYPE_NE2000; + + /* Check for a Realtek RTL8019. */ + bus_space_write_1(nict, nich, ED_P0_CR, ED_CR_PAGE_0 | ED_CR_STP); + if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == RTL0_8019ID0 && + bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == RTL0_8019ID1) + rv = NE2000_TYPE_RTL8019; + + out: /* Clear any pending interrupts that might have occurred above. */ NIC_BARRIER(nict, nich); bus_space_write_1(nict, nich, ED_P0_ISR, 0xff); - out: return (rv); } @@ -521,8 +549,8 @@ * so that case requires some extra code to patch over odd-length * mbufs. */ - if (nsc->sc_type == NE2000_TYPE_NE1000) { - /* NE1000s are easy. */ + if (nsc->sc_useword == 0) { + /* byte ops are easy. */ for (; m != 0; m = m->m_next) { if (m->m_len) { bus_space_write_multi_1(asict, asich, @@ -536,7 +564,7 @@ NE2000_ASIC_DATA, 0); } } else { - /* NE2000s are a bit trickier. */ + /* word ops are a bit trickier. */ u_int8_t *data, savebyte[2]; int l, leftover; #ifdef DIAGNOSTIC Index: dev/ic/ne2000var.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/ne2000var.h,v retrieving revision 1.23 diff -u -r1.23 ne2000var.h --- dev/ic/ne2000var.h 8 Jan 2010 20:02:39 -0000 1.23 +++ dev/ic/ne2000var.h 24 Feb 2010 16:17:16 -0000 @@ -46,14 +46,12 @@ NE2000_TYPE_DL10019, NE2000_TYPE_DL10022, NE2000_TYPE_AX88190, - NE2000_TYPE_AX88790 + NE2000_TYPE_AX88790, + NE2000_TYPE_RTL8019 } sc_type; int sc_useword; - enum { - NE2000_DMAWIDTH_UNKNOWN = 0, - NE2000_DMAWIDTH_16BIT, - NE2000_DMAWIDTH_8BIT, - } sc_dmawidth; + u_int sc_quirk; /* quirks passed from attachments */ +#define NE2000_QUIRK_8BIT 0x0001 /* force 8bit mode even on NE2000 */ }; int ne2000_attach(struct ne2000_softc *, u_int8_t *); Index: dev/isa/if_ne_isa.c =================================================================== RCS file: /cvsroot/src/sys/dev/isa/if_ne_isa.c,v retrieving revision 1.26 diff -u -r1.26 if_ne_isa.c --- dev/isa/if_ne_isa.c 28 Apr 2008 20:23:52 -0000 1.26 +++ dev/isa/if_ne_isa.c 24 Feb 2010 16:17:16 -0000 @@ -57,9 +57,6 @@ #include #include -#include -#include - #include int ne_isa_match(device_t, cfdata_t, void *); @@ -178,21 +175,10 @@ case NE2000_TYPE_NE2000: typestr = "NE2000"; - /* - * Check for a Realtek 8019. - */ - bus_space_write_1(nict, nich, ED_P0_CR, - ED_CR_PAGE_0 | ED_CR_STP); - if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == - RTL0_8019ID0 && - bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == - RTL0_8019ID1) { - typestr = "NE2000 (RTL8019)"; - dsc->sc_mediachange = rtl80x9_mediachange; - dsc->sc_mediastatus = rtl80x9_mediastatus; - dsc->init_card = rtl80x9_init_card; - dsc->sc_media_init = rtl80x9_media_init; - } + break; + + case NE2000_TYPE_RTL8019: + typestr = "NE2000 (RTL8019)"; break; default: @@ -209,6 +195,7 @@ * Do generic NE2000 attach. This will read the station address * from the EEPROM. */ +nsc->sc_quirk = NE2000_QUIRK_8BIT; ne2000_attach(nsc, NULL); /* Establish the interrupt handler. */ Index: dev/isapnp/if_ne_isapnp.c =================================================================== RCS file: /cvsroot/src/sys/dev/isapnp/if_ne_isapnp.c,v retrieving revision 1.26 diff -u -r1.26 if_ne_isapnp.c --- dev/isapnp/if_ne_isapnp.c 28 Apr 2008 20:23:53 -0000 1.26 +++ dev/isapnp/if_ne_isapnp.c 24 Feb 2010 16:17:16 -0000 @@ -57,9 +57,6 @@ #include #include -#include -#include - #include #include @@ -142,21 +139,10 @@ case NE2000_TYPE_NE2000: typestr = "NE2000"; - /* - * Check for a Realtek 8019. - */ - bus_space_write_1(nict, nich, ED_P0_CR, - ED_CR_PAGE_0 | ED_CR_STP); - if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == - RTL0_8019ID0 && - bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == - RTL0_8019ID1) { - typestr = "NE2000 (RTL8019)"; - dsc->sc_mediachange = rtl80x9_mediachange; - dsc->sc_mediastatus = rtl80x9_mediastatus; - dsc->init_card = rtl80x9_init_card; - dsc->sc_media_init = rtl80x9_media_init; - } + break; + + case NE2000_TYPE_RTL8019: + typestr = "NE2000 (RTL8019)"; break; default: