wmm.c 33 KB

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