Firmware sometimes returns erroneous timestamps
authorIanR778 <ianr778@zippymail.info>
Wed, 8 Oct 2014 00:11:04 +0000 (01:11 +0100)
committerIanR778 <ianr778@zippymail.info>
Wed, 8 Oct 2014 00:11:04 +0000 (01:11 +0100)
Added proper synchronization while handling lower 32 bit and upper 32 bit parts in ar5416GetTsf64().

target_firmware/wlan/ar5416_hw.c

index 3f3c4bc74cc9e2c9b473e42040b7f5c5883c29a4..4d2a9f4bcc6bbc4202cdd83b65bf5acb34ec282a 100644 (file)
@@ -275,14 +275,23 @@ ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
 /* TSF Handling */
 /****************/
 
+#define ATH9K_HTC_MAX_TSF_READ 3
+
 u_int64_t ar5416GetTsf64(struct ath_hal *ah)
 {
-        u_int64_t tsf;
-
-       tsf = ioread32_mac(AR_TSF_U32);
-       tsf = (tsf << 32) | ioread32_mac(AR_TSF_L32);
+       a_uint32_t tsf_lower, tsf_upper1, tsf_upper2;
+       a_int32_t i;
+
+       tsf_upper1 = ioread32_mac(AR_TSF_U32);
+       for (i = 0; i < ATH9K_HTC_MAX_TSF_READ; i++) {
+               tsf_lower = ioread32_mac(AR_TSF_L32);
+               tsf_upper2 = ioread32_mac(AR_TSF_U32);
+               if (tsf_upper2 == tsf_upper1)
+                       break;
+               tsf_upper1 = tsf_upper2;
+       }
 
-        return tsf;
+       return (((u_int64_t)tsf_upper2 << 32) | tsf_lower);
 }
 
 /******/