+static inline u16 get_tid(struct ieee80211_hdr *hdr)
+{
+ return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
+}
+
+/* This function will only work on uint32_t-aligned pointers! */
+static bool same_hdr(const void *_d0, const void *_d1)
+{
+ const uint32_t *d0 = _d0;
+ const uint32_t *d1 = _d1;
+
+ /* BUG_ON((unsigned long)d0 & 3 || (unsigned long)d1 & 3)) */
+ return !((d0[0] ^ d1[0]) | /* FC + DU */
+ (d0[1] ^ d1[1]) | /* addr1 */
+ (d0[2] ^ d1[2]) | (d0[3] ^ d1[3]) | /* addr2 + addr3 */
+ (d0[4] ^ d1[4])); /* addr3 */
+}
+
+static inline bool same_aggr(struct ieee80211_hdr *a, struct ieee80211_hdr *b)
+{
+ return (get_tid(a) == get_tid(b)) || same_hdr(a, b);
+}
+
+static void wlan_tx_ampdu_reset(unsigned int qidx)
+{
+ fw.wlan.ampdu_prev[qidx] = NULL;
+}
+
+static void wlan_tx_ampdu_end(unsigned int qidx)
+{
+ struct carl9170_tx_superframe *ht_prev = fw.wlan.ampdu_prev[qidx];
+
+ if (ht_prev)
+ ht_prev->f.hdr.mac.ba_end = 1;
+
+ wlan_tx_ampdu_reset(qidx);
+}
+
+static void wlan_tx_ampdu(struct carl9170_tx_superframe *super)
+{
+ unsigned int qidx = super->s.queue;
+ struct carl9170_tx_superframe *ht_prev = fw.wlan.ampdu_prev[qidx];
+
+ if (super->f.hdr.mac.ampdu) {
+ if (ht_prev &&
+ !same_aggr(&super->f.data.i3e, &ht_prev->f.data.i3e))
+ ht_prev->f.hdr.mac.ba_end = 1;
+ else
+ super->f.hdr.mac.ba_end = 0;
+
+ fw.wlan.ampdu_prev[qidx] = super;
+ } else {
+ wlan_tx_ampdu_end(qidx);
+ }
+}
+