From patchwork Thu Nov 10 23:10:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: david decotigny X-Patchwork-Id: 125017 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 66C691007D1 for ; Fri, 11 Nov 2011 10:34:51 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757178Ab1KJXep (ORCPT ); Thu, 10 Nov 2011 18:34:45 -0500 Received: from mail-ww0-f74.google.com ([74.125.82.74]:34194 "EHLO mail-ww0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755196Ab1KJXeo (ORCPT ); Thu, 10 Nov 2011 18:34:44 -0500 X-Greylist: delayed 996 seconds by postgrey-1.27 at vger.kernel.org; Thu, 10 Nov 2011 18:34:44 EST Received: by wwe5 with SMTP id 5so8279wwe.1 for ; Thu, 10 Nov 2011 15:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :organization:x-system-of-record; bh=Xhddb3iGR5d1Zs6xLXRA1NxWaUhdnvD6HDXtYOfalLY=; b=MfccPk1yYF44GHkseoRKOMvPo2KVjlxcDr0q97L9bq1D8lJoZ0lweg9bNhPiIAFL1A c1y++dPI+HT8wMWdaoIw== Received: by 10.14.19.9 with SMTP id m9mr578921eem.8.1320966653588; Thu, 10 Nov 2011 15:10:53 -0800 (PST) Received: by 10.14.19.9 with SMTP id m9mr578877eem.8.1320966653301; Thu, 10 Nov 2011 15:10:53 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id i11si5546240eea.0.2011.11.10.15.10.53 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 10 Nov 2011 15:10:53 -0800 (PST) Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by hpza10.eem.corp.google.com (Postfix) with ESMTPS id 1199920004E; Thu, 10 Nov 2011 15:10:52 -0800 (PST) Received: from decotigny.mtv.corp.google.com (decotigny.mtv.corp.google.com [172.18.64.159]) by wpaz21.hot.corp.google.com with ESMTP id pAANAmg2004383; Thu, 10 Nov 2011 15:10:48 -0800 Received: by decotigny.mtv.corp.google.com (Postfix, from userid 128857) id 3635E20B7F; Thu, 10 Nov 2011 15:10:48 -0800 (PST) From: David Decotigny To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , David Decotigny , Ian Campbell , Eric Dumazet , Jeff Kirsher , Jiri Pirko , Joe Perches , Szymon Janc Subject: [PATCH FIX net v1] forcedeth: fix ifconfig stats on hardware without extended stats support Date: Thu, 10 Nov 2011 15:10:40 -0800 Message-Id: <202cfa353085f52352650ecc169cbee66a034301.1320966597.git.david.decotigny@google.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: References: Organization: Google, Inc. X-System-Of-Record: true Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This change makes sure that tx_packets/rx_bytes ifconfig counters are updated even on NICs that don't provide hardware support for these stats. In that case, they are updated in software. Related commit: "forcedeth: Improve stats counters" (0bdfea8ba8) Signed-off-by: David Decotigny --- drivers/net/ethernet/nvidia/forcedeth.c | 34 ++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c index 1dca570..c0afe8e 100644 --- a/drivers/net/ethernet/nvidia/forcedeth.c +++ b/drivers/net/ethernet/nvidia/forcedeth.c @@ -90,6 +90,7 @@ #define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */ #define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */ #define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */ +#define DEV_HAS_STATISTICS_V23 0x0000c00 /* device supports hw statistics version 2 and 3 */ #define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */ #define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */ #define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */ @@ -1703,12 +1704,19 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev) struct fe_priv *np = netdev_priv(dev); /* If the nic supports hw counters then retrieve latest values */ - if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) { + if (np->driver_data & DEV_HAS_STATISTICS_V123) { + /* query hardware */ nv_get_hw_stats(dev); /* copy to net_device stats */ - dev->stats.tx_packets = np->estats.tx_packets; - dev->stats.rx_bytes = np->estats.rx_bytes; + + if (np->driver_data & DEV_HAS_STATISTICS_V23) { + /* When HW stats are available for following + * stats, we use them. Otherwise they are + * updated by software. */ + dev->stats.tx_packets = np->estats.tx_packets; + dev->stats.rx_bytes = np->estats.rx_bytes; + } dev->stats.tx_bytes = np->estats.tx_bytes; dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors; dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors; @@ -2378,8 +2386,12 @@ static int nv_tx_done(struct net_device *dev, int limit) if (np->desc_ver == DESC_VER_1) { if (flags & NV_TX_LASTPACKET) { if (flags & NV_TX_ERROR) { - if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK)) + if ((flags & NV_TX_RETRYERROR) + && !(flags & NV_TX_RETRYCOUNT_MASK)) nv_legacybackoff_reseed(dev); + } else if (unlikely(!(np->driver_data + & DEV_HAS_STATISTICS_V23))) { + dev->stats.tx_packets++; } dev_kfree_skb_any(np->get_tx_ctx->skb); np->get_tx_ctx->skb = NULL; @@ -2388,8 +2400,12 @@ static int nv_tx_done(struct net_device *dev, int limit) } else { if (flags & NV_TX2_LASTPACKET) { if (flags & NV_TX2_ERROR) { - if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) + if ((flags & NV_TX2_RETRYERROR) + && !(flags & NV_TX2_RETRYCOUNT_MASK)) nv_legacybackoff_reseed(dev); + } else if (unlikely(!(np->driver_data + & DEV_HAS_STATISTICS_V23))) { + dev->stats.tx_packets++; } dev_kfree_skb_any(np->get_tx_ctx->skb); np->get_tx_ctx->skb = NULL; @@ -2429,6 +2445,9 @@ static int nv_tx_done_optimized(struct net_device *dev, int limit) else nv_legacybackoff_reseed(dev); } + } else if (unlikely(!(np->driver_data + & DEV_HAS_STATISTICS_V23))) { + dev->stats.tx_packets++; } dev_kfree_skb_any(np->get_tx_ctx->skb); @@ -2678,6 +2697,8 @@ static int nv_rx_process(struct net_device *dev, int limit) skb->protocol = eth_type_trans(skb, dev); napi_gro_receive(&np->napi, skb); dev->stats.rx_packets++; + if (unlikely(!(np->driver_data & DEV_HAS_STATISTICS_V23))) + dev->stats.rx_bytes += len; next_pkt: if (unlikely(np->get_rx.orig++ == np->last_rx.orig)) np->get_rx.orig = np->first_rx.orig; @@ -2761,6 +2782,9 @@ static int nv_rx_process_optimized(struct net_device *dev, int limit) } napi_gro_receive(&np->napi, skb); dev->stats.rx_packets++; + if (unlikely(!(np->driver_data + & DEV_HAS_STATISTICS_V23))) + dev->stats.rx_bytes += len; } else { dev_kfree_skb(skb); }