From patchwork Thu Oct 22 16:43:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA07EB7BAD for ; Fri, 23 Oct 2009 05:16:01 +1100 (EST) Received: from localhost ([127.0.0.1]:57022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N12Cc-0006xX-9h for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 14:15:58 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N11gk-0000CG-5R for qemu-devel@nongnu.org; Thu, 22 Oct 2009 13:43:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N11gS-0008Or-KJ for qemu-devel@nongnu.org; Thu, 22 Oct 2009 13:42:54 -0400 Received: from [199.232.76.173] (port=53801 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N11gR-0008Nl-7r for qemu-devel@nongnu.org; Thu, 22 Oct 2009 13:42:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21177) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N11gQ-0003kE-Cw for qemu-devel@nongnu.org; Thu, 22 Oct 2009 13:42:42 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGjiSO017104 for ; Thu, 22 Oct 2009 12:45:44 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGjhrb008055; Thu, 22 Oct 2009 12:45:44 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id BEF9F45B89; Thu, 22 Oct 2009 17:43:50 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2009 17:43:46 +0100 Message-Id: <1256229830-28066-16-git-send-email-markmc@redhat.com> In-Reply-To: <1256229830-28066-1-git-send-email-markmc@redhat.com> References: <1256229830-28066-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 15/19] net: add tap_set_offload() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This API allows virtio-net to enable various offload features on a tap interface - e.g. to tell the host kernel it can pass up partial checksums to userspace. Signed-off-by: Mark McLoughlin --- net.c | 24 ++++++++++++++++++++++++ net.h | 1 + tap-linux.h | 7 +++++++ 3 files changed, 32 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index b44495d..746a3d6 100644 --- a/net.c +++ b/net.c @@ -1287,6 +1287,9 @@ int tap_has_vnet_hdr(VLANClientState *vc) void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) { } +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +{ +} #else /* !defined(_WIN32) */ /* Maximum GSO packet size (64k) plus plenty of room for @@ -1524,6 +1527,27 @@ static int tap_probe_vnet_hdr(int fd) return ifr.ifr_flags & IFF_VNET_HDR; } +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +{ + TAPState *s = vc->opaque; + unsigned int offload = 0; + + if (csum) { + offload |= TUN_F_CSUM; + if (tso4) + offload |= TUN_F_TSO4; + if (tso6) + offload |= TUN_F_TSO6; + if ((tso4 || tso6) && ecn) + offload |= TUN_F_TSO_ECN; + } + + if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) { + fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n", + strerror(errno)); + } +} + static void tap_cleanup(VLANClientState *vc) { TAPState *s = vc->opaque; diff --git a/net.h b/net.h index 6255e2b..a0f0359 100644 --- a/net.h +++ b/net.h @@ -170,5 +170,6 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, int tap_has_vnet_hdr(VLANClientState *vc); void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn); #endif diff --git a/tap-linux.h b/tap-linux.h index 8e75348..241cf83 100644 --- a/tap-linux.h +++ b/tap-linux.h @@ -22,6 +22,7 @@ /* Ioctl defines */ #define TUNSETIFF _IOW('T', 202, int) #define TUNGETFEATURES _IOR('T', 207, unsigned int) +#define TUNSETOFFLOAD _IOW('T', 208, unsigned int) #define TUNGETIFF _IOR('T', 210, unsigned int) #define TUNSETSNDBUF _IOW('T', 212, int) @@ -30,6 +31,12 @@ #define IFF_NO_PI 0x1000 #define IFF_VNET_HDR 0x4000 +/* Features for GSO (TUNSETOFFLOAD). */ +#define TUN_F_CSUM 0x01 /* You can hand me unchecksummed packets. */ +#define TUN_F_TSO4 0x02 /* I can handle TSO for IPv4 packets */ +#define TUN_F_TSO6 0x04 /* I can handle TSO for IPv6 packets */ +#define TUN_F_TSO_ECN 0x08 /* I can handle TSO with ECN bits. */ + struct virtio_net_hdr { uint8_t flags;