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