From patchwork Thu Jun 30 08:41:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 932342 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5U8jNml014463 for ; Thu, 30 Jun 2011 08:45:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758252Ab1F3IpV (ORCPT ); Thu, 30 Jun 2011 04:45:21 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:59621 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757363Ab1F3IpU (ORCPT ); Thu, 30 Jun 2011 04:45:20 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so1722525iyb.19 for ; Thu, 30 Jun 2011 01:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=k6j8lft8wkXZJED8tlU4O29yZ4WRd9g5bcExi1mKH/E=; b=xXVKIdfhvsDrgyazAAAgfbuvncXTZJm6I3rpJt9bIqtzt0IMU6ZxwdLGG/DL/U4my9 N/WWddj9XTq7c1ZKtrhJlnHYnZzitPFDPdd+Fkdj2NpW2DpNumTQfbEx5CwswAI+0e7z +eCpNjGGmwyDJ2jdIHylRZwgxb9bdoYPO3SJs= Received: by 10.42.97.70 with SMTP id m6mr1849269icn.45.1309423519711; Thu, 30 Jun 2011 01:45:19 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id d6sm1967338icx.1.2011.06.30.01.45.15 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Jun 2011 01:45:19 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH v2 21/31] kvm tools: Introduce uip_init() for uip Date: Thu, 30 Jun 2011 16:41:09 +0800 Message-Id: <1309423279-3093-22-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> References: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 30 Jun 2011 08:45:24 +0000 (UTC) - Initialize TCP/UDP socket list, ethernet buffer list. - Allocate memory for ethernet buffer. Signed-off-by: Asias He --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 2 + tools/kvm/uip/core.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/uip/core.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index c088718..733769d 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -45,6 +45,7 @@ OBJS += disk/qcow.o OBJS += disk/raw.o OBJS += ioeventfd.o OBJS += irq.o +OBJS += uip/core.o OBJS += uip/arp.o OBJS += uip/icmp.o OBJS += uip/ipv4.o diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 893c5f8..c300de0 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -267,6 +267,8 @@ static inline u16 uip_eth_hdrlen(struct uip_eth *eth) return sizeof(*eth); } +int uip_init(struct uip_info *info); + int uip_tx_do_ipv4_icmp(struct uip_tx_arg *arg); int uip_tx_do_ipv4_tcp(struct uip_tx_arg *arg); int uip_tx_do_ipv4_udp(struct uip_tx_arg *arg); diff --git a/tools/kvm/uip/core.c b/tools/kvm/uip/core.c new file mode 100644 index 0000000..58eba6b --- /dev/null +++ b/tools/kvm/uip/core.c @@ -0,0 +1,58 @@ +#include "kvm/mutex.h" +#include "kvm/uip.h" + +#include +#include +#include + +int uip_init(struct uip_info *info) +{ + struct list_head *udp_socket_head; + struct list_head *tcp_socket_head; + struct list_head *buf_head; + struct uip_buf *buf; + int buf_nr; + int i; + + udp_socket_head = &info->udp_socket_head; + tcp_socket_head = &info->tcp_socket_head; + buf_head = &info->buf_head; + buf_nr = info->buf_nr; + + INIT_LIST_HEAD(udp_socket_head); + INIT_LIST_HEAD(tcp_socket_head); + INIT_LIST_HEAD(buf_head); + + pthread_mutex_init(&info->udp_socket_lock, NULL); + pthread_mutex_init(&info->tcp_socket_lock, NULL); + pthread_mutex_init(&info->buf_lock, NULL); + + pthread_cond_init(&info->buf_used_cond, NULL); + pthread_cond_init(&info->buf_free_cond, NULL); + + + for (i = 0; i < buf_nr; i++) { + buf = malloc(sizeof(*buf)); + memset(buf, 0, sizeof(*buf)); + + buf->status = UIP_BUF_STATUS_FREE; + buf->info = info; + buf->id = i; + list_add_tail(&buf->list, buf_head); + } + + list_for_each_entry(buf, buf_head, list) { + buf->vnet = malloc(sizeof(struct virtio_net_hdr)); + buf->vnet_len = sizeof(struct virtio_net_hdr); + buf->eth = malloc(1024*64 + sizeof(struct uip_pseudo_hdr)); + buf->eth_len = 1024*64 + sizeof(struct uip_pseudo_hdr); + + memset(buf->vnet, 0, buf->vnet_len); + memset(buf->eth, 0, buf->eth_len); + } + + info->buf_free_nr = buf_nr; + info->buf_used_nr = 0; + + return 0; +}