wmm.c 34 KB

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