wmm.c 36 KB

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