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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
177 for (i = VTE_PHY_TIMEOUT; i > 0; i--) { in vte_miibus_readreg()
184 device_printf(sc->vte_dev, "phy read timeout : %d\n", reg); in vte_miibus_readreg()
202 for (i = VTE_PHY_TIMEOUT; i > 0; i--) { in vte_miibus_writereg()
209 device_printf(sc->vte_dev, "phy write timeout : %d\n", reg); in vte_miibus_writereg()
224 mii = device_get_softc(sc->vte_miibus); in vte_miibus_statchg()
225 ifp = sc->vte_ifp; in vte_miibus_statchg()
229 sc->vte_flags &= ~VTE_FLAG_LINK; in vte_miibus_statchg()
230 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == in vte_miibus_statchg()
232 switch (IFM_SUBTYPE(mii->mii_media_active)) { in vte_miibus_statchg()
235 sc->vte_flags |= VTE_FLAG_LINK; in vte_miibus_statchg()
242 /* Stop RX/TX MACs. */ in vte_miibus_statchg()
245 if ((sc->vte_flags & VTE_FLAG_LINK) != 0) { in vte_miibus_statchg()
250 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) in vte_miibus_statchg()
254 val |= sc->vte_int_rx_mod << VTE_IM_BUNDLE_SHIFT; in vte_miibus_statchg()
258 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) in vte_miibus_statchg()
262 val |= sc->vte_int_tx_mod << VTE_IM_BUNDLE_SHIFT; in vte_miibus_statchg()
283 mii = device_get_softc(sc->vte_miibus); in vte_mediastatus()
286 ifmr->ifm_status = mii->mii_media_status; in vte_mediastatus()
287 ifmr->ifm_active = mii->mii_media_active; in vte_mediastatus()
313 mii = device_get_softc(sc->vte_miibus); in vte_mediachange_locked()
314 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) in vte_mediachange_locked()
329 for (ident = vte_ident_table; ident->name != NULL; ident++) { in vte_find_ident()
330 if (vendor == ident->vendorid && devid == ident->deviceid) in vte_find_ident()
344 device_set_desc(dev, ident->name); in vte_probe()
361 sc->vte_eaddr[0] = (mid >> 0) & 0xFF; in vte_get_macaddr()
362 sc->vte_eaddr[1] = (mid >> 8) & 0xFF; in vte_get_macaddr()
364 sc->vte_eaddr[2] = (mid >> 0) & 0xFF; in vte_get_macaddr()
365 sc->vte_eaddr[3] = (mid >> 8) & 0xFF; in vte_get_macaddr()
367 sc->vte_eaddr[4] = (mid >> 0) & 0xFF; in vte_get_macaddr()
368 sc->vte_eaddr[5] = (mid >> 8) & 0xFF; in vte_get_macaddr()
381 sc->vte_dev = dev; in vte_attach()
383 mtx_init(&sc->vte_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in vte_attach()
385 callout_init_mtx(&sc->vte_tick_ch, &sc->vte_mtx, 0); in vte_attach()
386 sc->vte_ident = vte_find_ident(dev); in vte_attach()
390 sc->vte_res_id = PCIR_BAR(1); in vte_attach()
391 sc->vte_res_type = SYS_RES_MEMORY; in vte_attach()
392 sc->vte_res = bus_alloc_resource_any(dev, sc->vte_res_type, in vte_attach()
393 &sc->vte_res_id, RF_ACTIVE); in vte_attach()
394 if (sc->vte_res == NULL) { in vte_attach()
395 sc->vte_res_id = PCIR_BAR(0); in vte_attach()
396 sc->vte_res_type = SYS_RES_IOPORT; in vte_attach()
397 sc->vte_res = bus_alloc_resource_any(dev, sc->vte_res_type, in vte_attach()
398 &sc->vte_res_id, RF_ACTIVE); in vte_attach()
399 if (sc->vte_res == NULL) { in vte_attach()
401 mtx_destroy(&sc->vte_mtx); in vte_attach()
407 sc->vte_res_type == SYS_RES_MEMORY ? "memory" : "I/O"); in vte_attach()
417 sc->vte_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in vte_attach()
419 if (sc->vte_irq == NULL) { in vte_attach()
437 ifp = sc->vte_ifp = if_alloc(IFT_ETHER); in vte_attach()
445 if_setsendqlen(ifp, VTE_TX_RING_CNT - 1); in vte_attach()
462 error = mii_attach(dev, &sc->vte_miibus, ifp, vte_mediachange, in vte_attach()
469 ether_ifattach(ifp, sc->vte_eaddr); in vte_attach()
474 /* Tell the upper layer we support VLAN over-sized frames. */ in vte_attach()
477 error = bus_setup_intr(dev, sc->vte_irq, INTR_TYPE_NET | INTR_MPSAFE, in vte_attach()
478 NULL, vte_intr, sc, &sc->vte_intrhand); in vte_attach()
500 ifp = sc->vte_ifp; in vte_detach()
505 callout_drain(&sc->vte_tick_ch); in vte_detach()
511 if (sc->vte_intrhand != NULL) { in vte_detach()
512 bus_teardown_intr(dev, sc->vte_irq, sc->vte_intrhand); in vte_detach()
513 sc->vte_intrhand = NULL; in vte_detach()
515 if (sc->vte_irq != NULL) { in vte_detach()
516 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vte_irq); in vte_detach()
517 sc->vte_irq = NULL; in vte_detach()
519 if (sc->vte_res != NULL) { in vte_detach()
520 bus_release_resource(dev, sc->vte_res_type, sc->vte_res_id, in vte_detach()
521 sc->vte_res); in vte_detach()
522 sc->vte_res = NULL; in vte_detach()
526 sc->vte_ifp = NULL; in vte_detach()
529 mtx_destroy(&sc->vte_mtx); in vte_detach()
546 stats = &sc->vte_stats; in vte_sysctl_node()
547 ctx = device_get_sysctl_ctx(sc->vte_dev); in vte_sysctl_node()
548 child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->vte_dev)); in vte_sysctl_node()
552 &sc->vte_int_rx_mod, 0, sysctl_hw_vte_int_mod, "I", in vte_sysctl_node()
553 "vte RX interrupt moderation"); in vte_sysctl_node()
556 &sc->vte_int_tx_mod, 0, sysctl_hw_vte_int_mod, "I", in vte_sysctl_node()
559 sc->vte_int_rx_mod = VTE_IM_RX_BUNDLE_DEFAULT; in vte_sysctl_node()
560 error = resource_int_value(device_get_name(sc->vte_dev), in vte_sysctl_node()
561 device_get_unit(sc->vte_dev), "int_rx_mod", &sc->vte_int_rx_mod); in vte_sysctl_node()
563 if (sc->vte_int_rx_mod < VTE_IM_BUNDLE_MIN || in vte_sysctl_node()
564 sc->vte_int_rx_mod > VTE_IM_BUNDLE_MAX) { in vte_sysctl_node()
565 device_printf(sc->vte_dev, "int_rx_mod value out of " in vte_sysctl_node()
568 sc->vte_int_rx_mod = VTE_IM_RX_BUNDLE_DEFAULT; in vte_sysctl_node()
572 sc->vte_int_tx_mod = VTE_IM_TX_BUNDLE_DEFAULT; in vte_sysctl_node()
573 error = resource_int_value(device_get_name(sc->vte_dev), in vte_sysctl_node()
574 device_get_unit(sc->vte_dev), "int_tx_mod", &sc->vte_int_tx_mod); in vte_sysctl_node()
576 if (sc->vte_int_tx_mod < VTE_IM_BUNDLE_MIN || in vte_sysctl_node()
577 sc->vte_int_tx_mod > VTE_IM_BUNDLE_MAX) { in vte_sysctl_node()
578 device_printf(sc->vte_dev, "int_tx_mod value out of " in vte_sysctl_node()
581 sc->vte_int_tx_mod = VTE_IM_TX_BUNDLE_DEFAULT; in vte_sysctl_node()
589 /* RX statistics. */ in vte_sysctl_node()
590 tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx", in vte_sysctl_node()
591 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "RX MAC statistics"); in vte_sysctl_node()
594 &stats->rx_frames, "Good frames"); in vte_sysctl_node()
596 &stats->rx_bcast_frames, "Good broadcast frames"); in vte_sysctl_node()
598 &stats->rx_mcast_frames, "Good multicast frames"); in vte_sysctl_node()
600 &stats->rx_runts, "Too short frames"); in vte_sysctl_node()
602 &stats->rx_crcerrs, "CRC errors"); in vte_sysctl_node()
604 &stats->rx_long_frames, in vte_sysctl_node()
607 &stats->rx_fifo_full, "FIFO full"); in vte_sysctl_node()
609 &stats->rx_desc_unavail, "Descriptor unavailable frames"); in vte_sysctl_node()
611 &stats->rx_pause_frames, "Pause control frames"); in vte_sysctl_node()
618 &stats->tx_frames, "Good frames"); in vte_sysctl_node()
620 &stats->tx_underruns, "FIFO underruns"); in vte_sysctl_node()
622 &stats->tx_late_colls, "Late collisions"); in vte_sysctl_node()
624 &stats->tx_pause_frames, "Pause control frames"); in vte_sysctl_node()
644 ctx->vte_busaddr = segs[0].ds_addr; in vte_dmamap_cb()
657 bus_get_dma_tag(sc->vte_dev), /* parent */ in vte_dma_alloc()
667 &sc->vte_cdata.vte_parent_tag); in vte_dma_alloc()
669 device_printf(sc->vte_dev, in vte_dma_alloc()
676 sc->vte_cdata.vte_parent_tag, /* parent */ in vte_dma_alloc()
686 &sc->vte_cdata.vte_tx_ring_tag); in vte_dma_alloc()
688 device_printf(sc->vte_dev, in vte_dma_alloc()
693 /* Create DMA tag for RX free descriptor ring. */ in vte_dma_alloc()
695 sc->vte_cdata.vte_parent_tag, /* parent */ in vte_dma_alloc()
705 &sc->vte_cdata.vte_rx_ring_tag); in vte_dma_alloc()
707 device_printf(sc->vte_dev, in vte_dma_alloc()
708 "could not create RX ring DMA tag.\n"); in vte_dma_alloc()
713 error = bus_dmamem_alloc(sc->vte_cdata.vte_tx_ring_tag, in vte_dma_alloc()
714 (void **)&sc->vte_cdata.vte_tx_ring, in vte_dma_alloc()
716 &sc->vte_cdata.vte_tx_ring_map); in vte_dma_alloc()
718 device_printf(sc->vte_dev, in vte_dma_alloc()
723 error = bus_dmamap_load(sc->vte_cdata.vte_tx_ring_tag, in vte_dma_alloc()
724 sc->vte_cdata.vte_tx_ring_map, sc->vte_cdata.vte_tx_ring, in vte_dma_alloc()
727 device_printf(sc->vte_dev, in vte_dma_alloc()
731 sc->vte_cdata.vte_tx_ring_paddr = ctx.vte_busaddr; in vte_dma_alloc()
733 /* Allocate DMA'able memory and load the DMA map for RX ring. */ in vte_dma_alloc()
734 error = bus_dmamem_alloc(sc->vte_cdata.vte_rx_ring_tag, in vte_dma_alloc()
735 (void **)&sc->vte_cdata.vte_rx_ring, in vte_dma_alloc()
737 &sc->vte_cdata.vte_rx_ring_map); in vte_dma_alloc()
739 device_printf(sc->vte_dev, in vte_dma_alloc()
740 "could not allocate DMA'able memory for RX ring.\n"); in vte_dma_alloc()
744 error = bus_dmamap_load(sc->vte_cdata.vte_rx_ring_tag, in vte_dma_alloc()
745 sc->vte_cdata.vte_rx_ring_map, sc->vte_cdata.vte_rx_ring, in vte_dma_alloc()
748 device_printf(sc->vte_dev, in vte_dma_alloc()
749 "could not load DMA'able memory for RX ring.\n"); in vte_dma_alloc()
752 sc->vte_cdata.vte_rx_ring_paddr = ctx.vte_busaddr; in vte_dma_alloc()
756 bus_get_dma_tag(sc->vte_dev), /* parent */ in vte_dma_alloc()
766 &sc->vte_cdata.vte_buffer_tag); in vte_dma_alloc()
768 device_printf(sc->vte_dev, in vte_dma_alloc()
775 sc->vte_cdata.vte_buffer_tag, /* parent */ in vte_dma_alloc()
785 &sc->vte_cdata.vte_tx_tag); in vte_dma_alloc()
787 device_printf(sc->vte_dev, "could not create TX DMA tag.\n"); in vte_dma_alloc()
791 /* Create DMA tag for RX buffers. */ in vte_dma_alloc()
793 sc->vte_cdata.vte_buffer_tag, /* parent */ in vte_dma_alloc()
803 &sc->vte_cdata.vte_rx_tag); in vte_dma_alloc()
805 device_printf(sc->vte_dev, "could not create RX DMA tag.\n"); in vte_dma_alloc()
810 txd = &sc->vte_cdata.vte_txdesc[i]; in vte_dma_alloc()
811 txd->tx_m = NULL; in vte_dma_alloc()
812 txd->tx_dmamap = NULL; in vte_dma_alloc()
813 error = bus_dmamap_create(sc->vte_cdata.vte_tx_tag, 0, in vte_dma_alloc()
814 &txd->tx_dmamap); in vte_dma_alloc()
816 device_printf(sc->vte_dev, in vte_dma_alloc()
821 /* Create DMA maps for RX buffers. */ in vte_dma_alloc()
822 if ((error = bus_dmamap_create(sc->vte_cdata.vte_rx_tag, 0, in vte_dma_alloc()
823 &sc->vte_cdata.vte_rx_sparemap)) != 0) { in vte_dma_alloc()
824 device_printf(sc->vte_dev, in vte_dma_alloc()
825 "could not create spare RX dmamap.\n"); in vte_dma_alloc()
829 rxd = &sc->vte_cdata.vte_rxdesc[i]; in vte_dma_alloc()
830 rxd->rx_m = NULL; in vte_dma_alloc()
831 rxd->rx_dmamap = NULL; in vte_dma_alloc()
832 error = bus_dmamap_create(sc->vte_cdata.vte_rx_tag, 0, in vte_dma_alloc()
833 &rxd->rx_dmamap); in vte_dma_alloc()
835 device_printf(sc->vte_dev, in vte_dma_alloc()
836 "could not create RX dmamap.\n"); in vte_dma_alloc()
853 if (sc->vte_cdata.vte_tx_tag != NULL) { in vte_dma_free()
855 txd = &sc->vte_cdata.vte_txdesc[i]; in vte_dma_free()
856 if (txd->tx_dmamap != NULL) { in vte_dma_free()
857 bus_dmamap_destroy(sc->vte_cdata.vte_tx_tag, in vte_dma_free()
858 txd->tx_dmamap); in vte_dma_free()
859 txd->tx_dmamap = NULL; in vte_dma_free()
862 bus_dma_tag_destroy(sc->vte_cdata.vte_tx_tag); in vte_dma_free()
863 sc->vte_cdata.vte_tx_tag = NULL; in vte_dma_free()
865 /* RX buffers */ in vte_dma_free()
866 if (sc->vte_cdata.vte_rx_tag != NULL) { in vte_dma_free()
868 rxd = &sc->vte_cdata.vte_rxdesc[i]; in vte_dma_free()
869 if (rxd->rx_dmamap != NULL) { in vte_dma_free()
870 bus_dmamap_destroy(sc->vte_cdata.vte_rx_tag, in vte_dma_free()
871 rxd->rx_dmamap); in vte_dma_free()
872 rxd->rx_dmamap = NULL; in vte_dma_free()
875 if (sc->vte_cdata.vte_rx_sparemap != NULL) { in vte_dma_free()
876 bus_dmamap_destroy(sc->vte_cdata.vte_rx_tag, in vte_dma_free()
877 sc->vte_cdata.vte_rx_sparemap); in vte_dma_free()
878 sc->vte_cdata.vte_rx_sparemap = NULL; in vte_dma_free()
880 bus_dma_tag_destroy(sc->vte_cdata.vte_rx_tag); in vte_dma_free()
881 sc->vte_cdata.vte_rx_tag = NULL; in vte_dma_free()
884 if (sc->vte_cdata.vte_tx_ring_tag != NULL) { in vte_dma_free()
885 if (sc->vte_cdata.vte_tx_ring_paddr != 0) in vte_dma_free()
886 bus_dmamap_unload(sc->vte_cdata.vte_tx_ring_tag, in vte_dma_free()
887 sc->vte_cdata.vte_tx_ring_map); in vte_dma_free()
888 if (sc->vte_cdata.vte_tx_ring != NULL) in vte_dma_free()
889 bus_dmamem_free(sc->vte_cdata.vte_tx_ring_tag, in vte_dma_free()
890 sc->vte_cdata.vte_tx_ring, in vte_dma_free()
891 sc->vte_cdata.vte_tx_ring_map); in vte_dma_free()
892 sc->vte_cdata.vte_tx_ring = NULL; in vte_dma_free()
893 sc->vte_cdata.vte_tx_ring_paddr = 0; in vte_dma_free()
894 bus_dma_tag_destroy(sc->vte_cdata.vte_tx_ring_tag); in vte_dma_free()
895 sc->vte_cdata.vte_tx_ring_tag = NULL; in vte_dma_free()
897 /* RX ring. */ in vte_dma_free()
898 if (sc->vte_cdata.vte_rx_ring_tag != NULL) { in vte_dma_free()
899 if (sc->vte_cdata.vte_rx_ring_paddr != 0) in vte_dma_free()
900 bus_dmamap_unload(sc->vte_cdata.vte_rx_ring_tag, in vte_dma_free()
901 sc->vte_cdata.vte_rx_ring_map); in vte_dma_free()
902 if (sc->vte_cdata.vte_rx_ring != NULL) in vte_dma_free()
903 bus_dmamem_free(sc->vte_cdata.vte_rx_ring_tag, in vte_dma_free()
904 sc->vte_cdata.vte_rx_ring, in vte_dma_free()
905 sc->vte_cdata.vte_rx_ring_map); in vte_dma_free()
906 sc->vte_cdata.vte_rx_ring = NULL; in vte_dma_free()
907 sc->vte_cdata.vte_rx_ring_paddr = 0; in vte_dma_free()
908 bus_dma_tag_destroy(sc->vte_cdata.vte_rx_ring_tag); in vte_dma_free()
909 sc->vte_cdata.vte_rx_ring_tag = NULL; in vte_dma_free()
911 if (sc->vte_cdata.vte_buffer_tag != NULL) { in vte_dma_free()
912 bus_dma_tag_destroy(sc->vte_cdata.vte_buffer_tag); in vte_dma_free()
913 sc->vte_cdata.vte_buffer_tag = NULL; in vte_dma_free()
915 if (sc->vte_cdata.vte_parent_tag != NULL) { in vte_dma_free()
916 bus_dma_tag_destroy(sc->vte_cdata.vte_parent_tag); in vte_dma_free()
917 sc->vte_cdata.vte_parent_tag = NULL; in vte_dma_free()
937 ifp = sc->vte_ifp; in vte_suspend()
954 ifp = sc->vte_ifp; in vte_resume()
968 struct mbuf *m, *n; in vte_encap() local
976 txd = &sc->vte_cdata.vte_txdesc[sc->vte_cdata.vte_tx_prod]; in vte_encap()
977 m = *m_head; in vte_encap()
979 * Controller doesn't auto-pad, so we have to make sure pad in vte_encap()
982 if (m->m_pkthdr.len < VTE_MIN_FRAMELEN) in vte_encap()
983 padlen = VTE_MIN_FRAMELEN - m->m_pkthdr.len; in vte_encap()
988 * Controller does not support multi-fragmented TX buffers. in vte_encap()
990 * de-fragmenting TX buffers. Either faster CPU or more in vte_encap()
993 * To mitigate the de-fragmenting issue, perform deep copy in vte_encap()
994 * from fragmented mbuf chains to a pre-allocated mbuf in vte_encap()
1001 if (m->m_next != NULL) in vte_encap()
1003 if (padlen > 0 && (M_WRITABLE(m) == 0 || in vte_encap()
1004 padlen > M_TRAILINGSPACE(m))) in vte_encap()
1008 n = sc->vte_cdata.vte_txmbufs[sc->vte_cdata.vte_tx_prod]; in vte_encap()
1009 m_copydata(m, 0, m->m_pkthdr.len, mtod(n, char *)); in vte_encap()
1010 n->m_pkthdr.len = m->m_pkthdr.len; in vte_encap()
1011 n->m_len = m->m_pkthdr.len; in vte_encap()
1012 m = n; in vte_encap()
1013 txd->tx_flags |= VTE_TXMBUF; in vte_encap()
1018 bzero(mtod(m, char *) + m->m_pkthdr.len, padlen); in vte_encap()
1019 m->m_pkthdr.len += padlen; in vte_encap()
1020 m->m_len = m->m_pkthdr.len; in vte_encap()
1023 if (M_WRITABLE(m) == 0) { in vte_encap()
1024 if (m->m_next != NULL || padlen > 0) { in vte_encap()
1026 m = m_dup(*m_head, M_NOWAIT); in vte_encap()
1029 if (m == NULL) { in vte_encap()
1033 *m_head = m; in vte_encap()
1037 if (m->m_next != NULL) { in vte_encap()
1038 m = m_defrag(*m_head, M_NOWAIT); in vte_encap()
1039 if (m == NULL) { in vte_encap()
1044 *m_head = m; in vte_encap()
1048 if (M_TRAILINGSPACE(m) < padlen) { in vte_encap()
1049 m = m_defrag(*m_head, M_NOWAIT); in vte_encap()
1050 if (m == NULL) { in vte_encap()
1055 *m_head = m; in vte_encap()
1058 bzero(mtod(m, char *) + m->m_pkthdr.len, padlen); in vte_encap()
1059 m->m_pkthdr.len += padlen; in vte_encap()
1060 m->m_len = m->m_pkthdr.len; in vte_encap()
1064 error = bus_dmamap_load_mbuf_sg(sc->vte_cdata.vte_tx_tag, in vte_encap()
1065 txd->tx_dmamap, m, txsegs, &nsegs, 0); in vte_encap()
1067 txd->tx_flags &= ~VTE_TXMBUF; in vte_encap()
1071 bus_dmamap_sync(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap, in vte_encap()
1074 txd->tx_desc->dtlen = htole16(VTE_TX_LEN(txsegs[0].ds_len)); in vte_encap()
1075 txd->tx_desc->dtbp = htole32(txsegs[0].ds_addr); in vte_encap()
1076 sc->vte_cdata.vte_tx_cnt++; in vte_encap()
1078 VTE_DESC_INC(sc->vte_cdata.vte_tx_prod, VTE_TX_RING_CNT); in vte_encap()
1081 txd->tx_desc->dtst = htole16(VTE_DTST_TX_OWN); in vte_encap()
1082 txd->tx_m = m; in vte_encap()
1106 ifp = sc->vte_ifp; in vte_start_locked()
1109 IFF_DRV_RUNNING || (sc->vte_flags & VTE_FLAG_LINK) == 0) in vte_start_locked()
1114 if (sc->vte_cdata.vte_tx_cnt >= VTE_TX_RING_CNT - 1) { in vte_start_locked()
1139 if ((txd->tx_flags & VTE_TXMBUF) != 0) in vte_start_locked()
1144 bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag, in vte_start_locked()
1145 sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_PREREAD | in vte_start_locked()
1148 sc->vte_watchdog_timer = VTE_TX_TIMEOUT; in vte_start_locked()
1159 if (sc->vte_watchdog_timer == 0 || --sc->vte_watchdog_timer) in vte_watchdog()
1162 ifp = sc->vte_ifp; in vte_watchdog()
1163 if_printf(sc->vte_ifp, "watchdog timeout -- resetting\n"); in vte_watchdog()
1187 ((if_getflags(ifp) ^ sc->vte_if_flags) & in vte_ioctl()
1194 sc->vte_if_flags = if_getflags(ifp); in vte_ioctl()
1206 mii = device_get_softc(sc->vte_miibus); in vte_ioctl()
1207 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd); in vte_ioctl()
1225 mii = device_get_softc(sc->vte_miibus); in vte_mac_config()
1228 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { in vte_mac_config()
1231 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0) in vte_mac_config()
1236 * separate control bit for RX pause frame so just in vte_mac_config()
1239 if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0) in vte_mac_config()
1269 stat = &sc->vte_stats; in vte_stats_update()
1272 /* RX stats. */ in vte_stats_update()
1273 stat->rx_frames += CSR_READ_2(sc, VTE_CNT_RX_DONE); in vte_stats_update()
1275 stat->rx_bcast_frames += (value >> 8); in vte_stats_update()
1276 stat->rx_mcast_frames += (value & 0xFF); in vte_stats_update()
1278 stat->rx_runts += (value >> 8); in vte_stats_update()
1279 stat->rx_crcerrs += (value & 0xFF); in vte_stats_update()
1281 stat->rx_long_frames += (value & 0xFF); in vte_stats_update()
1283 stat->rx_fifo_full += (value >> 8); in vte_stats_update()
1284 stat->rx_desc_unavail += (value & 0xFF); in vte_stats_update()
1287 stat->tx_frames += CSR_READ_2(sc, VTE_CNT_TX_DONE); in vte_stats_update()
1289 stat->tx_underruns += (value >> 8); in vte_stats_update()
1290 stat->tx_late_colls += (value & 0xFF); in vte_stats_update()
1293 stat->tx_pause_frames += (value >> 8); in vte_stats_update()
1294 stat->rx_pause_frames += (value & 0xFF); in vte_stats_update()
1304 stat = &sc->vte_stats; in vte_get_counter()
1308 return (stat->tx_frames); in vte_get_counter()
1310 return (stat->tx_late_colls); in vte_get_counter()
1312 return (stat->tx_late_colls + stat->tx_underruns); in vte_get_counter()
1314 return (stat->rx_frames); in vte_get_counter()
1316 return (stat->rx_crcerrs + stat->rx_runts + in vte_get_counter()
1317 stat->rx_long_frames + stat->rx_fifo_full); in vte_get_counter()
1334 ifp = sc->vte_ifp; in vte_intr()
1357 if (--n > 0) in vte_intr()
1364 /* Re-enable interrupts. */ in vte_intr()
1380 ifp = sc->vte_ifp; in vte_txeof()
1382 if (sc->vte_cdata.vte_tx_cnt == 0) in vte_txeof()
1384 bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag, in vte_txeof()
1385 sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_POSTREAD | in vte_txeof()
1387 cons = sc->vte_cdata.vte_tx_cons; in vte_txeof()
1392 for (prog = 0; sc->vte_cdata.vte_tx_cnt > 0; prog++) { in vte_txeof()
1393 txd = &sc->vte_cdata.vte_txdesc[cons]; in vte_txeof()
1394 status = le16toh(txd->tx_desc->dtst); in vte_txeof()
1397 sc->vte_cdata.vte_tx_cnt--; in vte_txeof()
1399 bus_dmamap_sync(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap, in vte_txeof()
1401 bus_dmamap_unload(sc->vte_cdata.vte_tx_tag, txd->tx_dmamap); in vte_txeof()
1402 if ((txd->tx_flags & VTE_TXMBUF) == 0) in vte_txeof()
1403 m_freem(txd->tx_m); in vte_txeof()
1404 txd->tx_flags &= ~VTE_TXMBUF; in vte_txeof()
1405 txd->tx_m = NULL; in vte_txeof()
1412 sc->vte_cdata.vte_tx_cons = cons; in vte_txeof()
1417 if (sc->vte_cdata.vte_tx_cnt == 0) in vte_txeof()
1418 sc->vte_watchdog_timer = 0; in vte_txeof()
1425 struct mbuf *m; in vte_newbuf() local
1430 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in vte_newbuf()
1431 if (m == NULL) in vte_newbuf()
1433 m->m_len = m->m_pkthdr.len = MCLBYTES; in vte_newbuf()
1434 m_adj(m, sizeof(uint32_t)); in vte_newbuf()
1436 if (bus_dmamap_load_mbuf_sg(sc->vte_cdata.vte_rx_tag, in vte_newbuf()
1437 sc->vte_cdata.vte_rx_sparemap, m, segs, &nsegs, 0) != 0) { in vte_newbuf()
1438 m_freem(m); in vte_newbuf()
1443 if (rxd->rx_m != NULL) { in vte_newbuf()
1444 bus_dmamap_sync(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap, in vte_newbuf()
1446 bus_dmamap_unload(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap); in vte_newbuf()
1448 map = rxd->rx_dmamap; in vte_newbuf()
1449 rxd->rx_dmamap = sc->vte_cdata.vte_rx_sparemap; in vte_newbuf()
1450 sc->vte_cdata.vte_rx_sparemap = map; in vte_newbuf()
1451 bus_dmamap_sync(sc->vte_cdata.vte_rx_tag, rxd->rx_dmamap, in vte_newbuf()
1453 rxd->rx_m = m; in vte_newbuf()
1454 rxd->rx_desc->drbp = htole32(segs[0].ds_addr); in vte_newbuf()
1455 rxd->rx_desc->drlen = htole16(VTE_RX_LEN(segs[0].ds_len)); in vte_newbuf()
1456 rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN); in vte_newbuf()
1462 * It's not supposed to see this controller on strict-alignment
1467 vte_fixup_rx(if_t ifp, struct mbuf *m) in vte_fixup_rx() argument
1472 src = mtod(m, uint16_t *); in vte_fixup_rx()
1473 dst = src - 1; in vte_fixup_rx()
1475 for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++) in vte_fixup_rx()
1477 m->m_data -= ETHER_ALIGN; in vte_fixup_rx()
1478 return (m); in vte_fixup_rx()
1487 struct mbuf *m; in vte_rxeof() local
1491 bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag, in vte_rxeof()
1492 sc->vte_cdata.vte_rx_ring_map, BUS_DMASYNC_POSTREAD | in vte_rxeof()
1494 cons = sc->vte_cdata.vte_rx_cons; in vte_rxeof()
1495 ifp = sc->vte_ifp; in vte_rxeof()
1498 rxd = &sc->vte_cdata.vte_rxdesc[cons]; in vte_rxeof()
1499 status = le16toh(rxd->rx_desc->drst); in vte_rxeof()
1502 total_len = VTE_RX_LEN(le16toh(rxd->rx_desc->drlen)); in vte_rxeof()
1503 m = rxd->rx_m; in vte_rxeof()
1506 rxd->rx_desc->drlen = in vte_rxeof()
1507 htole16(MCLBYTES - sizeof(uint32_t)); in vte_rxeof()
1508 rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN); in vte_rxeof()
1513 rxd->rx_desc->drlen = in vte_rxeof()
1514 htole16(MCLBYTES - sizeof(uint32_t)); in vte_rxeof()
1515 rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN); in vte_rxeof()
1522 m->m_pkthdr.len = m->m_len = total_len - ETHER_CRC_LEN; in vte_rxeof()
1523 m->m_pkthdr.rcvif = ifp; in vte_rxeof()
1525 vte_fixup_rx(ifp, m); in vte_rxeof()
1528 if_input(ifp, m); in vte_rxeof()
1534 sc->vte_cdata.vte_rx_cons = cons; in vte_rxeof()
1536 * Sync updated RX descriptors such that controller see in vte_rxeof()
1537 * modified RX buffer addresses. in vte_rxeof()
1539 bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag, in vte_rxeof()
1540 sc->vte_cdata.vte_rx_ring_map, in vte_rxeof()
1545 * keep track of number of available RX descriptors in vte_rxeof()
1547 * to make controller know how many free RX in vte_rxeof()
1551 * polls OWN bit of current RX descriptor pointer. in vte_rxeof()
1554 * pause frames once RX pause threshold crossed. in vte_rxeof()
1581 mii = device_get_softc(sc->vte_miibus); in vte_tick()
1586 callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc); in vte_tick()
1598 for (i = VTE_RESET_TIMEOUT; i > 0; i--) { in vte_reset()
1604 device_printf(sc->vte_dev, "reset timeout(0x%04x)!\n", mcr); in vte_reset()
1643 ifp = sc->vte_ifp; in vte_init_locked()
1656 /* Initialize RX descriptors. */ in vte_init_locked()
1658 device_printf(sc->vte_dev, "no memory for RX buffers.\n"); in vte_init_locked()
1663 device_printf(sc->vte_dev, "no memory for TX buffers.\n"); in vte_init_locked()
1675 eaddr = if_getlladdr(sc->vte_ifp); in vte_init_locked()
1681 paddr = sc->vte_cdata.vte_tx_ring_paddr; in vte_init_locked()
1684 /* Set RX descriptor base addresses. */ in vte_init_locked()
1685 paddr = sc->vte_cdata.vte_rx_ring_paddr; in vte_init_locked()
1689 * Initialize RX descriptor residue counter and set RX in vte_init_locked()
1690 * pause threshold to 20% of available RX descriptors. in vte_init_locked()
1701 * in controller. This would break path-MTU discovery as in vte_init_locked()
1703 * RX buffer size should be multiple of 4. in vte_init_locked()
1715 * Configure TX/RX MACs. Actual resolved duplex and flow in vte_init_locked()
1731 /* Initialize RX filter. */ in vte_init_locked()
1734 /* Disable TX/RX interrupt moderation control. */ in vte_init_locked()
1747 sc->vte_flags &= ~VTE_FLAG_LINK; in vte_init_locked()
1751 callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc); in vte_init_locked()
1769 ifp = sc->vte_ifp; in vte_stop()
1771 sc->vte_flags &= ~VTE_FLAG_LINK; in vte_stop()
1772 callout_stop(&sc->vte_tick_ch); in vte_stop()
1773 sc->vte_watchdog_timer = 0; in vte_stop()
1778 /* Stop RX/TX MACs. */ in vte_stop()
1783 * Free TX/RX mbufs still in the queues. in vte_stop()
1786 rxd = &sc->vte_cdata.vte_rxdesc[i]; in vte_stop()
1787 if (rxd->rx_m != NULL) { in vte_stop()
1788 bus_dmamap_sync(sc->vte_cdata.vte_rx_tag, in vte_stop()
1789 rxd->rx_dmamap, BUS_DMASYNC_POSTREAD); in vte_stop()
1790 bus_dmamap_unload(sc->vte_cdata.vte_rx_tag, in vte_stop()
1791 rxd->rx_dmamap); in vte_stop()
1792 m_freem(rxd->rx_m); in vte_stop()
1793 rxd->rx_m = NULL; in vte_stop()
1797 txd = &sc->vte_cdata.vte_txdesc[i]; in vte_stop()
1798 if (txd->tx_m != NULL) { in vte_stop()
1799 bus_dmamap_sync(sc->vte_cdata.vte_tx_tag, in vte_stop()
1800 txd->tx_dmamap, BUS_DMASYNC_POSTWRITE); in vte_stop()
1801 bus_dmamap_unload(sc->vte_cdata.vte_tx_tag, in vte_stop()
1802 txd->tx_dmamap); in vte_stop()
1803 if ((txd->tx_flags & VTE_TXMBUF) == 0) in vte_stop()
1804 m_freem(txd->tx_m); in vte_stop()
1805 txd->tx_m = NULL; in vte_stop()
1806 txd->tx_flags &= ~VTE_TXMBUF; in vte_stop()
1811 if (sc->vte_cdata.vte_txmbufs[i] != NULL) { in vte_stop()
1812 m_freem(sc->vte_cdata.vte_txmbufs[i]); in vte_stop()
1813 sc->vte_cdata.vte_txmbufs[i] = NULL; in vte_stop()
1826 /* Enable RX/TX MACs. */ in vte_start_mac()
1832 for (i = VTE_TIMEOUT; i > 0; i--) { in vte_start_mac()
1840 device_printf(sc->vte_dev, in vte_start_mac()
1841 "could not enable RX/TX MAC(0x%04x)!\n", mcr); in vte_start_mac()
1853 /* Disable RX/TX MACs. */ in vte_stop_mac()
1858 for (i = VTE_TIMEOUT; i > 0; i--) { in vte_stop_mac()
1865 device_printf(sc->vte_dev, in vte_stop_mac()
1866 "could not disable RX/TX MAC(0x%04x)!\n", mcr); in vte_stop_mac()
1880 sc->vte_cdata.vte_tx_prod = 0; in vte_init_tx_ring()
1881 sc->vte_cdata.vte_tx_cons = 0; in vte_init_tx_ring()
1882 sc->vte_cdata.vte_tx_cnt = 0; in vte_init_tx_ring()
1884 /* Pre-allocate TX mbufs for deep copy. */ in vte_init_tx_ring()
1887 sc->vte_cdata.vte_txmbufs[i] = m_getcl(M_NOWAIT, in vte_init_tx_ring()
1889 if (sc->vte_cdata.vte_txmbufs[i] == NULL) in vte_init_tx_ring()
1891 sc->vte_cdata.vte_txmbufs[i]->m_pkthdr.len = MCLBYTES; in vte_init_tx_ring()
1892 sc->vte_cdata.vte_txmbufs[i]->m_len = MCLBYTES; in vte_init_tx_ring()
1895 desc = sc->vte_cdata.vte_tx_ring; in vte_init_tx_ring()
1898 txd = &sc->vte_cdata.vte_txdesc[i]; in vte_init_tx_ring()
1899 txd->tx_m = NULL; in vte_init_tx_ring()
1900 if (i != VTE_TX_RING_CNT - 1) in vte_init_tx_ring()
1901 addr = sc->vte_cdata.vte_tx_ring_paddr + in vte_init_tx_ring()
1904 addr = sc->vte_cdata.vte_tx_ring_paddr + in vte_init_tx_ring()
1906 desc = &sc->vte_cdata.vte_tx_ring[i]; in vte_init_tx_ring()
1907 desc->dtnp = htole32(addr); in vte_init_tx_ring()
1908 txd->tx_desc = desc; in vte_init_tx_ring()
1911 bus_dmamap_sync(sc->vte_cdata.vte_tx_ring_tag, in vte_init_tx_ring()
1912 sc->vte_cdata.vte_tx_ring_map, BUS_DMASYNC_PREREAD | in vte_init_tx_ring()
1927 sc->vte_cdata.vte_rx_cons = 0; in vte_init_rx_ring()
1928 desc = sc->vte_cdata.vte_rx_ring; in vte_init_rx_ring()
1931 rxd = &sc->vte_cdata.vte_rxdesc[i]; in vte_init_rx_ring()
1932 rxd->rx_m = NULL; in vte_init_rx_ring()
1933 if (i != VTE_RX_RING_CNT - 1) in vte_init_rx_ring()
1934 addr = sc->vte_cdata.vte_rx_ring_paddr + in vte_init_rx_ring()
1937 addr = sc->vte_cdata.vte_rx_ring_paddr + in vte_init_rx_ring()
1939 desc = &sc->vte_cdata.vte_rx_ring[i]; in vte_init_rx_ring()
1940 desc->drnp = htole32(addr); in vte_init_rx_ring()
1941 rxd->rx_desc = desc; in vte_init_rx_ring()
1946 bus_dmamap_sync(sc->vte_cdata.vte_rx_ring_tag, in vte_init_rx_ring()
1947 sc->vte_cdata.vte_rx_ring_map, BUS_DMASYNC_PREREAD | in vte_init_rx_ring()
1970 if (ctx->nperf < VTE_RXFILT_PERFECT_CNT) { in vte_hash_maddr()
1972 ctx->rxfilt_perf[ctx->nperf][0] = eaddr[1] << 8 | eaddr[0]; in vte_hash_maddr()
1973 ctx->rxfilt_perf[ctx->nperf][1] = eaddr[3] << 8 | eaddr[2]; in vte_hash_maddr()
1974 ctx->rxfilt_perf[ctx->nperf][2] = eaddr[5] << 8 | eaddr[4]; in vte_hash_maddr()
1975 ctx->nperf++; in vte_hash_maddr()
1980 ctx->mchash[crc >> 30] |= 1 << ((crc >> 26) & 0x0F); in vte_hash_maddr()
1995 ifp = sc->vte_ifp; in vte_rxfilter()
2055 if (error || req->newptr == NULL) in sysctl_int_range()