wmm.c 36 KB

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