From patchwork Tue Apr 9 00:37:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 2412481 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2EF67DFB78 for ; Tue, 9 Apr 2013 00:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936610Ab3DIAiM (ORCPT ); Mon, 8 Apr 2013 20:38:12 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:28260 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936310Ab3DIAiK (ORCPT ); Mon, 8 Apr 2013 20:38:10 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r390c1hx024975 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 9 Apr 2013 00:38:02 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r390c075014224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 9 Apr 2013 00:38:01 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r390c0vS008668; Tue, 9 Apr 2013 00:38:00 GMT Received: from lappy.hsd1.ma.comcast.net. (/50.133.228.71) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 08 Apr 2013 17:38:00 -0700 From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, kvm@vger.kernel.org, mst@redhat.com, rusty@rustcorp.com.au, Sasha Levin Subject: [PATCH 2/3] kvm-tools: support virtio-net ctrl queue Date: Mon, 8 Apr 2013 20:37:36 -0400 Message-Id: <1365467857-15928-2-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1365467857-15928-1-git-send-email-sasha.levin@oracle.com> References: <1365467857-15928-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We don't need much out of it at this point, but we will need it for virtio-net mq patch. Signed-off-by: Sasha Levin --- tools/kvm/virtio/net.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 68bd107..253d167 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -27,9 +27,10 @@ #include #define VIRTIO_NET_QUEUE_SIZE 256 -#define VIRTIO_NET_NUM_QUEUES 2 +#define VIRTIO_NET_NUM_QUEUES 3 #define VIRTIO_NET_RX_QUEUE 0 #define VIRTIO_NET_TX_QUEUE 1 +#define VIRTIO_NET_CTRL_QUEUE 2 struct net_dev; @@ -144,6 +145,31 @@ static void *virtio_net_tx_thread(void *p) } +static void virtio_net_handle_ctrl(struct kvm *kvm, struct net_dev *ndev) +{ + struct iovec iov[VIRTIO_NET_QUEUE_SIZE]; + u16 out, in, head; + struct virtio_net_ctrl_hdr *ctrl; + virtio_net_ctrl_ack *ack; + + head = virt_queue__get_iov(&ndev->vqs[VIRTIO_NET_CTRL_QUEUE], iov, &out, &in, kvm); + ctrl = iov[0].iov_base; + ack = iov[out].iov_base; + + switch (ctrl->class) { + default: + *ack = VIRTIO_NET_ERR; + break; + } + + virt_queue__set_used_elem(&ndev->vqs[VIRTIO_NET_CTRL_QUEUE], head, iov[out].iov_len); + + if (virtio_queue__should_signal(&ndev->vqs[VIRTIO_NET_CTRL_QUEUE])) + ndev->vdev.ops->signal_vq(kvm, &ndev->vdev, VIRTIO_NET_CTRL_QUEUE); + + return; +} + static void virtio_net_handle_callback(struct kvm *kvm, struct net_dev *ndev, int queue) { switch (queue) { @@ -157,6 +183,9 @@ static void virtio_net_handle_callback(struct kvm *kvm, struct net_dev *ndev, in pthread_cond_signal(&ndev->io_rx_cond); mutex_unlock(&ndev->io_rx_lock); break; + case VIRTIO_NET_CTRL_QUEUE: + virtio_net_handle_ctrl(kvm, ndev); + break; default: pr_warning("Unknown queue index %u", queue); } @@ -310,7 +339,8 @@ static u32 get_host_features(struct kvm *kvm, void *dev) | 1UL << VIRTIO_NET_F_GUEST_TSO4 | 1UL << VIRTIO_NET_F_GUEST_TSO6 | 1UL << VIRTIO_RING_F_EVENT_IDX - | 1UL << VIRTIO_RING_F_INDIRECT_DESC; + | 1UL << VIRTIO_RING_F_INDIRECT_DESC + | 1UL << VIRTIO_NET_F_CTRL_VQ; } static void set_guest_features(struct kvm *kvm, void *dev, u32 features)