1/*- 2 * Copyright (c) 2011, Bryan Venteicher <bryanv@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27/* Driver for VirtIO network devices. */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: stable/10/sys/dev/virtio/network/if_vtnet.c 268010 2014-06-29 00:37:59Z bryanv $"); |
31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/sockio.h> 36#include <sys/mbuf.h> 37#include <sys/malloc.h> 38#include <sys/module.h> --- 506 unchanged lines hidden (view full) --- 545 if (vtnet_tunable_int(sc, "csum_disable", vtnet_csum_disable)) { 546 mask |= VIRTIO_NET_F_CSUM | VIRTIO_NET_F_GUEST_CSUM; 547 mask |= VTNET_TSO_FEATURES | VTNET_LRO_FEATURES; 548 } 549 if (vtnet_tunable_int(sc, "tso_disable", vtnet_tso_disable)) 550 mask |= VTNET_TSO_FEATURES; 551 if (vtnet_tunable_int(sc, "lro_disable", vtnet_lro_disable)) 552 mask |= VTNET_LRO_FEATURES; |
553#ifndef VTNET_LEGACY_TX |
554 if (vtnet_tunable_int(sc, "mq_disable", vtnet_mq_disable)) 555 mask |= VIRTIO_NET_F_MQ; |
556#else |
557 mask |= VIRTIO_NET_F_MQ; 558#endif 559 560 features = VTNET_FEATURES & ~mask; 561 sc->vtnet_features = virtio_negotiate_features(dev, features); 562 |
563 if (virtio_with_feature(dev, VTNET_LRO_FEATURES) && 564 virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF) == 0) { 565 /* 566 * LRO without mergeable buffers requires special care. This 567 * is not ideal because every receive buffer must be large 568 * enough to hold the maximum TCP packet, the Ethernet header, 569 * and the header. This requires up to 34 descriptors with 570 * MCLBYTES clusters. If we do not have indirect descriptors, 571 * LRO is disabled since the virtqueue will not contain very 572 * many receive buffers. 573 */ 574 if (!virtio_with_feature(dev, VIRTIO_RING_F_INDIRECT_DESC)) { 575 device_printf(dev, 576 "LRO disabled due to both mergeable buffers and " 577 "indirect descriptors not negotiated\n"); |
578 |
579 features &= ~VTNET_LRO_FEATURES; 580 sc->vtnet_features = 581 virtio_negotiate_features(dev, features); 582 } else 583 sc->vtnet_flags |= VTNET_FLAG_LRO_NOMRG; 584 } |
585} 586 587static void 588vtnet_setup_features(struct vtnet_softc *sc) 589{ 590 device_t dev; 591 int max_pairs, max; 592 --- 1514 unchanged lines hidden (view full) --- 2107 *m_head = NULL; 2108 2109 return (ENOBUFS); 2110} 2111 2112static int 2113vtnet_txq_encap(struct vtnet_txq *txq, struct mbuf **m_head) 2114{ |
2115 struct vtnet_tx_header *txhdr; 2116 struct virtio_net_hdr *hdr; 2117 struct mbuf *m; 2118 int error; 2119 |
2120 m = *m_head; 2121 M_ASSERTPKTHDR(m); 2122 2123 txhdr = uma_zalloc(vtnet_tx_header_zone, M_NOWAIT | M_ZERO); 2124 if (txhdr == NULL) { 2125 m_freem(m); 2126 *m_head = NULL; 2127 return (ENOMEM); --- 810 unchanged lines hidden (view full) --- 2938 } 2939 2940 sc->vtnet_act_vq_pairs = npairs; 2941} 2942 2943static int 2944vtnet_reinit(struct vtnet_softc *sc) 2945{ |
2946 struct ifnet *ifp; 2947 int error; 2948 |
2949 ifp = sc->vtnet_ifp; 2950 2951 /* Use the current MAC address. */ 2952 bcopy(IF_LLADDR(ifp), sc->vtnet_hwaddr, ETHER_ADDR_LEN); 2953 vtnet_set_hwaddr(sc); 2954 2955 vtnet_set_active_vq_pairs(sc); 2956 --- 104 unchanged lines hidden (view full) --- 3061 */ 3062 virtqueue_notify(vq); 3063 virtqueue_poll(vq, NULL); 3064} 3065 3066static int 3067vtnet_ctrl_mac_cmd(struct vtnet_softc *sc, uint8_t *hwaddr) 3068{ |
3069 struct virtio_net_ctrl_hdr hdr __aligned(2); |
3070 struct sglist_seg segs[3]; 3071 struct sglist sg; 3072 uint8_t ack; 3073 int error; 3074 3075 hdr.class = VIRTIO_NET_CTRL_MAC; 3076 hdr.cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET; 3077 ack = VIRTIO_NET_ERR; --- 17 unchanged lines hidden (view full) --- 3095 struct sglist_seg segs[3]; 3096 struct sglist sg; 3097 struct { 3098 struct virtio_net_ctrl_hdr hdr; 3099 uint8_t pad1; 3100 struct virtio_net_ctrl_mq mq; 3101 uint8_t pad2; 3102 uint8_t ack; |
3103 } s __aligned(2); |
3104 int error; 3105 3106 s.hdr.class = VIRTIO_NET_CTRL_MQ; 3107 s.hdr.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET; 3108 s.mq.virtqueue_pairs = npairs; 3109 s.ack = VIRTIO_NET_ERR; 3110 3111 sglist_init(&sg, 3, segs); --- 15 unchanged lines hidden (view full) --- 3127 struct sglist_seg segs[3]; 3128 struct sglist sg; 3129 struct { 3130 struct virtio_net_ctrl_hdr hdr; 3131 uint8_t pad1; 3132 uint8_t onoff; 3133 uint8_t pad2; 3134 uint8_t ack; |
3135 } s __aligned(2); |
3136 int error; 3137 3138 KASSERT(sc->vtnet_flags & VTNET_FLAG_CTRL_RX, 3139 ("%s: CTRL_RX feature not negotiated", __func__)); 3140 3141 s.hdr.class = VIRTIO_NET_CTRL_RX; 3142 s.hdr.cmd = cmd; 3143 s.onoff = !!on; --- 66 unchanged lines hidden (view full) --- 3210 if (vtnet_set_allmulti(sc, ifp->if_flags & IFF_ALLMULTI) != 0) 3211 device_printf(dev, "cannot %s all-multicast mode\n", 3212 ifp->if_flags & IFF_ALLMULTI ? "enable" : "disable"); 3213} 3214 3215static void 3216vtnet_rx_filter_mac(struct vtnet_softc *sc) 3217{ |
3218 struct virtio_net_ctrl_hdr hdr __aligned(2); |
3219 struct vtnet_mac_filter *filter; 3220 struct sglist_seg segs[4]; 3221 struct sglist sg; 3222 struct ifnet *ifp; 3223 struct ifaddr *ifa; 3224 struct ifmultiaddr *ifma; 3225 int ucnt, mcnt, promisc, allmulti, error; 3226 uint8_t ack; --- 96 unchanged lines hidden (view full) --- 3323 struct sglist_seg segs[3]; 3324 struct sglist sg; 3325 struct { 3326 struct virtio_net_ctrl_hdr hdr; 3327 uint8_t pad1; 3328 uint16_t tag; 3329 uint8_t pad2; 3330 uint8_t ack; |
3331 } s __aligned(2); |
3332 int error; 3333 3334 s.hdr.class = VIRTIO_NET_CTRL_VLAN; 3335 s.hdr.cmd = add ? VIRTIO_NET_CTRL_VLAN_ADD : VIRTIO_NET_CTRL_VLAN_DEL; 3336 s.tag = tag; 3337 s.ack = VIRTIO_NET_ERR; 3338 3339 sglist_init(&sg, 3, segs); --- 495 unchanged lines hidden --- |