Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: WMM |
| 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 | /* Maximum value FW can accept for driver delay in packet transmission */ |
| 30 | #define DRV_PKT_DELAY_TO_FW_MAX 512 |
| 31 | |
| 32 | |
| 33 | #define WMM_QUEUED_PACKET_LOWER_LIMIT 180 |
| 34 | |
| 35 | #define WMM_QUEUED_PACKET_UPPER_LIMIT 200 |
| 36 | |
| 37 | /* Offset for TOS field in the IP header */ |
| 38 | #define IPTOS_OFFSET 5 |
| 39 | |
| 40 | /* WMM information IE */ |
| 41 | static const u8 wmm_info_ie[] = { WLAN_EID_VENDOR_SPECIFIC, 0x07, |
| 42 | 0x00, 0x50, 0xf2, 0x02, |
| 43 | 0x00, 0x01, 0x00 |
| 44 | }; |
| 45 | |
| 46 | static const u8 wmm_aci_to_qidx_map[] = { WMM_AC_BE, |
| 47 | WMM_AC_BK, |
| 48 | WMM_AC_VI, |
| 49 | WMM_AC_VO |
| 50 | }; |
| 51 | |
| 52 | static u8 tos_to_tid[] = { |
| 53 | /* TID DSCP_P2 DSCP_P1 DSCP_P0 WMM_AC */ |
| 54 | 0x01, /* 0 1 0 AC_BK */ |
| 55 | 0x02, /* 0 0 0 AC_BK */ |
| 56 | 0x00, /* 0 0 1 AC_BE */ |
| 57 | 0x03, /* 0 1 1 AC_BE */ |
| 58 | 0x04, /* 1 0 0 AC_VI */ |
| 59 | 0x05, /* 1 0 1 AC_VI */ |
| 60 | 0x06, /* 1 1 0 AC_VO */ |
| 61 | 0x07 /* 1 1 1 AC_VO */ |
| 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * This table inverses the tos_to_tid operation to get a priority |
| 66 | * which is in sequential order, and can be compared. |
| 67 | * Use this to compare the priority of two different TIDs. |
| 68 | */ |
| 69 | static u8 tos_to_tid_inv[] = { |
| 70 | 0x02, /* from tos_to_tid[2] = 0 */ |
| 71 | 0x00, /* from tos_to_tid[0] = 1 */ |
| 72 | 0x01, /* from tos_to_tid[1] = 2 */ |
| 73 | 0x03, |
| 74 | 0x04, |
| 75 | 0x05, |
| 76 | 0x06, |
| 77 | 0x07}; |
| 78 | |
| 79 | static u8 ac_to_tid[4][2] = { {1, 2}, {0, 3}, {4, 5}, {6, 7} }; |
| 80 | |
| 81 | /* |
| 82 | * This function debug prints the priority parameters for a WMM AC. |
| 83 | */ |
| 84 | static void |
| 85 | mwifiex_wmm_ac_debug_print(const struct ieee_types_wmm_ac_parameters *ac_param) |
| 86 | { |
| 87 | const char *ac_str[] = { "BK", "BE", "VI", "VO" }; |
| 88 | |
| 89 | pr_debug("info: WMM AC_%s: ACI=%d, ACM=%d, Aifsn=%d, " |
| 90 | "EcwMin=%d, EcwMax=%d, TxopLimit=%d\n", |
| 91 | ac_str[wmm_aci_to_qidx_map[(ac_param->aci_aifsn_bitmap |
| 92 | & MWIFIEX_ACI) >> 5]], |
| 93 | (ac_param->aci_aifsn_bitmap & MWIFIEX_ACI) >> 5, |
| 94 | (ac_param->aci_aifsn_bitmap & MWIFIEX_ACM) >> 4, |
| 95 | ac_param->aci_aifsn_bitmap & MWIFIEX_AIFSN, |
| 96 | ac_param->ecw_bitmap & MWIFIEX_ECW_MIN, |
| 97 | (ac_param->ecw_bitmap & MWIFIEX_ECW_MAX) >> 4, |
| 98 | le16_to_cpu(ac_param->tx_op_limit)); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * This function allocates a route address list. |
| 103 | * |
| 104 | * The function also initializes the list with the provided RA. |
| 105 | */ |
| 106 | static struct mwifiex_ra_list_tbl * |
| 107 | mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, u8 *ra) |
| 108 | { |
| 109 | struct mwifiex_ra_list_tbl *ra_list; |
| 110 | |
| 111 | ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC); |
| 112 | |
| 113 | if (!ra_list) { |
| 114 | dev_err(adapter->dev, "%s: failed to alloc ra_list\n", |
| 115 | __func__); |
| 116 | return NULL; |
| 117 | } |
| 118 | INIT_LIST_HEAD(&ra_list->list); |
| 119 | skb_queue_head_init(&ra_list->skb_head); |
| 120 | |
| 121 | memcpy(ra_list->ra, ra, ETH_ALEN); |
| 122 | |
| 123 | ra_list->total_pkts_size = 0; |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 124 | ra_list->total_pkts = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 125 | |
| 126 | dev_dbg(adapter->dev, "info: allocated ra_list %p\n", ra_list); |
| 127 | |
| 128 | return ra_list; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * This function allocates and adds a RA list for all TIDs |
| 133 | * with the given RA. |
| 134 | */ |
| 135 | void |
| 136 | mwifiex_ralist_add(struct mwifiex_private *priv, u8 *ra) |
| 137 | { |
| 138 | int i; |
| 139 | struct mwifiex_ra_list_tbl *ra_list; |
| 140 | struct mwifiex_adapter *adapter = priv->adapter; |
| 141 | |
| 142 | for (i = 0; i < MAX_NUM_TID; ++i) { |
| 143 | ra_list = mwifiex_wmm_allocate_ralist_node(adapter, ra); |
| 144 | dev_dbg(adapter->dev, "info: created ra_list %p\n", ra_list); |
| 145 | |
| 146 | if (!ra_list) |
| 147 | break; |
| 148 | |
| 149 | if (!mwifiex_queuing_ra_based(priv)) |
| 150 | ra_list->is_11n_enabled = IS_11N_ENABLED(priv); |
| 151 | else |
| 152 | ra_list->is_11n_enabled = false; |
| 153 | |
| 154 | dev_dbg(adapter->dev, "data: ralist %p: is_11n_enabled=%d\n", |
| 155 | ra_list, ra_list->is_11n_enabled); |
| 156 | |
| 157 | list_add_tail(&ra_list->list, |
| 158 | &priv->wmm.tid_tbl_ptr[i].ra_list); |
| 159 | |
| 160 | if (!priv->wmm.tid_tbl_ptr[i].ra_list_curr) |
| 161 | priv->wmm.tid_tbl_ptr[i].ra_list_curr = ra_list; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * This function sets the WMM queue priorities to their default values. |
| 167 | */ |
| 168 | static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private *priv) |
| 169 | { |
| 170 | /* Default queue priorities: VO->VI->BE->BK */ |
| 171 | priv->wmm.queue_priority[0] = WMM_AC_VO; |
| 172 | priv->wmm.queue_priority[1] = WMM_AC_VI; |
| 173 | priv->wmm.queue_priority[2] = WMM_AC_BE; |
| 174 | priv->wmm.queue_priority[3] = WMM_AC_BK; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * This function map ACs to TIDs. |
| 179 | */ |
| 180 | static void |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 181 | mwifiex_wmm_queue_priorities_tid(struct mwifiex_wmm_desc *wmm) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 182 | { |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 183 | u8 *queue_priority = wmm->queue_priority; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 184 | int i; |
| 185 | |
| 186 | for (i = 0; i < 4; ++i) { |
| 187 | tos_to_tid[7 - (i * 2)] = ac_to_tid[queue_priority[i]][1]; |
| 188 | tos_to_tid[6 - (i * 2)] = ac_to_tid[queue_priority[i]][0]; |
| 189 | } |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 190 | |
| 191 | for (i = 0; i < MAX_NUM_TID; ++i) |
| 192 | tos_to_tid_inv[tos_to_tid[i]] = (u8)i; |
| 193 | |
| 194 | atomic_set(&wmm->highest_queued_prio, HIGH_PRIO_TID); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function initializes WMM priority queues. |
| 199 | */ |
| 200 | void |
| 201 | mwifiex_wmm_setup_queue_priorities(struct mwifiex_private *priv, |
| 202 | struct ieee_types_wmm_parameter *wmm_ie) |
| 203 | { |
| 204 | u16 cw_min, avg_back_off, tmp[4]; |
| 205 | u32 i, j, num_ac; |
| 206 | u8 ac_idx; |
| 207 | |
| 208 | if (!wmm_ie || !priv->wmm_enabled) { |
| 209 | /* WMM is not enabled, just set the defaults and return */ |
| 210 | mwifiex_wmm_default_queue_priorities(priv); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | dev_dbg(priv->adapter->dev, "info: WMM Parameter IE: version=%d, " |
| 215 | "qos_info Parameter Set Count=%d, Reserved=%#x\n", |
| 216 | wmm_ie->vend_hdr.version, wmm_ie->qos_info_bitmap & |
| 217 | IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK, |
| 218 | wmm_ie->reserved); |
| 219 | |
| 220 | for (num_ac = 0; num_ac < ARRAY_SIZE(wmm_ie->ac_params); num_ac++) { |
| 221 | cw_min = (1 << (wmm_ie->ac_params[num_ac].ecw_bitmap & |
| 222 | MWIFIEX_ECW_MIN)) - 1; |
| 223 | avg_back_off = (cw_min >> 1) + |
| 224 | (wmm_ie->ac_params[num_ac].aci_aifsn_bitmap & |
| 225 | MWIFIEX_AIFSN); |
| 226 | |
| 227 | ac_idx = wmm_aci_to_qidx_map[(wmm_ie->ac_params[num_ac]. |
| 228 | aci_aifsn_bitmap & |
| 229 | MWIFIEX_ACI) >> 5]; |
| 230 | priv->wmm.queue_priority[ac_idx] = ac_idx; |
| 231 | tmp[ac_idx] = avg_back_off; |
| 232 | |
| 233 | dev_dbg(priv->adapter->dev, "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n", |
| 234 | (1 << ((wmm_ie->ac_params[num_ac].ecw_bitmap & |
| 235 | MWIFIEX_ECW_MAX) >> 4)) - 1, |
| 236 | cw_min, avg_back_off); |
| 237 | mwifiex_wmm_ac_debug_print(&wmm_ie->ac_params[num_ac]); |
| 238 | } |
| 239 | |
| 240 | /* Bubble sort */ |
| 241 | for (i = 0; i < num_ac; i++) { |
| 242 | for (j = 1; j < num_ac - i; j++) { |
| 243 | if (tmp[j - 1] > tmp[j]) { |
| 244 | swap(tmp[j - 1], tmp[j]); |
| 245 | swap(priv->wmm.queue_priority[j - 1], |
| 246 | priv->wmm.queue_priority[j]); |
| 247 | } else if (tmp[j - 1] == tmp[j]) { |
| 248 | if (priv->wmm.queue_priority[j - 1] |
| 249 | < priv->wmm.queue_priority[j]) |
| 250 | swap(priv->wmm.queue_priority[j - 1], |
| 251 | priv->wmm.queue_priority[j]); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 256 | mwifiex_wmm_queue_priorities_tid(&priv->wmm); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* |
| 260 | * This function evaluates whether or not an AC is to be downgraded. |
| 261 | * |
| 262 | * In case the AC is not enabled, the highest AC is returned that is |
| 263 | * enabled and does not require admission control. |
| 264 | */ |
| 265 | static enum mwifiex_wmm_ac_e |
| 266 | mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private *priv, |
| 267 | enum mwifiex_wmm_ac_e eval_ac) |
| 268 | { |
| 269 | int down_ac; |
| 270 | enum mwifiex_wmm_ac_e ret_ac; |
| 271 | struct mwifiex_wmm_ac_status *ac_status; |
| 272 | |
| 273 | ac_status = &priv->wmm.ac_status[eval_ac]; |
| 274 | |
| 275 | if (!ac_status->disabled) |
| 276 | /* Okay to use this AC, its enabled */ |
| 277 | return eval_ac; |
| 278 | |
| 279 | /* Setup a default return value of the lowest priority */ |
| 280 | ret_ac = WMM_AC_BK; |
| 281 | |
| 282 | /* |
| 283 | * Find the highest AC that is enabled and does not require |
| 284 | * admission control. The spec disallows downgrading to an AC, |
| 285 | * which is enabled due to a completed admission control. |
| 286 | * Unadmitted traffic is not to be sent on an AC with admitted |
| 287 | * traffic. |
| 288 | */ |
| 289 | for (down_ac = WMM_AC_BK; down_ac < eval_ac; down_ac++) { |
| 290 | ac_status = &priv->wmm.ac_status[down_ac]; |
| 291 | |
| 292 | if (!ac_status->disabled && !ac_status->flow_required) |
| 293 | /* AC is enabled and does not require admission |
| 294 | control */ |
| 295 | ret_ac = (enum mwifiex_wmm_ac_e) down_ac; |
| 296 | } |
| 297 | |
| 298 | return ret_ac; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * This function downgrades WMM priority queue. |
| 303 | */ |
| 304 | void |
| 305 | mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private *priv) |
| 306 | { |
| 307 | int ac_val; |
| 308 | |
| 309 | dev_dbg(priv->adapter->dev, "info: WMM: AC Priorities:" |
| 310 | "BK(0), BE(1), VI(2), VO(3)\n"); |
| 311 | |
| 312 | if (!priv->wmm_enabled) { |
| 313 | /* WMM is not enabled, default priorities */ |
| 314 | for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) |
| 315 | priv->wmm.ac_down_graded_vals[ac_val] = |
| 316 | (enum mwifiex_wmm_ac_e) ac_val; |
| 317 | } else { |
| 318 | for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) { |
| 319 | priv->wmm.ac_down_graded_vals[ac_val] |
| 320 | = mwifiex_wmm_eval_downgrade_ac(priv, |
| 321 | (enum mwifiex_wmm_ac_e) ac_val); |
| 322 | dev_dbg(priv->adapter->dev, "info: WMM: AC PRIO %d maps to %d\n", |
| 323 | ac_val, priv->wmm.ac_down_graded_vals[ac_val]); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * This function converts the IP TOS field to an WMM AC |
| 330 | * Queue assignment. |
| 331 | */ |
| 332 | static enum mwifiex_wmm_ac_e |
| 333 | mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter *adapter, u32 tos) |
| 334 | { |
| 335 | /* Map of TOS UP values to WMM AC */ |
| 336 | const enum mwifiex_wmm_ac_e tos_to_ac[] = { WMM_AC_BE, |
| 337 | WMM_AC_BK, |
| 338 | WMM_AC_BK, |
| 339 | WMM_AC_BE, |
| 340 | WMM_AC_VI, |
| 341 | WMM_AC_VI, |
| 342 | WMM_AC_VO, |
| 343 | WMM_AC_VO |
| 344 | }; |
| 345 | |
| 346 | if (tos >= ARRAY_SIZE(tos_to_ac)) |
| 347 | return WMM_AC_BE; |
| 348 | |
| 349 | return tos_to_ac[tos]; |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * This function evaluates a given TID and downgrades it to a lower |
| 354 | * TID if the WMM Parameter IE received from the AP indicates that the |
| 355 | * AP is disabled (due to call admission control (ACM bit). Mapping |
| 356 | * of TID to AC is taken care of internally. |
| 357 | */ |
| 358 | static u8 |
| 359 | mwifiex_wmm_downgrade_tid(struct mwifiex_private *priv, u32 tid) |
| 360 | { |
| 361 | enum mwifiex_wmm_ac_e ac, ac_down; |
| 362 | u8 new_tid; |
| 363 | |
| 364 | ac = mwifiex_wmm_convert_tos_to_ac(priv->adapter, tid); |
| 365 | ac_down = priv->wmm.ac_down_graded_vals[ac]; |
| 366 | |
| 367 | /* Send the index to tid array, picking from the array will be |
| 368 | * taken care by dequeuing function |
| 369 | */ |
| 370 | new_tid = ac_to_tid[ac_down][tid % 2]; |
| 371 | |
| 372 | return new_tid; |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * This function initializes the WMM state information and the |
| 377 | * WMM data path queues. |
| 378 | */ |
| 379 | void |
| 380 | mwifiex_wmm_init(struct mwifiex_adapter *adapter) |
| 381 | { |
| 382 | int i, j; |
| 383 | struct mwifiex_private *priv; |
| 384 | |
| 385 | for (j = 0; j < adapter->priv_num; ++j) { |
| 386 | priv = adapter->priv[j]; |
| 387 | if (!priv) |
| 388 | continue; |
| 389 | |
| 390 | for (i = 0; i < MAX_NUM_TID; ++i) { |
| 391 | priv->aggr_prio_tbl[i].amsdu = tos_to_tid_inv[i]; |
| 392 | priv->aggr_prio_tbl[i].ampdu_ap = tos_to_tid_inv[i]; |
| 393 | priv->aggr_prio_tbl[i].ampdu_user = tos_to_tid_inv[i]; |
| 394 | priv->wmm.tid_tbl_ptr[i].ra_list_curr = NULL; |
| 395 | } |
| 396 | |
| 397 | priv->aggr_prio_tbl[6].amsdu |
| 398 | = priv->aggr_prio_tbl[6].ampdu_ap |
| 399 | = priv->aggr_prio_tbl[6].ampdu_user |
| 400 | = BA_STREAM_NOT_ALLOWED; |
| 401 | |
| 402 | priv->aggr_prio_tbl[7].amsdu = priv->aggr_prio_tbl[7].ampdu_ap |
| 403 | = priv->aggr_prio_tbl[7].ampdu_user |
| 404 | = BA_STREAM_NOT_ALLOWED; |
| 405 | |
| 406 | priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT; |
| 407 | priv->add_ba_param.tx_win_size = MWIFIEX_AMPDU_DEF_TXWINSIZE; |
| 408 | priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE; |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 409 | |
| 410 | atomic_set(&priv->wmm.tx_pkts_queued, 0); |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 411 | atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * This function checks if WMM Tx queue is empty. |
| 417 | */ |
| 418 | int |
| 419 | mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter) |
| 420 | { |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 421 | int i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 422 | struct mwifiex_private *priv; |
| 423 | |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 424 | for (i = 0; i < adapter->priv_num; ++i) { |
| 425 | priv = adapter->priv[i]; |
| 426 | if (priv && atomic_read(&priv->wmm.tx_pkts_queued)) |
| 427 | return false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * This function deletes all packets in an RA list node. |
| 435 | * |
| 436 | * The packet sent completion callback handler are called with |
| 437 | * status failure, after they are dequeued to ensure proper |
| 438 | * cleanup. The RA list node itself is freed at the end. |
| 439 | */ |
| 440 | static void |
| 441 | mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv, |
| 442 | struct mwifiex_ra_list_tbl *ra_list) |
| 443 | { |
| 444 | struct mwifiex_adapter *adapter = priv->adapter; |
| 445 | struct sk_buff *skb, *tmp; |
| 446 | |
| 447 | skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) |
| 448 | mwifiex_write_data_complete(adapter, skb, -1); |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * This function deletes all packets in an RA list. |
| 453 | * |
| 454 | * Each nodes in the RA list are freed individually first, and then |
| 455 | * the RA list itself is freed. |
| 456 | */ |
| 457 | static void |
| 458 | mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv, |
| 459 | struct list_head *ra_list_head) |
| 460 | { |
| 461 | struct mwifiex_ra_list_tbl *ra_list; |
| 462 | |
| 463 | list_for_each_entry(ra_list, ra_list_head, list) |
| 464 | mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list); |
| 465 | } |
| 466 | |
| 467 | /* |
| 468 | * This function deletes all packets in all RA lists. |
| 469 | */ |
| 470 | static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv) |
| 471 | { |
| 472 | int i; |
| 473 | |
| 474 | for (i = 0; i < MAX_NUM_TID; i++) |
| 475 | mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i]. |
| 476 | ra_list); |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 477 | |
| 478 | atomic_set(&priv->wmm.tx_pkts_queued, 0); |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 479 | atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* |
| 483 | * This function deletes all route addresses from all RA lists. |
| 484 | */ |
| 485 | static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv) |
| 486 | { |
| 487 | struct mwifiex_ra_list_tbl *ra_list, *tmp_node; |
| 488 | int i; |
| 489 | |
| 490 | for (i = 0; i < MAX_NUM_TID; ++i) { |
| 491 | dev_dbg(priv->adapter->dev, |
| 492 | "info: ra_list: freeing buf for tid %d\n", i); |
| 493 | list_for_each_entry_safe(ra_list, tmp_node, |
| 494 | &priv->wmm.tid_tbl_ptr[i].ra_list, list) { |
| 495 | list_del(&ra_list->list); |
| 496 | kfree(ra_list); |
| 497 | } |
| 498 | |
| 499 | INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list); |
| 500 | |
| 501 | priv->wmm.tid_tbl_ptr[i].ra_list_curr = NULL; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | * This function cleans up the Tx and Rx queues. |
| 507 | * |
| 508 | * Cleanup includes - |
| 509 | * - All packets in RA lists |
| 510 | * - All entries in Rx reorder table |
| 511 | * - All entries in Tx BA stream table |
| 512 | * - MPA buffer (if required) |
| 513 | * - All RA lists |
| 514 | */ |
| 515 | void |
| 516 | mwifiex_clean_txrx(struct mwifiex_private *priv) |
| 517 | { |
| 518 | unsigned long flags; |
| 519 | |
| 520 | mwifiex_11n_cleanup_reorder_tbl(priv); |
| 521 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags); |
| 522 | |
| 523 | mwifiex_wmm_cleanup_queues(priv); |
| 524 | mwifiex_11n_delete_all_tx_ba_stream_tbl(priv); |
| 525 | |
| 526 | if (priv->adapter->if_ops.cleanup_mpa_buf) |
| 527 | priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter); |
| 528 | |
| 529 | mwifiex_wmm_delete_all_ralist(priv); |
| 530 | memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid)); |
| 531 | |
| 532 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * This function retrieves a particular RA list node, matching with the |
| 537 | * given TID and RA address. |
| 538 | */ |
| 539 | static struct mwifiex_ra_list_tbl * |
| 540 | mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid, |
| 541 | u8 *ra_addr) |
| 542 | { |
| 543 | struct mwifiex_ra_list_tbl *ra_list; |
| 544 | |
| 545 | list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list, |
| 546 | list) { |
| 547 | if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN)) |
| 548 | return ra_list; |
| 549 | } |
| 550 | |
| 551 | return NULL; |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * This function retrieves an RA list node for a given TID and |
| 556 | * RA address pair. |
| 557 | * |
| 558 | * If no such node is found, a new node is added first and then |
| 559 | * retrieved. |
| 560 | */ |
| 561 | static struct mwifiex_ra_list_tbl * |
| 562 | mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid, u8 *ra_addr) |
| 563 | { |
| 564 | struct mwifiex_ra_list_tbl *ra_list; |
| 565 | |
| 566 | ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr); |
| 567 | if (ra_list) |
| 568 | return ra_list; |
| 569 | mwifiex_ralist_add(priv, ra_addr); |
| 570 | |
| 571 | return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * This function checks if a particular RA list node exists in a given TID |
| 576 | * table index. |
| 577 | */ |
| 578 | int |
| 579 | mwifiex_is_ralist_valid(struct mwifiex_private *priv, |
| 580 | struct mwifiex_ra_list_tbl *ra_list, int ptr_index) |
| 581 | { |
| 582 | struct mwifiex_ra_list_tbl *rlist; |
| 583 | |
| 584 | list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list, |
| 585 | list) { |
| 586 | if (rlist == ra_list) |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * This function adds a packet to WMM queue. |
| 595 | * |
| 596 | * In disconnected state the packet is immediately dropped and the |
| 597 | * packet send completion callback is called with status failure. |
| 598 | * |
| 599 | * Otherwise, the correct RA list node is located and the packet |
| 600 | * is queued at the list tail. |
| 601 | */ |
| 602 | void |
| 603 | mwifiex_wmm_add_buf_txqueue(struct mwifiex_adapter *adapter, |
| 604 | struct sk_buff *skb) |
| 605 | { |
| 606 | struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb); |
| 607 | struct mwifiex_private *priv = adapter->priv[tx_info->bss_index]; |
| 608 | u32 tid; |
| 609 | struct mwifiex_ra_list_tbl *ra_list; |
| 610 | u8 ra[ETH_ALEN], tid_down; |
| 611 | unsigned long flags; |
| 612 | |
| 613 | if (!priv->media_connected) { |
| 614 | dev_dbg(adapter->dev, "data: drop packet in disconnect\n"); |
| 615 | mwifiex_write_data_complete(adapter, skb, -1); |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | tid = skb->priority; |
| 620 | |
| 621 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags); |
| 622 | |
| 623 | tid_down = mwifiex_wmm_downgrade_tid(priv, tid); |
| 624 | |
| 625 | /* In case of infra as we have already created the list during |
| 626 | association we just don't have to call get_queue_raptr, we will |
| 627 | have only 1 raptr for a tid in case of infra */ |
| 628 | if (!mwifiex_queuing_ra_based(priv)) { |
| 629 | if (!list_empty(&priv->wmm.tid_tbl_ptr[tid_down].ra_list)) |
| 630 | ra_list = list_first_entry( |
| 631 | &priv->wmm.tid_tbl_ptr[tid_down].ra_list, |
| 632 | struct mwifiex_ra_list_tbl, list); |
| 633 | else |
| 634 | ra_list = NULL; |
| 635 | } else { |
| 636 | memcpy(ra, skb->data, ETH_ALEN); |
Amitkumar Karwar | 4e3c442 | 2011-07-13 20:51:57 -0700 | [diff] [blame] | 637 | if (ra[0] & 0x01) |
| 638 | memset(ra, 0xff, ETH_ALEN); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 639 | ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra); |
| 640 | } |
| 641 | |
| 642 | if (!ra_list) { |
| 643 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); |
| 644 | mwifiex_write_data_complete(adapter, skb, -1); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | skb_queue_tail(&ra_list->skb_head, skb); |
| 649 | |
| 650 | ra_list->total_pkts_size += skb->len; |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 651 | ra_list->total_pkts++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 652 | |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 653 | atomic_inc(&priv->wmm.tx_pkts_queued); |
| 654 | |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 655 | if (atomic_read(&priv->wmm.highest_queued_prio) < |
| 656 | tos_to_tid_inv[tid_down]) |
| 657 | atomic_set(&priv->wmm.highest_queued_prio, |
| 658 | tos_to_tid_inv[tid_down]); |
| 659 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 660 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); |
| 661 | } |
| 662 | |
| 663 | /* |
| 664 | * This function processes the get WMM status command response from firmware. |
| 665 | * |
| 666 | * The response may contain multiple TLVs - |
| 667 | * - AC Queue status TLVs |
| 668 | * - Current WMM Parameter IE TLV |
| 669 | * - Admission Control action frame TLVs |
| 670 | * |
| 671 | * This function parses the TLVs and then calls further specific functions |
| 672 | * to process any changes in the queue prioritize or state. |
| 673 | */ |
| 674 | int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv, |
| 675 | const struct host_cmd_ds_command *resp) |
| 676 | { |
| 677 | u8 *curr = (u8 *) &resp->params.get_wmm_status; |
| 678 | uint16_t resp_len = le16_to_cpu(resp->size), tlv_len; |
| 679 | int valid = true; |
| 680 | |
| 681 | struct mwifiex_ie_types_data *tlv_hdr; |
| 682 | struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus; |
| 683 | struct ieee_types_wmm_parameter *wmm_param_ie = NULL; |
| 684 | struct mwifiex_wmm_ac_status *ac_status; |
| 685 | |
| 686 | dev_dbg(priv->adapter->dev, "info: WMM: WMM_GET_STATUS cmdresp received: %d\n", |
| 687 | resp_len); |
| 688 | |
| 689 | while ((resp_len >= sizeof(tlv_hdr->header)) && valid) { |
| 690 | tlv_hdr = (struct mwifiex_ie_types_data *) curr; |
| 691 | tlv_len = le16_to_cpu(tlv_hdr->header.len); |
| 692 | |
| 693 | switch (le16_to_cpu(tlv_hdr->header.type)) { |
| 694 | case TLV_TYPE_WMMQSTATUS: |
| 695 | tlv_wmm_qstatus = |
| 696 | (struct mwifiex_ie_types_wmm_queue_status *) |
| 697 | tlv_hdr; |
| 698 | dev_dbg(priv->adapter->dev, |
| 699 | "info: CMD_RESP: WMM_GET_STATUS:" |
| 700 | " QSTATUS TLV: %d, %d, %d\n", |
| 701 | tlv_wmm_qstatus->queue_index, |
| 702 | tlv_wmm_qstatus->flow_required, |
| 703 | tlv_wmm_qstatus->disabled); |
| 704 | |
| 705 | ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus-> |
| 706 | queue_index]; |
| 707 | ac_status->disabled = tlv_wmm_qstatus->disabled; |
| 708 | ac_status->flow_required = |
| 709 | tlv_wmm_qstatus->flow_required; |
| 710 | ac_status->flow_created = tlv_wmm_qstatus->flow_created; |
| 711 | break; |
| 712 | |
| 713 | case WLAN_EID_VENDOR_SPECIFIC: |
| 714 | /* |
| 715 | * Point the regular IEEE IE 2 bytes into the Marvell IE |
| 716 | * and setup the IEEE IE type and length byte fields |
| 717 | */ |
| 718 | |
| 719 | wmm_param_ie = |
| 720 | (struct ieee_types_wmm_parameter *) (curr + |
| 721 | 2); |
| 722 | wmm_param_ie->vend_hdr.len = (u8) tlv_len; |
| 723 | wmm_param_ie->vend_hdr.element_id = |
| 724 | WLAN_EID_VENDOR_SPECIFIC; |
| 725 | |
| 726 | dev_dbg(priv->adapter->dev, |
| 727 | "info: CMD_RESP: WMM_GET_STATUS:" |
| 728 | " WMM Parameter Set Count: %d\n", |
| 729 | wmm_param_ie->qos_info_bitmap & |
| 730 | IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK); |
| 731 | |
| 732 | memcpy((u8 *) &priv->curr_bss_params.bss_descriptor. |
| 733 | wmm_ie, wmm_param_ie, |
| 734 | wmm_param_ie->vend_hdr.len + 2); |
| 735 | |
| 736 | break; |
| 737 | |
| 738 | default: |
| 739 | valid = false; |
| 740 | break; |
| 741 | } |
| 742 | |
| 743 | curr += (tlv_len + sizeof(tlv_hdr->header)); |
| 744 | resp_len -= (tlv_len + sizeof(tlv_hdr->header)); |
| 745 | } |
| 746 | |
| 747 | mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie); |
| 748 | mwifiex_wmm_setup_ac_downgrade(priv); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | /* |
| 754 | * Callback handler from the command module to allow insertion of a WMM TLV. |
| 755 | * |
| 756 | * If the BSS we are associating to supports WMM, this function adds the |
| 757 | * required WMM Information IE to the association request command buffer in |
| 758 | * the form of a Marvell extended IEEE IE. |
| 759 | */ |
| 760 | u32 |
| 761 | mwifiex_wmm_process_association_req(struct mwifiex_private *priv, |
| 762 | u8 **assoc_buf, |
| 763 | struct ieee_types_wmm_parameter *wmm_ie, |
| 764 | struct ieee80211_ht_cap *ht_cap) |
| 765 | { |
| 766 | struct mwifiex_ie_types_wmm_param_set *wmm_tlv; |
| 767 | u32 ret_len = 0; |
| 768 | |
| 769 | /* Null checks */ |
| 770 | if (!assoc_buf) |
| 771 | return 0; |
| 772 | if (!(*assoc_buf)) |
| 773 | return 0; |
| 774 | |
| 775 | if (!wmm_ie) |
| 776 | return 0; |
| 777 | |
| 778 | dev_dbg(priv->adapter->dev, "info: WMM: process assoc req:" |
| 779 | "bss->wmmIe=0x%x\n", |
| 780 | wmm_ie->vend_hdr.element_id); |
| 781 | |
| 782 | if ((priv->wmm_required |
| 783 | || (ht_cap && (priv->adapter->config_bands & BAND_GN |
| 784 | || priv->adapter->config_bands & BAND_AN)) |
| 785 | ) |
| 786 | && wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) { |
| 787 | wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf; |
| 788 | wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]); |
| 789 | wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]); |
| 790 | memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2], |
| 791 | le16_to_cpu(wmm_tlv->header.len)); |
| 792 | if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) |
| 793 | memcpy((u8 *) (wmm_tlv->wmm_ie |
| 794 | + le16_to_cpu(wmm_tlv->header.len) |
| 795 | - sizeof(priv->wmm_qosinfo)), |
| 796 | &priv->wmm_qosinfo, |
| 797 | sizeof(priv->wmm_qosinfo)); |
| 798 | |
| 799 | ret_len = sizeof(wmm_tlv->header) |
| 800 | + le16_to_cpu(wmm_tlv->header.len); |
| 801 | |
| 802 | *assoc_buf += ret_len; |
| 803 | } |
| 804 | |
| 805 | return ret_len; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * This function computes the time delay in the driver queues for a |
| 810 | * given packet. |
| 811 | * |
| 812 | * When the packet is received at the OS/Driver interface, the current |
| 813 | * time is set in the packet structure. The difference between the present |
| 814 | * time and that received time is computed in this function and limited |
| 815 | * based on pre-compiled limits in the driver. |
| 816 | */ |
| 817 | u8 |
| 818 | mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv, |
| 819 | const struct sk_buff *skb) |
| 820 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 821 | u8 ret_val; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 822 | struct timeval out_tstamp, in_tstamp; |
| 823 | u32 queue_delay; |
| 824 | |
| 825 | do_gettimeofday(&out_tstamp); |
| 826 | in_tstamp = ktime_to_timeval(skb->tstamp); |
| 827 | |
| 828 | queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) * 1000; |
| 829 | queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) / 1000; |
| 830 | |
| 831 | /* |
| 832 | * Queue delay is passed as a uint8 in units of 2ms (ms shifted |
| 833 | * by 1). Min value (other than 0) is therefore 2ms, max is 510ms. |
| 834 | * |
| 835 | * Pass max value if queue_delay is beyond the uint8 range |
| 836 | */ |
| 837 | ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1); |
| 838 | |
| 839 | dev_dbg(priv->adapter->dev, "data: WMM: Pkt Delay: %d ms," |
| 840 | " %d ms sent to FW\n", queue_delay, ret_val); |
| 841 | |
| 842 | return ret_val; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * This function retrieves the highest priority RA list table pointer. |
| 847 | */ |
| 848 | static struct mwifiex_ra_list_tbl * |
| 849 | mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter, |
| 850 | struct mwifiex_private **priv, int *tid) |
| 851 | { |
| 852 | struct mwifiex_private *priv_tmp; |
| 853 | struct mwifiex_ra_list_tbl *ptr, *head; |
| 854 | struct mwifiex_bss_prio_node *bssprio_node, *bssprio_head; |
| 855 | struct mwifiex_tid_tbl *tid_ptr; |
| 856 | int is_list_empty; |
| 857 | unsigned long flags; |
| 858 | int i, j; |
| 859 | |
| 860 | for (j = adapter->priv_num - 1; j >= 0; --j) { |
| 861 | spin_lock_irqsave(&adapter->bss_prio_tbl[j].bss_prio_lock, |
| 862 | flags); |
| 863 | is_list_empty = list_empty(&adapter->bss_prio_tbl[j] |
| 864 | .bss_prio_head); |
| 865 | spin_unlock_irqrestore(&adapter->bss_prio_tbl[j].bss_prio_lock, |
| 866 | flags); |
| 867 | if (is_list_empty) |
| 868 | continue; |
| 869 | |
| 870 | if (adapter->bss_prio_tbl[j].bss_prio_cur == |
| 871 | (struct mwifiex_bss_prio_node *) |
| 872 | &adapter->bss_prio_tbl[j].bss_prio_head) { |
| 873 | bssprio_node = |
| 874 | list_first_entry(&adapter->bss_prio_tbl[j] |
| 875 | .bss_prio_head, |
| 876 | struct mwifiex_bss_prio_node, |
| 877 | list); |
| 878 | bssprio_head = bssprio_node; |
| 879 | } else { |
| 880 | bssprio_node = adapter->bss_prio_tbl[j].bss_prio_cur; |
| 881 | bssprio_head = bssprio_node; |
| 882 | } |
| 883 | |
| 884 | do { |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 885 | atomic_t *hqp; |
| 886 | spinlock_t *lock; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 887 | |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 888 | priv_tmp = bssprio_node->priv; |
| 889 | hqp = &priv_tmp->wmm.highest_queued_prio; |
| 890 | lock = &priv_tmp->wmm.ra_list_spinlock; |
| 891 | |
| 892 | for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 893 | |
| 894 | tid_ptr = &(priv_tmp)->wmm. |
| 895 | tid_tbl_ptr[tos_to_tid[i]]; |
| 896 | |
| 897 | spin_lock_irqsave(&tid_ptr->tid_tbl_lock, |
| 898 | flags); |
| 899 | is_list_empty = |
| 900 | list_empty(&adapter->bss_prio_tbl[j] |
| 901 | .bss_prio_head); |
| 902 | spin_unlock_irqrestore(&tid_ptr->tid_tbl_lock, |
| 903 | flags); |
| 904 | if (is_list_empty) |
| 905 | continue; |
| 906 | |
| 907 | /* |
| 908 | * Always choose the next ra we transmitted |
| 909 | * last time, this way we pick the ra's in |
| 910 | * round robin fashion. |
| 911 | */ |
| 912 | ptr = list_first_entry( |
| 913 | &tid_ptr->ra_list_curr->list, |
| 914 | struct mwifiex_ra_list_tbl, |
| 915 | list); |
| 916 | |
| 917 | head = ptr; |
| 918 | if (ptr == (struct mwifiex_ra_list_tbl *) |
| 919 | &tid_ptr->ra_list) { |
| 920 | /* Get next ra */ |
| 921 | ptr = list_first_entry(&ptr->list, |
| 922 | struct mwifiex_ra_list_tbl, list); |
| 923 | head = ptr; |
| 924 | } |
| 925 | |
| 926 | do { |
| 927 | is_list_empty = |
| 928 | skb_queue_empty(&ptr->skb_head); |
| 929 | if (!is_list_empty) { |
Marc Yang | 49729ff | 2011-05-16 19:17:50 -0700 | [diff] [blame] | 930 | spin_lock_irqsave(lock, flags); |
| 931 | if (atomic_read(hqp) > i) |
| 932 | atomic_set(hqp, i); |
| 933 | spin_unlock_irqrestore(lock, |
| 934 | flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 935 | *priv = priv_tmp; |
| 936 | *tid = tos_to_tid[i]; |
| 937 | return ptr; |
| 938 | } |
| 939 | /* Get next ra */ |
| 940 | ptr = list_first_entry(&ptr->list, |
| 941 | struct mwifiex_ra_list_tbl, |
| 942 | list); |
| 943 | if (ptr == |
| 944 | (struct mwifiex_ra_list_tbl *) |
| 945 | &tid_ptr->ra_list) |
| 946 | ptr = list_first_entry( |
| 947 | &ptr->list, |
| 948 | struct mwifiex_ra_list_tbl, |
| 949 | list); |
| 950 | } while (ptr != head); |
| 951 | } |
| 952 | |
Marc Yang | 17e8cec | 2011-05-16 19:17:52 -0700 | [diff] [blame] | 953 | /* No packet at any TID for this priv. Mark as such |
| 954 | * to skip checking TIDs for this priv (until pkt is |
| 955 | * added). |
| 956 | */ |
| 957 | atomic_set(hqp, NO_PKT_PRIO_TID); |
| 958 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 959 | /* Get next bss priority node */ |
| 960 | bssprio_node = list_first_entry(&bssprio_node->list, |
| 961 | struct mwifiex_bss_prio_node, |
| 962 | list); |
| 963 | |
| 964 | if (bssprio_node == |
| 965 | (struct mwifiex_bss_prio_node *) |
| 966 | &adapter->bss_prio_tbl[j].bss_prio_head) |
| 967 | /* Get next bss priority node */ |
| 968 | bssprio_node = list_first_entry( |
| 969 | &bssprio_node->list, |
| 970 | struct mwifiex_bss_prio_node, |
| 971 | list); |
| 972 | } while (bssprio_node != bssprio_head); |
| 973 | } |
| 974 | return NULL; |
| 975 | } |
| 976 | |
| 977 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 978 | * This function sends a single packet to firmware for transmission. |
| 979 | */ |
| 980 | static void |
| 981 | mwifiex_send_single_packet(struct mwifiex_private *priv, |
| 982 | struct mwifiex_ra_list_tbl *ptr, int ptr_index, |
| 983 | unsigned long ra_list_flags) |
| 984 | __releases(&priv->wmm.ra_list_spinlock) |
| 985 | { |
| 986 | struct sk_buff *skb, *skb_next; |
| 987 | struct mwifiex_tx_param tx_param; |
| 988 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 989 | struct mwifiex_txinfo *tx_info; |
| 990 | |
| 991 | if (skb_queue_empty(&ptr->skb_head)) { |
| 992 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 993 | ra_list_flags); |
| 994 | dev_dbg(adapter->dev, "data: nothing to send\n"); |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | skb = skb_dequeue(&ptr->skb_head); |
| 999 | |
| 1000 | tx_info = MWIFIEX_SKB_TXCB(skb); |
| 1001 | dev_dbg(adapter->dev, "data: dequeuing the packet %p %p\n", ptr, skb); |
| 1002 | |
| 1003 | ptr->total_pkts_size -= skb->len; |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 1004 | ptr->total_pkts--; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1005 | |
| 1006 | if (!skb_queue_empty(&ptr->skb_head)) |
| 1007 | skb_next = skb_peek(&ptr->skb_head); |
| 1008 | else |
| 1009 | skb_next = NULL; |
| 1010 | |
| 1011 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1012 | |
| 1013 | tx_param.next_pkt_len = ((skb_next) ? skb_next->len + |
| 1014 | sizeof(struct txpd) : 0); |
| 1015 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1016 | if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1017 | /* Queue the packet back at the head */ |
| 1018 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1019 | |
| 1020 | if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) { |
| 1021 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1022 | ra_list_flags); |
| 1023 | mwifiex_write_data_complete(adapter, skb, -1); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | skb_queue_tail(&ptr->skb_head, skb); |
| 1028 | |
| 1029 | ptr->total_pkts_size += skb->len; |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 1030 | ptr->total_pkts++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1031 | tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT; |
| 1032 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1033 | ra_list_flags); |
| 1034 | } else { |
| 1035 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1036 | if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) { |
| 1037 | priv->wmm.packets_out[ptr_index]++; |
| 1038 | priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr; |
| 1039 | } |
| 1040 | adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur = |
| 1041 | list_first_entry( |
| 1042 | &adapter->bss_prio_tbl[priv->bss_priority] |
| 1043 | .bss_prio_cur->list, |
| 1044 | struct mwifiex_bss_prio_node, |
| 1045 | list); |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 1046 | atomic_dec(&priv->wmm.tx_pkts_queued); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1047 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1048 | ra_list_flags); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * This function checks if the first packet in the given RA list |
| 1054 | * is already processed or not. |
| 1055 | */ |
| 1056 | static int |
| 1057 | mwifiex_is_ptr_processed(struct mwifiex_private *priv, |
| 1058 | struct mwifiex_ra_list_tbl *ptr) |
| 1059 | { |
| 1060 | struct sk_buff *skb; |
| 1061 | struct mwifiex_txinfo *tx_info; |
| 1062 | |
| 1063 | if (skb_queue_empty(&ptr->skb_head)) |
| 1064 | return false; |
| 1065 | |
| 1066 | skb = skb_peek(&ptr->skb_head); |
| 1067 | |
| 1068 | tx_info = MWIFIEX_SKB_TXCB(skb); |
| 1069 | if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT) |
| 1070 | return true; |
| 1071 | |
| 1072 | return false; |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * This function sends a single processed packet to firmware for |
| 1077 | * transmission. |
| 1078 | */ |
| 1079 | static void |
| 1080 | mwifiex_send_processed_packet(struct mwifiex_private *priv, |
| 1081 | struct mwifiex_ra_list_tbl *ptr, int ptr_index, |
| 1082 | unsigned long ra_list_flags) |
| 1083 | __releases(&priv->wmm.ra_list_spinlock) |
| 1084 | { |
| 1085 | struct mwifiex_tx_param tx_param; |
| 1086 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1087 | int ret = -1; |
| 1088 | struct sk_buff *skb, *skb_next; |
| 1089 | struct mwifiex_txinfo *tx_info; |
| 1090 | |
| 1091 | if (skb_queue_empty(&ptr->skb_head)) { |
| 1092 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1093 | ra_list_flags); |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | skb = skb_dequeue(&ptr->skb_head); |
| 1098 | |
| 1099 | if (!skb_queue_empty(&ptr->skb_head)) |
| 1100 | skb_next = skb_peek(&ptr->skb_head); |
| 1101 | else |
| 1102 | skb_next = NULL; |
| 1103 | |
| 1104 | tx_info = MWIFIEX_SKB_TXCB(skb); |
| 1105 | |
| 1106 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1107 | tx_param.next_pkt_len = |
| 1108 | ((skb_next) ? skb_next->len + |
| 1109 | sizeof(struct txpd) : 0); |
| 1110 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, |
| 1111 | skb->data, skb->len, &tx_param); |
| 1112 | switch (ret) { |
| 1113 | case -EBUSY: |
| 1114 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); |
| 1115 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1116 | |
| 1117 | if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) { |
| 1118 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1119 | ra_list_flags); |
| 1120 | mwifiex_write_data_complete(adapter, skb, -1); |
| 1121 | return; |
| 1122 | } |
| 1123 | |
| 1124 | skb_queue_tail(&ptr->skb_head, skb); |
| 1125 | |
| 1126 | tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT; |
| 1127 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1128 | ra_list_flags); |
| 1129 | break; |
| 1130 | case -1: |
| 1131 | adapter->data_sent = false; |
| 1132 | dev_err(adapter->dev, "host_to_card failed: %#x\n", ret); |
| 1133 | adapter->dbg.num_tx_host_to_card_failure++; |
| 1134 | mwifiex_write_data_complete(adapter, skb, ret); |
| 1135 | break; |
| 1136 | case -EINPROGRESS: |
| 1137 | adapter->data_sent = false; |
| 1138 | default: |
| 1139 | break; |
| 1140 | } |
| 1141 | if (ret != -EBUSY) { |
| 1142 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags); |
| 1143 | if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) { |
| 1144 | priv->wmm.packets_out[ptr_index]++; |
| 1145 | priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr; |
| 1146 | } |
| 1147 | adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur = |
| 1148 | list_first_entry( |
| 1149 | &adapter->bss_prio_tbl[priv->bss_priority] |
| 1150 | .bss_prio_cur->list, |
| 1151 | struct mwifiex_bss_prio_node, |
| 1152 | list); |
Marc Yang | f699254 | 2011-05-16 19:17:49 -0700 | [diff] [blame] | 1153 | atomic_dec(&priv->wmm.tx_pkts_queued); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1154 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, |
| 1155 | ra_list_flags); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | /* |
| 1160 | * This function dequeues a packet from the highest priority list |
| 1161 | * and transmits it. |
| 1162 | */ |
| 1163 | static int |
| 1164 | mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter) |
| 1165 | { |
| 1166 | struct mwifiex_ra_list_tbl *ptr; |
| 1167 | struct mwifiex_private *priv = NULL; |
| 1168 | int ptr_index = 0; |
| 1169 | u8 ra[ETH_ALEN]; |
| 1170 | int tid_del = 0, tid = 0; |
| 1171 | unsigned long flags; |
| 1172 | |
| 1173 | ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index); |
| 1174 | if (!ptr) |
| 1175 | return -1; |
| 1176 | |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 1177 | tid = mwifiex_get_tid(ptr); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1178 | |
| 1179 | dev_dbg(adapter->dev, "data: tid=%d\n", tid); |
| 1180 | |
| 1181 | spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags); |
| 1182 | if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) { |
| 1183 | spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); |
| 1184 | return -1; |
| 1185 | } |
| 1186 | |
| 1187 | if (mwifiex_is_ptr_processed(priv, ptr)) { |
| 1188 | mwifiex_send_processed_packet(priv, ptr, ptr_index, flags); |
| 1189 | /* ra_list_spinlock has been freed in |
| 1190 | mwifiex_send_processed_packet() */ |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | if (!ptr->is_11n_enabled || mwifiex_is_ba_stream_setup(priv, ptr, tid) |
| 1195 | || ((priv->sec_info.wpa_enabled |
| 1196 | || priv->sec_info.wpa2_enabled) && !priv->wpa_is_gtk_set) |
| 1197 | ) { |
| 1198 | mwifiex_send_single_packet(priv, ptr, ptr_index, flags); |
| 1199 | /* ra_list_spinlock has been freed in |
| 1200 | mwifiex_send_single_packet() */ |
| 1201 | } else { |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 1202 | if (mwifiex_is_ampdu_allowed(priv, tid)) { |
Bing Zhao | 53d7938 | 2011-04-13 17:27:09 -0700 | [diff] [blame] | 1203 | if (mwifiex_space_avail_for_new_ba_stream(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1204 | mwifiex_11n_create_tx_ba_stream_tbl(priv, |
| 1205 | ptr->ra, tid, |
| 1206 | BA_STREAM_SETUP_INPROGRESS); |
| 1207 | mwifiex_send_addba(priv, tid, ptr->ra); |
| 1208 | } else if (mwifiex_find_stream_to_delete |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 1209 | (priv, tid, &tid_del, ra)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1210 | mwifiex_11n_create_tx_ba_stream_tbl(priv, |
| 1211 | ptr->ra, tid, |
| 1212 | BA_STREAM_SETUP_INPROGRESS); |
| 1213 | mwifiex_send_delba(priv, tid_del, ra, 1); |
| 1214 | } |
| 1215 | } |
| 1216 | /* Minimum number of AMSDU */ |
| 1217 | #define MIN_NUM_AMSDU 2 |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 1218 | |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 1219 | if (mwifiex_is_amsdu_allowed(priv, tid) && |
Yogesh Ashok Powar | fcf2176 | 2011-06-06 14:49:32 +0530 | [diff] [blame] | 1220 | (ptr->total_pkts >= MIN_NUM_AMSDU)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1221 | mwifiex_11n_aggregate_pkt(priv, ptr, INTF_HEADER_LEN, |
| 1222 | ptr_index, flags); |
| 1223 | /* ra_list_spinlock has been freed in |
| 1224 | mwifiex_11n_aggregate_pkt() */ |
| 1225 | else |
| 1226 | mwifiex_send_single_packet(priv, ptr, ptr_index, flags); |
| 1227 | /* ra_list_spinlock has been freed in |
| 1228 | mwifiex_send_single_packet() */ |
| 1229 | } |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | /* |
| 1234 | * This function transmits the highest priority packet awaiting in the |
| 1235 | * WMM Queues. |
| 1236 | */ |
| 1237 | void |
| 1238 | mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter) |
| 1239 | { |
| 1240 | do { |
| 1241 | /* Check if busy */ |
| 1242 | if (adapter->data_sent || adapter->tx_lock_flag) |
| 1243 | break; |
| 1244 | |
| 1245 | if (mwifiex_dequeue_tx_packet(adapter)) |
| 1246 | break; |
Marc Yang | 9396814 | 2011-05-16 19:17:51 -0700 | [diff] [blame] | 1247 | } while (!mwifiex_wmm_lists_empty(adapter)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1248 | } |