From patchwork Mon Apr 25 02:10:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= X-Patchwork-Id: 92692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 15339B6EEC for ; Mon, 25 Apr 2011 12:10:57 +1000 (EST) Received: from localhost ([::1]:56538 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEBGH-0007nf-PD for incoming@patchwork.ozlabs.org; Sun, 24 Apr 2011 22:10:53 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEBGA-0007na-Pf for qemu-devel@nongnu.org; Sun, 24 Apr 2011 22:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QEBG9-00019B-PZ for qemu-devel@nongnu.org; Sun, 24 Apr 2011 22:10:46 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:61265) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEBG9-000195-JQ for qemu-devel@nongnu.org; Sun, 24 Apr 2011 22:10:45 -0400 Received: by pxi15 with SMTP id 15so1580309pxi.33 for ; Sun, 24 Apr 2011 19:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :mime-version:content-type:content-transfer-encoding; bh=h2wO4fX8Ti0SOxnAamims44WJMQXeEq7b5uDa1zjLMw=; b=KkoNOu5yC8TMkJPmZSgDRj2itkWkNIrRob6ZFg5Lx/6fOw7MxCh2L1qs0sSTTMMIVJ SvLqir6RdC2iam3lrFSiBT7GB/nKwPhznmGMxGzlZn6KwpSd3VuK1SPWdGE88mwpbO+l MAOer4z8j1iVgN/ZPktLa3kHvEi+fYfNECh88= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=gqFNAKfxvef3eEMPIkB4TjWgtxDvjiimA+cRB/XEkD+NW6uRpjcm37f5N963c7e84W sQQyvRX88vSOFsi8m7VLaWcWrc9AdOiCzLvYAtijOILYiOQact/XhsxJXaDBbDjza5mP fkKI11Tv2J2kXcmg/ECwQnLxtb/Sevsr1EehU= Received: by 10.68.66.162 with SMTP id g2mr5802970pbt.391.1303697444004; Sun, 24 Apr 2011 19:10:44 -0700 (PDT) Received: from pclouds@gmail.com ([118.69.34.31]) by mx.google.com with ESMTPS id n4sm1218858pbj.97.2011.04.24.19.10.40 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 24 Apr 2011 19:10:42 -0700 (PDT) Received: by pclouds@gmail.com (sSMTP sendmail emulation); Mon, 25 Apr 2011 09:10:37 +0700 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: qemu-devel@nongnu.org Date: Mon, 25 Apr 2011 09:10:35 +0700 Message-Id: <1303697435-12542-1-git-send-email-pclouds@gmail.com> X-Mailer: git-send-email 1.7.3.1.256.g2539c.dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.212.174 Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= , Mark McLoughlin , Anthony Liguori Subject: [Qemu-devel] [PATCH] net: add drop_packets parameter to -net nic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Dropping packets is sometimes perferred behavior. Add drop_packets parameter to NICConf struct and let nic simulation decide how to use it. Only e1000 supports this for now. Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation is missing, but I'm not even sure if there's any other user who finds this useful. hw/e1000.c | 4 +++- hw/qdev.c | 1 + net.c | 5 +++++ net.h | 9 +++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index fe3e812..57ffdec 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -656,7 +656,9 @@ e1000_can_receive(VLANClientState *nc) { E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; - return (s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1); + return (s->conf.flags & NIC_CONF_DROP_PACKETS) || + ((s->mac_reg[RCTL] & E1000_RCTL_EN) && + e1000_has_rxbufs(s, 1)); } static uint64_t rx_desc_base(E1000State *s) diff --git a/hw/qdev.c b/hw/qdev.c index 9519f5d..d8605d6 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -468,6 +468,7 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd) qdev_prop_exists(dev, "vectors")) { qdev_prop_set_uint32(dev, "vectors", nd->nvectors); } + qdev_prop_set_bit(dev, "drop_packets", nd->drop_packets); } BusState *qdev_get_child_bus(DeviceState *dev, const char *name) diff --git a/net.c b/net.c index 6746bc7..566be48 100644 --- a/net.c +++ b/net.c @@ -798,6 +798,7 @@ static int net_init_nic(QemuOpts *opts, return -1; } + nd->drop_packets = qemu_opt_get_bool(opts, "drop_packets", 0); nd->used = 1; nb_nics++; @@ -864,6 +865,10 @@ static const struct { .name = "vectors", .type = QEMU_OPT_NUMBER, .help = "number of MSI-x vectors, 0 to disable MSI-X", + }, { + .name = "drop_packets", + .type = QEMU_OPT_BOOL, + .help = "drop packets if driver is not ready to receive" }, { /* end of list */ } }, diff --git a/net.h b/net.h index 6ceca50..a594313 100644 --- a/net.h +++ b/net.h @@ -12,19 +12,23 @@ struct MACAddr { }; /* qdev nic properties */ +#define NIC_CONF_DROP_PACKETS_BIT 0 +#define NIC_CONF_DROP_PACKETS (1 << NIC_CONF_DROP_PACKETS_BIT) typedef struct NICConf { MACAddr macaddr; VLANState *vlan; VLANClientState *peer; int32_t bootindex; + uint32_t flags; } NICConf; #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peer), \ - DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) + DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ + DEFINE_PROP_BIT("drop_packets", _state, _conf.flags, NIC_CONF_DROP_PACKETS_BIT, 0) /* VLANs support */ @@ -133,8 +137,9 @@ struct NICInfo { char *devaddr; VLANState *vlan; VLANClientState *netdev; - int used; int nvectors; + unsigned int used : 1; + unsigned int drop_packets : 1; }; extern int nb_nics;