wmm.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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. priv->add_ba_param.timeout = MWIFIEX_DEFAULT_BLOCK_ACK_TIMEOUT;
  371. priv->add_ba_param.tx_win_size = MWIFIEX_AMPDU_DEF_TXWINSIZE;
  372. priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE;
  373. mwifiex_reset_11n_rx_seq_num(priv);
  374. atomic_set(&priv->wmm.tx_pkts_queued, 0);
  375. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  376. }
  377. }
  378. /*
  379. * This function checks if WMM Tx queue is empty.
  380. */
  381. int
  382. mwifiex_wmm_lists_empty(struct mwifiex_adapter *adapter)
  383. {
  384. int i;
  385. struct mwifiex_private *priv;
  386. for (i = 0; i < adapter->priv_num; ++i) {
  387. priv = adapter->priv[i];
  388. if (priv && atomic_read(&priv->wmm.tx_pkts_queued))
  389. return false;
  390. }
  391. return true;
  392. }
  393. /*
  394. * This function deletes all packets in an RA list node.
  395. *
  396. * The packet sent completion callback handler are called with
  397. * status failure, after they are dequeued to ensure proper
  398. * cleanup. The RA list node itself is freed at the end.
  399. */
  400. static void
  401. mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
  402. struct mwifiex_ra_list_tbl *ra_list)
  403. {
  404. struct mwifiex_adapter *adapter = priv->adapter;
  405. struct sk_buff *skb, *tmp;
  406. skb_queue_walk_safe(&ra_list->skb_head, skb, tmp)
  407. mwifiex_write_data_complete(adapter, skb, 0, -1);
  408. }
  409. /*
  410. * This function deletes all packets in an RA list.
  411. *
  412. * Each nodes in the RA list are freed individually first, and then
  413. * the RA list itself is freed.
  414. */
  415. static void
  416. mwifiex_wmm_del_pkts_in_ralist(struct mwifiex_private *priv,
  417. struct list_head *ra_list_head)
  418. {
  419. struct mwifiex_ra_list_tbl *ra_list;
  420. list_for_each_entry(ra_list, ra_list_head, list)
  421. mwifiex_wmm_del_pkts_in_ralist_node(priv, ra_list);
  422. }
  423. /*
  424. * This function deletes all packets in all RA lists.
  425. */
  426. static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
  427. {
  428. int i;
  429. for (i = 0; i < MAX_NUM_TID; i++)
  430. mwifiex_wmm_del_pkts_in_ralist(priv, &priv->wmm.tid_tbl_ptr[i].
  431. ra_list);
  432. atomic_set(&priv->wmm.tx_pkts_queued, 0);
  433. atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
  434. }
  435. /*
  436. * This function deletes all route addresses from all RA lists.
  437. */
  438. static void mwifiex_wmm_delete_all_ralist(struct mwifiex_private *priv)
  439. {
  440. struct mwifiex_ra_list_tbl *ra_list, *tmp_node;
  441. int i;
  442. for (i = 0; i < MAX_NUM_TID; ++i) {
  443. dev_dbg(priv->adapter->dev,
  444. "info: ra_list: freeing buf for tid %d\n", i);
  445. list_for_each_entry_safe(ra_list, tmp_node,
  446. &priv->wmm.tid_tbl_ptr[i].ra_list,
  447. list) {
  448. list_del(&ra_list->list);
  449. kfree(ra_list);
  450. }
  451. INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[i].ra_list);
  452. priv->wmm.tid_tbl_ptr[i].ra_list_curr = NULL;
  453. }
  454. }
  455. /*
  456. * This function cleans up the Tx and Rx queues.
  457. *
  458. * Cleanup includes -
  459. * - All packets in RA lists
  460. * - All entries in Rx reorder table
  461. * - All entries in Tx BA stream table
  462. * - MPA buffer (if required)
  463. * - All RA lists
  464. */
  465. void
  466. mwifiex_clean_txrx(struct mwifiex_private *priv)
  467. {
  468. unsigned long flags;
  469. mwifiex_11n_cleanup_reorder_tbl(priv);
  470. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  471. mwifiex_wmm_cleanup_queues(priv);
  472. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  473. if (priv->adapter->if_ops.cleanup_mpa_buf)
  474. priv->adapter->if_ops.cleanup_mpa_buf(priv->adapter);
  475. mwifiex_wmm_delete_all_ralist(priv);
  476. memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
  477. if (priv->adapter->if_ops.clean_pcie_ring)
  478. priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
  479. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  480. }
  481. /*
  482. * This function retrieves a particular RA list node, matching with the
  483. * given TID and RA address.
  484. */
  485. static struct mwifiex_ra_list_tbl *
  486. mwifiex_wmm_get_ralist_node(struct mwifiex_private *priv, u8 tid,
  487. u8 *ra_addr)
  488. {
  489. struct mwifiex_ra_list_tbl *ra_list;
  490. list_for_each_entry(ra_list, &priv->wmm.tid_tbl_ptr[tid].ra_list,
  491. list) {
  492. if (!memcmp(ra_list->ra, ra_addr, ETH_ALEN))
  493. return ra_list;
  494. }
  495. return NULL;
  496. }
  497. /*
  498. * This function retrieves an RA list node for a given TID and
  499. * RA address pair.
  500. *
  501. * If no such node is found, a new node is added first and then
  502. * retrieved.
  503. */
  504. static struct mwifiex_ra_list_tbl *
  505. mwifiex_wmm_get_queue_raptr(struct mwifiex_private *priv, u8 tid, u8 *ra_addr)
  506. {
  507. struct mwifiex_ra_list_tbl *ra_list;
  508. ra_list = mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  509. if (ra_list)
  510. return ra_list;
  511. mwifiex_ralist_add(priv, ra_addr);
  512. return mwifiex_wmm_get_ralist_node(priv, tid, ra_addr);
  513. }
  514. /*
  515. * This function checks if a particular RA list node exists in a given TID
  516. * table index.
  517. */
  518. int
  519. mwifiex_is_ralist_valid(struct mwifiex_private *priv,
  520. struct mwifiex_ra_list_tbl *ra_list, int ptr_index)
  521. {
  522. struct mwifiex_ra_list_tbl *rlist;
  523. list_for_each_entry(rlist, &priv->wmm.tid_tbl_ptr[ptr_index].ra_list,
  524. list) {
  525. if (rlist == ra_list)
  526. return true;
  527. }
  528. return false;
  529. }
  530. /*
  531. * This function adds a packet to WMM queue.
  532. *
  533. * In disconnected state the packet is immediately dropped and the
  534. * packet send completion callback is called with status failure.
  535. *
  536. * Otherwise, the correct RA list node is located and the packet
  537. * is queued at the list tail.
  538. */
  539. void
  540. mwifiex_wmm_add_buf_txqueue(struct mwifiex_private *priv,
  541. struct sk_buff *skb)
  542. {
  543. struct mwifiex_adapter *adapter = priv->adapter;
  544. u32 tid;
  545. struct mwifiex_ra_list_tbl *ra_list;
  546. u8 ra[ETH_ALEN], tid_down;
  547. unsigned long flags;
  548. if (!priv->media_connected && !mwifiex_is_skb_mgmt_frame(skb)) {
  549. dev_dbg(adapter->dev, "data: drop packet in disconnect\n");
  550. mwifiex_write_data_complete(adapter, skb, 0, -1);
  551. return;
  552. }
  553. tid = skb->priority;
  554. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  555. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  556. /* In case of infra as we have already created the list during
  557. association we just don't have to call get_queue_raptr, we will
  558. have only 1 raptr for a tid in case of infra */
  559. if (!mwifiex_queuing_ra_based(priv) &&
  560. !mwifiex_is_skb_mgmt_frame(skb)) {
  561. if (!list_empty(&priv->wmm.tid_tbl_ptr[tid_down].ra_list))
  562. ra_list = list_first_entry(
  563. &priv->wmm.tid_tbl_ptr[tid_down].ra_list,
  564. struct mwifiex_ra_list_tbl, list);
  565. else
  566. ra_list = NULL;
  567. } else {
  568. memcpy(ra, skb->data, ETH_ALEN);
  569. if (ra[0] & 0x01 || mwifiex_is_skb_mgmt_frame(skb))
  570. memset(ra, 0xff, ETH_ALEN);
  571. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid_down, ra);
  572. }
  573. if (!ra_list) {
  574. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  575. mwifiex_write_data_complete(adapter, skb, 0, -1);
  576. return;
  577. }
  578. skb_queue_tail(&ra_list->skb_head, skb);
  579. ra_list->total_pkts_size += skb->len;
  580. ra_list->pkt_count++;
  581. atomic_inc(&priv->wmm.tx_pkts_queued);
  582. if (atomic_read(&priv->wmm.highest_queued_prio) <
  583. tos_to_tid_inv[tid_down])
  584. atomic_set(&priv->wmm.highest_queued_prio,
  585. tos_to_tid_inv[tid_down]);
  586. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  587. }
  588. /*
  589. * This function processes the get WMM status command response from firmware.
  590. *
  591. * The response may contain multiple TLVs -
  592. * - AC Queue status TLVs
  593. * - Current WMM Parameter IE TLV
  594. * - Admission Control action frame TLVs
  595. *
  596. * This function parses the TLVs and then calls further specific functions
  597. * to process any changes in the queue prioritize or state.
  598. */
  599. int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
  600. const struct host_cmd_ds_command *resp)
  601. {
  602. u8 *curr = (u8 *) &resp->params.get_wmm_status;
  603. uint16_t resp_len = le16_to_cpu(resp->size), tlv_len;
  604. int valid = true;
  605. struct mwifiex_ie_types_data *tlv_hdr;
  606. struct mwifiex_ie_types_wmm_queue_status *tlv_wmm_qstatus;
  607. struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
  608. struct mwifiex_wmm_ac_status *ac_status;
  609. dev_dbg(priv->adapter->dev, "info: WMM: WMM_GET_STATUS cmdresp received: %d\n",
  610. resp_len);
  611. while ((resp_len >= sizeof(tlv_hdr->header)) && valid) {
  612. tlv_hdr = (struct mwifiex_ie_types_data *) curr;
  613. tlv_len = le16_to_cpu(tlv_hdr->header.len);
  614. switch (le16_to_cpu(tlv_hdr->header.type)) {
  615. case TLV_TYPE_WMMQSTATUS:
  616. tlv_wmm_qstatus =
  617. (struct mwifiex_ie_types_wmm_queue_status *)
  618. tlv_hdr;
  619. dev_dbg(priv->adapter->dev,
  620. "info: CMD_RESP: WMM_GET_STATUS:"
  621. " QSTATUS TLV: %d, %d, %d\n",
  622. tlv_wmm_qstatus->queue_index,
  623. tlv_wmm_qstatus->flow_required,
  624. tlv_wmm_qstatus->disabled);
  625. ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus->
  626. queue_index];
  627. ac_status->disabled = tlv_wmm_qstatus->disabled;
  628. ac_status->flow_required =
  629. tlv_wmm_qstatus->flow_required;
  630. ac_status->flow_created = tlv_wmm_qstatus->flow_created;
  631. break;
  632. case WLAN_EID_VENDOR_SPECIFIC:
  633. /*
  634. * Point the regular IEEE IE 2 bytes into the Marvell IE
  635. * and setup the IEEE IE type and length byte fields
  636. */
  637. wmm_param_ie =
  638. (struct ieee_types_wmm_parameter *) (curr +
  639. 2);
  640. wmm_param_ie->vend_hdr.len = (u8) tlv_len;
  641. wmm_param_ie->vend_hdr.element_id =
  642. WLAN_EID_VENDOR_SPECIFIC;
  643. dev_dbg(priv->adapter->dev,
  644. "info: CMD_RESP: WMM_GET_STATUS:"
  645. " WMM Parameter Set Count: %d\n",
  646. wmm_param_ie->qos_info_bitmap &
  647. IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK);
  648. memcpy((u8 *) &priv->curr_bss_params.bss_descriptor.
  649. wmm_ie, wmm_param_ie,
  650. wmm_param_ie->vend_hdr.len + 2);
  651. break;
  652. default:
  653. valid = false;
  654. break;
  655. }
  656. curr += (tlv_len + sizeof(tlv_hdr->header));
  657. resp_len -= (tlv_len + sizeof(tlv_hdr->header));
  658. }
  659. mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
  660. mwifiex_wmm_setup_ac_downgrade(priv);
  661. return 0;
  662. }
  663. /*
  664. * Callback handler from the command module to allow insertion of a WMM TLV.
  665. *
  666. * If the BSS we are associating to supports WMM, this function adds the
  667. * required WMM Information IE to the association request command buffer in
  668. * the form of a Marvell extended IEEE IE.
  669. */
  670. u32
  671. mwifiex_wmm_process_association_req(struct mwifiex_private *priv,
  672. u8 **assoc_buf,
  673. struct ieee_types_wmm_parameter *wmm_ie,
  674. struct ieee80211_ht_cap *ht_cap)
  675. {
  676. struct mwifiex_ie_types_wmm_param_set *wmm_tlv;
  677. u32 ret_len = 0;
  678. /* Null checks */
  679. if (!assoc_buf)
  680. return 0;
  681. if (!(*assoc_buf))
  682. return 0;
  683. if (!wmm_ie)
  684. return 0;
  685. dev_dbg(priv->adapter->dev,
  686. "info: WMM: process assoc req: bss->wmm_ie=%#x\n",
  687. wmm_ie->vend_hdr.element_id);
  688. if ((priv->wmm_required ||
  689. (ht_cap && (priv->adapter->config_bands & BAND_GN ||
  690. priv->adapter->config_bands & BAND_AN))) &&
  691. wmm_ie->vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) {
  692. wmm_tlv = (struct mwifiex_ie_types_wmm_param_set *) *assoc_buf;
  693. wmm_tlv->header.type = cpu_to_le16((u16) wmm_info_ie[0]);
  694. wmm_tlv->header.len = cpu_to_le16((u16) wmm_info_ie[1]);
  695. memcpy(wmm_tlv->wmm_ie, &wmm_info_ie[2],
  696. le16_to_cpu(wmm_tlv->header.len));
  697. if (wmm_ie->qos_info_bitmap & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD)
  698. memcpy((u8 *) (wmm_tlv->wmm_ie
  699. + le16_to_cpu(wmm_tlv->header.len)
  700. - sizeof(priv->wmm_qosinfo)),
  701. &priv->wmm_qosinfo, sizeof(priv->wmm_qosinfo));
  702. ret_len = sizeof(wmm_tlv->header)
  703. + le16_to_cpu(wmm_tlv->header.len);
  704. *assoc_buf += ret_len;
  705. }
  706. return ret_len;
  707. }
  708. /*
  709. * This function computes the time delay in the driver queues for a
  710. * given packet.
  711. *
  712. * When the packet is received at the OS/Driver interface, the current
  713. * time is set in the packet structure. The difference between the present
  714. * time and that received time is computed in this function and limited
  715. * based on pre-compiled limits in the driver.
  716. */
  717. u8
  718. mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv,
  719. const struct sk_buff *skb)
  720. {
  721. u8 ret_val;
  722. struct timeval out_tstamp, in_tstamp;
  723. u32 queue_delay;
  724. do_gettimeofday(&out_tstamp);
  725. in_tstamp = ktime_to_timeval(skb->tstamp);
  726. queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) * 1000;
  727. queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) / 1000;
  728. /*
  729. * Queue delay is passed as a uint8 in units of 2ms (ms shifted
  730. * by 1). Min value (other than 0) is therefore 2ms, max is 510ms.
  731. *
  732. * Pass max value if queue_delay is beyond the uint8 range
  733. */
  734. ret_val = (u8) (min(queue_delay, priv->wmm.drv_pkt_delay_max) >> 1);
  735. dev_dbg(priv->adapter->dev, "data: WMM: Pkt Delay: %d ms,"
  736. " %d ms sent to FW\n", queue_delay, ret_val);
  737. return ret_val;
  738. }
  739. /*
  740. * This function retrieves the highest priority RA list table pointer.
  741. */
  742. static struct mwifiex_ra_list_tbl *
  743. mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
  744. struct mwifiex_private **priv, int *tid)
  745. {
  746. struct mwifiex_private *priv_tmp;
  747. struct mwifiex_ra_list_tbl *ptr, *head;
  748. struct mwifiex_bss_prio_node *bssprio_node, *bssprio_head;
  749. struct mwifiex_tid_tbl *tid_ptr;
  750. atomic_t *hqp;
  751. int is_list_empty;
  752. unsigned long flags;
  753. int i, j;
  754. for (j = adapter->priv_num - 1; j >= 0; --j) {
  755. spin_lock_irqsave(&adapter->bss_prio_tbl[j].bss_prio_lock,
  756. flags);
  757. is_list_empty = list_empty(&adapter->bss_prio_tbl[j]
  758. .bss_prio_head);
  759. spin_unlock_irqrestore(&adapter->bss_prio_tbl[j].bss_prio_lock,
  760. flags);
  761. if (is_list_empty)
  762. continue;
  763. if (adapter->bss_prio_tbl[j].bss_prio_cur ==
  764. (struct mwifiex_bss_prio_node *)
  765. &adapter->bss_prio_tbl[j].bss_prio_head) {
  766. adapter->bss_prio_tbl[j].bss_prio_cur =
  767. list_first_entry(&adapter->bss_prio_tbl[j]
  768. .bss_prio_head,
  769. struct mwifiex_bss_prio_node,
  770. list);
  771. }
  772. bssprio_node = adapter->bss_prio_tbl[j].bss_prio_cur;
  773. bssprio_head = bssprio_node;
  774. do {
  775. priv_tmp = bssprio_node->priv;
  776. hqp = &priv_tmp->wmm.highest_queued_prio;
  777. for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
  778. tid_ptr = &(priv_tmp)->wmm.
  779. tid_tbl_ptr[tos_to_tid[i]];
  780. /* For non-STA ra_list_curr may be NULL */
  781. if (!tid_ptr->ra_list_curr)
  782. continue;
  783. spin_lock_irqsave(&tid_ptr->tid_tbl_lock,
  784. flags);
  785. is_list_empty =
  786. list_empty(&adapter->bss_prio_tbl[j]
  787. .bss_prio_head);
  788. spin_unlock_irqrestore(&tid_ptr->tid_tbl_lock,
  789. flags);
  790. if (is_list_empty)
  791. continue;
  792. /*
  793. * Always choose the next ra we transmitted
  794. * last time, this way we pick the ra's in
  795. * round robin fashion.
  796. */
  797. ptr = list_first_entry(
  798. &tid_ptr->ra_list_curr->list,
  799. struct mwifiex_ra_list_tbl,
  800. list);
  801. head = ptr;
  802. if (ptr == (struct mwifiex_ra_list_tbl *)
  803. &tid_ptr->ra_list) {
  804. /* Get next ra */
  805. ptr = list_first_entry(&ptr->list,
  806. struct mwifiex_ra_list_tbl, list);
  807. head = ptr;
  808. }
  809. do {
  810. is_list_empty =
  811. skb_queue_empty(&ptr->skb_head);
  812. if (!is_list_empty)
  813. goto found;
  814. /* Get next ra */
  815. ptr = list_first_entry(&ptr->list,
  816. struct mwifiex_ra_list_tbl,
  817. list);
  818. if (ptr ==
  819. (struct mwifiex_ra_list_tbl *)
  820. &tid_ptr->ra_list)
  821. ptr = list_first_entry(
  822. &ptr->list,
  823. struct mwifiex_ra_list_tbl,
  824. list);
  825. } while (ptr != head);
  826. }
  827. /* No packet at any TID for this priv. Mark as such
  828. * to skip checking TIDs for this priv (until pkt is
  829. * added).
  830. */
  831. atomic_set(hqp, NO_PKT_PRIO_TID);
  832. /* Get next bss priority node */
  833. bssprio_node = list_first_entry(&bssprio_node->list,
  834. struct mwifiex_bss_prio_node,
  835. list);
  836. if (bssprio_node ==
  837. (struct mwifiex_bss_prio_node *)
  838. &adapter->bss_prio_tbl[j].bss_prio_head)
  839. /* Get next bss priority node */
  840. bssprio_node = list_first_entry(
  841. &bssprio_node->list,
  842. struct mwifiex_bss_prio_node,
  843. list);
  844. } while (bssprio_node != bssprio_head);
  845. }
  846. return NULL;
  847. found:
  848. spin_lock_irqsave(&priv_tmp->wmm.ra_list_spinlock, flags);
  849. if (atomic_read(hqp) > i)
  850. atomic_set(hqp, i);
  851. spin_unlock_irqrestore(&priv_tmp->wmm.ra_list_spinlock, flags);
  852. *priv = priv_tmp;
  853. *tid = tos_to_tid[i];
  854. return ptr;
  855. }
  856. /*
  857. * This function checks if 11n aggregation is possible.
  858. */
  859. static int
  860. mwifiex_is_11n_aggragation_possible(struct mwifiex_private *priv,
  861. struct mwifiex_ra_list_tbl *ptr,
  862. int max_buf_size)
  863. {
  864. int count = 0, total_size = 0;
  865. struct sk_buff *skb, *tmp;
  866. int max_amsdu_size;
  867. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP && priv->ap_11n_enabled &&
  868. ptr->is_11n_enabled)
  869. max_amsdu_size = min_t(int, ptr->max_amsdu, max_buf_size);
  870. else
  871. max_amsdu_size = max_buf_size;
  872. skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
  873. total_size += skb->len;
  874. if (total_size >= max_amsdu_size)
  875. break;
  876. if (++count >= MIN_NUM_AMSDU)
  877. return true;
  878. }
  879. return false;
  880. }
  881. /*
  882. * This function sends a single packet to firmware for transmission.
  883. */
  884. static void
  885. mwifiex_send_single_packet(struct mwifiex_private *priv,
  886. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  887. unsigned long ra_list_flags)
  888. __releases(&priv->wmm.ra_list_spinlock)
  889. {
  890. struct sk_buff *skb, *skb_next;
  891. struct mwifiex_tx_param tx_param;
  892. struct mwifiex_adapter *adapter = priv->adapter;
  893. struct mwifiex_txinfo *tx_info;
  894. if (skb_queue_empty(&ptr->skb_head)) {
  895. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  896. ra_list_flags);
  897. dev_dbg(adapter->dev, "data: nothing to send\n");
  898. return;
  899. }
  900. skb = skb_dequeue(&ptr->skb_head);
  901. tx_info = MWIFIEX_SKB_TXCB(skb);
  902. dev_dbg(adapter->dev, "data: dequeuing the packet %p %p\n", ptr, skb);
  903. ptr->total_pkts_size -= skb->len;
  904. if (!skb_queue_empty(&ptr->skb_head))
  905. skb_next = skb_peek(&ptr->skb_head);
  906. else
  907. skb_next = NULL;
  908. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  909. tx_param.next_pkt_len = ((skb_next) ? skb_next->len +
  910. sizeof(struct txpd) : 0);
  911. if (mwifiex_process_tx(priv, skb, &tx_param) == -EBUSY) {
  912. /* Queue the packet back at the head */
  913. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  914. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  915. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  916. ra_list_flags);
  917. mwifiex_write_data_complete(adapter, skb, 0, -1);
  918. return;
  919. }
  920. skb_queue_tail(&ptr->skb_head, skb);
  921. ptr->total_pkts_size += skb->len;
  922. ptr->pkt_count++;
  923. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  924. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  925. ra_list_flags);
  926. } else {
  927. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  928. if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  929. priv->wmm.packets_out[ptr_index]++;
  930. priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
  931. }
  932. adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
  933. list_first_entry(
  934. &adapter->bss_prio_tbl[priv->bss_priority]
  935. .bss_prio_cur->list,
  936. struct mwifiex_bss_prio_node,
  937. list);
  938. atomic_dec(&priv->wmm.tx_pkts_queued);
  939. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  940. ra_list_flags);
  941. }
  942. }
  943. /*
  944. * This function checks if the first packet in the given RA list
  945. * is already processed or not.
  946. */
  947. static int
  948. mwifiex_is_ptr_processed(struct mwifiex_private *priv,
  949. struct mwifiex_ra_list_tbl *ptr)
  950. {
  951. struct sk_buff *skb;
  952. struct mwifiex_txinfo *tx_info;
  953. if (skb_queue_empty(&ptr->skb_head))
  954. return false;
  955. skb = skb_peek(&ptr->skb_head);
  956. tx_info = MWIFIEX_SKB_TXCB(skb);
  957. if (tx_info->flags & MWIFIEX_BUF_FLAG_REQUEUED_PKT)
  958. return true;
  959. return false;
  960. }
  961. /*
  962. * This function sends a single processed packet to firmware for
  963. * transmission.
  964. */
  965. static void
  966. mwifiex_send_processed_packet(struct mwifiex_private *priv,
  967. struct mwifiex_ra_list_tbl *ptr, int ptr_index,
  968. unsigned long ra_list_flags)
  969. __releases(&priv->wmm.ra_list_spinlock)
  970. {
  971. struct mwifiex_tx_param tx_param;
  972. struct mwifiex_adapter *adapter = priv->adapter;
  973. int ret = -1;
  974. struct sk_buff *skb, *skb_next;
  975. struct mwifiex_txinfo *tx_info;
  976. if (skb_queue_empty(&ptr->skb_head)) {
  977. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  978. ra_list_flags);
  979. return;
  980. }
  981. skb = skb_dequeue(&ptr->skb_head);
  982. if (!skb_queue_empty(&ptr->skb_head))
  983. skb_next = skb_peek(&ptr->skb_head);
  984. else
  985. skb_next = NULL;
  986. tx_info = MWIFIEX_SKB_TXCB(skb);
  987. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
  988. if (adapter->iface_type == MWIFIEX_USB) {
  989. adapter->data_sent = true;
  990. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
  991. skb, NULL);
  992. } else {
  993. tx_param.next_pkt_len =
  994. ((skb_next) ? skb_next->len +
  995. sizeof(struct txpd) : 0);
  996. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
  997. skb, &tx_param);
  998. }
  999. switch (ret) {
  1000. case -EBUSY:
  1001. dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
  1002. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1003. if (!mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1004. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1005. ra_list_flags);
  1006. mwifiex_write_data_complete(adapter, skb, 0, -1);
  1007. return;
  1008. }
  1009. skb_queue_tail(&ptr->skb_head, skb);
  1010. tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
  1011. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1012. ra_list_flags);
  1013. break;
  1014. case -1:
  1015. if (adapter->iface_type != MWIFIEX_PCIE)
  1016. adapter->data_sent = false;
  1017. dev_err(adapter->dev, "host_to_card failed: %#x\n", ret);
  1018. adapter->dbg.num_tx_host_to_card_failure++;
  1019. mwifiex_write_data_complete(adapter, skb, 0, ret);
  1020. break;
  1021. case -EINPROGRESS:
  1022. if (adapter->iface_type != MWIFIEX_PCIE)
  1023. adapter->data_sent = false;
  1024. default:
  1025. break;
  1026. }
  1027. if (ret != -EBUSY) {
  1028. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
  1029. if (mwifiex_is_ralist_valid(priv, ptr, ptr_index)) {
  1030. priv->wmm.packets_out[ptr_index]++;
  1031. priv->wmm.tid_tbl_ptr[ptr_index].ra_list_curr = ptr;
  1032. }
  1033. adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur =
  1034. list_first_entry(
  1035. &adapter->bss_prio_tbl[priv->bss_priority]
  1036. .bss_prio_cur->list,
  1037. struct mwifiex_bss_prio_node,
  1038. list);
  1039. atomic_dec(&priv->wmm.tx_pkts_queued);
  1040. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  1041. ra_list_flags);
  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. ((priv->sec_info.wpa_enabled ||
  1077. priv->sec_info.wpa2_enabled) &&
  1078. !priv->wpa_is_gtk_set)) {
  1079. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1080. /* ra_list_spinlock has been freed in
  1081. mwifiex_send_single_packet() */
  1082. } else {
  1083. if (mwifiex_is_ampdu_allowed(priv, tid) &&
  1084. ptr->pkt_count > ptr->ba_packet_thr) {
  1085. if (mwifiex_space_avail_for_new_ba_stream(adapter)) {
  1086. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1087. BA_SETUP_INPROGRESS);
  1088. mwifiex_send_addba(priv, tid, ptr->ra);
  1089. } else if (mwifiex_find_stream_to_delete
  1090. (priv, tid, &tid_del, ra)) {
  1091. mwifiex_create_ba_tbl(priv, ptr->ra, tid,
  1092. BA_SETUP_INPROGRESS);
  1093. mwifiex_send_delba(priv, tid_del, ra, 1);
  1094. }
  1095. }
  1096. if (mwifiex_is_amsdu_allowed(priv, tid) &&
  1097. mwifiex_is_11n_aggragation_possible(priv, ptr,
  1098. adapter->tx_buf_size))
  1099. mwifiex_11n_aggregate_pkt(priv, ptr, INTF_HEADER_LEN,
  1100. ptr_index, flags);
  1101. /* ra_list_spinlock has been freed in
  1102. mwifiex_11n_aggregate_pkt() */
  1103. else
  1104. mwifiex_send_single_packet(priv, ptr, ptr_index, flags);
  1105. /* ra_list_spinlock has been freed in
  1106. mwifiex_send_single_packet() */
  1107. }
  1108. return 0;
  1109. }
  1110. /*
  1111. * This function transmits the highest priority packet awaiting in the
  1112. * WMM Queues.
  1113. */
  1114. void
  1115. mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
  1116. {
  1117. do {
  1118. /* Check if busy */
  1119. if (adapter->data_sent || adapter->tx_lock_flag)
  1120. break;
  1121. if (mwifiex_dequeue_tx_packet(adapter))
  1122. break;
  1123. } while (!mwifiex_wmm_lists_empty(adapter));
  1124. }