wmm.c 34 KB

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