wmm.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. /*
  2. * Marvell Wireless LAN device driver: WMM
  3. *
  4. * Copyright (C) 2011-2014, 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. mwifiex_dbg(adapter, INFO, "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. u64 ns;
  99. /* setup ba_packet_threshold here random number between
  100. * [BA_SETUP_PACKET_OFFSET,
  101. * BA_SETUP_PACKET_OFFSET+BA_SETUP_MAX_PACKET_THRESHOLD-1]
  102. */
  103. ns = ktime_get_ns();
  104. ns += (ns >> 32) + (ns >> 16);
  105. return ((u8)ns % BA_SETUP_MAX_PACKET_THRESHOLD) + BA_SETUP_PACKET_OFFSET;
  106. }
  107. /*
  108. * This function allocates and adds a RA list for all TIDs
  109. * with the given RA.
  110. */
  111. void mwifiex_ralist_add(struct mwifiex_private *priv, const u8 *ra)
  112. {
  113. int i;
  114. struct mwifiex_ra_list_tbl *ra_list;
  115. struct mwifiex_adapter *adapter = priv->adapter;
  116. struct mwifiex_sta_node *node;
  117. unsigned long flags;
  118. for (i = 0; i < MAX_NUM_TID; ++i) {
  119. ra_list = mwifiex_wmm_allocate_ralist_node(adapter, ra);
  120. mwifiex_dbg(adapter, INFO,
  121. "info: created ra_list %p\n", ra_list);
  122. if (!ra_list)
  123. break;
  124. ra_list->is_11n_enabled = 0;
  125. ra_list->tdls_link = false;
  126. ra_list->ba_status = BA_SETUP_NONE;
  127. ra_list->amsdu_in_ampdu = false;
  128. if (!mwifiex_queuing_ra_based(priv)) {
  129. if (mwifiex_is_tdls_link_setup
  130. (mwifiex_get_tdls_link_status(priv, ra))) {
  131. ra_list->tdls_link = true;
  132. ra_list->is_11n_enabled =
  133. mwifiex_tdls_peer_11n_enabled(priv, ra);
  134. } else {
  135. ra_list->is_11n_enabled = IS_11N_ENABLED(priv);
  136. }
  137. } else {
  138. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  139. node = mwifiex_get_sta_entry(priv, ra);
  140. if (node)
  141. ra_list->tx_paused = node->tx_pause;
  142. ra_list->is_11n_enabled =
  143. mwifiex_is_sta_11n_enabled(priv, node);
  144. if (ra_list->is_11n_enabled)
  145. ra_list->max_amsdu = node->max_amsdu;
  146. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  147. }
  148. mwifiex_dbg(adapter, DATA, "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. mwifiex_dbg(priv->adapter, INFO,
  203. "info: WMM Parameter IE: version=%d,\t"
  204. "qos_info Parameter Set Count=%d, Reserved=%#x\n",
  205. wmm_ie->vend_hdr.version, wmm_ie->qos_info_bitmap &
  206. IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK,
  207. wmm_ie->reserved);
  208. for (num_ac = 0; num_ac < ARRAY_SIZE(wmm_ie->ac_params); num_ac++) {
  209. u8 ecw = wmm_ie->ac_params[num_ac].ecw_bitmap;
  210. u8 aci_aifsn = wmm_ie->ac_params[num_ac].aci_aifsn_bitmap;
  211. cw_min = (1 << (ecw & MWIFIEX_ECW_MIN)) - 1;
  212. avg_back_off = (cw_min >> 1) + (aci_aifsn & MWIFIEX_AIFSN);
  213. ac_idx = wmm_aci_to_qidx_map[(aci_aifsn & MWIFIEX_ACI) >> 5];
  214. priv->wmm.queue_priority[ac_idx] = ac_idx;
  215. tmp[ac_idx] = avg_back_off;
  216. mwifiex_dbg(priv->adapter, INFO,
  217. "info: WMM: CWmax=%d CWmin=%d Avg Back-off=%d\n",
  218. (1 << ((ecw & MWIFIEX_ECW_MAX) >> 4)) - 1,
  219. cw_min, avg_back_off);
  220. mwifiex_wmm_ac_debug_print(&wmm_ie->ac_params[num_ac]);
  221. }
  222. /* Bubble sort */
  223. for (i = 0; i < num_ac; i++) {
  224. for (j = 1; j < num_ac - i; j++) {
  225. if (tmp[j - 1] > tmp[j]) {
  226. swap(tmp[j - 1], tmp[j]);
  227. swap(priv->wmm.queue_priority[j - 1],
  228. priv->wmm.queue_priority[j]);
  229. } else if (tmp[j - 1] == tmp[j]) {
  230. if (priv->wmm.queue_priority[j - 1]
  231. < priv->wmm.queue_priority[j])
  232. swap(priv->wmm.queue_priority[j - 1],
  233. priv->wmm.queue_priority[j]);
  234. }
  235. }
  236. }
  237. mwifiex_wmm_queue_priorities_tid(priv);
  238. }
  239. /*
  240. * This function evaluates whether or not an AC is to be downgraded.
  241. *
  242. * In case the AC is not enabled, the highest AC is returned that is
  243. * enabled and does not require admission control.
  244. */
  245. static enum mwifiex_wmm_ac_e
  246. mwifiex_wmm_eval_downgrade_ac(struct mwifiex_private *priv,
  247. enum mwifiex_wmm_ac_e eval_ac)
  248. {
  249. int down_ac;
  250. enum mwifiex_wmm_ac_e ret_ac;
  251. struct mwifiex_wmm_ac_status *ac_status;
  252. ac_status = &priv->wmm.ac_status[eval_ac];
  253. if (!ac_status->disabled)
  254. /* Okay to use this AC, its enabled */
  255. return eval_ac;
  256. /* Setup a default return value of the lowest priority */
  257. ret_ac = WMM_AC_BK;
  258. /*
  259. * Find the highest AC that is enabled and does not require
  260. * admission control. The spec disallows downgrading to an AC,
  261. * which is enabled due to a completed admission control.
  262. * Unadmitted traffic is not to be sent on an AC with admitted
  263. * traffic.
  264. */
  265. for (down_ac = WMM_AC_BK; down_ac < eval_ac; down_ac++) {
  266. ac_status = &priv->wmm.ac_status[down_ac];
  267. if (!ac_status->disabled && !ac_status->flow_required)
  268. /* AC is enabled and does not require admission
  269. control */
  270. ret_ac = (enum mwifiex_wmm_ac_e) down_ac;
  271. }
  272. return ret_ac;
  273. }
  274. /*
  275. * This function downgrades WMM priority queue.
  276. */
  277. void
  278. mwifiex_wmm_setup_ac_downgrade(struct mwifiex_private *priv)
  279. {
  280. int ac_val;
  281. mwifiex_dbg(priv->adapter, INFO, "info: WMM: AC Priorities:\t"
  282. "BK(0), BE(1), VI(2), VO(3)\n");
  283. if (!priv->wmm_enabled) {
  284. /* WMM is not enabled, default priorities */
  285. for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++)
  286. priv->wmm.ac_down_graded_vals[ac_val] =
  287. (enum mwifiex_wmm_ac_e) ac_val;
  288. } else {
  289. for (ac_val = WMM_AC_BK; ac_val <= WMM_AC_VO; ac_val++) {
  290. priv->wmm.ac_down_graded_vals[ac_val]
  291. = mwifiex_wmm_eval_downgrade_ac(priv,
  292. (enum mwifiex_wmm_ac_e) ac_val);
  293. mwifiex_dbg(priv->adapter, INFO,
  294. "info: WMM: AC PRIO %d maps to %d\n",
  295. ac_val,
  296. priv->wmm.ac_down_graded_vals[ac_val]);
  297. }
  298. }
  299. }
  300. /*
  301. * This function converts the IP TOS field to an WMM AC
  302. * Queue assignment.
  303. */
  304. static enum mwifiex_wmm_ac_e
  305. mwifiex_wmm_convert_tos_to_ac(struct mwifiex_adapter *adapter, u32 tos)
  306. {
  307. /* Map of TOS UP values to WMM AC */
  308. const enum mwifiex_wmm_ac_e tos_to_ac[] = { WMM_AC_BE,
  309. WMM_AC_BK,
  310. WMM_AC_BK,
  311. WMM_AC_BE,
  312. WMM_AC_VI,
  313. WMM_AC_VI,
  314. WMM_AC_VO,
  315. WMM_AC_VO
  316. };
  317. if (tos >= ARRAY_SIZE(tos_to_ac))
  318. return WMM_AC_BE;
  319. return tos_to_ac[tos];
  320. }
  321. /*
  322. * This function evaluates a given TID and downgrades it to a lower
  323. * TID if the WMM Parameter IE received from the AP indicates that the
  324. * AP is disabled (due to call admission control (ACM bit). Mapping
  325. * of TID to AC is taken care of internally.
  326. */
  327. u8 mwifiex_wmm_downgrade_tid(struct mwifiex_private *priv, u32 tid)
  328. {
  329. enum mwifiex_wmm_ac_e ac, ac_down;
  330. u8 new_tid;
  331. ac = mwifiex_wmm_convert_tos_to_ac(priv->adapter, tid);
  332. ac_down = priv->wmm.ac_down_graded_vals[ac];
  333. /* Send the index to tid array, picking from the array will be
  334. * taken care by dequeuing function
  335. */
  336. new_tid = ac_to_tid[ac_down][tid % 2];
  337. return new_tid;
  338. }
  339. /*
  340. * This function initializes the WMM state information and the
  341. * WMM data path queues.
  342. */
  343. void
  344. mwifiex_wmm_init(struct mwifiex_adapter *adapter)
  345. {
  346. int i, j;
  347. struct mwifiex_private *priv;
  348. for (j = 0; j < adapter->priv_num; ++j) {
  349. priv = adapter->priv[j];
  350. if (!priv)
  351. continue;
  352. for (i = 0; i < MAX_NUM_TID; ++i) {
  353. if (!disable_tx_amsdu &&
  354. adapter->tx_buf_size > MWIFIEX_TX_DATA_BUF_SIZE_2K)
  355. priv->aggr_prio_tbl[i].amsdu =
  356. priv->tos_to_tid_inv[i];
  357. else
  358. priv->aggr_prio_tbl[i].amsdu =
  359. BA_STREAM_NOT_ALLOWED;
  360. priv->aggr_prio_tbl[i].ampdu_ap =
  361. priv->tos_to_tid_inv[i];
  362. priv->aggr_prio_tbl[i].ampdu_user =
  363. priv->tos_to_tid_inv[i];
  364. }
  365. priv->aggr_prio_tbl[6].amsdu
  366. = priv->aggr_prio_tbl[6].ampdu_ap
  367. = priv->aggr_prio_tbl[6].ampdu_user
  368. = BA_STREAM_NOT_ALLOWED;
  369. priv->aggr_prio_tbl[7].amsdu = priv->aggr_prio_tbl[7].ampdu_ap
  370. = priv->aggr_prio_tbl[7].ampdu_user
  371. = BA_STREAM_NOT_ALLOWED;
  372. mwifiex_set_ba_params(priv);
  373. mwifiex_reset_11n_rx_seq_num(priv);
  374. priv->wmm.drv_pkt_delay_max = MWIFIEX_WMM_DRV_DELAY_MAX;
  375. atomic_set(&priv->wmm.tx_pkts_queued, 0);
  376. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  377. }
  378. }
  379. int mwifiex_bypass_txlist_empty(struct mwifiex_adapter *adapter)
  380. {
  381. struct mwifiex_private *priv;
  382. int i;
  383. for (i = 0; i < adapter->priv_num; i++) {
  384. priv = adapter->priv[i];
  385. if (!priv)
  386. continue;
  387. if (adapter->if_ops.is_port_ready &&
  388. !adapter->if_ops.is_port_ready(priv))
  389. continue;
  390. if (!skb_queue_empty(&priv->bypass_txq))
  391. return false;
  392. }
  393. return true;
  394. }
  395. /*
  396. * This function checks if WMM Tx queue is empty.
  397. */
  398. int
  399. mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter)
  400. {
  401. int i;
  402. struct mwifiex_private *priv;
  403. for (i = 0; i < adapter->priv_num; ++i) {
  404. priv = adapter->priv[i];
  405. if (!priv)
  406. continue;
  407. if (!priv->port_open &&
  408. (priv->bss_mode != NL80211_IFTYPE_ADHOC))
  409. continue;
  410. if (adapter->if_ops.is_port_ready &&
  411. !adapter->if_ops.is_port_ready(priv))
  412. continue;
  413. if (atomic_read(&priv->wmm.tx_pkts_queued))
  414. return false;
  415. }
  416. return true;
  417. }
  418. /*
  419. * This function deletes all packets in an RA list node.
  420. *
  421. * The packet sent completion callback handler are called with
  422. * status failure, after they are dequeued to ensure proper
  423. * cleanup. The RA list node itself is freed at the end.
  424. */
  425. static void
  426. mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
  427. struct mwifiex_ra_list_tbl *ra_list)
  428. {
  429. struct mwifiex_adapter *adapter = priv->adapter;
  430. struct sk_buff *skb, *tmp;
  431. skb_queue_walk_safe(&ra_list->skb_head, skb, tmp)
  432. mwifiex_write_data_complete(adapter, skb, 0, -1);
  433. }
  434. /*
  435. * This function deletes all packets in an RA list.
  436. *
  437. * Each nodes in the RA list are freed individually first, and then
  438. * the RA list itself is freed.
  439. */
  440. static void
  441. mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
  442. struct list_head *ra_list_head)
  443. {
  444. struct mwifiex_ra_list_tbl *ra_list;
  445. list_for_each_entry(ra_list, ra_list_head, list)
  446. mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
  447. }
  448. /*
  449. * This function deletes all packets in all RA lists.
  450. */
  451. static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
  452. {
  453. int i;
  454. for (i = 0; i < MAX_NUM_TID; i++)
  455. mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
  456. ra_list);
  457. atomic_set(&priv->wmm.tx_pkts_queued, 0);
  458. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  459. }
  460. /*
  461. * This function deletes all route addresses from all RA lists.
  462. */
  463. static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
  464. {
  465. struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
  466. int i;
  467. for (i = 0; i < MAX_NUM_TID; ++i) {
  468. mwifiex_dbg(priv->adapter, INFO,
  469. "info: ra_list: freeing buf for tid %d\n", i);
  470. list_for_each_entry_safe(ra_list, tmp_node,
  471. &priv->wmm.tid_tbl_ptr[i].ra_list,
  472. list) {
  473. list_del(&ra_list->list);
  474. kfree(ra_list);
  475. }
  476. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
  477. }
  478. }
  479. static int mwifiex_free_ack_frame(int id, void *p, void *data)
  480. {
  481. pr_warn("Have pending ack frames!\n");
  482. kfree_skb(p);
  483. return 0;
  484. }
  485. /*
  486. * This function cleans up the Tx and Rx queues.
  487. *
  488. * Cleanup includes -
  489. * - All packets in RA lists
  490. * - All entries in Rx reorder table
  491. * - All entries in Tx BA stream table
  492. * - MPA buffer (if required)
  493. * - All RA lists
  494. */
  495. void
  496. mwifiex_clean_txrx(struct mwifiex_private *priv)
  497. {
  498. unsigned long flags;
  499. struct sk_buff *skb, *tmp;
  500. mwifiex_11n_cleanup_reorder_tbl(priv);
  501. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  502. mwifiex_wmm_cleanup_queues(priv);
  503. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  504. if (priv->adapter->if_ops.cleanup_mpa_buf)
  505. priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
  506. mwifiex_wmm_delete_all_ralist(priv);
  507. memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
  508. if (priv->adapter->if_ops.clean_pcie_ring &&
  509. !priv->adapter->surprise_removed)
  510. priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
  511. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  512. skb_queue_walk_safe(&priv->tdls_txq, skb, tmp)
  513. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  514. skb_queue_walk_safe(&priv->bypass_txq, skb, tmp)
  515. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  516. atomic_set(&priv->adapter->bypass_tx_pending, 0);
  517. idr_for_each(&priv->ack_status_frames, mwifiex_free_ack_frame, NULL);
  518. idr_destroy(&priv->ack_status_frames);
  519. }
  520. /*
  521. * This function retrieves a particular RA list node, matching with the
  522. * given TID and RA address.
  523. */
  524. struct mwifiex_ra_list_tbl *
  525. mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
  526. const u8 *ra_addr)
  527. {
  528. struct mwifiex_ra_list_tbl *ra_list;
  529. list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
  530. list) {
  531. if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
  532. return ra_list;
  533. }
  534. return NULL;
  535. }
  536. void mwifiex_update_ralist_tx_pause(struct mwifiex_private *priv, u8 *mac,
  537. u8 tx_pause)
  538. {
  539. struct mwifiex_ra_list_tbl *ra_list;
  540. u32 pkt_cnt = 0, tx_pkts_queued;
  541. unsigned long flags;
  542. int i;
  543. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  544. for (i = 0; i < MAX_NUM_TID; ++i) {
  545. ra_list = mwifiex_wmm_get_ralist_node(priv, i, mac);
  546. if (ra_list && ra_list->tx_paused != tx_pause) {
  547. pkt_cnt += ra_list->total_pkt_count;
  548. ra_list->tx_paused = tx_pause;
  549. if (tx_pause)
  550. priv->wmm.pkts_paused[i] +=
  551. ra_list->total_pkt_count;
  552. else
  553. priv->wmm.pkts_paused[i] -=
  554. ra_list->total_pkt_count;
  555. }
  556. }
  557. if (pkt_cnt) {
  558. tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
  559. if (tx_pause)
  560. tx_pkts_queued -= pkt_cnt;
  561. else
  562. tx_pkts_queued += pkt_cnt;
  563. atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
  564. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  565. }
  566. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  567. }
  568. /* This function update non-tdls peer ralist tx_pause while
  569. * tdls channel swithing
  570. */
  571. void mwifiex_update_ralist_tx_pause_in_tdls_cs(struct mwifiex_private *priv,
  572. u8 *mac, u8 tx_pause)
  573. {
  574. struct mwifiex_ra_list_tbl *ra_list;
  575. u32 pkt_cnt = 0, tx_pkts_queued;
  576. unsigned long flags;
  577. int i;
  578. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  579. for (i = 0; i < MAX_NUM_TID; ++i) {
  580. list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[i].ra_list,
  581. list) {
  582. if (!memcmp(ra_list->ra, mac, ETH_ALEN))
  583. continue;
  584. if (ra_list->tx_paused != tx_pause) {
  585. pkt_cnt += ra_list->total_pkt_count;
  586. ra_list->tx_paused = tx_pause;
  587. if (tx_pause)
  588. priv->wmm.pkts_paused[i] +=
  589. ra_list->total_pkt_count;
  590. else
  591. priv->wmm.pkts_paused[i] -=
  592. ra_list->total_pkt_count;
  593. }
  594. }
  595. }
  596. if (pkt_cnt) {
  597. tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
  598. if (tx_pause)
  599. tx_pkts_queued -= pkt_cnt;
  600. else
  601. tx_pkts_queued += pkt_cnt;
  602. atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
  603. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  604. }
  605. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  606. }
  607. /*
  608. * This function retrieves an RA list node for a given TID and
  609. * RA address pair.
  610. *
  611. * If no such node is found, a new node is added first and then
  612. * retrieved.
  613. */
  614. struct mwifiex_ra_list_tbl *
  615. mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid,
  616. const u8 *ra_addr)
  617. {
  618. struct mwifiex_ra_list_tbl *ra_list;
  619. ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  620. if (ra_list)
  621. return ra_list;
  622. mwifiex_ralist_add(priv, ra_addr);
  623. return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  624. }
  625. /*
  626. * This function deletes RA list nodes for given mac for all TIDs.
  627. * Function also decrements TX pending count accordingly.
  628. */
  629. void
  630. mwifiex_wmm_del_peer_ra_list(struct mwifiex_private *priv, const u8 *ra_addr)
  631. {
  632. struct mwifiex_ra_list_tbl *ra_list;
  633. unsigned long flags;
  634. int i;
  635. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  636. for (i = 0; i < MAX_NUM_TID; ++i) {
  637. ra_list = mwifiex_wmm_get_ralist_node(priv, i, ra_addr);
  638. if (!ra_list)
  639. continue;
  640. mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
  641. if (ra_list->tx_paused)
  642. priv->wmm.pkts_paused[i] -= ra_list->total_pkt_count;
  643. else
  644. atomic_sub(ra_list->total_pkt_count,
  645. &priv->wmm.tx_pkts_queued);
  646. list_del(&ra_list->list);
  647. kfree(ra_list);
  648. }
  649. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  650. }
  651. /*
  652. * This function checks if a particular RA list node exists in a given TID
  653. * table index.
  654. */
  655. int
  656. mwifiex_is_ralist_valid(struct mwifiex_private *priv,
  657. struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
  658. {
  659. struct mwifiex_ra_list_tbl *rlist;
  660. list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
  661. list) {
  662. if (rlist == ra_list)
  663. return true;
  664. }
  665. return false;
  666. }
  667. /*
  668. * This function adds a packet to bypass TX queue.
  669. * This is special TX queue for packets which can be sent even when port_open
  670. * is false.
  671. */
  672. void
  673. mwifiex_wmm_add_buf_bypass_txqueue(struct mwifiex_private *priv,
  674. struct sk_buff *skb)
  675. {
  676. skb_queue_tail(&priv->bypass_txq, skb);
  677. }
  678. /*
  679. * This function adds a packet to WMM queue.
  680. *
  681. * In disconnected state the packet is immediately dropped and the
  682. * packet send completion callback is called with status failure.
  683. *
  684. * Otherwise, the correct RA list node is located and the packet
  685. * is queued at the list tail.
  686. */
  687. void
  688. mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
  689. struct sk_buff *skb)
  690. {
  691. struct mwifiex_adapter *adapter = priv->adapter;
  692. u32 tid;
  693. struct mwifiex_ra_list_tbl *ra_list;
  694. u8 ra[ETH_ALEN], tid_down;
  695. unsigned long flags;
  696. struct list_head list_head;
  697. int tdls_status = TDLS_NOT_SETUP;
  698. struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
  699. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  700. memcpy(ra, eth_hdr->h_dest, ETH_ALEN);
  701. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  702. ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) {
  703. if (ntohs(eth_hdr->h_proto) == ETH_P_TDLS)
  704. mwifiex_dbg(adapter, DATA,
  705. "TDLS setup packet for %pM.\t"
  706. "Don't block\n", ra);
  707. else if (memcmp(priv->cfg_bssid, ra, ETH_ALEN))
  708. tdls_status = mwifiex_get_tdls_link_status(priv, ra);
  709. }
  710. if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
  711. mwifiex_dbg(adapter, DATA, "data: drop packet in disconnect\n");
  712. mwifiex_write_data_complete(adapter, skb, 0, -1);
  713. return;
  714. }
  715. tid = skb->priority;
  716. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  717. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  718. /* In case of infra as we have already created the list during
  719. association we just don't have to call get_queue_raptr, we will
  720. have only 1 raptr for a tid in case of infra */
  721. if (!mwifiex_queuing_ra_based(priv) &&
  722. !mwifiex_is_skb_mgmt_frame(skb)) {
  723. switch (tdls_status) {
  724. case TDLS_SETUP_COMPLETE:
  725. case TDLS_CHAN_SWITCHING:
  726. case TDLS_IN_BASE_CHAN:
  727. case TDLS_IN_OFF_CHAN:
  728. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down,
  729. ra);
  730. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  731. break;
  732. case TDLS_SETUP_INPROGRESS:
  733. skb_queue_tail(&priv->tdls_txq, skb);
  734. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  735. flags);
  736. return;
  737. default:
  738. list_head = priv->wmm.tid_tbl_ptr[tid_down].ra_list;
  739. if (!list_empty(&list_head))
  740. ra_list = list_first_entry(
  741. &list_head, struct mwifiex_ra_list_tbl,
  742. list);
  743. else
  744. ra_list = NULL;
  745. break;
  746. }
  747. } else {
  748. memcpy(ra, skb->data, ETH_ALEN);
  749. if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
  750. eth_broadcast_addr(ra);
  751. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
  752. }
  753. if (!ra_list) {
  754. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  755. mwifiex_write_data_complete(adapter, skb, 0, -1);
  756. return;
  757. }
  758. skb_queue_tail(&ra_list->skb_head, skb);
  759. ra_list->ba_pkt_count++;
  760. ra_list->total_pkt_count++;
  761. if (atomic_read(&priv->wmm.highest_queued_prio) <
  762. priv->tos_to_tid_inv[tid_down])
  763. atomic_set(&priv->wmm.highest_queued_prio,
  764. priv->tos_to_tid_inv[tid_down]);
  765. if (ra_list->tx_paused)
  766. priv->wmm.pkts_paused[tid_down]++;
  767. else
  768. atomic_inc(&priv->wmm.tx_pkts_queued);
  769. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  770. }
  771. /*
  772. * This function processes the get WMM status command response from firmware.
  773. *
  774. * The response may contain multiple TLVs -
  775. * - AC Queue status TLVs
  776. * - Current WMM Parameter IE TLV
  777. * - Admission Control action frame TLVs
  778. *
  779. * This function parses the TLVs and then calls further specific functions
  780. * to process any changes in the queue prioritize or state.
  781. */
  782. int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
  783. const struct host_cmd_ds_command *resp)
  784. {
  785. u8 *curr = (u8 *) &resp->params.get_wmm_status;
  786. uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
  787. int mask = IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK;
  788. bool valid = true;
  789. struct mwifiex_ie_types_data *tlv_hdr;
  790. struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
  791. struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
  792. struct mwifiex_wmm_ac_status *ac_status;
  793. mwifiex_dbg(priv->adapter, INFO,
  794. "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
  795. resp_len);
  796. while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
  797. tlv_hdr = (struct mwifiex_ie_types_data *) curr;
  798. tlv_len = le16_to_cpu(tlv_hdr->header.len);
  799. if (resp_len < tlv_len + sizeof(tlv_hdr->header))
  800. break;
  801. switch (le16_to_cpu(tlv_hdr->header.type)) {
  802. case TLV_TYPE_WMMQSTATUS:
  803. tlv_wmm_qstatus =
  804. (struct mwifiex_ie_types_wmm_queue_status *)
  805. tlv_hdr;
  806. mwifiex_dbg(priv->adapter, CMD,
  807. "info: CMD_RESP: WMM_GET_STATUS:\t"
  808. "QSTATUS TLV: %d, %d, %d\n",
  809. tlv_wmm_qstatus->queue_index,
  810. tlv_wmm_qstatus->flow_required,
  811. tlv_wmm_qstatus->disabled);
  812. ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
  813. queue_index];
  814. ac_status->disabled = tlv_wmm_qstatus->disabled;
  815. ac_status->flow_required =
  816. tlv_wmm_qstatus->flow_required;
  817. ac_status->flow_created = tlv_wmm_qstatus->flow_created;
  818. break;
  819. case WLAN_EID_VENDOR_SPECIFIC:
  820. /*
  821. * Point the regular IEEE IE 2 bytes into the Marvell IE
  822. * and setup the IEEE IE type and length byte fields
  823. */
  824. wmm_param_ie =
  825. (struct ieee_types_wmm_parameter *) (curr +
  826. 2);
  827. wmm_param_ie->vend_hdr.len = (u8) tlv_len;
  828. wmm_param_ie->vend_hdr.element_id =
  829. WLAN_EID_VENDOR_SPECIFIC;
  830. mwifiex_dbg(priv->adapter, CMD,
  831. "info: CMD_RESP: WMM_GET_STATUS:\t"
  832. "WMM Parameter Set Count: %d\n",
  833. wmm_param_ie->qos_info_bitmap & mask);
  834. memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
  835. wmm_ie, wmm_param_ie,
  836. wmm_param_ie->vend_hdr.len + 2);
  837. break;
  838. default:
  839. valid = false;
  840. break;
  841. }
  842. curr += (tlv_len + sizeof(tlv_hdr->header));
  843. resp_len -= (tlv_len + sizeof(tlv_hdr->header));
  844. }
  845. mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
  846. mwifiex_wmm_setup_ac_downgrade(priv);
  847. return 0;
  848. }
  849. /*
  850. * Callback handler from the command module to allow insertion of a WMM TLV.
  851. *
  852. * If the BSS we are associating to supports WMM, this function adds the
  853. * required WMM Information IE to the association request command buffer in
  854. * the form of a Marvell extended IEEE IE.
  855. */
  856. u32
  857. mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
  858. u8 **assoc_buf,
  859. struct ieee_types_wmm_parameter *wmm_ie,
  860. struct ieee80211_ht_cap *ht_cap)
  861. {
  862. struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
  863. u32 ret_len = 0;
  864. /* Null checks */
  865. if (!assoc_buf)
  866. return 0;
  867. if (!(*assoc_buf))
  868. return 0;
  869. if (!wmm_ie)
  870. return 0;
  871. mwifiex_dbg(priv->adapter, INFO,
  872. "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
  873. wmm_ie->vend_hdr.element_id);
  874. if ((priv->wmm_required ||
  875. (ht_cap && (priv->adapter->config_bands & BAND_GN ||
  876. priv->adapter->config_bands & BAND_AN))) &&
  877. wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
  878. wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
  879. wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
  880. wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
  881. memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
  882. le16_to_cpu(wmm_tlv->header.len));
  883. if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
  884. memcpy((u8 *) (wmm_tlv->wmm_ie
  885. + le16_to_cpu(wmm_tlv->header.len)
  886. - sizeof(priv->wmm_qosinfo)),
  887. &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
  888. ret_len = sizeof(wmm_tlv->header)
  889. + le16_to_cpu(wmm_tlv->header.len);
  890. *assoc_buf += ret_len;
  891. }
  892. return ret_len;
  893. }
  894. /*
  895. * This function computes the time delay in the driver queues for a
  896. * given packet.
  897. *
  898. * When the packet is received at the OS/Driver interface, the current
  899. * time is set in the packet structure. The difference between the present
  900. * time and that received time is computed in this function and limited
  901. * based on pre-compiled limits in the driver.
  902. */
  903. u8
  904. mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
  905. const struct sk_buff *skb)
  906. {
  907. u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));
  908. u8 ret_val;
  909. /*
  910. * Queue delay is passed as a uint8 in units of 2ms (ms shifted
  911. * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
  912. *
  913. * Pass max value if queue_delay is beyond the uint8 range
  914. */
  915. ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
  916. mwifiex_dbg(priv->adapter, DATA, "data: WMM: Pkt Delay: %d ms,\t"
  917. "%d ms sent to FW\n", queue_delay, ret_val);
  918. return ret_val;
  919. }
  920. /*
  921. * This function retrieves the highest priority RA list table pointer.
  922. */
  923. static struct mwifiex_ra_list_tbl *
  924. mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
  925. struct mwifiex_private **priv, int *tid)
  926. {
  927. struct mwifiex_private *priv_tmp;
  928. struct mwifiex_ra_list_tbl *ptr;
  929. struct mwifiex_tid_tbl *tid_ptr;
  930. atomic_t *hqp;
  931. unsigned long flags_ra;
  932. int i, j;
  933. /* check the BSS with highest priority first */
  934. for (j = adapter->priv_num - 1; j >= 0; --j) {
  935. /* iterate over BSS with the equal priority */
  936. list_for_each_entry(adapter->bss_prio_tbl[j].bss_prio_cur,
  937. &adapter->bss_prio_tbl[j].bss_prio_head,
  938. list) {
  939. priv_tmp = adapter->bss_prio_tbl[j].bss_prio_cur->priv;
  940. if (((priv_tmp->bss_mode != NL80211_IFTYPE_ADHOC) &&
  941. !priv_tmp->port_open) ||
  942. (atomic_read(&priv_tmp->wmm.tx_pkts_queued) == 0))
  943. continue;
  944. if (adapter->if_ops.is_port_ready &&
  945. !adapter->if_ops.is_port_ready(priv_tmp))
  946. continue;
  947. /* iterate over the WMM queues of the BSS */
  948. hqp = &priv_tmp->wmm.highest_queued_prio;
  949. for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
  950. spin_lock_irqsave(&priv_tmp->wmm.
  951. ra_list_spinlock, flags_ra);
  952. tid_ptr = &(priv_tmp)->wmm.
  953. tid_tbl_ptr[tos_to_tid[i]];
  954. /* iterate over receiver addresses */
  955. list_for_each_entry(ptr, &tid_ptr->ra_list,
  956. list) {
  957. if (!ptr->tx_paused &&
  958. !skb_queue_empty(&ptr->skb_head))
  959. /* holds both locks */
  960. goto found;
  961. }
  962. spin_unlock_irqrestore(&priv_tmp->wmm.
  963. ra_list_spinlock,
  964. flags_ra);
  965. }
  966. }
  967. }
  968. return NULL;
  969. found:
  970. /* holds ra_list_spinlock */
  971. if (atomic_read(hqp) > i)
  972. atomic_set(hqp, i);
  973. spin_unlock_irqrestore(&priv_tmp->wmm.ra_list_spinlock, flags_ra);
  974. *priv = priv_tmp;
  975. *tid = tos_to_tid[i];
  976. return ptr;
  977. }
  978. /* This functions rotates ra and bss lists so packets are picked round robin.
  979. *
  980. * After a packet is successfully transmitted, rotate the ra list, so the ra
  981. * next to the one transmitted, will come first in the list. This way we pick
  982. * the ra' in a round robin fashion. Same applies to bss nodes of equal
  983. * priority.
  984. *
  985. * Function also increments wmm.packets_out counter.
  986. */
  987. void mwifiex_rotate_priolists(struct mwifiex_private *priv,
  988. struct mwifiex_ra_list_tbl *ra,
  989. int tid)
  990. {
  991. struct mwifiex_adapter *adapter = priv->adapter;
  992. struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
  993. struct mwifiex_tid_tbl *tid_ptr = &priv->wmm.tid_tbl_ptr[tid];
  994. unsigned long flags;
  995. spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
  996. /*
  997. * dirty trick: we remove 'head' temporarily and reinsert it after
  998. * curr bss node. imagine list to stay fixed while head is moved
  999. */
  1000. list_move(&tbl[priv->bss_priority].bss_prio_head,
  1001. &tbl[priv->bss_priority].bss_prio_cur->list);
  1002. spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
  1003. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  1004. if (mwifiex_is_ralist_valid(priv, ra, tid)) {
  1005. priv->wmm.packets_out[tid]++;
  1006. /* same as above */
  1007. list_move(&tid_ptr->ra_list, &ra->list);
  1008. }
  1009. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  1010. }
  1011. /*
  1012. * This function checks if 11n aggregation is possible.
  1013. */
  1014. static int
  1015. mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
  1016. struct mwifiex_ra_list_tbl *ptr,
  1017. int max_buf_size)
  1018. {
  1019. int count = 0, total_size = 0;
  1020. struct sk_buff *skb, *tmp;
  1021. int max_amsdu_size;
  1022. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
  1023. ptr->is_11n_enabled)
  1024. max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
  1025. else
  1026. max_amsdu_size = max_buf_size;
  1027. skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
  1028. total_size += skb->len;
  1029. if (total_size >= max_amsdu_size)
  1030. break;
  1031. if (++count >= MIN_NUM_AMSDU)
  1032. return true;
  1033. }
  1034. return false;
  1035. }
  1036. /*
  1037. * This function sends a single packet to firmware for transmission.
  1038. */
  1039. static void
  1040. mwifiex_send_single_packet(struct mwifiex_private *priv,
  1041. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  1042. unsigned long ra_list_flags)
  1043. __releases(&priv->wmm.ra_list_spinlock)
  1044. {
  1045. struct sk_buff *skb, *skb_next;
  1046. struct mwifiex_tx_param tx_param;
  1047. struct mwifiex_adapter *adapter = priv->adapter;
  1048. struct mwifiex_txinfo *tx_info;
  1049. if (skb_queue_empty(&ptr->skb_head)) {
  1050. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1051. ra_list_flags);
  1052. mwifiex_dbg(adapter, DATA, "data: nothing to send\n");
  1053. return;
  1054. }
  1055. skb = skb_dequeue(&ptr->skb_head);
  1056. tx_info = MWIFIEX_SKB_TXCB(skb);
  1057. mwifiex_dbg(adapter, DATA,
  1058. "data: dequeuing the packet %p %p\n", ptr, skb);
  1059. ptr->total_pkt_count--;
  1060. if (!skb_queue_empty(&ptr->skb_head))
  1061. skb_next = skb_peek(&ptr->skb_head);
  1062. else
  1063. skb_next = NULL;
  1064. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1065. tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
  1066. sizeof(struct txpd) : 0);
  1067. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  1068. /* Queue the packet back at the head */
  1069. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1070. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1071. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1072. ra_list_flags);
  1073. mwifiex_write_data_complete(adapter, skb, 0, -1);
  1074. return;
  1075. }
  1076. skb_queue_tail(&ptr->skb_head, skb);
  1077. ptr->total_pkt_count++;
  1078. ptr->ba_pkt_count++;
  1079. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1080. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1081. ra_list_flags);
  1082. } else {
  1083. mwifiex_rotate_priolists(priv, ptr, ptr_index);
  1084. atomic_dec(&priv->wmm.tx_pkts_queued);
  1085. }
  1086. }
  1087. /*
  1088. * This function checks if the first packet in the given RA list
  1089. * is already processed or not.
  1090. */
  1091. static int
  1092. mwifiex_is_ptr_processed(struct mwifiex_private *priv,
  1093. struct mwifiex_ra_list_tbl *ptr)
  1094. {
  1095. struct sk_buff *skb;
  1096. struct mwifiex_txinfo *tx_info;
  1097. if (skb_queue_empty(&ptr->skb_head))
  1098. return false;
  1099. skb = skb_peek(&ptr->skb_head);
  1100. tx_info = MWIFIEX_SKB_TXCB(skb);
  1101. if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
  1102. return true;
  1103. return false;
  1104. }
  1105. /*
  1106. * This function sends a single processed packet to firmware for
  1107. * transmission.
  1108. */
  1109. static void
  1110. mwifiex_send_processed_packet(struct mwifiex_private *priv,
  1111. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  1112. unsigned long ra_list_flags)
  1113. __releases(&priv->wmm.ra_list_spinlock)
  1114. {
  1115. struct mwifiex_tx_param tx_param;
  1116. struct mwifiex_adapter *adapter = priv->adapter;
  1117. int ret = -1;
  1118. struct sk_buff *skb, *skb_next;
  1119. struct mwifiex_txinfo *tx_info;
  1120. if (skb_queue_empty(&ptr->skb_head)) {
  1121. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1122. ra_list_flags);
  1123. return;
  1124. }
  1125. skb = skb_dequeue(&ptr->skb_head);
  1126. if (adapter->data_sent || adapter->tx_lock_flag) {
  1127. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1128. ra_list_flags);
  1129. skb_queue_tail(&adapter->tx_data_q, skb);
  1130. atomic_inc(&adapter->tx_queued);
  1131. return;
  1132. }
  1133. if (!skb_queue_empty(&ptr->skb_head))
  1134. skb_next = skb_peek(&ptr->skb_head);
  1135. else
  1136. skb_next = NULL;
  1137. tx_info = MWIFIEX_SKB_TXCB(skb);
  1138. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1139. if (adapter->iface_type == MWIFIEX_USB) {
  1140. ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
  1141. skb, NULL);
  1142. } else {
  1143. tx_param.next_pkt_len =
  1144. ((skb_next) ? skb_next->len +
  1145. sizeof(struct txpd) : 0);
  1146. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  1147. skb, &tx_param);
  1148. }
  1149. switch (ret) {
  1150. case -EBUSY:
  1151. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  1152. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1153. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1154. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1155. ra_list_flags);
  1156. mwifiex_write_data_complete(adapter, skb, 0, -1);
  1157. return;
  1158. }
  1159. skb_queue_tail(&ptr->skb_head, skb);
  1160. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1161. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1162. ra_list_flags);
  1163. break;
  1164. case -1:
  1165. mwifiex_dbg(adapter, ERROR, "host_to_card failed: %#x\n", ret);
  1166. adapter->dbg.num_tx_host_to_card_failure++;
  1167. mwifiex_write_data_complete(adapter, skb, 0, ret);
  1168. break;
  1169. case -EINPROGRESS:
  1170. break;
  1171. case 0:
  1172. mwifiex_write_data_complete(adapter, skb, 0, ret);
  1173. default:
  1174. break;
  1175. }
  1176. if (ret != -EBUSY) {
  1177. mwifiex_rotate_priolists(priv, ptr, ptr_index);
  1178. atomic_dec(&priv->wmm.tx_pkts_queued);
  1179. }
  1180. }
  1181. /*
  1182. * This function dequeues a packet from the highest priority list
  1183. * and transmits it.
  1184. */
  1185. static int
  1186. mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
  1187. {
  1188. struct mwifiex_ra_list_tbl *ptr;
  1189. struct mwifiex_private *priv = NULL;
  1190. int ptr_index = 0;
  1191. u8 ra[ETH_ALEN];
  1192. int tid_del = 0, tid = 0;
  1193. unsigned long flags;
  1194. ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
  1195. if (!ptr)
  1196. return -1;
  1197. tid = mwifiex_get_tid(ptr);
  1198. mwifiex_dbg(adapter, DATA, "data: tid=%d\n", tid);
  1199. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  1200. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1201. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  1202. return -1;
  1203. }
  1204. if (mwifiex_is_ptr_processed(priv, ptr)) {
  1205. mwifiex_send_processed_packet(priv, ptr, ptr_index, flags);
  1206. /* ra_list_spinlock has been freed in
  1207. mwifiex_send_processed_packet() */
  1208. return 0;
  1209. }
  1210. if (!ptr->is_11n_enabled ||
  1211. ptr->ba_status ||
  1212. priv->wps.session_enable) {
  1213. if (ptr->is_11n_enabled &&
  1214. ptr->ba_status &&
  1215. ptr->amsdu_in_ampdu &&
  1216. mwifiex_is_amsdu_allowed(priv, tid) &&
  1217. mwifiex_is_11n_aggragation_possible(priv, ptr,
  1218. adapter->tx_buf_size))
  1219. mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index, flags);
  1220. /* ra_list_spinlock has been freed in
  1221. * mwifiex_11n_aggregate_pkt()
  1222. */
  1223. else
  1224. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1225. /* ra_list_spinlock has been freed in
  1226. * mwifiex_send_single_packet()
  1227. */
  1228. } else {
  1229. if (mwifiex_is_ampdu_allowed(priv, ptr, tid) &&
  1230. ptr->ba_pkt_count > ptr->ba_packet_thr) {
  1231. if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
  1232. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1233. BA_SETUP_INPROGRESS);
  1234. mwifiex_send_addba(priv, tid, ptr->ra);
  1235. } else if (mwifiex_find_stream_to_delete
  1236. (priv, tid, &tid_del, ra)) {
  1237. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1238. BA_SETUP_INPROGRESS);
  1239. mwifiex_send_delba(priv, tid_del, ra, 1);
  1240. }
  1241. }
  1242. if (mwifiex_is_amsdu_allowed(priv, tid) &&
  1243. mwifiex_is_11n_aggragation_possible(priv, ptr,
  1244. adapter->tx_buf_size))
  1245. mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index, flags);
  1246. /* ra_list_spinlock has been freed in
  1247. mwifiex_11n_aggregate_pkt() */
  1248. else
  1249. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1250. /* ra_list_spinlock has been freed in
  1251. mwifiex_send_single_packet() */
  1252. }
  1253. return 0;
  1254. }
  1255. void mwifiex_process_bypass_tx(struct mwifiex_adapter *adapter)
  1256. {
  1257. struct mwifiex_tx_param tx_param;
  1258. struct sk_buff *skb;
  1259. struct mwifiex_txinfo *tx_info;
  1260. struct mwifiex_private *priv;
  1261. int i;
  1262. if (adapter->data_sent || adapter->tx_lock_flag)
  1263. return;
  1264. for (i = 0; i < adapter->priv_num; ++i) {
  1265. priv = adapter->priv[i];
  1266. if (!priv)
  1267. continue;
  1268. if (adapter->if_ops.is_port_ready &&
  1269. !adapter->if_ops.is_port_ready(priv))
  1270. continue;
  1271. if (skb_queue_empty(&priv->bypass_txq))
  1272. continue;
  1273. skb = skb_dequeue(&priv->bypass_txq);
  1274. tx_info = MWIFIEX_SKB_TXCB(skb);
  1275. /* no aggregation for bypass packets */
  1276. tx_param.next_pkt_len = 0;
  1277. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  1278. skb_queue_head(&priv->bypass_txq, skb);
  1279. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1280. } else {
  1281. atomic_dec(&adapter->bypass_tx_pending);
  1282. }
  1283. }
  1284. }
  1285. /*
  1286. * This function transmits the highest priority packet awaiting in the
  1287. * WMM Queues.
  1288. */
  1289. void
  1290. mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
  1291. {
  1292. do {
  1293. if (mwifiex_dequeue_tx_packet(adapter))
  1294. break;
  1295. if (adapter->iface_type != MWIFIEX_SDIO) {
  1296. if (adapter->data_sent ||
  1297. adapter->tx_lock_flag)
  1298. break;
  1299. } else {
  1300. if (atomic_read(&adapter->tx_queued) >=
  1301. MWIFIEX_MAX_PKTS_TXQ)
  1302. break;
  1303. }
  1304. } while (!mwifiex_wmm_lists_empty(adapter));
  1305. }