wmm.c 36 KB

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