From patchwork Fri May 22 08:18:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 6461751 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 38DF4C0020 for ; Fri, 22 May 2015 08:18:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3EDEF2037F for ; Fri, 22 May 2015 08:18:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 905A220459 for ; Fri, 22 May 2015 08:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756807AbbEVISa (ORCPT ); Fri, 22 May 2015 04:18:30 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:36811 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756508AbbEVISW (ORCPT ); Fri, 22 May 2015 04:18:22 -0400 Received: by wizk4 with SMTP id k4so39382218wiz.1 for ; Fri, 22 May 2015 01:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QQpjqNMtZiFi6uHt/UFlF2S3Nj42XSQwb9Gwt7i3TmA=; b=IdPu+tB9c41os1ds7npR5TJTRfI/IbAtmZ7NSno+KwHwW0zBD7DS8wnv2WvNnEVMpn BXBuv8u7h9cq6VF1lQ0EHk4a/FahWz3N1WxXGAlNTLDfP8faM5bJEpbXdBMEMCXD+kq1 PpB0aHlPSStmSBPOMgVDnHZEOFF0IT7XKrBdI= 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=QQpjqNMtZiFi6uHt/UFlF2S3Nj42XSQwb9Gwt7i3TmA=; b=eXUEiLNB8OceBpCnjJxO5EpXflwfIE/J5NebcAzT5OzFUEbwcA8pKsVVS5Sx9qHupT 4y0fKyQhM28QG4rHkr+/SULECwTsTlOSlJK5LLGdSqkzy+tMeL7a/xB+xndKiht8oSiw H2Ym28Qvo1dO+tQNCeykQIwu3THpcGlOmNK3P4R955fCnpbtrI28f8XgD0Pe5XznmW7+ 77dJgq7kty8TBP0K7tud6AQ0Kyou6t2sJgf2aK8HniYIEzqtEFo44K+jn9EoJb/I551Y 0WlTnw7XKv8BoR94rGBCXC9GsIuRln2HdWVGDPw6EEeHq+1kZ33ArpR3NX0rsntNnixh 80Ow== X-Gm-Message-State: ALoCoQm88BPrbempKoQIQMwhWzszeIWpYpPdI7/zz41Rh6GF2Rs1axcxug8w04tjo7Bmnuabw5Q+ndId6+CSa0uYaE76v1BDEqtF5OwJGaxN/jJgdfT0t2oZwfDsXah8WiqIoKJRKOys X-Received: by 10.194.92.2 with SMTP id ci2mr12650805wjb.34.1432282701325; Fri, 22 May 2015 01:18:21 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by mx.google.com with ESMTPSA id l3sm6334770wik.16.2015.05.22.01.18.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 May 2015 01:18:20 -0700 (PDT) From: Michal Kazior To: ath10k@lists.infradead.org Cc: linux-wireless@vger.kernel.org, Michal Kazior Subject: [PATCH v3 1/2] ath10k: handle cycle counter wraparound Date: Fri, 22 May 2015 10:18:12 +0200 Message-Id: <1432282693-4553-1-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-DomainID: tieto.com Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When QCA988X cycle counter HW register wraps around it resets to 0x7fffffff instead of 0. All other cycle counter related registers are divided by 2 so they never wraparound themselves. QCA61X4 has a uniform CC and it wraparounds in a regular fashion though. Worst case wraparound time is approx 24 seconds (2**31 / 88MHz). Since scan channel visit times are max 5 seconds (offchannel case) it is guaranteed there's been at most 1 wraparound and it is possible to compute survey data. This fixes some occasional incorrect survey data on QCA988X as some channels (depending on how/when scan/offchannel requests were requested) would have approx 24 sec active time which wasn't actually the case. This should help make hostapd ACS more reliable. Reported-by: Srinivasa Duvvuri Signed-off-by: Michal Kazior --- Notes: v3: * split into 2 separate patches * don't ignore all wraparound data: scans can be computed * apply the shifted wraparound fix only for QCA988X * improve commit log drivers/net/wireless/ath/ath10k/core.c | 15 +++++++++++++++ drivers/net/wireless/ath/ath10k/core.h | 12 ++++++++++++ drivers/net/wireless/ath/ath10k/wmi.c | 14 ++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index bcccae19325d..0cc2122d6921 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -48,6 +48,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = { .name = "qca988x hw2.0", .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR, .uart_pin = 7, + .has_shifted_cc_wraparound = true, .fw = { .dir = QCA988X_HW_2_0_FW_DIR, .fw = QCA988X_HW_2_0_FW_FILE, @@ -102,6 +103,20 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = { }, }; +void ath10k_core_get_cc_delta(struct ath10k *ar, + u32 *cc_delta, u32 *rcc_delta, + u32 cc, u32 rcc, + u32 cc_prev, u32 rcc_prev) +{ + if (ar->hw_params.has_shifted_cc_wraparound && cc < cc_prev) { + cc_prev -= 0x7fffffff; + rcc *= 2; + } + + *cc_delta = cc - cc_prev; + *rcc_delta = rcc - rcc_prev; +} + static void ath10k_send_suspend_complete(struct ath10k *ar) { ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n"); diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index 827b3d79ed0c..fb403972b1c5 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -572,6 +572,13 @@ struct ath10k { u32 patch_load_addr; int uart_pin; + /* This is true if given HW chip has a quirky Cycle Counter + * wraparound which resets to 0x7fffffff instead of 0. All + * other CC related counters (e.g. Rx Clear Count) are divided + * by 2 so they never wraparound themselves. + */ + bool has_shifted_cc_wraparound; + struct ath10k_hw_params_fw { const char *dir; const char *fw; @@ -742,4 +749,9 @@ void ath10k_core_stop(struct ath10k *ar); int ath10k_core_register(struct ath10k *ar, u32 chip_id); void ath10k_core_unregister(struct ath10k *ar); +void ath10k_core_get_cc_delta(struct ath10k *ar, + u32 *cc_delta, u32 *rcc_delta, + u32 cc, u32 rcc, + u32 cc_prev, u32 rcc_prev); + #endif /* _CORE_H_ */ diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c index 0fabe689179c..52ed48b7e5f9 100644 --- a/drivers/net/wireless/ath/ath10k/wmi.c +++ b/drivers/net/wireless/ath/ath10k/wmi.c @@ -1640,8 +1640,18 @@ void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb) * visited channel. The reported cycle count is global * and per-channel cycle count must be calculated */ - cycle_count -= ar->survey_last_cycle_count; - rx_clear_count -= ar->survey_last_rx_clear_count; + /* Worst case wraparound time is approx 24 seconds (2**31 / + * 88MHz). Since scan channel visit times are max 5 seconds + * (offchannel case) it is guaranteed there's been at most 1 + * wraparound and it is possible to compute survey data. + */ + ath10k_core_get_cc_delta(ar, + &cycle_count, + &rx_clear_count, + cycle_count, + rx_clear_count, + ar->survey_last_cycle_count, + ar->survey_last_rx_clear_count); survey = &ar->survey[idx]; survey->time = WMI_CHAN_INFO_MSEC(cycle_count);