summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradrian <adrian@FreeBSD.org>2011-01-28 08:35:55 +0000
committeradrian <adrian@FreeBSD.org>2011-01-28 08:35:55 +0000
commit2dc68374964e0ce1ac3ef355d0b1ffffdfaafd0e (patch)
treef4a1dfbf8c19384fa0d8aacd88c0e41c562a5837
parent4d002160ce841251c6eae54ef713c0b159b250ea (diff)
downloadFreeBSD-src-2dc68374964e0ce1ac3ef355d0b1ffffdfaafd0e.zip
FreeBSD-src-2dc68374964e0ce1ac3ef355d0b1ffffdfaafd0e.tar.gz
Bring in some 802.11n packet duration calculation functions from a mix of Sam/Rui and linux ath9k .
This will eventually be used by rate control modules and by the TX code for calculating packet duration when handling rts/cts protection. Obtained from: sam@, rpaulo@, linux ath9k
-rw-r--r--sys/dev/ath/ath_hal/ah.c72
-rw-r--r--sys/dev/ath/ath_hal/ah.h15
2 files changed, 86 insertions, 1 deletions
diff --git a/sys/dev/ath/ath_hal/ah.c b/sys/dev/ath/ath_hal/ah.c
index f208d48..031caa2 100644
--- a/sys/dev/ath/ath_hal/ah.c
+++ b/sys/dev/ath/ath_hal/ah.c
@@ -234,6 +234,78 @@ ath_hal_reverseBits(uint32_t val, uint32_t n)
return retval;
}
+/* 802.11n related timing definitions */
+
+#define OFDM_PLCP_BITS 22
+#define HT_L_STF 8
+#define HT_L_LTF 8
+#define HT_L_SIG 4
+#define HT_SIG 8
+#define HT_STF 4
+#define HT_LTF(n) ((n) * 4)
+
+#define HT_RC_2_MCS(_rc) ((_rc) & 0xf)
+#define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
+#define IS_HT_RATE(_rc) ( (_rc) & IEEE80211_RATE_MCS)
+
+/*
+ * Calculate the duration of a packet whether it is 11n or legacy.
+ */
+uint32_t
+ath_hal_pkt_txtime(struct ath_hal *ah, const HAL_RATE_TABLE *rates, uint32_t frameLen,
+ uint16_t rateix, HAL_BOOL isht40, HAL_BOOL shortPreamble)
+{
+ uint8_t rc;
+ int numStreams;
+
+ rc = rates->info[rateix].rateCode;
+
+ /* Legacy rate? Return the old way */
+ if (! IS_HT_RATE(rc))
+ return ath_hal_computetxtime(ah, rates, frameLen, rateix, shortPreamble);
+
+ /* 11n frame - extract out the number of spatial streams */
+ numStreams = HT_RC_2_STREAMS(rc);
+ KASSERT(numStreams == 1 || numStreams == 2, ("number of spatial streams needs to be 1 or 2: MCS rate 0x%x!", rateix));
+
+ return ath_computedur_ht(frameLen, rc, numStreams, isht40, shortPreamble);
+}
+
+/*
+ * Calculate the transmit duration of an 11n frame.
+ * This only works for MCS0->MCS15.
+ */
+uint32_t
+ath_computedur_ht(uint32_t frameLen, uint16_t rate, int streams, HAL_BOOL isht40,
+ HAL_BOOL isShortGI)
+{
+ static const uint16_t ht20_bps[16] = {
+ 26, 52, 78, 104, 156, 208, 234, 260,
+ 52, 104, 156, 208, 312, 416, 468, 520
+ };
+ static const uint16_t ht40_bps[16] = {
+ 54, 108, 162, 216, 324, 432, 486, 540,
+ 108, 216, 324, 432, 648, 864, 972, 1080,
+ };
+ uint32_t bitsPerSymbol, numBits, numSymbols, txTime;
+
+ KASSERT(rate & IEEE80211_RATE_MCS, ("not mcs %d", rate));
+ KASSERT((rate &~ IEEE80211_RATE_MCS) < 16, ("bad mcs 0x%x", rate));
+
+ if (isht40)
+ bitsPerSymbol = ht40_bps[rate & 0xf];
+ else
+ bitsPerSymbol = ht20_bps[rate & 0xf];
+ numBits = OFDM_PLCP_BITS + (frameLen << 3);
+ numSymbols = howmany(numBits, bitsPerSymbol);
+ if (isShortGI)
+ txTime = ((numSymbols * 18) + 4) / 5; /* 3.6us */
+ else
+ txTime = numSymbols * 4; /* 4us */
+ return txTime + HT_L_STF + HT_L_LTF +
+ HT_L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
+}
+
/*
* Compute the time to transmit a frame of length frameLen bytes
* using the specified rate, phy, and short preamble setting.
diff --git a/sys/dev/ath/ath_hal/ah.h b/sys/dev/ath/ath_hal/ah.h
index c9bdfbb..3a8ad6b 100644
--- a/sys/dev/ath/ath_hal/ah.h
+++ b/sys/dev/ath/ath_hal/ah.h
@@ -882,7 +882,20 @@ extern void __ahdecl ath_hal_process_noisefloor(struct ath_hal *ah);
extern u_int __ahdecl ath_hal_getwirelessmodes(struct ath_hal*);
/*
- * Calculate the transmit duration of a frame.
+ * Calculate the packet TX time for a legacy or 11n frame
+ */
+extern uint32_t __ahdecl ath_hal_pkt_txtime(struct ath_hal *ah,
+ const HAL_RATE_TABLE *rates, uint32_t frameLen,
+ uint16_t rateix, HAL_BOOL isht40, HAL_BOOL shortPreamble);
+
+/*
+ * Calculate the duration of an 11n frame.
+ */
+extern uint32_t __ahdecl ath_computedur_ht(uint32_t frameLen, uint16_t rate,
+ int streams, HAL_BOOL isht40, HAL_BOOL isShortGI);
+
+/*
+ * Calculate the transmit duration of a legacy frame.
*/
extern uint16_t __ahdecl ath_hal_computetxtime(struct ath_hal *,
const HAL_RATE_TABLE *rates, uint32_t frameLen,
OpenPOWER on IntegriCloud