wmm.c 36 KB

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