From patchwork Wed Oct 28 15:31:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 537428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3EE57140323 for ; Thu, 29 Oct 2015 02:38:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ravellosystems_com.20150623.gappssmtp.com header.i=@ravellosystems_com.20150623.gappssmtp.com header.b=WIY1orw2; dkim-atps=neutral Received: from localhost ([::1]:38860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSoO-0000lY-1Q for incoming@patchwork.ozlabs.org; Wed, 28 Oct 2015 11:38:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSiR-0007Bf-5z for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrSiM-0003ZQ-JY for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:43 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:38654) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSiM-0003ZK-BS for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:32:38 -0400 Received: by wicll6 with SMTP id ll6so17131843wic.1 for ; Wed, 28 Oct 2015 08:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ravellosystems_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7P5+tDx+6bFMx0jvTfwFjeVVuPXn5p1lzsx5VvCsUAI=; b=WIY1orw2jyrohx/800iie3T7ftu2xKJK8akEVPBB3slIXp2DKQfeG7afChrRhjubaK WV6ibFe9gDQOO3/1oShoxRnlNGZlbgAuOd6Y0aa6lgtzJL+3kIUNNbM5DIEeExw6QkCt KkLCV/sL+rjbfbFAxCEPjtHMxbOvmetmXxJMzlb5ERxcKy3AfPtI7kgaiYS3MGuKSsN9 poDQnBIyvaluVtldAHYapl3XMcYGKsGQ/u3rnJFj8uZEY5ZB4ui1gC9b3qeHyQbfKZ5t 9UMp/djraIENpbce7XZhke2otHJYaNg+Ey7ocMClLlxpINz9qfRxjT4kyN5iddaSgJQe +h5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7P5+tDx+6bFMx0jvTfwFjeVVuPXn5p1lzsx5VvCsUAI=; b=OEzKblWEg/VakW9IrozPSL1uvchUJPpZboV9P+VRa40tWiCqcTPF73yxIgDVnQlR1S eovw0mB5/57l0y8EHkC7BtJbdT9fYVQyiz3KClg+ZQAz9zMAhdcD7xu0wTS0h/hm8dR3 rlnKKPifHc1Twrv0EQuETjuj1CFX+f9l5tS5E2YqzPV2yR4rJq4kyUrMtTKuuW2radbw lxMTdd92j2ZeAThYT8P9QJ55PqHPqF5lVi30pi+w2dE4dCP8wBxC8x4lx2YHHLoIc8n4 kZslhfg+3H3OUEkuHNSEM19Twa/68ZCyVYvCUz2TcLnzYlEKdNvudFqaV1mN0d9g6eOO toPA== X-Gm-Message-State: ALoCoQmzR60yTduiWAinSYZvxWQb9ubOtGL2kfym19XKuEIS2DtJIzxes+/SKfu4gYjIrKjAEIwD X-Received: by 10.194.78.135 with SMTP id b7mr32539870wjx.67.1446046357929; Wed, 28 Oct 2015 08:32:37 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id he3sm50495704wjc.48.2015.10.28.08.32.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Oct 2015 08:32:36 -0700 (PDT) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Wed, 28 Oct 2015 17:31:28 +0200 Message-Id: <1446046288-25650-7-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1446046288-25650-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1446046288-25650-1-git-send-email-leonid.bloch@ravellosystems.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::235 Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani Subject: [Qemu-devel] [PATCH v3 6/6] e1000: Implementing various counters 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 This implements the following Statistic registers (various counters) according to Intel's specs: TSCTC GOTCL GOTCH GORCL GORCH MPRC BPRC RUC ROC BPTC MPTC PTC... PRC... Signed-off-by: Leonid Bloch Signed-off-by: Dmitry Fleytman --- hw/net/e1000.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 5 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 2f83a9e..c24cd24 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -37,6 +37,8 @@ #include "e1000_regs.h" +static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + #define E1000_DEBUG #ifdef E1000_DEBUG @@ -178,7 +180,13 @@ enum { defreg(DC), defreg(TNCRS), defreg(SEC), defreg(CEXTERR), defreg(RLEC), defreg(XONRXC), defreg(XONTXC), defreg(XOFFRXC), defreg(XOFFTXC), defreg(RFC), defreg(RJC), defreg(RNBC), - defreg(TSCTFC), defreg(MGTPRC), defreg(MGTPDC), defreg(MGTPTC) + defreg(TSCTFC), defreg(MGTPRC), defreg(MGTPDC), defreg(MGTPTC), + defreg(RUC), defreg(ROC), defreg(GORCL), defreg(GORCH), + defreg(GOTCL), defreg(GOTCH), defreg(BPRC), defreg(MPRC), + defreg(TSCTC), defreg(PRC64), defreg(PRC127), defreg(PRC255), + defreg(PRC511), defreg(PRC1023), defreg(PRC1522), defreg(PTC64), + defreg(PTC127), defreg(PTC255), defreg(PTC511), defreg(PTC1023), + defreg(PTC1522), defreg(MPTC), defreg(BPTC) }; static void @@ -583,6 +591,16 @@ inc_reg_if_not_full(E1000State *s, int index) } } +static inline void +inc_tx_bcast_or_mcast_count(E1000State *s, const unsigned char *arr) +{ + if (!memcmp(arr, bcast, sizeof bcast)) { + inc_reg_if_not_full(s, BPTC); + } else if (arr[0] & 1) { + inc_reg_if_not_full(s, MPTC); + } +} + static void grow_8reg_if_not_full(E1000State *s, int index, int size) { @@ -597,6 +615,24 @@ grow_8reg_if_not_full(E1000State *s, int index, int size) s->mac_reg[index+1] = sum >> 32; } +static void +increase_size_stats(E1000State *s, const int *size_regs, int size) +{ + if (size > 1023) { + inc_reg_if_not_full(s, size_regs[5]); + } else if (size > 511) { + inc_reg_if_not_full(s, size_regs[4]); + } else if (size > 255) { + inc_reg_if_not_full(s, size_regs[3]); + } else if (size > 127) { + inc_reg_if_not_full(s, size_regs[2]); + } else if (size > 64) { + inc_reg_if_not_full(s, size_regs[1]); + } else if (size == 64) { + inc_reg_if_not_full(s, size_regs[0]); + } +} + static inline int vlan_enabled(E1000State *s) { @@ -634,12 +670,17 @@ fcs_len(E1000State *s) static void e1000_send_packet(E1000State *s, const uint8_t *buf, int size) { + static const int PTCregs[6] = { PTC64, PTC127, PTC255, PTC511, + PTC1023, PTC1522 }; + NetClientState *nc = qemu_get_queue(s->nic); if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) { nc->info->receive(nc, buf, size); } else { qemu_send_packet(nc, buf, size); } + inc_tx_bcast_or_mcast_count(s, buf); + increase_size_stats(s, PTCregs, size); } static void @@ -665,8 +706,11 @@ xmit_seg(E1000State *s) if (tp->tcp) { sofar = frames * tp->mss; stl_be_p(tp->data+css+4, ldl_be_p(tp->data+css+4)+sofar); /* seq */ - if (tp->paylen - sofar > tp->mss) + if (tp->paylen - sofar > tp->mss) { tp->data[css + 13] &= ~9; /* PSH, FIN */ + } else if (frames) { + inc_reg_if_not_full(s, TSCTC); + } } else /* UDP */ stw_be_p(tp->data+css+4, len); if (tp->sum_needed & E1000_TXD_POPTS_TXSM) { @@ -696,6 +740,8 @@ xmit_seg(E1000State *s) inc_reg_if_not_full(s, TPT); grow_8reg_if_not_full(s, TOTL, s->tx.size); s->mac_reg[GPTC] = s->mac_reg[TPT]; + s->mac_reg[GOTCL] = s->mac_reg[TOTL]; + s->mac_reg[GOTCH] = s->mac_reg[TOTH]; } static void @@ -863,7 +909,6 @@ start_xmit(E1000State *s) static int receive_filter(E1000State *s, const uint8_t *buf, int size) { - static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; static const int mta_shift[] = {4, 3, 2, 0}; uint32_t f, rctl = s->mac_reg[RCTL], ra[2], *rp; int isbcast = !memcmp(buf, bcast, sizeof bcast), ismcast = (buf[0] & 1); @@ -881,10 +926,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size) } if (ismcast && (rctl & E1000_RCTL_MPE)) { /* promiscuous mcast */ + inc_reg_if_not_full(s, MPRC); return 1; } if (isbcast && (rctl & E1000_RCTL_BAM)) { /* broadcast enabled */ + inc_reg_if_not_full(s, BPRC); return 1; } @@ -906,8 +953,10 @@ receive_filter(E1000State *s, const uint8_t *buf, int size) f = mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3]; f = (((buf[5] << 8) | buf[4]) >> f) & 0xfff; - if (s->mac_reg[MTA + (f >> 5)] & (1 << (f & 0x1f))) + if (s->mac_reg[MTA + (f >> 5)] & (1 << (f & 0x1f))) { + inc_reg_if_not_full(s, MPRC); return 1; + } DBGOUT(RXFILTER, "dropping, inexact filter mismatch: %02x:%02x:%02x:%02x:%02x:%02x MO %d MTA[%d] %x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], @@ -996,6 +1045,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) size_t desc_offset; size_t desc_size; size_t total_size; + static const int PRCregs[6] = { PRC64, PRC127, PRC255, PRC511, + PRC1023, PRC1522 }; if (!(s->mac_reg[STATUS] & E1000_STATUS_LU)) { return -1; @@ -1009,6 +1060,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) if (size < sizeof(min_buf)) { iov_to_buf(iov, iovcnt, 0, min_buf, size); memset(&min_buf[size], 0, sizeof(min_buf) - size); + inc_reg_if_not_full(s, RUC); min_iov.iov_base = filter_buf = min_buf; min_iov.iov_len = size = sizeof(min_buf); iovcnt = 1; @@ -1024,6 +1076,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) (size > MAXIMUM_ETHERNET_VLAN_SIZE && !(s->mac_reg[RCTL] & E1000_RCTL_LPE))) && !(s->mac_reg[RCTL] & E1000_RCTL_SBP)) { + inc_reg_if_not_full(s, ROC); return size; } @@ -1109,6 +1162,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) } } while (desc_offset < total_size); + increase_size_stats(s, PRCregs, total_size); inc_reg_if_not_full(s, TPR); s->mac_reg[GPRC] = s->mac_reg[TPR]; /* TOR - Total Octets Received: @@ -1117,6 +1171,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) * Always include FCS length (4) in size. */ grow_8reg_if_not_full(s, TORL, size+4); + s->mac_reg[GORCL] = s->mac_reg[TORL]; + s->mac_reg[GORCH] = s->mac_reg[TORH]; n = E1000_ICS_RXT0; if ((rdt = s->mac_reg[RDT]) < s->mac_reg[RDH]) @@ -1305,11 +1361,23 @@ static uint32_t (*macreg_readops[])(E1000State *, int) = { getreg(TNCRS), getreg(SEC), getreg(CEXTERR), getreg(RLEC), getreg(XONRXC), getreg(XONTXC), getreg(XOFFRXC), getreg(XOFFTXC), getreg(RFC), getreg(RJC), getreg(RNBC), getreg(TSCTFC), - getreg(MGTPRC), getreg(MGTPDC), getreg(MGTPTC), + getreg(MGTPRC), getreg(MGTPDC), getreg(MGTPTC), getreg(GORCL), + getreg(GOTCL), [TOTH] = mac_read_clr8, [TORH] = mac_read_clr8, + [GOTCH] = mac_read_clr8, [GORCH] = mac_read_clr8, + [PRC64] = mac_read_clr4, [PRC127] = mac_read_clr4, + [PRC255] = mac_read_clr4, [PRC511] = mac_read_clr4, + [PRC1023] = mac_read_clr4, [PRC1522] = mac_read_clr4, + [PTC64] = mac_read_clr4, [PTC127] = mac_read_clr4, + [PTC255] = mac_read_clr4, [PTC511] = mac_read_clr4, + [PTC1023] = mac_read_clr4, [PTC1522] = mac_read_clr4, [GPRC] = mac_read_clr4, [GPTC] = mac_read_clr4, [TPT] = mac_read_clr4, [TPR] = mac_read_clr4, + [RUC] = mac_read_clr4, [ROC] = mac_read_clr4, + [BPRC] = mac_read_clr4, [MPRC] = mac_read_clr4, + [TSCTC] = mac_read_clr4, [BPTC] = mac_read_clr4, + [MPTC] = mac_read_clr4, [ICR] = mac_icr_read, [EECD] = get_eecd, [EERD] = flash_eerd_read, [RDFH] = mac_low13_read_prt, [RDFT] = mac_low13_read_prt, @@ -1559,6 +1627,44 @@ static const VMStateDescription vmstate_e1000_extra_trivial_regs = { } }; +static bool e1000_extra_counters_needed(void *opaque) +{ + return true; +} + +static const VMStateDescription vmstate_e1000_extra_counters = { + .name = "e1000/extra_counters", + .version_id = 1, + .minimum_version_id = 1, + .needed = e1000_extra_counters_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT32(mac_reg[PRC64], E1000State), + VMSTATE_UINT32(mac_reg[PRC127], E1000State), + VMSTATE_UINT32(mac_reg[PRC255], E1000State), + VMSTATE_UINT32(mac_reg[PRC511], E1000State), + VMSTATE_UINT32(mac_reg[PRC1023], E1000State), + VMSTATE_UINT32(mac_reg[PRC1522], E1000State), + VMSTATE_UINT32(mac_reg[BPRC], E1000State), + VMSTATE_UINT32(mac_reg[MPRC], E1000State), + VMSTATE_UINT32(mac_reg[GORCL], E1000State), + VMSTATE_UINT32(mac_reg[GORCH], E1000State), + VMSTATE_UINT32(mac_reg[GOTCL], E1000State), + VMSTATE_UINT32(mac_reg[GOTCH], E1000State), + VMSTATE_UINT32(mac_reg[RUC], E1000State), + VMSTATE_UINT32(mac_reg[ROC], E1000State), + VMSTATE_UINT32(mac_reg[PTC64], E1000State), + VMSTATE_UINT32(mac_reg[PTC127], E1000State), + VMSTATE_UINT32(mac_reg[PTC255], E1000State), + VMSTATE_UINT32(mac_reg[PTC511], E1000State), + VMSTATE_UINT32(mac_reg[PTC1023], E1000State), + VMSTATE_UINT32(mac_reg[PTC1522], E1000State), + VMSTATE_UINT32(mac_reg[MPTC], E1000State), + VMSTATE_UINT32(mac_reg[BPTC], E1000State), + VMSTATE_UINT32(mac_reg[TSCTC], E1000State), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_e1000 = { .name = "e1000", .version_id = 2, @@ -1639,6 +1745,7 @@ static const VMStateDescription vmstate_e1000 = { .subsections = (const VMStateDescription*[]) { &vmstate_e1000_mit_state, &vmstate_e1000_extra_trivial_regs, + &vmstate_e1000_extra_counters, NULL } };