wmm.c 34 KB

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