From patchwork Mon Dec 5 18:58:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 9461355 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28AAA60459 for ; Mon, 5 Dec 2016 18:59:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 122A227F86 for ; Mon, 5 Dec 2016 18:59:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0689827F8F; Mon, 5 Dec 2016 18:59:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87F4127F86 for ; Mon, 5 Dec 2016 18:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751510AbcLES7M (ORCPT ); Mon, 5 Dec 2016 13:59:12 -0500 Received: from mail2.candelatech.com ([208.74.158.173]:50690 "EHLO mail2.candelatech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751201AbcLES7J (ORCPT ); Mon, 5 Dec 2016 13:59:09 -0500 Received: from ben-dt3.candelatech.com (firewall.candelatech.com [50.251.239.81]) by mail2.candelatech.com (Postfix) with ESMTP id 7133740A5C4; Mon, 5 Dec 2016 10:58:32 -0800 (PST) From: greearb@candelatech.com To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, Ben Greear Subject: [PATCH v2 1/2] mac80211: Return avg sig, rx, tx values in ethtool stats. Date: Mon, 5 Dec 2016 10:58:29 -0800 Message-Id: <1480964310-16698-1-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 2.4.11 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Greear For non-station devices. This gives at least some useful summary in some cases (especially when we know AP has only one station attached, for instance). Signed-off-by: Ben Greear --- v2: Remove commented out pr_err code, remove trailing i++ that had no effect. net/mac80211/ethtool.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/net/mac80211/ethtool.c b/net/mac80211/ethtool.c index 4e937c1..e7df3d3 100644 --- a/net/mac80211/ethtool.c +++ b/net/mac80211/ethtool.c @@ -12,6 +12,25 @@ #include "ieee80211_i.h" #include "sta_info.h" #include "driver-ops.h" +#include + +static inline __s64 mac_div(__s64 n, __u32 base) +{ + if (n < 0) { + __u64 tmp = -n; + do_div(tmp, base); + /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n", + n, base, tmp); */ + return -tmp; + } + else { + __u64 tmp = n; + do_div(tmp, base); + /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n", + n, base, tmp); */ + return tmp; + } +} static int ieee80211_set_ringparam(struct net_device *dev, struct ethtool_ringparam *rp) @@ -128,6 +147,12 @@ static void ieee80211_get_stats(struct net_device *dev, data[i] = (u8)sinfo.signal_avg; i++; } else { + int amt_tx = 0; + int amt_rx = 0; + int amt_sig = 0; + s64 tx_accum = 0; + s64 rx_accum = 0; + s64 sig_accum = 0; list_for_each_entry(sta, &local->sta_list, list) { /* Make sure this station belongs to the proper dev */ if (sta->sdata->dev != dev) @@ -137,6 +162,30 @@ static void ieee80211_get_stats(struct net_device *dev, sta_set_sinfo(sta, &sinfo); i = 0; ADD_STA_STATS(sta); + + i++; /* skip sta state */ + + if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { + tx_accum += 100000 * + cfg80211_calculate_bitrate(&sinfo.txrate); + amt_tx++; + data[i] = mac_div(tx_accum, amt_tx); + } + i++; + + if (sinfo.filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { + rx_accum += 100000 * + cfg80211_calculate_bitrate(&sinfo.rxrate); + amt_rx++; + data[i] = mac_div(rx_accum, amt_rx); + } + i++; + + if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL_AVG)) { + sig_accum += sinfo.signal_avg; + amt_sig++; + data[i] = (mac_div(sig_accum, amt_sig) & 0xFF); + } } }