فهرست منبع

qcacmn: Add circular arithmetic operations for MGMT Rx REO data

HW uses only 16-bits to represent MGMT packet counter and 32-bits to
represent global timestamp. Overflow is bound to happen with such sizes.
So, Host can't directly use regular comparison and subtract operators on
the REO data sent by the HW. Add support for operations that take
overflow into consideration.

CRs-Fixed: 3028771
Change-Id: I1c280409b023e0783bf05fe68351e071801f59bc
Shiva Krishna Pittala 4 سال پیش
والد
کامیت
ff4f258129
1فایلهای تغییر یافته به همراه73 افزوده شده و 0 حذف شده
  1. 73 0
      umac/cmn_services/mgmt_txrx/core/src/wlan_mgmt_txrx_rx_reo.c

+ 73 - 0
umac/cmn_services/mgmt_txrx/core/src/wlan_mgmt_txrx_rx_reo.c

@@ -22,3 +22,76 @@
 #include "wlan_mgmt_txrx_rx_reo_i.h"
 
 struct mgmt_rx_reo_context rx_reo_global;
+
+#define MGMT_RX_REO_PKT_CTR_HALF_RANGE (0x8000)
+#define MGMT_RX_REO_PKT_CTR_FULL_RANGE (MGMT_RX_REO_PKT_CTR_HALF_RANGE << 1)
+
+/**
+ * mgmt_rx_reo_compare_pkt_ctrs_gte() - Compare given mgmt packet counters
+ * @ctr1: Management packet counter1
+ * @ctr2: Management packet counter2
+ *
+ * We can't directly use the comparison operator here because the counters can
+ * overflow. But these counters have a property that the difference between
+ * them can never be greater than half the range of the data type.
+ * We can make use of this condition to detect which one is actually greater.
+ *
+ * Return: true if @ctr1 is greater than or equal to @ctr2, else false
+ */
+static inline bool
+mgmt_rx_reo_compare_pkt_ctrs_gte(uint16_t ctr1, uint16_t ctr2)
+{
+	uint16_t delta = ctr1 - ctr2;
+
+	return delta <= MGMT_RX_REO_PKT_CTR_HALF_RANGE;
+}
+
+/**
+ * mgmt_rx_reo_subtract_pkt_ctrs() - Subtract given mgmt packet counters
+ * @ctr1: Management packet counter1
+ * @ctr2: Management packet counter2
+ *
+ * We can't directly use the subtract operator here because the counters can
+ * overflow. But these counters have a property that the difference between
+ * them can never be greater than half the range of the data type.
+ * We can make use of this condition to detect whichone is actually greater and
+ * return the difference accordingly.
+ *
+ * Return: Difference between @ctr1 and @crt2
+ */
+static inline int
+mgmt_rx_reo_subtract_pkt_ctrs(uint16_t ctr1, uint16_t ctr2)
+{
+	uint16_t delta = ctr1 - ctr2;
+
+	/**
+	 * if delta is greater than half the range (i.e, ctr1 is actually
+	 * smaller than ctr2), then the result should be a negative number.
+	 * subtracting the entire range should give the correct value.
+	 */
+	if (delta > MGMT_RX_REO_PKT_CTR_HALF_RANGE)
+		return delta - MGMT_RX_REO_PKT_CTR_FULL_RANGE;
+
+	return delta;
+}
+
+#define MGMT_RX_REO_GLOBAL_TS_HALF_RANGE (0x80000000)
+/**
+ * mgmt_rx_reo_compare_global_timestamps_gte()-Compare given global timestamps
+ * @ts1: Global timestamp1
+ * @ts2: Global timestamp2
+ *
+ * We can't directly use the comparison operator here because the timestamps can
+ * overflow. But these timestamps have a property that the difference between
+ * them can never be greater than half the range of the data type.
+ * We can make use of this condition to detect which one is actually greater.
+ *
+ * Return: true if @ts1 is greater than or equal to @ts2, else false
+ */
+static inline bool
+mgmt_rx_reo_compare_global_timestamps_gte(uint32_t ts1, uint32_t ts2)
+{
+	uint32_t delta = ts1 - ts2;
+
+	return delta <= MGMT_RX_REO_GLOBAL_TS_HALF_RANGE;
+}