Lines Matching +full:pme +full:- +full:active +full:- +full:high

1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
18 * 4. Neither the name of the author nor the names of any co-contributors
40 * and Rhine II PCI controllers, including the D-Link DFE530TX.
52 * receiver has a one entry perfect filter and a 64-bit hash table
257 device_printf(sc->vr_dev, "phy read timeout %d:%d\n", phy, reg); in vr_miibus_readreg()
281 device_printf(sc->vr_dev, "phy write timeout %d:%d\n", phy, in vr_miibus_writereg()
289 * 'full-duplex' and '100Mbps' bits in the netconfig register, we
302 mii = device_get_softc(sc->vr_miibus); in vr_miibus_statchg()
303 ifp = sc->vr_ifp; in vr_miibus_statchg()
308 sc->vr_flags &= ~(VR_F_LINK | VR_F_TXPAUSE); in vr_miibus_statchg()
309 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in vr_miibus_statchg()
311 switch (IFM_SUBTYPE(mii->mii_media_active)) { in vr_miibus_statchg()
314 sc->vr_flags |= VR_F_LINK; in vr_miibus_statchg()
321 if ((sc->vr_flags & VR_F_LINK) != 0) { in vr_miibus_statchg()
325 lfdx = (IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0; in vr_miibus_statchg()
330 device_printf(sc->vr_dev, in vr_miibus_statchg()
331 "%s: Tx/Rx shutdown error -- " in vr_miibus_statchg()
333 sc->vr_flags |= VR_F_RESTART; in vr_miibus_statchg()
345 /* Configure flow-control. */ in vr_miibus_statchg()
346 if (sc->vr_revid >= REV_ID_VT6105_A0) { in vr_miibus_statchg()
349 if ((IFM_OPTIONS(mii->mii_media_active) & in vr_miibus_statchg()
352 if ((IFM_OPTIONS(mii->mii_media_active) & in vr_miibus_statchg()
355 sc->vr_flags |= VR_F_TXPAUSE; in vr_miibus_statchg()
358 } else if (sc->vr_revid >= REV_ID_VT6102_A) { in vr_miibus_statchg()
362 if ((IFM_OPTIONS(mii->mii_media_active) & in vr_miibus_statchg()
371 device_printf(sc->vr_dev, in vr_miibus_statchg()
372 "%s: Tx/Rx shutdown error -- resetting\n", in vr_miibus_statchg()
374 sc->vr_flags |= VR_F_RESTART; in vr_miibus_statchg()
414 /* Write CAM and wait for self-clear of VR_CAMCTL_WRITE bit. */ in vr_cam_data()
423 device_printf(sc->vr_dev, "%s: setting CAM filter timeout!\n", in vr_cam_data()
441 if (ctx->error != 0) in vr_hash_maddr_cam()
443 ctx->error = vr_cam_data(ctx->sc, VR_MCAST_CAM, mcnt, LLADDR(sdl)); in vr_hash_maddr_cam()
444 if (ctx->error != 0) { in vr_hash_maddr_cam()
445 ctx->mask = 0; in vr_hash_maddr_cam()
448 ctx->mask |= 1 << mcnt; in vr_hash_maddr_cam()
463 hashes[1] |= (1 << (h - 32)); in vr_hash_maddr()
469 * Program the 64-bit multicast hash filter.
481 ifp = sc->vr_ifp; in vr_set_filter()
499 if ((sc->vr_quirks & VR_Q_CAM) != 0) { in vr_set_filter()
513 if ((sc->vr_quirks & VR_Q_CAM) == 0 || error != 0) { in vr_set_filter()
538 if (sc->vr_revid < REV_ID_VT6102_A) { in vr_reset()
548 if (sc->vr_revid < REV_ID_VT6102_A) in vr_reset()
549 device_printf(sc->vr_dev, "reset never completed!\n"); in vr_reset()
552 device_printf(sc->vr_dev, in vr_reset()
574 for (t = vr_devs; t->vr_name != NULL; t++) in vr_match()
575 if ((pci_get_vendor(dev) == t->vr_vid) && in vr_match()
576 (pci_get_device(dev) == t->vr_did)) in vr_match()
592 device_set_desc(dev, t->vr_name); in vr_probe()
613 sc->vr_dev = dev; in vr_attach()
616 sc->vr_quirks = t->vr_quirks; in vr_attach()
617 device_printf(dev, "Quirks: 0x%x\n", sc->vr_quirks); in vr_attach()
619 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in vr_attach()
621 callout_init_mtx(&sc->vr_stat_callout, &sc->vr_mtx, 0); in vr_attach()
633 sc->vr_revid = pci_get_revid(dev); in vr_attach()
634 device_printf(dev, "Revision: 0x%x\n", sc->vr_revid); in vr_attach()
636 sc->vr_res_id = PCIR_BAR(0); in vr_attach()
637 sc->vr_res_type = SYS_RES_IOPORT; in vr_attach()
638 sc->vr_res = bus_alloc_resource_any(dev, sc->vr_res_type, in vr_attach()
639 &sc->vr_res_id, RF_ACTIVE); in vr_attach()
640 if (sc->vr_res == NULL) { in vr_attach()
648 sc->vr_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in vr_attach()
651 if (sc->vr_irq == NULL) { in vr_attach()
658 ifp = sc->vr_ifp = if_alloc(IFT_ETHER); in vr_attach()
665 if_setsendqlen(ifp, VR_TX_RING_CNT - 1); in vr_attach()
668 NET_TASK_INIT(&sc->vr_inttask, 0, vr_int_task, sc); in vr_attach()
671 sc->vr_txthresh = VR_TXTHRESH_MIN; in vr_attach()
672 if (sc->vr_revid < REV_ID_VT6105_A0) { in vr_attach()
679 sc->vr_txthresh = VR_TXTHRESH_MAX; in vr_attach()
681 if ((sc->vr_quirks & VR_Q_CSUM) != 0) { in vr_attach()
688 sc->vr_txthresh = VR_TXTHRESH_MAX; in vr_attach()
691 if (sc->vr_revid >= REV_ID_VT6102_A && in vr_attach()
721 for (i = VR_TIMEOUT; i > 0; i--) { in vr_attach()
736 if (sc->vr_revid >= REV_ID_VT6102_A) in vr_attach()
739 if (sc->vr_revid < REV_ID_VT6102_A) { in vr_attach()
752 if (sc->vr_revid >= REV_ID_VT6105_LOM && in vr_attach()
753 sc->vr_revid < REV_ID_VT6105M_A0) in vr_attach()
757 /* Enable Memory-Read-Multiple. */ in vr_attach()
758 if (sc->vr_revid >= REV_ID_VT6107_A1 && in vr_attach()
759 sc->vr_revid < REV_ID_VT6105M_A0) in vr_attach()
773 if (sc->vr_revid >= REV_ID_VT6105_A0) in vr_attach()
777 error = mii_attach(dev, &sc->vr_miibus, ifp, vr_ifmedia_upd, in vr_attach()
779 sc->vr_revid >= REV_ID_VT6102_A ? MIIF_DOPAUSE : 0); in vr_attach()
795 error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET | INTR_MPSAFE, in vr_attach()
796 vr_intr, NULL, sc, &sc->vr_intrhand); in vr_attach()
822 if_t ifp = sc->vr_ifp; in vr_detach()
824 KASSERT(mtx_initialized(&sc->vr_mtx), ("vr mutex not initialized")); in vr_detach()
831 /* These should only be active if attach succeeded. */ in vr_detach()
834 sc->vr_flags |= VR_F_DETACHED; in vr_detach()
837 callout_drain(&sc->vr_stat_callout); in vr_detach()
838 taskqueue_drain(taskqueue_fast, &sc->vr_inttask); in vr_detach()
843 if (sc->vr_intrhand) in vr_detach()
844 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); in vr_detach()
845 if (sc->vr_irq) in vr_detach()
846 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); in vr_detach()
847 if (sc->vr_res) in vr_detach()
848 bus_release_resource(dev, sc->vr_res_type, sc->vr_res_id, in vr_detach()
849 sc->vr_res); in vr_detach()
856 mtx_destroy(&sc->vr_mtx); in vr_detach()
873 ctx->vr_busaddr = segs[0].ds_addr; in vr_dmamap_cb()
887 bus_get_dma_tag(sc->vr_dev), /* parent */ in vr_dma_alloc()
897 &sc->vr_cdata.vr_parent_tag); in vr_dma_alloc()
899 device_printf(sc->vr_dev, "failed to create parent DMA tag\n"); in vr_dma_alloc()
904 sc->vr_cdata.vr_parent_tag, /* parent */ in vr_dma_alloc()
914 &sc->vr_cdata.vr_tx_ring_tag); in vr_dma_alloc()
916 device_printf(sc->vr_dev, "failed to create Tx ring DMA tag\n"); in vr_dma_alloc()
922 sc->vr_cdata.vr_parent_tag, /* parent */ in vr_dma_alloc()
932 &sc->vr_cdata.vr_rx_ring_tag); in vr_dma_alloc()
934 device_printf(sc->vr_dev, "failed to create Rx ring DMA tag\n"); in vr_dma_alloc()
938 if ((sc->vr_quirks & VR_Q_NEEDALIGN) != 0) in vr_dma_alloc()
944 sc->vr_cdata.vr_parent_tag, /* parent */ in vr_dma_alloc()
954 &sc->vr_cdata.vr_tx_tag); in vr_dma_alloc()
956 device_printf(sc->vr_dev, "failed to create Tx DMA tag\n"); in vr_dma_alloc()
962 sc->vr_cdata.vr_parent_tag, /* parent */ in vr_dma_alloc()
972 &sc->vr_cdata.vr_rx_tag); in vr_dma_alloc()
974 device_printf(sc->vr_dev, "failed to create Rx DMA tag\n"); in vr_dma_alloc()
979 error = bus_dmamem_alloc(sc->vr_cdata.vr_tx_ring_tag, in vr_dma_alloc()
980 (void **)&sc->vr_rdata.vr_tx_ring, BUS_DMA_WAITOK | in vr_dma_alloc()
981 BUS_DMA_COHERENT | BUS_DMA_ZERO, &sc->vr_cdata.vr_tx_ring_map); in vr_dma_alloc()
983 device_printf(sc->vr_dev, in vr_dma_alloc()
989 error = bus_dmamap_load(sc->vr_cdata.vr_tx_ring_tag, in vr_dma_alloc()
990 sc->vr_cdata.vr_tx_ring_map, sc->vr_rdata.vr_tx_ring, in vr_dma_alloc()
993 device_printf(sc->vr_dev, in vr_dma_alloc()
997 sc->vr_rdata.vr_tx_ring_paddr = ctx.vr_busaddr; in vr_dma_alloc()
1000 error = bus_dmamem_alloc(sc->vr_cdata.vr_rx_ring_tag, in vr_dma_alloc()
1001 (void **)&sc->vr_rdata.vr_rx_ring, BUS_DMA_WAITOK | in vr_dma_alloc()
1002 BUS_DMA_COHERENT | BUS_DMA_ZERO, &sc->vr_cdata.vr_rx_ring_map); in vr_dma_alloc()
1004 device_printf(sc->vr_dev, in vr_dma_alloc()
1010 error = bus_dmamap_load(sc->vr_cdata.vr_rx_ring_tag, in vr_dma_alloc()
1011 sc->vr_cdata.vr_rx_ring_map, sc->vr_rdata.vr_rx_ring, in vr_dma_alloc()
1014 device_printf(sc->vr_dev, in vr_dma_alloc()
1018 sc->vr_rdata.vr_rx_ring_paddr = ctx.vr_busaddr; in vr_dma_alloc()
1022 txd = &sc->vr_cdata.vr_txdesc[i]; in vr_dma_alloc()
1023 txd->tx_m = NULL; in vr_dma_alloc()
1024 txd->tx_dmamap = NULL; in vr_dma_alloc()
1025 error = bus_dmamap_create(sc->vr_cdata.vr_tx_tag, 0, in vr_dma_alloc()
1026 &txd->tx_dmamap); in vr_dma_alloc()
1028 device_printf(sc->vr_dev, in vr_dma_alloc()
1034 if ((error = bus_dmamap_create(sc->vr_cdata.vr_rx_tag, 0, in vr_dma_alloc()
1035 &sc->vr_cdata.vr_rx_sparemap)) != 0) { in vr_dma_alloc()
1036 device_printf(sc->vr_dev, in vr_dma_alloc()
1041 rxd = &sc->vr_cdata.vr_rxdesc[i]; in vr_dma_alloc()
1042 rxd->rx_m = NULL; in vr_dma_alloc()
1043 rxd->rx_dmamap = NULL; in vr_dma_alloc()
1044 error = bus_dmamap_create(sc->vr_cdata.vr_rx_tag, 0, in vr_dma_alloc()
1045 &rxd->rx_dmamap); in vr_dma_alloc()
1047 device_printf(sc->vr_dev, in vr_dma_alloc()
1065 if (sc->vr_cdata.vr_tx_ring_tag) { in vr_dma_free()
1066 if (sc->vr_rdata.vr_tx_ring_paddr) in vr_dma_free()
1067 bus_dmamap_unload(sc->vr_cdata.vr_tx_ring_tag, in vr_dma_free()
1068 sc->vr_cdata.vr_tx_ring_map); in vr_dma_free()
1069 if (sc->vr_rdata.vr_tx_ring) in vr_dma_free()
1070 bus_dmamem_free(sc->vr_cdata.vr_tx_ring_tag, in vr_dma_free()
1071 sc->vr_rdata.vr_tx_ring, in vr_dma_free()
1072 sc->vr_cdata.vr_tx_ring_map); in vr_dma_free()
1073 sc->vr_rdata.vr_tx_ring = NULL; in vr_dma_free()
1074 sc->vr_rdata.vr_tx_ring_paddr = 0; in vr_dma_free()
1075 bus_dma_tag_destroy(sc->vr_cdata.vr_tx_ring_tag); in vr_dma_free()
1076 sc->vr_cdata.vr_tx_ring_tag = NULL; in vr_dma_free()
1079 if (sc->vr_cdata.vr_rx_ring_tag) { in vr_dma_free()
1080 if (sc->vr_rdata.vr_rx_ring_paddr) in vr_dma_free()
1081 bus_dmamap_unload(sc->vr_cdata.vr_rx_ring_tag, in vr_dma_free()
1082 sc->vr_cdata.vr_rx_ring_map); in vr_dma_free()
1083 if (sc->vr_rdata.vr_rx_ring) in vr_dma_free()
1084 bus_dmamem_free(sc->vr_cdata.vr_rx_ring_tag, in vr_dma_free()
1085 sc->vr_rdata.vr_rx_ring, in vr_dma_free()
1086 sc->vr_cdata.vr_rx_ring_map); in vr_dma_free()
1087 sc->vr_rdata.vr_rx_ring = NULL; in vr_dma_free()
1088 sc->vr_rdata.vr_rx_ring_paddr = 0; in vr_dma_free()
1089 bus_dma_tag_destroy(sc->vr_cdata.vr_rx_ring_tag); in vr_dma_free()
1090 sc->vr_cdata.vr_rx_ring_tag = NULL; in vr_dma_free()
1093 if (sc->vr_cdata.vr_tx_tag) { in vr_dma_free()
1095 txd = &sc->vr_cdata.vr_txdesc[i]; in vr_dma_free()
1096 if (txd->tx_dmamap) { in vr_dma_free()
1097 bus_dmamap_destroy(sc->vr_cdata.vr_tx_tag, in vr_dma_free()
1098 txd->tx_dmamap); in vr_dma_free()
1099 txd->tx_dmamap = NULL; in vr_dma_free()
1102 bus_dma_tag_destroy(sc->vr_cdata.vr_tx_tag); in vr_dma_free()
1103 sc->vr_cdata.vr_tx_tag = NULL; in vr_dma_free()
1106 if (sc->vr_cdata.vr_rx_tag) { in vr_dma_free()
1108 rxd = &sc->vr_cdata.vr_rxdesc[i]; in vr_dma_free()
1109 if (rxd->rx_dmamap) { in vr_dma_free()
1110 bus_dmamap_destroy(sc->vr_cdata.vr_rx_tag, in vr_dma_free()
1111 rxd->rx_dmamap); in vr_dma_free()
1112 rxd->rx_dmamap = NULL; in vr_dma_free()
1115 if (sc->vr_cdata.vr_rx_sparemap) { in vr_dma_free()
1116 bus_dmamap_destroy(sc->vr_cdata.vr_rx_tag, in vr_dma_free()
1117 sc->vr_cdata.vr_rx_sparemap); in vr_dma_free()
1118 sc->vr_cdata.vr_rx_sparemap = 0; in vr_dma_free()
1120 bus_dma_tag_destroy(sc->vr_cdata.vr_rx_tag); in vr_dma_free()
1121 sc->vr_cdata.vr_rx_tag = NULL; in vr_dma_free()
1124 if (sc->vr_cdata.vr_parent_tag) { in vr_dma_free()
1125 bus_dma_tag_destroy(sc->vr_cdata.vr_parent_tag); in vr_dma_free()
1126 sc->vr_cdata.vr_parent_tag = NULL; in vr_dma_free()
1141 sc->vr_cdata.vr_tx_prod = 0; in vr_tx_ring_init()
1142 sc->vr_cdata.vr_tx_cons = 0; in vr_tx_ring_init()
1143 sc->vr_cdata.vr_tx_cnt = 0; in vr_tx_ring_init()
1144 sc->vr_cdata.vr_tx_pkts = 0; in vr_tx_ring_init()
1146 rd = &sc->vr_rdata; in vr_tx_ring_init()
1147 bzero(rd->vr_tx_ring, VR_TX_RING_SIZE); in vr_tx_ring_init()
1149 if (i == VR_TX_RING_CNT - 1) in vr_tx_ring_init()
1153 rd->vr_tx_ring[i].vr_nextphys = htole32(VR_ADDR_LO(addr)); in vr_tx_ring_init()
1154 txd = &sc->vr_cdata.vr_txdesc[i]; in vr_tx_ring_init()
1155 txd->tx_m = NULL; in vr_tx_ring_init()
1158 bus_dmamap_sync(sc->vr_cdata.vr_tx_ring_tag, in vr_tx_ring_init()
1159 sc->vr_cdata.vr_tx_ring_map, in vr_tx_ring_init()
1178 sc->vr_cdata.vr_rx_cons = 0; in vr_rx_ring_init()
1180 rd = &sc->vr_rdata; in vr_rx_ring_init()
1181 bzero(rd->vr_rx_ring, VR_RX_RING_SIZE); in vr_rx_ring_init()
1183 rxd = &sc->vr_cdata.vr_rxdesc[i]; in vr_rx_ring_init()
1184 rxd->rx_m = NULL; in vr_rx_ring_init()
1185 rxd->desc = &rd->vr_rx_ring[i]; in vr_rx_ring_init()
1186 if (i == VR_RX_RING_CNT - 1) in vr_rx_ring_init()
1190 rd->vr_rx_ring[i].vr_nextphys = htole32(VR_ADDR_LO(addr)); in vr_rx_ring_init()
1195 bus_dmamap_sync(sc->vr_cdata.vr_rx_ring_tag, in vr_rx_ring_init()
1196 sc->vr_cdata.vr_rx_ring_map, in vr_rx_ring_init()
1207 desc = rxd->desc; in vr_discard_rxbuf()
1208 desc->vr_ctl = htole32(VR_RXCTL | (MCLBYTES - sizeof(uint64_t))); in vr_discard_rxbuf()
1209 desc->vr_status = htole32(VR_RXSTAT_OWN); in vr_discard_rxbuf()
1232 m->m_len = m->m_pkthdr.len = MCLBYTES; in vr_newbuf()
1235 if (bus_dmamap_load_mbuf_sg(sc->vr_cdata.vr_rx_tag, in vr_newbuf()
1236 sc->vr_cdata.vr_rx_sparemap, m, segs, &nsegs, 0) != 0) { in vr_newbuf()
1242 rxd = &sc->vr_cdata.vr_rxdesc[idx]; in vr_newbuf()
1243 if (rxd->rx_m != NULL) { in vr_newbuf()
1244 bus_dmamap_sync(sc->vr_cdata.vr_rx_tag, rxd->rx_dmamap, in vr_newbuf()
1246 bus_dmamap_unload(sc->vr_cdata.vr_rx_tag, rxd->rx_dmamap); in vr_newbuf()
1248 map = rxd->rx_dmamap; in vr_newbuf()
1249 rxd->rx_dmamap = sc->vr_cdata.vr_rx_sparemap; in vr_newbuf()
1250 sc->vr_cdata.vr_rx_sparemap = map; in vr_newbuf()
1251 bus_dmamap_sync(sc->vr_cdata.vr_rx_tag, rxd->rx_dmamap, in vr_newbuf()
1253 rxd->rx_m = m; in vr_newbuf()
1254 desc = rxd->desc; in vr_newbuf()
1255 desc->vr_data = htole32(VR_ADDR_LO(segs[0].ds_addr)); in vr_newbuf()
1256 desc->vr_ctl = htole32(VR_RXCTL | segs[0].ds_len); in vr_newbuf()
1257 desc->vr_status = htole32(VR_RXSTAT_OWN); in vr_newbuf()
1270 dst = src - 1; in vr_fixup_rx()
1272 for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++) in vr_fixup_rx()
1275 m->m_data -= ETHER_ALIGN; in vr_fixup_rx()
1294 ifp = sc->vr_ifp; in vr_rxeof()
1295 cons = sc->vr_cdata.vr_rx_cons; in vr_rxeof()
1298 bus_dmamap_sync(sc->vr_cdata.vr_rx_ring_tag, in vr_rxeof()
1299 sc->vr_cdata.vr_rx_ring_map, in vr_rxeof()
1305 if (sc->rxcycles <= 0) in vr_rxeof()
1307 sc->rxcycles--; in vr_rxeof()
1310 cur_rx = &sc->vr_rdata.vr_rx_ring[cons]; in vr_rxeof()
1311 rxstat = le32toh(cur_rx->vr_status); in vr_rxeof()
1312 rxctl = le32toh(cur_rx->vr_ctl); in vr_rxeof()
1317 rxd = &sc->vr_cdata.vr_rxdesc[cons]; in vr_rxeof()
1318 m = rxd->rx_m; in vr_rxeof()
1323 * it should simply get re-used next time this descriptor in vr_rxeof()
1332 sc->vr_stat.rx_errors++; in vr_rxeof()
1334 sc->vr_stat.rx_crc_errors++; in vr_rxeof()
1336 sc->vr_stat.rx_alignment++; in vr_rxeof()
1338 sc->vr_stat.rx_fifo_overflows++; in vr_rxeof()
1340 sc->vr_stat.rx_giants++; in vr_rxeof()
1342 sc->vr_stat.rx_runts++; in vr_rxeof()
1344 sc->vr_stat.rx_no_buffers++; in vr_rxeof()
1346 device_printf(sc->vr_dev, "%s: receive error = 0x%b\n", in vr_rxeof()
1355 sc->vr_stat.rx_errors++; in vr_rxeof()
1356 sc->vr_stat.rx_no_mbufs++; in vr_rxeof()
1369 total_len -= ETHER_CRC_LEN; in vr_rxeof()
1370 m->m_pkthdr.len = m->m_len = total_len; in vr_rxeof()
1373 * RX buffers must be 32-bit aligned. in vr_rxeof()
1374 * Ignore the alignment problems on the non-strict alignment in vr_rxeof()
1381 m->m_pkthdr.rcvif = ifp; in vr_rxeof()
1383 sc->vr_stat.rx_ok++; in vr_rxeof()
1387 /* Checksum is valid for non-fragmented IP packets. */ in vr_rxeof()
1388 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; in vr_rxeof()
1390 m->m_pkthdr.csum_flags |= CSUM_IP_VALID; in vr_rxeof()
1392 m->m_pkthdr.csum_flags |= in vr_rxeof()
1395 m->m_pkthdr.csum_data = 0xffff; in vr_rxeof()
1412 if ((sc->vr_flags & VR_F_TXPAUSE) != 0) { in vr_rxeof()
1414 prog = VR_RX_RING_CNT - 1; in vr_rxeof()
1417 sc->vr_cdata.vr_rx_cons = cons; in vr_rxeof()
1418 bus_dmamap_sync(sc->vr_cdata.vr_rx_ring_tag, in vr_rxeof()
1419 sc->vr_cdata.vr_rx_ring_map, in vr_rxeof()
1440 cons = sc->vr_cdata.vr_tx_cons; in vr_txeof()
1441 prod = sc->vr_cdata.vr_tx_prod; in vr_txeof()
1445 bus_dmamap_sync(sc->vr_cdata.vr_tx_ring_tag, in vr_txeof()
1446 sc->vr_cdata.vr_tx_ring_map, in vr_txeof()
1449 ifp = sc->vr_ifp; in vr_txeof()
1455 cur_tx = &sc->vr_rdata.vr_tx_ring[cons]; in vr_txeof()
1456 txctl = le32toh(cur_tx->vr_ctl); in vr_txeof()
1457 txstat = le32toh(cur_tx->vr_status); in vr_txeof()
1461 sc->vr_cdata.vr_tx_cnt--; in vr_txeof()
1467 txd = &sc->vr_cdata.vr_txdesc[cons]; in vr_txeof()
1468 KASSERT(txd->tx_m != NULL, ("%s: accessing NULL mbuf!\n", in vr_txeof()
1473 sc->vr_stat.tx_errors++; in vr_txeof()
1476 sc->vr_stat.tx_abort++; in vr_txeof()
1477 bus_dmamap_sync(sc->vr_cdata.vr_tx_tag, in vr_txeof()
1478 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in vr_txeof()
1479 bus_dmamap_unload(sc->vr_cdata.vr_tx_tag, in vr_txeof()
1480 txd->tx_dmamap); in vr_txeof()
1481 m_freem(txd->tx_m); in vr_txeof()
1482 txd->tx_m = NULL; in vr_txeof()
1484 sc->vr_cdata.vr_tx_cons = cons; in vr_txeof()
1486 device_printf(sc->vr_dev, in vr_txeof()
1487 "%s: Tx shutdown error -- " in vr_txeof()
1489 sc->vr_flags |= VR_F_RESTART; in vr_txeof()
1495 if ((sc->vr_revid < REV_ID_VT3071_A && in vr_txeof()
1498 sc->vr_stat.tx_underrun++; in vr_txeof()
1500 sc->vr_cdata.vr_tx_cnt++; in vr_txeof()
1501 sc->vr_cdata.vr_tx_cons = cons; in vr_txeof()
1502 cur_tx->vr_status = htole32(VR_TXSTAT_OWN); in vr_txeof()
1503 bus_dmamap_sync(sc->vr_cdata.vr_tx_ring_tag, in vr_txeof()
1504 sc->vr_cdata.vr_tx_ring_map, in vr_txeof()
1511 sc->vr_stat.tx_collisions++; in vr_txeof()
1515 sc->vr_stat.tx_late_collisions++; in vr_txeof()
1518 sc->vr_stat.tx_ok++; in vr_txeof()
1522 bus_dmamap_sync(sc->vr_cdata.vr_tx_tag, txd->tx_dmamap, in vr_txeof()
1524 bus_dmamap_unload(sc->vr_cdata.vr_tx_tag, txd->tx_dmamap); in vr_txeof()
1525 if (sc->vr_revid < REV_ID_VT3071_A) { in vr_txeof()
1528 sc->vr_stat.tx_collisions += in vr_txeof()
1532 sc->vr_stat.tx_collisions += (txstat & 0x0f); in vr_txeof()
1534 m_freem(txd->tx_m); in vr_txeof()
1535 txd->tx_m = NULL; in vr_txeof()
1538 sc->vr_cdata.vr_tx_cons = cons; in vr_txeof()
1539 if (sc->vr_cdata.vr_tx_cnt == 0) in vr_txeof()
1540 sc->vr_watchdog_timer = 0; in vr_txeof()
1553 if ((sc->vr_flags & VR_F_RESTART) != 0) { in vr_tick()
1554 device_printf(sc->vr_dev, "restarting\n"); in vr_tick()
1555 sc->vr_stat.num_restart++; in vr_tick()
1556 if_setdrvflagbits(sc->vr_ifp, 0, IFF_DRV_RUNNING); in vr_tick()
1558 sc->vr_flags &= ~VR_F_RESTART; in vr_tick()
1561 mii = device_get_softc(sc->vr_miibus); in vr_tick()
1563 if ((sc->vr_flags & VR_F_LINK) == 0) in vr_tick()
1564 vr_miibus_statchg(sc->vr_dev); in vr_tick()
1566 callout_reset(&sc->vr_stat_callout, hz, vr_tick, sc); in vr_tick()
1599 sc->rxcycles = count; in vr_poll_locked()
1623 device_printf(sc->vr_dev, "%s: receive error : 0x%b\n", in vr_poll_locked()
1639 device_printf(sc->vr_dev, "Tx underrun -- "); in vr_tx_underrun()
1640 if (sc->vr_txthresh < VR_TXTHRESH_MAX) { in vr_tx_underrun()
1641 thresh = sc->vr_txthresh; in vr_tx_underrun()
1642 sc->vr_txthresh++; in vr_tx_underrun()
1643 if (sc->vr_txthresh >= VR_TXTHRESH_MAX) { in vr_tx_underrun()
1644 sc->vr_txthresh = VR_TXTHRESH_MAX; in vr_tx_underrun()
1647 printf("increasing Tx threshold(%d -> %d)\n", in vr_tx_underrun()
1652 sc->vr_stat.tx_underrun++; in vr_tx_underrun()
1654 device_printf(sc->vr_dev, "%s: Tx shutdown error -- " in vr_tx_underrun()
1656 sc->vr_flags |= VR_F_RESTART; in vr_tx_underrun()
1677 taskqueue_enqueue(taskqueue_fast, &sc->vr_inttask); in vr_intr()
1693 if ((sc->vr_flags & VR_F_SUSPENDED) != 0) in vr_int_task()
1697 ifp = sc->vr_ifp; in vr_int_task()
1705 (sc->vr_flags & VR_F_RESTART) != 0) { in vr_int_task()
1723 device_printf(sc->vr_dev, "%s: receive error = 0x%b\n", in vr_int_task()
1737 /* Re-enable interrupts. */ in vr_int_task()
1752 sc->vr_stat.bus_errors++; in vr_error()
1755 pcis = pci_read_config(sc->vr_dev, PCIR_STATUS, 2); in vr_error()
1756 device_printf(sc->vr_dev, "PCI bus error(0x%04x) -- " in vr_error()
1758 pci_write_config(sc->vr_dev, PCIR_STATUS, pcis, 2); in vr_error()
1759 sc->vr_flags |= VR_F_RESTART; in vr_error()
1768 if (sc->vr_revid >= REV_ID_VT6105M_A0) { in vr_error()
1774 device_printf(sc->vr_dev, in vr_error()
1804 if ((sc->vr_quirks & VR_Q_NEEDALIGN) != 0) { in vr_encap()
1815 * The Rhine chip doesn't auto-pad, so we have to make in vr_encap()
1819 if ((*m_head)->m_pkthdr.len < VR_MIN_FRAMELEN) { in vr_encap()
1821 padlen = VR_MIN_FRAMELEN - m->m_pkthdr.len; in vr_encap()
1832 if (m->m_next != NULL || M_TRAILINGSPACE(m) < padlen) { in vr_encap()
1844 bzero(mtod(m, char *) + m->m_pkthdr.len, padlen); in vr_encap()
1845 m->m_pkthdr.len += padlen; in vr_encap()
1846 m->m_len = m->m_pkthdr.len; in vr_encap()
1850 prod = sc->vr_cdata.vr_tx_prod; in vr_encap()
1851 txd = &sc->vr_cdata.vr_txdesc[prod]; in vr_encap()
1852 error = bus_dmamap_load_mbuf_sg(sc->vr_cdata.vr_tx_tag, txd->tx_dmamap, in vr_encap()
1862 error = bus_dmamap_load_mbuf_sg(sc->vr_cdata.vr_tx_tag, in vr_encap()
1863 txd->tx_dmamap, *m_head, txsegs, &nsegs, BUS_DMA_NOWAIT); in vr_encap()
1878 if (sc->vr_cdata.vr_tx_cnt + nsegs >= (VR_TX_RING_CNT - 1)) { in vr_encap()
1879 bus_dmamap_unload(sc->vr_cdata.vr_tx_tag, txd->tx_dmamap); in vr_encap()
1883 txd->tx_m = *m_head; in vr_encap()
1884 bus_dmamap_sync(sc->vr_cdata.vr_tx_tag, txd->tx_dmamap, in vr_encap()
1889 if (((*m_head)->m_pkthdr.csum_flags & VR_CSUM_FEATURES) != 0) { in vr_encap()
1890 if ((*m_head)->m_pkthdr.csum_flags & CSUM_IP) in vr_encap()
1892 if ((*m_head)->m_pkthdr.csum_flags & CSUM_TCP) in vr_encap()
1894 if ((*m_head)->m_pkthdr.csum_flags & CSUM_UDP) in vr_encap()
1902 * the first descriptor for a multi-fragmented frames. Without in vr_encap()
1908 desc = &sc->vr_rdata.vr_tx_ring[prod]; in vr_encap()
1909 desc->vr_status = 0; in vr_encap()
1913 desc->vr_ctl = htole32(txctl); in vr_encap()
1914 desc->vr_data = htole32(VR_ADDR_LO(txsegs[i].ds_addr)); in vr_encap()
1915 sc->vr_cdata.vr_tx_cnt++; in vr_encap()
1919 sc->vr_cdata.vr_tx_prod = prod; in vr_encap()
1921 prod = (prod + VR_TX_RING_CNT - 1) % VR_TX_RING_CNT; in vr_encap()
1922 desc = &sc->vr_rdata.vr_tx_ring[prod]; in vr_encap()
1926 * interrupt for every VR_TX_INTR_THRESH-th frames. in vr_encap()
1928 VR_INC(sc->vr_cdata.vr_tx_pkts, VR_TX_INTR_THRESH); in vr_encap()
1929 if (sc->vr_cdata.vr_tx_pkts == 0) in vr_encap()
1930 desc->vr_ctl |= htole32(VR_TXCTL_LASTFRAG | VR_TXCTL_FINT); in vr_encap()
1932 desc->vr_ctl |= htole32(VR_TXCTL_LASTFRAG); in vr_encap()
1935 desc = &sc->vr_rdata.vr_tx_ring[si]; in vr_encap()
1936 desc->vr_status |= htole32(VR_TXSTAT_OWN); in vr_encap()
1939 bus_dmamap_sync(sc->vr_cdata.vr_tx_ring_tag, in vr_encap()
1940 sc->vr_cdata.vr_tx_ring_map, in vr_encap()
1969 IFF_DRV_RUNNING || (sc->vr_flags & VR_F_LINK) == 0) in vr_start_locked()
1973 sc->vr_cdata.vr_tx_cnt < VR_TX_RING_CNT - 2; ) { in vr_start_locked()
2002 sc->vr_watchdog_timer = 5; in vr_start_locked()
2027 ifp = sc->vr_ifp; in vr_init_locked()
2028 mii = device_get_softc(sc->vr_miibus); in vr_init_locked()
2039 CSR_WRITE_1(sc, VR_PAR0 + i, if_getlladdr(sc->vr_ifp)[i]); in vr_init_locked()
2053 VR_SETBIT(sc, VR_BCR1, vr_tx_threshold_tables[sc->vr_txthresh].bcr_cfg); in vr_init_locked()
2059 VR_SETBIT(sc, VR_TXCFG, vr_tx_threshold_tables[sc->vr_txthresh].tx_cfg); in vr_init_locked()
2063 device_printf(sc->vr_dev, in vr_init_locked()
2072 if ((sc->vr_quirks & VR_Q_CAM) != 0) { in vr_init_locked()
2102 /* Default : full-duplex, no Tx poll. */ in vr_init_locked()
2105 /* Set flow-control parameters for Rhine III. */ in vr_init_locked()
2106 if (sc->vr_revid >= REV_ID_VT6105_A0) { in vr_init_locked()
2121 * to the number of total RX buffers - 1 before in vr_init_locked()
2126 CSR_WRITE_1(sc, VR_FLOWCR0, VR_RX_RING_CNT - 1); in vr_init_locked()
2129 * Tx pause XON high threshold : 24 free receive buffers in vr_init_locked()
2154 if (sc->vr_revid > REV_ID_VT6102_A) in vr_init_locked()
2160 sc->vr_flags &= ~(VR_F_LINK | VR_F_TXPAUSE); in vr_init_locked()
2163 callout_reset(&sc->vr_stat_callout, hz, vr_tick, sc); in vr_init_locked()
2179 mii = device_get_softc(sc->vr_miibus); in vr_ifmedia_upd()
2180 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in vr_ifmedia_upd()
2182 sc->vr_flags &= ~(VR_F_LINK | VR_F_TXPAUSE); in vr_ifmedia_upd()
2199 mii = device_get_softc(sc->vr_miibus); in vr_ifmedia_sts()
2206 ifmr->ifm_active = mii->mii_media_active; in vr_ifmedia_sts()
2207 ifmr->ifm_status = mii->mii_media_status; in vr_ifmedia_sts()
2228 if ((if_getflags(ifp) ^ sc->vr_if_flags) & in vr_ioctl()
2232 if ((sc->vr_flags & VR_F_DETACHED) == 0) in vr_ioctl()
2239 sc->vr_if_flags = if_getflags(ifp); in vr_ioctl()
2250 mii = device_get_softc(sc->vr_miibus); in vr_ioctl()
2251 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); in vr_ioctl()
2254 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); in vr_ioctl()
2257 if (ifr->ifr_reqcap & IFCAP_POLLING) { in vr_ioctl()
2309 if (sc->vr_watchdog_timer == 0 || --sc->vr_watchdog_timer) in vr_watchdog()
2312 ifp = sc->vr_ifp; in vr_watchdog()
2317 if (sc->vr_cdata.vr_tx_cnt == 0) in vr_watchdog()
2320 if ((sc->vr_flags & VR_F_LINK) == 0) { in vr_watchdog()
2322 if_printf(sc->vr_ifp, "watchdog timeout " in vr_watchdog()
2348 addr = VR_TX_RING_ADDR(sc, sc->vr_cdata.vr_tx_cons); in vr_tx_start()
2353 if (sc->vr_cdata.vr_tx_cnt != 0) { in vr_tx_start()
2354 sc->vr_watchdog_timer = 5; in vr_tx_start()
2367 addr = VR_RX_RING_ADDR(sc, sc->vr_cdata.vr_rx_cons); in vr_rx_start()
2385 for (i = VR_TIMEOUT; i > 0; i--) { in vr_tx_stop()
2407 for (i = VR_TIMEOUT; i > 0; i--) { in vr_rx_stop()
2433 ifp = sc->vr_ifp; in vr_stop()
2434 sc->vr_watchdog_timer = 0; in vr_stop()
2436 callout_stop(&sc->vr_stat_callout); in vr_stop()
2441 device_printf(sc->vr_dev, "%s: Rx shutdown error\n", __func__); in vr_stop()
2443 device_printf(sc->vr_dev, "%s: Tx shutdown error\n", __func__); in vr_stop()
2454 rxd = &sc->vr_cdata.vr_rxdesc[i]; in vr_stop()
2455 if (rxd->rx_m != NULL) { in vr_stop()
2456 bus_dmamap_sync(sc->vr_cdata.vr_rx_tag, in vr_stop()
2457 rxd->rx_dmamap, BUS_DMASYNC_POSTREAD); in vr_stop()
2458 bus_dmamap_unload(sc->vr_cdata.vr_rx_tag, in vr_stop()
2459 rxd->rx_dmamap); in vr_stop()
2460 m_freem(rxd->rx_m); in vr_stop()
2461 rxd->rx_m = NULL; in vr_stop()
2465 txd = &sc->vr_cdata.vr_txdesc[i]; in vr_stop()
2466 if (txd->tx_m != NULL) { in vr_stop()
2467 bus_dmamap_sync(sc->vr_cdata.vr_tx_tag, in vr_stop()
2468 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in vr_stop()
2469 bus_dmamap_unload(sc->vr_cdata.vr_tx_tag, in vr_stop()
2470 txd->tx_dmamap); in vr_stop()
2471 m_freem(txd->tx_m); in vr_stop()
2472 txd->tx_m = NULL; in vr_stop()
2498 sc->vr_flags |= VR_F_SUSPENDED; in vr_suspend()
2513 ifp = sc->vr_ifp; in vr_resume()
2519 sc->vr_flags &= ~VR_F_SUSPENDED; in vr_resume()
2535 if (sc->vr_revid < REV_ID_VT6102_A || in vr_setwol()
2536 pci_find_cap(sc->vr_dev, PCIY_PMG, &pmc) != 0) in vr_setwol()
2539 ifp = sc->vr_ifp; in vr_setwol()
2546 if (sc->vr_revid > REV_ID_VT6105_B0) { in vr_setwol()
2574 /* Request PME if WOL is requested. */ in vr_setwol()
2575 pmstat = pci_read_config(sc->vr_dev, pmc + PCIR_POWER_STATUS, 2); in vr_setwol()
2579 pci_write_config(sc->vr_dev, pmc + PCIR_POWER_STATUS, pmstat, 2); in vr_setwol()
2589 if (sc->vr_revid < REV_ID_VT6102_A) in vr_clrwol()
2603 if (sc->vr_revid > REV_ID_VT6105_B0) { in vr_clrwol()
2619 result = -1; in vr_sysctl_stats()
2622 if (error != 0 || req->newptr == NULL) in vr_sysctl_stats()
2627 stat = &sc->vr_stat; in vr_sysctl_stats()
2629 printf("%s statistics:\n", device_get_nameunit(sc->vr_dev)); in vr_sysctl_stats()
2631 (uintmax_t)stat->tx_ok); in vr_sysctl_stats()
2633 (uintmax_t)stat->rx_ok); in vr_sysctl_stats()
2634 printf("Outbound errors : %u\n", stat->tx_errors); in vr_sysctl_stats()
2635 printf("Inbound errors : %u\n", stat->rx_errors); in vr_sysctl_stats()
2636 printf("Inbound no buffers : %u\n", stat->rx_no_buffers); in vr_sysctl_stats()
2637 printf("Inbound no mbuf clusters: %d\n", stat->rx_no_mbufs); in vr_sysctl_stats()
2639 stat->rx_fifo_overflows); in vr_sysctl_stats()
2640 printf("Inbound CRC errors : %u\n", stat->rx_crc_errors); in vr_sysctl_stats()
2642 stat->rx_alignment); in vr_sysctl_stats()
2643 printf("Inbound giant frames : %u\n", stat->rx_giants); in vr_sysctl_stats()
2644 printf("Inbound runt frames : %u\n", stat->rx_runts); in vr_sysctl_stats()
2646 stat->tx_abort); in vr_sysctl_stats()
2647 printf("Outbound collisions : %u\n", stat->tx_collisions); in vr_sysctl_stats()
2649 stat->tx_late_collisions); in vr_sysctl_stats()
2650 printf("Outbound underrun : %u\n", stat->tx_underrun); in vr_sysctl_stats()
2651 printf("PCI bus errors : %u\n", stat->bus_errors); in vr_sysctl_stats()
2653 stat->num_restart); in vr_sysctl_stats()