/*
- * Copyright (c) 2014-2015 Qualcomm Atheros, Inc.
+ * Copyright (c) 2014-2016 Qualcomm Atheros, Inc.
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
        return min(max_agg_size, req_agg_wsize);
 }
 
-/* Block Ack - Rx side (recipient */
+/* Block Ack - Rx side (recipient) */
 int wil_addba_rx_request(struct wil6210_priv *wil, u8 cidxtid,
                         u8 dialog_token, __le16 ba_param_set,
                         __le16 ba_timeout, __le16 ba_seq_ctrl)
-{
-       struct wil_back_rx *req = kzalloc(sizeof(*req), GFP_KERNEL);
-
-       if (!req)
-               return -ENOMEM;
-
-       req->cidxtid = cidxtid;
-       req->dialog_token = dialog_token;
-       req->ba_param_set = le16_to_cpu(ba_param_set);
-       req->ba_timeout = le16_to_cpu(ba_timeout);
-       req->ba_seq_ctrl = le16_to_cpu(ba_seq_ctrl);
-
-       mutex_lock(&wil->back_rx_mutex);
-       list_add_tail(&req->list, &wil->back_rx_pending);
-       mutex_unlock(&wil->back_rx_mutex);
-
-       queue_work(wil->wq_service, &wil->back_rx_worker);
-
-       return 0;
-}
-
-static void wil_back_rx_handle(struct wil6210_priv *wil,
-                              struct wil_back_rx *req)
 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
 {
+       u16 param_set = le16_to_cpu(ba_param_set);
+       u16 agg_timeout = le16_to_cpu(ba_timeout);
+       u16 seq_ctrl = le16_to_cpu(ba_seq_ctrl);
        struct wil_sta_info *sta;
        u8 cid, tid;
        u16 agg_wsize = 0;
         * bits 2..5: TID
         * bits 6..15: buffer size
         */
-       u16 req_agg_wsize = WIL_GET_BITS(req->ba_param_set, 6, 15);
-       bool agg_amsdu = !!(req->ba_param_set & BIT(0));
-       int ba_policy = req->ba_param_set & BIT(1);
-       u16 agg_timeout = req->ba_timeout;
+       u16 req_agg_wsize = WIL_GET_BITS(param_set, 6, 15);
+       bool agg_amsdu = !!(param_set & BIT(0));
+       int ba_policy = param_set & BIT(1);
        u16 status = WLAN_STATUS_SUCCESS;
-       u16 ssn = req->ba_seq_ctrl >> 4;
+       u16 ssn = seq_ctrl >> 4;
        struct wil_tid_ampdu_rx *r;
-       int rc;
+       int rc = 0;
 
        might_sleep();
-       parse_cidxtid(req->cidxtid, &cid, &tid);
+       parse_cidxtid(cidxtid, &cid, &tid);
 
        /* sanity checks */
        if (cid >= WIL6210_MAX_CID) {
                wil_err(wil, "BACK: invalid CID %d\n", cid);
-               return;
+               rc = -EINVAL;
+               goto out;
        }
 
        sta = &wil->sta[cid];
        if (sta->status != wil_sta_connected) {
                wil_err(wil, "BACK: CID %d not connected\n", cid);
-               return;
+               rc = -EINVAL;
+               goto out;
        }
 
        wil_dbg_wmi(wil,
                    "ADDBA request for CID %d %pM TID %d size %d timeout %d AMSDU%s policy %d token %d SSN 0x%03x\n",
-                   cid, sta->addr, tid, req_agg_wsize, req->ba_timeout,
-                   agg_amsdu ? "+" : "-", !!ba_policy, req->dialog_token, ssn);
+                   cid, sta->addr, tid, req_agg_wsize, agg_timeout,
+                   agg_amsdu ? "+" : "-", !!ba_policy, dialog_token, ssn);
 
        /* apply policies */
        if (ba_policy) {
        if (status == WLAN_STATUS_SUCCESS)
                agg_wsize = wil_agg_size(wil, req_agg_wsize);
 
-       rc = wmi_addba_rx_resp(wil, cid, tid, req->dialog_token, status,
+       rc = wmi_addba_rx_resp(wil, cid, tid, dialog_token, status,
                               agg_amsdu, agg_wsize, agg_timeout);
-       if (rc || (status != WLAN_STATUS_SUCCESS))
-               return;
+       if (rc || (status != WLAN_STATUS_SUCCESS)) {
+               wil_err(wil, "%s: do not apply ba, rc(%d), status(%d)\n",
+                       __func__, rc, status);
+               goto out;
+       }
 
        /* apply */
        r = wil_tid_ampdu_rx_alloc(wil, agg_wsize, ssn);
        wil_tid_ampdu_rx_free(wil, sta->tid_rx[tid]);
        sta->tid_rx[tid] = r;
        spin_unlock_bh(&sta->tid_rx_lock);
-}
-
-void wil_back_rx_flush(struct wil6210_priv *wil)
-{
-       struct wil_back_rx *evt, *t;
 
-       wil_dbg_misc(wil, "%s()\n", __func__);
-
-       mutex_lock(&wil->back_rx_mutex);
-
-       list_for_each_entry_safe(evt, t, &wil->back_rx_pending, list) {
-               list_del(&evt->list);
-               kfree(evt);
-       }
-
-       mutex_unlock(&wil->back_rx_mutex);
-}
-
-/* Retrieve next ADDBA request from the pending list */
-static struct list_head *next_back_rx(struct wil6210_priv *wil)
-{
-       struct list_head *ret = NULL;
-
-       mutex_lock(&wil->back_rx_mutex);
-
-       if (!list_empty(&wil->back_rx_pending)) {
-               ret = wil->back_rx_pending.next;
-               list_del(ret);
-       }
-
-       mutex_unlock(&wil->back_rx_mutex);
-
-       return ret;
-}
-
-void wil_back_rx_worker(struct work_struct *work)
-{
-       struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
-                                               back_rx_worker);
-       struct wil_back_rx *evt;
-       struct list_head *lh;
-
-       while ((lh = next_back_rx(wil)) != NULL) {
-               evt = list_entry(lh, struct wil_back_rx, list);
-
-               wil_back_rx_handle(wil, evt);
-               kfree(evt);
-       }
+out:
+       return rc;
 }
 
-/* BACK - Tx (originator) side */
-static void wil_back_tx_handle(struct wil6210_priv *wil,
-                              struct wil_back_tx *req)
+/* BACK - Tx side (originator) */
+int wil_addba_tx_request(struct wil6210_priv *wil, u8 ringid, u16 wsize)
 {
-       struct vring_tx_data *txdata = &wil->vring_tx_data[req->ringid];
-       int rc;
+       u8 agg_wsize = wil_agg_size(wil, wsize);
+       u16 agg_timeout = 0;
+       struct vring_tx_data *txdata = &wil->vring_tx_data[ringid];
+       int rc = 0;
 
        if (txdata->addba_in_progress) {
                wil_dbg_misc(wil, "ADDBA for vring[%d] already in progress\n",
-                            req->ringid);
-               return;
+                            ringid);
+               goto out;
        }
        if (txdata->agg_wsize) {
                wil_dbg_misc(wil,
-                            "ADDBA for vring[%d] already established wsize %d\n",
-                            req->ringid, txdata->agg_wsize);
-               return;
+                            "ADDBA for vring[%d] already done for wsize %d\n",
+                            ringid, txdata->agg_wsize);
+               goto out;
        }
        txdata->addba_in_progress = true;
-       rc = wmi_addba(wil, req->ringid, req->agg_wsize, req->agg_timeout);
-       if (rc)
+       rc = wmi_addba(wil, ringid, agg_wsize, agg_timeout);
+       if (rc) {
+               wil_err(wil, "%s: wmi_addba failed, rc (%d)", __func__, rc);
                txdata->addba_in_progress = false;
-}
-
-static struct list_head *next_back_tx(struct wil6210_priv *wil)
-{
-       struct list_head *ret = NULL;
-
-       mutex_lock(&wil->back_tx_mutex);
-
-       if (!list_empty(&wil->back_tx_pending)) {
-               ret = wil->back_tx_pending.next;
-               list_del(ret);
-       }
-
-       mutex_unlock(&wil->back_tx_mutex);
-
-       return ret;
-}
-
-void wil_back_tx_worker(struct work_struct *work)
-{
-       struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
-                                                back_tx_worker);
-       struct wil_back_tx *evt;
-       struct list_head *lh;
-
-       while ((lh = next_back_tx(wil)) != NULL) {
-               evt = list_entry(lh, struct wil_back_tx, list);
-
-               wil_back_tx_handle(wil, evt);
-               kfree(evt);
        }
-}
-
-void wil_back_tx_flush(struct wil6210_priv *wil)
-{
-       struct wil_back_tx *evt, *t;
-
-       wil_dbg_misc(wil, "%s()\n", __func__);
-
-       mutex_lock(&wil->back_tx_mutex);
-
-       list_for_each_entry_safe(evt, t, &wil->back_tx_pending, list) {
-               list_del(&evt->list);
-               kfree(evt);
-       }
-
-       mutex_unlock(&wil->back_tx_mutex);
-}
-
-int wil_addba_tx_request(struct wil6210_priv *wil, u8 ringid, u16 wsize)
-{
-       struct wil_back_tx *req = kzalloc(sizeof(*req), GFP_KERNEL);
-
-       if (!req)
-               return -ENOMEM;
 
-       req->ringid = ringid;
-       req->agg_wsize = wil_agg_size(wil, wsize);
-       req->agg_timeout = 0;
-
-       mutex_lock(&wil->back_tx_mutex);
-       list_add_tail(&req->list, &wil->back_tx_pending);
-       mutex_unlock(&wil->back_tx_mutex);
-
-       queue_work(wil->wq_service, &wil->back_tx_worker);
-
-       return 0;
+out:
+       return rc;
 }