wmm.c 34 KB

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