From patchwork Thu Jul 31 00:48:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 34567 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5774F20792 for ; Thu, 31 Jul 2014 00:48:12 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf11817896pde.11 for ; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=/30hcSF6JEoHWDsYcofJ3qalxUbgbL3/RYqcYddtJUE=; b=eEVIo+zpL2CuNT46NxopkfqM3Dq8JuniT8eNxRJ4ICe5lAVvnsjtcdACL4Cvl8Ypjp n31le8blSFK/HU9hQti2ivymVXGszoOsK6FpAn5lnfRsOoNiyjIhQ83RvfS8dyBIBZSh r6Z/ABD7W2WJbpLt7HJ6HPMAxG52rloMPdiuKQOhsuc5J6DW83x1/ua2vN7W1XpDwowL a1+xyeJr4emx+XtPc6ZEmFTONp/C1kRe67W8LYbjXhaZNoSjjMKn6qRPPc92MyBlpUUS ckDyyt5U8VEaaUkfNMJpN+aspag4ZEPl++LAeTGdgUNv8x7tUO+YG465C5zdj4YvcqPJ xf4A== X-Gm-Message-State: ALoCoQmx8sKoTCYZWpcQAAWYiETJPM5/QjmTQ5Y1TrnST6+N7E85Xl0qVJSeGlBK2djnrTAeJGSc X-Received: by 10.66.129.139 with SMTP id nw11mr273466pab.35.1406767691592; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.227 with SMTP id s90ls759040qga.95.gmail; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) X-Received: by 10.52.106.198 with SMTP id gw6mr11725682vdb.23.1406767691444; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id dn3si3248092vcb.40.2014.07.30.17.48.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 17:48:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ik5so3140868vcb.34 for ; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr9145731vcq.50.1406767691310; Wed, 30 Jul 2014 17:48:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp67091vcb; Wed, 30 Jul 2014 17:48:10 -0700 (PDT) X-Received: by 10.68.116.235 with SMTP id jz11mr42821pbb.149.1406767690460; Wed, 30 Jul 2014 17:48:10 -0700 (PDT) Received: from mail-pd0-f180.google.com (mail-pd0-f180.google.com [209.85.192.180]) by mx.google.com with ESMTPS id dz9si4014674pab.161.2014.07.30.17.48.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 17:48:10 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.180 as permitted sender) client-ip=209.85.192.180; Received: by mail-pd0-f180.google.com with SMTP id y13so2394784pdi.39 for ; Wed, 30 Jul 2014 17:48:10 -0700 (PDT) X-Received: by 10.66.141.71 with SMTP id rm7mr387207pab.120.1406767689967; Wed, 30 Jul 2014 17:48:09 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id xj3sm13037105pac.29.2014.07.30.17.48.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jul 2014 17:48:09 -0700 (PDT) From: John Stultz To: linux-kernel@vger.kernel.org Cc: John Stultz , Stephen Rothwell , Ingo Molnar , "H. Peter Anvin" , Peter Zijlstra , David Miller , "John W. Linville" , Felix Fietkau , Rajkumar Manoharan , , QCA ath9k Development , linux-next@vger.kernel.org Subject: [RFC][PATCH v2] wireless: ath9k: Convert from timespecs to ktime_t Date: Wed, 30 Jul 2014 17:48:00 -0700 Message-Id: <1406767680-716-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20140731102750.4a4c1315@canb.auug.org.au> References: <20140731102750.4a4c1315@canb.auug.org.au> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Convert from using timespecs to ktime_t for internal timekeeping needs. This simplifies the logic and avoids extra math required to convert from timespec to usecs. Cc: Stephen Rothwell Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Peter Zijlstra Cc: David Miller Cc: "John W. Linville" Cc: Felix Fietkau Cc: Rajkumar Manoharan Cc: Cc: QCA ath9k Development Cc: linux-next@vger.kernel.org Signed-off-by: John Stultz --- Thomas made an earlier version of this patch which I queued, but it collided badly in -next with the timestamping rework in ath9k code. So this is my swing at fixing it up again. v2: Fix an embarasing null pointer assignment Stephen pointed out Compile tested only. Would apprecate feedback, testing, and review. drivers/net/wireless/ath/ath9k/ath9k.h | 2 +- drivers/net/wireless/ath/ath9k/channel.c | 18 +++++++++--------- drivers/net/wireless/ath/ath9k/hw.c | 19 ++++++++----------- drivers/net/wireless/ath/ath9k/hw.h | 2 +- drivers/net/wireless/ath/ath9k/main.c | 2 +- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h index 7fc13a8..5553c0f 100644 --- a/drivers/net/wireless/ath/ath9k/ath9k.h +++ b/drivers/net/wireless/ath/ath9k/ath9k.h @@ -335,7 +335,7 @@ struct ath_chanctx { struct ath_beacon_config beacon; struct ath9k_hw_cal_data caldata; - struct timespec tsf_ts; + ktime_t tsf_kt; u64 tsf_val; u32 last_beacon; diff --git a/drivers/net/wireless/ath/ath9k/channel.c b/drivers/net/wireless/ath/ath9k/channel.c index ba214eb..2b37f8d 100644 --- a/drivers/net/wireless/ath/ath9k/channel.c +++ b/drivers/net/wireless/ath/ath9k/channel.c @@ -228,9 +228,9 @@ static bool ath_chanctx_defer_switch(struct ath_softc *sc) static void ath_chanctx_set_next(struct ath_softc *sc, bool force) { - struct timespec ts; bool measure_time = false; bool send_ps = false; + ktime_t now; spin_lock_bh(&sc->chan_lock); if (!sc->next_chan) { @@ -248,7 +248,7 @@ static void ath_chanctx_set_next(struct ath_softc *sc, bool force) spin_unlock_bh(&sc->chan_lock); if (sc->next_chan == &sc->offchannel.chan) { - getrawmonotonic(&ts); + now = ktime_get_raw(); measure_time = true; } __ath9k_flush(sc->hw, ~0, true); @@ -260,7 +260,7 @@ static void ath_chanctx_set_next(struct ath_softc *sc, bool force) spin_lock_bh(&sc->chan_lock); if (sc->cur_chan != &sc->offchannel.chan) { - getrawmonotonic(&sc->cur_chan->tsf_ts); + sc->cur_chan->tsf_kt = ktime_get_raw(); sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah); } } @@ -279,7 +279,7 @@ static void ath_chanctx_set_next(struct ath_softc *sc, bool force) ath_set_channel(sc); if (measure_time) sc->sched.channel_switch_time = - ath9k_hw_get_tsf_offset(&ts, NULL); + ath9k_hw_get_tsf_offset(&now, NULL); } if (send_ps) ath_chanctx_send_ps_frame(sc, false); @@ -440,8 +440,8 @@ ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx) static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc) { struct ath_chanctx *prev, *cur; - struct timespec ts; u32 cur_tsf, prev_tsf, beacon_int; + ktime_t now; s32 offset; beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval); @@ -449,12 +449,12 @@ static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc) cur = sc->cur_chan; prev = ath_chanctx_get_next(sc, cur); - getrawmonotonic(&ts); + now = ktime_get_raw(); cur_tsf = (u32) cur->tsf_val + - ath9k_hw_get_tsf_offset(&cur->tsf_ts, &ts); + ath9k_hw_get_tsf_offset(&cur->tsf_kt, &now); prev_tsf = prev->last_beacon - (u32) prev->tsf_val + cur_tsf; - prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_ts, &ts); + prev_tsf -= ath9k_hw_get_tsf_offset(&prev->tsf_kt, &now); /* Adjust the TSF time of the AP chanctx to keep its beacons * at half beacon interval offset relative to the STA chanctx. @@ -614,7 +614,7 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif, */ tsf_time = sc->sched.switch_start_time; tsf_time -= (u32) sc->cur_chan->tsf_val + - ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL); + ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_kt, NULL); tsf_time += ath9k_hw_gettsf32(ah); diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c index fd0158f..1a0a556 100644 --- a/drivers/net/wireless/ath/ath9k/hw.c +++ b/drivers/net/wireless/ath/ath9k/hw.c @@ -1731,19 +1731,16 @@ fail: return -EINVAL; } -u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur) +u32 ath9k_hw_get_tsf_offset(ktime_t *last, ktime_t *cur) { - struct timespec ts; + ktime_t tmp; s64 usec; if (!cur) { - getrawmonotonic(&ts); - cur = &ts; + tmp = ktime_get_raw(); + cur = &tmp; } - - usec = cur->tv_sec * 1000000ULL + cur->tv_nsec / 1000; - usec -= last->tv_sec * 1000000ULL + last->tv_nsec / 1000; - + usec = ktime_to_us(ktime_sub(*cur, *last)); return (u32) usec; } EXPORT_SYMBOL(ath9k_hw_get_tsf_offset); @@ -1752,7 +1749,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, struct ath9k_hw_cal_data *caldata, bool fastcc) { struct ath_common *common = ath9k_hw_common(ah); - struct timespec ts; + ktime_t now; u32 saveLedState; u32 saveDefAntenna; u32 macStaId1; @@ -1801,7 +1798,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, /* Save TSF before chip reset, a cold reset clears it */ tsf = ath9k_hw_gettsf64(ah); - getrawmonotonic(&ts); + now = ktime_get_raw(); saveLedState = REG_READ(ah, AR_CFG_LED) & (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | @@ -1834,7 +1831,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, } /* Restore TSF */ - ath9k_hw_settsf64(ah, tsf + ath9k_hw_get_tsf_offset(&ts, NULL)); + ath9k_hw_settsf64(ah, tsf + ath9k_hw_get_tsf_offset(&now, NULL)); if (AR_SREV_9280_20_OR_LATER(ah)) REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE); diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h index 51b4ebe..a57b4e2 100644 --- a/drivers/net/wireless/ath/ath9k/hw.h +++ b/drivers/net/wireless/ath/ath9k/hw.h @@ -1000,7 +1000,7 @@ u32 ath9k_hw_gettsf32(struct ath_hw *ah); u64 ath9k_hw_gettsf64(struct ath_hw *ah); void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64); void ath9k_hw_reset_tsf(struct ath_hw *ah); -u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur); +u32 ath9k_hw_get_tsf_offset(ktime_t *last, ktime_t *cur); void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set); void ath9k_hw_init_global_settings(struct ath_hw *ah); u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah); diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c index e6ac8d2..e47dbd3 100644 --- a/drivers/net/wireless/ath/ath9k/main.c +++ b/drivers/net/wireless/ath/ath9k/main.c @@ -241,7 +241,7 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start) if (sc->cur_chan->tsf_val) { u32 offset; - offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, + offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_kt, NULL); ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset); }