wmm.c 34 KB

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