Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: 802.11n |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 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 Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 32 | * HT capability information field, AMPDU Parameters field, supported MCS set |
| 33 | * fields are retrieved from cfg80211 stack |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 34 | * |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 35 | * RD responder bit to set to clear in the extended capability header. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 36 | */ |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 37 | int mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type, |
| 38 | struct ieee80211_ht_cap *ht_cap) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 39 | { |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 40 | uint16_t ht_ext_cap = le16_to_cpu(ht_cap->extended_ht_cap_info); |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 41 | struct ieee80211_supported_band *sband = |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 42 | priv->wdev.wiphy->bands[radio_type]; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 43 | |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 44 | if (WARN_ON_ONCE(!sband)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 45 | mwifiex_dbg(priv->adapter, ERROR, "Invalid radio type!\n"); |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | ht_cap->ampdu_params_info = |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 50 | (sband->ht_cap.ampdu_factor & |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 51 | IEEE80211_HT_AMPDU_PARM_FACTOR) | |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 52 | ((sband->ht_cap.ampdu_density << |
| 53 | IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT) & |
| 54 | IEEE80211_HT_AMPDU_PARM_DENSITY); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 56 | memcpy((u8 *)&ht_cap->mcs, &sband->ht_cap.mcs, |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 57 | sizeof(sband->ht_cap.mcs)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 58 | |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 59 | if (priv->bss_mode == NL80211_IFTYPE_STATION || |
Amitkumar Karwar | d35f103 | 2013-01-02 16:56:00 -0800 | [diff] [blame] | 60 | (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
| 61 | (priv->adapter->sec_chan_offset != |
| 62 | IEEE80211_HT_PARAM_CHA_SEC_NONE))) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 63 | /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */ |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 64 | SETHT_MCS32(ht_cap->mcs.rx_mask); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 65 | |
| 66 | /* Clear RD responder bit */ |
Amitkumar Karwar | a373165 | 2011-04-15 20:50:41 -0700 | [diff] [blame] | 67 | ht_ext_cap &= ~IEEE80211_HT_EXT_CAP_RD_RESPONDER; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 68 | |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 69 | ht_cap->cap_info = cpu_to_le16(sband->ht_cap.cap); |
| 70 | ht_cap->extended_ht_cap_info = cpu_to_le16(ht_ext_cap); |
Amitkumar Karwar | 645097c | 2014-02-07 16:27:26 -0800 | [diff] [blame] | 71 | |
| 72 | if (ISSUPP_BEAMFORMING(priv->adapter->hw_dot_11n_dev_cap)) |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 73 | ht_cap->tx_BF_cap_info = cpu_to_le32(MWIFIEX_DEF_11N_TX_BF_CAP); |
| 74 | |
| 75 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 79 | * This function returns the pointer to an entry in BA Stream |
| 80 | * table which matches the requested BA status. |
| 81 | */ |
| 82 | static struct mwifiex_tx_ba_stream_tbl * |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 83 | mwifiex_get_ba_status(struct mwifiex_private *priv, |
| 84 | enum mwifiex_ba_status ba_status) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 85 | { |
| 86 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl; |
| 87 | unsigned long flags; |
| 88 | |
| 89 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
| 90 | list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) { |
| 91 | if (tx_ba_tsr_tbl->ba_status == ba_status) { |
| 92 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, |
| 93 | flags); |
| 94 | return tx_ba_tsr_tbl; |
| 95 | } |
| 96 | } |
| 97 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * This function handles the command response of delete a block |
| 103 | * ack request. |
| 104 | * |
| 105 | * The function checks the response success status and takes action |
| 106 | * accordingly (send an add BA request in case of success, or recreate |
| 107 | * the deleted stream in case of failure, if the add BA was also |
| 108 | * initiated by us). |
| 109 | */ |
| 110 | int mwifiex_ret_11n_delba(struct mwifiex_private *priv, |
| 111 | struct host_cmd_ds_command *resp) |
| 112 | { |
| 113 | int tid; |
| 114 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 115 | struct host_cmd_ds_11n_delba *del_ba = &resp->params.del_ba; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 116 | uint16_t del_ba_param_set = le16_to_cpu(del_ba->del_ba_param_set); |
| 117 | |
| 118 | tid = del_ba_param_set >> DELBA_TID_POS; |
| 119 | if (del_ba->del_result == BA_RESULT_SUCCESS) { |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 120 | mwifiex_del_ba_tbl(priv, tid, del_ba->peer_mac_addr, |
| 121 | TYPE_DELBA_SENT, |
| 122 | INITIATOR_BIT(del_ba_param_set)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 123 | |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 124 | tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 125 | if (tx_ba_tbl) |
| 126 | mwifiex_send_addba(priv, tx_ba_tbl->tid, |
| 127 | tx_ba_tbl->ra); |
| 128 | } else { /* |
| 129 | * In case of failure, recreate the deleted stream in case |
| 130 | * we initiated the ADDBA |
| 131 | */ |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 132 | if (!INITIATOR_BIT(del_ba_param_set)) |
| 133 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 134 | |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 135 | mwifiex_create_ba_tbl(priv, del_ba->peer_mac_addr, tid, |
| 136 | BA_SETUP_INPROGRESS); |
| 137 | |
| 138 | tx_ba_tbl = mwifiex_get_ba_status(priv, BA_SETUP_INPROGRESS); |
| 139 | |
| 140 | if (tx_ba_tbl) |
| 141 | mwifiex_del_ba_tbl(priv, tx_ba_tbl->tid, tx_ba_tbl->ra, |
| 142 | TYPE_DELBA_SENT, true); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * This function handles the command response of add a block |
| 150 | * ack request. |
| 151 | * |
| 152 | * Handling includes changing the header fields to CPU formats, checking |
| 153 | * the response success status and taking actions accordingly (delete the |
| 154 | * BA stream table in case of failure). |
| 155 | */ |
| 156 | int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv, |
| 157 | struct host_cmd_ds_command *resp) |
| 158 | { |
Xinming Hu | 719a25e | 2015-06-03 16:59:46 +0530 | [diff] [blame] | 159 | int tid, tid_down; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 160 | struct host_cmd_ds_11n_addba_rsp *add_ba_rsp = &resp->params.add_ba_rsp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 161 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tbl; |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 162 | struct mwifiex_ra_list_tbl *ra_list; |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 163 | u16 block_ack_param_set = le16_to_cpu(add_ba_rsp->block_ack_param_set); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 164 | |
| 165 | add_ba_rsp->ssn = cpu_to_le16((le16_to_cpu(add_ba_rsp->ssn)) |
| 166 | & SSN_MASK); |
| 167 | |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 168 | tid = (block_ack_param_set & IEEE80211_ADDBA_PARAM_TID_MASK) |
| 169 | >> BLOCKACKPARAM_TID_POS; |
Xinming Hu | 719a25e | 2015-06-03 16:59:46 +0530 | [diff] [blame] | 170 | |
| 171 | tid_down = mwifiex_wmm_downgrade_tid(priv, tid); |
| 172 | ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, add_ba_rsp-> |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 173 | peer_mac_addr); |
Amitkumar Karwar | 63410c3 | 2014-03-07 19:41:29 -0800 | [diff] [blame] | 174 | if (le16_to_cpu(add_ba_rsp->status_code) != BA_RESULT_SUCCESS) { |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 175 | if (ra_list) { |
| 176 | ra_list->ba_status = BA_SETUP_NONE; |
| 177 | ra_list->amsdu_in_ampdu = false; |
| 178 | } |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 179 | mwifiex_del_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr, |
| 180 | TYPE_DELBA_SENT, true); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 181 | if (add_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT) |
| 182 | priv->aggr_prio_tbl[tid].ampdu_ap = |
| 183 | BA_STREAM_NOT_ALLOWED; |
Amitkumar Karwar | 63410c3 | 2014-03-07 19:41:29 -0800 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | tx_ba_tbl = mwifiex_get_ba_tbl(priv, tid, add_ba_rsp->peer_mac_addr); |
| 188 | if (tx_ba_tbl) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 189 | mwifiex_dbg(priv->adapter, EVENT, "info: BA stream complete\n"); |
Amitkumar Karwar | 63410c3 | 2014-03-07 19:41:29 -0800 | [diff] [blame] | 190 | tx_ba_tbl->ba_status = BA_SETUP_COMPLETE; |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 191 | if ((block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) && |
| 192 | priv->add_ba_param.tx_amsdu && |
| 193 | (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED)) |
| 194 | tx_ba_tbl->amsdu = true; |
| 195 | else |
| 196 | tx_ba_tbl->amsdu = false; |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 197 | if (ra_list) { |
| 198 | ra_list->amsdu_in_ampdu = tx_ba_tbl->amsdu; |
| 199 | ra_list->ba_status = BA_SETUP_COMPLETE; |
| 200 | } |
Amitkumar Karwar | 63410c3 | 2014-03-07 19:41:29 -0800 | [diff] [blame] | 201 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 202 | mwifiex_dbg(priv->adapter, ERROR, "BA stream not created\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 209 | * This function prepares command of reconfigure Tx buffer. |
| 210 | * |
| 211 | * Preparation includes - |
| 212 | * - Setting command ID, action and proper size |
| 213 | * - Setting Tx buffer size (for SET only) |
| 214 | * - Ensuring correct endian-ness |
| 215 | */ |
| 216 | int mwifiex_cmd_recfg_tx_buf(struct mwifiex_private *priv, |
| 217 | struct host_cmd_ds_command *cmd, int cmd_action, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 218 | u16 *buf_size) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 219 | { |
| 220 | struct host_cmd_ds_txbuf_cfg *tx_buf = &cmd->params.tx_buf; |
| 221 | u16 action = (u16) cmd_action; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 222 | |
| 223 | cmd->command = cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF); |
| 224 | cmd->size = |
| 225 | cpu_to_le16(sizeof(struct host_cmd_ds_txbuf_cfg) + S_DS_GEN); |
| 226 | tx_buf->action = cpu_to_le16(action); |
| 227 | switch (action) { |
| 228 | case HostCmd_ACT_GEN_SET: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 229 | mwifiex_dbg(priv->adapter, CMD, |
| 230 | "cmd: set tx_buf=%d\n", *buf_size); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 231 | tx_buf->buff_size = cpu_to_le16(*buf_size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 232 | break; |
| 233 | case HostCmd_ACT_GEN_GET: |
| 234 | default: |
| 235 | tx_buf->buff_size = 0; |
| 236 | break; |
| 237 | } |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * This function prepares command of AMSDU aggregation control. |
| 243 | * |
| 244 | * Preparation includes - |
| 245 | * - Setting command ID, action and proper size |
| 246 | * - Setting AMSDU control parameters (for SET only) |
| 247 | * - Ensuring correct endian-ness |
| 248 | */ |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 249 | int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 250 | int cmd_action, |
| 251 | struct mwifiex_ds_11n_amsdu_aggr_ctrl *aa_ctrl) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 252 | { |
| 253 | struct host_cmd_ds_amsdu_aggr_ctrl *amsdu_ctrl = |
| 254 | &cmd->params.amsdu_aggr_ctrl; |
| 255 | u16 action = (u16) cmd_action; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 256 | |
| 257 | cmd->command = cpu_to_le16(HostCmd_CMD_AMSDU_AGGR_CTRL); |
| 258 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_amsdu_aggr_ctrl) |
| 259 | + S_DS_GEN); |
| 260 | amsdu_ctrl->action = cpu_to_le16(action); |
| 261 | switch (action) { |
| 262 | case HostCmd_ACT_GEN_SET: |
| 263 | amsdu_ctrl->enable = cpu_to_le16(aa_ctrl->enable); |
| 264 | amsdu_ctrl->curr_buf_size = 0; |
| 265 | break; |
| 266 | case HostCmd_ACT_GEN_GET: |
| 267 | default: |
| 268 | amsdu_ctrl->curr_buf_size = 0; |
| 269 | break; |
| 270 | } |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 275 | * This function prepares 11n configuration command. |
| 276 | * |
| 277 | * Preparation includes - |
| 278 | * - Setting command ID, action and proper size |
| 279 | * - Setting HT Tx capability and HT Tx information fields |
| 280 | * - Ensuring correct endian-ness |
| 281 | */ |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 282 | int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv, |
| 283 | struct host_cmd_ds_command *cmd, u16 cmd_action, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 284 | struct mwifiex_ds_11n_tx_cfg *txcfg) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 285 | { |
| 286 | struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 287 | |
| 288 | cmd->command = cpu_to_le16(HostCmd_CMD_11N_CFG); |
| 289 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_11n_cfg) + S_DS_GEN); |
| 290 | htcfg->action = cpu_to_le16(cmd_action); |
| 291 | htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap); |
| 292 | htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo); |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 293 | |
| 294 | if (priv->adapter->is_hw_11ac_capable) |
| 295 | htcfg->misc_config = cpu_to_le16(txcfg->misc_config); |
| 296 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * This function appends an 11n TLV to a buffer. |
| 302 | * |
| 303 | * Buffer allocation is responsibility of the calling |
| 304 | * function. No size validation is made here. |
| 305 | * |
| 306 | * The function fills up the following sections, if applicable - |
| 307 | * - HT capability IE |
| 308 | * - HT information IE (with channel list) |
| 309 | * - 20/40 BSS Coexistence IE |
| 310 | * - HT Extended Capabilities IE |
| 311 | */ |
| 312 | int |
| 313 | mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv, |
| 314 | struct mwifiex_bssdescriptor *bss_desc, |
| 315 | u8 **buffer) |
| 316 | { |
| 317 | struct mwifiex_ie_types_htcap *ht_cap; |
| 318 | struct mwifiex_ie_types_htinfo *ht_info; |
| 319 | struct mwifiex_ie_types_chan_list_param_set *chan_list; |
| 320 | struct mwifiex_ie_types_2040bssco *bss_co_2040; |
| 321 | struct mwifiex_ie_types_extcap *ext_cap; |
| 322 | int ret_len = 0; |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 323 | struct ieee80211_supported_band *sband; |
Avinash Patil | 68f95b09 | 2013-08-23 16:48:22 -0700 | [diff] [blame] | 324 | struct ieee_types_header *hdr; |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 325 | u8 radio_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 326 | |
| 327 | if (!buffer || !*buffer) |
| 328 | return ret_len; |
| 329 | |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 330 | radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band); |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 331 | sband = priv->wdev.wiphy->bands[radio_type]; |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 332 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 333 | if (bss_desc->bcn_ht_cap) { |
| 334 | ht_cap = (struct mwifiex_ie_types_htcap *) *buffer; |
| 335 | memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap)); |
| 336 | ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY); |
| 337 | ht_cap->header.len = |
| 338 | cpu_to_le16(sizeof(struct ieee80211_ht_cap)); |
| 339 | memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header), |
Amitkumar Karwar | c99b186 | 2014-03-04 18:43:13 -0800 | [diff] [blame] | 340 | (u8 *)bss_desc->bcn_ht_cap, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 341 | le16_to_cpu(ht_cap->header.len)); |
| 342 | |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 343 | mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 344 | |
| 345 | *buffer += sizeof(struct mwifiex_ie_types_htcap); |
| 346 | ret_len += sizeof(struct mwifiex_ie_types_htcap); |
| 347 | } |
| 348 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 349 | if (bss_desc->bcn_ht_oper) { |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 350 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 351 | ht_info = (struct mwifiex_ie_types_htinfo *) *buffer; |
| 352 | memset(ht_info, 0, |
| 353 | sizeof(struct mwifiex_ie_types_htinfo)); |
| 354 | ht_info->header.type = |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 355 | cpu_to_le16(WLAN_EID_HT_OPERATION); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 356 | ht_info->header.len = |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 357 | cpu_to_le16( |
| 358 | sizeof(struct ieee80211_ht_operation)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 359 | |
| 360 | memcpy((u8 *) ht_info + |
| 361 | sizeof(struct mwifiex_ie_types_header), |
Amitkumar Karwar | cf831ff | 2014-04-16 22:01:53 -0700 | [diff] [blame] | 362 | (u8 *)bss_desc->bcn_ht_oper, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 363 | le16_to_cpu(ht_info->header.len)); |
| 364 | |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 365 | if (!(sband->ht_cap.cap & |
| 366 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 367 | ht_info->ht_oper.ht_param &= |
Marc Yang | 6d2bd91 | 2011-03-25 19:47:02 -0700 | [diff] [blame] | 368 | ~(IEEE80211_HT_PARAM_CHAN_WIDTH_ANY | |
| 369 | IEEE80211_HT_PARAM_CHA_SEC_OFFSET); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 370 | |
| 371 | *buffer += sizeof(struct mwifiex_ie_types_htinfo); |
| 372 | ret_len += sizeof(struct mwifiex_ie_types_htinfo); |
| 373 | } |
| 374 | |
| 375 | chan_list = |
| 376 | (struct mwifiex_ie_types_chan_list_param_set *) *buffer; |
| 377 | memset(chan_list, 0, |
| 378 | sizeof(struct mwifiex_ie_types_chan_list_param_set)); |
| 379 | chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 380 | chan_list->header.len = cpu_to_le16( |
| 381 | sizeof(struct mwifiex_ie_types_chan_list_param_set) - |
| 382 | sizeof(struct mwifiex_ie_types_header)); |
| 383 | chan_list->chan_scan_param[0].chan_number = |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 384 | bss_desc->bcn_ht_oper->primary_chan; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 385 | chan_list->chan_scan_param[0].radio_type = |
| 386 | mwifiex_band_to_radio_type((u8) bss_desc->bss_band); |
| 387 | |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 388 | if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 389 | bss_desc->bcn_ht_oper->ht_param & |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 390 | IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 391 | SET_SECONDARYCHAN(chan_list->chan_scan_param[0]. |
| 392 | radio_type, |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 393 | (bss_desc->bcn_ht_oper->ht_param & |
Marc Yang | 6d2bd91 | 2011-03-25 19:47:02 -0700 | [diff] [blame] | 394 | IEEE80211_HT_PARAM_CHA_SEC_OFFSET)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 395 | |
| 396 | *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set); |
| 397 | ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set); |
| 398 | } |
| 399 | |
| 400 | if (bss_desc->bcn_bss_co_2040) { |
| 401 | bss_co_2040 = (struct mwifiex_ie_types_2040bssco *) *buffer; |
| 402 | memset(bss_co_2040, 0, |
| 403 | sizeof(struct mwifiex_ie_types_2040bssco)); |
| 404 | bss_co_2040->header.type = cpu_to_le16(WLAN_EID_BSS_COEX_2040); |
| 405 | bss_co_2040->header.len = |
| 406 | cpu_to_le16(sizeof(bss_co_2040->bss_co_2040)); |
| 407 | |
| 408 | memcpy((u8 *) bss_co_2040 + |
| 409 | sizeof(struct mwifiex_ie_types_header), |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 410 | bss_desc->bcn_bss_co_2040 + |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 411 | sizeof(struct ieee_types_header), |
| 412 | le16_to_cpu(bss_co_2040->header.len)); |
| 413 | |
| 414 | *buffer += sizeof(struct mwifiex_ie_types_2040bssco); |
| 415 | ret_len += sizeof(struct mwifiex_ie_types_2040bssco); |
| 416 | } |
| 417 | |
| 418 | if (bss_desc->bcn_ext_cap) { |
Avinash Patil | 68f95b09 | 2013-08-23 16:48:22 -0700 | [diff] [blame] | 419 | hdr = (void *)bss_desc->bcn_ext_cap; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 420 | ext_cap = (struct mwifiex_ie_types_extcap *) *buffer; |
| 421 | memset(ext_cap, 0, sizeof(struct mwifiex_ie_types_extcap)); |
| 422 | ext_cap->header.type = cpu_to_le16(WLAN_EID_EXT_CAPABILITY); |
Avinash Patil | 68f95b09 | 2013-08-23 16:48:22 -0700 | [diff] [blame] | 423 | ext_cap->header.len = cpu_to_le16(hdr->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 424 | |
Avinash Patil | 68f95b09 | 2013-08-23 16:48:22 -0700 | [diff] [blame] | 425 | memcpy((u8 *)ext_cap->ext_capab, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 426 | bss_desc->bcn_ext_cap + sizeof(struct ieee_types_header), |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 427 | le16_to_cpu(ext_cap->header.len)); |
| 428 | |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 429 | if (hdr->len > 3 && |
| 430 | ext_cap->ext_capab[3] & WLAN_EXT_CAPA4_INTERWORKING_ENABLED) |
| 431 | priv->hs2_enabled = true; |
| 432 | else |
| 433 | priv->hs2_enabled = false; |
| 434 | |
Avinash Patil | 68f95b09 | 2013-08-23 16:48:22 -0700 | [diff] [blame] | 435 | *buffer += sizeof(struct mwifiex_ie_types_extcap) + hdr->len; |
| 436 | ret_len += sizeof(struct mwifiex_ie_types_extcap) + hdr->len; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | return ret_len; |
| 440 | } |
| 441 | |
| 442 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 443 | * This function checks if the given pointer is valid entry of |
| 444 | * Tx BA Stream table. |
| 445 | */ |
| 446 | static int mwifiex_is_tx_ba_stream_ptr_valid(struct mwifiex_private *priv, |
| 447 | struct mwifiex_tx_ba_stream_tbl *tx_tbl_ptr) |
| 448 | { |
| 449 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl; |
| 450 | |
| 451 | list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) { |
| 452 | if (tx_ba_tsr_tbl == tx_tbl_ptr) |
| 453 | return true; |
| 454 | } |
| 455 | |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * This function deletes the given entry in Tx BA Stream table. |
| 461 | * |
| 462 | * The function also performs a validity check on the supplied |
| 463 | * pointer before trying to delete. |
| 464 | */ |
| 465 | void mwifiex_11n_delete_tx_ba_stream_tbl_entry(struct mwifiex_private *priv, |
| 466 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl) |
| 467 | { |
| 468 | if (!tx_ba_tsr_tbl && |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 469 | mwifiex_is_tx_ba_stream_ptr_valid(priv, tx_ba_tsr_tbl)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 470 | return; |
| 471 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 472 | mwifiex_dbg(priv->adapter, INFO, |
| 473 | "info: tx_ba_tsr_tbl %p\n", tx_ba_tsr_tbl); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 474 | |
| 475 | list_del(&tx_ba_tsr_tbl->list); |
| 476 | |
| 477 | kfree(tx_ba_tsr_tbl); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /* |
| 481 | * This function deletes all the entries in Tx BA Stream table. |
| 482 | */ |
| 483 | void mwifiex_11n_delete_all_tx_ba_stream_tbl(struct mwifiex_private *priv) |
| 484 | { |
| 485 | int i; |
| 486 | struct mwifiex_tx_ba_stream_tbl *del_tbl_ptr, *tmp_node; |
| 487 | unsigned long flags; |
| 488 | |
| 489 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
| 490 | list_for_each_entry_safe(del_tbl_ptr, tmp_node, |
| 491 | &priv->tx_ba_stream_tbl_ptr, list) |
| 492 | mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, del_tbl_ptr); |
| 493 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 494 | |
| 495 | INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); |
| 496 | |
| 497 | for (i = 0; i < MAX_NUM_TID; ++i) |
| 498 | priv->aggr_prio_tbl[i].ampdu_ap = |
| 499 | priv->aggr_prio_tbl[i].ampdu_user; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * This function returns the pointer to an entry in BA Stream |
| 504 | * table which matches the given RA/TID pair. |
| 505 | */ |
| 506 | struct mwifiex_tx_ba_stream_tbl * |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 507 | mwifiex_get_ba_tbl(struct mwifiex_private *priv, int tid, u8 *ra) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 508 | { |
| 509 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl; |
| 510 | unsigned long flags; |
| 511 | |
| 512 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
| 513 | list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) { |
dingtianhong | fcad766 | 2013-12-26 19:41:27 +0800 | [diff] [blame] | 514 | if (ether_addr_equal_unaligned(tx_ba_tsr_tbl->ra, ra) && |
Yogesh Ashok Powar | 8426684 | 2012-03-13 19:22:34 -0700 | [diff] [blame] | 515 | tx_ba_tsr_tbl->tid == tid) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 516 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, |
| 517 | flags); |
| 518 | return tx_ba_tsr_tbl; |
| 519 | } |
| 520 | } |
| 521 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 522 | return NULL; |
| 523 | } |
| 524 | |
| 525 | /* |
| 526 | * This function creates an entry in Tx BA stream table for the |
| 527 | * given RA/TID pair. |
| 528 | */ |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 529 | void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid, |
| 530 | enum mwifiex_ba_status ba_status) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 531 | { |
| 532 | struct mwifiex_tx_ba_stream_tbl *new_node; |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 533 | struct mwifiex_ra_list_tbl *ra_list; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 534 | unsigned long flags; |
Xinming Hu | 719a25e | 2015-06-03 16:59:46 +0530 | [diff] [blame] | 535 | int tid_down; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 536 | |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 537 | if (!mwifiex_get_ba_tbl(priv, tid, ra)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 538 | new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl), |
| 539 | GFP_ATOMIC); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 540 | if (!new_node) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 541 | return; |
Xinming Hu | 719a25e | 2015-06-03 16:59:46 +0530 | [diff] [blame] | 542 | |
| 543 | tid_down = mwifiex_wmm_downgrade_tid(priv, tid); |
| 544 | ra_list = mwifiex_wmm_get_ralist_node(priv, tid_down, ra); |
Zhaoyang Liu | 39df5e8 | 2015-03-13 17:37:55 +0530 | [diff] [blame] | 545 | if (ra_list) { |
| 546 | ra_list->ba_status = ba_status; |
| 547 | ra_list->amsdu_in_ampdu = false; |
| 548 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 549 | INIT_LIST_HEAD(&new_node->list); |
| 550 | |
| 551 | new_node->tid = tid; |
| 552 | new_node->ba_status = ba_status; |
| 553 | memcpy(new_node->ra, ra, ETH_ALEN); |
| 554 | |
| 555 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
| 556 | list_add_tail(&new_node->list, &priv->tx_ba_stream_tbl_ptr); |
| 557 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 558 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /* |
| 562 | * This function sends an add BA request to the given TID/RA pair. |
| 563 | */ |
| 564 | int mwifiex_send_addba(struct mwifiex_private *priv, int tid, u8 *peer_mac) |
| 565 | { |
| 566 | struct host_cmd_ds_11n_addba_req add_ba_req; |
Avinash Patil | b06c5321 | 2014-02-07 16:30:40 -0800 | [diff] [blame] | 567 | u32 tx_win_size = priv->add_ba_param.tx_win_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 568 | static u8 dialog_tok; |
| 569 | int ret; |
Avinash Patil | c11fb98 | 2014-12-05 23:23:41 +0530 | [diff] [blame] | 570 | unsigned long flags; |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 571 | u16 block_ack_param_set; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 572 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 573 | mwifiex_dbg(priv->adapter, CMD, "cmd: %s: tid %d\n", __func__, tid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 574 | |
Xinming Hu | e37f648 | 2017-08-01 01:38:23 +0000 | [diff] [blame] | 575 | memset(&add_ba_req, 0, sizeof(add_ba_req)); |
| 576 | |
Avinash Patil | b06c5321 | 2014-02-07 16:30:40 -0800 | [diff] [blame] | 577 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && |
| 578 | ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
| 579 | priv->adapter->is_hw_11ac_capable && |
| 580 | memcmp(priv->cfg_bssid, peer_mac, ETH_ALEN)) { |
Bing Zhao | ea4eb7f | 2014-07-11 20:57:14 -0700 | [diff] [blame] | 581 | struct mwifiex_sta_node *sta_ptr; |
| 582 | |
Avinash Patil | c11fb98 | 2014-12-05 23:23:41 +0530 | [diff] [blame] | 583 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); |
Avinash Patil | b06c5321 | 2014-02-07 16:30:40 -0800 | [diff] [blame] | 584 | sta_ptr = mwifiex_get_sta_entry(priv, peer_mac); |
| 585 | if (!sta_ptr) { |
Avinash Patil | 09bd197 | 2015-01-07 18:10:25 +0530 | [diff] [blame] | 586 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 587 | mwifiex_dbg(priv->adapter, ERROR, |
| 588 | "BA setup with unknown TDLS peer %pM!\n", |
| 589 | peer_mac); |
Avinash Patil | b06c5321 | 2014-02-07 16:30:40 -0800 | [diff] [blame] | 590 | return -1; |
| 591 | } |
| 592 | if (sta_ptr->is_11ac_enabled) |
| 593 | tx_win_size = MWIFIEX_11AC_STA_AMPDU_DEF_TXWINSIZE; |
Avinash Patil | c11fb98 | 2014-12-05 23:23:41 +0530 | [diff] [blame] | 594 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); |
Avinash Patil | b06c5321 | 2014-02-07 16:30:40 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 597 | block_ack_param_set = (u16)((tid << BLOCKACKPARAM_TID_POS) | |
| 598 | tx_win_size << BLOCKACKPARAM_WINSIZE_POS | |
| 599 | IMMEDIATE_BLOCK_ACK); |
| 600 | |
| 601 | /* enable AMSDU inside AMPDU */ |
| 602 | if (priv->add_ba_param.tx_amsdu && |
| 603 | (priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED)) |
| 604 | block_ack_param_set |= BLOCKACKPARAM_AMSDU_SUPP_MASK; |
| 605 | |
| 606 | add_ba_req.block_ack_param_set = cpu_to_le16(block_ack_param_set); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 607 | add_ba_req.block_ack_tmo = cpu_to_le16((u16)priv->add_ba_param.timeout); |
| 608 | |
| 609 | ++dialog_tok; |
| 610 | |
| 611 | if (dialog_tok == 0) |
| 612 | dialog_tok = 1; |
| 613 | |
| 614 | add_ba_req.dialog_token = dialog_tok; |
| 615 | memcpy(&add_ba_req.peer_mac_addr, peer_mac, ETH_ALEN); |
| 616 | |
| 617 | /* We don't wait for the response of this command */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 618 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_REQ, |
| 619 | 0, 0, &add_ba_req, false); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 620 | |
| 621 | return ret; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * This function sends a delete BA request to the given TID/RA pair. |
| 626 | */ |
| 627 | int mwifiex_send_delba(struct mwifiex_private *priv, int tid, u8 *peer_mac, |
| 628 | int initiator) |
| 629 | { |
| 630 | struct host_cmd_ds_11n_delba delba; |
| 631 | int ret; |
| 632 | uint16_t del_ba_param_set; |
| 633 | |
| 634 | memset(&delba, 0, sizeof(delba)); |
| 635 | delba.del_ba_param_set = cpu_to_le16(tid << DELBA_TID_POS); |
| 636 | |
| 637 | del_ba_param_set = le16_to_cpu(delba.del_ba_param_set); |
| 638 | if (initiator) |
| 639 | del_ba_param_set |= IEEE80211_DELBA_PARAM_INITIATOR_MASK; |
| 640 | else |
| 641 | del_ba_param_set &= ~IEEE80211_DELBA_PARAM_INITIATOR_MASK; |
| 642 | |
| 643 | memcpy(&delba.peer_mac_addr, peer_mac, ETH_ALEN); |
| 644 | |
| 645 | /* We don't wait for the response of this command */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 646 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_DELBA, |
| 647 | HostCmd_ACT_GEN_SET, 0, &delba, false); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 648 | |
| 649 | return ret; |
| 650 | } |
| 651 | |
| 652 | /* |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 653 | * This function sends delba to specific tid |
| 654 | */ |
| 655 | void mwifiex_11n_delba(struct mwifiex_private *priv, int tid) |
| 656 | { |
| 657 | struct mwifiex_rx_reorder_tbl *rx_reor_tbl_ptr; |
Douglas Anderson | 09bdb65 | 2017-05-12 09:42:01 -0700 | [diff] [blame] | 658 | unsigned long flags; |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 659 | |
Douglas Anderson | 09bdb65 | 2017-05-12 09:42:01 -0700 | [diff] [blame] | 660 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 661 | list_for_each_entry(rx_reor_tbl_ptr, &priv->rx_reorder_tbl_ptr, list) { |
| 662 | if (rx_reor_tbl_ptr->tid == tid) { |
| 663 | dev_dbg(priv->adapter->dev, |
| 664 | "Send delba to tid=%d, %pM\n", |
| 665 | tid, rx_reor_tbl_ptr->ta); |
| 666 | mwifiex_send_delba(priv, tid, rx_reor_tbl_ptr->ta, 0); |
Douglas Anderson | 09bdb65 | 2017-05-12 09:42:01 -0700 | [diff] [blame] | 667 | goto exit; |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
Douglas Anderson | 09bdb65 | 2017-05-12 09:42:01 -0700 | [diff] [blame] | 670 | exit: |
| 671 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 675 | * This function handles the command response of a delete BA request. |
| 676 | */ |
| 677 | void mwifiex_11n_delete_ba_stream(struct mwifiex_private *priv, u8 *del_ba) |
| 678 | { |
| 679 | struct host_cmd_ds_11n_delba *cmd_del_ba = |
| 680 | (struct host_cmd_ds_11n_delba *) del_ba; |
| 681 | uint16_t del_ba_param_set = le16_to_cpu(cmd_del_ba->del_ba_param_set); |
| 682 | int tid; |
| 683 | |
| 684 | tid = del_ba_param_set >> DELBA_TID_POS; |
| 685 | |
Yogesh Ashok Powar | 3e82263 | 2012-03-12 19:35:08 -0700 | [diff] [blame] | 686 | mwifiex_del_ba_tbl(priv, tid, cmd_del_ba->peer_mac_addr, |
| 687 | TYPE_DELBA_RECEIVE, INITIATOR_BIT(del_ba_param_set)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /* |
| 691 | * This function retrieves the Rx reordering table. |
| 692 | */ |
| 693 | int mwifiex_get_rx_reorder_tbl(struct mwifiex_private *priv, |
| 694 | struct mwifiex_ds_rx_reorder_tbl *buf) |
| 695 | { |
| 696 | int i; |
| 697 | struct mwifiex_ds_rx_reorder_tbl *rx_reo_tbl = buf; |
| 698 | struct mwifiex_rx_reorder_tbl *rx_reorder_tbl_ptr; |
| 699 | int count = 0; |
| 700 | unsigned long flags; |
| 701 | |
| 702 | spin_lock_irqsave(&priv->rx_reorder_tbl_lock, flags); |
| 703 | list_for_each_entry(rx_reorder_tbl_ptr, &priv->rx_reorder_tbl_ptr, |
| 704 | list) { |
| 705 | rx_reo_tbl->tid = (u16) rx_reorder_tbl_ptr->tid; |
| 706 | memcpy(rx_reo_tbl->ta, rx_reorder_tbl_ptr->ta, ETH_ALEN); |
| 707 | rx_reo_tbl->start_win = rx_reorder_tbl_ptr->start_win; |
| 708 | rx_reo_tbl->win_size = rx_reorder_tbl_ptr->win_size; |
| 709 | for (i = 0; i < rx_reorder_tbl_ptr->win_size; ++i) { |
| 710 | if (rx_reorder_tbl_ptr->rx_reorder_ptr[i]) |
| 711 | rx_reo_tbl->buffer[i] = true; |
| 712 | else |
| 713 | rx_reo_tbl->buffer[i] = false; |
| 714 | } |
| 715 | rx_reo_tbl++; |
| 716 | count++; |
| 717 | |
| 718 | if (count >= MWIFIEX_MAX_RX_BASTREAM_SUPPORTED) |
| 719 | break; |
| 720 | } |
| 721 | spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); |
| 722 | |
| 723 | return count; |
| 724 | } |
| 725 | |
| 726 | /* |
| 727 | * This function retrieves the Tx BA stream table. |
| 728 | */ |
| 729 | int mwifiex_get_tx_ba_stream_tbl(struct mwifiex_private *priv, |
| 730 | struct mwifiex_ds_tx_ba_stream_tbl *buf) |
| 731 | { |
| 732 | struct mwifiex_tx_ba_stream_tbl *tx_ba_tsr_tbl; |
| 733 | struct mwifiex_ds_tx_ba_stream_tbl *rx_reo_tbl = buf; |
| 734 | int count = 0; |
| 735 | unsigned long flags; |
| 736 | |
| 737 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
| 738 | list_for_each_entry(tx_ba_tsr_tbl, &priv->tx_ba_stream_tbl_ptr, list) { |
| 739 | rx_reo_tbl->tid = (u16) tx_ba_tsr_tbl->tid; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 740 | mwifiex_dbg(priv->adapter, DATA, "data: %s tid=%d\n", |
| 741 | __func__, rx_reo_tbl->tid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 742 | memcpy(rx_reo_tbl->ra, tx_ba_tsr_tbl->ra, ETH_ALEN); |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 743 | rx_reo_tbl->amsdu = tx_ba_tsr_tbl->amsdu; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 744 | rx_reo_tbl++; |
| 745 | count++; |
| 746 | if (count >= MWIFIEX_MAX_TX_BASTREAM_SUPPORTED) |
| 747 | break; |
| 748 | } |
| 749 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 750 | |
| 751 | return count; |
| 752 | } |
Avinash Patil | 3e238a1 | 2012-08-03 18:06:11 -0700 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * This function retrieves the entry for specific tx BA stream table by RA and |
| 756 | * deletes it. |
| 757 | */ |
| 758 | void mwifiex_del_tx_ba_stream_tbl_by_ra(struct mwifiex_private *priv, u8 *ra) |
| 759 | { |
| 760 | struct mwifiex_tx_ba_stream_tbl *tbl, *tmp; |
| 761 | unsigned long flags; |
| 762 | |
| 763 | if (!ra) |
| 764 | return; |
| 765 | |
| 766 | spin_lock_irqsave(&priv->tx_ba_stream_tbl_lock, flags); |
Douglas Anderson | e0b636e | 2017-05-12 09:41:59 -0700 | [diff] [blame] | 767 | list_for_each_entry_safe(tbl, tmp, &priv->tx_ba_stream_tbl_ptr, list) |
| 768 | if (!memcmp(tbl->ra, ra, ETH_ALEN)) |
Avinash Patil | 3e238a1 | 2012-08-03 18:06:11 -0700 | [diff] [blame] | 769 | mwifiex_11n_delete_tx_ba_stream_tbl_entry(priv, tbl); |
Avinash Patil | 3e238a1 | 2012-08-03 18:06:11 -0700 | [diff] [blame] | 770 | spin_unlock_irqrestore(&priv->tx_ba_stream_tbl_lock, flags); |
| 771 | |
| 772 | return; |
| 773 | } |
Avinash Patil | 04abc0a | 2013-03-27 19:10:31 -0700 | [diff] [blame] | 774 | |
| 775 | /* This function initializes the BlockACK setup information for given |
| 776 | * mwifiex_private structure. |
| 777 | */ |
| 778 | void mwifiex_set_ba_params(struct mwifiex_private *priv) |
| 779 | { |
| 780 | priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT; |
| 781 | |
| 782 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { |
| 783 | priv->add_ba_param.tx_win_size = |
| 784 | MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE; |
| 785 | priv->add_ba_param.rx_win_size = |
| 786 | MWIFIEX_UAP_AMPDU_DEF_RXWINSIZE; |
| 787 | } else { |
| 788 | priv->add_ba_param.tx_win_size = |
| 789 | MWIFIEX_STA_AMPDU_DEF_TXWINSIZE; |
| 790 | priv->add_ba_param.rx_win_size = |
| 791 | MWIFIEX_STA_AMPDU_DEF_RXWINSIZE; |
| 792 | } |
| 793 | |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 794 | priv->add_ba_param.tx_amsdu = true; |
| 795 | priv->add_ba_param.rx_amsdu = true; |
| 796 | |
Avinash Patil | 04abc0a | 2013-03-27 19:10:31 -0700 | [diff] [blame] | 797 | return; |
| 798 | } |
Avinash Patil | 396939f | 2014-05-06 22:02:45 -0700 | [diff] [blame] | 799 | |
| 800 | u8 mwifiex_get_sec_chan_offset(int chan) |
| 801 | { |
| 802 | u8 sec_offset; |
| 803 | |
| 804 | switch (chan) { |
| 805 | case 36: |
| 806 | case 44: |
| 807 | case 52: |
| 808 | case 60: |
| 809 | case 100: |
| 810 | case 108: |
| 811 | case 116: |
| 812 | case 124: |
| 813 | case 132: |
| 814 | case 140: |
| 815 | case 149: |
| 816 | case 157: |
| 817 | sec_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
| 818 | break; |
| 819 | case 40: |
| 820 | case 48: |
| 821 | case 56: |
| 822 | case 64: |
| 823 | case 104: |
| 824 | case 112: |
| 825 | case 120: |
| 826 | case 128: |
| 827 | case 136: |
| 828 | case 144: |
| 829 | case 153: |
| 830 | case 161: |
| 831 | sec_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
| 832 | break; |
| 833 | case 165: |
| 834 | default: |
| 835 | sec_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE; |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | return sec_offset; |
| 840 | } |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 841 | |
| 842 | /* This function will send DELBA to entries in the priv's |
| 843 | * Tx BA stream table |
| 844 | */ |
| 845 | static void |
| 846 | mwifiex_send_delba_txbastream_tbl(struct mwifiex_private *priv, u8 tid) |
| 847 | { |
| 848 | struct mwifiex_adapter *adapter = priv->adapter; |
| 849 | struct mwifiex_tx_ba_stream_tbl *tx_ba_stream_tbl_ptr; |
| 850 | |
Chunfan Chen | d219b7e | 2015-06-10 06:19:48 -0700 | [diff] [blame] | 851 | list_for_each_entry(tx_ba_stream_tbl_ptr, |
| 852 | &priv->tx_ba_stream_tbl_ptr, list) { |
| 853 | if (tx_ba_stream_tbl_ptr->ba_status == BA_SETUP_COMPLETE) { |
| 854 | if (tid == tx_ba_stream_tbl_ptr->tid) { |
| 855 | dev_dbg(adapter->dev, |
| 856 | "Tx:Send delba to tid=%d, %pM\n", tid, |
| 857 | tx_ba_stream_tbl_ptr->ra); |
| 858 | mwifiex_send_delba(priv, |
| 859 | tx_ba_stream_tbl_ptr->tid, |
| 860 | tx_ba_stream_tbl_ptr->ra, 1); |
| 861 | return; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /* This function updates all the tx_win_size |
| 868 | */ |
| 869 | void mwifiex_update_ampdu_txwinsize(struct mwifiex_adapter *adapter) |
| 870 | { |
| 871 | u8 i; |
| 872 | u32 tx_win_size; |
| 873 | struct mwifiex_private *priv; |
| 874 | |
| 875 | for (i = 0; i < adapter->priv_num; i++) { |
| 876 | if (!adapter->priv[i]) |
| 877 | continue; |
| 878 | priv = adapter->priv[i]; |
| 879 | tx_win_size = priv->add_ba_param.tx_win_size; |
| 880 | |
| 881 | if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) |
| 882 | priv->add_ba_param.tx_win_size = |
| 883 | MWIFIEX_STA_AMPDU_DEF_TXWINSIZE; |
| 884 | |
| 885 | if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P) |
| 886 | priv->add_ba_param.tx_win_size = |
| 887 | MWIFIEX_STA_AMPDU_DEF_TXWINSIZE; |
| 888 | |
| 889 | if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) |
| 890 | priv->add_ba_param.tx_win_size = |
| 891 | MWIFIEX_UAP_AMPDU_DEF_TXWINSIZE; |
| 892 | |
| 893 | if (adapter->coex_win_size) { |
| 894 | if (adapter->coex_tx_win_size) |
| 895 | priv->add_ba_param.tx_win_size = |
| 896 | adapter->coex_tx_win_size; |
| 897 | } |
| 898 | |
| 899 | if (tx_win_size != priv->add_ba_param.tx_win_size) { |
| 900 | if (!priv->media_connected) |
| 901 | continue; |
| 902 | for (i = 0; i < MAX_NUM_TID; i++) |
| 903 | mwifiex_send_delba_txbastream_tbl(priv, i); |
| 904 | } |
| 905 | } |
| 906 | } |