blob: ada809f576fe56c290a9150728b5b08e358c2d53 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: 802.11n RX Re-ordering
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27#include "11n_rxreorder.h"
28
29/*
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070030 * This function dispatches all packets in the Rx reorder table until the
31 * start window.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032 *
33 * There could be holes in the buffer, which are skipped by the function.
34 * Since the buffer is linear, the function uses rotation to simulate
35 * circular buffer.
36 */
Yogesh Ashok Powarab581472011-11-07 21:41:08 -080037static void
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070038mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv,
39 struct mwifiex_rx_reorder_tbl *tbl, int start_win)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070040{
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070041 int pkt_to_send, i;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070042 void *rx_tmp_ptr;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070043 unsigned long flags;
44
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070045 pkt_to_send = (start_win > tbl->start_win) ?
46 min((start_win - tbl->start_win), tbl->win_size) :
47 tbl->win_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070048
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070049 for (i = 0; i < pkt_to_send; ++i) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070050 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
51 rx_tmp_ptr = NULL;
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070052 if (tbl->rx_reorder_ptr[i]) {
53 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
54 tbl->rx_reorder_ptr[i] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070055 }
56 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -070057 if (rx_tmp_ptr) {
58 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
59 mwifiex_handle_uap_rx_forward(priv, rx_tmp_ptr);
60 else
Avinash Patilf3b369e2012-10-19 19:19:21 -070061 mwifiex_process_rx_packet(priv, rx_tmp_ptr);
Avinash Patild1cf3b92012-08-03 18:06:09 -070062 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070063 }
64
65 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
66 /*
67 * We don't have a circular buffer, hence use rotation to simulate
68 * circular buffer
69 */
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070070 for (i = 0; i < tbl->win_size - pkt_to_send; ++i) {
71 tbl->rx_reorder_ptr[i] = tbl->rx_reorder_ptr[pkt_to_send + i];
72 tbl->rx_reorder_ptr[pkt_to_send + i] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073 }
74
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070075 tbl->start_win = start_win;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077}
78
79/*
80 * This function dispatches all packets in the Rx reorder table until
81 * a hole is found.
82 *
83 * The start window is adjusted automatically when a hole is located.
84 * Since the buffer is linear, the function uses rotation to simulate
85 * circular buffer.
86 */
Yogesh Ashok Powarab581472011-11-07 21:41:08 -080087static void
Bing Zhao5e6e3a92011-03-21 18:00:50 -070088mwifiex_11n_scan_and_dispatch(struct mwifiex_private *priv,
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070089 struct mwifiex_rx_reorder_tbl *tbl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090{
91 int i, j, xchg;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070092 void *rx_tmp_ptr;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093 unsigned long flags;
94
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070095 for (i = 0; i < tbl->win_size; ++i) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070096 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -070097 if (!tbl->rx_reorder_ptr[i]) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070098 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
99 break;
100 }
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700101 rx_tmp_ptr = tbl->rx_reorder_ptr[i];
102 tbl->rx_reorder_ptr[i] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700103 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700104
105 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
106 mwifiex_handle_uap_rx_forward(priv, rx_tmp_ptr);
107 else
Avinash Patilf3b369e2012-10-19 19:19:21 -0700108 mwifiex_process_rx_packet(priv, rx_tmp_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700109 }
110
111 spin_lock_irqsave(&priv->rx_pkt_lock, flags);
112 /*
113 * We don't have a circular buffer, hence use rotation to simulate
114 * circular buffer
115 */
116 if (i > 0) {
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700117 xchg = tbl->win_size - i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700118 for (j = 0; j < xchg; ++j) {
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700119 tbl->rx_reorder_ptr[j] = tbl->rx_reorder_ptr[i + j];
120 tbl->rx_reorder_ptr[i + j] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 }
122 }
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700123 tbl->start_win = (tbl->start_win + i) & (MAX_TID_VALUE - 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124 spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125}
126
127/*
128 * This function deletes the Rx reorder table and frees the memory.
129 *
130 * The function stops the associated timer and dispatches all the
131 * pending packets in the Rx reorder table before deletion.
132 */
133static void
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700134mwifiex_del_rx_reorder_entry(struct mwifiex_private *priv,
135 struct mwifiex_rx_reorder_tbl *tbl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700136{
137 unsigned long flags;
138
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700139 if (!tbl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700140 return;
141
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700142 mwifiex_11n_dispatch_pkt(priv, tbl, (tbl->start_win + tbl->win_size) &
143 (MAX_TID_VALUE - 1));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700144
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700145 del_timer(&tbl->timer_context.timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700146
147 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700148 list_del(&tbl->list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700149 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
150
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700151 kfree(tbl->rx_reorder_ptr);
152 kfree(tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153}
154
155/*
156 * This function returns the pointer to an entry in Rx reordering
157 * table which matches the given TA/TID pair.
158 */
Avinash Patild1cf3b92012-08-03 18:06:09 -0700159struct mwifiex_rx_reorder_tbl *
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700160mwifiex_11n_get_rx_reorder_tbl(struct mwifiex_private *priv, int tid, u8 *ta)
161{
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700162 struct mwifiex_rx_reorder_tbl *tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700163 unsigned long flags;
164
165 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700166 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list) {
167 if (!memcmp(tbl->ta, ta, ETH_ALEN) && tbl->tid == tid) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700168 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
169 flags);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700170 return tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700171 }
172 }
173 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
174
175 return NULL;
176}
177
Avinash Patil3e238a12012-08-03 18:06:11 -0700178/* This function retrieves the pointer to an entry in Rx reordering
179 * table which matches the given TA and deletes it.
180 */
181void mwifiex_11n_del_rx_reorder_tbl_by_ta(struct mwifiex_private *priv, u8 *ta)
182{
183 struct mwifiex_rx_reorder_tbl *tbl, *tmp;
184 unsigned long flags;
185
186 if (!ta)
187 return;
188
189 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
190 list_for_each_entry_safe(tbl, tmp, &priv->rx_reorder_tbl_ptr, list) {
191 if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
192 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock,
193 flags);
194 mwifiex_del_rx_reorder_entry(priv, tbl);
195 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
196 }
197 }
198 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
199
200 return;
201}
202
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700203/*
204 * This function finds the last sequence number used in the packets
205 * buffered in Rx reordering table.
206 */
207static int
208mwifiex_11n_find_last_seq_num(struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr)
209{
210 int i;
211
212 for (i = (rx_reorder_tbl_ptr->win_size - 1); i >= 0; --i)
213 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
214 return i;
215
216 return -1;
217}
218
219/*
220 * This function flushes all the packets in Rx reordering table.
221 *
222 * The function checks if any packets are currently buffered in the
223 * table or not. In case there are packets available, it dispatches
224 * them and then dumps the Rx reordering table.
225 */
226static void
227mwifiex_flush_data(unsigned long context)
228{
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700229 struct reorder_tmr_cnxt *ctx =
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700230 (struct reorder_tmr_cnxt *) context;
231 int start_win;
232
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700233 start_win = mwifiex_11n_find_last_seq_num(ctx->ptr);
Yogesh Ashok Powarbb7de2b2012-03-12 19:35:12 -0700234
235 if (start_win < 0)
236 return;
237
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700238 dev_dbg(ctx->priv->adapter->dev, "info: flush data %d\n", start_win);
239 mwifiex_11n_dispatch_pkt(ctx->priv, ctx->ptr,
240 (ctx->ptr->start_win + start_win + 1) &
241 (MAX_TID_VALUE - 1));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700242}
243
244/*
245 * This function creates an entry in Rx reordering table for the
246 * given TA/TID.
247 *
248 * The function also initializes the entry with sequence number, window
249 * size as well as initializes the timer.
250 *
251 * If the received TA/TID pair is already present, all the packets are
252 * dispatched and the window size is moved until the SSN.
253 */
254static void
255mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700256 int tid, int win_size, int seq_num)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700257{
258 int i;
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700259 struct mwifiex_rx_reorder_tbl *tbl, *new_node;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260 u16 last_seq = 0;
261 unsigned long flags;
Avinash Patil5a009ad2012-08-03 18:06:10 -0700262 struct mwifiex_sta_node *node;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263
264 /*
265 * If we get a TID, ta pair which is already present dispatch all the
266 * the packets and move the window size until the ssn
267 */
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700268 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
269 if (tbl) {
270 mwifiex_11n_dispatch_pkt(priv, tbl, seq_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271 return;
272 }
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700273 /* if !tbl then create one */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000275 if (!new_node)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700277
278 INIT_LIST_HEAD(&new_node->list);
279 new_node->tid = tid;
280 memcpy(new_node->ta, ta, ETH_ALEN);
281 new_node->start_win = seq_num;
Avinash Patil5a009ad2012-08-03 18:06:10 -0700282
283 if (mwifiex_queuing_ra_based(priv)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700284 dev_dbg(priv->adapter->dev,
Avinash Patil5a009ad2012-08-03 18:06:10 -0700285 "info: AP/ADHOC:last_seq=%d start_win=%d\n",
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700286 last_seq, new_node->start_win);
Avinash Patil5a009ad2012-08-03 18:06:10 -0700287 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
288 node = mwifiex_get_sta_entry(priv, ta);
289 if (node)
290 last_seq = node->rx_seq[tid];
291 }
292 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700293 last_seq = priv->rx_seq[tid];
Avinash Patil5a009ad2012-08-03 18:06:10 -0700294 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700295
Stone Piao92583922012-06-20 20:21:10 -0700296 if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
297 last_seq >= new_node->start_win)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298 new_node->start_win = last_seq + 1;
299
300 new_node->win_size = win_size;
Avinash Patil2db96c32012-09-27 19:00:10 -0700301 new_node->flags = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700302
303 new_node->rx_reorder_ptr = kzalloc(sizeof(void *) * win_size,
304 GFP_KERNEL);
305 if (!new_node->rx_reorder_ptr) {
306 kfree((u8 *) new_node);
307 dev_err(priv->adapter->dev,
308 "%s: failed to alloc reorder_ptr\n", __func__);
309 return;
310 }
311
312 new_node->timer_context.ptr = new_node;
313 new_node->timer_context.priv = priv;
314
315 init_timer(&new_node->timer_context.timer);
316 new_node->timer_context.timer.function = mwifiex_flush_data;
317 new_node->timer_context.timer.data =
318 (unsigned long) &new_node->timer_context;
319
320 for (i = 0; i < win_size; ++i)
321 new_node->rx_reorder_ptr[i] = NULL;
322
323 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
324 list_add_tail(&new_node->list, &priv->rx_reorder_tbl_ptr);
325 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700326}
327
328/*
329 * This function prepares command for adding a BA request.
330 *
331 * Preparation includes -
332 * - Setting command ID and proper size
333 * - Setting add BA request buffer
334 * - Ensuring correct endian-ness
335 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700336int mwifiex_cmd_11n_addba_req(struct host_cmd_ds_command *cmd, void *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337{
Joe Perches2c208892012-06-04 12:44:17 +0000338 struct host_cmd_ds_11n_addba_req *add_ba_req = &cmd->params.add_ba_req;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700339
340 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_REQ);
341 cmd->size = cpu_to_le16(sizeof(*add_ba_req) + S_DS_GEN);
342 memcpy(add_ba_req, data_buf, sizeof(*add_ba_req));
343
344 return 0;
345}
346
347/*
348 * This function prepares command for adding a BA response.
349 *
350 * Preparation includes -
351 * - Setting command ID and proper size
352 * - Setting add BA response buffer
353 * - Ensuring correct endian-ness
354 */
355int mwifiex_cmd_11n_addba_rsp_gen(struct mwifiex_private *priv,
356 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700357 struct host_cmd_ds_11n_addba_req
358 *cmd_addba_req)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700359{
Joe Perches2c208892012-06-04 12:44:17 +0000360 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &cmd->params.add_ba_rsp;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700361 u8 tid;
362 int win_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 uint16_t block_ack_param_set;
364
365 cmd->command = cpu_to_le16(HostCmd_CMD_11N_ADDBA_RSP);
366 cmd->size = cpu_to_le16(sizeof(*add_ba_rsp) + S_DS_GEN);
367
368 memcpy(add_ba_rsp->peer_mac_addr, cmd_addba_req->peer_mac_addr,
369 ETH_ALEN);
370 add_ba_rsp->dialog_token = cmd_addba_req->dialog_token;
371 add_ba_rsp->block_ack_tmo = cmd_addba_req->block_ack_tmo;
372 add_ba_rsp->ssn = cmd_addba_req->ssn;
373
374 block_ack_param_set = le16_to_cpu(cmd_addba_req->block_ack_param_set);
375 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
376 >> BLOCKACKPARAM_TID_POS;
377 add_ba_rsp->status_code = cpu_to_le16(ADDBA_RSP_STATUS_ACCEPT);
378 block_ack_param_set &= ~IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
379 /* We donot support AMSDU inside AMPDU, hence reset the bit */
380 block_ack_param_set &= ~BLOCKACKPARAM_AMSDU_SUPP_MASK;
381 block_ack_param_set |= (priv->add_ba_param.rx_win_size <<
382 BLOCKACKPARAM_WINSIZE_POS);
383 add_ba_rsp->block_ack_param_set = cpu_to_le16(block_ack_param_set);
384 win_size = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
385 & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
386 >> BLOCKACKPARAM_WINSIZE_POS;
387 cmd_addba_req->block_ack_param_set = cpu_to_le16(block_ack_param_set);
388
389 mwifiex_11n_create_rx_reorder_tbl(priv, cmd_addba_req->peer_mac_addr,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700390 tid, win_size,
391 le16_to_cpu(cmd_addba_req->ssn));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 return 0;
393}
394
395/*
396 * This function prepares command for deleting a BA request.
397 *
398 * Preparation includes -
399 * - Setting command ID and proper size
400 * - Setting del BA request buffer
401 * - Ensuring correct endian-ness
402 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700403int mwifiex_cmd_11n_delba(struct host_cmd_ds_command *cmd, void *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404{
Joe Perches2c208892012-06-04 12:44:17 +0000405 struct host_cmd_ds_11n_delba *del_ba = &cmd->params.del_ba;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406
407 cmd->command = cpu_to_le16(HostCmd_CMD_11N_DELBA);
408 cmd->size = cpu_to_le16(sizeof(*del_ba) + S_DS_GEN);
409 memcpy(del_ba, data_buf, sizeof(*del_ba));
410
411 return 0;
412}
413
414/*
415 * This function identifies if Rx reordering is needed for a received packet.
416 *
417 * In case reordering is required, the function will do the reordering
418 * before sending it to kernel.
419 *
420 * The Rx reorder table is checked first with the received TID/TA pair. If
421 * not found, the received packet is dispatched immediately. But if found,
422 * the packet is reordered and all the packets in the updated Rx reordering
423 * table is dispatched until a hole is found.
424 *
425 * For sequence number less than the starting window, the packet is dropped.
426 */
427int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *priv,
428 u16 seq_num, u16 tid,
429 u8 *ta, u8 pkt_type, void *payload)
430{
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700431 struct mwifiex_rx_reorder_tbl *tbl;
Yogesh Ashok Powarab581472011-11-07 21:41:08 -0800432 int start_win, end_win, win_size;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700433 u16 pkt_index;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700434
Joe Perches2c208892012-06-04 12:44:17 +0000435 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid, ta);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700436 if (!tbl) {
Avinash Patild1cf3b92012-08-03 18:06:09 -0700437 if (pkt_type != PKT_TYPE_BAR) {
438 if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
439 mwifiex_handle_uap_rx_forward(priv, payload);
440 else
Avinash Patilf3b369e2012-10-19 19:19:21 -0700441 mwifiex_process_rx_packet(priv, payload);
Avinash Patild1cf3b92012-08-03 18:06:09 -0700442 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700443 return 0;
444 }
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700445 start_win = tbl->start_win;
446 win_size = tbl->win_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 end_win = ((start_win + win_size) - 1) & (MAX_TID_VALUE - 1);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700448 del_timer(&tbl->timer_context.timer);
449 mod_timer(&tbl->timer_context.timer,
Bing Zhao4587eea2013-04-19 17:44:44 -0700450 jiffies + msecs_to_jiffies(MIN_FLUSH_TIMER_MS * win_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700451
452 /*
453 * If seq_num is less then starting win then ignore and drop the
454 * packet
455 */
Avinash Patil2db96c32012-09-27 19:00:10 -0700456 if (tbl->flags & RXREOR_FORCE_NO_DROP) {
457 dev_dbg(priv->adapter->dev,
458 "RXREOR_FORCE_NO_DROP when HS is activated\n");
459 tbl->flags &= ~RXREOR_FORCE_NO_DROP;
460 } else {
461 if ((start_win + TWOPOW11) > (MAX_TID_VALUE - 1)) {
462 if (seq_num >= ((start_win + TWOPOW11) &
463 (MAX_TID_VALUE - 1)) &&
464 seq_num < start_win)
465 return -1;
466 } else if ((seq_num < start_win) ||
467 (seq_num > (start_win + TWOPOW11))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468 return -1;
Avinash Patil2db96c32012-09-27 19:00:10 -0700469 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 }
471
472 /*
473 * If this packet is a BAR we adjust seq_num as
474 * WinStart = seq_num
475 */
476 if (pkt_type == PKT_TYPE_BAR)
477 seq_num = ((seq_num + win_size) - 1) & (MAX_TID_VALUE - 1);
478
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700479 if (((end_win < start_win) &&
Avinash Patil2db96c32012-09-27 19:00:10 -0700480 (seq_num < start_win) && (seq_num > end_win)) ||
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700481 ((end_win > start_win) && ((seq_num > end_win) ||
482 (seq_num < start_win)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700483 end_win = seq_num;
484 if (((seq_num - win_size) + 1) >= 0)
485 start_win = (end_win - win_size) + 1;
486 else
487 start_win = (MAX_TID_VALUE - (win_size - seq_num)) + 1;
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700488 mwifiex_11n_dispatch_pkt(priv, tbl, start_win);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700489 }
490
491 if (pkt_type != PKT_TYPE_BAR) {
492 if (seq_num >= start_win)
493 pkt_index = seq_num - start_win;
494 else
495 pkt_index = (seq_num+MAX_TID_VALUE) - start_win;
496
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700497 if (tbl->rx_reorder_ptr[pkt_index])
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498 return -1;
499
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700500 tbl->rx_reorder_ptr[pkt_index] = payload;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501 }
502
503 /*
504 * Dispatch all packets sequentially from start_win until a
505 * hole is found and adjust the start_win appropriately
506 */
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700507 mwifiex_11n_scan_and_dispatch(priv, tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508
Yogesh Ashok Powarab581472011-11-07 21:41:08 -0800509 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510}
511
512/*
513 * This function deletes an entry for a given TID/TA pair.
514 *
515 * The TID/TA are taken from del BA event body.
516 */
517void
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700518mwifiex_del_ba_tbl(struct mwifiex_private *priv, int tid, u8 *peer_mac,
519 u8 type, int initiator)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700520{
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700521 struct mwifiex_rx_reorder_tbl *tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522 struct mwifiex_tx_ba_stream_tbl *ptx_tbl;
523 u8 cleanup_rx_reorder_tbl;
524 unsigned long flags;
525
526 if (type == TYPE_DELBA_RECEIVE)
527 cleanup_rx_reorder_tbl = (initiator) ? true : false;
528 else
529 cleanup_rx_reorder_tbl = (initiator) ? false : true;
530
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700531 dev_dbg(priv->adapter->dev, "event: DELBA: %pM tid=%d initiator=%d\n",
532 peer_mac, tid, initiator);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700533
534 if (cleanup_rx_reorder_tbl) {
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700535 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 peer_mac);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700537 if (!tbl) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538 dev_dbg(priv->adapter->dev,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700539 "event: TID, TA not found in table\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 return;
541 }
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700542 mwifiex_del_rx_reorder_entry(priv, tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 } else {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700544 ptx_tbl = mwifiex_get_ba_tbl(priv, tid, peer_mac);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545 if (!ptx_tbl) {
546 dev_dbg(priv->adapter->dev,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700547 "event: TID, RA not found in table\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 return;
549 }
550
551 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
552 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, ptx_tbl);
553 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
554 }
555}
556
557/*
558 * This function handles the command response of an add BA response.
559 *
560 * Handling includes changing the header fields into CPU format and
561 * creating the stream, provided the add BA is accepted.
562 */
563int mwifiex_ret_11n_addba_resp(struct mwifiex_private *priv,
564 struct host_cmd_ds_command *resp)
565{
Joe Perches2c208892012-06-04 12:44:17 +0000566 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 int tid, win_size;
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700568 struct mwifiex_rx_reorder_tbl *tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 uint16_t block_ack_param_set;
570
571 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set);
572
573 tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK)
574 >> BLOCKACKPARAM_TID_POS;
575 /*
576 * Check if we had rejected the ADDBA, if yes then do not create
577 * the stream
578 */
579 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
580 win_size = (block_ack_param_set &
581 IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK)
582 >> BLOCKACKPARAM_WINSIZE_POS;
583
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700584 dev_dbg(priv->adapter->dev,
585 "cmd: ADDBA RSP: %pM tid=%d ssn=%d win_size=%d\n",
586 add_ba_rsp->peer_mac_addr, tid,
587 add_ba_rsp->ssn, win_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588 } else {
589 dev_err(priv->adapter->dev, "ADDBA RSP: failed %pM tid=%d)\n",
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700590 add_ba_rsp->peer_mac_addr, tid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700592 tbl = mwifiex_11n_get_rx_reorder_tbl(priv, tid,
593 add_ba_rsp->peer_mac_addr);
594 if (tbl)
595 mwifiex_del_rx_reorder_entry(priv, tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 }
597
598 return 0;
599}
600
601/*
602 * This function handles BA stream timeout event by preparing and sending
603 * a command to the firmware.
604 */
605void mwifiex_11n_ba_stream_timeout(struct mwifiex_private *priv,
606 struct host_cmd_ds_11n_batimeout *event)
607{
608 struct host_cmd_ds_11n_delba delba;
609
610 memset(&delba, 0, sizeof(struct host_cmd_ds_11n_delba));
611 memcpy(delba.peer_mac_addr, event->peer_mac_addr, ETH_ALEN);
612
613 delba.del_ba_param_set |=
614 cpu_to_le16((u16) event->tid << DELBA_TID_POS);
615 delba.del_ba_param_set |= cpu_to_le16(
616 (u16) event->origninator << DELBA_INITIATOR_POS);
617 delba.reason_code = cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700618 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA, 0, 0, &delba);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619}
620
621/*
622 * This function cleans up the Rx reorder table by deleting all the entries
623 * and re-initializing.
624 */
625void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
626{
627 struct mwifiex_rx_reorder_tbl *del_tbl_ptr, *tmp_node;
628 unsigned long flags;
629
630 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
631 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
632 &priv->rx_reorder_tbl_ptr, list) {
633 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
Yogesh Ashok Powar8c002282012-03-12 19:35:13 -0700634 mwifiex_del_rx_reorder_entry(priv, del_tbl_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
636 }
637 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
638
639 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
Stone Piao92583922012-06-20 20:21:10 -0700640 mwifiex_reset_11n_rx_seq_num(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641}
Avinash Patil2db96c32012-09-27 19:00:10 -0700642
643/*
644 * This function updates all rx_reorder_tbl's flags.
645 */
646void mwifiex_update_rxreor_flags(struct mwifiex_adapter *adapter, u8 flags)
647{
648 struct mwifiex_private *priv;
649 struct mwifiex_rx_reorder_tbl *tbl;
650 unsigned long lock_flags;
651 int i;
652
653 for (i = 0; i < adapter->priv_num; i++) {
654 priv = adapter->priv[i];
655 if (!priv)
656 continue;
657 if (list_empty(&priv->rx_reorder_tbl_ptr))
658 continue;
659
660 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, lock_flags);
661 list_for_each_entry(tbl, &priv->rx_reorder_tbl_ptr, list)
662 tbl->flags = flags;
663 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, lock_flags);
664 }
665
666 return;
667}