wmm.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  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. skb_unlink(skb, &ra_list->skb_head);
  433. mwifiex_write_data_complete(adapter, skb, 0, -1);
  434. }
  435. }
  436. /*
  437. * This function deletes all packets in an RA list.
  438. *
  439. * Each nodes in the RA list are freed individually first, and then
  440. * the RA list itself is freed.
  441. */
  442. static void
  443. mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
  444. struct list_head *ra_list_head)
  445. {
  446. struct mwifiex_ra_list_tbl *ra_list;
  447. list_for_each_entry(ra_list, ra_list_head, list)
  448. mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
  449. }
  450. /*
  451. * This function deletes all packets in all RA lists.
  452. */
  453. static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
  454. {
  455. int i;
  456. for (i = 0; i < MAX_NUM_TID; i++)
  457. mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
  458. ra_list);
  459. atomic_set(&priv->wmm.tx_pkts_queued, 0);
  460. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  461. }
  462. /*
  463. * This function deletes all route addresses from all RA lists.
  464. */
  465. static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
  466. {
  467. struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
  468. int i;
  469. for (i = 0; i < MAX_NUM_TID; ++i) {
  470. mwifiex_dbg(priv->adapter, INFO,
  471. "info: ra_list: freeing buf for tid %d\n", i);
  472. list_for_each_entry_safe(ra_list, tmp_node,
  473. &priv->wmm.tid_tbl_ptr[i].ra_list,
  474. list) {
  475. list_del(&ra_list->list);
  476. kfree(ra_list);
  477. }
  478. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
  479. }
  480. }
  481. static int mwifiex_free_ack_frame(int id, void *p, void *data)
  482. {
  483. pr_warn("Have pending ack frames!\n");
  484. kfree_skb(p);
  485. return 0;
  486. }
  487. /*
  488. * This function cleans up the Tx and Rx queues.
  489. *
  490. * Cleanup includes -
  491. * - All packets in RA lists
  492. * - All entries in Rx reorder table
  493. * - All entries in Tx BA stream table
  494. * - MPA buffer (if required)
  495. * - All RA lists
  496. */
  497. void
  498. mwifiex_clean_txrx(struct mwifiex_private *priv)
  499. {
  500. unsigned long flags;
  501. struct sk_buff *skb, *tmp;
  502. mwifiex_11n_cleanup_reorder_tbl(priv);
  503. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  504. mwifiex_wmm_cleanup_queues(priv);
  505. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  506. if (priv->adapter->if_ops.cleanup_mpa_buf)
  507. priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
  508. mwifiex_wmm_delete_all_ralist(priv);
  509. memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
  510. if (priv->adapter->if_ops.clean_pcie_ring &&
  511. !priv->adapter->surprise_removed)
  512. priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
  513. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  514. skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
  515. skb_unlink(skb, &priv->tdls_txq);
  516. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  517. }
  518. skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
  519. skb_unlink(skb, &priv->bypass_txq);
  520. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  521. }
  522. atomic_set(&priv->adapter->bypass_tx_pending, 0);
  523. idr_for_each(&priv->ack_status_frames, mwifiex_free_ack_frame, NULL);
  524. idr_destroy(&priv->ack_status_frames);
  525. }
  526. /*
  527. * This function retrieves a particular RA list node, matching with the
  528. * given TID and RA address.
  529. */
  530. struct mwifiex_ra_list_tbl *
  531. mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
  532. const u8 *ra_addr)
  533. {
  534. struct mwifiex_ra_list_tbl *ra_list;
  535. list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
  536. list) {
  537. if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
  538. return ra_list;
  539. }
  540. return NULL;
  541. }
  542. void mwifiex_update_ralist_tx_pause(struct mwifiex_private *priv, u8 *mac,
  543. u8 tx_pause)
  544. {
  545. struct mwifiex_ra_list_tbl *ra_list;
  546. u32 pkt_cnt = 0, tx_pkts_queued;
  547. unsigned long flags;
  548. int i;
  549. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  550. for (i = 0; i < MAX_NUM_TID; ++i) {
  551. ra_list = mwifiex_wmm_get_ralist_node(priv, i, mac);
  552. if (ra_list && ra_list->tx_paused != tx_pause) {
  553. pkt_cnt += ra_list->total_pkt_count;
  554. ra_list->tx_paused = tx_pause;
  555. if (tx_pause)
  556. priv->wmm.pkts_paused[i] +=
  557. ra_list->total_pkt_count;
  558. else
  559. priv->wmm.pkts_paused[i] -=
  560. ra_list->total_pkt_count;
  561. }
  562. }
  563. if (pkt_cnt) {
  564. tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
  565. if (tx_pause)
  566. tx_pkts_queued -= pkt_cnt;
  567. else
  568. tx_pkts_queued += pkt_cnt;
  569. atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
  570. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  571. }
  572. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  573. }
  574. /* This function updates non-tdls peer ralist tx_pause while
  575. * tdls channel switching
  576. */
  577. void mwifiex_update_ralist_tx_pause_in_tdls_cs(struct mwifiex_private *priv,
  578. u8 *mac, u8 tx_pause)
  579. {
  580. struct mwifiex_ra_list_tbl *ra_list;
  581. u32 pkt_cnt = 0, tx_pkts_queued;
  582. unsigned long flags;
  583. int i;
  584. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  585. for (i = 0; i < MAX_NUM_TID; ++i) {
  586. list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[i].ra_list,
  587. list) {
  588. if (!memcmp(ra_list->ra, mac, ETH_ALEN))
  589. continue;
  590. if (ra_list->tx_paused != tx_pause) {
  591. pkt_cnt += ra_list->total_pkt_count;
  592. ra_list->tx_paused = tx_pause;
  593. if (tx_pause)
  594. priv->wmm.pkts_paused[i] +=
  595. ra_list->total_pkt_count;
  596. else
  597. priv->wmm.pkts_paused[i] -=
  598. ra_list->total_pkt_count;
  599. }
  600. }
  601. }
  602. if (pkt_cnt) {
  603. tx_pkts_queued = atomic_read(&priv->wmm.tx_pkts_queued);
  604. if (tx_pause)
  605. tx_pkts_queued -= pkt_cnt;
  606. else
  607. tx_pkts_queued += pkt_cnt;
  608. atomic_set(&priv->wmm.tx_pkts_queued, tx_pkts_queued);
  609. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  610. }
  611. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  612. }
  613. /*
  614. * This function retrieves an RA list node for a given TID and
  615. * RA address pair.
  616. *
  617. * If no such node is found, a new node is added first and then
  618. * retrieved.
  619. */
  620. struct mwifiex_ra_list_tbl *
  621. mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid,
  622. const u8 *ra_addr)
  623. {
  624. struct mwifiex_ra_list_tbl *ra_list;
  625. ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  626. if (ra_list)
  627. return ra_list;
  628. mwifiex_ralist_add(priv, ra_addr);
  629. return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  630. }
  631. /*
  632. * This function deletes RA list nodes for given mac for all TIDs.
  633. * Function also decrements TX pending count accordingly.
  634. */
  635. void
  636. mwifiex_wmm_del_peer_ra_list(struct mwifiex_private *priv, const u8 *ra_addr)
  637. {
  638. struct mwifiex_ra_list_tbl *ra_list;
  639. unsigned long flags;
  640. int i;
  641. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  642. for (i = 0; i < MAX_NUM_TID; ++i) {
  643. ra_list = mwifiex_wmm_get_ralist_node(priv, i, ra_addr);
  644. if (!ra_list)
  645. continue;
  646. mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
  647. if (ra_list->tx_paused)
  648. priv->wmm.pkts_paused[i] -= ra_list->total_pkt_count;
  649. else
  650. atomic_sub(ra_list->total_pkt_count,
  651. &priv->wmm.tx_pkts_queued);
  652. list_del(&ra_list->list);
  653. kfree(ra_list);
  654. }
  655. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  656. }
  657. /*
  658. * This function checks if a particular RA list node exists in a given TID
  659. * table index.
  660. */
  661. int
  662. mwifiex_is_ralist_valid(struct mwifiex_private *priv,
  663. struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
  664. {
  665. struct mwifiex_ra_list_tbl *rlist;
  666. list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
  667. list) {
  668. if (rlist == ra_list)
  669. return true;
  670. }
  671. return false;
  672. }
  673. /*
  674. * This function adds a packet to bypass TX queue.
  675. * This is special TX queue for packets which can be sent even when port_open
  676. * is false.
  677. */
  678. void
  679. mwifiex_wmm_add_buf_bypass_txqueue(struct mwifiex_private *priv,
  680. struct sk_buff *skb)
  681. {
  682. skb_queue_tail(&priv->bypass_txq, skb);
  683. }
  684. /*
  685. * This function adds a packet to WMM queue.
  686. *
  687. * In disconnected state the packet is immediately dropped and the
  688. * packet send completion callback is called with status failure.
  689. *
  690. * Otherwise, the correct RA list node is located and the packet
  691. * is queued at the list tail.
  692. */
  693. void
  694. mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
  695. struct sk_buff *skb)
  696. {
  697. struct mwifiex_adapter *adapter = priv->adapter;
  698. u32 tid;
  699. struct mwifiex_ra_list_tbl *ra_list;
  700. u8 ra[ETH_ALEN], tid_down;
  701. unsigned long flags;
  702. struct list_head list_head;
  703. int tdls_status = TDLS_NOT_SETUP;
  704. struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
  705. struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
  706. memcpy(ra, eth_hdr->h_dest, ETH_ALEN);
  707. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  708. ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) {
  709. if (ntohs(eth_hdr->h_proto) == ETH_P_TDLS)
  710. mwifiex_dbg(adapter, DATA,
  711. "TDLS setup packet for %pM.\t"
  712. "Don't block\n", ra);
  713. else if (memcmp(priv->cfg_bssid, ra, ETH_ALEN))
  714. tdls_status = mwifiex_get_tdls_link_status(priv, ra);
  715. }
  716. if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
  717. mwifiex_dbg(adapter, DATA, "data: drop packet in disconnect\n");
  718. mwifiex_write_data_complete(adapter, skb, 0, -1);
  719. return;
  720. }
  721. tid = skb->priority;
  722. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  723. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  724. /* In case of infra as we have already created the list during
  725. association we just don't have to call get_queue_raptr, we will
  726. have only 1 raptr for a tid in case of infra */
  727. if (!mwifiex_queuing_ra_based(priv) &&
  728. !mwifiex_is_skb_mgmt_frame(skb)) {
  729. switch (tdls_status) {
  730. case TDLS_SETUP_COMPLETE:
  731. case TDLS_CHAN_SWITCHING:
  732. case TDLS_IN_BASE_CHAN:
  733. case TDLS_IN_OFF_CHAN:
  734. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down,
  735. ra);
  736. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  737. break;
  738. case TDLS_SETUP_INPROGRESS:
  739. skb_queue_tail(&priv->tdls_txq, skb);
  740. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  741. flags);
  742. return;
  743. default:
  744. list_head = priv->wmm.tid_tbl_ptr[tid_down].ra_list;
  745. if (!list_empty(&list_head))
  746. ra_list = list_first_entry(
  747. &list_head, struct mwifiex_ra_list_tbl,
  748. list);
  749. else
  750. ra_list = NULL;
  751. break;
  752. }
  753. } else {
  754. memcpy(ra, skb->data, ETH_ALEN);
  755. if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
  756. eth_broadcast_addr(ra);
  757. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
  758. }
  759. if (!ra_list) {
  760. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  761. mwifiex_write_data_complete(adapter, skb, 0, -1);
  762. return;
  763. }
  764. skb_queue_tail(&ra_list->skb_head, skb);
  765. ra_list->ba_pkt_count++;
  766. ra_list->total_pkt_count++;
  767. if (atomic_read(&priv->wmm.highest_queued_prio) <
  768. priv->tos_to_tid_inv[tid_down])
  769. atomic_set(&priv->wmm.highest_queued_prio,
  770. priv->tos_to_tid_inv[tid_down]);
  771. if (ra_list->tx_paused)
  772. priv->wmm.pkts_paused[tid_down]++;
  773. else
  774. atomic_inc(&priv->wmm.tx_pkts_queued);
  775. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  776. }
  777. /*
  778. * This function processes the get WMM status command response from firmware.
  779. *
  780. * The response may contain multiple TLVs -
  781. * - AC Queue status TLVs
  782. * - Current WMM Parameter IE TLV
  783. * - Admission Control action frame TLVs
  784. *
  785. * This function parses the TLVs and then calls further specific functions
  786. * to process any changes in the queue prioritize or state.
  787. */
  788. int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
  789. const struct host_cmd_ds_command *resp)
  790. {
  791. u8 *curr = (u8 *) &resp->params.get_wmm_status;
  792. uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
  793. int mask = IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK;
  794. bool valid = true;
  795. struct mwifiex_ie_types_data *tlv_hdr;
  796. struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
  797. struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
  798. struct mwifiex_wmm_ac_status *ac_status;
  799. mwifiex_dbg(priv->adapter, INFO,
  800. "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
  801. resp_len);
  802. while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
  803. tlv_hdr = (struct mwifiex_ie_types_data *) curr;
  804. tlv_len = le16_to_cpu(tlv_hdr->header.len);
  805. if (resp_len < tlv_len + sizeof(tlv_hdr->header))
  806. break;
  807. switch (le16_to_cpu(tlv_hdr->header.type)) {
  808. case TLV_TYPE_WMMQSTATUS:
  809. tlv_wmm_qstatus =
  810. (struct mwifiex_ie_types_wmm_queue_status *)
  811. tlv_hdr;
  812. mwifiex_dbg(priv->adapter, CMD,
  813. "info: CMD_RESP: WMM_GET_STATUS:\t"
  814. "QSTATUS TLV: %d, %d, %d\n",
  815. tlv_wmm_qstatus->queue_index,
  816. tlv_wmm_qstatus->flow_required,
  817. tlv_wmm_qstatus->disabled);
  818. ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
  819. queue_index];
  820. ac_status->disabled = tlv_wmm_qstatus->disabled;
  821. ac_status->flow_required =
  822. tlv_wmm_qstatus->flow_required;
  823. ac_status->flow_created = tlv_wmm_qstatus->flow_created;
  824. break;
  825. case WLAN_EID_VENDOR_SPECIFIC:
  826. /*
  827. * Point the regular IEEE IE 2 bytes into the Marvell IE
  828. * and setup the IEEE IE type and length byte fields
  829. */
  830. wmm_param_ie =
  831. (struct ieee_types_wmm_parameter *) (curr +
  832. 2);
  833. wmm_param_ie->vend_hdr.len = (u8) tlv_len;
  834. wmm_param_ie->vend_hdr.element_id =
  835. WLAN_EID_VENDOR_SPECIFIC;
  836. mwifiex_dbg(priv->adapter, CMD,
  837. "info: CMD_RESP: WMM_GET_STATUS:\t"
  838. "WMM Parameter Set Count: %d\n",
  839. wmm_param_ie->qos_info_bitmap & mask);
  840. memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
  841. wmm_ie, wmm_param_ie,
  842. wmm_param_ie->vend_hdr.len + 2);
  843. break;
  844. default:
  845. valid = false;
  846. break;
  847. }
  848. curr += (tlv_len + sizeof(tlv_hdr->header));
  849. resp_len -= (tlv_len + sizeof(tlv_hdr->header));
  850. }
  851. mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
  852. mwifiex_wmm_setup_ac_downgrade(priv);
  853. return 0;
  854. }
  855. /*
  856. * Callback handler from the command module to allow insertion of a WMM TLV.
  857. *
  858. * If the BSS we are associating to supports WMM, this function adds the
  859. * required WMM Information IE to the association request command buffer in
  860. * the form of a Marvell extended IEEE IE.
  861. */
  862. u32
  863. mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
  864. u8 **assoc_buf,
  865. struct ieee_types_wmm_parameter *wmm_ie,
  866. struct ieee80211_ht_cap *ht_cap)
  867. {
  868. struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
  869. u32 ret_len = 0;
  870. /* Null checks */
  871. if (!assoc_buf)
  872. return 0;
  873. if (!(*assoc_buf))
  874. return 0;
  875. if (!wmm_ie)
  876. return 0;
  877. mwifiex_dbg(priv->adapter, INFO,
  878. "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
  879. wmm_ie->vend_hdr.element_id);
  880. if ((priv->wmm_required ||
  881. (ht_cap && (priv->adapter->config_bands & BAND_GN ||
  882. priv->adapter->config_bands & BAND_AN))) &&
  883. wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
  884. wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
  885. wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
  886. wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
  887. memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
  888. le16_to_cpu(wmm_tlv->header.len));
  889. if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
  890. memcpy((u8 *) (wmm_tlv->wmm_ie
  891. + le16_to_cpu(wmm_tlv->header.len)
  892. - sizeof(priv->wmm_qosinfo)),
  893. &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
  894. ret_len = sizeof(wmm_tlv->header)
  895. + le16_to_cpu(wmm_tlv->header.len);
  896. *assoc_buf += ret_len;
  897. }
  898. return ret_len;
  899. }
  900. /*
  901. * This function computes the time delay in the driver queues for a
  902. * given packet.
  903. *
  904. * When the packet is received at the OS/Driver interface, the current
  905. * time is set in the packet structure. The difference between the present
  906. * time and that received time is computed in this function and limited
  907. * based on pre-compiled limits in the driver.
  908. */
  909. u8
  910. mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
  911. const struct sk_buff *skb)
  912. {
  913. u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));
  914. u8 ret_val;
  915. /*
  916. * Queue delay is passed as a uint8 in units of 2ms (ms shifted
  917. * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
  918. *
  919. * Pass max value if queue_delay is beyond the uint8 range
  920. */
  921. ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
  922. mwifiex_dbg(priv->adapter, DATA, "data: WMM: Pkt Delay: %d ms,\t"
  923. "%d ms sent to FW\n", queue_delay, ret_val);
  924. return ret_val;
  925. }
  926. /*
  927. * This function retrieves the highest priority RA list table pointer.
  928. */
  929. static struct mwifiex_ra_list_tbl *
  930. mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
  931. struct mwifiex_private **priv, int *tid)
  932. {
  933. struct mwifiex_private *priv_tmp;
  934. struct mwifiex_ra_list_tbl *ptr;
  935. struct mwifiex_tid_tbl *tid_ptr;
  936. atomic_t *hqp;
  937. unsigned long flags_ra;
  938. int i, j;
  939. /* check the BSS with highest priority first */
  940. for (j = adapter->priv_num - 1; j >= 0; --j) {
  941. /* iterate over BSS with the equal priority */
  942. list_for_each_entry(adapter->bss_prio_tbl[j].bss_prio_cur,
  943. &adapter->bss_prio_tbl[j].bss_prio_head,
  944. list) {
  945. try_again:
  946. priv_tmp = adapter->bss_prio_tbl[j].bss_prio_cur->priv;
  947. if (((priv_tmp->bss_mode != NL80211_IFTYPE_ADHOC) &&
  948. !priv_tmp->port_open) ||
  949. (atomic_read(&priv_tmp->wmm.tx_pkts_queued) == 0))
  950. continue;
  951. if (adapter->if_ops.is_port_ready &&
  952. !adapter->if_ops.is_port_ready(priv_tmp))
  953. continue;
  954. /* iterate over the WMM queues of the BSS */
  955. hqp = &priv_tmp->wmm.highest_queued_prio;
  956. for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
  957. spin_lock_irqsave(&priv_tmp->wmm.
  958. ra_list_spinlock, flags_ra);
  959. tid_ptr = &(priv_tmp)->wmm.
  960. tid_tbl_ptr[tos_to_tid[i]];
  961. /* iterate over receiver addresses */
  962. list_for_each_entry(ptr, &tid_ptr->ra_list,
  963. list) {
  964. if (!ptr->tx_paused &&
  965. !skb_queue_empty(&ptr->skb_head))
  966. /* holds both locks */
  967. goto found;
  968. }
  969. spin_unlock_irqrestore(&priv_tmp->wmm.
  970. ra_list_spinlock,
  971. flags_ra);
  972. }
  973. if (atomic_read(&priv_tmp->wmm.tx_pkts_queued) != 0) {
  974. atomic_set(&priv_tmp->wmm.highest_queued_prio,
  975. HIGH_PRIO_TID);
  976. /* Iterate current private once more, since
  977. * there still exist packets in data queue
  978. */
  979. goto try_again;
  980. } else
  981. atomic_set(&priv_tmp->wmm.highest_queued_prio,
  982. NO_PKT_PRIO_TID);
  983. }
  984. }
  985. return NULL;
  986. found:
  987. /* holds ra_list_spinlock */
  988. if (atomic_read(hqp) > i)
  989. atomic_set(hqp, i);
  990. spin_unlock_irqrestore(&priv_tmp->wmm.ra_list_spinlock, flags_ra);
  991. *priv = priv_tmp;
  992. *tid = tos_to_tid[i];
  993. return ptr;
  994. }
  995. /* This functions rotates ra and bss lists so packets are picked round robin.
  996. *
  997. * After a packet is successfully transmitted, rotate the ra list, so the ra
  998. * next to the one transmitted, will come first in the list. This way we pick
  999. * the ra' in a round robin fashion. Same applies to bss nodes of equal
  1000. * priority.
  1001. *
  1002. * Function also increments wmm.packets_out counter.
  1003. */
  1004. void mwifiex_rotate_priolists(struct mwifiex_private *priv,
  1005. struct mwifiex_ra_list_tbl *ra,
  1006. int tid)
  1007. {
  1008. struct mwifiex_adapter *adapter = priv->adapter;
  1009. struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
  1010. struct mwifiex_tid_tbl *tid_ptr = &priv->wmm.tid_tbl_ptr[tid];
  1011. unsigned long flags;
  1012. spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
  1013. /*
  1014. * dirty trick: we remove 'head' temporarily and reinsert it after
  1015. * curr bss node. imagine list to stay fixed while head is moved
  1016. */
  1017. list_move(&tbl[priv->bss_priority].bss_prio_head,
  1018. &tbl[priv->bss_priority].bss_prio_cur->list);
  1019. spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
  1020. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  1021. if (mwifiex_is_ralist_valid(priv, ra, tid)) {
  1022. priv->wmm.packets_out[tid]++;
  1023. /* same as above */
  1024. list_move(&tid_ptr->ra_list, &ra->list);
  1025. }
  1026. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  1027. }
  1028. /*
  1029. * This function checks if 11n aggregation is possible.
  1030. */
  1031. static int
  1032. mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
  1033. struct mwifiex_ra_list_tbl *ptr,
  1034. int max_buf_size)
  1035. {
  1036. int count = 0, total_size = 0;
  1037. struct sk_buff *skb, *tmp;
  1038. int max_amsdu_size;
  1039. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
  1040. ptr->is_11n_enabled)
  1041. max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
  1042. else
  1043. max_amsdu_size = max_buf_size;
  1044. skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
  1045. total_size += skb->len;
  1046. if (total_size >= max_amsdu_size)
  1047. break;
  1048. if (++count >= MIN_NUM_AMSDU)
  1049. return true;
  1050. }
  1051. return false;
  1052. }
  1053. /*
  1054. * This function sends a single packet to firmware for transmission.
  1055. */
  1056. static void
  1057. mwifiex_send_single_packet(struct mwifiex_private *priv,
  1058. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  1059. unsigned long ra_list_flags)
  1060. __releases(&priv->wmm.ra_list_spinlock)
  1061. {
  1062. struct sk_buff *skb, *skb_next;
  1063. struct mwifiex_tx_param tx_param;
  1064. struct mwifiex_adapter *adapter = priv->adapter;
  1065. struct mwifiex_txinfo *tx_info;
  1066. if (skb_queue_empty(&ptr->skb_head)) {
  1067. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1068. ra_list_flags);
  1069. mwifiex_dbg(adapter, DATA, "data: nothing to send\n");
  1070. return;
  1071. }
  1072. skb = skb_dequeue(&ptr->skb_head);
  1073. tx_info = MWIFIEX_SKB_TXCB(skb);
  1074. mwifiex_dbg(adapter, DATA,
  1075. "data: dequeuing the packet %p %p\n", ptr, skb);
  1076. ptr->total_pkt_count--;
  1077. if (!skb_queue_empty(&ptr->skb_head))
  1078. skb_next = skb_peek(&ptr->skb_head);
  1079. else
  1080. skb_next = NULL;
  1081. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1082. tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
  1083. sizeof(struct txpd) : 0);
  1084. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  1085. /* Queue the packet back at the head */
  1086. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1087. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1088. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1089. ra_list_flags);
  1090. mwifiex_write_data_complete(adapter, skb, 0, -1);
  1091. return;
  1092. }
  1093. skb_queue_tail(&ptr->skb_head, skb);
  1094. ptr->total_pkt_count++;
  1095. ptr->ba_pkt_count++;
  1096. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1097. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1098. ra_list_flags);
  1099. } else {
  1100. mwifiex_rotate_priolists(priv, ptr, ptr_index);
  1101. atomic_dec(&priv->wmm.tx_pkts_queued);
  1102. }
  1103. }
  1104. /*
  1105. * This function checks if the first packet in the given RA list
  1106. * is already processed or not.
  1107. */
  1108. static int
  1109. mwifiex_is_ptr_processed(struct mwifiex_private *priv,
  1110. struct mwifiex_ra_list_tbl *ptr)
  1111. {
  1112. struct sk_buff *skb;
  1113. struct mwifiex_txinfo *tx_info;
  1114. if (skb_queue_empty(&ptr->skb_head))
  1115. return false;
  1116. skb = skb_peek(&ptr->skb_head);
  1117. tx_info = MWIFIEX_SKB_TXCB(skb);
  1118. if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
  1119. return true;
  1120. return false;
  1121. }
  1122. /*
  1123. * This function sends a single processed packet to firmware for
  1124. * transmission.
  1125. */
  1126. static void
  1127. mwifiex_send_processed_packet(struct mwifiex_private *priv,
  1128. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  1129. unsigned long ra_list_flags)
  1130. __releases(&priv->wmm.ra_list_spinlock)
  1131. {
  1132. struct mwifiex_tx_param tx_param;
  1133. struct mwifiex_adapter *adapter = priv->adapter;
  1134. int ret = -1;
  1135. struct sk_buff *skb, *skb_next;
  1136. struct mwifiex_txinfo *tx_info;
  1137. if (skb_queue_empty(&ptr->skb_head)) {
  1138. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1139. ra_list_flags);
  1140. return;
  1141. }
  1142. skb = skb_dequeue(&ptr->skb_head);
  1143. if (adapter->data_sent || adapter->tx_lock_flag) {
  1144. ptr->total_pkt_count--;
  1145. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1146. ra_list_flags);
  1147. skb_queue_tail(&adapter->tx_data_q, skb);
  1148. atomic_dec(&priv->wmm.tx_pkts_queued);
  1149. atomic_inc(&adapter->tx_queued);
  1150. return;
  1151. }
  1152. if (!skb_queue_empty(&ptr->skb_head))
  1153. skb_next = skb_peek(&ptr->skb_head);
  1154. else
  1155. skb_next = NULL;
  1156. tx_info = MWIFIEX_SKB_TXCB(skb);
  1157. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1158. if (adapter->iface_type == MWIFIEX_USB) {
  1159. ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
  1160. skb, NULL);
  1161. } else {
  1162. tx_param.next_pkt_len =
  1163. ((skb_next) ? skb_next->len +
  1164. sizeof(struct txpd) : 0);
  1165. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  1166. skb, &tx_param);
  1167. }
  1168. switch (ret) {
  1169. case -EBUSY:
  1170. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  1171. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1172. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1173. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1174. ra_list_flags);
  1175. mwifiex_write_data_complete(adapter, skb, 0, -1);
  1176. return;
  1177. }
  1178. skb_queue_tail(&ptr->skb_head, skb);
  1179. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1180. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1181. ra_list_flags);
  1182. break;
  1183. case -1:
  1184. mwifiex_dbg(adapter, ERROR, "host_to_card failed: %#x\n", ret);
  1185. adapter->dbg.num_tx_host_to_card_failure++;
  1186. mwifiex_write_data_complete(adapter, skb, 0, ret);
  1187. break;
  1188. case -EINPROGRESS:
  1189. break;
  1190. case 0:
  1191. mwifiex_write_data_complete(adapter, skb, 0, ret);
  1192. default:
  1193. break;
  1194. }
  1195. if (ret != -EBUSY) {
  1196. mwifiex_rotate_priolists(priv, ptr, ptr_index);
  1197. atomic_dec(&priv->wmm.tx_pkts_queued);
  1198. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1199. ptr->total_pkt_count--;
  1200. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1201. ra_list_flags);
  1202. }
  1203. }
  1204. /*
  1205. * This function dequeues a packet from the highest priority list
  1206. * and transmits it.
  1207. */
  1208. static int
  1209. mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
  1210. {
  1211. struct mwifiex_ra_list_tbl *ptr;
  1212. struct mwifiex_private *priv = NULL;
  1213. int ptr_index = 0;
  1214. u8 ra[ETH_ALEN];
  1215. int tid_del = 0, tid = 0;
  1216. unsigned long flags;
  1217. ptr = mwifiex_wmm_get_highest_priolist_ptr(adapter, &priv, &ptr_index);
  1218. if (!ptr)
  1219. return -1;
  1220. tid = mwifiex_get_tid(ptr);
  1221. mwifiex_dbg(adapter, DATA, "data: tid=%d\n", tid);
  1222. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  1223. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1224. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  1225. return -1;
  1226. }
  1227. if (mwifiex_is_ptr_processed(priv, ptr)) {
  1228. mwifiex_send_processed_packet(priv, ptr, ptr_index, flags);
  1229. /* ra_list_spinlock has been freed in
  1230. mwifiex_send_processed_packet() */
  1231. return 0;
  1232. }
  1233. if (!ptr->is_11n_enabled ||
  1234. ptr->ba_status ||
  1235. priv->wps.session_enable) {
  1236. if (ptr->is_11n_enabled &&
  1237. ptr->ba_status &&
  1238. ptr->amsdu_in_ampdu &&
  1239. mwifiex_is_amsdu_allowed(priv, tid) &&
  1240. mwifiex_is_11n_aggragation_possible(priv, ptr,
  1241. adapter->tx_buf_size))
  1242. mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index, flags);
  1243. /* ra_list_spinlock has been freed in
  1244. * mwifiex_11n_aggregate_pkt()
  1245. */
  1246. else
  1247. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1248. /* ra_list_spinlock has been freed in
  1249. * mwifiex_send_single_packet()
  1250. */
  1251. } else {
  1252. if (mwifiex_is_ampdu_allowed(priv, ptr, tid) &&
  1253. ptr->ba_pkt_count > ptr->ba_packet_thr) {
  1254. if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
  1255. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1256. BA_SETUP_INPROGRESS);
  1257. mwifiex_send_addba(priv, tid, ptr->ra);
  1258. } else if (mwifiex_find_stream_to_delete
  1259. (priv, tid, &tid_del, ra)) {
  1260. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1261. BA_SETUP_INPROGRESS);
  1262. mwifiex_send_delba(priv, tid_del, ra, 1);
  1263. }
  1264. }
  1265. if (mwifiex_is_amsdu_allowed(priv, tid) &&
  1266. mwifiex_is_11n_aggragation_possible(priv, ptr,
  1267. adapter->tx_buf_size))
  1268. mwifiex_11n_aggregate_pkt(priv, ptr, ptr_index, flags);
  1269. /* ra_list_spinlock has been freed in
  1270. mwifiex_11n_aggregate_pkt() */
  1271. else
  1272. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1273. /* ra_list_spinlock has been freed in
  1274. mwifiex_send_single_packet() */
  1275. }
  1276. return 0;
  1277. }
  1278. void mwifiex_process_bypass_tx(struct mwifiex_adapter *adapter)
  1279. {
  1280. struct mwifiex_tx_param tx_param;
  1281. struct sk_buff *skb;
  1282. struct mwifiex_txinfo *tx_info;
  1283. struct mwifiex_private *priv;
  1284. int i;
  1285. if (adapter->data_sent || adapter->tx_lock_flag)
  1286. return;
  1287. for (i = 0; i < adapter->priv_num; ++i) {
  1288. priv = adapter->priv[i];
  1289. if (!priv)
  1290. continue;
  1291. if (adapter->if_ops.is_port_ready &&
  1292. !adapter->if_ops.is_port_ready(priv))
  1293. continue;
  1294. if (skb_queue_empty(&priv->bypass_txq))
  1295. continue;
  1296. skb = skb_dequeue(&priv->bypass_txq);
  1297. tx_info = MWIFIEX_SKB_TXCB(skb);
  1298. /* no aggregation for bypass packets */
  1299. tx_param.next_pkt_len = 0;
  1300. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  1301. skb_queue_head(&priv->bypass_txq, skb);
  1302. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1303. } else {
  1304. atomic_dec(&adapter->bypass_tx_pending);
  1305. }
  1306. }
  1307. }
  1308. /*
  1309. * This function transmits the highest priority packet awaiting in the
  1310. * WMM Queues.
  1311. */
  1312. void
  1313. mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
  1314. {
  1315. do {
  1316. if (mwifiex_dequeue_tx_packet(adapter))
  1317. break;
  1318. if (adapter->iface_type != MWIFIEX_SDIO) {
  1319. if (adapter->data_sent ||
  1320. adapter->tx_lock_flag)
  1321. break;
  1322. } else {
  1323. if (atomic_read(&adapter->tx_queued) >=
  1324. MWIFIEX_MAX_PKTS_TXQ)
  1325. break;
  1326. }
  1327. } while (!mwifiex_wmm_lists_empty(adapter));
  1328. }