blob: 7b0ae2407083d6a873ac3bf38664bbaf666b6462 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: 802.11n
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
28/*
29 * Fills HT capability information field, AMPDU Parameters field, HT extended
30 * capability field, and supported MCS set fields.
31 *
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070032 * HT capability information field, AMPDU Parameters field, supported MCS set
33 * fields are retrieved from cfg80211 stack
Bing Zhao5e6e3a92011-03-21 18:00:50 -070034 *
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070035 * RD responder bit to set to clear in the extended capability header.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070036 */
37void
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070038mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type,
Bing Zhao5e6e3a92011-03-21 18:00:50 -070039 struct mwifiex_ie_types_htcap *ht_cap)
40{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041 uint16_t ht_ext_cap = le16_to_cpu(ht_cap->ht_cap.extended_ht_cap_info);
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070042 struct ieee80211_supported_band *sband =
43 priv->wdev->wiphy->bands[radio_type];
Bing Zhao5e6e3a92011-03-21 18:00:50 -070044
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070045 ht_cap->ht_cap.ampdu_params_info =
46 (sband->ht_cap.ampdu_factor &
Yogesh Ashok Powar84266842012-03-13 19:22:34 -070047 IEEE80211_HT_AMPDU_PARM_FACTOR) |
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070048 ((sband->ht_cap.ampdu_density <<
49 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) &
50 IEEE80211_HT_AMPDU_PARM_DENSITY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070051
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070052 memcpy((u8 *) &ht_cap->ht_cap.mcs, &sband->ht_cap.mcs,
Yogesh Ashok Powar84266842012-03-13 19:22:34 -070053 sizeof(sband->ht_cap.mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -070054
Bing Zhaoeecd8252011-03-28 17:55:41 -070055 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Amitkumar Karward35f1032013-01-02 16:56:00 -080056 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
57 (priv->adapter->sec_chan_offset !=
58 IEEE80211_HT_PARAM_CHA_SEC_NONE)))
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
60 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
61
62 /* Clear RD responder bit */
Amitkumar Karwara3731652011-04-15 20:50:41 -070063 ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064
Amitkumar Karwara46b7b52011-04-27 19:13:12 -070065 ht_cap->ht_cap.cap_info = cpu_to_le16(sband->ht_cap.cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070066 ht_cap->ht_cap.extended_ht_cap_info = cpu_to_le16(ht_ext_cap);
67}
68
69/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070070 * This function returns the pointer to an entry in BA Stream
71 * table which matches the requested BA status.
72 */
73static struct mwifiex_tx_ba_stream_tbl *
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -070074mwifiex_get_ba_status(struct mwifiex_private *priv,
75 enum mwifiex_ba_status ba_status)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076{
77 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
78 unsigned long flags;
79
80 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
81 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
82 if (tx_ba_tsr_tbl->ba_status == ba_status) {
83 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
84 flags);
85 return tx_ba_tsr_tbl;
86 }
87 }
88 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
89 return NULL;
90}
91
92/*
93 * This function handles the command response of delete a block
94 * ack request.
95 *
96 * The function checks the response success status and takes action
97 * accordingly (send an add BA request in case of success, or recreate
98 * the deleted stream in case of failure, if the add BA was also
99 * initiated by us).
100 */
101int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
102 struct host_cmd_ds_command *resp)
103{
104 int tid;
105 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
Joe Perches2c208892012-06-04 12:44:17 +0000106 struct host_cmd_ds_11n_delba *del_ba = &resp->params.del_ba;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700107 uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set);
108
109 tid = del_ba_param_set >> DELBA_TID_POS;
110 if (del_ba->del_result == BA_RESULT_SUCCESS) {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700111 mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr,
112 TYPE_DELBA_SENT,
113 INITIATOR_BIT(del_ba_param_set));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700115 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 if (tx_ba_tbl)
117 mwifiex_send_addba(priv, tx_ba_tbl->tid,
118 tx_ba_tbl->ra);
119 } else { /*
120 * In case of failure, recreate the deleted stream in case
121 * we initiated the ADDBA
122 */
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700123 if (!INITIATOR_BIT(del_ba_param_set))
124 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700126 mwifiex_create_ba_tbl(priv, del_ba->peer_mac_addr, tid,
127 BA_SETUP_INPROGRESS);
128
129 tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS);
130
131 if (tx_ba_tbl)
132 mwifiex_del_ba_tbl(priv, tx_ba_tbl->tid, tx_ba_tbl->ra,
133 TYPE_DELBA_SENT, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700134 }
135
136 return 0;
137}
138
139/*
140 * This function handles the command response of add a block
141 * ack request.
142 *
143 * Handling includes changing the header fields to CPU formats, checking
144 * the response success status and taking actions accordingly (delete the
145 * BA stream table in case of failure).
146 */
147int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
148 struct host_cmd_ds_command *resp)
149{
150 int tid;
Joe Perches2c208892012-06-04 12:44:17 +0000151 struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700152 struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl;
153
154 add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn))
155 & SSN_MASK);
156
157 tid = (le16_to_cpu(add_ba_rsp->block_ack_param_set)
158 & IEEE80211_ADDBA_PARAM_TID_MASK)
159 >> BLOCKACKPARAM_TID_POS;
160 if (le16_to_cpu(add_ba_rsp->status_code) == BA_RESULT_SUCCESS) {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700161 tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700162 add_ba_rsp->peer_mac_addr);
163 if (tx_ba_tbl) {
164 dev_dbg(priv->adapter->dev, "info: BA stream complete\n");
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700165 tx_ba_tbl->ba_status = BA_SETUP_COMPLETE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166 } else {
167 dev_err(priv->adapter->dev, "BA stream not created\n");
168 }
169 } else {
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700170 mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr,
171 TYPE_DELBA_SENT, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172 if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
173 priv->aggr_prio_tbl[tid].ampdu_ap =
174 BA_STREAM_NOT_ALLOWED;
175 }
176
177 return 0;
178}
179
180/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181 * This function prepares command of reconfigure Tx buffer.
182 *
183 * Preparation includes -
184 * - Setting command ID, action and proper size
185 * - Setting Tx buffer size (for SET only)
186 * - Ensuring correct endian-ness
187 */
188int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv,
189 struct host_cmd_ds_command *cmd, int cmd_action,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700190 u16 *buf_size)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700191{
192 struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf;
193 u16 action = (u16) cmd_action;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700194
195 cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);
196 cmd->size =
197 cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN);
198 tx_buf->action = cpu_to_le16(action);
199 switch (action) {
200 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700201 dev_dbg(priv->adapter->dev, "cmd: set tx_buf=%d\n", *buf_size);
202 tx_buf->buff_size = cpu_to_le16(*buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700203 break;
204 case HostCmd_ACT_GEN_GET:
205 default:
206 tx_buf->buff_size = 0;
207 break;
208 }
209 return 0;
210}
211
212/*
213 * This function prepares command of AMSDU aggregation control.
214 *
215 * Preparation includes -
216 * - Setting command ID, action and proper size
217 * - Setting AMSDU control parameters (for SET only)
218 * - Ensuring correct endian-ness
219 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700220int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700221 int cmd_action,
222 struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700223{
224 struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl =
225 &cmd->params.amsdu_aggr_ctrl;
226 u16 action = (u16) cmd_action;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700227
228 cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL);
229 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl)
230 + S_DS_GEN);
231 amsdu_ctrl->action = cpu_to_le16(action);
232 switch (action) {
233 case HostCmd_ACT_GEN_SET:
234 amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable);
235 amsdu_ctrl->curr_buf_size = 0;
236 break;
237 case HostCmd_ACT_GEN_GET:
238 default:
239 amsdu_ctrl->curr_buf_size = 0;
240 break;
241 }
242 return 0;
243}
244
245/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246 * This function prepares 11n configuration command.
247 *
248 * Preparation includes -
249 * - Setting command ID, action and proper size
250 * - Setting HT Tx capability and HT Tx information fields
251 * - Ensuring correct endian-ness
252 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700253int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action,
254 struct mwifiex_ds_11n_tx_cfg *txcfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255{
256 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700257
258 cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG);
259 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN);
260 htcfg->action = cpu_to_le16(cmd_action);
261 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
262 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
263 return 0;
264}
265
266/*
267 * This function appends an 11n TLV to a buffer.
268 *
269 * Buffer allocation is responsibility of the calling
270 * function. No size validation is made here.
271 *
272 * The function fills up the following sections, if applicable -
273 * - HT capability IE
274 * - HT information IE (with channel list)
275 * - 20/40 BSS Coexistence IE
276 * - HT Extended Capabilities IE
277 */
278int
279mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
280 struct mwifiex_bssdescriptor *bss_desc,
281 u8 **buffer)
282{
283 struct mwifiex_ie_types_htcap *ht_cap;
284 struct mwifiex_ie_types_htinfo *ht_info;
285 struct mwifiex_ie_types_chan_list_param_set *chan_list;
286 struct mwifiex_ie_types_2040bssco *bss_co_2040;
287 struct mwifiex_ie_types_extcap *ext_cap;
288 int ret_len = 0;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700289 struct ieee80211_supported_band *sband;
290 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700291
292 if (!buffer || !*buffer)
293 return ret_len;
294
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700295 radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
296 sband = priv->wdev->wiphy->bands[radio_type];
297
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298 if (bss_desc->bcn_ht_cap) {
299 ht_cap = (struct mwifiex_ie_types_htcap *) *buffer;
300 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
301 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
302 ht_cap->header.len =
303 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
304 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
305 (u8 *) bss_desc->bcn_ht_cap +
306 sizeof(struct ieee_types_header),
307 le16_to_cpu(ht_cap->header.len));
308
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700309 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310
311 *buffer += sizeof(struct mwifiex_ie_types_htcap);
312 ret_len += sizeof(struct mwifiex_ie_types_htcap);
313 }
314
Johannes Berg074d46d2012-03-15 19:45:16 +0100315 if (bss_desc->bcn_ht_oper) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700316 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700317 ht_info = (struct mwifiex_ie_types_htinfo *) *buffer;
318 memset(ht_info, 0,
319 sizeof(struct mwifiex_ie_types_htinfo));
320 ht_info->header.type =
Johannes Berg074d46d2012-03-15 19:45:16 +0100321 cpu_to_le16(WLAN_EID_HT_OPERATION);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700322 ht_info->header.len =
Johannes Berg074d46d2012-03-15 19:45:16 +0100323 cpu_to_le16(
324 sizeof(struct ieee80211_ht_operation));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325
326 memcpy((u8 *) ht_info +
327 sizeof(struct mwifiex_ie_types_header),
Johannes Berg074d46d2012-03-15 19:45:16 +0100328 (u8 *) bss_desc->bcn_ht_oper +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329 sizeof(struct ieee_types_header),
330 le16_to_cpu(ht_info->header.len));
331
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700332 if (!(sband->ht_cap.cap &
333 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Johannes Berg074d46d2012-03-15 19:45:16 +0100334 ht_info->ht_oper.ht_param &=
Marc Yang6d2bd912011-03-25 19:47:02 -0700335 ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY |
336 IEEE80211_HT_PARAM_CHA_SEC_OFFSET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337
338 *buffer += sizeof(struct mwifiex_ie_types_htinfo);
339 ret_len += sizeof(struct mwifiex_ie_types_htinfo);
340 }
341
342 chan_list =
343 (struct mwifiex_ie_types_chan_list_param_set *) *buffer;
344 memset(chan_list, 0,
345 sizeof(struct mwifiex_ie_types_chan_list_param_set));
346 chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
347 chan_list->header.len = cpu_to_le16(
348 sizeof(struct mwifiex_ie_types_chan_list_param_set) -
349 sizeof(struct mwifiex_ie_types_header));
350 chan_list->chan_scan_param[0].chan_number =
Johannes Berg074d46d2012-03-15 19:45:16 +0100351 bss_desc->bcn_ht_oper->primary_chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352 chan_list->chan_scan_param[0].radio_type =
353 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
354
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700355 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
Johannes Berg074d46d2012-03-15 19:45:16 +0100356 bss_desc->bcn_ht_oper->ht_param &
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700357 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358 SET_SECONDARYCHAN(chan_list->chan_scan_param[0].
359 radio_type,
Johannes Berg074d46d2012-03-15 19:45:16 +0100360 (bss_desc->bcn_ht_oper->ht_param &
Marc Yang6d2bd912011-03-25 19:47:02 -0700361 IEEE80211_HT_PARAM_CHA_SEC_OFFSET));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362
363 *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
364 ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
365 }
366
367 if (bss_desc->bcn_bss_co_2040) {
368 bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer;
369 memset(bss_co_2040, 0,
370 sizeof(struct mwifiex_ie_types_2040bssco));
371 bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040);
372 bss_co_2040->header.len =
373 cpu_to_le16(sizeof(bss_co_2040->bss_co_2040));
374
375 memcpy((u8 *) bss_co_2040 +
376 sizeof(struct mwifiex_ie_types_header),
Joe Perches2c208892012-06-04 12:44:17 +0000377 bss_desc->bcn_bss_co_2040 +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700378 sizeof(struct ieee_types_header),
379 le16_to_cpu(bss_co_2040->header.len));
380
381 *buffer += sizeof(struct mwifiex_ie_types_2040bssco);
382 ret_len += sizeof(struct mwifiex_ie_types_2040bssco);
383 }
384
385 if (bss_desc->bcn_ext_cap) {
386 ext_cap = (struct mwifiex_ie_types_extcap *) *buffer;
387 memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap));
388 ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
389 ext_cap->header.len = cpu_to_le16(sizeof(ext_cap->ext_cap));
390
Joe Perches2c208892012-06-04 12:44:17 +0000391 memcpy((u8 *)ext_cap + sizeof(struct mwifiex_ie_types_header),
392 bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700393 le16_to_cpu(ext_cap->header.len));
394
395 *buffer += sizeof(struct mwifiex_ie_types_extcap);
396 ret_len += sizeof(struct mwifiex_ie_types_extcap);
397 }
398
399 return ret_len;
400}
401
402/*
403 * This function reconfigures the Tx buffer size in firmware.
404 *
405 * This function prepares a firmware command and issues it, if
406 * the current Tx buffer size is different from the one requested.
407 * Maximum configurable Tx buffer size is limited by the HT capability
408 * field value.
409 */
410void
411mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
412 struct mwifiex_bssdescriptor *bss_desc)
413{
414 u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700415 u16 tx_buf, curr_tx_buf_size = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700416
417 if (bss_desc->bcn_ht_cap) {
Marc Yang6d2bd912011-03-25 19:47:02 -0700418 if (le16_to_cpu(bss_desc->bcn_ht_cap->cap_info) &
419 IEEE80211_HT_CAP_MAX_AMSDU)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700420 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
421 else
422 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
423 }
424
425 tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
426
427 dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700428 max_amsdu, priv->adapter->max_tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429
430 if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
431 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
432 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
433 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
434 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
435 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
436 if (curr_tx_buf_size != tx_buf)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700437 mwifiex_send_cmd_async(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
438 HostCmd_ACT_GEN_SET, 0, &tx_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439}
440
441/*
442 * This function checks if the given pointer is valid entry of
443 * Tx BA Stream table.
444 */
445static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv,
446 struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr)
447{
448 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
449
450 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
451 if (tx_ba_tsr_tbl == tx_tbl_ptr)
452 return true;
453 }
454
455 return false;
456}
457
458/*
459 * This function deletes the given entry in Tx BA Stream table.
460 *
461 * The function also performs a validity check on the supplied
462 * pointer before trying to delete.
463 */
464void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv,
465 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl)
466{
467 if (!tx_ba_tsr_tbl &&
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700468 mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 return;
470
471 dev_dbg(priv->adapter->dev, "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl);
472
473 list_del(&tx_ba_tsr_tbl->list);
474
475 kfree(tx_ba_tsr_tbl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476}
477
478/*
479 * This function deletes all the entries in Tx BA Stream table.
480 */
481void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv)
482{
483 int i;
484 struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node;
485 unsigned long flags;
486
487 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
488 list_for_each_entry_safe(del_tbl_ptr, tmp_node,
489 &priv->tx_ba_stream_tbl_ptr, list)
490 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr);
491 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
492
493 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
494
495 for (i = 0; i < MAX_NUM_TID; ++i)
496 priv->aggr_prio_tbl[i].ampdu_ap =
497 priv->aggr_prio_tbl[i].ampdu_user;
498}
499
500/*
501 * This function returns the pointer to an entry in BA Stream
502 * table which matches the given RA/TID pair.
503 */
504struct mwifiex_tx_ba_stream_tbl *
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700505mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506{
507 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
508 unsigned long flags;
509
510 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
511 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700512 if (!memcmp(tx_ba_tsr_tbl->ra, ra, ETH_ALEN) &&
513 tx_ba_tsr_tbl->tid == tid) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
515 flags);
516 return tx_ba_tsr_tbl;
517 }
518 }
519 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
520 return NULL;
521}
522
523/*
524 * This function creates an entry in Tx BA stream table for the
525 * given RA/TID pair.
526 */
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700527void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
528 enum mwifiex_ba_status ba_status)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529{
530 struct mwifiex_tx_ba_stream_tbl *new_node;
531 unsigned long flags;
532
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700533 if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
535 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000536 if (!new_node)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538
539 INIT_LIST_HEAD(&new_node->list);
540
541 new_node->tid = tid;
542 new_node->ba_status = ba_status;
543 memcpy(new_node->ra, ra, ETH_ALEN);
544
545 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
546 list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr);
547 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
548 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549}
550
551/*
552 * This function sends an add BA request to the given TID/RA pair.
553 */
554int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac)
555{
556 struct host_cmd_ds_11n_addba_req add_ba_req;
557 static u8 dialog_tok;
558 int ret;
559
560 dev_dbg(priv->adapter->dev, "cmd: %s: tid %d\n", __func__, tid);
561
562 add_ba_req.block_ack_param_set = cpu_to_le16(
563 (u16) ((tid << BLOCKACKPARAM_TID_POS) |
564 (priv->add_ba_param.
565 tx_win_size << BLOCKACKPARAM_WINSIZE_POS) |
566 IMMEDIATE_BLOCK_ACK));
567 add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout);
568
569 ++dialog_tok;
570
571 if (dialog_tok == 0)
572 dialog_tok = 1;
573
574 add_ba_req.dialog_token = dialog_tok;
575 memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN);
576
577 /* We don't wait for the response of this command */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700578 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_REQ,
579 0, 0, &add_ba_req);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700580
581 return ret;
582}
583
584/*
585 * This function sends a delete BA request to the given TID/RA pair.
586 */
587int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac,
588 int initiator)
589{
590 struct host_cmd_ds_11n_delba delba;
591 int ret;
592 uint16_t del_ba_param_set;
593
594 memset(&delba, 0, sizeof(delba));
595 delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS);
596
597 del_ba_param_set = le16_to_cpu(delba.del_ba_param_set);
598 if (initiator)
599 del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK;
600 else
601 del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK;
602
603 memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN);
604
605 /* We don't wait for the response of this command */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700606 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_DELBA,
607 HostCmd_ACT_GEN_SET, 0, &delba);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608
609 return ret;
610}
611
612/*
613 * This function handles the command response of a delete BA request.
614 */
615void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba)
616{
617 struct host_cmd_ds_11n_delba *cmd_del_ba =
618 (struct host_cmd_ds_11n_delba *) del_ba;
619 uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set);
620 int tid;
621
622 tid = del_ba_param_set >> DELBA_TID_POS;
623
Yogesh Ashok Powar3e822632012-03-12 19:35:08 -0700624 mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr,
625 TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626}
627
628/*
629 * This function retrieves the Rx reordering table.
630 */
631int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv,
632 struct mwifiex_ds_rx_reorder_tbl *buf)
633{
634 int i;
635 struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf;
636 struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr;
637 int count = 0;
638 unsigned long flags;
639
640 spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags);
641 list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr,
642 list) {
643 rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid;
644 memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN);
645 rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win;
646 rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size;
647 for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) {
648 if (rx_reorder_tbl_ptr->rx_reorder_ptr[i])
649 rx_reo_tbl->buffer[i] = true;
650 else
651 rx_reo_tbl->buffer[i] = false;
652 }
653 rx_reo_tbl++;
654 count++;
655
656 if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED)
657 break;
658 }
659 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
660
661 return count;
662}
663
664/*
665 * This function retrieves the Tx BA stream table.
666 */
667int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv,
668 struct mwifiex_ds_tx_ba_stream_tbl *buf)
669{
670 struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl;
671 struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf;
672 int count = 0;
673 unsigned long flags;
674
675 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
676 list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) {
677 rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid;
678 dev_dbg(priv->adapter->dev, "data: %s tid=%d\n",
Yogesh Ashok Powar84266842012-03-13 19:22:34 -0700679 __func__, rx_reo_tbl->tid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700680 memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN);
681 rx_reo_tbl++;
682 count++;
683 if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED)
684 break;
685 }
686 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
687
688 return count;
689}
Avinash Patil3e238a12012-08-03 18:06:11 -0700690
691/*
692 * This function retrieves the entry for specific tx BA stream table by RA and
693 * deletes it.
694 */
695void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra)
696{
697 struct mwifiex_tx_ba_stream_tbl *tbl, *tmp;
698 unsigned long flags;
699
700 if (!ra)
701 return;
702
703 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
704 list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list) {
705 if (!memcmp(tbl->ra, ra, ETH_ALEN)) {
706 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock,
707 flags);
708 mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl);
709 spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags);
710 }
711 }
712 spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags);
713
714 return;
715}