Lines Matching +full:led +full:- +full:cur

1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
18 * 4. Neither the name of the author nor the names of any co-contributors
41 * Macronix/Lite-On 82c115 PNIC II (www.macronix.com)
42 * Lite-On 82c168/82c169 PNIC (www.litecom.com)
179 "Compex RL100-TX 10/100BaseTX" },
181 "Compex RL100-TX 10/100BaseTX" },
185 "Macronix 98715AEC-C 10/100BaseTX" },
203 "Neteasy DRP-32TXD Cardbus 10/100" },
213 "PlaneX FNW-3602-T CardBus 10/100" },
217 "Microsoft MN-120 CardBus 10/100" },
219 "Microsoft MN-130 10/100" },
302 * MII bit-bang glue
353 nitems(dc_devs) - 1);
370 for (idx = (300 / 33) + 1; idx > 0; idx--)
392 for (i = 3; i--;) {
420 sc->dc_romwidth = 6;
422 sc->dc_romwidth = i;
475 for (i = 3; i--; ) {
490 for (i = sc->dc_romwidth; i--;) {
506 * The PNIC 82c168/82c169 has its own non-standard way to read
529 * The Xircom X3201 has its own non-standard way to read
619 * Write the MII serial port for the MII bit-bang module.
634 * Read the MII serial port for the MII bit-bang module.
659 if (sc->dc_pmode != DC_PMODE_MII) {
660 if (phy == (MII_NPHY - 1)) {
697 if (sc->dc_type == DC_TYPE_ULI_M5263) {
749 if (sc->dc_type == DC_TYPE_98713) {
754 if (sc->dc_type == DC_TYPE_98713)
778 if (sc->dc_type == DC_TYPE_ULI_M5263) {
822 if (sc->dc_type == DC_TYPE_98713) {
827 if (sc->dc_type == DC_TYPE_98713)
843 mii = device_get_softc(sc->dc_miibus);
844 ifp = sc->dc_ifp;
849 ifm = &mii->mii_media;
850 if (DC_IS_DAVICOM(sc) && IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
851 dc_setcfg(sc, ifm->ifm_media);
854 dc_setcfg(sc, mii->mii_media_active);
856 sc->dc_link = 0;
857 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
859 switch (IFM_SUBTYPE(mii->mii_media_active)) {
862 sc->dc_link = 1;
887 mii = device_get_softc(sc->dc_miibus);
888 ifm = &mii->mii_media;
907 * The hash table on the PNIC II and the MX98715AEC-C/D/E
910 if (sc->dc_flags & DC_128BIT_HASH)
911 return (crc & ((1 << DC_BITS_128) - 1));
914 if (sc->dc_flags & DC_64BIT_HASH)
915 return (crc & ((1 << DC_BITS_64) - 1));
927 return (crc & ((1 << DC_BITS_512) - 1));
946 * 21143-style RX filter setup routine. Filter programming is done by
951 * address (our node address) and a 512-bit hash filter for multicast
962 sc->dc_cdata.dc_sbuf[h >> 4] |= htole32(1 << (h & 0xF));
976 ifp = sc->dc_ifp;
978 i = sc->dc_cdata.dc_tx_prod;
979 DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
980 sc->dc_cdata.dc_tx_cnt++;
981 sframe = &sc->dc_ldata.dc_tx_list[i];
982 sp = sc->dc_cdata.dc_sbuf;
985 sframe->dc_data = htole32(DC_ADDR_LO(sc->dc_saddr));
986 sframe->dc_ctl = htole32(DC_SFRAME_LEN | DC_TXCTL_SETUP |
989 sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)sc->dc_cdata.dc_sbuf;
1010 bcopy(if_getlladdr(sc->dc_ifp), eaddr, ETHER_ADDR_LEN);
1015 sframe->dc_status = htole32(DC_TXSTAT_OWN);
1016 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap, BUS_DMASYNC_PREREAD |
1018 bus_dmamap_sync(sc->dc_stag, sc->dc_smap, BUS_DMASYNC_PREWRITE);
1029 sc->dc_wdog_timer = 5;
1042 hashes[1] |= (1 << (h - 32));
1058 h = dc_mchash_le(ctx->sc, LLADDR(sdl));
1060 ctx->hashes[0] |= (1 << h);
1062 ctx->hashes[1] |= (1 << (h - 32));
1074 ifp = sc->dc_ifp;
1077 bcopy(if_getlladdr(sc->dc_ifp), eaddr, ETHER_ADDR_LEN);
1121 ifp = sc->dc_ifp;
1124 bcopy(if_getlladdr(sc->dc_ifp), eaddr, ETHER_ADDR_LEN);
1197 ifp = sc->dc_ifp;
1199 i = sc->dc_cdata.dc_tx_prod;
1200 DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
1201 sc->dc_cdata.dc_tx_cnt++;
1202 sframe = &sc->dc_ldata.dc_tx_list[i];
1203 sp = sc->dc_cdata.dc_sbuf;
1206 sframe->dc_data = htole32(DC_ADDR_LO(sc->dc_saddr));
1207 sframe->dc_ctl = htole32(DC_SFRAME_LEN | DC_TXCTL_SETUP |
1210 sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)sc->dc_cdata.dc_sbuf;
1213 bcopy(if_getlladdr(sc->dc_ifp), eaddr, ETHER_ADDR_LEN);
1251 sframe->dc_status = htole32(DC_TXSTAT_OWN);
1252 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap, BUS_DMASYNC_PREREAD |
1254 bus_dmamap_sync(sc->dc_stag, sc->dc_smap, BUS_DMASYNC_PREWRITE);
1262 sc->dc_wdog_timer = 5;
1272 sc->dc_cdata.dc_sbuf[h >> 4] |= htole32(1 << (h & 0xF));
1285 ifp = sc->dc_ifp;
1288 i = sc->dc_cdata.dc_tx_prod;
1289 DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
1290 sc->dc_cdata.dc_tx_cnt++;
1291 sframe = &sc->dc_ldata.dc_tx_list[i];
1292 sp = sc->dc_cdata.dc_sbuf;
1295 sframe->dc_data = htole32(DC_ADDR_LO(sc->dc_saddr));
1296 sframe->dc_ctl = htole32(DC_SFRAME_LEN | DC_TXCTL_SETUP |
1299 sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)sc->dc_cdata.dc_sbuf;
1320 bcopy(if_getlladdr(sc->dc_ifp), eaddr, ETHER_ADDR_LEN);
1327 sframe->dc_status = htole32(DC_TXSTAT_OWN);
1328 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap, BUS_DMASYNC_PREREAD |
1330 bus_dmamap_sync(sc->dc_stag, sc->dc_smap, BUS_DMASYNC_PREWRITE);
1338 sc->dc_wdog_timer = 5;
1376 if (i == DC_TIMEOUT && bus_child_present(sc->dc_dev)) {
1378 device_printf(sc->dc_dev,
1383 device_printf(sc->dc_dev,
1389 * In order to fiddle with the 'full-duplex' and '100Mbps' bits in
1410 if (sc->dc_pmode == DC_PMODE_MII) {
1422 if (sc->dc_type == DC_TYPE_98713)
1443 if (sc->dc_pmode == DC_PMODE_MII) {
1455 if (sc->dc_type == DC_TYPE_98713)
1492 sc->dc_link = 1;
1500 if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
1504 if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
1533 device_printf(sc->dc_dev, "reset never completed!\n");
1566 while (t->dc_name != NULL) {
1567 if (devid == t->dc_devid && rev >= t->dc_minrev)
1592 device_set_desc(dev, t->dc_name);
1607 m = sc->dc_mi;
1610 if (m->dc_media == media)
1612 m = m->dc_next;
1618 for (i = 0, p = m->dc_reset_ptr; i < m->dc_reset_len; i++, p += 2) {
1623 for (i = 0, p = m->dc_gp_ptr; i < m->dc_gp_len; i++, p += 2) {
1636 device_printf(sc->dc_dev, "Could not allocate mediainfo\n");
1639 switch (l->dc_sia_code & ~DC_SIA_CODE_EXT) {
1641 m->dc_media = IFM_10_T;
1644 m->dc_media = IFM_10_T | IFM_FDX;
1647 m->dc_media = IFM_10_2;
1650 m->dc_media = IFM_10_5;
1661 if (l->dc_sia_code & DC_SIA_CODE_EXT) {
1662 m->dc_gp_len = 2;
1663 m->dc_gp_ptr =
1664 (uint8_t *)&l->dc_un.dc_sia_ext.dc_sia_gpio_ctl;
1666 m->dc_gp_len = 2;
1667 m->dc_gp_ptr =
1668 (uint8_t *)&l->dc_un.dc_sia_noext.dc_sia_gpio_ctl;
1671 m->dc_next = sc->dc_mi;
1672 sc->dc_mi = m;
1674 sc->dc_pmode = DC_PMODE_SIA;
1685 device_printf(sc->dc_dev, "Could not allocate mediainfo\n");
1688 if (l->dc_sym_code == DC_SYM_CODE_100BT)
1689 m->dc_media = IFM_100_TX;
1691 if (l->dc_sym_code == DC_SYM_CODE_100BT_FDX)
1692 m->dc_media = IFM_100_TX | IFM_FDX;
1694 m->dc_gp_len = 2;
1695 m->dc_gp_ptr = (uint8_t *)&l->dc_sym_gpio_ctl;
1697 m->dc_next = sc->dc_mi;
1698 sc->dc_mi = m;
1700 sc->dc_pmode = DC_PMODE_SYM;
1712 device_printf(sc->dc_dev, "Could not allocate mediainfo\n");
1716 m->dc_media = IFM_AUTO;
1717 m->dc_gp_len = l->dc_gpr_len;
1721 m->dc_gp_ptr = p;
1722 p += 2 * l->dc_gpr_len;
1723 m->dc_reset_len = *p;
1725 m->dc_reset_ptr = p;
1727 m->dc_next = sc->dc_mi;
1728 sc->dc_mi = m;
1738 sc->dc_srom = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
1739 if (sc->dc_srom == NULL) {
1740 device_printf(sc->dc_dev, "Could not allocate SROM buffer\n");
1743 dc_read_eeprom(sc, (caddr_t)sc->dc_srom, 0, (size / 2), 0);
1756 loff = sc->dc_srom[27];
1757 lhdr = (struct dc_leaf_hdr *)&(sc->dc_srom[loff]);
1760 ptr += sizeof(struct dc_leaf_hdr) - 1;
1764 for (i = 0; i < lhdr->dc_mcnt; i++) {
1766 if (hdr->dc_type == DC_EBLOCK_MII)
1769 ptr += (hdr->dc_len & 0x7F);
1778 ptr += sizeof(struct dc_leaf_hdr) - 1;
1780 for (i = 0; i < lhdr->dc_mcnt; i++) {
1782 switch (hdr->dc_type) {
1800 ptr += (hdr->dc_len & 0x7F);
1814 *paddr = segs->ds_addr;
1822 error = bus_dma_tag_create(bus_get_dma_tag(sc->dc_dev), 1, 0,
1825 NULL, NULL, &sc->dc_ptag);
1827 device_printf(sc->dc_dev,
1833 error = bus_dma_tag_create(sc->dc_ptag, DC_LIST_ALIGN, 0,
1835 DC_RX_LIST_SZ, 0, NULL, NULL, &sc->dc_rx_ltag);
1837 device_printf(sc->dc_dev, "failed to create RX list DMA tag\n");
1841 error = bus_dma_tag_create(sc->dc_ptag, DC_LIST_ALIGN, 0,
1843 DC_TX_LIST_SZ, 0, NULL, NULL, &sc->dc_tx_ltag);
1845 device_printf(sc->dc_dev, "failed to create TX list DMA tag\n");
1850 error = bus_dmamem_alloc(sc->dc_rx_ltag,
1851 (void **)&sc->dc_ldata.dc_rx_list, BUS_DMA_NOWAIT |
1852 BUS_DMA_ZERO | BUS_DMA_COHERENT, &sc->dc_rx_lmap);
1854 device_printf(sc->dc_dev,
1858 error = bus_dmamap_load(sc->dc_rx_ltag, sc->dc_rx_lmap,
1859 sc->dc_ldata.dc_rx_list, DC_RX_LIST_SZ, dc_dma_map_addr,
1860 &sc->dc_ldata.dc_rx_list_paddr, BUS_DMA_NOWAIT);
1862 device_printf(sc->dc_dev,
1867 error = bus_dmamem_alloc(sc->dc_tx_ltag,
1868 (void **)&sc->dc_ldata.dc_tx_list, BUS_DMA_NOWAIT |
1869 BUS_DMA_ZERO | BUS_DMA_COHERENT, &sc->dc_tx_lmap);
1871 device_printf(sc->dc_dev,
1875 error = bus_dmamap_load(sc->dc_tx_ltag, sc->dc_tx_lmap,
1876 sc->dc_ldata.dc_tx_list, DC_TX_LIST_SZ, dc_dma_map_addr,
1877 &sc->dc_ldata.dc_tx_list_paddr, BUS_DMA_NOWAIT);
1879 device_printf(sc->dc_dev,
1888 error = bus_dma_tag_create(sc->dc_ptag, DC_LIST_ALIGN, 0,
1891 0, NULL, NULL, &sc->dc_stag);
1893 device_printf(sc->dc_dev,
1897 error = bus_dmamem_alloc(sc->dc_stag, (void **)&sc->dc_cdata.dc_sbuf,
1898 BUS_DMA_NOWAIT, &sc->dc_smap);
1900 device_printf(sc->dc_dev,
1904 error = bus_dmamap_load(sc->dc_stag, sc->dc_smap, sc->dc_cdata.dc_sbuf,
1905 DC_SFRAME_LEN, dc_dma_map_addr, &sc->dc_saddr, BUS_DMA_NOWAIT);
1907 device_printf(sc->dc_dev,
1913 error = bus_dma_tag_create(sc->dc_ptag, DC_RXBUF_ALIGN, 0,
1915 MCLBYTES, 1, MCLBYTES, 0, NULL, NULL, &sc->dc_rx_mtag);
1917 device_printf(sc->dc_dev, "failed to create RX mbuf tag\n");
1922 error = bus_dma_tag_create(sc->dc_ptag, 1, 0,
1925 0, NULL, NULL, &sc->dc_tx_mtag);
1927 device_printf(sc->dc_dev, "failed to create TX mbuf tag\n");
1933 error = bus_dmamap_create(sc->dc_tx_mtag, 0,
1934 &sc->dc_cdata.dc_tx_map[i]);
1936 device_printf(sc->dc_dev,
1942 error = bus_dmamap_create(sc->dc_rx_mtag, 0,
1943 &sc->dc_cdata.dc_rx_map[i]);
1945 device_printf(sc->dc_dev,
1950 error = bus_dmamap_create(sc->dc_rx_mtag, 0, &sc->dc_sparemap);
1952 device_printf(sc->dc_dev,
1967 if (sc->dc_rx_mtag != NULL) {
1969 if (sc->dc_cdata.dc_rx_map[i] != NULL)
1970 bus_dmamap_destroy(sc->dc_rx_mtag,
1971 sc->dc_cdata.dc_rx_map[i]);
1973 if (sc->dc_sparemap != NULL)
1974 bus_dmamap_destroy(sc->dc_rx_mtag, sc->dc_sparemap);
1975 bus_dma_tag_destroy(sc->dc_rx_mtag);
1979 if (sc->dc_rx_mtag != NULL) {
1981 if (sc->dc_cdata.dc_tx_map[i] != NULL)
1982 bus_dmamap_destroy(sc->dc_tx_mtag,
1983 sc->dc_cdata.dc_tx_map[i]);
1985 bus_dma_tag_destroy(sc->dc_tx_mtag);
1989 if (sc->dc_rx_ltag) {
1990 if (sc->dc_ldata.dc_rx_list_paddr != 0)
1991 bus_dmamap_unload(sc->dc_rx_ltag, sc->dc_rx_lmap);
1992 if (sc->dc_ldata.dc_rx_list != NULL)
1993 bus_dmamem_free(sc->dc_rx_ltag, sc->dc_ldata.dc_rx_list,
1994 sc->dc_rx_lmap);
1995 bus_dma_tag_destroy(sc->dc_rx_ltag);
1999 if (sc->dc_tx_ltag) {
2000 if (sc->dc_ldata.dc_tx_list_paddr != 0)
2001 bus_dmamap_unload(sc->dc_tx_ltag, sc->dc_tx_lmap);
2002 if (sc->dc_ldata.dc_tx_list != NULL)
2003 bus_dmamem_free(sc->dc_tx_ltag, sc->dc_ldata.dc_tx_list,
2004 sc->dc_tx_lmap);
2005 bus_dma_tag_destroy(sc->dc_tx_ltag);
2009 if (sc->dc_stag) {
2010 if (sc->dc_saddr != 0)
2011 bus_dmamap_unload(sc->dc_stag, sc->dc_smap);
2012 if (sc->dc_cdata.dc_sbuf != NULL)
2013 bus_dmamem_free(sc->dc_stag, sc->dc_cdata.dc_sbuf,
2014 sc->dc_smap);
2015 bus_dma_tag_destroy(sc->dc_stag);
2037 sc->dc_dev = dev;
2039 mtx_init(&sc->dc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2048 sc->dc_res = bus_alloc_resource_any(dev, DC_RES, &rid, RF_ACTIVE);
2050 if (sc->dc_res == NULL) {
2056 sc->dc_btag = rman_get_bustag(sc->dc_res);
2057 sc->dc_bhandle = rman_get_bushandle(sc->dc_res);
2061 sc->dc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2064 if (sc->dc_irq == NULL) {
2071 sc->dc_info = dc_devtype(dev);
2076 if (sc->dc_info->dc_devid !=
2078 sc->dc_info->dc_devid !=
2082 switch (sc->dc_info->dc_devid) {
2084 sc->dc_type = DC_TYPE_21143;
2085 sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
2086 sc->dc_flags |= DC_REDUCED_MII_POLL;
2088 error = dc_read_srom(sc, sc->dc_romwidth);
2095 sc->dc_type = DC_TYPE_DM9102;
2096 sc->dc_flags |= DC_TX_COALESCE | DC_TX_INTR_ALWAYS;
2097 sc->dc_flags |= DC_REDUCED_MII_POLL | DC_TX_STORENFWD;
2098 sc->dc_flags |= DC_TX_ALIGN;
2099 sc->dc_pmode = DC_PMODE_MII;
2105 sc->dc_type = DC_TYPE_AL981;
2106 sc->dc_flags |= DC_TX_USE_TX_INTR;
2107 sc->dc_flags |= DC_TX_ADMTEK_WAR;
2108 sc->dc_pmode = DC_PMODE_MII;
2109 error = dc_read_srom(sc, sc->dc_romwidth);
2128 sc->dc_type = DC_TYPE_AN983;
2129 sc->dc_flags |= DC_64BIT_HASH;
2130 sc->dc_flags |= DC_TX_USE_TX_INTR;
2131 sc->dc_flags |= DC_TX_ADMTEK_WAR;
2132 sc->dc_pmode = DC_PMODE_MII;
2133 /* Don't read SROM for - auto-loaded on reset */
2138 sc->dc_type = DC_TYPE_98713;
2141 sc->dc_type = DC_TYPE_98713A;
2142 sc->dc_flags |= DC_21143_NWAY;
2144 sc->dc_flags |= DC_REDUCED_MII_POLL;
2145 sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
2150 * Macronix MX98715AEC-C/D/E parts have only a
2151 * 128-bit hash table. We need to deal with these
2158 sc->dc_flags |= DC_128BIT_HASH;
2159 sc->dc_type = DC_TYPE_987x5;
2160 sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
2161 sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
2164 sc->dc_type = DC_TYPE_987x5;
2165 sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
2166 sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
2169 sc->dc_type = DC_TYPE_PNICII;
2170 sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR | DC_128BIT_HASH;
2171 sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
2174 sc->dc_type = DC_TYPE_PNIC;
2175 sc->dc_flags |= DC_TX_STORENFWD | DC_TX_INTR_ALWAYS;
2176 sc->dc_flags |= DC_PNIC_RX_BUG_WAR;
2177 sc->dc_pnic_rx_buf = malloc(DC_RXLEN * 5, M_DEVBUF, M_NOWAIT);
2178 if (sc->dc_pnic_rx_buf == NULL) {
2179 device_printf(sc->dc_dev,
2185 sc->dc_pmode = DC_PMODE_SYM;
2188 sc->dc_type = DC_TYPE_ASIX;
2189 sc->dc_flags |= DC_TX_USE_TX_INTR | DC_TX_INTR_FIRSTFRAG;
2190 sc->dc_flags |= DC_REDUCED_MII_POLL;
2191 sc->dc_pmode = DC_PMODE_MII;
2194 sc->dc_type = DC_TYPE_XIRCOM;
2195 sc->dc_flags |= DC_TX_INTR_ALWAYS | DC_TX_COALESCE |
2202 sc->dc_pmode = DC_PMODE_MII;
2205 sc->dc_type = DC_TYPE_CONEXANT;
2206 sc->dc_flags |= DC_TX_INTR_ALWAYS;
2207 sc->dc_flags |= DC_REDUCED_MII_POLL;
2208 sc->dc_pmode = DC_PMODE_MII;
2209 error = dc_read_srom(sc, sc->dc_romwidth);
2215 if (sc->dc_info->dc_devid ==
2217 sc->dc_type = DC_TYPE_ULI_M5261;
2219 sc->dc_type = DC_TYPE_ULI_M5263;
2221 sc->dc_flags |= DC_TX_INTR_ALWAYS | DC_TX_COALESCE |
2223 sc->dc_pmode = DC_PMODE_MII;
2224 error = dc_read_srom(sc, sc->dc_romwidth);
2230 sc->dc_info->dc_devid);
2236 sc->dc_cachesize = 0;
2238 sc->dc_cachesize = pci_get_cachelnsz(dev);
2253 * will *always* be using MII media, so that's a no-brainer.
2262 if (sc->dc_type == DC_TYPE_98713)
2263 sc->dc_pmode = DC_PMODE_MII;
2265 sc->dc_pmode = DC_PMODE_SYM;
2266 } else if (!sc->dc_pmode)
2267 sc->dc_pmode = DC_PMODE_MII;
2272 switch(sc->dc_type) {
2304 bcopy(sc->dc_srom + DC_CONEXANT_EE_NODEADDR, &eaddr,
2319 srom = (uint16_t *)sc->dc_srom;
2349 bcopy(eaddr, sc->dc_eaddr, sizeof(eaddr));
2352 * find station address for chip 0. Some multi-port controllers
2356 if ((sc->dc_eaddr[0] == 0 && (sc->dc_eaddr[1] & ~0xffff) == 0) ||
2357 (sc->dc_eaddr[0] == 0xffffffff &&
2358 (sc->dc_eaddr[1] & 0xffff) == 0xffff)) {
2361 bcopy(sc->dc_eaddr, eaddr, sizeof(eaddr));
2363 if (DC_IS_INTEL(sc) && sc->dc_srom != NULL) {
2364 while (sc->dc_mi != NULL) {
2365 m = sc->dc_mi->dc_next;
2366 free(sc->dc_mi, M_DEVBUF);
2367 sc->dc_mi = m;
2382 ifp = sc->dc_ifp = if_alloc(IFT_ETHER);
2389 if_setsendqlen(ifp, DC_TX_LIST_CNT - 1);
2402 tmp = sc->dc_pmode;
2403 sc->dc_pmode = DC_PMODE_MII;
2440 error = mii_attach(dev, &sc->dc_miibus, ifp, dc_ifmedia_upd,
2444 sc->dc_pmode = tmp;
2445 if (sc->dc_pmode != DC_PMODE_SIA)
2446 sc->dc_pmode = DC_PMODE_SYM;
2447 sc->dc_flags |= DC_21143_NWAY;
2449 * For non-MII cards, we need to have the 21143
2457 sc->dc_flags |= DC_TULIP_LEDS;
2458 error = mii_attach(dev, &sc->dc_miibus, ifp, dc_ifmedia_upd,
2485 callout_init_mtx(&sc->dc_stat_ch, &sc->dc_mtx, 0);
2486 callout_init_mtx(&sc->dc_wdog_ch, &sc->dc_mtx, 0);
2494 error = bus_setup_intr(dev, sc->dc_irq, INTR_TYPE_NET | INTR_MPSAFE,
2495 NULL, dc_intr, sc, &sc->dc_intrhand);
2524 KASSERT(mtx_initialized(&sc->dc_mtx), ("dc mutex not initialized"));
2526 ifp = sc->dc_ifp;
2538 callout_drain(&sc->dc_stat_ch);
2539 callout_drain(&sc->dc_wdog_ch);
2544 if (sc->dc_intrhand)
2545 bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand);
2546 if (sc->dc_irq)
2547 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq);
2548 if (sc->dc_res)
2549 bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res);
2556 free(sc->dc_pnic_rx_buf, M_DEVBUF);
2558 while (sc->dc_mi != NULL) {
2559 m = sc->dc_mi->dc_next;
2560 free(sc->dc_mi, M_DEVBUF);
2561 sc->dc_mi = m;
2563 free(sc->dc_srom, M_DEVBUF);
2565 mtx_destroy(&sc->dc_mtx);
2580 cd = &sc->dc_cdata;
2581 ld = &sc->dc_ldata;
2583 if (i == DC_TX_LIST_CNT - 1)
2587 ld->dc_tx_list[i].dc_status = 0;
2588 ld->dc_tx_list[i].dc_ctl = 0;
2589 ld->dc_tx_list[i].dc_data = 0;
2590 ld->dc_tx_list[i].dc_next = htole32(DC_TXDESC(sc, nexti));
2591 cd->dc_tx_chain[i] = NULL;
2594 cd->dc_tx_prod = cd->dc_tx_cons = cd->dc_tx_cnt = 0;
2595 cd->dc_tx_pkts = 0;
2596 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap,
2613 cd = &sc->dc_cdata;
2614 ld = &sc->dc_ldata;
2619 if (i == DC_RX_LIST_CNT - 1)
2623 ld->dc_rx_list[i].dc_next = htole32(DC_RXDESC(sc, nexti));
2626 cd->dc_rx_prod = 0;
2627 bus_dmamap_sync(sc->dc_rx_ltag, sc->dc_rx_lmap,
2646 m->m_len = m->m_pkthdr.len = MCLBYTES;
2654 if (sc->dc_flags & DC_PNIC_RX_BUG_WAR)
2655 bzero(mtod(m, char *), m->m_len);
2657 error = bus_dmamap_load_mbuf_sg(sc->dc_rx_mtag, sc->dc_sparemap,
2665 if (sc->dc_cdata.dc_rx_chain[i] != NULL)
2666 bus_dmamap_unload(sc->dc_rx_mtag, sc->dc_cdata.dc_rx_map[i]);
2668 map = sc->dc_cdata.dc_rx_map[i];
2669 sc->dc_cdata.dc_rx_map[i] = sc->dc_sparemap;
2670 sc->dc_sparemap = map;
2671 sc->dc_cdata.dc_rx_chain[i] = m;
2672 bus_dmamap_sync(sc->dc_rx_mtag, sc->dc_cdata.dc_rx_map[i],
2675 sc->dc_ldata.dc_rx_list[i].dc_ctl = htole32(DC_RXCTL_RLINK | DC_RXLEN);
2676 sc->dc_ldata.dc_rx_list[i].dc_data =
2678 sc->dc_ldata.dc_rx_list[i].dc_status = htole32(DC_RXSTAT_OWN);
2679 bus_dmamap_sync(sc->dc_rx_ltag, sc->dc_rx_lmap,
2698 * - We know there will always be somewhere between one and three extra
2701 * - We know the desired received frame will always be at the end of the
2704 * - We know the size of the desired received frame because it will be
2709 * - When we allocate buffers for the receive ring, we bzero() them.
2713 * - We also force the PNIC chip to upload frames that include the
2716 * - We gather all of the bogus frame data into a single buffer.
2718 * - We then position a pointer at the end of this buffer and scan
2719 * backwards until we encounter the first non-zero byte of data.
2725 * - We know the size of the actual received frame, so we subtract
2729 * - We copy this into an mbuf and pass it on, along with the actual
2747 i = sc->dc_pnic_rx_bug_save;
2748 cur_rx = &sc->dc_ldata.dc_rx_list[idx];
2749 ptr = sc->dc_pnic_rx_buf;
2754 c = &sc->dc_ldata.dc_rx_list[i];
2755 rxstat = le32toh(c->dc_status);
2756 m = sc->dc_cdata.dc_rx_chain[i];
2769 /* Scan backwards until we hit a non-zero byte. */
2771 ptr--;
2775 ptr -= 1;
2778 ptr -= total_len;
2779 if (ptr < sc->dc_pnic_rx_buf)
2780 ptr = sc->dc_pnic_rx_buf;
2788 cur_rx->dc_status = htole32(rxstat | DC_RXSTAT_FIRSTFRAG);
2808 pos = sc->dc_cdata.dc_rx_prod;
2811 cur_rx = &sc->dc_ldata.dc_rx_list[pos];
2812 if (!(le32toh(cur_rx->dc_status) & DC_RXSTAT_OWN))
2822 sc->dc_cdata.dc_rx_prod = pos;
2832 if (sc->dc_flags & DC_PNIC_RX_BUG_WAR) {
2833 m = sc->dc_cdata.dc_rx_chain[i];
2834 bzero(mtod(m, char *), m->m_len);
2837 sc->dc_ldata.dc_rx_list[i].dc_ctl = htole32(DC_RXCTL_RLINK | DC_RXLEN);
2838 sc->dc_ldata.dc_rx_list[i].dc_status = htole32(DC_RXSTAT_OWN);
2839 bus_dmamap_sync(sc->dc_rx_ltag, sc->dc_rx_lmap, BUS_DMASYNC_PREREAD |
2858 ifp = sc->dc_ifp;
2861 bus_dmamap_sync(sc->dc_rx_ltag, sc->dc_rx_lmap, BUS_DMASYNC_POSTREAD |
2863 for (i = sc->dc_cdata.dc_rx_prod;
2868 if (sc->rxcycles <= 0)
2870 sc->rxcycles--;
2873 cur_rx = &sc->dc_ldata.dc_rx_list[i];
2874 rxstat = le32toh(cur_rx->dc_status);
2877 m = sc->dc_cdata.dc_rx_chain[i];
2878 bus_dmamap_sync(sc->dc_rx_mtag, sc->dc_cdata.dc_rx_map[i],
2883 if (sc->dc_flags & DC_PNIC_RX_BUG_WAR) {
2886 sc->dc_pnic_rx_bug_save = i;
2890 rxstat = le32toh(cur_rx->dc_status);
2898 * it should simply get re-used next time this descriptor
2922 total_len -= ETHER_CRC_LEN;
2938 m->m_pkthdr.rcvif = ifp;
2939 m->m_pkthdr.len = m->m_len = total_len;
2961 sc->dc_cdata.dc_rx_prod = i;
2977 if (sc->dc_cdata.dc_tx_cnt == 0)
2980 ifp = sc->dc_ifp;
2986 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap, BUS_DMASYNC_POSTREAD |
2989 for (idx = sc->dc_cdata.dc_tx_cons; idx != sc->dc_cdata.dc_tx_prod;
2990 DC_INC(idx, DC_TX_LIST_CNT), sc->dc_cdata.dc_tx_cnt--) {
2991 cur_tx = &sc->dc_ldata.dc_tx_list[idx];
2992 txstat = le32toh(cur_tx->dc_status);
2993 ctl = le32toh(cur_tx->dc_ctl);
2998 if (sc->dc_cdata.dc_tx_chain[idx] == NULL)
3002 cur_tx->dc_ctl = htole32(ctl & ~DC_TXCTL_SETUP);
3004 bus_dmamap_sync(sc->dc_stag, sc->dc_smap,
3019 sc->dc_cdata.dc_tx_chain[idx] = NULL;
3032 if (/*sc->dc_type == DC_TYPE_21143 &&*/
3033 sc->dc_pmode == DC_PMODE_MII &&
3038 if (/*sc->dc_type == DC_TYPE_21143 &&*/
3039 sc->dc_pmode == DC_PMODE_MII &&
3060 bus_dmamap_sync(sc->dc_tx_mtag, sc->dc_cdata.dc_tx_map[idx],
3062 bus_dmamap_unload(sc->dc_tx_mtag, sc->dc_cdata.dc_tx_map[idx]);
3063 m_freem(sc->dc_cdata.dc_tx_chain[idx]);
3064 sc->dc_cdata.dc_tx_chain[idx] = NULL;
3066 sc->dc_cdata.dc_tx_cons = idx;
3068 if (sc->dc_cdata.dc_tx_cnt <= DC_TX_LIST_CNT - DC_TX_LIST_RSVD) {
3070 if (sc->dc_cdata.dc_tx_cnt == 0)
3071 sc->dc_wdog_timer = 0;
3074 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap,
3088 ifp = sc->dc_ifp;
3089 mii = device_get_softc(sc->dc_miibus);
3095 if (sc->dc_flags & DC_TX_USE_TX_INTR)
3098 if (sc->dc_flags & DC_REDUCED_MII_POLL) {
3099 if (sc->dc_flags & DC_21143_NWAY) {
3101 if (IFM_SUBTYPE(mii->mii_media_active) ==
3103 sc->dc_link = 0;
3106 if (IFM_SUBTYPE(mii->mii_media_active) ==
3108 sc->dc_link = 0;
3111 if (sc->dc_link == 0)
3120 sc->dc_cdata.dc_tx_cnt == 0)
3145 if (sc->dc_link != 0 && !if_sendq_empty(ifp))
3148 if (sc->dc_flags & DC_21143_NWAY && !sc->dc_link)
3149 callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
3151 callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
3166 device_printf(sc->dc_dev, "TX underrun -- ");
3167 if ((sc->dc_flags & DC_TX_STORENFWD) == 0) {
3168 if (sc->dc_txthresh + DC_TXTHRESH_INC > DC_TXTHRESH_MAX) {
3173 sc->dc_txthresh += DC_TXTHRESH_INC;
3175 netcfg |= sc->dc_txthresh;
3193 device_printf(sc->dc_dev,
3209 if_setdrvflagbits(sc->dc_ifp, 0, IFF_DRV_RUNNING);
3230 sc->rxcycles = count;
3259 if (status & DC_ISR_TX_IDLE && sc->dc_cdata.dc_tx_cnt)
3286 if (sc->suspended)
3295 ifp = sc->dc_ifp;
3305 for (n = 16; n > 0; n--) {
3323 if (sc->dc_cdata.dc_tx_cnt) {
3356 /* Re-enable interrupts. */
3374 int cur, defragged, error, first, frag, i, idx, nseg;
3378 if (sc->dc_flags & DC_TX_COALESCE &&
3379 ((*m_head)->m_next != NULL || sc->dc_flags & DC_TX_ALIGN)) {
3390 for (m = *m_head; m != NULL; m = m->m_next)
3393 DC_TX_LIST_CNT - i + sc->dc_cdata.dc_tx_cnt <=
3408 idx = sc->dc_cdata.dc_tx_prod;
3409 error = bus_dmamap_load_mbuf_sg(sc->dc_tx_mtag,
3410 sc->dc_cdata.dc_tx_map[idx], *m_head, segs, &nseg, 0);
3419 error = bus_dmamap_load_mbuf_sg(sc->dc_tx_mtag,
3420 sc->dc_cdata.dc_tx_map[idx], *m_head, segs, &nseg, 0);
3437 if (sc->dc_cdata.dc_tx_cnt + nseg > DC_TX_LIST_CNT - DC_TX_LIST_RSVD) {
3438 bus_dmamap_unload(sc->dc_tx_mtag, sc->dc_cdata.dc_tx_map[idx]);
3441 bus_dmamap_sync(sc->dc_tx_mtag, sc->dc_cdata.dc_tx_map[idx],
3444 first = cur = frag = sc->dc_cdata.dc_tx_prod;
3446 if ((sc->dc_flags & DC_TX_ADMTEK_WAR) &&
3447 (frag == (DC_TX_LIST_CNT - 1)) &&
3448 (first != sc->dc_cdata.dc_tx_first)) {
3449 bus_dmamap_unload(sc->dc_tx_mtag,
3450 sc->dc_cdata.dc_tx_map[first]);
3456 f = &sc->dc_ldata.dc_tx_list[frag];
3457 f->dc_ctl = htole32(DC_TXCTL_TLINK | segs[i].ds_len);
3459 f->dc_status = 0;
3460 f->dc_ctl |= htole32(DC_TXCTL_FIRSTFRAG);
3462 f->dc_status = htole32(DC_TXSTAT_OWN);
3463 f->dc_data = htole32(DC_ADDR_LO(segs[i].ds_addr));
3464 cur = frag;
3468 sc->dc_cdata.dc_tx_prod = frag;
3469 sc->dc_cdata.dc_tx_cnt += nseg;
3470 sc->dc_cdata.dc_tx_chain[cur] = *m_head;
3471 sc->dc_ldata.dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_LASTFRAG);
3472 if (sc->dc_flags & DC_TX_INTR_FIRSTFRAG)
3473 sc->dc_ldata.dc_tx_list[first].dc_ctl |=
3475 if (sc->dc_flags & DC_TX_INTR_ALWAYS)
3476 sc->dc_ldata.dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_FINT);
3477 if (sc->dc_flags & DC_TX_USE_TX_INTR &&
3478 ++sc->dc_cdata.dc_tx_pkts >= 8) {
3479 sc->dc_cdata.dc_tx_pkts = 0;
3480 sc->dc_ldata.dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_FINT);
3482 sc->dc_ldata.dc_tx_list[first].dc_status = htole32(DC_TXSTAT_OWN);
3484 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap,
3491 map = sc->dc_cdata.dc_tx_map[cur];
3492 sc->dc_cdata.dc_tx_map[cur] = sc->dc_cdata.dc_tx_map[first];
3493 sc->dc_cdata.dc_tx_map[first] = map;
3528 IFF_DRV_RUNNING || sc->dc_link == 0)
3531 sc->dc_cdata.dc_tx_first = sc->dc_cdata.dc_tx_prod;
3537 if (sc->dc_cdata.dc_tx_cnt > DC_TX_LIST_CNT - DC_TX_LIST_RSVD) {
3563 if (!(sc->dc_flags & DC_TX_POLL))
3569 sc->dc_wdog_timer = 5;
3586 if_t ifp = sc->dc_ifp;
3595 mii = device_get_softc(sc->dc_miibus);
3603 ifm = &mii->mii_media;
3604 dc_apply_fixup(sc, ifm->ifm_media);
3624 if (sc->dc_flags & DC_TX_POLL)
3626 switch(sc->dc_cachesize) {
3642 if (sc->dc_flags & DC_TX_STORENFWD)
3645 if (sc->dc_txthresh > DC_TXTHRESH_MAX) {
3649 DC_SETBIT(sc, DC_NETCFG, sc->dc_txthresh);
3666 if (sc->dc_type == DC_TYPE_98713)
3690 device_printf(sc->dc_dev,
3733 * MII port, program the LED control pins so we get
3736 if (sc->dc_flags & DC_TULIP_LEDS) {
3763 if (IFM_SUBTYPE(mii->mii_media.ifm_media) == IFM_HPNA_1)
3764 sc->dc_link = 1;
3766 if (sc->dc_flags & DC_21143_NWAY)
3767 callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
3769 callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
3772 sc->dc_wdog_timer = 0;
3773 callout_reset(&sc->dc_wdog_ch, hz, dc_watchdog, sc);
3801 sc->dc_link = 0;
3802 mii = device_get_softc(sc->dc_miibus);
3805 ifm = &mii->mii_media;
3807 dc_setcfg(sc, ifm->ifm_media);
3809 IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1)
3810 dc_setcfg(sc, ifm->ifm_media);
3827 mii = device_get_softc(sc->dc_miibus);
3830 ifm = &mii->mii_media;
3832 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
3833 ifmr->ifm_active = ifm->ifm_media;
3834 ifmr->ifm_status = 0;
3839 ifmr->ifm_active = mii->mii_media_active;
3840 ifmr->ifm_status = mii->mii_media_status;
3856 int need_setfilt = (if_getflags(ifp) ^ sc->dc_if_flags) &
3870 sc->dc_if_flags = if_getflags(ifp);
3882 mii = device_get_softc(sc->dc_miibus);
3883 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
3887 if (ifr->ifr_reqcap & IFCAP_POLLING &&
3899 if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
3927 if (sc->dc_wdog_timer == 0 || --sc->dc_wdog_timer != 0) {
3928 callout_reset(&sc->dc_wdog_ch, hz, dc_watchdog, sc);
3932 ifp = sc->dc_ifp;
3934 device_printf(sc->dc_dev, "watchdog timeout\n");
3958 ifp = sc->dc_ifp;
3959 ld = &sc->dc_ldata;
3960 cd = &sc->dc_cdata;
3962 callout_stop(&sc->dc_stat_ch);
3963 callout_stop(&sc->dc_wdog_ch);
3964 sc->dc_wdog_timer = 0;
3965 sc->dc_link = 0;
3985 if (cd->dc_rx_chain[i] != NULL) {
3986 bus_dmamap_sync(sc->dc_rx_mtag,
3987 cd->dc_rx_map[i], BUS_DMASYNC_POSTREAD);
3988 bus_dmamap_unload(sc->dc_rx_mtag,
3989 cd->dc_rx_map[i]);
3990 m_freem(cd->dc_rx_chain[i]);
3991 cd->dc_rx_chain[i] = NULL;
3994 bzero(ld->dc_rx_list, DC_RX_LIST_SZ);
3995 bus_dmamap_sync(sc->dc_rx_ltag, sc->dc_rx_lmap,
4002 if (cd->dc_tx_chain[i] != NULL) {
4003 ctl = le32toh(ld->dc_tx_list[i].dc_ctl);
4005 bus_dmamap_sync(sc->dc_stag, sc->dc_smap,
4008 bus_dmamap_sync(sc->dc_tx_mtag,
4009 cd->dc_tx_map[i], BUS_DMASYNC_POSTWRITE);
4010 bus_dmamap_unload(sc->dc_tx_mtag,
4011 cd->dc_tx_map[i]);
4012 m_freem(cd->dc_tx_chain[i]);
4014 cd->dc_tx_chain[i] = NULL;
4017 bzero(ld->dc_tx_list, DC_TX_LIST_SZ);
4018 bus_dmamap_sync(sc->dc_tx_ltag, sc->dc_tx_lmap,
4035 sc->suspended = 1;
4043 * doesn't, re-enable busmastering, and restart the interface if
4053 ifp = sc->dc_ifp;
4060 sc->suspended = 0;
4098 if (child == sc->dc_dev)
4100 if (device_get_parent(child) != device_get_parent(sc->dc_dev))
4102 if (unit > device_get_unit(sc->dc_dev))
4107 device_printf(sc->dc_dev,
4110 bcopy(dsc->dc_eaddr, sc->dc_eaddr, ETHER_ADDR_LEN);
4111 eaddr = (uint8_t *)sc->dc_eaddr;
4114 if (DC_IS_INTEL(sc) && dsc->dc_srom != NULL &&
4115 sc->dc_romwidth != 0) {
4116 free(sc->dc_srom, M_DEVBUF);
4117 sc->dc_romwidth = dsc->dc_romwidth;
4118 sc->dc_srom = malloc(DC_ROM_SIZE(sc->dc_romwidth),
4120 if (sc->dc_srom == NULL) {
4121 device_printf(sc->dc_dev,
4125 bcopy(dsc->dc_srom, sc->dc_srom,
4126 DC_ROM_SIZE(sc->dc_romwidth));