wmm.c 41 KB

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