wmm.c 36 KB

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