wmm.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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. if (ra[0] & 0x01)
  538. memset(ra, 0xff, ETH_ALEN);
  539. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
  540. }
  541. if (!ra_list) {
  542. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  543. mwifiex_write_data_complete(adapter, skb, -1);
  544. return;
  545. }
  546. skb_queue_tail(&ra_list->skb_head, skb);
  547. ra_list->total_pkts_size += skb->len;
  548. ra_list->total_pkts++;
  549. atomic_inc(&priv->wmm.tx_pkts_queued);
  550. if (atomic_read(&priv->wmm.highest_queued_prio) <
  551. tos_to_tid_inv[tid_down])
  552. atomic_set(&priv->wmm.highest_queued_prio,
  553. tos_to_tid_inv[tid_down]);
  554. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  555. }
  556. /*
  557. * This function processes the get WMM status command response from firmware.
  558. *
  559. * The response may contain multiple TLVs -
  560. * - AC Queue status TLVs
  561. * - Current WMM Parameter IE TLV
  562. * - Admission Control action frame TLVs
  563. *
  564. * This function parses the TLVs and then calls further specific functions
  565. * to process any changes in the queue prioritize or state.
  566. */
  567. int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
  568. const struct host_cmd_ds_command *resp)
  569. {
  570. u8 *curr = (u8 *) &resp->params.get_wmm_status;
  571. uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
  572. int valid = true;
  573. struct mwifiex_ie_types_data *tlv_hdr;
  574. struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
  575. struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
  576. struct mwifiex_wmm_ac_status *ac_status;
  577. dev_dbg(priv->adapter->dev, "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
  578. resp_len);
  579. while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
  580. tlv_hdr = (struct mwifiex_ie_types_data *) curr;
  581. tlv_len = le16_to_cpu(tlv_hdr->header.len);
  582. switch (le16_to_cpu(tlv_hdr->header.type)) {
  583. case TLV_TYPE_WMMQSTATUS:
  584. tlv_wmm_qstatus =
  585. (struct mwifiex_ie_types_wmm_queue_status *)
  586. tlv_hdr;
  587. dev_dbg(priv->adapter->dev,
  588. "info: CMD_RESP: WMM_GET_STATUS:"
  589. " QSTATUS TLV: %d, %d, %d\n",
  590. tlv_wmm_qstatus->queue_index,
  591. tlv_wmm_qstatus->flow_required,
  592. tlv_wmm_qstatus->disabled);
  593. ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
  594. queue_index];
  595. ac_status->disabled = tlv_wmm_qstatus->disabled;
  596. ac_status->flow_required =
  597. tlv_wmm_qstatus->flow_required;
  598. ac_status->flow_created = tlv_wmm_qstatus->flow_created;
  599. break;
  600. case WLAN_EID_VENDOR_SPECIFIC:
  601. /*
  602. * Point the regular IEEE IE 2 bytes into the Marvell IE
  603. * and setup the IEEE IE type and length byte fields
  604. */
  605. wmm_param_ie =
  606. (struct ieee_types_wmm_parameter *) (curr +
  607. 2);
  608. wmm_param_ie->vend_hdr.len = (u8) tlv_len;
  609. wmm_param_ie->vend_hdr.element_id =
  610. WLAN_EID_VENDOR_SPECIFIC;
  611. dev_dbg(priv->adapter->dev,
  612. "info: CMD_RESP: WMM_GET_STATUS:"
  613. " WMM Parameter Set Count: %d\n",
  614. wmm_param_ie->qos_info_bitmap &
  615. IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK);
  616. memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
  617. wmm_ie, wmm_param_ie,
  618. wmm_param_ie->vend_hdr.len + 2);
  619. break;
  620. default:
  621. valid = false;
  622. break;
  623. }
  624. curr += (tlv_len + sizeof(tlv_hdr->header));
  625. resp_len -= (tlv_len + sizeof(tlv_hdr->header));
  626. }
  627. mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
  628. mwifiex_wmm_setup_ac_downgrade(priv);
  629. return 0;
  630. }
  631. /*
  632. * Callback handler from the command module to allow insertion of a WMM TLV.
  633. *
  634. * If the BSS we are associating to supports WMM, this function adds the
  635. * required WMM Information IE to the association request command buffer in
  636. * the form of a Marvell extended IEEE IE.
  637. */
  638. u32
  639. mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
  640. u8 **assoc_buf,
  641. struct ieee_types_wmm_parameter *wmm_ie,
  642. struct ieee80211_ht_cap *ht_cap)
  643. {
  644. struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
  645. u32 ret_len = 0;
  646. /* Null checks */
  647. if (!assoc_buf)
  648. return 0;
  649. if (!(*assoc_buf))
  650. return 0;
  651. if (!wmm_ie)
  652. return 0;
  653. dev_dbg(priv->adapter->dev, "info: WMM: process assoc req:"
  654. "bss->wmmIe=0x%x\n",
  655. wmm_ie->vend_hdr.element_id);
  656. if ((priv->wmm_required
  657. || (ht_cap && (priv->adapter->config_bands & BAND_GN
  658. || priv->adapter->config_bands & BAND_AN))
  659. )
  660. && wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
  661. wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
  662. wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
  663. wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
  664. memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
  665. le16_to_cpu(wmm_tlv->header.len));
  666. if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
  667. memcpy((u8 *) (wmm_tlv->wmm_ie
  668. + le16_to_cpu(wmm_tlv->header.len)
  669. - sizeof(priv->wmm_qosinfo)),
  670. &priv->wmm_qosinfo,
  671. sizeof(priv->wmm_qosinfo));
  672. ret_len = sizeof(wmm_tlv->header)
  673. + le16_to_cpu(wmm_tlv->header.len);
  674. *assoc_buf += ret_len;
  675. }
  676. return ret_len;
  677. }
  678. /*
  679. * This function computes the time delay in the driver queues for a
  680. * given packet.
  681. *
  682. * When the packet is received at the OS/Driver interface, the current
  683. * time is set in the packet structure. The difference between the present
  684. * time and that received time is computed in this function and limited
  685. * based on pre-compiled limits in the driver.
  686. */
  687. u8
  688. mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
  689. const struct sk_buff *skb)
  690. {
  691. u8 ret_val;
  692. struct timeval out_tstamp, in_tstamp;
  693. u32 queue_delay;
  694. do_gettimeofday(&out_tstamp);
  695. in_tstamp = ktime_to_timeval(skb->tstamp);
  696. queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) * 1000;
  697. queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) / 1000;
  698. /*
  699. * Queue delay is passed as a uint8 in units of 2ms (ms shifted
  700. * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
  701. *
  702. * Pass max value if queue_delay is beyond the uint8 range
  703. */
  704. ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
  705. dev_dbg(priv->adapter->dev, "data: WMM: Pkt Delay: %d ms,"
  706. " %d ms sent to FW\n", queue_delay, ret_val);
  707. return ret_val;
  708. }
  709. /*
  710. * This function retrieves the highest priority RA list table pointer.
  711. */
  712. static struct mwifiex_ra_list_tbl *
  713. mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
  714. struct mwifiex_private **priv, int *tid)
  715. {
  716. struct mwifiex_private *priv_tmp;
  717. struct mwifiex_ra_list_tbl *ptr, *head;
  718. struct mwifiex_bss_prio_node *bssprio_node, *bssprio_head;
  719. struct mwifiex_tid_tbl *tid_ptr;
  720. int is_list_empty;
  721. unsigned long flags;
  722. int i, j;
  723. for (j = adapter->priv_num - 1; j >= 0; --j) {
  724. spin_lock_irqsave(&adapter->bss_prio_tbl[j].bss_prio_lock,
  725. flags);
  726. is_list_empty = list_empty(&adapter->bss_prio_tbl[j]
  727. .bss_prio_head);
  728. spin_unlock_irqrestore(&adapter->bss_prio_tbl[j].bss_prio_lock,
  729. flags);
  730. if (is_list_empty)
  731. continue;
  732. if (adapter->bss_prio_tbl[j].bss_prio_cur ==
  733. (struct mwifiex_bss_prio_node *)
  734. &adapter->bss_prio_tbl[j].bss_prio_head) {
  735. bssprio_node =
  736. list_first_entry(&adapter->bss_prio_tbl[j]
  737. .bss_prio_head,
  738. struct mwifiex_bss_prio_node,
  739. list);
  740. bssprio_head = bssprio_node;
  741. } else {
  742. bssprio_node = adapter->bss_prio_tbl[j].bss_prio_cur;
  743. bssprio_head = bssprio_node;
  744. }
  745. do {
  746. atomic_t *hqp;
  747. spinlock_t *lock;
  748. priv_tmp = bssprio_node->priv;
  749. hqp = &priv_tmp->wmm.highest_queued_prio;
  750. lock = &priv_tmp->wmm.ra_list_spinlock;
  751. for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
  752. tid_ptr = &(priv_tmp)->wmm.
  753. tid_tbl_ptr[tos_to_tid[i]];
  754. spin_lock_irqsave(&tid_ptr->tid_tbl_lock,
  755. flags);
  756. is_list_empty =
  757. list_empty(&adapter->bss_prio_tbl[j]
  758. .bss_prio_head);
  759. spin_unlock_irqrestore(&tid_ptr->tid_tbl_lock,
  760. flags);
  761. if (is_list_empty)
  762. continue;
  763. /*
  764. * Always choose the next ra we transmitted
  765. * last time, this way we pick the ra's in
  766. * round robin fashion.
  767. */
  768. ptr = list_first_entry(
  769. &tid_ptr->ra_list_curr->list,
  770. struct mwifiex_ra_list_tbl,
  771. list);
  772. head = ptr;
  773. if (ptr == (struct mwifiex_ra_list_tbl *)
  774. &tid_ptr->ra_list) {
  775. /* Get next ra */
  776. ptr = list_first_entry(&ptr->list,
  777. struct mwifiex_ra_list_tbl, list);
  778. head = ptr;
  779. }
  780. do {
  781. is_list_empty =
  782. skb_queue_empty(&ptr->skb_head);
  783. if (!is_list_empty) {
  784. spin_lock_irqsave(lock, flags);
  785. if (atomic_read(hqp) > i)
  786. atomic_set(hqp, i);
  787. spin_unlock_irqrestore(lock,
  788. flags);
  789. *priv = priv_tmp;
  790. *tid = tos_to_tid[i];
  791. return ptr;
  792. }
  793. /* Get next ra */
  794. ptr = list_first_entry(&ptr->list,
  795. struct mwifiex_ra_list_tbl,
  796. list);
  797. if (ptr ==
  798. (struct mwifiex_ra_list_tbl *)
  799. &tid_ptr->ra_list)
  800. ptr = list_first_entry(
  801. &ptr->list,
  802. struct mwifiex_ra_list_tbl,
  803. list);
  804. } while (ptr != head);
  805. }
  806. /* No packet at any TID for this priv. Mark as such
  807. * to skip checking TIDs for this priv (until pkt is
  808. * added).
  809. */
  810. atomic_set(hqp, NO_PKT_PRIO_TID);
  811. /* Get next bss priority node */
  812. bssprio_node = list_first_entry(&bssprio_node->list,
  813. struct mwifiex_bss_prio_node,
  814. list);
  815. if (bssprio_node ==
  816. (struct mwifiex_bss_prio_node *)
  817. &adapter->bss_prio_tbl[j].bss_prio_head)
  818. /* Get next bss priority node */
  819. bssprio_node = list_first_entry(
  820. &bssprio_node->list,
  821. struct mwifiex_bss_prio_node,
  822. list);
  823. } while (bssprio_node != bssprio_head);
  824. }
  825. return NULL;
  826. }
  827. /*
  828. * This function sends a single packet to firmware for transmission.
  829. */
  830. static void
  831. mwifiex_send_single_packet(struct mwifiex_private *priv,
  832. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  833. unsigned long ra_list_flags)
  834. __releases(&priv->wmm.ra_list_spinlock)
  835. {
  836. struct sk_buff *skb, *skb_next;
  837. struct mwifiex_tx_param tx_param;
  838. struct mwifiex_adapter *adapter = priv->adapter;
  839. struct mwifiex_txinfo *tx_info;
  840. if (skb_queue_empty(&ptr->skb_head)) {
  841. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  842. ra_list_flags);
  843. dev_dbg(adapter->dev, "data: nothing to send\n");
  844. return;
  845. }
  846. skb = skb_dequeue(&ptr->skb_head);
  847. tx_info = MWIFIEX_SKB_TXCB(skb);
  848. dev_dbg(adapter->dev, "data: dequeuing the packet %p %p\n", ptr, skb);
  849. ptr->total_pkts_size -= skb->len;
  850. ptr->total_pkts--;
  851. if (!skb_queue_empty(&ptr->skb_head))
  852. skb_next = skb_peek(&ptr->skb_head);
  853. else
  854. skb_next = NULL;
  855. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  856. tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
  857. sizeof(struct txpd) : 0);
  858. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  859. /* Queue the packet back at the head */
  860. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  861. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  862. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  863. ra_list_flags);
  864. mwifiex_write_data_complete(adapter, skb, -1);
  865. return;
  866. }
  867. skb_queue_tail(&ptr->skb_head, skb);
  868. ptr->total_pkts_size += skb->len;
  869. ptr->total_pkts++;
  870. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  871. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  872. ra_list_flags);
  873. } else {
  874. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  875. if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  876. priv->wmm.packets_out[ptr_index]++;
  877. priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
  878. }
  879. adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
  880. list_first_entry(
  881. &adapter->bss_prio_tbl[priv->bss_priority]
  882. .bss_prio_cur->list,
  883. struct mwifiex_bss_prio_node,
  884. list);
  885. atomic_dec(&priv->wmm.tx_pkts_queued);
  886. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  887. ra_list_flags);
  888. }
  889. }
  890. /*
  891. * This function checks if the first packet in the given RA list
  892. * is already processed or not.
  893. */
  894. static int
  895. mwifiex_is_ptr_processed(struct mwifiex_private *priv,
  896. struct mwifiex_ra_list_tbl *ptr)
  897. {
  898. struct sk_buff *skb;
  899. struct mwifiex_txinfo *tx_info;
  900. if (skb_queue_empty(&ptr->skb_head))
  901. return false;
  902. skb = skb_peek(&ptr->skb_head);
  903. tx_info = MWIFIEX_SKB_TXCB(skb);
  904. if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
  905. return true;
  906. return false;
  907. }
  908. /*
  909. * This function sends a single processed packet to firmware for
  910. * transmission.
  911. */
  912. static void
  913. mwifiex_send_processed_packet(struct mwifiex_private *priv,
  914. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  915. unsigned long ra_list_flags)
  916. __releases(&priv->wmm.ra_list_spinlock)
  917. {
  918. struct mwifiex_tx_param tx_param;
  919. struct mwifiex_adapter *adapter = priv->adapter;
  920. int ret = -1;
  921. struct sk_buff *skb, *skb_next;
  922. struct mwifiex_txinfo *tx_info;
  923. if (skb_queue_empty(&ptr->skb_head)) {
  924. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  925. ra_list_flags);
  926. return;
  927. }
  928. skb = skb_dequeue(&ptr->skb_head);
  929. if (!skb_queue_empty(&ptr->skb_head))
  930. skb_next = skb_peek(&ptr->skb_head);
  931. else
  932. skb_next = NULL;
  933. tx_info = MWIFIEX_SKB_TXCB(skb);
  934. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  935. tx_param.next_pkt_len =
  936. ((skb_next) ? skb_next->len +
  937. sizeof(struct txpd) : 0);
  938. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  939. skb->data, skb->len, &tx_param);
  940. switch (ret) {
  941. case -EBUSY:
  942. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  943. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  944. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  945. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  946. ra_list_flags);
  947. mwifiex_write_data_complete(adapter, skb, -1);
  948. return;
  949. }
  950. skb_queue_tail(&ptr->skb_head, skb);
  951. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  952. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  953. ra_list_flags);
  954. break;
  955. case -1:
  956. adapter->data_sent = false;
  957. dev_err(adapter->dev, "host_to_card failed: %#x\n", ret);
  958. adapter->dbg.num_tx_host_to_card_failure++;
  959. mwifiex_write_data_complete(adapter, skb, ret);
  960. break;
  961. case -EINPROGRESS:
  962. adapter->data_sent = false;
  963. default:
  964. break;
  965. }
  966. if (ret != -EBUSY) {
  967. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  968. if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  969. priv->wmm.packets_out[ptr_index]++;
  970. priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
  971. }
  972. adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
  973. list_first_entry(
  974. &adapter->bss_prio_tbl[priv->bss_priority]
  975. .bss_prio_cur->list,
  976. struct mwifiex_bss_prio_node,
  977. list);
  978. atomic_dec(&priv->wmm.tx_pkts_queued);
  979. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  980. ra_list_flags);
  981. }
  982. }
  983. /*
  984. * This function dequeues a packet from the highest priority list
  985. * and transmits it.
  986. */
  987. static int
  988. mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
  989. {
  990. struct mwifiex_ra_list_tbl *ptr;
  991. struct mwifiex_private *priv = NULL;
  992. int ptr_index = 0;
  993. u8 ra[ETH_ALEN];
  994. int tid_del = 0, tid = 0;
  995. unsigned long flags;
  996. ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
  997. if (!ptr)
  998. return -1;
  999. tid = mwifiex_get_tid(ptr);
  1000. dev_dbg(adapter->dev, "data: tid=%d\n", tid);
  1001. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  1002. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1003. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  1004. return -1;
  1005. }
  1006. if (mwifiex_is_ptr_processed(priv, ptr)) {
  1007. mwifiex_send_processed_packet(priv, ptr, ptr_index, flags);
  1008. /* ra_list_spinlock has been freed in
  1009. mwifiex_send_processed_packet() */
  1010. return 0;
  1011. }
  1012. if (!ptr->is_11n_enabled || mwifiex_is_ba_stream_setup(priv, ptr, tid)
  1013. || ((priv->sec_info.wpa_enabled
  1014. || priv->sec_info.wpa2_enabled) && !priv->wpa_is_gtk_set)
  1015. ) {
  1016. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1017. /* ra_list_spinlock has been freed in
  1018. mwifiex_send_single_packet() */
  1019. } else {
  1020. if (mwifiex_is_ampdu_allowed(priv, tid)) {
  1021. if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
  1022. mwifiex_11n_create_tx_ba_stream_tbl(priv,
  1023. ptr->ra, tid,
  1024. BA_STREAM_SETUP_INPROGRESS);
  1025. mwifiex_send_addba(priv, tid, ptr->ra);
  1026. } else if (mwifiex_find_stream_to_delete
  1027. (priv, tid, &tid_del, ra)) {
  1028. mwifiex_11n_create_tx_ba_stream_tbl(priv,
  1029. ptr->ra, tid,
  1030. BA_STREAM_SETUP_INPROGRESS);
  1031. mwifiex_send_delba(priv, tid_del, ra, 1);
  1032. }
  1033. }
  1034. /* Minimum number of AMSDU */
  1035. #define MIN_NUM_AMSDU 2
  1036. if (mwifiex_is_amsdu_allowed(priv, tid) &&
  1037. (ptr->total_pkts >= MIN_NUM_AMSDU))
  1038. mwifiex_11n_aggregate_pkt(priv, ptr, INTF_HEADER_LEN,
  1039. ptr_index, flags);
  1040. /* ra_list_spinlock has been freed in
  1041. mwifiex_11n_aggregate_pkt() */
  1042. else
  1043. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1044. /* ra_list_spinlock has been freed in
  1045. mwifiex_send_single_packet() */
  1046. }
  1047. return 0;
  1048. }
  1049. /*
  1050. * This function transmits the highest priority packet awaiting in the
  1051. * WMM Queues.
  1052. */
  1053. void
  1054. mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
  1055. {
  1056. do {
  1057. /* Check if busy */
  1058. if (adapter->data_sent || adapter->tx_lock_flag)
  1059. break;
  1060. if (mwifiex_dequeue_tx_packet(adapter))
  1061. break;
  1062. } while (!mwifiex_wmm_lists_empty(adapter));
  1063. }