Lines Matching +full:rx +full:- +full:input +full:- +full:m

1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
19 * 4. Neither the name of the author nor the names of any co-contributors
45 * sold by D-Link, Addtron, SMC and Asante. Both parts are
46 * virtually the same, except the 83820 is a 64-bit/32-bit part,
47 * while the 83821 is 32-bit only.
64 * ports. Other features include 8K TX FIFO and 32K RX FIFO, TCP/IP
66 * priority TX and RX queues, a 2048 bit multicast hash filter, 4 RX pattern
68 * moderation. The 83820 supports both 64-bit and 32-bit addressing
69 * and data transfers: the 64-bit support can be toggled on or off
76 * - Receive buffers must be aligned on 64-bit boundaries, which means
80 * - In order to transmit jumbo frames larger than 8170 bytes, you have
88 * if the user selects an MTU larger than 8152 (8170 - 18).
201 * MII bit-bang glue
263 for (idx = (300 / 33) + 1; idx > 0; idx--) in nge_delay()
378 * Read the MII serial port for the MII bit-bang module.
396 * Write the MII serial port for the MII bit-bang module.
417 if ((sc->nge_flags & NGE_FLAG_TBI) != 0) { in nge_miibus_readreg()
450 device_printf(sc->nge_dev, in nge_miibus_readreg()
466 if ((sc->nge_flags & NGE_FLAG_TBI) != 0) { in nge_miibus_writereg()
492 device_printf(sc->nge_dev, in nge_miibus_writereg()
521 mii = device_get_softc(sc->nge_miibus); in nge_miibus_statchg()
522 ifp = sc->nge_ifp; in nge_miibus_statchg()
527 sc->nge_flags &= ~NGE_FLAG_LINK; in nge_miibus_statchg()
528 if ((mii->mii_media_status & (IFM_AVALID | IFM_ACTIVE)) == in nge_miibus_statchg()
530 switch (IFM_SUBTYPE(mii->mii_media_active)) { in nge_miibus_statchg()
537 sc->nge_flags |= NGE_FLAG_LINK; in nge_miibus_statchg()
544 /* Stop Tx/Rx MACs. */ in nge_miibus_statchg()
546 device_printf(sc->nge_dev, in nge_miibus_statchg()
547 "%s: unable to stop Tx/Rx MAC\n", __func__); in nge_miibus_statchg()
550 if (sc->nge_head != NULL) { in nge_miibus_statchg()
551 m_freem(sc->nge_head); in nge_miibus_statchg()
552 sc->nge_head = sc->nge_tail = NULL; in nge_miibus_statchg()
557 txd = &sc->nge_cdata.nge_txdesc[i]; in nge_miibus_statchg()
558 if (txd->tx_m != NULL) { in nge_miibus_statchg()
559 bus_dmamap_sync(sc->nge_cdata.nge_tx_tag, in nge_miibus_statchg()
560 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in nge_miibus_statchg()
561 bus_dmamap_unload(sc->nge_cdata.nge_tx_tag, in nge_miibus_statchg()
562 txd->tx_dmamap); in nge_miibus_statchg()
563 m_freem(txd->tx_m); in nge_miibus_statchg()
564 txd->tx_m = NULL; in nge_miibus_statchg()
569 if ((sc->nge_flags & NGE_FLAG_LINK) != 0) { in nge_miibus_statchg()
570 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in nge_miibus_statchg()
575 /* Enable flow-control. */ in nge_miibus_statchg()
576 if ((IFM_OPTIONS(mii->mii_media_active) & in nge_miibus_statchg()
589 switch (IFM_SUBTYPE(mii->mii_media_active)) { in nge_miibus_statchg()
602 /* Reset Tx/Rx MAC. */ in nge_miibus_statchg()
620 device_printf(sc->nge_dev, in nge_miibus_statchg()
621 "%s: unable to reset Tx/Rx MAC\n", __func__); in nge_miibus_statchg()
622 /* Reuse Rx buffer and reset consumer pointer. */ in nge_miibus_statchg()
623 sc->nge_cdata.nge_rx_cons = 0; in nge_miibus_statchg()
625 * It seems that resetting Rx/Tx MAC results in in nge_miibus_statchg()
626 * resetting Tx/Rx descriptor pointer registers such in nge_miibus_statchg()
627 * that reloading Tx/Rx lists address are needed. in nge_miibus_statchg()
630 NGE_ADDR_HI(sc->nge_rdata.nge_rx_ring_paddr)); in nge_miibus_statchg()
632 NGE_ADDR_LO(sc->nge_rdata.nge_rx_ring_paddr)); in nge_miibus_statchg()
634 NGE_ADDR_HI(sc->nge_rdata.nge_tx_ring_paddr)); in nge_miibus_statchg()
636 NGE_ADDR_LO(sc->nge_rdata.nge_tx_ring_paddr)); in nge_miibus_statchg()
640 /* Restart Rx MAC. */ in nge_miibus_statchg()
650 device_printf(sc->nge_dev, in nge_miibus_statchg()
651 "%s: unable to restart Rx MAC\n", __func__); in nge_miibus_statchg()
655 if ((sc->nge_flags & NGE_FLAG_TBI) != 0) in nge_miibus_statchg()
669 * bits represent the 16-bit word in the mcast hash table in nge_write_maddr()
689 ifp = sc->nge_ifp; in nge_rxfilter()
691 /* Make sure to stop Rx filtering. */ in nge_rxfilter()
763 device_printf(sc->nge_dev, "reset never completed\n"); in nge_reset()
775 /* Clear WOL events which may interfere normal Rx filter opertaion. */ in nge_reset()
799 while (t->nge_name != NULL) { in nge_probe()
800 if ((pci_get_vendor(dev) == t->nge_vid) && in nge_probe()
801 (pci_get_device(dev) == t->nge_did)) { in nge_probe()
802 device_set_desc(dev, t->nge_name); in nge_probe()
826 sc->nge_dev = dev; in nge_attach()
829 callout_init_mtx(&sc->nge_stat_ch, &sc->nge_mtx, 0); in nge_attach()
837 sc->nge_res_type = SYS_RES_IOPORT; in nge_attach()
838 sc->nge_res_id = PCIR_BAR(0); in nge_attach()
840 sc->nge_res_type = SYS_RES_MEMORY; in nge_attach()
841 sc->nge_res_id = PCIR_BAR(1); in nge_attach()
843 sc->nge_res = bus_alloc_resource_any(dev, sc->nge_res_type, in nge_attach()
844 &sc->nge_res_id, RF_ACTIVE); in nge_attach()
846 if (sc->nge_res == NULL) { in nge_attach()
847 if (sc->nge_res_type == SYS_RES_MEMORY) { in nge_attach()
848 sc->nge_res_type = SYS_RES_IOPORT; in nge_attach()
849 sc->nge_res_id = PCIR_BAR(0); in nge_attach()
851 sc->nge_res_type = SYS_RES_MEMORY; in nge_attach()
852 sc->nge_res_id = PCIR_BAR(1); in nge_attach()
854 sc->nge_res = bus_alloc_resource_any(dev, sc->nge_res_type, in nge_attach()
855 &sc->nge_res_id, RF_ACTIVE); in nge_attach()
856 if (sc->nge_res == NULL) { in nge_attach()
858 sc->nge_res_type == SYS_RES_MEMORY ? "memory" : in nge_attach()
867 sc->nge_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in nge_attach()
870 if (sc->nge_irq == NULL) { in nge_attach()
902 ifp = sc->nge_ifp = if_alloc(IFT_ETHER); in nge_attach()
909 if_setsendqlen(ifp, NGE_TX_RING_CNT - 1); in nge_attach()
918 if (pci_find_cap(sc->nge_dev, PCIY_PMG, &i) == 0) in nge_attach()
923 sc->nge_flags |= NGE_FLAG_TBI; in nge_attach()
936 error = mii_attach(dev, &sc->nge_miibus, ifp, nge_mediachange, in nge_attach()
965 error = bus_setup_intr(dev, sc->nge_irq, INTR_TYPE_NET | INTR_MPSAFE, in nge_attach()
966 NULL, nge_intr, sc, &sc->nge_intrhand); in nge_attach()
985 ifp = sc->nge_ifp; in nge_detach()
994 sc->nge_flags |= NGE_FLAG_DETACH; in nge_detach()
997 callout_drain(&sc->nge_stat_ch); in nge_detach()
1002 if (sc->nge_miibus != NULL) { in nge_detach()
1003 device_delete_child(dev, sc->nge_miibus); in nge_detach()
1004 sc->nge_miibus = NULL; in nge_detach()
1007 if (sc->nge_intrhand != NULL) in nge_detach()
1008 bus_teardown_intr(dev, sc->nge_irq, sc->nge_intrhand); in nge_detach()
1009 if (sc->nge_irq != NULL) in nge_detach()
1010 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq); in nge_detach()
1011 if (sc->nge_res != NULL) in nge_detach()
1012 bus_release_resource(dev, sc->nge_res_type, sc->nge_res_id, in nge_detach()
1013 sc->nge_res); in nge_detach()
1036 ctx->nge_busaddr = segs[0].ds_addr; in nge_dmamap_cb()
1049 bus_get_dma_tag(sc->nge_dev), /* parent */ in nge_dma_alloc()
1059 &sc->nge_cdata.nge_parent_tag); in nge_dma_alloc()
1061 device_printf(sc->nge_dev, "failed to create parent DMA tag\n"); in nge_dma_alloc()
1065 error = bus_dma_tag_create(sc->nge_cdata.nge_parent_tag,/* parent */ in nge_dma_alloc()
1075 &sc->nge_cdata.nge_tx_ring_tag); in nge_dma_alloc()
1077 device_printf(sc->nge_dev, "failed to create Tx ring DMA tag\n"); in nge_dma_alloc()
1081 /* Create tag for Rx ring. */ in nge_dma_alloc()
1082 error = bus_dma_tag_create(sc->nge_cdata.nge_parent_tag,/* parent */ in nge_dma_alloc()
1092 &sc->nge_cdata.nge_rx_ring_tag); in nge_dma_alloc()
1094 device_printf(sc->nge_dev, in nge_dma_alloc()
1095 "failed to create Rx ring DMA tag\n"); in nge_dma_alloc()
1100 error = bus_dma_tag_create(sc->nge_cdata.nge_parent_tag,/* parent */ in nge_dma_alloc()
1110 &sc->nge_cdata.nge_tx_tag); in nge_dma_alloc()
1112 device_printf(sc->nge_dev, "failed to create Tx DMA tag\n"); in nge_dma_alloc()
1116 /* Create tag for Rx buffers. */ in nge_dma_alloc()
1117 error = bus_dma_tag_create(sc->nge_cdata.nge_parent_tag,/* parent */ in nge_dma_alloc()
1127 &sc->nge_cdata.nge_rx_tag); in nge_dma_alloc()
1129 device_printf(sc->nge_dev, "failed to create Rx DMA tag\n"); in nge_dma_alloc()
1134 error = bus_dmamem_alloc(sc->nge_cdata.nge_tx_ring_tag, in nge_dma_alloc()
1135 (void **)&sc->nge_rdata.nge_tx_ring, BUS_DMA_WAITOK | in nge_dma_alloc()
1136 BUS_DMA_COHERENT | BUS_DMA_ZERO, &sc->nge_cdata.nge_tx_ring_map); in nge_dma_alloc()
1138 device_printf(sc->nge_dev, in nge_dma_alloc()
1144 error = bus_dmamap_load(sc->nge_cdata.nge_tx_ring_tag, in nge_dma_alloc()
1145 sc->nge_cdata.nge_tx_ring_map, sc->nge_rdata.nge_tx_ring, in nge_dma_alloc()
1148 device_printf(sc->nge_dev, in nge_dma_alloc()
1152 sc->nge_rdata.nge_tx_ring_paddr = ctx.nge_busaddr; in nge_dma_alloc()
1154 /* Allocate DMA'able memory and load the DMA map for Rx ring. */ in nge_dma_alloc()
1155 error = bus_dmamem_alloc(sc->nge_cdata.nge_rx_ring_tag, in nge_dma_alloc()
1156 (void **)&sc->nge_rdata.nge_rx_ring, BUS_DMA_WAITOK | in nge_dma_alloc()
1157 BUS_DMA_COHERENT | BUS_DMA_ZERO, &sc->nge_cdata.nge_rx_ring_map); in nge_dma_alloc()
1159 device_printf(sc->nge_dev, in nge_dma_alloc()
1160 "failed to allocate DMA'able memory for Rx ring\n"); in nge_dma_alloc()
1165 error = bus_dmamap_load(sc->nge_cdata.nge_rx_ring_tag, in nge_dma_alloc()
1166 sc->nge_cdata.nge_rx_ring_map, sc->nge_rdata.nge_rx_ring, in nge_dma_alloc()
1169 device_printf(sc->nge_dev, in nge_dma_alloc()
1170 "failed to load DMA'able memory for Rx ring\n"); in nge_dma_alloc()
1173 sc->nge_rdata.nge_rx_ring_paddr = ctx.nge_busaddr; in nge_dma_alloc()
1177 txd = &sc->nge_cdata.nge_txdesc[i]; in nge_dma_alloc()
1178 txd->tx_m = NULL; in nge_dma_alloc()
1179 txd->tx_dmamap = NULL; in nge_dma_alloc()
1180 error = bus_dmamap_create(sc->nge_cdata.nge_tx_tag, 0, in nge_dma_alloc()
1181 &txd->tx_dmamap); in nge_dma_alloc()
1183 device_printf(sc->nge_dev, in nge_dma_alloc()
1188 /* Create DMA maps for Rx buffers. */ in nge_dma_alloc()
1189 if ((error = bus_dmamap_create(sc->nge_cdata.nge_rx_tag, 0, in nge_dma_alloc()
1190 &sc->nge_cdata.nge_rx_sparemap)) != 0) { in nge_dma_alloc()
1191 device_printf(sc->nge_dev, in nge_dma_alloc()
1192 "failed to create spare Rx dmamap\n"); in nge_dma_alloc()
1196 rxd = &sc->nge_cdata.nge_rxdesc[i]; in nge_dma_alloc()
1197 rxd->rx_m = NULL; in nge_dma_alloc()
1198 rxd->rx_dmamap = NULL; in nge_dma_alloc()
1199 error = bus_dmamap_create(sc->nge_cdata.nge_rx_tag, 0, in nge_dma_alloc()
1200 &rxd->rx_dmamap); in nge_dma_alloc()
1202 device_printf(sc->nge_dev, in nge_dma_alloc()
1203 "failed to create Rx dmamap\n"); in nge_dma_alloc()
1220 if (sc->nge_cdata.nge_tx_ring_tag) { in nge_dma_free()
1221 if (sc->nge_rdata.nge_tx_ring_paddr) in nge_dma_free()
1222 bus_dmamap_unload(sc->nge_cdata.nge_tx_ring_tag, in nge_dma_free()
1223 sc->nge_cdata.nge_tx_ring_map); in nge_dma_free()
1224 if (sc->nge_rdata.nge_tx_ring) in nge_dma_free()
1225 bus_dmamem_free(sc->nge_cdata.nge_tx_ring_tag, in nge_dma_free()
1226 sc->nge_rdata.nge_tx_ring, in nge_dma_free()
1227 sc->nge_cdata.nge_tx_ring_map); in nge_dma_free()
1228 sc->nge_rdata.nge_tx_ring = NULL; in nge_dma_free()
1229 sc->nge_rdata.nge_tx_ring_paddr = 0; in nge_dma_free()
1230 bus_dma_tag_destroy(sc->nge_cdata.nge_tx_ring_tag); in nge_dma_free()
1231 sc->nge_cdata.nge_tx_ring_tag = NULL; in nge_dma_free()
1233 /* Rx ring. */ in nge_dma_free()
1234 if (sc->nge_cdata.nge_rx_ring_tag) { in nge_dma_free()
1235 if (sc->nge_rdata.nge_rx_ring_paddr) in nge_dma_free()
1236 bus_dmamap_unload(sc->nge_cdata.nge_rx_ring_tag, in nge_dma_free()
1237 sc->nge_cdata.nge_rx_ring_map); in nge_dma_free()
1238 if (sc->nge_rdata.nge_rx_ring) in nge_dma_free()
1239 bus_dmamem_free(sc->nge_cdata.nge_rx_ring_tag, in nge_dma_free()
1240 sc->nge_rdata.nge_rx_ring, in nge_dma_free()
1241 sc->nge_cdata.nge_rx_ring_map); in nge_dma_free()
1242 sc->nge_rdata.nge_rx_ring = NULL; in nge_dma_free()
1243 sc->nge_rdata.nge_rx_ring_paddr = 0; in nge_dma_free()
1244 bus_dma_tag_destroy(sc->nge_cdata.nge_rx_ring_tag); in nge_dma_free()
1245 sc->nge_cdata.nge_rx_ring_tag = NULL; in nge_dma_free()
1248 if (sc->nge_cdata.nge_tx_tag) { in nge_dma_free()
1250 txd = &sc->nge_cdata.nge_txdesc[i]; in nge_dma_free()
1251 if (txd->tx_dmamap) { in nge_dma_free()
1252 bus_dmamap_destroy(sc->nge_cdata.nge_tx_tag, in nge_dma_free()
1253 txd->tx_dmamap); in nge_dma_free()
1254 txd->tx_dmamap = NULL; in nge_dma_free()
1257 bus_dma_tag_destroy(sc->nge_cdata.nge_tx_tag); in nge_dma_free()
1258 sc->nge_cdata.nge_tx_tag = NULL; in nge_dma_free()
1260 /* Rx buffers. */ in nge_dma_free()
1261 if (sc->nge_cdata.nge_rx_tag) { in nge_dma_free()
1263 rxd = &sc->nge_cdata.nge_rxdesc[i]; in nge_dma_free()
1264 if (rxd->rx_dmamap) { in nge_dma_free()
1265 bus_dmamap_destroy(sc->nge_cdata.nge_rx_tag, in nge_dma_free()
1266 rxd->rx_dmamap); in nge_dma_free()
1267 rxd->rx_dmamap = NULL; in nge_dma_free()
1270 if (sc->nge_cdata.nge_rx_sparemap) { in nge_dma_free()
1271 bus_dmamap_destroy(sc->nge_cdata.nge_rx_tag, in nge_dma_free()
1272 sc->nge_cdata.nge_rx_sparemap); in nge_dma_free()
1273 sc->nge_cdata.nge_rx_sparemap = 0; in nge_dma_free()
1275 bus_dma_tag_destroy(sc->nge_cdata.nge_rx_tag); in nge_dma_free()
1276 sc->nge_cdata.nge_rx_tag = NULL; in nge_dma_free()
1279 if (sc->nge_cdata.nge_parent_tag) { in nge_dma_free()
1280 bus_dma_tag_destroy(sc->nge_cdata.nge_parent_tag); in nge_dma_free()
1281 sc->nge_cdata.nge_parent_tag = NULL; in nge_dma_free()
1296 sc->nge_cdata.nge_tx_prod = 0; in nge_list_tx_init()
1297 sc->nge_cdata.nge_tx_cons = 0; in nge_list_tx_init()
1298 sc->nge_cdata.nge_tx_cnt = 0; in nge_list_tx_init()
1300 rd = &sc->nge_rdata; in nge_list_tx_init()
1301 bzero(rd->nge_tx_ring, sizeof(struct nge_desc) * NGE_TX_RING_CNT); in nge_list_tx_init()
1303 if (i == NGE_TX_RING_CNT - 1) in nge_list_tx_init()
1307 rd->nge_tx_ring[i].nge_next = htole32(NGE_ADDR_LO(addr)); in nge_list_tx_init()
1308 txd = &sc->nge_cdata.nge_txdesc[i]; in nge_list_tx_init()
1309 txd->tx_m = NULL; in nge_list_tx_init()
1312 bus_dmamap_sync(sc->nge_cdata.nge_tx_ring_tag, in nge_list_tx_init()
1313 sc->nge_cdata.nge_tx_ring_map, in nge_list_tx_init()
1320 * Initialize the RX descriptors and allocate mbufs for them. Note that
1331 sc->nge_cdata.nge_rx_cons = 0; in nge_list_rx_init()
1332 sc->nge_head = sc->nge_tail = NULL; in nge_list_rx_init()
1334 rd = &sc->nge_rdata; in nge_list_rx_init()
1335 bzero(rd->nge_rx_ring, sizeof(struct nge_desc) * NGE_RX_RING_CNT); in nge_list_rx_init()
1339 if (i == NGE_RX_RING_CNT - 1) in nge_list_rx_init()
1343 rd->nge_rx_ring[i].nge_next = htole32(NGE_ADDR_LO(addr)); in nge_list_rx_init()
1346 bus_dmamap_sync(sc->nge_cdata.nge_rx_ring_tag, in nge_list_rx_init()
1347 sc->nge_cdata.nge_rx_ring_map, in nge_list_rx_init()
1358 desc = &sc->nge_rdata.nge_rx_ring[idx]; in nge_discard_rxbuf()
1359 desc->nge_cmdsts = htole32(MCLBYTES - sizeof(uint64_t)); in nge_discard_rxbuf()
1360 desc->nge_extsts = 0; in nge_discard_rxbuf()
1364 * Initialize an RX descriptor and attach an MBUF cluster.
1371 struct mbuf *m; in nge_newbuf() local
1376 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in nge_newbuf()
1377 if (m == NULL) in nge_newbuf()
1379 m->m_len = m->m_pkthdr.len = MCLBYTES; in nge_newbuf()
1380 m_adj(m, sizeof(uint64_t)); in nge_newbuf()
1382 if (bus_dmamap_load_mbuf_sg(sc->nge_cdata.nge_rx_tag, in nge_newbuf()
1383 sc->nge_cdata.nge_rx_sparemap, m, segs, &nsegs, 0) != 0) { in nge_newbuf()
1384 m_freem(m); in nge_newbuf()
1389 rxd = &sc->nge_cdata.nge_rxdesc[idx]; in nge_newbuf()
1390 if (rxd->rx_m != NULL) { in nge_newbuf()
1391 bus_dmamap_sync(sc->nge_cdata.nge_rx_tag, rxd->rx_dmamap, in nge_newbuf()
1393 bus_dmamap_unload(sc->nge_cdata.nge_rx_tag, rxd->rx_dmamap); in nge_newbuf()
1395 map = rxd->rx_dmamap; in nge_newbuf()
1396 rxd->rx_dmamap = sc->nge_cdata.nge_rx_sparemap; in nge_newbuf()
1397 sc->nge_cdata.nge_rx_sparemap = map; in nge_newbuf()
1398 bus_dmamap_sync(sc->nge_cdata.nge_rx_tag, rxd->rx_dmamap, in nge_newbuf()
1400 rxd->rx_m = m; in nge_newbuf()
1401 desc = &sc->nge_rdata.nge_rx_ring[idx]; in nge_newbuf()
1402 desc->nge_ptr = htole32(NGE_ADDR_LO(segs[0].ds_addr)); in nge_newbuf()
1403 desc->nge_cmdsts = htole32(segs[0].ds_len); in nge_newbuf()
1404 desc->nge_extsts = 0; in nge_newbuf()
1411 nge_fixup_rx(struct mbuf *m) in nge_fixup_rx() argument
1416 src = mtod(m, uint16_t *); in nge_fixup_rx()
1417 dst = src - 1; in nge_fixup_rx()
1419 for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++) in nge_fixup_rx()
1422 m->m_data -= ETHER_ALIGN; in nge_fixup_rx()
1433 struct mbuf *m; in nge_rxeof() local
1442 ifp = sc->nge_ifp; in nge_rxeof()
1443 cons = sc->nge_cdata.nge_rx_cons; in nge_rxeof()
1446 bus_dmamap_sync(sc->nge_cdata.nge_rx_ring_tag, in nge_rxeof()
1447 sc->nge_cdata.nge_rx_ring_map, in nge_rxeof()
1455 if (sc->rxcycles <= 0) in nge_rxeof()
1457 sc->rxcycles--; in nge_rxeof()
1460 cur_rx = &sc->nge_rdata.nge_rx_ring[cons]; in nge_rxeof()
1461 cmdsts = le32toh(cur_rx->nge_cmdsts); in nge_rxeof()
1462 extsts = le32toh(cur_rx->nge_extsts); in nge_rxeof()
1466 rxd = &sc->nge_cdata.nge_rxdesc[cons]; in nge_rxeof()
1467 m = rxd->rx_m; in nge_rxeof()
1473 if (sc->nge_head != NULL) { in nge_rxeof()
1474 m_freem(sc->nge_head); in nge_rxeof()
1475 sc->nge_head = sc->nge_tail = NULL; in nge_rxeof()
1480 m->m_len = total_len; in nge_rxeof()
1481 if (sc->nge_head == NULL) { in nge_rxeof()
1482 m->m_pkthdr.len = total_len; in nge_rxeof()
1483 sc->nge_head = sc->nge_tail = m; in nge_rxeof()
1485 m->m_flags &= ~M_PKTHDR; in nge_rxeof()
1486 sc->nge_head->m_pkthdr.len += total_len; in nge_rxeof()
1487 sc->nge_tail->m_next = m; in nge_rxeof()
1488 sc->nge_tail = m; in nge_rxeof()
1496 * it should simply get re-used next time this descriptor in nge_rxeof()
1501 total_len >= (ETHER_MIN_LEN - ETHER_CRC_LEN - 4)) { in nge_rxeof()
1503 * Work-around hardware bug, accept runt frames in nge_rxeof()
1508 * Input error counters are updated by hardware. in nge_rxeof()
1510 if (sc->nge_head != NULL) { in nge_rxeof()
1511 m_freem(sc->nge_head); in nge_rxeof()
1512 sc->nge_head = sc->nge_tail = NULL; in nge_rxeof()
1523 if (sc->nge_head != NULL) { in nge_rxeof()
1524 m_freem(sc->nge_head); in nge_rxeof()
1525 sc->nge_head = sc->nge_tail = NULL; in nge_rxeof()
1532 if (sc->nge_head != NULL) { in nge_rxeof()
1533 m->m_len = total_len; in nge_rxeof()
1534 m->m_flags &= ~M_PKTHDR; in nge_rxeof()
1535 sc->nge_tail->m_next = m; in nge_rxeof()
1536 m = sc->nge_head; in nge_rxeof()
1537 m->m_pkthdr.len += total_len; in nge_rxeof()
1538 sc->nge_head = sc->nge_tail = NULL; in nge_rxeof()
1540 m->m_pkthdr.len = m->m_len = total_len; in nge_rxeof()
1545 * on receive buffers. RX buffers must be 64-bit aligned. in nge_rxeof()
1549 * on the non-strict alignment platform. The performance hit in nge_rxeof()
1556 nge_fixup_rx(m); in nge_rxeof()
1558 m->m_pkthdr.rcvif = ifp; in nge_rxeof()
1564 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; in nge_rxeof()
1566 m->m_pkthdr.csum_flags |= CSUM_IP_VALID; in nge_rxeof()
1571 m->m_pkthdr.csum_flags |= in nge_rxeof()
1573 m->m_pkthdr.csum_data = 0xffff; in nge_rxeof()
1583 m->m_pkthdr.ether_vtag = in nge_rxeof()
1585 m->m_flags |= M_VLANTAG; in nge_rxeof()
1588 if_input(ifp, m); in nge_rxeof()
1594 sc->nge_cdata.nge_rx_cons = cons; in nge_rxeof()
1595 bus_dmamap_sync(sc->nge_cdata.nge_rx_ring_tag, in nge_rxeof()
1596 sc->nge_cdata.nge_rx_ring_map, in nge_rxeof()
1616 ifp = sc->nge_ifp; in nge_txeof()
1618 cons = sc->nge_cdata.nge_tx_cons; in nge_txeof()
1619 prod = sc->nge_cdata.nge_tx_prod; in nge_txeof()
1623 bus_dmamap_sync(sc->nge_cdata.nge_tx_ring_tag, in nge_txeof()
1624 sc->nge_cdata.nge_tx_ring_map, in nge_txeof()
1632 cur_tx = &sc->nge_rdata.nge_tx_ring[cons]; in nge_txeof()
1633 cmdsts = le32toh(cur_tx->nge_cmdsts); in nge_txeof()
1636 sc->nge_cdata.nge_tx_cnt--; in nge_txeof()
1641 txd = &sc->nge_cdata.nge_txdesc[cons]; in nge_txeof()
1642 bus_dmamap_sync(sc->nge_cdata.nge_tx_tag, txd->tx_dmamap, in nge_txeof()
1644 bus_dmamap_unload(sc->nge_cdata.nge_tx_tag, txd->tx_dmamap); in nge_txeof()
1655 KASSERT(txd->tx_m != NULL, ("%s: freeing NULL mbuf!\n", in nge_txeof()
1657 m_freem(txd->tx_m); in nge_txeof()
1658 txd->tx_m = NULL; in nge_txeof()
1661 sc->nge_cdata.nge_tx_cons = cons; in nge_txeof()
1662 if (sc->nge_cdata.nge_tx_cnt == 0) in nge_txeof()
1663 sc->nge_watchdog_timer = 0; in nge_txeof()
1674 mii = device_get_softc(sc->nge_miibus); in nge_tick()
1683 if ((sc->nge_flags & NGE_FLAG_LINK) == 0) in nge_tick()
1684 nge_miibus_statchg(sc->nge_dev); in nge_tick()
1687 callout_reset(&sc->nge_stat_ch, hz, nge_tick, sc); in nge_tick()
1698 ifp = sc->nge_ifp; in nge_stats_update()
1700 stats->rx_pkts_errs = in nge_stats_update()
1702 stats->rx_crc_errs = in nge_stats_update()
1704 stats->rx_fifo_oflows = in nge_stats_update()
1706 stats->rx_align_errs = in nge_stats_update()
1708 stats->rx_sym_errs = in nge_stats_update()
1710 stats->rx_pkts_jumbos = in nge_stats_update()
1712 stats->rx_len_errs = in nge_stats_update()
1714 stats->rx_unctl_frames = in nge_stats_update()
1716 stats->rx_pause = in nge_stats_update()
1718 stats->tx_pause = in nge_stats_update()
1720 stats->tx_seq_errs = in nge_stats_update()
1724 * Since we've accept errored frames exclude Rx length errors. in nge_stats_update()
1727 stats->rx_pkts_errs + stats->rx_crc_errs + in nge_stats_update()
1728 stats->rx_fifo_oflows + stats->rx_sym_errs); in nge_stats_update()
1730 nstats = &sc->nge_stats; in nge_stats_update()
1731 nstats->rx_pkts_errs += stats->rx_pkts_errs; in nge_stats_update()
1732 nstats->rx_crc_errs += stats->rx_crc_errs; in nge_stats_update()
1733 nstats->rx_fifo_oflows += stats->rx_fifo_oflows; in nge_stats_update()
1734 nstats->rx_align_errs += stats->rx_align_errs; in nge_stats_update()
1735 nstats->rx_sym_errs += stats->rx_sym_errs; in nge_stats_update()
1736 nstats->rx_pkts_jumbos += stats->rx_pkts_jumbos; in nge_stats_update()
1737 nstats->rx_len_errs += stats->rx_len_errs; in nge_stats_update()
1738 nstats->rx_unctl_frames += stats->rx_unctl_frames; in nge_stats_update()
1739 nstats->rx_pause += stats->rx_pause; in nge_stats_update()
1740 nstats->tx_pause += stats->tx_pause; in nge_stats_update()
1741 nstats->tx_seq_errs += stats->tx_seq_errs; in nge_stats_update()
1768 sc->rxcycles = count; in nge_poll()
1774 if (sc->rxcycles > 0 || cmd == POLL_AND_CHECK_STATUS) { in nge_poll()
1804 ifp = sc->nge_ifp; in nge_intr()
1808 if ((sc->nge_flags & NGE_FLAG_SUSPENDED) != 0) in nge_intr()
1826 if ((sc->nge_flags & NGE_FLAG_TBI) != 0) in nge_intr()
1851 /* Re-enable interrupts. */ in nge_intr()
1858 if ((sc->nge_flags & NGE_FLAG_TBI) != 0) in nge_intr()
1875 struct mbuf *m; in nge_encap() local
1882 m = *m_head; in nge_encap()
1883 prod = sc->nge_cdata.nge_tx_prod; in nge_encap()
1884 txd = &sc->nge_cdata.nge_txdesc[prod]; in nge_encap()
1886 map = txd->tx_dmamap; in nge_encap()
1887 error = bus_dmamap_load_mbuf_sg(sc->nge_cdata.nge_tx_tag, map, in nge_encap()
1890 m = m_collapse(*m_head, M_NOWAIT, NGE_MAXTXSEGS); in nge_encap()
1891 if (m == NULL) { in nge_encap()
1896 *m_head = m; in nge_encap()
1897 error = bus_dmamap_load_mbuf_sg(sc->nge_cdata.nge_tx_tag, in nge_encap()
1913 if (sc->nge_cdata.nge_tx_cnt + nsegs >= (NGE_TX_RING_CNT - 1)) { in nge_encap()
1914 bus_dmamap_unload(sc->nge_cdata.nge_tx_tag, map); in nge_encap()
1918 bus_dmamap_sync(sc->nge_cdata.nge_tx_tag, map, BUS_DMASYNC_PREWRITE); in nge_encap()
1922 desc = &sc->nge_rdata.nge_tx_ring[prod]; in nge_encap()
1923 desc->nge_ptr = htole32(NGE_ADDR_LO(txsegs[i].ds_addr)); in nge_encap()
1925 desc->nge_cmdsts = htole32(txsegs[i].ds_len | in nge_encap()
1928 desc->nge_cmdsts = htole32(txsegs[i].ds_len | in nge_encap()
1930 desc->nge_extsts = 0; in nge_encap()
1931 sc->nge_cdata.nge_tx_cnt++; in nge_encap()
1935 sc->nge_cdata.nge_tx_prod = prod; in nge_encap()
1937 prod = (prod + NGE_TX_RING_CNT - 1) % NGE_TX_RING_CNT; in nge_encap()
1938 desc = &sc->nge_rdata.nge_tx_ring[prod]; in nge_encap()
1940 if ((m->m_flags & M_VLANTAG) != 0) in nge_encap()
1941 desc->nge_extsts |= htole32(NGE_TXEXTSTS_VLANPKT | in nge_encap()
1942 bswap16(m->m_pkthdr.ether_vtag)); in nge_encap()
1944 desc->nge_cmdsts &= htole32(~NGE_CMDSTS_MORE); in nge_encap()
1947 desc = &sc->nge_rdata.nge_tx_ring[si]; in nge_encap()
1948 if ((m->m_pkthdr.csum_flags & NGE_CSUM_FEATURES) != 0) { in nge_encap()
1949 if ((m->m_pkthdr.csum_flags & CSUM_IP) != 0) in nge_encap()
1950 desc->nge_extsts |= htole32(NGE_TXEXTSTS_IPCSUM); in nge_encap()
1951 if ((m->m_pkthdr.csum_flags & CSUM_TCP) != 0) in nge_encap()
1952 desc->nge_extsts |= htole32(NGE_TXEXTSTS_TCPCSUM); in nge_encap()
1953 if ((m->m_pkthdr.csum_flags & CSUM_UDP) != 0) in nge_encap()
1954 desc->nge_extsts |= htole32(NGE_TXEXTSTS_UDPCSUM); in nge_encap()
1957 desc->nge_cmdsts |= htole32(NGE_CMDSTS_OWN); in nge_encap()
1959 txd = &sc->nge_cdata.nge_txdesc[prod]; in nge_encap()
1960 map = txd_last->tx_dmamap; in nge_encap()
1961 txd_last->tx_dmamap = txd->tx_dmamap; in nge_encap()
1962 txd->tx_dmamap = map; in nge_encap()
1963 txd->tx_m = m; in nge_encap()
1998 IFF_DRV_RUNNING || (sc->nge_flags & NGE_FLAG_LINK) == 0) in nge_start_locked()
2002 sc->nge_cdata.nge_tx_cnt < NGE_TX_RING_CNT - 2; ) { in nge_start_locked()
2028 bus_dmamap_sync(sc->nge_cdata.nge_tx_ring_tag, in nge_start_locked()
2029 sc->nge_cdata.nge_tx_ring_map, in nge_start_locked()
2035 sc->nge_watchdog_timer = 5; in nge_start_locked()
2052 if_t ifp = sc->nge_ifp; in nge_init_locked()
2063 * Cancel pending I/O and free all RX/TX buffers. in nge_init_locked()
2070 /* Disable Rx filter prior to programming Rx filter. */ in nge_init_locked()
2074 mii = device_get_softc(sc->nge_miibus); in nge_init_locked()
2077 eaddr = if_getlladdr(sc->nge_ifp); in nge_init_locked()
2085 /* Init circular RX list. */ in nge_init_locked()
2087 device_printf(sc->nge_dev, "initialization failed: no " in nge_init_locked()
2088 "memory for rx buffers\n"); in nge_init_locked()
2098 /* Set Rx filter. */ in nge_init_locked()
2106 * Rx stat FIFO hi-threshold : 2 or more packets in nge_init_locked()
2107 * Rx stat FIFO lo-threshold : less than 2 packets in nge_init_locked()
2108 * Rx data FIFO hi-threshold : 2K or more bytes in nge_init_locked()
2109 * Rx data FIFO lo-threshold : less than 2K bytes in nge_init_locked()
2110 * pause time : (512ns * 0xffff) -> 33.55ms in nge_init_locked()
2122 * Load the address of the RX and TX lists. in nge_init_locked()
2125 NGE_ADDR_HI(sc->nge_rdata.nge_rx_ring_paddr)); in nge_init_locked()
2127 NGE_ADDR_LO(sc->nge_rdata.nge_rx_ring_paddr)); in nge_init_locked()
2129 NGE_ADDR_HI(sc->nge_rdata.nge_tx_ring_paddr)); in nge_init_locked()
2131 NGE_ADDR_LO(sc->nge_rdata.nge_tx_ring_paddr)); in nge_init_locked()
2133 /* Set RX configuration. */ in nge_init_locked()
2147 * field in the RX descriptors. in nge_init_locked()
2157 * Enable TX IPv4 checksumming on a per-packet basis. in nge_init_locked()
2162 * Tell the chip to insert VLAN tags on a per-packet basis as in nge_init_locked()
2182 CSR_WRITE_4(sc, NGE_IHR, sc->nge_int_holdoff); in nge_init_locked()
2207 sc->nge_flags &= ~NGE_FLAG_LINK; in nge_init_locked()
2210 sc->nge_watchdog_timer = 0; in nge_init_locked()
2211 callout_reset(&sc->nge_stat_ch, hz, nge_tick, sc); in nge_init_locked()
2230 mii = device_get_softc(sc->nge_miibus); in nge_mediachange()
2231 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in nge_mediachange()
2250 mii = device_get_softc(sc->nge_miibus); in nge_mediastatus()
2252 ifmr->ifm_active = mii->mii_media_active; in nge_mediastatus()
2253 ifmr->ifm_status = mii->mii_media_status; in nge_mediastatus()
2267 if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > NGE_JUMBO_MTU) in nge_ioctl()
2271 if_setmtu(ifp, ifr->ifr_mtu); in nge_ioctl()
2277 if (ifr->ifr_mtu >= 8152) { in nge_ioctl()
2292 if ((if_getflags(ifp) ^ sc->nge_if_flags) & in nge_ioctl()
2296 if ((sc->nge_flags & NGE_FLAG_DETACH) == 0) in nge_ioctl()
2303 sc->nge_if_flags = if_getflags(ifp); in nge_ioctl()
2316 mii = device_get_softc(sc->nge_miibus); in nge_ioctl()
2317 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); in nge_ioctl()
2321 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); in nge_ioctl()
2407 if (sc->nge_watchdog_timer == 0 || --sc->nge_watchdog_timer) in nge_watchdog()
2410 ifp = sc->nge_ifp; in nge_watchdog()
2449 * RX and TX lists.
2460 ifp = sc->nge_ifp; in nge_stop()
2463 sc->nge_flags &= ~NGE_FLAG_LINK; in nge_stop()
2464 callout_stop(&sc->nge_stat_ch); in nge_stop()
2465 sc->nge_watchdog_timer = 0; in nge_stop()
2470 device_printf(sc->nge_dev, in nge_stop()
2471 "%s: unable to stop Tx/Rx MAC\n", __func__); in nge_stop()
2477 if (sc->nge_head != NULL) { in nge_stop()
2478 m_freem(sc->nge_head); in nge_stop()
2479 sc->nge_head = sc->nge_tail = NULL; in nge_stop()
2483 * Free RX and TX mbufs still in the queues. in nge_stop()
2486 rxd = &sc->nge_cdata.nge_rxdesc[i]; in nge_stop()
2487 if (rxd->rx_m != NULL) { in nge_stop()
2488 bus_dmamap_sync(sc->nge_cdata.nge_rx_tag, in nge_stop()
2489 rxd->rx_dmamap, BUS_DMASYNC_POSTREAD); in nge_stop()
2490 bus_dmamap_unload(sc->nge_cdata.nge_rx_tag, in nge_stop()
2491 rxd->rx_dmamap); in nge_stop()
2492 m_freem(rxd->rx_m); in nge_stop()
2493 rxd->rx_m = NULL; in nge_stop()
2497 txd = &sc->nge_cdata.nge_txdesc[i]; in nge_stop()
2498 if (txd->tx_m != NULL) { in nge_stop()
2499 bus_dmamap_sync(sc->nge_cdata.nge_tx_tag, in nge_stop()
2500 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in nge_stop()
2501 bus_dmamap_unload(sc->nge_cdata.nge_tx_tag, in nge_stop()
2502 txd->tx_dmamap); in nge_stop()
2503 m_freem(txd->tx_m); in nge_stop()
2504 txd->tx_m = NULL; in nge_stop()
2522 if (pci_find_cap(sc->nge_dev, PCIY_PMG, &pmc) != 0) in nge_wol()
2525 ifp = sc->nge_ifp; in nge_wol()
2532 device_printf(sc->nge_dev, in nge_wol()
2533 "%s: unable to stop Tx/Rx MAC\n", __func__); in nge_wol()
2535 * Make sure wake frames will be buffered in the Rx FIFO. in nge_wol()
2536 * (i.e. Silent Rx mode.) in nge_wol()
2542 /* Enable Rx again. */ in nge_wol()
2563 pmstat = pci_read_config(sc->nge_dev, pmc + PCIR_POWER_STATUS, 2); in nge_wol()
2567 pci_write_config(sc->nge_dev, pmc + PCIR_POWER_STATUS, pmstat, 2); in nge_wol()
2591 sc->nge_flags |= NGE_FLAG_SUSPENDED; in nge_suspend()
2608 ifp = sc->nge_ifp; in nge_resume()
2609 if (pci_find_cap(sc->nge_dev, PCIY_PMG, &pmc) == 0) { in nge_resume()
2611 pmstat = pci_read_config(sc->nge_dev, in nge_resume()
2615 pci_write_config(sc->nge_dev, in nge_resume()
2624 sc->nge_flags &= ~NGE_FLAG_SUSPENDED; in nge_resume()
2642 ctx = device_get_sysctl_ctx(sc->nge_dev); in nge_sysctl_node()
2643 child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->nge_dev)); in nge_sysctl_node()
2645 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, &sc->nge_int_holdoff, in nge_sysctl_node()
2648 sc->nge_int_holdoff = NGE_INT_HOLDOFF_DEFAULT; in nge_sysctl_node()
2649 error = resource_int_value(device_get_name(sc->nge_dev), in nge_sysctl_node()
2650 device_get_unit(sc->nge_dev), "int_holdoff", &sc->nge_int_holdoff); in nge_sysctl_node()
2652 if (sc->nge_int_holdoff < NGE_INT_HOLDOFF_MIN || in nge_sysctl_node()
2653 sc->nge_int_holdoff > NGE_INT_HOLDOFF_MAX ) { in nge_sysctl_node()
2654 device_printf(sc->nge_dev, in nge_sysctl_node()
2659 sc->nge_int_holdoff = NGE_INT_HOLDOFF_DEFAULT; in nge_sysctl_node()
2663 stats = &sc->nge_stats; in nge_sysctl_node()
2668 /* Rx statistics. */ in nge_sysctl_node()
2669 tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx", in nge_sysctl_node()
2670 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Rx MAC statistics"); in nge_sysctl_node()
2673 &stats->rx_pkts_errs, in nge_sysctl_node()
2676 &stats->rx_crc_errs, "CRC errors"); in nge_sysctl_node()
2678 &stats->rx_fifo_oflows, "FIFO overflows"); in nge_sysctl_node()
2680 &stats->rx_align_errs, "Frame alignment errors"); in nge_sysctl_node()
2682 &stats->rx_sym_errs, "One or more symbol errors"); in nge_sysctl_node()
2684 &stats->rx_pkts_jumbos, in nge_sysctl_node()
2687 &stats->rx_len_errs, "In Range Length errors"); in nge_sysctl_node()
2689 &stats->rx_unctl_frames, "Control frames with unsupported opcode"); in nge_sysctl_node()
2691 &stats->rx_pause, "Pause frames"); in nge_sysctl_node()
2698 &stats->tx_pause, "Pause frames"); in nge_sysctl_node()
2700 &stats->tx_seq_errs, in nge_sysctl_node()
2715 if (error != 0 || req->newptr == NULL) in sysctl_int_range()