wmm.c 37 KB

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