Index: stable/12/sys/dev/netmap/if_vtnet_netmap.h =================================================================== --- stable/12/sys/dev/netmap/if_vtnet_netmap.h (revision 362023) +++ stable/12/sys/dev/netmap/if_vtnet_netmap.h (revision 362024) @@ -1,479 +1,489 @@ /* * Copyright (C) 2014-2018 Vincenzo Maffione, Luigi Rizzo. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * $FreeBSD$ */ #include #include #include #include /* vtophys ? */ #include /* * Return 1 if the queue identified by 't' and 'idx' is in netmap mode. */ static int vtnet_netmap_queue_on(struct vtnet_softc *sc, enum txrx t, int idx) { struct netmap_adapter *na = NA(sc->vtnet_ifp); if (!nm_native_on(na)) return 0; if (t == NR_RX) return !!(idx < na->num_rx_rings && na->rx_rings[idx]->nr_mode == NKR_NETMAP_ON); return !!(idx < na->num_tx_rings && na->tx_rings[idx]->nr_mode == NKR_NETMAP_ON); } /* Register and unregister. */ static int vtnet_netmap_reg(struct netmap_adapter *na, int state) { struct ifnet *ifp = na->ifp; struct vtnet_softc *sc = ifp->if_softc; int success; int i; /* Drain the taskqueues to make sure that there are no worker threads * accessing the virtqueues. */ vtnet_drain_taskqueues(sc); VTNET_CORE_LOCK(sc); /* We need nm_netmap_on() to return true when called by * vtnet_init_locked() below. */ if (state) nm_set_native_flags(na); /* We need to trigger a device reset in order to unexpose guest buffers * published to the host. */ ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); /* Get pending used buffers. The way they are freed depends on whether * they are netmap buffer or they are mbufs. We can tell apart the two * cases by looking at kring->nr_mode, before this is possibly updated * in the loop below. */ for (i = 0; i < sc->vtnet_act_vq_pairs; i++) { struct vtnet_txq *txq = &sc->vtnet_txqs[i]; struct vtnet_rxq *rxq = &sc->vtnet_rxqs[i]; VTNET_TXQ_LOCK(txq); vtnet_txq_free_mbufs(txq); VTNET_TXQ_UNLOCK(txq); VTNET_RXQ_LOCK(rxq); vtnet_rxq_free_mbufs(rxq); VTNET_RXQ_UNLOCK(rxq); } vtnet_init_locked(sc); success = (ifp->if_drv_flags & IFF_DRV_RUNNING) ? 0 : ENXIO; if (state) { netmap_krings_mode_commit(na, state); } else { nm_clear_native_flags(na); netmap_krings_mode_commit(na, state); } VTNET_CORE_UNLOCK(sc); return success; } /* Reconcile kernel and user view of the transmit ring. */ static int vtnet_netmap_txsync(struct netmap_kring *kring, int flags) { struct netmap_adapter *na = kring->na; struct ifnet *ifp = na->ifp; struct netmap_ring *ring = kring->ring; u_int ring_nr = kring->ring_id; u_int nm_i; /* index into the netmap ring */ u_int const lim = kring->nkr_num_slots - 1; u_int const head = kring->rhead; /* device-specific */ struct vtnet_softc *sc = ifp->if_softc; struct vtnet_txq *txq = &sc->vtnet_txqs[ring_nr]; struct virtqueue *vq = txq->vtntx_vq; int interrupts = !(kring->nr_kflags & NKR_NOINTR); u_int n; /* * First part: process new packets to send. */ nm_i = kring->nr_hwcur; if (nm_i != head) { /* we have new packets to send */ struct sglist *sg = txq->vtntx_sg; for (; nm_i != head; nm_i = nm_next(nm_i, lim)) { /* we use an empty header here */ struct netmap_slot *slot = &ring->slot[nm_i]; u_int len = slot->len; uint64_t paddr; void *addr = PNMB(na, slot, &paddr); int err; NM_CHECK_ADDR_LEN(na, addr, len); slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED); /* Initialize the scatterlist, expose it to the hypervisor, * and kick the hypervisor (if necessary). */ sglist_reset(sg); // cheap err = sglist_append(sg, &txq->vtntx_shrhdr, sc->vtnet_hdr_size); err |= sglist_append_phys(sg, paddr, len); KASSERT(err == 0, ("%s: cannot append to sglist %d", __func__, err)); err = virtqueue_enqueue(vq, /*cookie=*/txq, sg, /*readable=*/sg->sg_nseg, /*writeable=*/0); if (unlikely(err)) { if (err != ENOSPC) nm_prerr("virtqueue_enqueue(%s) failed: %d", kring->name, err); break; } } virtqueue_notify(vq); /* Update hwcur depending on where we stopped. */ kring->nr_hwcur = nm_i; /* note we migth break early */ } /* Free used slots. We only consider our own used buffers, recognized * by the token we passed to virtqueue_enqueue. */ n = 0; for (;;) { void *token = virtqueue_dequeue(vq, NULL); if (token == NULL) break; if (unlikely(token != (void *)txq)) nm_prerr("BUG: TX token mismatch"); else n++; } if (n > 0) { kring->nr_hwtail += n; if (kring->nr_hwtail > lim) kring->nr_hwtail -= lim + 1; } if (interrupts && virtqueue_nfree(vq) < 32) virtqueue_postpone_intr(vq, VQ_POSTPONE_LONG); return 0; } /* - * Publish (up to) num netmap receive buffers to the host, - * starting from the first one that the user made available - * (kring->nr_hwcur). + * Publish 'num 'netmap receive buffers to the host, starting + * from the next available one (rx->vtnrx_nm_refill). + * Return a positive error code on error, and 0 on success. + * If we could not publish all of the buffers that's an error, + * since the netmap ring and the virtqueue would go out of sync. */ static int vtnet_netmap_kring_refill(struct netmap_kring *kring, u_int num) { struct netmap_adapter *na = kring->na; struct ifnet *ifp = na->ifp; struct netmap_ring *ring = kring->ring; u_int ring_nr = kring->ring_id; u_int const lim = kring->nkr_num_slots - 1; - u_int nm_i = kring->nr_hwcur; + u_int nm_i; /* device-specific */ struct vtnet_softc *sc = ifp->if_softc; struct vtnet_rxq *rxq = &sc->vtnet_rxqs[ring_nr]; struct virtqueue *vq = rxq->vtnrx_vq; /* use a local sglist, default might be short */ struct sglist_seg ss[2]; struct sglist sg = { ss, 0, 0, 2 }; - for (; num > 0; nm_i = nm_next(nm_i, lim), num--) { + for (nm_i = rxq->vtnrx_nm_refill; num > 0; + nm_i = nm_next(nm_i, lim), num--) { struct netmap_slot *slot = &ring->slot[nm_i]; uint64_t paddr; void *addr = PNMB(na, slot, &paddr); int err; if (addr == NETMAP_BUF_BASE(na)) { /* bad buf */ if (netmap_ring_reinit(kring)) - return -1; + return EFAULT; } slot->flags &= ~NS_BUF_CHANGED; sglist_reset(&sg); err = sglist_append(&sg, &rxq->vtnrx_shrhdr, sc->vtnet_hdr_size); err |= sglist_append_phys(&sg, paddr, NETMAP_BUF_SIZE(na)); KASSERT(err == 0, ("%s: cannot append to sglist %d", __func__, err)); /* writable for the host */ err = virtqueue_enqueue(vq, /*cookie=*/rxq, &sg, /*readable=*/0, /*writeable=*/sg.sg_nseg); if (unlikely(err)) { - if (err != ENOSPC) - nm_prerr("virtqueue_enqueue(%s) failed: %d", - kring->name, err); + nm_prerr("virtqueue_enqueue(%s) failed: %d", + kring->name, err); break; } } + rxq->vtnrx_nm_refill = nm_i; - return nm_i; + return num == 0 ? 0 : ENOSPC; } /* * Publish netmap buffers on a RX virtqueue. * Returns -1 if this virtqueue is not being opened in netmap mode. * If the virtqueue is being opened in netmap mode, return 0 on success and * a positive error code on failure. */ static int vtnet_netmap_rxq_populate(struct vtnet_rxq *rxq) { struct netmap_adapter *na = NA(rxq->vtnrx_sc->vtnet_ifp); struct netmap_kring *kring; int error; if (!nm_native_on(na) || rxq->vtnrx_id >= na->num_rx_rings) return -1; kring = na->rx_rings[rxq->vtnrx_id]; if (!(nm_kring_pending_on(kring) || kring->nr_pending_mode == NKR_NETMAP_ON)) return -1; /* Expose all the RX netmap buffers we can. In case of no indirect * buffers, the number of netmap slots in the RX ring matches the * maximum number of 2-elements sglist that the RX virtqueue can - * accommodate (minus 1 to avoid netmap ring wraparound). */ + * accommodate. We need to start from kring->nr_hwcur, which is 0 + * on netmap register and may be different from 0 if a virtio + * re-init happens while the device is in use by netmap. */ + rxq->vtnrx_nm_refill = kring->nr_hwcur; error = vtnet_netmap_kring_refill(kring, na->num_rx_desc - 1); virtqueue_notify(rxq->vtnrx_vq); - return error < 0 ? ENXIO : 0; + return error; } /* Reconcile kernel and user view of the receive ring. */ static int vtnet_netmap_rxsync(struct netmap_kring *kring, int flags) { struct netmap_adapter *na = kring->na; struct ifnet *ifp = na->ifp; struct netmap_ring *ring = kring->ring; u_int ring_nr = kring->ring_id; u_int nm_i; /* index into the netmap ring */ u_int const lim = kring->nkr_num_slots - 1; u_int const head = kring->rhead; int force_update = (flags & NAF_FORCE_READ) || (kring->nr_kflags & NKR_PENDINTR); int interrupts = !(kring->nr_kflags & NKR_NOINTR); /* device-specific */ struct vtnet_softc *sc = ifp->if_softc; struct vtnet_rxq *rxq = &sc->vtnet_rxqs[ring_nr]; struct virtqueue *vq = rxq->vtnrx_vq; /* * First part: import newly received packets. * Only accept our own buffers (matching the token). We should only get * matching buffers. We may need to stop early to avoid hwtail to overrun * hwcur. */ if (netmap_no_pendintr || force_update) { uint32_t hwtail_lim = nm_prev(kring->nr_hwcur, lim); void *token; vtnet_rxq_disable_intr(rxq); nm_i = kring->nr_hwtail; while (nm_i != hwtail_lim) { int len; token = virtqueue_dequeue(vq, &len); if (token == NULL) { if (interrupts && vtnet_rxq_enable_intr(rxq)) { vtnet_rxq_disable_intr(rxq); continue; } break; } if (unlikely(token != (void *)rxq)) { nm_prerr("BUG: RX token mismatch"); } else { /* Skip the virtio-net header. */ len -= sc->vtnet_hdr_size; if (unlikely(len < 0)) { nm_prlim(1, "Truncated virtio-net-header, " "missing %d bytes", -len); len = 0; } ring->slot[nm_i].len = len; ring->slot[nm_i].flags = 0; nm_i = nm_next(nm_i, lim); } } kring->nr_hwtail = nm_i; kring->nr_kflags &= ~NKR_PENDINTR; } nm_prdis("[B] h %d c %d hwcur %d hwtail %d", ring->head, ring->cur, kring->nr_hwcur, kring->nr_hwtail); /* * Second part: skip past packets that userspace has released. */ nm_i = kring->nr_hwcur; /* netmap ring index */ if (nm_i != head) { - int howmany = head - nm_i; - int nm_j; + int released; + int error; - if (howmany < 0) - howmany += kring->nkr_num_slots; - nm_j = vtnet_netmap_kring_refill(kring, howmany); - if (nm_j < 0) - return nm_j; - kring->nr_hwcur = nm_j; + released = head - nm_i; + if (released < 0) + released += kring->nkr_num_slots; + error = vtnet_netmap_kring_refill(kring, released); + if (error) { + nm_prerr("Failed to replenish RX VQ with %u sgs", + released); + return error; + } + kring->nr_hwcur = head; virtqueue_notify(vq); } nm_prdis("[C] h %d c %d t %d hwcur %d hwtail %d", ring->head, ring->cur, ring->tail, kring->nr_hwcur, kring->nr_hwtail); return 0; } /* Enable/disable interrupts on all virtqueues. */ static void vtnet_netmap_intr(struct netmap_adapter *na, int state) { struct vtnet_softc *sc = na->ifp->if_softc; int i; for (i = 0; i < sc->vtnet_max_vq_pairs; i++) { struct vtnet_rxq *rxq = &sc->vtnet_rxqs[i]; struct vtnet_txq *txq = &sc->vtnet_txqs[i]; struct virtqueue *txvq = txq->vtntx_vq; if (state) { vtnet_rxq_enable_intr(rxq); virtqueue_enable_intr(txvq); } else { vtnet_rxq_disable_intr(rxq); virtqueue_disable_intr(txvq); } } } static int vtnet_netmap_tx_slots(struct vtnet_softc *sc) { int div; /* We need to prepend a virtio-net header to each netmap buffer to be * transmitted, therefore calling virtqueue_enqueue() passing sglist * with 2 elements. * TX virtqueues use indirect descriptors if the feature was negotiated * with the host, and if sc->vtnet_tx_nsegs > 1. With indirect * descriptors, a single virtio descriptor is sufficient to reference * each TX sglist. Without them, we need two separate virtio descriptors * for each TX sglist. We therefore compute the number of netmap TX * slots according to these assumptions. */ if ((sc->vtnet_flags & VTNET_FLAG_INDIRECT) && sc->vtnet_tx_nsegs > 1) div = 1; else div = 2; return virtqueue_size(sc->vtnet_txqs[0].vtntx_vq) / div; } static int vtnet_netmap_rx_slots(struct vtnet_softc *sc) { int div; /* We need to prepend a virtio-net header to each netmap buffer to be * received, therefore calling virtqueue_enqueue() passing sglist * with 2 elements. * RX virtqueues use indirect descriptors if the feature was negotiated * with the host, and if sc->vtnet_rx_nsegs > 1. With indirect * descriptors, a single virtio descriptor is sufficient to reference * each RX sglist. Without them, we need two separate virtio descriptors * for each RX sglist. We therefore compute the number of netmap RX * slots according to these assumptions. */ if ((sc->vtnet_flags & VTNET_FLAG_INDIRECT) && sc->vtnet_rx_nsegs > 1) div = 1; else div = 2; return virtqueue_size(sc->vtnet_rxqs[0].vtnrx_vq) / div; } static int vtnet_netmap_config(struct netmap_adapter *na, struct nm_config_info *info) { struct vtnet_softc *sc = na->ifp->if_softc; info->num_tx_rings = sc->vtnet_act_vq_pairs; info->num_rx_rings = sc->vtnet_act_vq_pairs; info->num_tx_descs = vtnet_netmap_tx_slots(sc); info->num_rx_descs = vtnet_netmap_rx_slots(sc); info->rx_buf_maxsize = NETMAP_BUF_SIZE(na); return 0; } static void vtnet_netmap_attach(struct vtnet_softc *sc) { struct netmap_adapter na; bzero(&na, sizeof(na)); na.ifp = sc->vtnet_ifp; na.na_flags = 0; na.num_tx_desc = vtnet_netmap_tx_slots(sc); na.num_rx_desc = vtnet_netmap_rx_slots(sc); na.num_tx_rings = na.num_rx_rings = sc->vtnet_max_vq_pairs; na.rx_buf_maxsize = 0; na.nm_register = vtnet_netmap_reg; na.nm_txsync = vtnet_netmap_txsync; na.nm_rxsync = vtnet_netmap_rxsync; na.nm_intr = vtnet_netmap_intr; na.nm_config = vtnet_netmap_config; netmap_attach(&na); nm_prinf("vtnet attached txq=%d, txd=%d rxq=%d, rxd=%d", na.num_tx_rings, na.num_tx_desc, na.num_tx_rings, na.num_rx_desc); } /* end of file */ Index: stable/12/sys/dev/virtio/network/if_vtnetvar.h =================================================================== --- stable/12/sys/dev/virtio/network/if_vtnetvar.h (revision 362023) +++ stable/12/sys/dev/virtio/network/if_vtnetvar.h (revision 362024) @@ -1,367 +1,368 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011, Bryan Venteicher * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _IF_VTNETVAR_H #define _IF_VTNETVAR_H struct vtnet_softc; struct vtnet_statistics { uint64_t mbuf_alloc_failed; uint64_t rx_frame_too_large; uint64_t rx_enq_replacement_failed; uint64_t rx_mergeable_failed; uint64_t rx_csum_bad_ethtype; uint64_t rx_csum_bad_ipproto; uint64_t rx_csum_bad_offset; uint64_t rx_csum_bad_proto; uint64_t tx_csum_bad_ethtype; uint64_t tx_tso_bad_ethtype; uint64_t tx_tso_not_tcp; uint64_t tx_defragged; uint64_t tx_defrag_failed; /* * These are accumulated from each Rx/Tx queue. */ uint64_t rx_csum_failed; uint64_t rx_csum_offloaded; uint64_t rx_task_rescheduled; uint64_t tx_csum_offloaded; uint64_t tx_tso_offloaded; uint64_t tx_task_rescheduled; }; struct vtnet_rxq_stats { uint64_t vrxs_ipackets; /* if_ipackets */ uint64_t vrxs_ibytes; /* if_ibytes */ uint64_t vrxs_iqdrops; /* if_iqdrops */ uint64_t vrxs_ierrors; /* if_ierrors */ uint64_t vrxs_csum; uint64_t vrxs_csum_failed; uint64_t vrxs_rescheduled; }; struct vtnet_rxq { struct mtx vtnrx_mtx; struct vtnet_softc *vtnrx_sc; struct virtqueue *vtnrx_vq; struct sglist *vtnrx_sg; int vtnrx_id; struct vtnet_rxq_stats vtnrx_stats; struct taskqueue *vtnrx_tq; struct task vtnrx_intrtask; #ifdef DEV_NETMAP + uint32_t vtnrx_nm_refill; struct virtio_net_hdr_mrg_rxbuf vtnrx_shrhdr; #endif /* DEV_NETMAP */ char vtnrx_name[16]; } __aligned(CACHE_LINE_SIZE); #define VTNET_RXQ_LOCK(_rxq) mtx_lock(&(_rxq)->vtnrx_mtx) #define VTNET_RXQ_UNLOCK(_rxq) mtx_unlock(&(_rxq)->vtnrx_mtx) #define VTNET_RXQ_LOCK_ASSERT(_rxq) \ mtx_assert(&(_rxq)->vtnrx_mtx, MA_OWNED) #define VTNET_RXQ_LOCK_ASSERT_NOTOWNED(_rxq) \ mtx_assert(&(_rxq)->vtnrx_mtx, MA_NOTOWNED) struct vtnet_txq_stats { uint64_t vtxs_opackets; /* if_opackets */ uint64_t vtxs_obytes; /* if_obytes */ uint64_t vtxs_omcasts; /* if_omcasts */ uint64_t vtxs_csum; uint64_t vtxs_tso; uint64_t vtxs_rescheduled; }; struct vtnet_txq { struct mtx vtntx_mtx; struct vtnet_softc *vtntx_sc; struct virtqueue *vtntx_vq; struct sglist *vtntx_sg; #ifndef VTNET_LEGACY_TX struct buf_ring *vtntx_br; #endif int vtntx_id; int vtntx_watchdog; struct vtnet_txq_stats vtntx_stats; struct taskqueue *vtntx_tq; struct task vtntx_intrtask; #ifndef VTNET_LEGACY_TX struct task vtntx_defrtask; #endif #ifdef DEV_NETMAP struct virtio_net_hdr_mrg_rxbuf vtntx_shrhdr; #endif /* DEV_NETMAP */ char vtntx_name[16]; } __aligned(CACHE_LINE_SIZE); #define VTNET_TXQ_LOCK(_txq) mtx_lock(&(_txq)->vtntx_mtx) #define VTNET_TXQ_TRYLOCK(_txq) mtx_trylock(&(_txq)->vtntx_mtx) #define VTNET_TXQ_UNLOCK(_txq) mtx_unlock(&(_txq)->vtntx_mtx) #define VTNET_TXQ_LOCK_ASSERT(_txq) \ mtx_assert(&(_txq)->vtntx_mtx, MA_OWNED) #define VTNET_TXQ_LOCK_ASSERT_NOTOWNED(_txq) \ mtx_assert(&(_txq)->vtntx_mtx, MA_NOTOWNED) struct vtnet_softc { device_t vtnet_dev; struct ifnet *vtnet_ifp; struct vtnet_rxq *vtnet_rxqs; struct vtnet_txq *vtnet_txqs; uint32_t vtnet_flags; #define VTNET_FLAG_SUSPENDED 0x0001 #define VTNET_FLAG_MAC 0x0002 #define VTNET_FLAG_CTRL_VQ 0x0004 #define VTNET_FLAG_CTRL_RX 0x0008 #define VTNET_FLAG_CTRL_MAC 0x0010 #define VTNET_FLAG_VLAN_FILTER 0x0020 #define VTNET_FLAG_TSO_ECN 0x0040 #define VTNET_FLAG_MRG_RXBUFS 0x0080 #define VTNET_FLAG_LRO_NOMRG 0x0100 #define VTNET_FLAG_MULTIQ 0x0200 #define VTNET_FLAG_INDIRECT 0x0400 #define VTNET_FLAG_EVENT_IDX 0x0800 int vtnet_link_active; int vtnet_hdr_size; int vtnet_rx_process_limit; int vtnet_rx_nsegs; int vtnet_rx_nmbufs; int vtnet_rx_clsize; int vtnet_rx_new_clsize; int vtnet_tx_intr_thresh; int vtnet_tx_nsegs; int vtnet_if_flags; int vtnet_act_vq_pairs; int vtnet_max_vq_pairs; int vtnet_requested_vq_pairs; struct virtqueue *vtnet_ctrl_vq; struct vtnet_mac_filter *vtnet_mac_filter; uint32_t *vtnet_vlan_filter; uint64_t vtnet_features; struct vtnet_statistics vtnet_stats; struct callout vtnet_tick_ch; struct ifmedia vtnet_media; eventhandler_tag vtnet_vlan_attach; eventhandler_tag vtnet_vlan_detach; struct mtx vtnet_mtx; char vtnet_mtx_name[16]; char vtnet_hwaddr[ETHER_ADDR_LEN]; }; /* * Maximum number of queue pairs we will autoconfigure to. */ #define VTNET_MAX_QUEUE_PAIRS 8 /* * Additional completed entries can appear in a virtqueue before we can * reenable interrupts. Number of times to retry before scheduling the * taskqueue to process the completed entries. */ #define VTNET_INTR_DISABLE_RETRIES 4 /* * Similarly, additional completed entries can appear in a virtqueue * between when lasted checked and before notifying the host. Number * of times to retry before scheduling the taskqueue to process the * queue. */ #define VTNET_NOTIFY_RETRIES 4 /* * Fake the media type. The host does not provide us with any real media * information. */ #define VTNET_MEDIATYPE (IFM_ETHER | IFM_10G_T | IFM_FDX) /* * Number of words to allocate for the VLAN shadow table. There is one * bit for each VLAN. */ #define VTNET_VLAN_FILTER_NWORDS (4096 / 32) /* * When mergeable buffers are not negotiated, the vtnet_rx_header structure * below is placed at the beginning of the mbuf data. Use 4 bytes of pad to * both keep the VirtIO header and the data non-contiguous and to keep the * frame's payload 4 byte aligned. * * When mergeable buffers are negotiated, the host puts the VirtIO header in * the beginning of the first mbuf's data. */ #define VTNET_RX_HEADER_PAD 4 struct vtnet_rx_header { struct virtio_net_hdr vrh_hdr; char vrh_pad[VTNET_RX_HEADER_PAD]; } __packed; /* * For each outgoing frame, the vtnet_tx_header below is allocated from * the vtnet_tx_header_zone. */ struct vtnet_tx_header { union { struct virtio_net_hdr hdr; struct virtio_net_hdr_mrg_rxbuf mhdr; } vth_uhdr; struct mbuf *vth_mbuf; }; /* * The VirtIO specification does not place a limit on the number of MAC * addresses the guest driver may request to be filtered. In practice, * the host is constrained by available resources. To simplify this driver, * impose a reasonably high limit of MAC addresses we will filter before * falling back to promiscuous or all-multicast modes. */ #define VTNET_MAX_MAC_ENTRIES 128 struct vtnet_mac_table { uint32_t nentries; uint8_t macs[VTNET_MAX_MAC_ENTRIES][ETHER_ADDR_LEN]; } __packed; struct vtnet_mac_filter { struct vtnet_mac_table vmf_unicast; uint32_t vmf_pad; /* Make tables non-contiguous. */ struct vtnet_mac_table vmf_multicast; }; /* * The MAC filter table is malloc(9)'d when needed. Ensure it will * always fit in one segment. */ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE); #define VTNET_TX_TIMEOUT 5 #define VTNET_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP) #define VTNET_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6) #define VTNET_CSUM_ALL_OFFLOAD \ (VTNET_CSUM_OFFLOAD | VTNET_CSUM_OFFLOAD_IPV6 | CSUM_TSO) /* Features desired/implemented by this driver. */ #define VTNET_FEATURES \ (VIRTIO_NET_F_MAC | \ VIRTIO_NET_F_STATUS | \ VIRTIO_NET_F_CTRL_VQ | \ VIRTIO_NET_F_CTRL_RX | \ VIRTIO_NET_F_CTRL_MAC_ADDR | \ VIRTIO_NET_F_CTRL_VLAN | \ VIRTIO_NET_F_CSUM | \ VIRTIO_NET_F_GSO | \ VIRTIO_NET_F_HOST_TSO4 | \ VIRTIO_NET_F_HOST_TSO6 | \ VIRTIO_NET_F_HOST_ECN | \ VIRTIO_NET_F_GUEST_CSUM | \ VIRTIO_NET_F_GUEST_TSO4 | \ VIRTIO_NET_F_GUEST_TSO6 | \ VIRTIO_NET_F_GUEST_ECN | \ VIRTIO_NET_F_MRG_RXBUF | \ VIRTIO_NET_F_MQ | \ VIRTIO_RING_F_EVENT_IDX | \ VIRTIO_RING_F_INDIRECT_DESC) /* * The VIRTIO_NET_F_HOST_TSO[46] features permit us to send the host * frames larger than 1514 bytes. */ #define VTNET_TSO_FEATURES (VIRTIO_NET_F_GSO | VIRTIO_NET_F_HOST_TSO4 | \ VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_ECN) /* * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us * frames larger than 1514 bytes. We do not yet support software LRO * via tcp_lro_rx(). */ #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \ VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN) #define VTNET_MAX_MTU 65536 #define VTNET_MAX_RX_SIZE 65550 /* * Used to preallocate the Vq indirect descriptors. The first segment * is reserved for the header, except for mergeable buffers since the * header is placed inline with the data. */ #define VTNET_MRG_RX_SEGS 1 #define VTNET_MIN_RX_SEGS 2 #define VTNET_MAX_RX_SEGS 34 #define VTNET_MIN_TX_SEGS 32 #define VTNET_MAX_TX_SEGS 64 /* * Assert we can receive and transmit the maximum with regular * size clusters. */ CTASSERT(((VTNET_MAX_RX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_RX_SIZE); CTASSERT(((VTNET_MAX_TX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_MTU); /* * Number of slots in the Tx bufrings. This value matches most other * multiqueue drivers. */ #define VTNET_DEFAULT_BUFRING_SIZE 4096 /* * Determine how many mbufs are in each receive buffer. For LRO without * mergeable buffers, we must allocate an mbuf chain large enough to * hold both the vtnet_rx_header and the maximum receivable data. */ #define VTNET_NEEDED_RX_MBUFS(_sc, _clsize) \ ((_sc)->vtnet_flags & VTNET_FLAG_LRO_NOMRG) == 0 ? 1 : \ howmany(sizeof(struct vtnet_rx_header) + VTNET_MAX_RX_SIZE, \ (_clsize)) #define VTNET_CORE_MTX(_sc) &(_sc)->vtnet_mtx #define VTNET_CORE_LOCK(_sc) mtx_lock(VTNET_CORE_MTX((_sc))) #define VTNET_CORE_UNLOCK(_sc) mtx_unlock(VTNET_CORE_MTX((_sc))) #define VTNET_CORE_LOCK_DESTROY(_sc) mtx_destroy(VTNET_CORE_MTX((_sc))) #define VTNET_CORE_LOCK_ASSERT(_sc) \ mtx_assert(VTNET_CORE_MTX((_sc)), MA_OWNED) #define VTNET_CORE_LOCK_ASSERT_NOTOWNED(_sc) \ mtx_assert(VTNET_CORE_MTX((_sc)), MA_NOTOWNED) #define VTNET_CORE_LOCK_INIT(_sc) do { \ snprintf((_sc)->vtnet_mtx_name, sizeof((_sc)->vtnet_mtx_name), \ "%s", device_get_nameunit((_sc)->vtnet_dev)); \ mtx_init(VTNET_CORE_MTX((_sc)), (_sc)->vtnet_mtx_name, \ "VTNET Core Lock", MTX_DEF); \ } while (0) #endif /* _IF_VTNETVAR_H */ Index: stable/12 =================================================================== --- stable/12 (revision 362023) +++ stable/12 (revision 362024) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r361758