wmm.c 33 KB

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