From owner-svn-src-head@freebsd.org Fri Sep 9 04:45:27 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 72216BD1E35; Fri, 9 Sep 2016 04:45:27 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 35F4CDC1; Fri, 9 Sep 2016 04:45:27 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u894jQtG098323; Fri, 9 Sep 2016 04:45:26 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u894jQVr098319; Fri, 9 Sep 2016 04:45:26 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201609090445.u894jQVr098319@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Fri, 9 Sep 2016 04:45:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305637 - in head/sys/dev/ath/ath_hal: . ar5416 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Sep 2016 04:45:27 -0000 Author: adrian Date: Fri Sep 9 04:45:25 2016 New Revision: 305637 URL: https://svnweb.freebsd.org/changeset/base/305637 Log: [ath_hal] fixes for finer grain timestamping, some 11n macros * change the HT_RC_2_MCS to do MCS0..23 * Use it when looking up the ht20/ht40 array for bits-per-symbol * add a clk_to_psec (picoseconds) routine, so we can get sub-microsecond accuracy for the math * .. and make that + clk_to_usec public, so higher layer code that is returning clocks (eg the ANI diag routines, some upcoming locationing experiments) can be converted to microseconds. Whilst here, add a comment in ar5416 so i or someone else can revisit the latency values. Modified: head/sys/dev/ath/ath_hal/ah.c head/sys/dev/ath/ath_hal/ah.h head/sys/dev/ath/ath_hal/ah_internal.h head/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c Modified: head/sys/dev/ath/ath_hal/ah.c ============================================================================== --- head/sys/dev/ath/ath_hal/ah.c Fri Sep 9 04:16:53 2016 (r305636) +++ head/sys/dev/ath/ath_hal/ah.c Fri Sep 9 04:45:25 2016 (r305637) @@ -275,7 +275,7 @@ ath_hal_reverseBits(uint32_t val, uint32 #define HT_STF 4 #define HT_LTF(n) ((n) * 4) -#define HT_RC_2_MCS(_rc) ((_rc) & 0xf) +#define HT_RC_2_MCS(_rc) ((_rc) & 0x1f) #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1) #define IS_HT_RATE(_rc) ( (_rc) & IEEE80211_RATE_MCS) @@ -334,9 +334,9 @@ ath_computedur_ht(uint32_t frameLen, uin KASSERT((rate &~ IEEE80211_RATE_MCS) < 31, ("bad mcs 0x%x", rate)); if (isht40) - bitsPerSymbol = ht40_bps[rate & 0x1f]; + bitsPerSymbol = ht40_bps[HT_RC_2_MCS(rate)]; else - bitsPerSymbol = ht20_bps[rate & 0x1f]; + bitsPerSymbol = ht20_bps[HT_RC_2_MCS(rate)]; numBits = OFDM_PLCP_BITS + (frameLen << 3); numSymbols = howmany(numBits, bitsPerSymbol); if (isShortGI) @@ -490,6 +490,11 @@ typedef enum { WIRELESS_MODE_MAX } WIRELESS_MODE; +/* + * XXX TODO: for some (?) chips, an 11b mode still runs at 11bg. + * Maybe AR5211 has separate 11b and 11g only modes, so 11b is 22MHz + * and 11g is 44MHz, but AR5416 and later run 11b in 11bg mode, right? + */ static WIRELESS_MODE ath_hal_chan2wmode(struct ath_hal *ah, const struct ieee80211_channel *chan) { @@ -543,22 +548,34 @@ ath_hal_mac_clks(struct ath_hal *ah, u_i u_int ath_hal_mac_usec(struct ath_hal *ah, u_int clks) { + uint64_t psec; + + psec = ath_hal_mac_psec(ah, clks); + return (psec / 1000000); +} + +/* + * XXX TODO: half, quarter rates. + */ +uint64_t +ath_hal_mac_psec(struct ath_hal *ah, u_int clks) +{ const struct ieee80211_channel *c = AH_PRIVATE(ah)->ah_curchan; - u_int usec; + uint64_t psec; /* NB: ah_curchan may be null when called attach time */ /* XXX merlin and later specific workaround - 5ghz fast clock is 44 */ if (c != AH_NULL && IS_5GHZ_FAST_CLOCK_EN(ah, c)) { - usec = clks / CLOCK_FAST_RATE_5GHZ_OFDM; + psec = (clks * 1000000ULL) / CLOCK_FAST_RATE_5GHZ_OFDM; if (IEEE80211_IS_CHAN_HT40(c)) - usec >>= 1; + psec >>= 1; } else if (c != AH_NULL) { - usec = clks / CLOCK_RATE[ath_hal_chan2wmode(ah, c)]; + psec = (clks * 1000000ULL) / CLOCK_RATE[ath_hal_chan2wmode(ah, c)]; if (IEEE80211_IS_CHAN_HT40(c)) - usec >>= 1; + psec >>= 1; } else - usec = clks / CLOCK_RATE[WIRELESS_MODE_11b]; - return usec; + psec = (clks * 1000000ULL) / CLOCK_RATE[WIRELESS_MODE_11b]; + return psec; } /* Modified: head/sys/dev/ath/ath_hal/ah.h ============================================================================== --- head/sys/dev/ath/ath_hal/ah.h Fri Sep 9 04:16:53 2016 (r305636) +++ head/sys/dev/ath/ath_hal/ah.h Fri Sep 9 04:45:25 2016 (r305637) @@ -1674,4 +1674,11 @@ ath_hal_get_mfp_qos(struct ath_hal *ah) return HAL_MFP_QOSDATA; } +/* + * Convert between microseconds and core system clocks. + */ +extern u_int ath_hal_mac_clks(struct ath_hal *ah, u_int usecs); +extern u_int ath_hal_mac_usec(struct ath_hal *ah, u_int clks); +extern uint64_t ath_hal_mac_psec(struct ath_hal *ah, u_int clks); + #endif /* _ATH_AH_H_ */ Modified: head/sys/dev/ath/ath_hal/ah_internal.h ============================================================================== --- head/sys/dev/ath/ath_hal/ah_internal.h Fri Sep 9 04:16:53 2016 (r305636) +++ head/sys/dev/ath/ath_hal/ah_internal.h Fri Sep 9 04:45:25 2016 (r305637) @@ -727,12 +727,6 @@ ath_hal_gethwchannel(struct ath_hal *ah, } /* - * Convert between microseconds and core system clocks. - */ -extern u_int ath_hal_mac_clks(struct ath_hal *ah, u_int usecs); -extern u_int ath_hal_mac_usec(struct ath_hal *ah, u_int clks); - -/* * Generic get/set capability support. Each chip overrides * this routine to support chip-specific capabilities. */ Modified: head/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c ============================================================================== --- head/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c Fri Sep 9 04:16:53 2016 (r305636) +++ head/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c Fri Sep 9 04:45:25 2016 (r305637) @@ -2833,6 +2833,9 @@ ar5416SetIFSTiming(struct ath_hal *ah, c clk_44 = 1; /* XXX does this need save/restoring for the 11n chips? */ + /* + * XXX TODO: should mask out the txlat/rxlat/usec values? + */ refClock = OS_REG_READ(ah, AR_USEC) & AR_USEC_USEC32; /*