svn commit: r218011 - head/sys/dev/ath/ath_hal

Adrian Chadd adrian at FreeBSD.org
Fri Jan 28 08:35:56 UTC 2011


Author: adrian
Date: Fri Jan 28 08:35:55 2011
New Revision: 218011
URL: http://svn.freebsd.org/changeset/base/218011

Log:
  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

Modified:
  head/sys/dev/ath/ath_hal/ah.c
  head/sys/dev/ath/ath_hal/ah.h

Modified: head/sys/dev/ath/ath_hal/ah.c
==============================================================================
--- head/sys/dev/ath/ath_hal/ah.c	Fri Jan 28 08:00:57 2011	(r218010)
+++ head/sys/dev/ath/ath_hal/ah.c	Fri Jan 28 08:35:55 2011	(r218011)
@@ -234,6 +234,78 @@ ath_hal_reverseBits(uint32_t val, uint32
 	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.

Modified: head/sys/dev/ath/ath_hal/ah.h
==============================================================================
--- head/sys/dev/ath/ath_hal/ah.h	Fri Jan 28 08:00:57 2011	(r218010)
+++ head/sys/dev/ath/ath_hal/ah.h	Fri Jan 28 08:35:55 2011	(r218011)
@@ -882,7 +882,20 @@ extern	void __ahdecl ath_hal_process_noi
 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,


More information about the svn-src-all mailing list