From owner-svn-src-all@freebsd.org Mon Jun 8 21:51:37 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CB84033C70A; Mon, 8 Jun 2020 21:51:37 +0000 (UTC) (envelope-from jrtc27@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49gn5P53k5z4dkw; Mon, 8 Jun 2020 21:51:37 +0000 (UTC) (envelope-from jrtc27@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A8FB8B50E; Mon, 8 Jun 2020 21:51:37 +0000 (UTC) (envelope-from jrtc27@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 058LpbJl003005; Mon, 8 Jun 2020 21:51:37 GMT (envelope-from jrtc27@FreeBSD.org) Received: (from jrtc27@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 058LpabU003001; Mon, 8 Jun 2020 21:51:36 GMT (envelope-from jrtc27@FreeBSD.org) Message-Id: <202006082151.058LpabU003001@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jrtc27 set sender to jrtc27@FreeBSD.org using -f From: Jessica Clarke Date: Mon, 8 Jun 2020 21:51:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361944 - in head/sys/dev/virtio: . network X-SVN-Group: head X-SVN-Commit-Author: jrtc27 X-SVN-Commit-Paths: in head/sys/dev/virtio: . network X-SVN-Commit-Revision: 361944 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2020 21:51:37 -0000 Author: jrtc27 Date: Mon Jun 8 21:51:36 2020 New Revision: 361944 URL: https://svnweb.freebsd.org/changeset/base/361944 Log: virtio: Support non-legacy network device and queue The non-legacy interface always defines num_buffers in the header, regardless of whether VIRTIO_NET_F_MRG_RXBUF, just leaving it unused. We also need to ensure our virtqueue doesn't filter out VIRTIO_F_VERSION_1 during negotiation, as it supports non-legacy transports just fine. This fixes network packet transmission on TinyEMU. Reviewed by: br, brooks (mentor), jhb (mentor) Approved by: br, brooks (mentor), jhb (mentor) Differential Revision: https://reviews.freebsd.org/D25132 Modified: head/sys/dev/virtio/network/if_vtnet.c head/sys/dev/virtio/network/if_vtnetvar.h head/sys/dev/virtio/virtio.c head/sys/dev/virtio/virtqueue.c Modified: head/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- head/sys/dev/virtio/network/if_vtnet.c Mon Jun 8 21:49:42 2020 (r361943) +++ head/sys/dev/virtio/network/if_vtnet.c Mon Jun 8 21:51:36 2020 (r361944) @@ -640,10 +640,13 @@ vtnet_setup_features(struct vtnet_softc *sc) sc->vtnet_flags |= VTNET_FLAG_MAC; } - if (virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF)) { + if (virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF)) sc->vtnet_flags |= VTNET_FLAG_MRG_RXBUFS; + + if (virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF) || + virtio_with_feature(dev, VIRTIO_F_VERSION_1)) sc->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf); - } else + else sc->vtnet_hdr_size = sizeof(struct virtio_net_hdr); if (sc->vtnet_flags & VTNET_FLAG_MRG_RXBUFS) @@ -1459,9 +1462,10 @@ vtnet_rxq_enqueue_buf(struct vtnet_rxq *rxq, struct mb sglist_reset(sg); if ((sc->vtnet_flags & VTNET_FLAG_MRG_RXBUFS) == 0) { - MPASS(sc->vtnet_hdr_size == sizeof(struct virtio_net_hdr)); + MPASS(sc->vtnet_hdr_size == sizeof(rxhdr->vrh_uhdr.hdr) || + sc->vtnet_hdr_size == sizeof(rxhdr->vrh_uhdr.mhdr)); rxhdr = (struct vtnet_rx_header *) mdata; - sglist_append(sg, &rxhdr->vrh_hdr, sc->vtnet_hdr_size); + sglist_append(sg, &rxhdr->vrh_uhdr, sc->vtnet_hdr_size); offset = sizeof(struct vtnet_rx_header); } else offset = 0; Modified: head/sys/dev/virtio/network/if_vtnetvar.h ============================================================================== --- head/sys/dev/virtio/network/if_vtnetvar.h Mon Jun 8 21:49:42 2020 (r361943) +++ head/sys/dev/virtio/network/if_vtnetvar.h Mon Jun 8 21:51:36 2020 (r361944) @@ -219,15 +219,20 @@ struct vtnet_softc { * 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. + * frame's payload 4 byte aligned. Note that non-legacy drivers still want + * room for a full mergeable buffer header. * * 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]; + union { + struct virtio_net_hdr hdr; + struct virtio_net_hdr_mrg_rxbuf mhdr; + } vrh_uhdr; + + char vrh_pad[VTNET_RX_HEADER_PAD]; } __packed; /* @@ -296,7 +301,8 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE) VIRTIO_NET_F_MRG_RXBUF | \ VIRTIO_NET_F_MQ | \ VIRTIO_RING_F_EVENT_IDX | \ - VIRTIO_RING_F_INDIRECT_DESC) + VIRTIO_RING_F_INDIRECT_DESC | \ + VIRTIO_F_VERSION_1) /* * The VIRTIO_NET_F_HOST_TSO[46] features permit us to send the host Modified: head/sys/dev/virtio/virtio.c ============================================================================== --- head/sys/dev/virtio/virtio.c Mon Jun 8 21:49:42 2020 (r361943) +++ head/sys/dev/virtio/virtio.c Mon Jun 8 21:51:36 2020 (r361944) @@ -79,6 +79,7 @@ static struct virtio_feature_desc virtio_common_featur { VIRTIO_RING_F_INDIRECT_DESC, "RingIndirect" }, { VIRTIO_RING_F_EVENT_IDX, "EventIdx" }, { VIRTIO_F_BAD_FEATURE, "BadFeature" }, + { VIRTIO_F_VERSION_1, "Version1" }, { 0, NULL } }; Modified: head/sys/dev/virtio/virtqueue.c ============================================================================== --- head/sys/dev/virtio/virtqueue.c Mon Jun 8 21:49:42 2020 (r361943) +++ head/sys/dev/virtio/virtqueue.c Mon Jun 8 21:51:36 2020 (r361944) @@ -142,6 +142,7 @@ virtqueue_filter_features(uint64_t features) mask = (1 << VIRTIO_TRANSPORT_F_START) - 1; mask |= VIRTIO_RING_F_INDIRECT_DESC; mask |= VIRTIO_RING_F_EVENT_IDX; + mask |= VIRTIO_F_VERSION_1; return (features & mask); }