rtw_xmit.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. ******************************************************************************/
  15. #define _RTW_XMIT_C_
  16. #include <osdep_service.h>
  17. #include <drv_types.h>
  18. #include <wifi.h>
  19. #include <osdep_intf.h>
  20. #include <linux/ip.h>
  21. #include <usb_ops.h>
  22. #include <rtl8723a_xmit.h>
  23. static void _init_txservq(struct tx_servq *ptxservq)
  24. {
  25. INIT_LIST_HEAD(&ptxservq->tx_pending);
  26. _rtw_init_queue23a(&ptxservq->sta_pending);
  27. ptxservq->qcnt = 0;
  28. }
  29. void _rtw_init_sta_xmit_priv23a(struct sta_xmit_priv *psta_xmitpriv)
  30. {
  31. spin_lock_init(&psta_xmitpriv->lock);
  32. /* for (i = 0 ; i < MAX_NUMBLKS; i++) */
  33. /* _init_txservq(&psta_xmitpriv->blk_q[i]); */
  34. _init_txservq(&psta_xmitpriv->be_q);
  35. _init_txservq(&psta_xmitpriv->bk_q);
  36. _init_txservq(&psta_xmitpriv->vi_q);
  37. _init_txservq(&psta_xmitpriv->vo_q);
  38. INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz);
  39. INIT_LIST_HEAD(&psta_xmitpriv->apsd);
  40. }
  41. int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv,
  42. struct rtw_adapter *padapter)
  43. {
  44. int i;
  45. struct xmit_buf *pxmitbuf;
  46. struct xmit_frame *pxframe;
  47. int res = _SUCCESS;
  48. u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  49. u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
  50. spin_lock_init(&pxmitpriv->lock);
  51. spin_lock_init(&pxmitpriv->lock_sctx);
  52. sema_init(&pxmitpriv->xmit_sema, 0);
  53. sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
  54. pxmitpriv->adapter = padapter;
  55. _rtw_init_queue23a(&pxmitpriv->be_pending);
  56. _rtw_init_queue23a(&pxmitpriv->bk_pending);
  57. _rtw_init_queue23a(&pxmitpriv->vi_pending);
  58. _rtw_init_queue23a(&pxmitpriv->vo_pending);
  59. _rtw_init_queue23a(&pxmitpriv->bm_pending);
  60. _rtw_init_queue23a(&pxmitpriv->free_xmit_queue);
  61. for (i = 0; i < NR_XMITFRAME; i++) {
  62. pxframe = kzalloc(sizeof(struct xmit_frame), GFP_KERNEL);
  63. if (!pxframe)
  64. break;
  65. INIT_LIST_HEAD(&pxframe->list);
  66. pxframe->padapter = padapter;
  67. pxframe->frame_tag = NULL_FRAMETAG;
  68. list_add_tail(&pxframe->list,
  69. &pxmitpriv->free_xmit_queue.queue);
  70. }
  71. pxmitpriv->free_xmitframe_cnt = i;
  72. pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
  73. /* init xmit_buf */
  74. _rtw_init_queue23a(&pxmitpriv->free_xmitbuf_queue);
  75. INIT_LIST_HEAD(&pxmitpriv->xmitbuf_list);
  76. _rtw_init_queue23a(&pxmitpriv->pending_xmitbuf_queue);
  77. for (i = 0; i < NR_XMITBUFF; i++) {
  78. pxmitbuf = kzalloc(sizeof(struct xmit_buf), GFP_KERNEL);
  79. if (!pxmitbuf)
  80. goto fail;
  81. INIT_LIST_HEAD(&pxmitbuf->list);
  82. INIT_LIST_HEAD(&pxmitbuf->list2);
  83. pxmitbuf->padapter = padapter;
  84. /* Tx buf allocation may fail sometimes, so sleep and retry. */
  85. res = rtw_os_xmit_resource_alloc23a(padapter, pxmitbuf,
  86. (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
  87. if (res == _FAIL) {
  88. goto fail;
  89. }
  90. list_add_tail(&pxmitbuf->list,
  91. &pxmitpriv->free_xmitbuf_queue.queue);
  92. list_add_tail(&pxmitbuf->list2,
  93. &pxmitpriv->xmitbuf_list);
  94. }
  95. pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
  96. /* init xframe_ext queue, the same count as extbuf */
  97. _rtw_init_queue23a(&pxmitpriv->free_xframe_ext_queue);
  98. for (i = 0; i < num_xmit_extbuf; i++) {
  99. pxframe = kzalloc(sizeof(struct xmit_frame), GFP_KERNEL);
  100. if (!pxframe)
  101. break;
  102. INIT_LIST_HEAD(&pxframe->list);
  103. pxframe->padapter = padapter;
  104. pxframe->frame_tag = NULL_FRAMETAG;
  105. pxframe->pkt = NULL;
  106. pxframe->buf_addr = NULL;
  107. pxframe->pxmitbuf = NULL;
  108. pxframe->ext_tag = 1;
  109. list_add_tail(&pxframe->list,
  110. &pxmitpriv->free_xframe_ext_queue.queue);
  111. }
  112. pxmitpriv->free_xframe_ext_cnt = i;
  113. /* Init xmit extension buff */
  114. _rtw_init_queue23a(&pxmitpriv->free_xmit_extbuf_queue);
  115. INIT_LIST_HEAD(&pxmitpriv->xmitextbuf_list);
  116. for (i = 0; i < num_xmit_extbuf; i++) {
  117. pxmitbuf = kzalloc(sizeof(struct xmit_buf), GFP_KERNEL);
  118. if (!pxmitbuf)
  119. goto fail;
  120. INIT_LIST_HEAD(&pxmitbuf->list);
  121. INIT_LIST_HEAD(&pxmitbuf->list2);
  122. pxmitbuf->padapter = padapter;
  123. /* Tx buf allocation may fail sometimes, so sleep and retry. */
  124. res = rtw_os_xmit_resource_alloc23a(padapter, pxmitbuf,
  125. max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
  126. if (res == _FAIL) {
  127. goto exit;
  128. }
  129. list_add_tail(&pxmitbuf->list,
  130. &pxmitpriv->free_xmit_extbuf_queue.queue);
  131. list_add_tail(&pxmitbuf->list2,
  132. &pxmitpriv->xmitextbuf_list);
  133. }
  134. pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
  135. rtw_alloc_hwxmits23a(padapter);
  136. rtw_init_hwxmits23a(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
  137. for (i = 0; i < 4; i ++)
  138. pxmitpriv->wmm_para_seq[i] = i;
  139. sema_init(&pxmitpriv->tx_retevt, 0);
  140. pxmitpriv->ack_tx = false;
  141. mutex_init(&pxmitpriv->ack_tx_mutex);
  142. rtw_sctx_init23a(&pxmitpriv->ack_tx_ops, 0);
  143. tasklet_init(&padapter->xmitpriv.xmit_tasklet,
  144. (void(*)(unsigned long))rtl8723au_xmit_tasklet,
  145. (unsigned long)padapter);
  146. exit:
  147. return res;
  148. fail:
  149. goto exit;
  150. }
  151. void _rtw_free_xmit_priv23a (struct xmit_priv *pxmitpriv)
  152. {
  153. struct rtw_adapter *padapter = pxmitpriv->adapter;
  154. struct xmit_frame *pxframe;
  155. struct xmit_buf *pxmitbuf;
  156. struct list_head *plist, *ptmp;
  157. list_for_each_safe(plist, ptmp, &pxmitpriv->free_xmit_queue.queue) {
  158. pxframe = container_of(plist, struct xmit_frame, list);
  159. list_del_init(&pxframe->list);
  160. rtw_os_xmit_complete23a(padapter, pxframe);
  161. kfree(pxframe);
  162. }
  163. list_for_each_safe(plist, ptmp, &pxmitpriv->xmitbuf_list) {
  164. pxmitbuf = container_of(plist, struct xmit_buf, list2);
  165. list_del_init(&pxmitbuf->list2);
  166. rtw_os_xmit_resource_free23a(padapter, pxmitbuf);
  167. kfree(pxmitbuf);
  168. }
  169. /* free xframe_ext queue, the same count as extbuf */
  170. list_for_each_safe(plist, ptmp,
  171. &pxmitpriv->free_xframe_ext_queue.queue) {
  172. pxframe = container_of(plist, struct xmit_frame, list);
  173. list_del_init(&pxframe->list);
  174. rtw_os_xmit_complete23a(padapter, pxframe);
  175. kfree(pxframe);
  176. }
  177. /* free xmit extension buff */
  178. list_for_each_safe(plist, ptmp, &pxmitpriv->xmitextbuf_list) {
  179. pxmitbuf = container_of(plist, struct xmit_buf, list2);
  180. list_del_init(&pxmitbuf->list2);
  181. rtw_os_xmit_resource_free23a(padapter, pxmitbuf);
  182. kfree(pxmitbuf);
  183. }
  184. rtw_free_hwxmits23a(padapter);
  185. mutex_destroy(&pxmitpriv->ack_tx_mutex);
  186. }
  187. static void update_attrib_vcs_info(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe)
  188. {
  189. u32 sz;
  190. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  191. struct sta_info *psta = pattrib->psta;
  192. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  193. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  194. if (pattrib->psta) {
  195. psta = pattrib->psta;
  196. } else {
  197. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  198. psta = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
  199. }
  200. if (psta == NULL) {
  201. DBG_8723A("%s, psta == NUL\n", __func__);
  202. return;
  203. }
  204. if (!(psta->state &_FW_LINKED)) {
  205. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  206. return;
  207. }
  208. if (pattrib->nr_frags != 1)
  209. sz = padapter->xmitpriv.frag_len;
  210. else /* no frag */
  211. sz = pattrib->last_txcmdsz;
  212. /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
  213. /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
  214. /* Other fragments are protected by previous fragment. */
  215. /* So we only need to check the length of first fragment. */
  216. if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
  217. if (sz > padapter->registrypriv.rts_thresh) {
  218. pattrib->vcs_mode = RTS_CTS;
  219. } else {
  220. if (psta->rtsen)
  221. pattrib->vcs_mode = RTS_CTS;
  222. else if (psta->cts2self)
  223. pattrib->vcs_mode = CTS_TO_SELF;
  224. else
  225. pattrib->vcs_mode = NONE_VCS;
  226. }
  227. } else {
  228. while (true) {
  229. /* IOT action */
  230. if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS &&
  231. pattrib->ampdu_en &&
  232. padapter->securitypriv.dot11PrivacyAlgrthm ==
  233. WLAN_CIPHER_SUITE_CCMP) {
  234. pattrib->vcs_mode = CTS_TO_SELF;
  235. break;
  236. }
  237. /* check ERP protection */
  238. if (psta->rtsen || psta->cts2self) {
  239. if (psta->rtsen)
  240. pattrib->vcs_mode = RTS_CTS;
  241. else if (psta->cts2self)
  242. pattrib->vcs_mode = CTS_TO_SELF;
  243. break;
  244. }
  245. /* check HT op mode */
  246. if (pattrib->ht_en) {
  247. u8 HTOpMode = pmlmeinfo->HT_protection;
  248. if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) ||
  249. (!pmlmeext->cur_bwmode && HTOpMode == 3)) {
  250. pattrib->vcs_mode = RTS_CTS;
  251. break;
  252. }
  253. }
  254. /* check rts */
  255. if (sz > padapter->registrypriv.rts_thresh) {
  256. pattrib->vcs_mode = RTS_CTS;
  257. break;
  258. }
  259. /* to do list: check MIMO power save condition. */
  260. /* check AMPDU aggregation for TXOP */
  261. if (pattrib->ampdu_en) {
  262. pattrib->vcs_mode = RTS_CTS;
  263. break;
  264. }
  265. pattrib->vcs_mode = NONE_VCS;
  266. break;
  267. }
  268. }
  269. }
  270. static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
  271. {
  272. /*if (psta->rtsen)
  273. pattrib->vcs_mode = RTS_CTS;
  274. else if (psta->cts2self)
  275. pattrib->vcs_mode = CTS_TO_SELF;
  276. else
  277. pattrib->vcs_mode = NONE_VCS;*/
  278. pattrib->mdata = 0;
  279. pattrib->eosp = 0;
  280. pattrib->triggered = 0;
  281. /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
  282. pattrib->qos_en = psta->qos_option;
  283. pattrib->raid = psta->raid;
  284. pattrib->ht_en = psta->htpriv.ht_option;
  285. pattrib->bwmode = psta->htpriv.bwmode;
  286. pattrib->ch_offset = psta->htpriv.ch_offset;
  287. pattrib->sgi = psta->htpriv.sgi;
  288. pattrib->ampdu_en = false;
  289. pattrib->retry_ctrl = false;
  290. }
  291. u8 qos_acm23a(u8 acm_mask, u8 priority)
  292. {
  293. u8 change_priority = priority;
  294. switch (priority) {
  295. case 0:
  296. case 3:
  297. if (acm_mask & BIT(1))
  298. change_priority = 1;
  299. break;
  300. case 1:
  301. case 2:
  302. break;
  303. case 4:
  304. case 5:
  305. if (acm_mask & BIT(2))
  306. change_priority = 0;
  307. break;
  308. case 6:
  309. case 7:
  310. if (acm_mask & BIT(3))
  311. change_priority = 5;
  312. break;
  313. default:
  314. DBG_8723A("qos_acm23a(): invalid pattrib->priority: %d!!!\n",
  315. priority);
  316. change_priority = 0;
  317. break;
  318. }
  319. return change_priority;
  320. }
  321. static void set_qos(struct sk_buff *skb, struct pkt_attrib *pattrib)
  322. {
  323. u8 *pframe = skb->data;
  324. struct iphdr *ip_hdr;
  325. u8 UserPriority = 0;
  326. /* get UserPriority from IP hdr */
  327. if (pattrib->ether_type == ETH_P_IP) {
  328. ip_hdr = (struct iphdr *)(pframe + ETH_HLEN);
  329. UserPriority = ip_hdr->tos >> 5;
  330. } else if (pattrib->ether_type == ETH_P_PAE) {
  331. /* "When priority processing of data frames is supported, */
  332. /* a STA's SME should send EAPOL-Key frames at the highest
  333. priority." */
  334. UserPriority = 7;
  335. }
  336. pattrib->priority = UserPriority;
  337. pattrib->hdrlen = sizeof(struct ieee80211_qos_hdr);
  338. pattrib->type = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
  339. }
  340. static int update_attrib(struct rtw_adapter *padapter,
  341. struct sk_buff *skb, struct pkt_attrib *pattrib)
  342. {
  343. struct sta_info *psta = NULL;
  344. int bmcast;
  345. struct sta_priv *pstapriv = &padapter->stapriv;
  346. struct security_priv *psecuritypriv = &padapter->securitypriv;
  347. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  348. int res = _SUCCESS;
  349. struct ethhdr *ehdr = (struct ethhdr *) skb->data;
  350. pattrib->ether_type = ntohs(ehdr->h_proto);
  351. ether_addr_copy(pattrib->dst, ehdr->h_dest);
  352. ether_addr_copy(pattrib->src, ehdr->h_source);
  353. pattrib->pctrl = 0;
  354. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
  355. check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
  356. ether_addr_copy(pattrib->ra, pattrib->dst);
  357. ether_addr_copy(pattrib->ta, pattrib->src);
  358. } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  359. ether_addr_copy(pattrib->ra, get_bssid(pmlmepriv));
  360. ether_addr_copy(pattrib->ta, pattrib->src);
  361. } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  362. ether_addr_copy(pattrib->ra, pattrib->dst);
  363. ether_addr_copy(pattrib->ta, get_bssid(pmlmepriv));
  364. }
  365. pattrib->pktlen = skb->len - ETH_HLEN;
  366. if (pattrib->ether_type == ETH_P_IP) {
  367. /* The following is for DHCP and ARP packet, we use cck1M
  368. to tx these packets and let LPS awake some time */
  369. /* to prevent DHCP protocol fail */
  370. pattrib->dhcp_pkt = 0;
  371. /* MINIMUM_DHCP_PACKET_SIZE) { */
  372. if (pattrib->pktlen > 282 + 24) {
  373. if (pattrib->ether_type == ETH_P_IP) {/* IP header */
  374. u8 *pframe = skb->data;
  375. pframe += ETH_HLEN;
  376. if ((pframe[21] == 68 && pframe[23] == 67) ||
  377. (pframe[21] == 67 && pframe[23] == 68)) {
  378. /* 68 : UDP BOOTP client */
  379. /* 67 : UDP BOOTP server */
  380. RT_TRACE(_module_rtl871x_xmit_c_,
  381. _drv_err_,
  382. "======================update_attrib: get DHCP Packet\n");
  383. pattrib->dhcp_pkt = 1;
  384. }
  385. }
  386. }
  387. } else if (pattrib->ether_type == ETH_P_PAE) {
  388. DBG_8723A_LEVEL(_drv_always_, "send eapol packet\n");
  389. }
  390. if ((pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) {
  391. rtw_set_scan_deny(padapter, 3000);
  392. }
  393. /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
  394. if ((pattrib->ether_type == ETH_P_ARP) ||
  395. (pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) {
  396. rtw_lps_ctrl_wk_cmd23a(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
  397. }
  398. bmcast = is_multicast_ether_addr(pattrib->ra);
  399. /* get sta_info */
  400. if (bmcast) {
  401. psta = rtw_get_bcmc_stainfo23a(padapter);
  402. } else {
  403. psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
  404. if (psta == NULL) { /* if we cannot get psta => drrp the pkt */
  405. RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
  406. "update_attrib => get sta_info fail, ra:%pM\n",
  407. pattrib->ra);
  408. res = _FAIL;
  409. goto exit;
  410. } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) &&
  411. (!(psta->state & _FW_LINKED))) {
  412. res = _FAIL;
  413. goto exit;
  414. }
  415. }
  416. if (psta) {
  417. pattrib->mac_id = psta->mac_id;
  418. /* DBG_8723A("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
  419. pattrib->psta = psta;
  420. } else {
  421. /* if we cannot get psta => drop the pkt */
  422. RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
  423. "update_attrib => get sta_info fail, ra:%pM\n",
  424. pattrib->ra);
  425. res = _FAIL;
  426. goto exit;
  427. }
  428. pattrib->ack_policy = 0;
  429. /* get ether_hdr_len */
  430. /* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
  431. pattrib->pkt_hdrlen = ETH_HLEN;
  432. pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr);
  433. pattrib->type = IEEE80211_FTYPE_DATA;
  434. pattrib->priority = 0;
  435. if (check_fwstate(pmlmepriv, WIFI_AP_STATE | WIFI_ADHOC_STATE |
  436. WIFI_ADHOC_MASTER_STATE)) {
  437. if (psta->qos_option)
  438. set_qos(skb, pattrib);
  439. } else {
  440. if (pmlmepriv->qos_option) {
  441. set_qos(skb, pattrib);
  442. if (pmlmepriv->acm_mask != 0) {
  443. pattrib->priority = qos_acm23a(pmlmepriv->acm_mask,
  444. pattrib->priority);
  445. }
  446. }
  447. }
  448. if (psta->ieee8021x_blocked == true) {
  449. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  450. "psta->ieee8021x_blocked == true\n");
  451. pattrib->encrypt = 0;
  452. if ((pattrib->ether_type != ETH_P_PAE) &&
  453. !check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
  454. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  455. "psta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n",
  456. pattrib->ether_type);
  457. res = _FAIL;
  458. goto exit;
  459. }
  460. } else {
  461. GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
  462. switch (psecuritypriv->dot11AuthAlgrthm) {
  463. case dot11AuthAlgrthm_Open:
  464. case dot11AuthAlgrthm_Shared:
  465. case dot11AuthAlgrthm_Auto:
  466. pattrib->key_idx =
  467. (u8)psecuritypriv->dot11PrivacyKeyIndex;
  468. break;
  469. case dot11AuthAlgrthm_8021X:
  470. if (bmcast)
  471. pattrib->key_idx =
  472. (u8)psecuritypriv->dot118021XGrpKeyid;
  473. else
  474. pattrib->key_idx = 0;
  475. break;
  476. default:
  477. pattrib->key_idx = 0;
  478. break;
  479. }
  480. }
  481. switch (pattrib->encrypt) {
  482. case WLAN_CIPHER_SUITE_WEP40:
  483. case WLAN_CIPHER_SUITE_WEP104:
  484. pattrib->iv_len = IEEE80211_WEP_IV_LEN;
  485. pattrib->icv_len = IEEE80211_WEP_ICV_LEN;
  486. break;
  487. case WLAN_CIPHER_SUITE_TKIP:
  488. pattrib->iv_len = IEEE80211_TKIP_IV_LEN;
  489. pattrib->icv_len = IEEE80211_TKIP_ICV_LEN;
  490. if (!padapter->securitypriv.busetkipkey) {
  491. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  492. "padapter->securitypriv.busetkipkey(%d) == false drop packet\n",
  493. padapter->securitypriv.busetkipkey);
  494. res = _FAIL;
  495. goto exit;
  496. }
  497. break;
  498. case WLAN_CIPHER_SUITE_CCMP:
  499. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  500. "pattrib->encrypt =%d (WLAN_CIPHER_SUITE_CCMP)\n",
  501. pattrib->encrypt);
  502. pattrib->iv_len = IEEE80211_CCMP_HDR_LEN;
  503. pattrib->icv_len = IEEE80211_CCMP_MIC_LEN;
  504. break;
  505. default:
  506. pattrib->iv_len = 0;
  507. pattrib->icv_len = 0;
  508. break;
  509. }
  510. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  511. "update_attrib: encrypt =%d\n", pattrib->encrypt);
  512. if (pattrib->encrypt && !psecuritypriv->hw_decrypted) {
  513. pattrib->bswenc = true;
  514. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  515. "update_attrib: encrypt =%d bswenc = true\n",
  516. pattrib->encrypt);
  517. } else {
  518. pattrib->bswenc = false;
  519. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  520. "update_attrib: bswenc = false\n");
  521. }
  522. update_attrib_phy_info(pattrib, psta);
  523. exit:
  524. return res;
  525. }
  526. static int xmitframe_addmic(struct rtw_adapter *padapter,
  527. struct xmit_frame *pxmitframe) {
  528. struct mic_data micdata;
  529. struct sta_info *stainfo;
  530. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  531. struct security_priv *psecuritypriv = &padapter->securitypriv;
  532. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  533. int curfragnum, length;
  534. u8 *pframe, *payload, mic[8];
  535. u8 priority[4]= {0x0, 0x0, 0x0, 0x0};
  536. u8 hw_hdr_offset = 0;
  537. int bmcst = is_multicast_ether_addr(pattrib->ra);
  538. if (pattrib->psta) {
  539. stainfo = pattrib->psta;
  540. } else {
  541. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  542. stainfo = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
  543. }
  544. if (!stainfo) {
  545. DBG_8723A("%s, psta == NUL\n", __func__);
  546. return _FAIL;
  547. }
  548. if (!(stainfo->state &_FW_LINKED)) {
  549. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n",
  550. __func__, stainfo->state);
  551. return _FAIL;
  552. }
  553. hw_hdr_offset = TXDESC_OFFSET;
  554. if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) {
  555. /* encode mic code */
  556. if (stainfo) {
  557. u8 null_key[16]={0x0, 0x0, 0x0, 0x0,
  558. 0x0, 0x0, 0x0, 0x0,
  559. 0x0, 0x0, 0x0, 0x0,
  560. 0x0, 0x0, 0x0, 0x0};
  561. pframe = pxmitframe->buf_addr + hw_hdr_offset;
  562. if (bmcst) {
  563. if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) {
  564. return _FAIL;
  565. }
  566. /* start to calculate the mic code */
  567. rtw_secmicsetkey23a(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
  568. } else {
  569. if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0],
  570. null_key, 16)) {
  571. return _FAIL;
  572. }
  573. /* start to calculate the mic code */
  574. rtw_secmicsetkey23a(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
  575. }
  576. if (pframe[1] & 1) { /* ToDS == 1 */
  577. /* DA */
  578. rtw_secmicappend23a(&micdata, &pframe[16], 6);
  579. if (pframe[1] & 2) /* From Ds == 1 */
  580. rtw_secmicappend23a(&micdata,
  581. &pframe[24], 6);
  582. else
  583. rtw_secmicappend23a(&micdata,
  584. &pframe[10], 6);
  585. } else { /* ToDS == 0 */
  586. /* DA */
  587. rtw_secmicappend23a(&micdata, &pframe[4], 6);
  588. if (pframe[1] & 2) /* From Ds == 1 */
  589. rtw_secmicappend23a(&micdata,
  590. &pframe[16], 6);
  591. else
  592. rtw_secmicappend23a(&micdata,
  593. &pframe[10], 6);
  594. }
  595. /* if (pmlmepriv->qos_option == 1) */
  596. if (pattrib->qos_en)
  597. priority[0] = (u8)pxmitframe->attrib.priority;
  598. rtw_secmicappend23a(&micdata, &priority[0], 4);
  599. payload = pframe;
  600. for (curfragnum = 0; curfragnum < pattrib->nr_frags;
  601. curfragnum++) {
  602. payload = PTR_ALIGN(payload, 4);
  603. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  604. "=== curfragnum =%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
  605. curfragnum, *payload, *(payload + 1),
  606. *(payload + 2), *(payload + 3),
  607. *(payload + 4), *(payload + 5),
  608. *(payload + 6), *(payload + 7));
  609. payload = payload + pattrib->hdrlen +
  610. pattrib->iv_len;
  611. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  612. "curfragnum =%d pattrib->hdrlen =%d pattrib->iv_len =%d\n",
  613. curfragnum,
  614. pattrib->hdrlen, pattrib->iv_len);
  615. if ((curfragnum + 1) == pattrib->nr_frags) {
  616. length = pattrib->last_txcmdsz -
  617. pattrib->hdrlen -
  618. pattrib->iv_len -
  619. ((pattrib->bswenc) ?
  620. pattrib->icv_len : 0);
  621. rtw_secmicappend23a(&micdata, payload,
  622. length);
  623. payload = payload + length;
  624. } else {
  625. length = pxmitpriv->frag_len -
  626. pattrib->hdrlen -
  627. pattrib->iv_len -
  628. ((pattrib->bswenc) ?
  629. pattrib->icv_len : 0);
  630. rtw_secmicappend23a(&micdata, payload,
  631. length);
  632. payload = payload + length +
  633. pattrib->icv_len;
  634. RT_TRACE(_module_rtl871x_xmit_c_,
  635. _drv_err_,
  636. "curfragnum =%d length =%d pattrib->icv_len =%d\n",
  637. curfragnum, length,
  638. pattrib->icv_len);
  639. }
  640. }
  641. rtw_secgetmic23a(&micdata, &mic[0]);
  642. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  643. "xmitframe_addmic: before add mic code!!\n");
  644. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  645. "xmitframe_addmic: pattrib->last_txcmdsz =%d!!!\n",
  646. pattrib->last_txcmdsz);
  647. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  648. "xmitframe_addmic: mic[0]= 0x%.2x , mic[1]=0x%.2x , mic[2]= 0x%.2x , mic[3]= 0x%.2x\nmic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
  649. mic[0], mic[1], mic[2], mic[3],
  650. mic[4], mic[5], mic[6], mic[7]);
  651. /* add mic code and add the mic code length
  652. in last_txcmdsz */
  653. memcpy(payload, &mic[0], 8);
  654. pattrib->last_txcmdsz += 8;
  655. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  656. "======== last pkt ========\n");
  657. payload = payload - pattrib->last_txcmdsz + 8;
  658. for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz;
  659. curfragnum = curfragnum + 8) {
  660. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  661. "%.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x\n",
  662. *(payload + curfragnum),
  663. *(payload + curfragnum + 1),
  664. *(payload + curfragnum + 2),
  665. *(payload + curfragnum + 3),
  666. *(payload + curfragnum + 4),
  667. *(payload + curfragnum + 5),
  668. *(payload + curfragnum + 6),
  669. *(payload + curfragnum + 7));
  670. }
  671. } else {
  672. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  673. "xmitframe_addmic: rtw_get_stainfo23a ==NULL!!!\n");
  674. }
  675. }
  676. return _SUCCESS;
  677. }
  678. static int xmitframe_swencrypt(struct rtw_adapter *padapter,
  679. struct xmit_frame *pxmitframe)
  680. {
  681. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  682. /* if ((psecuritypriv->sw_encrypt)||(pattrib->bswenc)) */
  683. if (pattrib->bswenc) {
  684. /* DBG_8723A("start xmitframe_swencrypt\n"); */
  685. RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_,
  686. "### xmitframe_swencrypt\n");
  687. switch (pattrib->encrypt) {
  688. case WLAN_CIPHER_SUITE_WEP40:
  689. case WLAN_CIPHER_SUITE_WEP104:
  690. rtw_wep_encrypt23a(padapter, pxmitframe);
  691. break;
  692. case WLAN_CIPHER_SUITE_TKIP:
  693. rtw_tkip_encrypt23a(padapter, pxmitframe);
  694. break;
  695. case WLAN_CIPHER_SUITE_CCMP:
  696. rtw_aes_encrypt23a(padapter, pxmitframe);
  697. break;
  698. default:
  699. break;
  700. }
  701. } else {
  702. RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
  703. "### xmitframe_hwencrypt\n");
  704. }
  705. return _SUCCESS;
  706. }
  707. static int rtw_make_wlanhdr(struct rtw_adapter *padapter, u8 *hdr,
  708. struct pkt_attrib *pattrib)
  709. {
  710. struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
  711. struct ieee80211_qos_hdr *qoshdr;
  712. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  713. u8 qos_option = false;
  714. int res = _SUCCESS;
  715. struct sta_info *psta;
  716. int bmcst = is_multicast_ether_addr(pattrib->ra);
  717. if (pattrib->psta) {
  718. psta = pattrib->psta;
  719. } else {
  720. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  721. if (bmcst) {
  722. psta = rtw_get_bcmc_stainfo23a(padapter);
  723. } else {
  724. psta = rtw_get_stainfo23a(&padapter->stapriv, pattrib->ra);
  725. }
  726. }
  727. if (psta == NULL) {
  728. DBG_8723A("%s, psta == NUL\n", __func__);
  729. return _FAIL;
  730. }
  731. if (!(psta->state &_FW_LINKED)) {
  732. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  733. return _FAIL;
  734. }
  735. memset(hdr, 0, WLANHDR_OFFSET);
  736. pwlanhdr->frame_control = cpu_to_le16(pattrib->type);
  737. if (pattrib->type & IEEE80211_FTYPE_DATA) {
  738. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  739. /* to_ds = 1, fr_ds = 0; */
  740. /* Data transfer to AP */
  741. pwlanhdr->frame_control |=
  742. cpu_to_le16(IEEE80211_FCTL_TODS);
  743. ether_addr_copy(pwlanhdr->addr1, get_bssid(pmlmepriv));
  744. ether_addr_copy(pwlanhdr->addr2, pattrib->src);
  745. ether_addr_copy(pwlanhdr->addr3, pattrib->dst);
  746. if (pmlmepriv->qos_option)
  747. qos_option = true;
  748. } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  749. /* to_ds = 0, fr_ds = 1; */
  750. pwlanhdr->frame_control |=
  751. cpu_to_le16(IEEE80211_FCTL_FROMDS);
  752. ether_addr_copy(pwlanhdr->addr1, pattrib->dst);
  753. ether_addr_copy(pwlanhdr->addr2, get_bssid(pmlmepriv));
  754. ether_addr_copy(pwlanhdr->addr3, pattrib->src);
  755. if (psta->qos_option)
  756. qos_option = true;
  757. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
  758. check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
  759. ether_addr_copy(pwlanhdr->addr1, pattrib->dst);
  760. ether_addr_copy(pwlanhdr->addr2, pattrib->src);
  761. ether_addr_copy(pwlanhdr->addr3, get_bssid(pmlmepriv));
  762. if (psta->qos_option)
  763. qos_option = true;
  764. }
  765. else {
  766. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  767. "fw_state:%x is not allowed to xmit frame\n",
  768. get_fwstate(pmlmepriv));
  769. res = _FAIL;
  770. goto exit;
  771. }
  772. if (pattrib->mdata)
  773. pwlanhdr->frame_control |=
  774. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  775. if (pattrib->encrypt)
  776. pwlanhdr->frame_control |=
  777. cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  778. if (qos_option) {
  779. qoshdr = (struct ieee80211_qos_hdr *)hdr;
  780. qoshdr->qos_ctrl = cpu_to_le16(
  781. pattrib->priority & IEEE80211_QOS_CTL_TID_MASK);
  782. qoshdr->qos_ctrl |= cpu_to_le16(
  783. (pattrib->ack_policy << 5) &
  784. IEEE80211_QOS_CTL_ACK_POLICY_MASK);
  785. if (pattrib->eosp)
  786. qoshdr->qos_ctrl |=
  787. cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
  788. }
  789. /* TODO: fill HT Control Field */
  790. /* Update Seq Num will be handled by f/w */
  791. if (psta) {
  792. psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
  793. psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
  794. pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
  795. /* We dont need to worry about frag bits here */
  796. pwlanhdr->seq_ctrl = cpu_to_le16(IEEE80211_SN_TO_SEQ(
  797. pattrib->seqnum));
  798. /* check if enable ampdu */
  799. if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
  800. if (pattrib->priority >= 16)
  801. printk(KERN_WARNING "%s: Invalid "
  802. "pattrib->priority %i\n",
  803. __func__, pattrib->priority);
  804. if (psta->htpriv.agg_enable_bitmap &
  805. BIT(pattrib->priority))
  806. pattrib->ampdu_en = true;
  807. }
  808. /* re-check if enable ampdu by BA_starting_seqctrl */
  809. if (pattrib->ampdu_en) {
  810. u16 tx_seq;
  811. tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
  812. /* check BA_starting_seqctrl */
  813. if (SN_LESS(pattrib->seqnum, tx_seq)) {
  814. /* DBG_8723A("tx ampdu seqnum(%d) < tx_seq(%d)\n", pattrib->seqnum, tx_seq); */
  815. pattrib->ampdu_en = false;/* AGG BK */
  816. } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
  817. psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
  818. pattrib->ampdu_en = true;/* AGG EN */
  819. } else {
  820. /* DBG_8723A("tx ampdu over run\n"); */
  821. psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
  822. pattrib->ampdu_en = true;/* AGG EN */
  823. }
  824. }
  825. }
  826. }
  827. exit:
  828. return res;
  829. }
  830. s32 rtw_txframes_pending23a(struct rtw_adapter *padapter)
  831. {
  832. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  833. return (!list_empty(&pxmitpriv->be_pending.queue)) ||
  834. (!list_empty(&pxmitpriv->bk_pending.queue)) ||
  835. (!list_empty(&pxmitpriv->vi_pending.queue)) ||
  836. (!list_empty(&pxmitpriv->vo_pending.queue));
  837. }
  838. s32 rtw_txframes_sta_ac_pending23a(struct rtw_adapter *padapter,
  839. struct pkt_attrib *pattrib)
  840. {
  841. struct sta_info *psta;
  842. struct tx_servq *ptxservq;
  843. int priority = pattrib->priority;
  844. if (pattrib->psta) {
  845. psta = pattrib->psta;
  846. } else {
  847. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  848. psta = rtw_get_stainfo23a(&padapter->stapriv, &pattrib->ra[0]);
  849. }
  850. if (psta == NULL) {
  851. DBG_8723A("%s, psta == NUL\n", __func__);
  852. return 0;
  853. }
  854. if (!(psta->state &_FW_LINKED)) {
  855. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
  856. psta->state);
  857. return 0;
  858. }
  859. switch (priority) {
  860. case 1:
  861. case 2:
  862. ptxservq = &psta->sta_xmitpriv.bk_q;
  863. break;
  864. case 4:
  865. case 5:
  866. ptxservq = &psta->sta_xmitpriv.vi_q;
  867. break;
  868. case 6:
  869. case 7:
  870. ptxservq = &psta->sta_xmitpriv.vo_q;
  871. break;
  872. case 0:
  873. case 3:
  874. default:
  875. ptxservq = &psta->sta_xmitpriv.be_q;
  876. break;
  877. }
  878. return ptxservq->qcnt;
  879. }
  880. /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
  881. * IEEE LLC/SNAP header contains 8 octets
  882. * First 3 octets comprise the LLC portion
  883. * SNAP portion, 5 octets, is divided into two fields:
  884. * Organizationally Unique Identifier(OUI), 3 octets,
  885. * type, defined by that organization, 2 octets.
  886. */
  887. static int rtw_put_snap(u8 *data, u16 h_proto)
  888. {
  889. if (h_proto == ETH_P_IPX || h_proto == ETH_P_AARP)
  890. ether_addr_copy(data, bridge_tunnel_header);
  891. else
  892. ether_addr_copy(data, rfc1042_header);
  893. data += ETH_ALEN;
  894. put_unaligned_be16(h_proto, data);
  895. return ETH_ALEN + sizeof(u16);
  896. }
  897. /*
  898. This sub-routine will perform all the following:
  899. 1. remove 802.3 header.
  900. 2. create wlan_header, based on the info in pxmitframe
  901. 3. append sta's iv/ext-iv
  902. 4. append LLC
  903. 5. move frag chunk from pframe to pxmitframe->mem
  904. 6. apply sw-encrypt, if necessary.
  905. */
  906. int rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *skb,
  907. struct xmit_frame *pxmitframe)
  908. {
  909. struct sta_info *psta;
  910. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  911. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  912. struct ieee80211_hdr *hdr;
  913. s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
  914. u8 *pframe, *mem_start;
  915. u8 hw_hdr_offset;
  916. u8 *pbuf_start;
  917. u8 *pdata = skb->data;
  918. int data_len = skb->len;
  919. s32 bmcst = is_multicast_ether_addr(pattrib->ra);
  920. int res = _SUCCESS;
  921. if (pattrib->psta)
  922. psta = pattrib->psta;
  923. else {
  924. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  925. psta = rtw_get_stainfo23a(&padapter->stapriv, pattrib->ra);
  926. }
  927. if (!psta) {
  928. DBG_8723A("%s, psta == NUL\n", __func__);
  929. return _FAIL;
  930. }
  931. if (!(psta->state &_FW_LINKED)) {
  932. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n",
  933. __func__, psta->state);
  934. return _FAIL;
  935. }
  936. if (!pxmitframe->buf_addr) {
  937. DBG_8723A("==> %s buf_addr == NULL\n", __func__);
  938. return _FAIL;
  939. }
  940. pbuf_start = pxmitframe->buf_addr;
  941. hw_hdr_offset = TXDESC_OFFSET;
  942. mem_start = pbuf_start + hw_hdr_offset;
  943. if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
  944. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  945. "%s: rtw_make_wlanhdr fail; drop pkt\n", __func__);
  946. res = _FAIL;
  947. goto exit;
  948. }
  949. pdata += pattrib->pkt_hdrlen;
  950. data_len -= pattrib->pkt_hdrlen;
  951. frg_inx = 0;
  952. frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
  953. while (1) {
  954. llc_sz = 0;
  955. mpdu_len = frg_len;
  956. pframe = mem_start;
  957. hdr = (struct ieee80211_hdr *)mem_start;
  958. pframe += pattrib->hdrlen;
  959. mpdu_len -= pattrib->hdrlen;
  960. /* adding icv, if necessary... */
  961. if (pattrib->iv_len) {
  962. if (psta) {
  963. switch (pattrib->encrypt) {
  964. case WLAN_CIPHER_SUITE_WEP40:
  965. case WLAN_CIPHER_SUITE_WEP104:
  966. WEP_IV(pattrib->iv, psta->dot11txpn,
  967. pattrib->key_idx);
  968. break;
  969. case WLAN_CIPHER_SUITE_TKIP:
  970. if (bmcst)
  971. TKIP_IV(pattrib->iv,
  972. psta->dot11txpn,
  973. pattrib->key_idx);
  974. else
  975. TKIP_IV(pattrib->iv,
  976. psta->dot11txpn, 0);
  977. break;
  978. case WLAN_CIPHER_SUITE_CCMP:
  979. if (bmcst)
  980. AES_IV(pattrib->iv,
  981. psta->dot11txpn,
  982. pattrib->key_idx);
  983. else
  984. AES_IV(pattrib->iv,
  985. psta->dot11txpn, 0);
  986. break;
  987. }
  988. }
  989. memcpy(pframe, pattrib->iv, pattrib->iv_len);
  990. RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
  991. "rtw_xmiaframe_coalesce23a: keyid =%d pattrib->iv[3]=%.2x pframe =%.2x %.2x %.2x %.2x\n",
  992. padapter->securitypriv.dot11PrivacyKeyIndex,
  993. pattrib->iv[3], *pframe, *(pframe+1),
  994. *(pframe+2), *(pframe+3));
  995. pframe += pattrib->iv_len;
  996. mpdu_len -= pattrib->iv_len;
  997. }
  998. if (frg_inx == 0) {
  999. llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
  1000. pframe += llc_sz;
  1001. mpdu_len -= llc_sz;
  1002. }
  1003. if (pattrib->icv_len > 0 && pattrib->bswenc)
  1004. mpdu_len -= pattrib->icv_len;
  1005. if (bmcst)
  1006. /* don't do fragment to broadcast/multicast packets */
  1007. mem_sz = min_t(s32, data_len, pattrib->pktlen);
  1008. else
  1009. mem_sz = min_t(s32, data_len, mpdu_len);
  1010. memcpy(pframe, pdata, mem_sz);
  1011. pframe += mem_sz;
  1012. pdata += mem_sz;
  1013. data_len -= mem_sz;
  1014. if ((pattrib->icv_len >0) && (pattrib->bswenc)) {
  1015. memcpy(pframe, pattrib->icv, pattrib->icv_len);
  1016. pframe += pattrib->icv_len;
  1017. }
  1018. frg_inx++;
  1019. if (bmcst || data_len <= 0) {
  1020. pattrib->nr_frags = frg_inx;
  1021. pattrib->last_txcmdsz = pattrib->hdrlen +
  1022. pattrib->iv_len +
  1023. ((pattrib->nr_frags == 1) ?
  1024. llc_sz : 0) +
  1025. ((pattrib->bswenc) ?
  1026. pattrib->icv_len : 0) + mem_sz;
  1027. hdr->frame_control &=
  1028. ~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
  1029. break;
  1030. } else {
  1031. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  1032. "%s: There're still something in packet!\n",
  1033. __func__);
  1034. }
  1035. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
  1036. mem_start = PTR_ALIGN(pframe, 4) + hw_hdr_offset;
  1037. memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
  1038. }
  1039. if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
  1040. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  1041. "xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
  1042. DBG_8723A("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
  1043. res = _FAIL;
  1044. goto exit;
  1045. }
  1046. xmitframe_swencrypt(padapter, pxmitframe);
  1047. if (bmcst == false)
  1048. update_attrib_vcs_info(padapter, pxmitframe);
  1049. else
  1050. pattrib->vcs_mode = NONE_VCS;
  1051. exit:
  1052. return res;
  1053. }
  1054. void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len)
  1055. {
  1056. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1057. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1058. uint protection;
  1059. const u8 *p;
  1060. switch (pregistrypriv->vrtl_carrier_sense) {
  1061. case DISABLE_VCS:
  1062. pxmitpriv->vcs = NONE_VCS;
  1063. break;
  1064. case ENABLE_VCS:
  1065. break;
  1066. case AUTO_VCS:
  1067. default:
  1068. p = cfg80211_find_ie(WLAN_EID_ERP_INFO, ie, ie_len);
  1069. if (!p)
  1070. pxmitpriv->vcs = NONE_VCS;
  1071. else {
  1072. protection = (*(p + 2)) & BIT(1);
  1073. if (protection) {
  1074. if (pregistrypriv->vcs_type == RTS_CTS)
  1075. pxmitpriv->vcs = RTS_CTS;
  1076. else
  1077. pxmitpriv->vcs = CTS_TO_SELF;
  1078. } else {
  1079. pxmitpriv->vcs = NONE_VCS;
  1080. }
  1081. }
  1082. break;
  1083. }
  1084. }
  1085. void rtw_count_tx_stats23a(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe, int sz)
  1086. {
  1087. struct sta_info *psta = NULL;
  1088. struct stainfo_stats *pstats = NULL;
  1089. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1090. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1091. if (pxmitframe->frame_tag == DATA_FRAMETAG) {
  1092. pxmitpriv->tx_bytes += sz;
  1093. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod++;
  1094. psta = pxmitframe->attrib.psta;
  1095. if (psta) {
  1096. pstats = &psta->sta_stats;
  1097. pstats->tx_pkts++;
  1098. pstats->tx_bytes += sz;
  1099. }
  1100. }
  1101. }
  1102. struct xmit_buf *rtw_alloc_xmitbuf23a_ext(struct xmit_priv *pxmitpriv)
  1103. {
  1104. unsigned long irqL;
  1105. struct xmit_buf *pxmitbuf = NULL;
  1106. struct list_head *phead;
  1107. struct rtw_queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
  1108. spin_lock_irqsave(&pfree_queue->lock, irqL);
  1109. phead = get_list_head(pfree_queue);
  1110. if (!list_empty(phead)) {
  1111. pxmitbuf = list_first_entry(phead, struct xmit_buf, list);
  1112. list_del_init(&pxmitbuf->list);
  1113. pxmitpriv->free_xmit_extbuf_cnt--;
  1114. pxmitbuf->priv_data = NULL;
  1115. pxmitbuf->ext_tag = true;
  1116. if (pxmitbuf->sctx) {
  1117. DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
  1118. rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
  1119. }
  1120. }
  1121. spin_unlock_irqrestore(&pfree_queue->lock, irqL);
  1122. return pxmitbuf;
  1123. }
  1124. int rtw_free_xmitbuf_ext23a(struct xmit_priv *pxmitpriv,
  1125. struct xmit_buf *pxmitbuf)
  1126. {
  1127. unsigned long irqL;
  1128. struct rtw_queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
  1129. if (pxmitbuf == NULL)
  1130. return _FAIL;
  1131. spin_lock_irqsave(&pfree_queue->lock, irqL);
  1132. list_del_init(&pxmitbuf->list);
  1133. list_add_tail(&pxmitbuf->list, get_list_head(pfree_queue));
  1134. pxmitpriv->free_xmit_extbuf_cnt++;
  1135. spin_unlock_irqrestore(&pfree_queue->lock, irqL);
  1136. return _SUCCESS;
  1137. }
  1138. struct xmit_buf *rtw_alloc_xmitbuf23a(struct xmit_priv *pxmitpriv)
  1139. {
  1140. unsigned long irqL;
  1141. struct xmit_buf *pxmitbuf = NULL;
  1142. struct list_head *phead;
  1143. struct rtw_queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
  1144. /* DBG_8723A("+rtw_alloc_xmitbuf23a\n"); */
  1145. spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
  1146. phead = get_list_head(pfree_xmitbuf_queue);
  1147. if (!list_empty(phead)) {
  1148. pxmitbuf = list_first_entry(phead, struct xmit_buf, list);
  1149. list_del_init(&pxmitbuf->list);
  1150. pxmitpriv->free_xmitbuf_cnt--;
  1151. pxmitbuf->priv_data = NULL;
  1152. pxmitbuf->ext_tag = false;
  1153. pxmitbuf->flags = XMIT_VO_QUEUE;
  1154. if (pxmitbuf->sctx) {
  1155. DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
  1156. rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
  1157. }
  1158. }
  1159. spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
  1160. return pxmitbuf;
  1161. }
  1162. int rtw_free_xmitbuf23a(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
  1163. {
  1164. unsigned long irqL;
  1165. struct rtw_queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
  1166. /* DBG_8723A("+rtw_free_xmitbuf23a\n"); */
  1167. if (pxmitbuf == NULL)
  1168. return _FAIL;
  1169. if (pxmitbuf->sctx) {
  1170. DBG_8723A("%s pxmitbuf->sctx is not NULL\n", __func__);
  1171. rtw23a_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
  1172. }
  1173. if (pxmitbuf->ext_tag) {
  1174. rtw_free_xmitbuf_ext23a(pxmitpriv, pxmitbuf);
  1175. } else {
  1176. spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
  1177. list_del_init(&pxmitbuf->list);
  1178. list_add_tail(&pxmitbuf->list,
  1179. get_list_head(pfree_xmitbuf_queue));
  1180. pxmitpriv->free_xmitbuf_cnt++;
  1181. spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
  1182. }
  1183. return _SUCCESS;
  1184. }
  1185. static void rtw_init_xmitframe(struct xmit_frame *pxframe)
  1186. {
  1187. if (pxframe != NULL) {
  1188. /* default value setting */
  1189. pxframe->buf_addr = NULL;
  1190. pxframe->pxmitbuf = NULL;
  1191. memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
  1192. /* pxframe->attrib.psta = NULL; */
  1193. pxframe->frame_tag = DATA_FRAMETAG;
  1194. pxframe->pkt = NULL;
  1195. pxframe->pkt_offset = 1;/* default use pkt_offset to fill tx desc */
  1196. pxframe->ack_report = 0;
  1197. }
  1198. }
  1199. /*
  1200. Calling context:
  1201. 1. OS_TXENTRY
  1202. 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
  1203. If we turn on USE_RXTHREAD, then, no need for critical section.
  1204. Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
  1205. Must be very very cautious...
  1206. */
  1207. static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
  1208. {
  1209. struct xmit_frame *pxframe = NULL;
  1210. struct list_head *plist, *phead;
  1211. struct rtw_queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
  1212. spin_lock_bh(&pfree_xmit_queue->lock);
  1213. if (list_empty(&pfree_xmit_queue->queue)) {
  1214. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1215. "rtw_alloc_xmitframe:%d\n",
  1216. pxmitpriv->free_xmitframe_cnt);
  1217. pxframe = NULL;
  1218. } else {
  1219. phead = get_list_head(pfree_xmit_queue);
  1220. plist = phead->next;
  1221. pxframe = container_of(plist, struct xmit_frame, list);
  1222. list_del_init(&pxframe->list);
  1223. pxmitpriv->free_xmitframe_cnt--;
  1224. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1225. "rtw_alloc_xmitframe():free_xmitframe_cnt =%d\n",
  1226. pxmitpriv->free_xmitframe_cnt);
  1227. }
  1228. spin_unlock_bh(&pfree_xmit_queue->lock);
  1229. rtw_init_xmitframe(pxframe);
  1230. return pxframe;
  1231. }
  1232. struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv)
  1233. {
  1234. struct xmit_frame *pxframe = NULL;
  1235. struct list_head *plist, *phead;
  1236. struct rtw_queue *queue = &pxmitpriv->free_xframe_ext_queue;
  1237. spin_lock_bh(&queue->lock);
  1238. if (list_empty(&queue->queue)) {
  1239. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1240. "rtw_alloc_xmitframe23a_ext:%d\n",
  1241. pxmitpriv->free_xframe_ext_cnt);
  1242. pxframe = NULL;
  1243. } else {
  1244. phead = get_list_head(queue);
  1245. plist = phead->next;
  1246. pxframe = container_of(plist, struct xmit_frame, list);
  1247. list_del_init(&pxframe->list);
  1248. pxmitpriv->free_xframe_ext_cnt--;
  1249. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1250. "rtw_alloc_xmitframe23a_ext():free_xmitframe_cnt =%d\n",
  1251. pxmitpriv->free_xframe_ext_cnt);
  1252. }
  1253. spin_unlock_bh(&queue->lock);
  1254. rtw_init_xmitframe(pxframe);
  1255. return pxframe;
  1256. }
  1257. s32 rtw_free_xmitframe23a(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
  1258. {
  1259. struct rtw_queue *queue = NULL;
  1260. struct rtw_adapter *padapter = pxmitpriv->adapter;
  1261. struct sk_buff *pndis_pkt = NULL;
  1262. if (pxmitframe == NULL) {
  1263. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  1264. "====== rtw_free_xmitframe23a():pxmitframe == NULL!!!!!!!!!!\n");
  1265. goto exit;
  1266. }
  1267. if (pxmitframe->pkt) {
  1268. pndis_pkt = pxmitframe->pkt;
  1269. pxmitframe->pkt = NULL;
  1270. }
  1271. if (pxmitframe->ext_tag == 0)
  1272. queue = &pxmitpriv->free_xmit_queue;
  1273. else if (pxmitframe->ext_tag == 1)
  1274. queue = &pxmitpriv->free_xframe_ext_queue;
  1275. if (!queue)
  1276. goto check_pkt_complete;
  1277. spin_lock_bh(&queue->lock);
  1278. list_del_init(&pxmitframe->list);
  1279. list_add_tail(&pxmitframe->list, get_list_head(queue));
  1280. if (pxmitframe->ext_tag == 0) {
  1281. pxmitpriv->free_xmitframe_cnt++;
  1282. RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_,
  1283. "rtw_free_xmitframe23a():free_xmitframe_cnt =%d\n",
  1284. pxmitpriv->free_xmitframe_cnt);
  1285. } else if (pxmitframe->ext_tag == 1) {
  1286. pxmitpriv->free_xframe_ext_cnt++;
  1287. RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_,
  1288. "rtw_free_xmitframe23a():free_xframe_ext_cnt =%d\n",
  1289. pxmitpriv->free_xframe_ext_cnt);
  1290. }
  1291. spin_unlock_bh(&queue->lock);
  1292. check_pkt_complete:
  1293. if (pndis_pkt)
  1294. rtw_os_pkt_complete23a(padapter, pndis_pkt);
  1295. exit:
  1296. return _SUCCESS;
  1297. }
  1298. void rtw_free_xmitframe_queue23a(struct xmit_priv *pxmitpriv,
  1299. struct rtw_queue *pframequeue)
  1300. {
  1301. struct list_head *plist, *phead, *ptmp;
  1302. struct xmit_frame *pxmitframe;
  1303. spin_lock_bh(&pframequeue->lock);
  1304. phead = get_list_head(pframequeue);
  1305. list_for_each_safe(plist, ptmp, phead) {
  1306. pxmitframe = container_of(plist, struct xmit_frame, list);
  1307. rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
  1308. }
  1309. spin_unlock_bh(&pframequeue->lock);
  1310. }
  1311. int rtw_xmitframe_enqueue23a(struct rtw_adapter *padapter,
  1312. struct xmit_frame *pxmitframe)
  1313. {
  1314. if (rtw_xmit23a_classifier(padapter, pxmitframe) == _FAIL) {
  1315. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  1316. "rtw_xmitframe_enqueue23a: drop xmit pkt for classifier fail\n");
  1317. return _FAIL;
  1318. }
  1319. return _SUCCESS;
  1320. }
  1321. static struct xmit_frame *
  1322. dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit,
  1323. struct tx_servq *ptxservq, struct rtw_queue *pframe_queue)
  1324. {
  1325. struct list_head *phead;
  1326. struct xmit_frame *pxmitframe = NULL;
  1327. phead = get_list_head(pframe_queue);
  1328. if (!list_empty(phead)) {
  1329. pxmitframe = list_first_entry(phead, struct xmit_frame, list);
  1330. list_del_init(&pxmitframe->list);
  1331. ptxservq->qcnt--;
  1332. }
  1333. return pxmitframe;
  1334. }
  1335. struct xmit_frame *
  1336. rtw_dequeue_xframe23a(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i,
  1337. int entry)
  1338. {
  1339. struct list_head *sta_plist, *sta_phead, *ptmp;
  1340. struct hw_xmit *phwxmit;
  1341. struct tx_servq *ptxservq = NULL;
  1342. struct rtw_queue *pframe_queue = NULL;
  1343. struct xmit_frame *pxmitframe = NULL;
  1344. struct rtw_adapter *padapter = pxmitpriv->adapter;
  1345. struct registry_priv *pregpriv = &padapter->registrypriv;
  1346. int i, inx[4];
  1347. inx[0] = 0;
  1348. inx[1] = 1;
  1349. inx[2] = 2;
  1350. inx[3] = 3;
  1351. if (pregpriv->wifi_spec == 1) {
  1352. int j;
  1353. for (j = 0; j < 4; j++)
  1354. inx[j] = pxmitpriv->wmm_para_seq[j];
  1355. }
  1356. spin_lock_bh(&pxmitpriv->lock);
  1357. for (i = 0; i < entry; i++) {
  1358. phwxmit = phwxmit_i + inx[i];
  1359. sta_phead = get_list_head(phwxmit->sta_queue);
  1360. list_for_each_safe(sta_plist, ptmp, sta_phead) {
  1361. ptxservq = container_of(sta_plist, struct tx_servq,
  1362. tx_pending);
  1363. pframe_queue = &ptxservq->sta_pending;
  1364. pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
  1365. if (pxmitframe) {
  1366. phwxmit->accnt--;
  1367. /* Remove sta node when there is no pending packets. */
  1368. /* must be done after get_next and
  1369. before break */
  1370. if (list_empty(&pframe_queue->queue))
  1371. list_del_init(&ptxservq->tx_pending);
  1372. goto exit;
  1373. }
  1374. }
  1375. }
  1376. exit:
  1377. spin_unlock_bh(&pxmitpriv->lock);
  1378. return pxmitframe;
  1379. }
  1380. struct tx_servq *rtw_get_sta_pending23a(struct rtw_adapter *padapter, struct sta_info *psta, int up, u8 *ac)
  1381. {
  1382. struct tx_servq *ptxservq = NULL;
  1383. switch (up) {
  1384. case 1:
  1385. case 2:
  1386. ptxservq = &psta->sta_xmitpriv.bk_q;
  1387. *(ac) = 3;
  1388. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1389. "rtw_get_sta_pending23a : BK\n");
  1390. break;
  1391. case 4:
  1392. case 5:
  1393. ptxservq = &psta->sta_xmitpriv.vi_q;
  1394. *(ac) = 1;
  1395. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1396. "rtw_get_sta_pending23a : VI\n");
  1397. break;
  1398. case 6:
  1399. case 7:
  1400. ptxservq = &psta->sta_xmitpriv.vo_q;
  1401. *(ac) = 0;
  1402. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1403. "rtw_get_sta_pending23a : VO\n");
  1404. break;
  1405. case 0:
  1406. case 3:
  1407. default:
  1408. ptxservq = &psta->sta_xmitpriv.be_q;
  1409. *(ac) = 2;
  1410. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  1411. "rtw_get_sta_pending23a : BE\n");
  1412. break;
  1413. }
  1414. return ptxservq;
  1415. }
  1416. /*
  1417. * Will enqueue pxmitframe to the proper queue,
  1418. * and indicate it to xx_pending list.....
  1419. */
  1420. int rtw_xmit23a_classifier(struct rtw_adapter *padapter,
  1421. struct xmit_frame *pxmitframe)
  1422. {
  1423. struct sta_info *psta;
  1424. struct tx_servq *ptxservq;
  1425. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1426. struct sta_priv *pstapriv = &padapter->stapriv;
  1427. struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
  1428. u8 ac_index;
  1429. int res = _SUCCESS;
  1430. if (pattrib->psta) {
  1431. psta = pattrib->psta;
  1432. } else {
  1433. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  1434. psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
  1435. }
  1436. if (psta == NULL) {
  1437. res = _FAIL;
  1438. DBG_8723A("rtw_xmit23a_classifier: psta == NULL\n");
  1439. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  1440. "rtw_xmit23a_classifier: psta == NULL\n");
  1441. goto exit;
  1442. }
  1443. if (!(psta->state & _FW_LINKED)) {
  1444. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
  1445. psta->state);
  1446. return _FAIL;
  1447. }
  1448. ptxservq = rtw_get_sta_pending23a(padapter, psta, pattrib->priority,
  1449. (u8 *)(&ac_index));
  1450. if (list_empty(&ptxservq->tx_pending)) {
  1451. list_add_tail(&ptxservq->tx_pending,
  1452. get_list_head(phwxmits[ac_index].sta_queue));
  1453. }
  1454. list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
  1455. ptxservq->qcnt++;
  1456. phwxmits[ac_index].accnt++;
  1457. exit:
  1458. return res;
  1459. }
  1460. void rtw_alloc_hwxmits23a(struct rtw_adapter *padapter)
  1461. {
  1462. struct hw_xmit *hwxmits;
  1463. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1464. int size;
  1465. pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
  1466. size = sizeof(struct hw_xmit) * (pxmitpriv->hwxmit_entry + 1);
  1467. pxmitpriv->hwxmits = kzalloc(size, GFP_KERNEL);
  1468. hwxmits = pxmitpriv->hwxmits;
  1469. if (pxmitpriv->hwxmit_entry == 5) {
  1470. /* pxmitpriv->bmc_txqueue.head = 0; */
  1471. /* hwxmits[0] .phwtxqueue = &pxmitpriv->bmc_txqueue; */
  1472. hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
  1473. /* pxmitpriv->vo_txqueue.head = 0; */
  1474. /* hwxmits[1] .phwtxqueue = &pxmitpriv->vo_txqueue; */
  1475. hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
  1476. /* pxmitpriv->vi_txqueue.head = 0; */
  1477. /* hwxmits[2] .phwtxqueue = &pxmitpriv->vi_txqueue; */
  1478. hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
  1479. /* pxmitpriv->bk_txqueue.head = 0; */
  1480. /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
  1481. hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
  1482. /* pxmitpriv->be_txqueue.head = 0; */
  1483. /* hwxmits[4] .phwtxqueue = &pxmitpriv->be_txqueue; */
  1484. hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
  1485. } else if (pxmitpriv->hwxmit_entry == 4) {
  1486. /* pxmitpriv->vo_txqueue.head = 0; */
  1487. /* hwxmits[0] .phwtxqueue = &pxmitpriv->vo_txqueue; */
  1488. hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
  1489. /* pxmitpriv->vi_txqueue.head = 0; */
  1490. /* hwxmits[1] .phwtxqueue = &pxmitpriv->vi_txqueue; */
  1491. hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
  1492. /* pxmitpriv->be_txqueue.head = 0; */
  1493. /* hwxmits[2] .phwtxqueue = &pxmitpriv->be_txqueue; */
  1494. hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
  1495. /* pxmitpriv->bk_txqueue.head = 0; */
  1496. /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
  1497. hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
  1498. } else {
  1499. }
  1500. }
  1501. void rtw_free_hwxmits23a(struct rtw_adapter *padapter)
  1502. {
  1503. struct hw_xmit *hwxmits;
  1504. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1505. hwxmits = pxmitpriv->hwxmits;
  1506. kfree(hwxmits);
  1507. }
  1508. void rtw_init_hwxmits23a(struct hw_xmit *phwxmit, int entry)
  1509. {
  1510. int i;
  1511. for (i = 0; i < entry; i++, phwxmit++)
  1512. phwxmit->accnt = 0;
  1513. }
  1514. u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe)
  1515. {
  1516. u32 addr;
  1517. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1518. switch (pattrib->qsel) {
  1519. case 0:
  1520. case 3:
  1521. addr = BE_QUEUE_INX;
  1522. break;
  1523. case 1:
  1524. case 2:
  1525. addr = BK_QUEUE_INX;
  1526. break;
  1527. case 4:
  1528. case 5:
  1529. addr = VI_QUEUE_INX;
  1530. break;
  1531. case 6:
  1532. case 7:
  1533. addr = VO_QUEUE_INX;
  1534. break;
  1535. case 0x10:
  1536. addr = BCN_QUEUE_INX;
  1537. break;
  1538. case 0x11:/* BC/MC in PS (HIQ) */
  1539. addr = HIGH_QUEUE_INX;
  1540. break;
  1541. case 0x12:
  1542. default:
  1543. addr = MGT_QUEUE_INX;
  1544. break;
  1545. }
  1546. return addr;
  1547. }
  1548. /*
  1549. * The main transmit(tx) entry
  1550. *
  1551. * Return
  1552. * 1 enqueue
  1553. * 0 success, hardware will handle this xmit frame(packet)
  1554. * <0 fail
  1555. */
  1556. int rtw_xmit23a(struct rtw_adapter *padapter, struct sk_buff *skb)
  1557. {
  1558. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1559. struct xmit_frame *pxmitframe = NULL;
  1560. int res;
  1561. pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
  1562. if (pxmitframe == NULL) {
  1563. RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
  1564. "rtw_xmit23a: no more pxmitframe\n");
  1565. return -1;
  1566. }
  1567. res = update_attrib(padapter, skb, &pxmitframe->attrib);
  1568. if (res == _FAIL) {
  1569. RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
  1570. "rtw_xmit23a: update attrib fail\n");
  1571. rtw_free_xmitframe23a(pxmitpriv, pxmitframe);
  1572. return -1;
  1573. }
  1574. pxmitframe->pkt = skb;
  1575. pxmitframe->attrib.qsel = pxmitframe->attrib.priority;
  1576. #ifdef CONFIG_8723AU_AP_MODE
  1577. spin_lock_bh(&pxmitpriv->lock);
  1578. if (xmitframe_enqueue_for_sleeping_sta23a(padapter, pxmitframe)) {
  1579. spin_unlock_bh(&pxmitpriv->lock);
  1580. return 1;
  1581. }
  1582. spin_unlock_bh(&pxmitpriv->lock);
  1583. #endif
  1584. if (rtl8723au_hal_xmit(padapter, pxmitframe) == false)
  1585. return 1;
  1586. return 0;
  1587. }
  1588. #if defined(CONFIG_8723AU_AP_MODE)
  1589. int xmitframe_enqueue_for_sleeping_sta23a(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe)
  1590. {
  1591. int ret = false;
  1592. struct sta_info *psta = NULL;
  1593. struct sta_priv *pstapriv = &padapter->stapriv;
  1594. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1595. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1596. int bmcst = is_multicast_ether_addr(pattrib->ra);
  1597. if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
  1598. return ret;
  1599. if (pattrib->psta) {
  1600. psta = pattrib->psta;
  1601. } else {
  1602. DBG_8723A("%s, call rtw_get_stainfo23a()\n", __func__);
  1603. psta = rtw_get_stainfo23a(pstapriv, pattrib->ra);
  1604. }
  1605. if (psta == NULL) {
  1606. DBG_8723A("%s, psta == NUL\n", __func__);
  1607. return false;
  1608. }
  1609. if (!(psta->state & _FW_LINKED)) {
  1610. DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__,
  1611. psta->state);
  1612. return false;
  1613. }
  1614. if (pattrib->triggered == 1) {
  1615. if (bmcst)
  1616. pattrib->qsel = 0x11;/* HIQ */
  1617. return ret;
  1618. }
  1619. if (bmcst) {
  1620. spin_lock_bh(&psta->sleep_q.lock);
  1621. if (pstapriv->sta_dz_bitmap) {
  1622. /* if anyone sta is in ps mode */
  1623. list_del_init(&pxmitframe->list);
  1624. /* spin_lock_bh(&psta->sleep_q.lock); */
  1625. list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
  1626. psta->sleepq_len++;
  1627. pstapriv->tim_bitmap |= BIT(0);/* */
  1628. pstapriv->sta_dz_bitmap |= BIT(0);
  1629. /* DBG_8723A("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
  1630. /* tx bc/mc packets after update bcn */
  1631. update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
  1632. /* spin_unlock_bh(&psta->sleep_q.lock); */
  1633. ret = true;
  1634. }
  1635. spin_unlock_bh(&psta->sleep_q.lock);
  1636. return ret;
  1637. }
  1638. spin_lock_bh(&psta->sleep_q.lock);
  1639. if (psta->state&WIFI_SLEEP_STATE) {
  1640. u8 wmmps_ac = 0;
  1641. if (pstapriv->sta_dz_bitmap & CHKBIT(psta->aid)) {
  1642. list_del_init(&pxmitframe->list);
  1643. /* spin_lock_bh(&psta->sleep_q.lock); */
  1644. list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
  1645. psta->sleepq_len++;
  1646. switch (pattrib->priority) {
  1647. case 1:
  1648. case 2:
  1649. wmmps_ac = psta->uapsd_bk & BIT(0);
  1650. break;
  1651. case 4:
  1652. case 5:
  1653. wmmps_ac = psta->uapsd_vi & BIT(0);
  1654. break;
  1655. case 6:
  1656. case 7:
  1657. wmmps_ac = psta->uapsd_vo & BIT(0);
  1658. break;
  1659. case 0:
  1660. case 3:
  1661. default:
  1662. wmmps_ac = psta->uapsd_be & BIT(0);
  1663. break;
  1664. }
  1665. if (wmmps_ac)
  1666. psta->sleepq_ac_len++;
  1667. if (((psta->has_legacy_ac) && (!wmmps_ac)) ||
  1668. ((!psta->has_legacy_ac) && (wmmps_ac))) {
  1669. pstapriv->tim_bitmap |= CHKBIT(psta->aid);
  1670. if (psta->sleepq_len == 1) {
  1671. /* update BCN for TIM IE */
  1672. update_beacon23a(padapter, WLAN_EID_TIM,
  1673. NULL, false);
  1674. }
  1675. }
  1676. /* spin_unlock_bh(&psta->sleep_q.lock); */
  1677. /* if (psta->sleepq_len > (NR_XMITFRAME>>3)) */
  1678. /* */
  1679. /* wakeup_sta_to_xmit23a(padapter, psta); */
  1680. /* */
  1681. ret = true;
  1682. }
  1683. }
  1684. spin_unlock_bh(&psta->sleep_q.lock);
  1685. return ret;
  1686. }
  1687. static void
  1688. dequeue_xmitframes_to_sleeping_queue(struct rtw_adapter *padapter,
  1689. struct sta_info *psta,
  1690. struct rtw_queue *pframequeue)
  1691. {
  1692. int ret;
  1693. struct list_head *plist, *phead, *ptmp;
  1694. u8 ac_index;
  1695. struct tx_servq *ptxservq;
  1696. struct pkt_attrib *pattrib;
  1697. struct xmit_frame *pxmitframe;
  1698. struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
  1699. phead = get_list_head(pframequeue);
  1700. list_for_each_safe(plist, ptmp, phead) {
  1701. pxmitframe = container_of(plist, struct xmit_frame, list);
  1702. ret = xmitframe_enqueue_for_sleeping_sta23a(padapter, pxmitframe);
  1703. if (ret == true) {
  1704. pattrib = &pxmitframe->attrib;
  1705. ptxservq = rtw_get_sta_pending23a(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
  1706. ptxservq->qcnt--;
  1707. phwxmits[ac_index].accnt--;
  1708. } else {
  1709. /* DBG_8723A("xmitframe_enqueue_for_sleeping_sta23a return false\n"); */
  1710. }
  1711. }
  1712. }
  1713. void stop_sta_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta)
  1714. {
  1715. struct sta_info *psta_bmc;
  1716. struct sta_xmit_priv *pstaxmitpriv;
  1717. struct sta_priv *pstapriv = &padapter->stapriv;
  1718. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1719. pstaxmitpriv = &psta->sta_xmitpriv;
  1720. /* for BC/MC Frames */
  1721. psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
  1722. spin_lock_bh(&pxmitpriv->lock);
  1723. psta->state |= WIFI_SLEEP_STATE;
  1724. pstapriv->sta_dz_bitmap |= CHKBIT(psta->aid);
  1725. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
  1726. list_del_init(&pstaxmitpriv->vo_q.tx_pending);
  1727. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
  1728. list_del_init(&pstaxmitpriv->vi_q.tx_pending);
  1729. dequeue_xmitframes_to_sleeping_queue(padapter, psta,
  1730. &pstaxmitpriv->be_q.sta_pending);
  1731. list_del_init(&pstaxmitpriv->be_q.tx_pending);
  1732. dequeue_xmitframes_to_sleeping_queue(padapter, psta,
  1733. &pstaxmitpriv->bk_q.sta_pending);
  1734. list_del_init(&pstaxmitpriv->bk_q.tx_pending);
  1735. /* for BC/MC Frames */
  1736. pstaxmitpriv = &psta_bmc->sta_xmitpriv;
  1737. dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc,
  1738. &pstaxmitpriv->be_q.sta_pending);
  1739. list_del_init(&pstaxmitpriv->be_q.tx_pending);
  1740. spin_unlock_bh(&pxmitpriv->lock);
  1741. }
  1742. void wakeup_sta_to_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta)
  1743. {
  1744. u8 update_mask = 0, wmmps_ac = 0;
  1745. struct sta_info *psta_bmc;
  1746. struct list_head *plist, *phead, *ptmp;
  1747. struct xmit_frame *pxmitframe = NULL;
  1748. struct sta_priv *pstapriv = &padapter->stapriv;
  1749. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1750. spin_lock_bh(&pxmitpriv->lock);
  1751. phead = get_list_head(&psta->sleep_q);
  1752. list_for_each_safe(plist, ptmp, phead) {
  1753. pxmitframe = container_of(plist, struct xmit_frame, list);
  1754. list_del_init(&pxmitframe->list);
  1755. switch (pxmitframe->attrib.priority) {
  1756. case 1:
  1757. case 2:
  1758. wmmps_ac = psta->uapsd_bk & BIT(1);
  1759. break;
  1760. case 4:
  1761. case 5:
  1762. wmmps_ac = psta->uapsd_vi & BIT(1);
  1763. break;
  1764. case 6:
  1765. case 7:
  1766. wmmps_ac = psta->uapsd_vo & BIT(1);
  1767. break;
  1768. case 0:
  1769. case 3:
  1770. default:
  1771. wmmps_ac = psta->uapsd_be & BIT(1);
  1772. break;
  1773. }
  1774. psta->sleepq_len--;
  1775. if (psta->sleepq_len > 0)
  1776. pxmitframe->attrib.mdata = 1;
  1777. else
  1778. pxmitframe->attrib.mdata = 0;
  1779. if (wmmps_ac) {
  1780. psta->sleepq_ac_len--;
  1781. if (psta->sleepq_ac_len > 0) {
  1782. pxmitframe->attrib.mdata = 1;
  1783. pxmitframe->attrib.eosp = 0;
  1784. } else {
  1785. pxmitframe->attrib.mdata = 0;
  1786. pxmitframe->attrib.eosp = 1;
  1787. }
  1788. }
  1789. pxmitframe->attrib.triggered = 1;
  1790. rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
  1791. }
  1792. if (psta->sleepq_len == 0) {
  1793. pstapriv->tim_bitmap &= ~CHKBIT(psta->aid);
  1794. /* update BCN for TIM IE */
  1795. update_mask = BIT(0);
  1796. if (psta->state&WIFI_SLEEP_STATE)
  1797. psta->state ^= WIFI_SLEEP_STATE;
  1798. if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
  1799. psta->expire_to = pstapriv->expire_to;
  1800. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  1801. }
  1802. pstapriv->sta_dz_bitmap &= ~CHKBIT(psta->aid);
  1803. }
  1804. /* spin_unlock_bh(&psta->sleep_q.lock); */
  1805. spin_unlock_bh(&pxmitpriv->lock);
  1806. /* for BC/MC Frames */
  1807. psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
  1808. if (!psta_bmc)
  1809. return;
  1810. if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) {
  1811. /* no any sta in ps mode */
  1812. spin_lock_bh(&pxmitpriv->lock);
  1813. phead = get_list_head(&psta_bmc->sleep_q);
  1814. list_for_each_safe(plist, ptmp, phead) {
  1815. pxmitframe = container_of(plist, struct xmit_frame,
  1816. list);
  1817. list_del_init(&pxmitframe->list);
  1818. psta_bmc->sleepq_len--;
  1819. if (psta_bmc->sleepq_len > 0)
  1820. pxmitframe->attrib.mdata = 1;
  1821. else
  1822. pxmitframe->attrib.mdata = 0;
  1823. pxmitframe->attrib.triggered = 1;
  1824. rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
  1825. }
  1826. if (psta_bmc->sleepq_len == 0) {
  1827. pstapriv->tim_bitmap &= ~BIT(0);
  1828. pstapriv->sta_dz_bitmap &= ~BIT(0);
  1829. /* update BCN for TIM IE */
  1830. /* update_BCNTIM(padapter); */
  1831. update_mask |= BIT(1);
  1832. }
  1833. /* spin_unlock_bh(&psta_bmc->sleep_q.lock); */
  1834. spin_unlock_bh(&pxmitpriv->lock);
  1835. }
  1836. if (update_mask)
  1837. update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
  1838. }
  1839. void xmit_delivery_enabled_frames23a(struct rtw_adapter *padapter,
  1840. struct sta_info *psta)
  1841. {
  1842. u8 wmmps_ac = 0;
  1843. struct list_head *plist, *phead, *ptmp;
  1844. struct xmit_frame *pxmitframe;
  1845. struct sta_priv *pstapriv = &padapter->stapriv;
  1846. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1847. /* spin_lock_bh(&psta->sleep_q.lock); */
  1848. spin_lock_bh(&pxmitpriv->lock);
  1849. phead = get_list_head(&psta->sleep_q);
  1850. list_for_each_safe(plist, ptmp, phead) {
  1851. pxmitframe = container_of(plist, struct xmit_frame, list);
  1852. switch (pxmitframe->attrib.priority) {
  1853. case 1:
  1854. case 2:
  1855. wmmps_ac = psta->uapsd_bk & BIT(1);
  1856. break;
  1857. case 4:
  1858. case 5:
  1859. wmmps_ac = psta->uapsd_vi & BIT(1);
  1860. break;
  1861. case 6:
  1862. case 7:
  1863. wmmps_ac = psta->uapsd_vo & BIT(1);
  1864. break;
  1865. case 0:
  1866. case 3:
  1867. default:
  1868. wmmps_ac = psta->uapsd_be & BIT(1);
  1869. break;
  1870. }
  1871. if (!wmmps_ac)
  1872. continue;
  1873. list_del_init(&pxmitframe->list);
  1874. psta->sleepq_len--;
  1875. psta->sleepq_ac_len--;
  1876. if (psta->sleepq_ac_len > 0) {
  1877. pxmitframe->attrib.mdata = 1;
  1878. pxmitframe->attrib.eosp = 0;
  1879. } else {
  1880. pxmitframe->attrib.mdata = 0;
  1881. pxmitframe->attrib.eosp = 1;
  1882. }
  1883. pxmitframe->attrib.triggered = 1;
  1884. rtl8723au_hal_xmitframe_enqueue(padapter, pxmitframe);
  1885. if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) &&
  1886. (wmmps_ac)) {
  1887. pstapriv->tim_bitmap &= ~CHKBIT(psta->aid);
  1888. /* update BCN for TIM IE */
  1889. update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
  1890. }
  1891. }
  1892. spin_unlock_bh(&pxmitpriv->lock);
  1893. }
  1894. #endif
  1895. void rtw_sctx_init23a(struct submit_ctx *sctx, int timeout_ms)
  1896. {
  1897. sctx->timeout_ms = timeout_ms;
  1898. init_completion(&sctx->done);
  1899. sctx->status = RTW_SCTX_SUBMITTED;
  1900. }
  1901. int rtw_sctx_wait23a(struct submit_ctx *sctx)
  1902. {
  1903. int ret = _FAIL;
  1904. unsigned long expire;
  1905. int status = 0;
  1906. expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) :
  1907. MAX_SCHEDULE_TIMEOUT;
  1908. if (!wait_for_completion_timeout(&sctx->done, expire)) {
  1909. /* timeout, do something?? */
  1910. status = RTW_SCTX_DONE_TIMEOUT;
  1911. DBG_8723A("%s timeout\n", __func__);
  1912. } else {
  1913. status = sctx->status;
  1914. }
  1915. if (status == RTW_SCTX_DONE_SUCCESS)
  1916. ret = _SUCCESS;
  1917. return ret;
  1918. }
  1919. static bool rtw_sctx_chk_waring_status(int status)
  1920. {
  1921. switch (status) {
  1922. case RTW_SCTX_DONE_UNKNOWN:
  1923. case RTW_SCTX_DONE_BUF_ALLOC:
  1924. case RTW_SCTX_DONE_BUF_FREE:
  1925. case RTW_SCTX_DONE_DRV_STOP:
  1926. case RTW_SCTX_DONE_DEV_REMOVE:
  1927. return true;
  1928. default:
  1929. return false;
  1930. }
  1931. }
  1932. void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status)
  1933. {
  1934. if (*sctx) {
  1935. if (rtw_sctx_chk_waring_status(status))
  1936. DBG_8723A("%s status:%d\n", __func__, status);
  1937. (*sctx)->status = status;
  1938. complete(&(*sctx)->done);
  1939. *sctx = NULL;
  1940. }
  1941. }
  1942. int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms)
  1943. {
  1944. struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
  1945. pack_tx_ops->timeout_ms = timeout_ms;
  1946. pack_tx_ops->status = RTW_SCTX_SUBMITTED;
  1947. return rtw_sctx_wait23a(pack_tx_ops);
  1948. }