r8192U_dm.c 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130
  1. /*++
  2. Copyright-c Realtek Semiconductor Corp. All rights reserved.
  3. Module Name:
  4. r8192U_dm.c
  5. Abstract:
  6. HW dynamic mechanism.
  7. Major Change History:
  8. When Who What
  9. ---------- --------------- -------------------------------
  10. 2008-05-14 amy create version 0 porting from windows code.
  11. --*/
  12. #include "r8192U.h"
  13. #include "r8192U_dm.h"
  14. #include "r8192U_hw.h"
  15. #include "r819xU_phy.h"
  16. #include "r819xU_phyreg.h"
  17. #include "r8190_rtl8256.h"
  18. #include "r819xU_cmdpkt.h"
  19. /*---------------------------Define Local Constant---------------------------*/
  20. /* Indicate different AP vendor for IOT issue. */
  21. static u32 edca_setting_DL[HT_IOT_PEER_MAX] = {
  22. 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0x00a44f, 0x5ea44f
  23. };
  24. static u32 edca_setting_UL[HT_IOT_PEER_MAX] = {
  25. 0x5e4322, 0x00a44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f
  26. };
  27. #define RTK_UL_EDCA 0xa44f
  28. #define RTK_DL_EDCA 0x5e4322
  29. /*---------------------------Define Local Constant---------------------------*/
  30. /*------------------------Define global variable-----------------------------*/
  31. /* Debug variable ? */
  32. struct dig dm_digtable;
  33. /* Store current software write register content for MAC PHY. */
  34. u8 dm_shadow[16][256] = { {0} };
  35. /* For Dynamic Rx Path Selection by Signal Strength */
  36. struct dynamic_rx_path_sel DM_RxPathSelTable;
  37. /*------------------------Define global variable-----------------------------*/
  38. /*------------------------Define local variable------------------------------*/
  39. /*------------------------Define local variable------------------------------*/
  40. /*--------------------Define export function prototype-----------------------*/
  41. extern void dm_check_fsync(struct net_device *dev);
  42. /*--------------------Define export function prototype-----------------------*/
  43. /*---------------------Define local function prototype-----------------------*/
  44. /* DM --> Rate Adaptive */
  45. static void dm_check_rate_adaptive(struct net_device *dev);
  46. /* DM --> Bandwidth switch */
  47. static void dm_init_bandwidth_autoswitch(struct net_device *dev);
  48. static void dm_bandwidth_autoswitch(struct net_device *dev);
  49. /* DM --> TX power control */
  50. /*static void dm_initialize_txpower_tracking(struct net_device *dev);*/
  51. static void dm_check_txpower_tracking(struct net_device *dev);
  52. /*static void dm_txpower_reset_recovery(struct net_device *dev);*/
  53. /* DM --> Dynamic Init Gain by RSSI */
  54. static void dm_dig_init(struct net_device *dev);
  55. static void dm_ctrl_initgain_byrssi(struct net_device *dev);
  56. static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev);
  57. static void dm_ctrl_initgain_byrssi_by_driverrssi(struct net_device *dev);
  58. static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct net_device *dev);
  59. static void dm_initial_gain(struct net_device *dev);
  60. static void dm_pd_th(struct net_device *dev);
  61. static void dm_cs_ratio(struct net_device *dev);
  62. static void dm_init_ctstoself(struct net_device *dev);
  63. /* DM --> EDCA turbo mode control */
  64. static void dm_check_edca_turbo(struct net_device *dev);
  65. /*static void dm_gpio_change_rf(struct net_device *dev);*/
  66. /* DM --> Check PBC */
  67. static void dm_check_pbc_gpio(struct net_device *dev);
  68. /* DM --> Check current RX RF path state */
  69. static void dm_check_rx_path_selection(struct net_device *dev);
  70. static void dm_init_rxpath_selection(struct net_device *dev);
  71. static void dm_rxpath_sel_byrssi(struct net_device *dev);
  72. /* DM --> Fsync for broadcom ap */
  73. static void dm_init_fsync(struct net_device *dev);
  74. static void dm_deInit_fsync(struct net_device *dev);
  75. /* Added by vivi, 20080522 */
  76. static void dm_check_txrateandretrycount(struct net_device *dev);
  77. /*---------------------Define local function prototype-----------------------*/
  78. /*---------------------Define of Tx Power Control For Near/Far Range --------*/ /*Add by Jacken 2008/02/18 */
  79. static void dm_init_dynamic_txpower(struct net_device *dev);
  80. static void dm_dynamic_txpower(struct net_device *dev);
  81. /* DM --> For rate adaptive and DIG, we must send RSSI to firmware */
  82. static void dm_send_rssi_tofw(struct net_device *dev);
  83. static void dm_ctstoself(struct net_device *dev);
  84. /*---------------------------Define function prototype------------------------*/
  85. /*
  86. * ================================================================================
  87. * HW Dynamic mechanism interface.
  88. * ================================================================================
  89. *
  90. *
  91. * Description:
  92. * Prepare SW resource for HW dynamic mechanism.
  93. *
  94. * Assumption:
  95. * This function is only invoked at driver initialization once.
  96. */
  97. void init_hal_dm(struct net_device *dev)
  98. {
  99. struct r8192_priv *priv = ieee80211_priv(dev);
  100. /* Undecorated Smoothed Signal Strength, it can utilized to dynamic mechanism. */
  101. priv->undecorated_smoothed_pwdb = -1;
  102. /* Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code. */
  103. dm_init_dynamic_txpower(dev);
  104. init_rate_adaptive(dev);
  105. /*dm_initialize_txpower_tracking(dev);*/
  106. dm_dig_init(dev);
  107. dm_init_edca_turbo(dev);
  108. dm_init_bandwidth_autoswitch(dev);
  109. dm_init_fsync(dev);
  110. dm_init_rxpath_selection(dev);
  111. dm_init_ctstoself(dev);
  112. } /* InitHalDm */
  113. void deinit_hal_dm(struct net_device *dev)
  114. {
  115. dm_deInit_fsync(dev);
  116. }
  117. #ifdef USB_RX_AGGREGATION_SUPPORT
  118. void dm_CheckRxAggregation(struct net_device *dev)
  119. {
  120. struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
  121. PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
  122. static unsigned long lastTxOkCnt;
  123. static unsigned long lastRxOkCnt;
  124. unsigned long curTxOkCnt = 0;
  125. unsigned long curRxOkCnt = 0;
  126. /*
  127. if (pHalData->bForcedUsbRxAggr) {
  128. if (pHalData->ForcedUsbRxAggrInfo == 0) {
  129. if (pHalData->bCurrentRxAggrEnable) {
  130. Adapter->HalFunc.HalUsbRxAggrHandler(Adapter, FALSE);
  131. }
  132. } else {
  133. if (!pHalData->bCurrentRxAggrEnable || (pHalData->ForcedUsbRxAggrInfo != pHalData->LastUsbRxAggrInfoSetting)) {
  134. Adapter->HalFunc.HalUsbRxAggrHandler(Adapter, TRUE);
  135. }
  136. }
  137. return;
  138. }
  139. */
  140. curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
  141. curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
  142. if ((curTxOkCnt + curRxOkCnt) < 15000000)
  143. return;
  144. if (curTxOkCnt > 4*curRxOkCnt) {
  145. if (priv->bCurrentRxAggrEnable) {
  146. write_nic_dword(dev, 0x1a8, 0);
  147. priv->bCurrentRxAggrEnable = false;
  148. }
  149. } else {
  150. if (!priv->bCurrentRxAggrEnable && !pHTInfo->bCurrentRT2RTAggregation) {
  151. u32 ulValue;
  152. ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
  153. (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
  154. /*
  155. * If usb rx firmware aggregation is enabled,
  156. * when anyone of three threshold conditions above is reached,
  157. * firmware will send aggregated packet to driver.
  158. */
  159. write_nic_dword(dev, 0x1a8, ulValue);
  160. priv->bCurrentRxAggrEnable = true;
  161. }
  162. }
  163. lastTxOkCnt = priv->stats.txbytesunicast;
  164. lastRxOkCnt = priv->stats.rxbytesunicast;
  165. } /* dm_CheckEdcaTurbo */
  166. #endif
  167. void hal_dm_watchdog(struct net_device *dev)
  168. {
  169. /*struct r8192_priv *priv = ieee80211_priv(dev);*/
  170. /*static u8 previous_bssid[6] ={0};*/
  171. /*Add by amy 2008/05/15 ,porting from windows code.*/
  172. dm_check_rate_adaptive(dev);
  173. dm_dynamic_txpower(dev);
  174. dm_check_txrateandretrycount(dev);
  175. dm_check_txpower_tracking(dev);
  176. dm_ctrl_initgain_byrssi(dev);
  177. dm_check_edca_turbo(dev);
  178. dm_bandwidth_autoswitch(dev);
  179. dm_check_rx_path_selection(dev);
  180. dm_check_fsync(dev);
  181. /* Add by amy 2008-05-15 porting from windows code. */
  182. dm_check_pbc_gpio(dev);
  183. dm_send_rssi_tofw(dev);
  184. dm_ctstoself(dev);
  185. #ifdef USB_RX_AGGREGATION_SUPPORT
  186. dm_CheckRxAggregation(dev);
  187. #endif
  188. } /* HalDmWatchDog */
  189. /*
  190. * Decide Rate Adaptive Set according to distance (signal strength)
  191. * 01/11/2008 MHC Modify input arguments and RATR table level.
  192. * 01/16/2008 MHC RF_Type is assigned in ReadAdapterInfo(). We must call
  193. * the function after making sure RF_Type.
  194. */
  195. void init_rate_adaptive(struct net_device *dev)
  196. {
  197. struct r8192_priv *priv = ieee80211_priv(dev);
  198. prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
  199. pra->ratr_state = DM_RATR_STA_MAX;
  200. pra->high2low_rssi_thresh_for_ra = RateAdaptiveTH_High;
  201. pra->low2high_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M+5;
  202. pra->low2high_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M+5;
  203. pra->high_rssi_thresh_for_ra = RateAdaptiveTH_High+5;
  204. pra->low_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M;
  205. pra->low_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M;
  206. if (priv->CustomerID == RT_CID_819x_Netcore)
  207. pra->ping_rssi_enable = 1;
  208. else
  209. pra->ping_rssi_enable = 0;
  210. pra->ping_rssi_thresh_for_ra = 15;
  211. if (priv->rf_type == RF_2T4R) {
  212. /*
  213. * 07/10/08 MH Modify for RA smooth scheme.
  214. * 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.
  215. */
  216. pra->upper_rssi_threshold_ratr = 0x8f0f0000;
  217. pra->middle_rssi_threshold_ratr = 0x8f0ff000;
  218. pra->low_rssi_threshold_ratr = 0x8f0ff001;
  219. pra->low_rssi_threshold_ratr_40M = 0x8f0ff005;
  220. pra->low_rssi_threshold_ratr_20M = 0x8f0ff001;
  221. pra->ping_rssi_ratr = 0x0000000d;/* cosa add for test */
  222. } else if (priv->rf_type == RF_1T2R) {
  223. pra->upper_rssi_threshold_ratr = 0x000f0000;
  224. pra->middle_rssi_threshold_ratr = 0x000ff000;
  225. pra->low_rssi_threshold_ratr = 0x000ff001;
  226. pra->low_rssi_threshold_ratr_40M = 0x000ff005;
  227. pra->low_rssi_threshold_ratr_20M = 0x000ff001;
  228. pra->ping_rssi_ratr = 0x0000000d;/* cosa add for test */
  229. }
  230. } /* InitRateAdaptive */
  231. /*-----------------------------------------------------------------------------
  232. * Function: dm_check_rate_adaptive()
  233. *
  234. * Overview:
  235. *
  236. * Input: NONE
  237. *
  238. * Output: NONE
  239. *
  240. * Return: NONE
  241. *
  242. * Revised History:
  243. * When Who Remark
  244. * 05/26/08 amy Create version 0 porting from windows code.
  245. *
  246. *---------------------------------------------------------------------------*/
  247. static void dm_check_rate_adaptive(struct net_device *dev)
  248. {
  249. struct r8192_priv *priv = ieee80211_priv(dev);
  250. PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
  251. prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
  252. u32 currentRATR, targetRATR = 0;
  253. u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0;
  254. bool bshort_gi_enabled = false;
  255. static u8 ping_rssi_state;
  256. if (!priv->up) {
  257. RT_TRACE(COMP_RATE, "<---- dm_check_rate_adaptive(): driver is going to unload\n");
  258. return;
  259. }
  260. if (pra->rate_adaptive_disabled) /* this variable is set by ioctl. */
  261. return;
  262. /* TODO: Only 11n mode is implemented currently, */
  263. if (!(priv->ieee80211->mode == WIRELESS_MODE_N_24G ||
  264. priv->ieee80211->mode == WIRELESS_MODE_N_5G))
  265. return;
  266. if (priv->ieee80211->state == IEEE80211_LINKED) {
  267. /*RT_TRACE(COMP_RATE, "dm_CheckRateAdaptive(): \t");*/
  268. /* Check whether Short GI is enabled */
  269. bshort_gi_enabled = (pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI40MHz) ||
  270. (!pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI20MHz);
  271. pra->upper_rssi_threshold_ratr =
  272. (pra->upper_rssi_threshold_ratr & (~BIT(31))) |
  273. ((bshort_gi_enabled) ? BIT(31) : 0);
  274. pra->middle_rssi_threshold_ratr =
  275. (pra->middle_rssi_threshold_ratr & (~BIT(31))) |
  276. ((bshort_gi_enabled) ? BIT(31) : 0);
  277. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  278. pra->low_rssi_threshold_ratr =
  279. (pra->low_rssi_threshold_ratr_40M & (~BIT(31))) |
  280. ((bshort_gi_enabled) ? BIT(31) : 0);
  281. } else {
  282. pra->low_rssi_threshold_ratr =
  283. (pra->low_rssi_threshold_ratr_20M & (~BIT(31))) |
  284. ((bshort_gi_enabled) ? BIT(31) : 0);
  285. }
  286. /* cosa add for test */
  287. pra->ping_rssi_ratr =
  288. (pra->ping_rssi_ratr & (~BIT(31))) |
  289. ((bshort_gi_enabled) ? BIT(31) : 0);
  290. /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
  291. time to link with AP. We will not change upper/lower threshold. If
  292. STA stay in high or low level, we must change two different threshold
  293. to prevent jumping frequently. */
  294. if (pra->ratr_state == DM_RATR_STA_HIGH) {
  295. HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra;
  296. LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) ?
  297. (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
  298. } else if (pra->ratr_state == DM_RATR_STA_LOW) {
  299. HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
  300. LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) ?
  301. (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M);
  302. } else {
  303. HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
  304. LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) ?
  305. (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
  306. }
  307. /*DbgPrint("[DM] THresh H/L=%d/%d\n\r", RATR.HighRSSIThreshForRA, RATR.LowRSSIThreshForRA);*/
  308. if (priv->undecorated_smoothed_pwdb >= (long)HighRSSIThreshForRA) {
  309. /*DbgPrint("[DM] RSSI=%d STA=HIGH\n\r", pHalData->UndecoratedSmoothedPWDB);*/
  310. pra->ratr_state = DM_RATR_STA_HIGH;
  311. targetRATR = pra->upper_rssi_threshold_ratr;
  312. } else if (priv->undecorated_smoothed_pwdb >= (long)LowRSSIThreshForRA) {
  313. /*DbgPrint("[DM] RSSI=%d STA=Middle\n\r", pHalData->UndecoratedSmoothedPWDB);*/
  314. pra->ratr_state = DM_RATR_STA_MIDDLE;
  315. targetRATR = pra->middle_rssi_threshold_ratr;
  316. } else {
  317. /*DbgPrint("[DM] RSSI=%d STA=LOW\n\r", pHalData->UndecoratedSmoothedPWDB);*/
  318. pra->ratr_state = DM_RATR_STA_LOW;
  319. targetRATR = pra->low_rssi_threshold_ratr;
  320. }
  321. /* cosa add for test */
  322. if (pra->ping_rssi_enable) {
  323. /*pHalData->UndecoratedSmoothedPWDB = 19;*/
  324. if (priv->undecorated_smoothed_pwdb < (long)(pra->ping_rssi_thresh_for_ra+5)) {
  325. if ((priv->undecorated_smoothed_pwdb < (long)pra->ping_rssi_thresh_for_ra) ||
  326. ping_rssi_state) {
  327. /*DbgPrint("TestRSSI = %d, set RATR to 0x%x\n", pHalData->UndecoratedSmoothedPWDB, pRA->TestRSSIRATR);*/
  328. pra->ratr_state = DM_RATR_STA_LOW;
  329. targetRATR = pra->ping_rssi_ratr;
  330. ping_rssi_state = 1;
  331. }
  332. /*else
  333. DbgPrint("TestRSSI is between the range.\n");*/
  334. } else {
  335. /*DbgPrint("TestRSSI Recover to 0x%x\n", targetRATR);*/
  336. ping_rssi_state = 0;
  337. }
  338. }
  339. /*
  340. * 2008.04.01
  341. * For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
  342. */
  343. if (priv->ieee80211->GetHalfNmodeSupportByAPsHandler(dev))
  344. targetRATR &= 0xf00fffff;
  345. /* Check whether updating of RATR0 is required */
  346. read_nic_dword(dev, RATR0, &currentRATR);
  347. if (targetRATR != currentRATR) {
  348. u32 ratr_value;
  349. ratr_value = targetRATR;
  350. RT_TRACE(COMP_RATE, "currentRATR = %x, targetRATR = %x\n", currentRATR, targetRATR);
  351. if (priv->rf_type == RF_1T2R)
  352. ratr_value &= ~(RATE_ALL_OFDM_2SS);
  353. write_nic_dword(dev, RATR0, ratr_value);
  354. write_nic_byte(dev, UFWP, 1);
  355. pra->last_ratr = targetRATR;
  356. }
  357. } else {
  358. pra->ratr_state = DM_RATR_STA_MAX;
  359. }
  360. } /* dm_CheckRateAdaptive */
  361. static void dm_init_bandwidth_autoswitch(struct net_device *dev)
  362. {
  363. struct r8192_priv *priv = ieee80211_priv(dev);
  364. priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz = BW_AUTO_SWITCH_LOW_HIGH;
  365. priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz = BW_AUTO_SWITCH_HIGH_LOW;
  366. priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
  367. priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable = false;
  368. } /* dm_init_bandwidth_autoswitch */
  369. static void dm_bandwidth_autoswitch(struct net_device *dev)
  370. {
  371. struct r8192_priv *priv = ieee80211_priv(dev);
  372. if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 || !priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable)
  373. return;
  374. if (!priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz) { /* If send packets in 40 Mhz in 20/40 */
  375. if (priv->undecorated_smoothed_pwdb <= priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz)
  376. priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = true;
  377. } else { /* in force send packets in 20 Mhz in 20/40 */
  378. if (priv->undecorated_smoothed_pwdb >= priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz)
  379. priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
  380. }
  381. } /* dm_BandwidthAutoSwitch */
  382. /* OFDM default at 0db, index=6. */
  383. static u32 OFDMSwingTable[OFDM_Table_Length] = {
  384. 0x7f8001fe, /* 0, +6db */
  385. 0x71c001c7, /* 1, +5db */
  386. 0x65400195, /* 2, +4db */
  387. 0x5a400169, /* 3, +3db */
  388. 0x50800142, /* 4, +2db */
  389. 0x47c0011f, /* 5, +1db */
  390. 0x40000100, /* 6, +0db ===> default, upper for higher temperature, lower for low temperature */
  391. 0x390000e4, /* 7, -1db */
  392. 0x32c000cb, /* 8, -2db */
  393. 0x2d4000b5, /* 9, -3db */
  394. 0x288000a2, /* 10, -4db */
  395. 0x24000090, /* 11, -5db */
  396. 0x20000080, /* 12, -6db */
  397. 0x1c800072, /* 13, -7db */
  398. 0x19800066, /* 14, -8db */
  399. 0x26c0005b, /* 15, -9db */
  400. 0x24400051, /* 16, -10db */
  401. 0x12000048, /* 17, -11db */
  402. 0x10000040 /* 18, -12db */
  403. };
  404. static u8 CCKSwingTable_Ch1_Ch13[CCK_Table_length][8] = {
  405. {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0db ===> CCK40M default */
  406. {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 1, -1db */
  407. {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 2, -2db */
  408. {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 3, -3db */
  409. {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 4, -4db */
  410. {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 5, -5db */
  411. {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 6, -6db ===> CCK20M default */
  412. {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 7, -7db */
  413. {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 8, -8db */
  414. {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 9, -9db */
  415. {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 10, -10db */
  416. {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01} /* 11, -11db */
  417. };
  418. static u8 CCKSwingTable_Ch14[CCK_Table_length][8] = {
  419. {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0db ===> CCK40M default */
  420. {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 1, -1db */
  421. {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 2, -2db */
  422. {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 3, -3db */
  423. {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 4, -4db */
  424. {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 5, -5db */
  425. {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 6, -6db ===> CCK20M default */
  426. {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 7, -7db */
  427. {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 8, -8db */
  428. {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 9, -9db */
  429. {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 10, -10db */
  430. {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00} /* 11, -11db */
  431. };
  432. static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
  433. {
  434. struct r8192_priv *priv = ieee80211_priv(dev);
  435. bool bHighpowerstate, viviflag = false;
  436. DCMD_TXCMD_T tx_cmd;
  437. u8 powerlevelOFDM24G;
  438. int i = 0, j = 0, k = 0;
  439. u8 RF_Type, tmp_report[5] = {0, 0, 0, 0, 0};
  440. u32 Value;
  441. u8 Pwr_Flag;
  442. u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver = 0;
  443. /*RT_STATUS rtStatus = RT_STATUS_SUCCESS;*/
  444. bool rtStatus = true;
  445. u32 delta = 0;
  446. write_nic_byte(dev, 0x1ba, 0);
  447. priv->ieee80211->bdynamic_txpower_enable = false;
  448. bHighpowerstate = priv->bDynamicTxHighPower;
  449. powerlevelOFDM24G = (u8)(priv->Pwr_Track>>24);
  450. RF_Type = priv->rf_type;
  451. Value = (RF_Type<<8) | powerlevelOFDM24G;
  452. RT_TRACE(COMP_POWER_TRACKING, "powerlevelOFDM24G = %x\n", powerlevelOFDM24G);
  453. for (j = 0; j <= 30; j++) { /* fill tx_cmd */
  454. tx_cmd.Op = TXCMD_SET_TX_PWR_TRACKING;
  455. tx_cmd.Length = 4;
  456. tx_cmd.Value = Value;
  457. rtStatus = SendTxCommandPacket(dev, &tx_cmd, 12);
  458. if (rtStatus == RT_STATUS_FAILURE)
  459. RT_TRACE(COMP_POWER_TRACKING, "Set configuration with tx cmd queue fail!\n");
  460. mdelay(1);
  461. /*DbgPrint("hi, vivi, strange\n");*/
  462. for (i = 0; i <= 30; i++) {
  463. read_nic_byte(dev, 0x1ba, &Pwr_Flag);
  464. if (Pwr_Flag == 0) {
  465. mdelay(1);
  466. continue;
  467. }
  468. read_nic_word(dev, 0x13c, &Avg_TSSI_Meas);
  469. if (Avg_TSSI_Meas == 0) {
  470. write_nic_byte(dev, 0x1ba, 0);
  471. break;
  472. }
  473. for (k = 0; k < 5; k++) {
  474. if (k != 4)
  475. read_nic_byte(dev, 0x134+k, &tmp_report[k]);
  476. else
  477. read_nic_byte(dev, 0x13e, &tmp_report[k]);
  478. RT_TRACE(COMP_POWER_TRACKING, "TSSI_report_value = %d\n", tmp_report[k]);
  479. }
  480. /* check if the report value is right */
  481. for (k = 0; k < 5; k++) {
  482. if (tmp_report[k] <= 20) {
  483. viviflag = true;
  484. break;
  485. }
  486. }
  487. if (viviflag) {
  488. write_nic_byte(dev, 0x1ba, 0);
  489. viviflag = false;
  490. RT_TRACE(COMP_POWER_TRACKING, "we filtered the data\n");
  491. for (k = 0; k < 5; k++)
  492. tmp_report[k] = 0;
  493. break;
  494. }
  495. for (k = 0; k < 5; k++)
  496. Avg_TSSI_Meas_from_driver += tmp_report[k];
  497. Avg_TSSI_Meas_from_driver = Avg_TSSI_Meas_from_driver*100/5;
  498. RT_TRACE(COMP_POWER_TRACKING, "Avg_TSSI_Meas_from_driver = %d\n", Avg_TSSI_Meas_from_driver);
  499. TSSI_13dBm = priv->TSSI_13dBm;
  500. RT_TRACE(COMP_POWER_TRACKING, "TSSI_13dBm = %d\n", TSSI_13dBm);
  501. /*if (abs(Avg_TSSI_Meas_from_driver - TSSI_13dBm) <= E_FOR_TX_POWER_TRACK)*/
  502. /* For MacOS-compatible */
  503. if (Avg_TSSI_Meas_from_driver > TSSI_13dBm)
  504. delta = Avg_TSSI_Meas_from_driver - TSSI_13dBm;
  505. else
  506. delta = TSSI_13dBm - Avg_TSSI_Meas_from_driver;
  507. if (delta <= E_FOR_TX_POWER_TRACK) {
  508. priv->ieee80211->bdynamic_txpower_enable = true;
  509. write_nic_byte(dev, 0x1ba, 0);
  510. RT_TRACE(COMP_POWER_TRACKING, "tx power track is done\n");
  511. RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
  512. RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
  513. RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation_difference = %d\n", priv->cck_present_attentuation_difference);
  514. RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation = %d\n", priv->cck_present_attentuation);
  515. return;
  516. }
  517. if (Avg_TSSI_Meas_from_driver < TSSI_13dBm - E_FOR_TX_POWER_TRACK) {
  518. if (priv->rfa_txpowertrackingindex > 0) {
  519. priv->rfa_txpowertrackingindex--;
  520. if (priv->rfa_txpowertrackingindex_real > 4) {
  521. priv->rfa_txpowertrackingindex_real--;
  522. rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
  523. }
  524. }
  525. } else {
  526. if (priv->rfa_txpowertrackingindex < 36) {
  527. priv->rfa_txpowertrackingindex++;
  528. priv->rfa_txpowertrackingindex_real++;
  529. rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
  530. }
  531. }
  532. priv->cck_present_attentuation_difference
  533. = priv->rfa_txpowertrackingindex - priv->rfa_txpowertracking_default;
  534. if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
  535. priv->cck_present_attentuation
  536. = priv->cck_present_attentuation_20Mdefault + priv->cck_present_attentuation_difference;
  537. else
  538. priv->cck_present_attentuation
  539. = priv->cck_present_attentuation_40Mdefault + priv->cck_present_attentuation_difference;
  540. if (priv->cck_present_attentuation > -1 && priv->cck_present_attentuation < 23) {
  541. if (priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14) {
  542. priv->bcck_in_ch14 = true;
  543. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  544. } else if (priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14) {
  545. priv->bcck_in_ch14 = false;
  546. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  547. } else
  548. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  549. }
  550. RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
  551. RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
  552. RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation_difference = %d\n", priv->cck_present_attentuation_difference);
  553. RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation = %d\n", priv->cck_present_attentuation);
  554. if (priv->cck_present_attentuation_difference <= -12 || priv->cck_present_attentuation_difference >= 24) {
  555. priv->ieee80211->bdynamic_txpower_enable = true;
  556. write_nic_byte(dev, 0x1ba, 0);
  557. RT_TRACE(COMP_POWER_TRACKING, "tx power track--->limited\n");
  558. return;
  559. }
  560. write_nic_byte(dev, 0x1ba, 0);
  561. Avg_TSSI_Meas_from_driver = 0;
  562. for (k = 0; k < 5; k++)
  563. tmp_report[k] = 0;
  564. break;
  565. }
  566. }
  567. priv->ieee80211->bdynamic_txpower_enable = true;
  568. write_nic_byte(dev, 0x1ba, 0);
  569. }
  570. static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
  571. {
  572. #define ThermalMeterVal 9
  573. struct r8192_priv *priv = ieee80211_priv(dev);
  574. u32 tmpRegA, TempCCk;
  575. u8 tmpOFDMindex, tmpCCKindex, tmpCCK20Mindex, tmpCCK40Mindex, tmpval;
  576. int i = 0, CCKSwingNeedUpdate = 0;
  577. if (!priv->btxpower_trackingInit) {
  578. /* Query OFDM default setting */
  579. tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
  580. for (i = 0; i < OFDM_Table_Length; i++) { /* find the index */
  581. if (tmpRegA == OFDMSwingTable[i]) {
  582. priv->OFDM_index = (u8)i;
  583. RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, OFDM_index=0x%x\n",
  584. rOFDM0_XATxIQImbalance, tmpRegA, priv->OFDM_index);
  585. }
  586. }
  587. /* Query CCK default setting From 0xa22 */
  588. TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
  589. for (i = 0; i < CCK_Table_length; i++) {
  590. if (TempCCk == (u32)CCKSwingTable_Ch1_Ch13[i][0]) {
  591. priv->CCK_index = (u8) i;
  592. RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, CCK_index=0x%x\n",
  593. rCCK0_TxFilter1, TempCCk, priv->CCK_index);
  594. break;
  595. }
  596. }
  597. priv->btxpower_trackingInit = true;
  598. /*pHalData->TXPowercount = 0;*/
  599. return;
  600. }
  601. /*
  602. * ==========================
  603. * this is only for test, should be masked
  604. * ==========================
  605. */
  606. /* read and filter out unreasonable value */
  607. tmpRegA = rtl8192_phy_QueryRFReg(dev, RF90_PATH_A, 0x12, 0x078); /* 0x12: RF Reg[10:7] */
  608. RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d\n", tmpRegA);
  609. if (tmpRegA < 3 || tmpRegA > 13)
  610. return;
  611. if (tmpRegA >= 12) /* if over 12, TP will be bad when high temperature */
  612. tmpRegA = 12;
  613. RT_TRACE(COMP_POWER_TRACKING, "Valid ThermalMeterA = %d\n", tmpRegA);
  614. priv->ThermalMeter[0] = ThermalMeterVal; /* We use fixed value by Bryant's suggestion */
  615. priv->ThermalMeter[1] = ThermalMeterVal; /* We use fixed value by Bryant's suggestion */
  616. /* Get current RF-A temperature index */
  617. if (priv->ThermalMeter[0] >= (u8)tmpRegA) { /* lower temperature */
  618. tmpOFDMindex = tmpCCK20Mindex = 6+(priv->ThermalMeter[0]-(u8)tmpRegA);
  619. tmpCCK40Mindex = tmpCCK20Mindex - 6;
  620. if (tmpOFDMindex >= OFDM_Table_Length)
  621. tmpOFDMindex = OFDM_Table_Length-1;
  622. if (tmpCCK20Mindex >= CCK_Table_length)
  623. tmpCCK20Mindex = CCK_Table_length-1;
  624. if (tmpCCK40Mindex >= CCK_Table_length)
  625. tmpCCK40Mindex = CCK_Table_length-1;
  626. } else {
  627. tmpval = (u8)tmpRegA - priv->ThermalMeter[0];
  628. if (tmpval >= 6) /* higher temperature */
  629. tmpOFDMindex = tmpCCK20Mindex = 0; /* max to +6dB */
  630. else
  631. tmpOFDMindex = tmpCCK20Mindex = 6 - tmpval;
  632. tmpCCK40Mindex = 0;
  633. }
  634. /*DbgPrint("%ddb, tmpOFDMindex = %d, tmpCCK20Mindex = %d, tmpCCK40Mindex = %d",
  635. ((u1Byte)tmpRegA - pHalData->ThermalMeter[0]),
  636. tmpOFDMindex, tmpCCK20Mindex, tmpCCK40Mindex);*/
  637. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) /* 40M */
  638. tmpCCKindex = tmpCCK40Mindex;
  639. else
  640. tmpCCKindex = tmpCCK20Mindex;
  641. if (priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14) {
  642. priv->bcck_in_ch14 = true;
  643. CCKSwingNeedUpdate = 1;
  644. } else if (priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14) {
  645. priv->bcck_in_ch14 = false;
  646. CCKSwingNeedUpdate = 1;
  647. }
  648. if (priv->CCK_index != tmpCCKindex) {
  649. priv->CCK_index = tmpCCKindex;
  650. CCKSwingNeedUpdate = 1;
  651. }
  652. if (CCKSwingNeedUpdate) {
  653. /*DbgPrint("Update CCK Swing, CCK_index = %d\n", pHalData->CCK_index);*/
  654. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  655. }
  656. if (priv->OFDM_index != tmpOFDMindex) {
  657. priv->OFDM_index = tmpOFDMindex;
  658. rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, OFDMSwingTable[priv->OFDM_index]);
  659. RT_TRACE(COMP_POWER_TRACKING, "Update OFDMSwing[%d] = 0x%x\n",
  660. priv->OFDM_index, OFDMSwingTable[priv->OFDM_index]);
  661. }
  662. priv->txpower_count = 0;
  663. }
  664. void dm_txpower_trackingcallback(struct work_struct *work)
  665. {
  666. struct delayed_work *dwork = container_of(work, struct delayed_work, work);
  667. struct r8192_priv *priv = container_of(dwork, struct r8192_priv, txpower_tracking_wq);
  668. struct net_device *dev = priv->ieee80211->dev;
  669. if (priv->bDcut)
  670. dm_TXPowerTrackingCallback_TSSI(dev);
  671. else
  672. dm_TXPowerTrackingCallback_ThermalMeter(dev);
  673. }
  674. static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
  675. {
  676. struct r8192_priv *priv = ieee80211_priv(dev);
  677. /* Initial the Tx BB index and mapping value */
  678. priv->txbbgain_table[0].txbb_iq_amplifygain = 12;
  679. priv->txbbgain_table[0].txbbgain_value = 0x7f8001fe;
  680. priv->txbbgain_table[1].txbb_iq_amplifygain = 11;
  681. priv->txbbgain_table[1].txbbgain_value = 0x788001e2;
  682. priv->txbbgain_table[2].txbb_iq_amplifygain = 10;
  683. priv->txbbgain_table[2].txbbgain_value = 0x71c001c7;
  684. priv->txbbgain_table[3].txbb_iq_amplifygain = 9;
  685. priv->txbbgain_table[3].txbbgain_value = 0x6b8001ae;
  686. priv->txbbgain_table[4].txbb_iq_amplifygain = 8;
  687. priv->txbbgain_table[4].txbbgain_value = 0x65400195;
  688. priv->txbbgain_table[5].txbb_iq_amplifygain = 7;
  689. priv->txbbgain_table[5].txbbgain_value = 0x5fc0017f;
  690. priv->txbbgain_table[6].txbb_iq_amplifygain = 6;
  691. priv->txbbgain_table[6].txbbgain_value = 0x5a400169;
  692. priv->txbbgain_table[7].txbb_iq_amplifygain = 5;
  693. priv->txbbgain_table[7].txbbgain_value = 0x55400155;
  694. priv->txbbgain_table[8].txbb_iq_amplifygain = 4;
  695. priv->txbbgain_table[8].txbbgain_value = 0x50800142;
  696. priv->txbbgain_table[9].txbb_iq_amplifygain = 3;
  697. priv->txbbgain_table[9].txbbgain_value = 0x4c000130;
  698. priv->txbbgain_table[10].txbb_iq_amplifygain = 2;
  699. priv->txbbgain_table[10].txbbgain_value = 0x47c0011f;
  700. priv->txbbgain_table[11].txbb_iq_amplifygain = 1;
  701. priv->txbbgain_table[11].txbbgain_value = 0x43c0010f;
  702. priv->txbbgain_table[12].txbb_iq_amplifygain = 0;
  703. priv->txbbgain_table[12].txbbgain_value = 0x40000100;
  704. priv->txbbgain_table[13].txbb_iq_amplifygain = -1;
  705. priv->txbbgain_table[13].txbbgain_value = 0x3c8000f2;
  706. priv->txbbgain_table[14].txbb_iq_amplifygain = -2;
  707. priv->txbbgain_table[14].txbbgain_value = 0x390000e4;
  708. priv->txbbgain_table[15].txbb_iq_amplifygain = -3;
  709. priv->txbbgain_table[15].txbbgain_value = 0x35c000d7;
  710. priv->txbbgain_table[16].txbb_iq_amplifygain = -4;
  711. priv->txbbgain_table[16].txbbgain_value = 0x32c000cb;
  712. priv->txbbgain_table[17].txbb_iq_amplifygain = -5;
  713. priv->txbbgain_table[17].txbbgain_value = 0x300000c0;
  714. priv->txbbgain_table[18].txbb_iq_amplifygain = -6;
  715. priv->txbbgain_table[18].txbbgain_value = 0x2d4000b5;
  716. priv->txbbgain_table[19].txbb_iq_amplifygain = -7;
  717. priv->txbbgain_table[19].txbbgain_value = 0x2ac000ab;
  718. priv->txbbgain_table[20].txbb_iq_amplifygain = -8;
  719. priv->txbbgain_table[20].txbbgain_value = 0x288000a2;
  720. priv->txbbgain_table[21].txbb_iq_amplifygain = -9;
  721. priv->txbbgain_table[21].txbbgain_value = 0x26000098;
  722. priv->txbbgain_table[22].txbb_iq_amplifygain = -10;
  723. priv->txbbgain_table[22].txbbgain_value = 0x24000090;
  724. priv->txbbgain_table[23].txbb_iq_amplifygain = -11;
  725. priv->txbbgain_table[23].txbbgain_value = 0x22000088;
  726. priv->txbbgain_table[24].txbb_iq_amplifygain = -12;
  727. priv->txbbgain_table[24].txbbgain_value = 0x20000080;
  728. priv->txbbgain_table[25].txbb_iq_amplifygain = -13;
  729. priv->txbbgain_table[25].txbbgain_value = 0x1a00006c;
  730. priv->txbbgain_table[26].txbb_iq_amplifygain = -14;
  731. priv->txbbgain_table[26].txbbgain_value = 0x1c800072;
  732. priv->txbbgain_table[27].txbb_iq_amplifygain = -15;
  733. priv->txbbgain_table[27].txbbgain_value = 0x18000060;
  734. priv->txbbgain_table[28].txbb_iq_amplifygain = -16;
  735. priv->txbbgain_table[28].txbbgain_value = 0x19800066;
  736. priv->txbbgain_table[29].txbb_iq_amplifygain = -17;
  737. priv->txbbgain_table[29].txbbgain_value = 0x15800056;
  738. priv->txbbgain_table[30].txbb_iq_amplifygain = -18;
  739. priv->txbbgain_table[30].txbbgain_value = 0x26c0005b;
  740. priv->txbbgain_table[31].txbb_iq_amplifygain = -19;
  741. priv->txbbgain_table[31].txbbgain_value = 0x14400051;
  742. priv->txbbgain_table[32].txbb_iq_amplifygain = -20;
  743. priv->txbbgain_table[32].txbbgain_value = 0x24400051;
  744. priv->txbbgain_table[33].txbb_iq_amplifygain = -21;
  745. priv->txbbgain_table[33].txbbgain_value = 0x1300004c;
  746. priv->txbbgain_table[34].txbb_iq_amplifygain = -22;
  747. priv->txbbgain_table[34].txbbgain_value = 0x12000048;
  748. priv->txbbgain_table[35].txbb_iq_amplifygain = -23;
  749. priv->txbbgain_table[35].txbbgain_value = 0x11000044;
  750. priv->txbbgain_table[36].txbb_iq_amplifygain = -24;
  751. priv->txbbgain_table[36].txbbgain_value = 0x10000040;
  752. /*
  753. * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
  754. * This Table is for CH1~CH13
  755. */
  756. priv->cck_txbbgain_table[0].ccktxbb_valuearray[0] = 0x36;
  757. priv->cck_txbbgain_table[0].ccktxbb_valuearray[1] = 0x35;
  758. priv->cck_txbbgain_table[0].ccktxbb_valuearray[2] = 0x2e;
  759. priv->cck_txbbgain_table[0].ccktxbb_valuearray[3] = 0x25;
  760. priv->cck_txbbgain_table[0].ccktxbb_valuearray[4] = 0x1c;
  761. priv->cck_txbbgain_table[0].ccktxbb_valuearray[5] = 0x12;
  762. priv->cck_txbbgain_table[0].ccktxbb_valuearray[6] = 0x09;
  763. priv->cck_txbbgain_table[0].ccktxbb_valuearray[7] = 0x04;
  764. priv->cck_txbbgain_table[1].ccktxbb_valuearray[0] = 0x33;
  765. priv->cck_txbbgain_table[1].ccktxbb_valuearray[1] = 0x32;
  766. priv->cck_txbbgain_table[1].ccktxbb_valuearray[2] = 0x2b;
  767. priv->cck_txbbgain_table[1].ccktxbb_valuearray[3] = 0x23;
  768. priv->cck_txbbgain_table[1].ccktxbb_valuearray[4] = 0x1a;
  769. priv->cck_txbbgain_table[1].ccktxbb_valuearray[5] = 0x11;
  770. priv->cck_txbbgain_table[1].ccktxbb_valuearray[6] = 0x08;
  771. priv->cck_txbbgain_table[1].ccktxbb_valuearray[7] = 0x04;
  772. priv->cck_txbbgain_table[2].ccktxbb_valuearray[0] = 0x30;
  773. priv->cck_txbbgain_table[2].ccktxbb_valuearray[1] = 0x2f;
  774. priv->cck_txbbgain_table[2].ccktxbb_valuearray[2] = 0x29;
  775. priv->cck_txbbgain_table[2].ccktxbb_valuearray[3] = 0x21;
  776. priv->cck_txbbgain_table[2].ccktxbb_valuearray[4] = 0x19;
  777. priv->cck_txbbgain_table[2].ccktxbb_valuearray[5] = 0x10;
  778. priv->cck_txbbgain_table[2].ccktxbb_valuearray[6] = 0x08;
  779. priv->cck_txbbgain_table[2].ccktxbb_valuearray[7] = 0x03;
  780. priv->cck_txbbgain_table[3].ccktxbb_valuearray[0] = 0x2d;
  781. priv->cck_txbbgain_table[3].ccktxbb_valuearray[1] = 0x2d;
  782. priv->cck_txbbgain_table[3].ccktxbb_valuearray[2] = 0x27;
  783. priv->cck_txbbgain_table[3].ccktxbb_valuearray[3] = 0x1f;
  784. priv->cck_txbbgain_table[3].ccktxbb_valuearray[4] = 0x18;
  785. priv->cck_txbbgain_table[3].ccktxbb_valuearray[5] = 0x0f;
  786. priv->cck_txbbgain_table[3].ccktxbb_valuearray[6] = 0x08;
  787. priv->cck_txbbgain_table[3].ccktxbb_valuearray[7] = 0x03;
  788. priv->cck_txbbgain_table[4].ccktxbb_valuearray[0] = 0x2b;
  789. priv->cck_txbbgain_table[4].ccktxbb_valuearray[1] = 0x2a;
  790. priv->cck_txbbgain_table[4].ccktxbb_valuearray[2] = 0x25;
  791. priv->cck_txbbgain_table[4].ccktxbb_valuearray[3] = 0x1e;
  792. priv->cck_txbbgain_table[4].ccktxbb_valuearray[4] = 0x16;
  793. priv->cck_txbbgain_table[4].ccktxbb_valuearray[5] = 0x0e;
  794. priv->cck_txbbgain_table[4].ccktxbb_valuearray[6] = 0x07;
  795. priv->cck_txbbgain_table[4].ccktxbb_valuearray[7] = 0x03;
  796. priv->cck_txbbgain_table[5].ccktxbb_valuearray[0] = 0x28;
  797. priv->cck_txbbgain_table[5].ccktxbb_valuearray[1] = 0x28;
  798. priv->cck_txbbgain_table[5].ccktxbb_valuearray[2] = 0x22;
  799. priv->cck_txbbgain_table[5].ccktxbb_valuearray[3] = 0x1c;
  800. priv->cck_txbbgain_table[5].ccktxbb_valuearray[4] = 0x15;
  801. priv->cck_txbbgain_table[5].ccktxbb_valuearray[5] = 0x0d;
  802. priv->cck_txbbgain_table[5].ccktxbb_valuearray[6] = 0x07;
  803. priv->cck_txbbgain_table[5].ccktxbb_valuearray[7] = 0x03;
  804. priv->cck_txbbgain_table[6].ccktxbb_valuearray[0] = 0x26;
  805. priv->cck_txbbgain_table[6].ccktxbb_valuearray[1] = 0x25;
  806. priv->cck_txbbgain_table[6].ccktxbb_valuearray[2] = 0x21;
  807. priv->cck_txbbgain_table[6].ccktxbb_valuearray[3] = 0x1b;
  808. priv->cck_txbbgain_table[6].ccktxbb_valuearray[4] = 0x14;
  809. priv->cck_txbbgain_table[6].ccktxbb_valuearray[5] = 0x0d;
  810. priv->cck_txbbgain_table[6].ccktxbb_valuearray[6] = 0x06;
  811. priv->cck_txbbgain_table[6].ccktxbb_valuearray[7] = 0x03;
  812. priv->cck_txbbgain_table[7].ccktxbb_valuearray[0] = 0x24;
  813. priv->cck_txbbgain_table[7].ccktxbb_valuearray[1] = 0x23;
  814. priv->cck_txbbgain_table[7].ccktxbb_valuearray[2] = 0x1f;
  815. priv->cck_txbbgain_table[7].ccktxbb_valuearray[3] = 0x19;
  816. priv->cck_txbbgain_table[7].ccktxbb_valuearray[4] = 0x13;
  817. priv->cck_txbbgain_table[7].ccktxbb_valuearray[5] = 0x0c;
  818. priv->cck_txbbgain_table[7].ccktxbb_valuearray[6] = 0x06;
  819. priv->cck_txbbgain_table[7].ccktxbb_valuearray[7] = 0x03;
  820. priv->cck_txbbgain_table[8].ccktxbb_valuearray[0] = 0x22;
  821. priv->cck_txbbgain_table[8].ccktxbb_valuearray[1] = 0x21;
  822. priv->cck_txbbgain_table[8].ccktxbb_valuearray[2] = 0x1d;
  823. priv->cck_txbbgain_table[8].ccktxbb_valuearray[3] = 0x18;
  824. priv->cck_txbbgain_table[8].ccktxbb_valuearray[4] = 0x11;
  825. priv->cck_txbbgain_table[8].ccktxbb_valuearray[5] = 0x0b;
  826. priv->cck_txbbgain_table[8].ccktxbb_valuearray[6] = 0x06;
  827. priv->cck_txbbgain_table[8].ccktxbb_valuearray[7] = 0x02;
  828. priv->cck_txbbgain_table[9].ccktxbb_valuearray[0] = 0x20;
  829. priv->cck_txbbgain_table[9].ccktxbb_valuearray[1] = 0x20;
  830. priv->cck_txbbgain_table[9].ccktxbb_valuearray[2] = 0x1b;
  831. priv->cck_txbbgain_table[9].ccktxbb_valuearray[3] = 0x16;
  832. priv->cck_txbbgain_table[9].ccktxbb_valuearray[4] = 0x11;
  833. priv->cck_txbbgain_table[9].ccktxbb_valuearray[5] = 0x08;
  834. priv->cck_txbbgain_table[9].ccktxbb_valuearray[6] = 0x05;
  835. priv->cck_txbbgain_table[9].ccktxbb_valuearray[7] = 0x02;
  836. priv->cck_txbbgain_table[10].ccktxbb_valuearray[0] = 0x1f;
  837. priv->cck_txbbgain_table[10].ccktxbb_valuearray[1] = 0x1e;
  838. priv->cck_txbbgain_table[10].ccktxbb_valuearray[2] = 0x1a;
  839. priv->cck_txbbgain_table[10].ccktxbb_valuearray[3] = 0x15;
  840. priv->cck_txbbgain_table[10].ccktxbb_valuearray[4] = 0x10;
  841. priv->cck_txbbgain_table[10].ccktxbb_valuearray[5] = 0x0a;
  842. priv->cck_txbbgain_table[10].ccktxbb_valuearray[6] = 0x05;
  843. priv->cck_txbbgain_table[10].ccktxbb_valuearray[7] = 0x02;
  844. priv->cck_txbbgain_table[11].ccktxbb_valuearray[0] = 0x1d;
  845. priv->cck_txbbgain_table[11].ccktxbb_valuearray[1] = 0x1c;
  846. priv->cck_txbbgain_table[11].ccktxbb_valuearray[2] = 0x18;
  847. priv->cck_txbbgain_table[11].ccktxbb_valuearray[3] = 0x14;
  848. priv->cck_txbbgain_table[11].ccktxbb_valuearray[4] = 0x0f;
  849. priv->cck_txbbgain_table[11].ccktxbb_valuearray[5] = 0x0a;
  850. priv->cck_txbbgain_table[11].ccktxbb_valuearray[6] = 0x05;
  851. priv->cck_txbbgain_table[11].ccktxbb_valuearray[7] = 0x02;
  852. priv->cck_txbbgain_table[12].ccktxbb_valuearray[0] = 0x1b;
  853. priv->cck_txbbgain_table[12].ccktxbb_valuearray[1] = 0x1a;
  854. priv->cck_txbbgain_table[12].ccktxbb_valuearray[2] = 0x17;
  855. priv->cck_txbbgain_table[12].ccktxbb_valuearray[3] = 0x13;
  856. priv->cck_txbbgain_table[12].ccktxbb_valuearray[4] = 0x0e;
  857. priv->cck_txbbgain_table[12].ccktxbb_valuearray[5] = 0x09;
  858. priv->cck_txbbgain_table[12].ccktxbb_valuearray[6] = 0x04;
  859. priv->cck_txbbgain_table[12].ccktxbb_valuearray[7] = 0x02;
  860. priv->cck_txbbgain_table[13].ccktxbb_valuearray[0] = 0x1a;
  861. priv->cck_txbbgain_table[13].ccktxbb_valuearray[1] = 0x19;
  862. priv->cck_txbbgain_table[13].ccktxbb_valuearray[2] = 0x16;
  863. priv->cck_txbbgain_table[13].ccktxbb_valuearray[3] = 0x12;
  864. priv->cck_txbbgain_table[13].ccktxbb_valuearray[4] = 0x0d;
  865. priv->cck_txbbgain_table[13].ccktxbb_valuearray[5] = 0x09;
  866. priv->cck_txbbgain_table[13].ccktxbb_valuearray[6] = 0x04;
  867. priv->cck_txbbgain_table[13].ccktxbb_valuearray[7] = 0x02;
  868. priv->cck_txbbgain_table[14].ccktxbb_valuearray[0] = 0x18;
  869. priv->cck_txbbgain_table[14].ccktxbb_valuearray[1] = 0x17;
  870. priv->cck_txbbgain_table[14].ccktxbb_valuearray[2] = 0x15;
  871. priv->cck_txbbgain_table[14].ccktxbb_valuearray[3] = 0x11;
  872. priv->cck_txbbgain_table[14].ccktxbb_valuearray[4] = 0x0c;
  873. priv->cck_txbbgain_table[14].ccktxbb_valuearray[5] = 0x08;
  874. priv->cck_txbbgain_table[14].ccktxbb_valuearray[6] = 0x04;
  875. priv->cck_txbbgain_table[14].ccktxbb_valuearray[7] = 0x02;
  876. priv->cck_txbbgain_table[15].ccktxbb_valuearray[0] = 0x17;
  877. priv->cck_txbbgain_table[15].ccktxbb_valuearray[1] = 0x16;
  878. priv->cck_txbbgain_table[15].ccktxbb_valuearray[2] = 0x13;
  879. priv->cck_txbbgain_table[15].ccktxbb_valuearray[3] = 0x10;
  880. priv->cck_txbbgain_table[15].ccktxbb_valuearray[4] = 0x0c;
  881. priv->cck_txbbgain_table[15].ccktxbb_valuearray[5] = 0x08;
  882. priv->cck_txbbgain_table[15].ccktxbb_valuearray[6] = 0x04;
  883. priv->cck_txbbgain_table[15].ccktxbb_valuearray[7] = 0x02;
  884. priv->cck_txbbgain_table[16].ccktxbb_valuearray[0] = 0x16;
  885. priv->cck_txbbgain_table[16].ccktxbb_valuearray[1] = 0x15;
  886. priv->cck_txbbgain_table[16].ccktxbb_valuearray[2] = 0x12;
  887. priv->cck_txbbgain_table[16].ccktxbb_valuearray[3] = 0x0f;
  888. priv->cck_txbbgain_table[16].ccktxbb_valuearray[4] = 0x0b;
  889. priv->cck_txbbgain_table[16].ccktxbb_valuearray[5] = 0x07;
  890. priv->cck_txbbgain_table[16].ccktxbb_valuearray[6] = 0x04;
  891. priv->cck_txbbgain_table[16].ccktxbb_valuearray[7] = 0x01;
  892. priv->cck_txbbgain_table[17].ccktxbb_valuearray[0] = 0x14;
  893. priv->cck_txbbgain_table[17].ccktxbb_valuearray[1] = 0x14;
  894. priv->cck_txbbgain_table[17].ccktxbb_valuearray[2] = 0x11;
  895. priv->cck_txbbgain_table[17].ccktxbb_valuearray[3] = 0x0e;
  896. priv->cck_txbbgain_table[17].ccktxbb_valuearray[4] = 0x0b;
  897. priv->cck_txbbgain_table[17].ccktxbb_valuearray[5] = 0x07;
  898. priv->cck_txbbgain_table[17].ccktxbb_valuearray[6] = 0x03;
  899. priv->cck_txbbgain_table[17].ccktxbb_valuearray[7] = 0x02;
  900. priv->cck_txbbgain_table[18].ccktxbb_valuearray[0] = 0x13;
  901. priv->cck_txbbgain_table[18].ccktxbb_valuearray[1] = 0x13;
  902. priv->cck_txbbgain_table[18].ccktxbb_valuearray[2] = 0x10;
  903. priv->cck_txbbgain_table[18].ccktxbb_valuearray[3] = 0x0d;
  904. priv->cck_txbbgain_table[18].ccktxbb_valuearray[4] = 0x0a;
  905. priv->cck_txbbgain_table[18].ccktxbb_valuearray[5] = 0x06;
  906. priv->cck_txbbgain_table[18].ccktxbb_valuearray[6] = 0x03;
  907. priv->cck_txbbgain_table[18].ccktxbb_valuearray[7] = 0x01;
  908. priv->cck_txbbgain_table[19].ccktxbb_valuearray[0] = 0x12;
  909. priv->cck_txbbgain_table[19].ccktxbb_valuearray[1] = 0x12;
  910. priv->cck_txbbgain_table[19].ccktxbb_valuearray[2] = 0x0f;
  911. priv->cck_txbbgain_table[19].ccktxbb_valuearray[3] = 0x0c;
  912. priv->cck_txbbgain_table[19].ccktxbb_valuearray[4] = 0x09;
  913. priv->cck_txbbgain_table[19].ccktxbb_valuearray[5] = 0x06;
  914. priv->cck_txbbgain_table[19].ccktxbb_valuearray[6] = 0x03;
  915. priv->cck_txbbgain_table[19].ccktxbb_valuearray[7] = 0x01;
  916. priv->cck_txbbgain_table[20].ccktxbb_valuearray[0] = 0x11;
  917. priv->cck_txbbgain_table[20].ccktxbb_valuearray[1] = 0x11;
  918. priv->cck_txbbgain_table[20].ccktxbb_valuearray[2] = 0x0f;
  919. priv->cck_txbbgain_table[20].ccktxbb_valuearray[3] = 0x0c;
  920. priv->cck_txbbgain_table[20].ccktxbb_valuearray[4] = 0x09;
  921. priv->cck_txbbgain_table[20].ccktxbb_valuearray[5] = 0x06;
  922. priv->cck_txbbgain_table[20].ccktxbb_valuearray[6] = 0x03;
  923. priv->cck_txbbgain_table[20].ccktxbb_valuearray[7] = 0x01;
  924. priv->cck_txbbgain_table[21].ccktxbb_valuearray[0] = 0x10;
  925. priv->cck_txbbgain_table[21].ccktxbb_valuearray[1] = 0x10;
  926. priv->cck_txbbgain_table[21].ccktxbb_valuearray[2] = 0x0e;
  927. priv->cck_txbbgain_table[21].ccktxbb_valuearray[3] = 0x0b;
  928. priv->cck_txbbgain_table[21].ccktxbb_valuearray[4] = 0x08;
  929. priv->cck_txbbgain_table[21].ccktxbb_valuearray[5] = 0x05;
  930. priv->cck_txbbgain_table[21].ccktxbb_valuearray[6] = 0x03;
  931. priv->cck_txbbgain_table[21].ccktxbb_valuearray[7] = 0x01;
  932. priv->cck_txbbgain_table[22].ccktxbb_valuearray[0] = 0x0f;
  933. priv->cck_txbbgain_table[22].ccktxbb_valuearray[1] = 0x0f;
  934. priv->cck_txbbgain_table[22].ccktxbb_valuearray[2] = 0x0d;
  935. priv->cck_txbbgain_table[22].ccktxbb_valuearray[3] = 0x0b;
  936. priv->cck_txbbgain_table[22].ccktxbb_valuearray[4] = 0x08;
  937. priv->cck_txbbgain_table[22].ccktxbb_valuearray[5] = 0x05;
  938. priv->cck_txbbgain_table[22].ccktxbb_valuearray[6] = 0x03;
  939. priv->cck_txbbgain_table[22].ccktxbb_valuearray[7] = 0x01;
  940. /*
  941. * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
  942. * This Table is for CH14
  943. */
  944. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[0] = 0x36;
  945. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[1] = 0x35;
  946. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[2] = 0x2e;
  947. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[3] = 0x1b;
  948. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[4] = 0x00;
  949. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[5] = 0x00;
  950. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[6] = 0x00;
  951. priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[7] = 0x00;
  952. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[0] = 0x33;
  953. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[1] = 0x32;
  954. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[2] = 0x2b;
  955. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[3] = 0x19;
  956. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[4] = 0x00;
  957. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[5] = 0x00;
  958. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[6] = 0x00;
  959. priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[7] = 0x00;
  960. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[0] = 0x30;
  961. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[1] = 0x2f;
  962. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[2] = 0x29;
  963. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[3] = 0x18;
  964. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[4] = 0x00;
  965. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[5] = 0x00;
  966. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[6] = 0x00;
  967. priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[7] = 0x00;
  968. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[0] = 0x2d;
  969. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[1] = 0x2d;
  970. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[2] = 0x27;
  971. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[3] = 0x17;
  972. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[4] = 0x00;
  973. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[5] = 0x00;
  974. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[6] = 0x00;
  975. priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[7] = 0x00;
  976. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[0] = 0x2b;
  977. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[1] = 0x2a;
  978. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[2] = 0x25;
  979. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[3] = 0x15;
  980. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[4] = 0x00;
  981. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[5] = 0x00;
  982. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[6] = 0x00;
  983. priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[7] = 0x00;
  984. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[0] = 0x28;
  985. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[1] = 0x28;
  986. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[2] = 0x22;
  987. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[3] = 0x14;
  988. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[4] = 0x00;
  989. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[5] = 0x00;
  990. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[6] = 0x00;
  991. priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[7] = 0x00;
  992. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[0] = 0x26;
  993. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[1] = 0x25;
  994. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[2] = 0x21;
  995. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[3] = 0x13;
  996. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[4] = 0x00;
  997. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[5] = 0x00;
  998. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[6] = 0x00;
  999. priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[7] = 0x00;
  1000. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[0] = 0x24;
  1001. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[1] = 0x23;
  1002. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[2] = 0x1f;
  1003. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[3] = 0x12;
  1004. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[4] = 0x00;
  1005. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[5] = 0x00;
  1006. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[6] = 0x00;
  1007. priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[7] = 0x00;
  1008. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[0] = 0x22;
  1009. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[1] = 0x21;
  1010. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[2] = 0x1d;
  1011. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[3] = 0x11;
  1012. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[4] = 0x00;
  1013. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[5] = 0x00;
  1014. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[6] = 0x00;
  1015. priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[7] = 0x00;
  1016. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[0] = 0x20;
  1017. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[1] = 0x20;
  1018. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[2] = 0x1b;
  1019. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[3] = 0x10;
  1020. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[4] = 0x00;
  1021. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[5] = 0x00;
  1022. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[6] = 0x00;
  1023. priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[7] = 0x00;
  1024. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[0] = 0x1f;
  1025. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[1] = 0x1e;
  1026. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[2] = 0x1a;
  1027. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[3] = 0x0f;
  1028. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[4] = 0x00;
  1029. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[5] = 0x00;
  1030. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[6] = 0x00;
  1031. priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[7] = 0x00;
  1032. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[0] = 0x1d;
  1033. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[1] = 0x1c;
  1034. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[2] = 0x18;
  1035. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[3] = 0x0e;
  1036. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[4] = 0x00;
  1037. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[5] = 0x00;
  1038. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[6] = 0x00;
  1039. priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[7] = 0x00;
  1040. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[0] = 0x1b;
  1041. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[1] = 0x1a;
  1042. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[2] = 0x17;
  1043. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[3] = 0x0e;
  1044. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[4] = 0x00;
  1045. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[5] = 0x00;
  1046. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[6] = 0x00;
  1047. priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[7] = 0x00;
  1048. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[0] = 0x1a;
  1049. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[1] = 0x19;
  1050. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[2] = 0x16;
  1051. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[3] = 0x0d;
  1052. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[4] = 0x00;
  1053. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[5] = 0x00;
  1054. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[6] = 0x00;
  1055. priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[7] = 0x00;
  1056. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[0] = 0x18;
  1057. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[1] = 0x17;
  1058. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[2] = 0x15;
  1059. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[3] = 0x0c;
  1060. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[4] = 0x00;
  1061. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[5] = 0x00;
  1062. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[6] = 0x00;
  1063. priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[7] = 0x00;
  1064. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[0] = 0x17;
  1065. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[1] = 0x16;
  1066. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[2] = 0x13;
  1067. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[3] = 0x0b;
  1068. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[4] = 0x00;
  1069. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[5] = 0x00;
  1070. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[6] = 0x00;
  1071. priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[7] = 0x00;
  1072. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[0] = 0x16;
  1073. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[1] = 0x15;
  1074. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[2] = 0x12;
  1075. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[3] = 0x0b;
  1076. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[4] = 0x00;
  1077. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[5] = 0x00;
  1078. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[6] = 0x00;
  1079. priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[7] = 0x00;
  1080. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[0] = 0x14;
  1081. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[1] = 0x14;
  1082. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[2] = 0x11;
  1083. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[3] = 0x0a;
  1084. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[4] = 0x00;
  1085. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[5] = 0x00;
  1086. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[6] = 0x00;
  1087. priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[7] = 0x00;
  1088. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[0] = 0x13;
  1089. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[1] = 0x13;
  1090. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[2] = 0x10;
  1091. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[3] = 0x0a;
  1092. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[4] = 0x00;
  1093. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[5] = 0x00;
  1094. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[6] = 0x00;
  1095. priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[7] = 0x00;
  1096. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[0] = 0x12;
  1097. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[1] = 0x12;
  1098. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[2] = 0x0f;
  1099. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[3] = 0x09;
  1100. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[4] = 0x00;
  1101. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[5] = 0x00;
  1102. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[6] = 0x00;
  1103. priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[7] = 0x00;
  1104. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[0] = 0x11;
  1105. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[1] = 0x11;
  1106. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[2] = 0x0f;
  1107. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[3] = 0x09;
  1108. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[4] = 0x00;
  1109. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[5] = 0x00;
  1110. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[6] = 0x00;
  1111. priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[7] = 0x00;
  1112. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[0] = 0x10;
  1113. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[1] = 0x10;
  1114. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[2] = 0x0e;
  1115. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[3] = 0x08;
  1116. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[4] = 0x00;
  1117. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[5] = 0x00;
  1118. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[6] = 0x00;
  1119. priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[7] = 0x00;
  1120. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[0] = 0x0f;
  1121. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[1] = 0x0f;
  1122. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[2] = 0x0d;
  1123. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[3] = 0x08;
  1124. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[4] = 0x00;
  1125. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[5] = 0x00;
  1126. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[6] = 0x00;
  1127. priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[7] = 0x00;
  1128. priv->btxpower_tracking = true;
  1129. priv->txpower_count = 0;
  1130. priv->btxpower_trackingInit = false;
  1131. }
  1132. static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
  1133. {
  1134. struct r8192_priv *priv = ieee80211_priv(dev);
  1135. /*
  1136. * Tx Power tracking by Thermal Meter requires Firmware R/W 3-wire. This mechanism
  1137. * can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
  1138. * 3-wire by driver causes RF to go into a wrong state.
  1139. */
  1140. if (priv->ieee80211->FwRWRF)
  1141. priv->btxpower_tracking = true;
  1142. else
  1143. priv->btxpower_tracking = false;
  1144. priv->txpower_count = 0;
  1145. priv->btxpower_trackingInit = false;
  1146. }
  1147. void dm_initialize_txpower_tracking(struct net_device *dev)
  1148. {
  1149. struct r8192_priv *priv = ieee80211_priv(dev);
  1150. if (priv->bDcut)
  1151. dm_InitializeTXPowerTracking_TSSI(dev);
  1152. else
  1153. dm_InitializeTXPowerTracking_ThermalMeter(dev);
  1154. } /* dm_InitializeTXPowerTracking */
  1155. static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
  1156. {
  1157. struct r8192_priv *priv = ieee80211_priv(dev);
  1158. static u32 tx_power_track_counter;
  1159. if (!priv->btxpower_tracking)
  1160. return;
  1161. if ((tx_power_track_counter % 30 == 0) && (tx_power_track_counter != 0))
  1162. queue_delayed_work(priv->priv_wq, &priv->txpower_tracking_wq, 0);
  1163. tx_power_track_counter++;
  1164. }
  1165. static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
  1166. {
  1167. struct r8192_priv *priv = ieee80211_priv(dev);
  1168. static u8 TM_Trigger;
  1169. /*DbgPrint("dm_CheckTXPowerTracking()\n");*/
  1170. if (!priv->btxpower_tracking)
  1171. return;
  1172. if (priv->txpower_count <= 2) {
  1173. priv->txpower_count++;
  1174. return;
  1175. }
  1176. if (!TM_Trigger) {
  1177. /*
  1178. * Attention!! You have to write all 12bits of data to RF, or it may cause RF to crash
  1179. * actually write reg0x02 bit1=0, then bit1=1.
  1180. * DbgPrint("Trigger ThermalMeter, write RF reg0x2 = 0x4d to 0x4f\n");
  1181. */
  1182. rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
  1183. rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
  1184. rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
  1185. rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
  1186. TM_Trigger = 1;
  1187. return;
  1188. }
  1189. /*DbgPrint("Schedule TxPowerTrackingWorkItem\n");*/
  1190. queue_delayed_work(priv->priv_wq, &priv->txpower_tracking_wq, 0);
  1191. TM_Trigger = 0;
  1192. }
  1193. static void dm_check_txpower_tracking(struct net_device *dev)
  1194. {
  1195. struct r8192_priv *priv = ieee80211_priv(dev);
  1196. /*static u32 tx_power_track_counter = 0;*/
  1197. #ifdef RTL8190P
  1198. dm_CheckTXPowerTracking_TSSI(dev);
  1199. #else
  1200. if (priv->bDcut)
  1201. dm_CheckTXPowerTracking_TSSI(dev);
  1202. else
  1203. dm_CheckTXPowerTracking_ThermalMeter(dev);
  1204. #endif
  1205. } /* dm_CheckTXPowerTracking */
  1206. static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
  1207. {
  1208. u32 TempVal;
  1209. struct r8192_priv *priv = ieee80211_priv(dev);
  1210. /* Write 0xa22 0xa23 */
  1211. TempVal = 0;
  1212. if (!bInCH14) {
  1213. /* Write 0xa22 0xa23 */
  1214. TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
  1215. (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8);
  1216. rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
  1217. /* Write 0xa24 ~ 0xa27 */
  1218. TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
  1219. (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
  1220. (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
  1221. (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
  1222. rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
  1223. /* Write 0xa28 0xa29 */
  1224. TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
  1225. (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8);
  1226. rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
  1227. } else {
  1228. TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
  1229. (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8);
  1230. rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
  1231. /* Write 0xa24 ~ 0xa27 */
  1232. TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
  1233. (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
  1234. (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
  1235. (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
  1236. rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
  1237. /* Write 0xa28 0xa29 */
  1238. TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
  1239. (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8);
  1240. rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
  1241. }
  1242. }
  1243. static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH14)
  1244. {
  1245. u32 TempVal;
  1246. struct r8192_priv *priv = ieee80211_priv(dev);
  1247. TempVal = 0;
  1248. if (!bInCH14) {
  1249. /* Write 0xa22 0xa23 */
  1250. TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] +
  1251. (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8);
  1252. rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
  1253. RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
  1254. rCCK0_TxFilter1, TempVal);
  1255. /* Write 0xa24 ~ 0xa27 */
  1256. TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
  1257. (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
  1258. (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16)+
  1259. (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24);
  1260. rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
  1261. RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
  1262. rCCK0_TxFilter2, TempVal);
  1263. /* Write 0xa28 0xa29 */
  1264. TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
  1265. (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8);
  1266. rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
  1267. RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
  1268. rCCK0_DebugPort, TempVal);
  1269. } else {
  1270. /*priv->CCKTxPowerAdjustCntNotCh14++; cosa add for debug.*/
  1271. /* Write 0xa22 0xa23 */
  1272. TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] +
  1273. (CCKSwingTable_Ch14[priv->CCK_index][1]<<8);
  1274. rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
  1275. RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
  1276. rCCK0_TxFilter1, TempVal);
  1277. /* Write 0xa24 ~ 0xa27 */
  1278. TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
  1279. (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
  1280. (CCKSwingTable_Ch14[priv->CCK_index][4]<<16)+
  1281. (CCKSwingTable_Ch14[priv->CCK_index][5]<<24);
  1282. rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
  1283. RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
  1284. rCCK0_TxFilter2, TempVal);
  1285. /* Write 0xa28 0xa29 */
  1286. TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
  1287. (CCKSwingTable_Ch14[priv->CCK_index][7]<<8);
  1288. rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
  1289. RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
  1290. rCCK0_DebugPort, TempVal);
  1291. }
  1292. }
  1293. void dm_cck_txpower_adjust(struct net_device *dev, bool binch14)
  1294. { /* dm_CCKTxPowerAdjust */
  1295. struct r8192_priv *priv = ieee80211_priv(dev);
  1296. if (priv->bDcut)
  1297. dm_CCKTxPowerAdjust_TSSI(dev, binch14);
  1298. else
  1299. dm_CCKTxPowerAdjust_ThermalMeter(dev, binch14);
  1300. }
  1301. #ifndef RTL8192U
  1302. static void dm_txpower_reset_recovery(
  1303. struct net_device *dev
  1304. )
  1305. {
  1306. struct r8192_priv *priv = ieee80211_priv(dev);
  1307. RT_TRACE(COMP_POWER_TRACKING, "Start Reset Recovery ==>\n");
  1308. rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex].txbbgain_value);
  1309. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc80 is %08x\n", priv->txbbgain_table[priv->rfa_txpowertrackingindex].txbbgain_value);
  1310. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in RFA_txPowerTrackingIndex is %x\n", priv->rfa_txpowertrackingindex);
  1311. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery : RF A I/Q Amplify Gain is %ld\n", priv->txbbgain_table[priv->rfa_txpowertrackingindex].txbb_iq_amplifygain);
  1312. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: CCK Attenuation is %d dB\n", priv->cck_present_attentuation);
  1313. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1314. rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex].txbbgain_value);
  1315. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc90 is %08x\n", priv->txbbgain_table[priv->rfc_txpowertrackingindex].txbbgain_value);
  1316. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in RFC_txPowerTrackingIndex is %x\n", priv->rfc_txpowertrackingindex);
  1317. RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery : RF C I/Q Amplify Gain is %ld\n", priv->txbbgain_table[priv->rfc_txpowertrackingindex].txbb_iq_amplifygain);
  1318. } /* dm_TXPowerResetRecovery */
  1319. void dm_restore_dynamic_mechanism_state(struct net_device *dev)
  1320. {
  1321. struct r8192_priv *priv = ieee80211_priv(dev);
  1322. u32 reg_ratr = priv->rate_adaptive.last_ratr;
  1323. if (!priv->up) {
  1324. RT_TRACE(COMP_RATE, "<---- dm_restore_dynamic_mechanism_state(): driver is going to unload\n");
  1325. return;
  1326. }
  1327. /* Restore previous state for rate adaptive */
  1328. if (priv->rate_adaptive.rate_adaptive_disabled)
  1329. return;
  1330. /* TODO: Only 11n mode is implemented currently, */
  1331. if (!(priv->ieee80211->mode == WIRELESS_MODE_N_24G ||
  1332. priv->ieee80211->mode == WIRELESS_MODE_N_5G))
  1333. return;
  1334. {
  1335. /* 2007/11/15 MH Copy from 8190PCI. */
  1336. u32 ratr_value;
  1337. ratr_value = reg_ratr;
  1338. if (priv->rf_type == RF_1T2R) { /* 1T2R, Spatial Stream 2 should be disabled */
  1339. ratr_value &= ~(RATE_ALL_OFDM_2SS);
  1340. /*DbgPrint("HW_VAR_TATR_0 from 0x%x ==> 0x%x\n", ((pu4Byte)(val))[0], ratr_value);*/
  1341. }
  1342. /*DbgPrint("set HW_VAR_TATR_0 = 0x%x\n", ratr_value);*/
  1343. /*cosa PlatformEFIOWrite4Byte(Adapter, RATR0, ((pu4Byte)(val))[0]);*/
  1344. write_nic_dword(dev, RATR0, ratr_value);
  1345. write_nic_byte(dev, UFWP, 1);
  1346. }
  1347. /* Restore TX Power Tracking Index */
  1348. if (priv->btxpower_trackingInit && priv->btxpower_tracking)
  1349. dm_txpower_reset_recovery(dev);
  1350. /* Restore BB Initial Gain */
  1351. dm_bb_initialgain_restore(dev);
  1352. } /* DM_RestoreDynamicMechanismState */
  1353. static void dm_bb_initialgain_restore(struct net_device *dev)
  1354. {
  1355. struct r8192_priv *priv = ieee80211_priv(dev);
  1356. u32 bit_mask = 0x7f; /* Bit0~ Bit6 */
  1357. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
  1358. return;
  1359. /* Disable Initial Gain */
  1360. /*PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);*/
  1361. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); /* Only clear byte 1 and rewrite. */
  1362. rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bit_mask, (u32)priv->initgain_backup.xaagccore1);
  1363. rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bit_mask, (u32)priv->initgain_backup.xbagccore1);
  1364. rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bit_mask, (u32)priv->initgain_backup.xcagccore1);
  1365. rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bit_mask, (u32)priv->initgain_backup.xdagccore1);
  1366. bit_mask = bMaskByte2;
  1367. rtl8192_setBBreg(dev, rCCK0_CCA, bit_mask, (u32)priv->initgain_backup.cca);
  1368. RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc50 is %x\n", priv->initgain_backup.xaagccore1);
  1369. RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc58 is %x\n", priv->initgain_backup.xbagccore1);
  1370. RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc60 is %x\n", priv->initgain_backup.xcagccore1);
  1371. RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc68 is %x\n", priv->initgain_backup.xdagccore1);
  1372. RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xa0a is %x\n", priv->initgain_backup.cca);
  1373. /* Enable Initial Gain */
  1374. /*PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x100);*/
  1375. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); /* Only clear byte 1 and rewrite. */
  1376. } /* dm_BBInitialGainRestore */
  1377. void dm_backup_dynamic_mechanism_state(struct net_device *dev)
  1378. {
  1379. struct r8192_priv *priv = ieee80211_priv(dev);
  1380. /* Fsync to avoid reset */
  1381. priv->bswitch_fsync = false;
  1382. priv->bfsync_processing = false;
  1383. /* Backup BB InitialGain */
  1384. dm_bb_initialgain_backup(dev);
  1385. } /* DM_BackupDynamicMechanismState */
  1386. static void dm_bb_initialgain_backup(struct net_device *dev)
  1387. {
  1388. struct r8192_priv *priv = ieee80211_priv(dev);
  1389. u32 bit_mask = bMaskByte0; /* Bit0~ Bit6 */
  1390. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
  1391. return;
  1392. /*PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);*/
  1393. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); /* Only clear byte 1 and rewrite. */
  1394. priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bit_mask);
  1395. priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bit_mask);
  1396. priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bit_mask);
  1397. priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bit_mask);
  1398. bit_mask = bMaskByte2;
  1399. priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bit_mask);
  1400. RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc50 is %x\n", priv->initgain_backup.xaagccore1);
  1401. RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc58 is %x\n", priv->initgain_backup.xbagccore1);
  1402. RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc60 is %x\n", priv->initgain_backup.xcagccore1);
  1403. RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc68 is %x\n", priv->initgain_backup.xdagccore1);
  1404. RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xa0a is %x\n", priv->initgain_backup.cca);
  1405. } /* dm_BBInitialGainBakcup */
  1406. #endif
  1407. /*-----------------------------------------------------------------------------
  1408. * Function: dm_change_dynamic_initgain_thresh()
  1409. *
  1410. * Overview:
  1411. *
  1412. * Input: NONE
  1413. *
  1414. * Output: NONE
  1415. *
  1416. * Return: NONE
  1417. *
  1418. * Revised History:
  1419. * When Who Remark
  1420. * 05/29/2008 amy Create Version 0 porting from windows code.
  1421. *
  1422. *---------------------------------------------------------------------------*/
  1423. void dm_change_dynamic_initgain_thresh(struct net_device *dev, u32 dm_type,
  1424. u32 dm_value)
  1425. {
  1426. if (dm_type == DIG_TYPE_THRESH_HIGH) {
  1427. dm_digtable.rssi_high_thresh = dm_value;
  1428. } else if (dm_type == DIG_TYPE_THRESH_LOW) {
  1429. dm_digtable.rssi_low_thresh = dm_value;
  1430. } else if (dm_type == DIG_TYPE_THRESH_HIGHPWR_HIGH) {
  1431. dm_digtable.rssi_high_power_highthresh = dm_value;
  1432. } else if (dm_type == DIG_TYPE_THRESH_HIGHPWR_LOW) {
  1433. dm_digtable.rssi_high_power_lowthresh = dm_value;
  1434. } else if (dm_type == DIG_TYPE_ENABLE) {
  1435. dm_digtable.dig_state = DM_STA_DIG_MAX;
  1436. dm_digtable.dig_enable_flag = true;
  1437. } else if (dm_type == DIG_TYPE_DISABLE) {
  1438. dm_digtable.dig_state = DM_STA_DIG_MAX;
  1439. dm_digtable.dig_enable_flag = false;
  1440. } else if (dm_type == DIG_TYPE_DBG_MODE) {
  1441. if (dm_value >= DM_DBG_MAX)
  1442. dm_value = DM_DBG_OFF;
  1443. dm_digtable.dbg_mode = (u8)dm_value;
  1444. } else if (dm_type == DIG_TYPE_RSSI) {
  1445. if (dm_value > 100)
  1446. dm_value = 30;
  1447. dm_digtable.rssi_val = (long)dm_value;
  1448. } else if (dm_type == DIG_TYPE_ALGORITHM) {
  1449. if (dm_value >= DIG_ALGO_MAX)
  1450. dm_value = DIG_ALGO_BY_FALSE_ALARM;
  1451. if (dm_digtable.dig_algorithm != (u8)dm_value)
  1452. dm_digtable.dig_algorithm_switch = 1;
  1453. dm_digtable.dig_algorithm = (u8)dm_value;
  1454. } else if (dm_type == DIG_TYPE_BACKOFF) {
  1455. if (dm_value > 30)
  1456. dm_value = 30;
  1457. dm_digtable.backoff_val = (u8)dm_value;
  1458. } else if (dm_type == DIG_TYPE_RX_GAIN_MIN) {
  1459. if (dm_value == 0)
  1460. dm_value = 0x1;
  1461. dm_digtable.rx_gain_range_min = (u8)dm_value;
  1462. } else if (dm_type == DIG_TYPE_RX_GAIN_MAX) {
  1463. if (dm_value > 0x50)
  1464. dm_value = 0x50;
  1465. dm_digtable.rx_gain_range_max = (u8)dm_value;
  1466. }
  1467. } /* DM_ChangeDynamicInitGainThresh */
  1468. /*-----------------------------------------------------------------------------
  1469. * Function: dm_dig_init()
  1470. *
  1471. * Overview: Set DIG scheme init value.
  1472. *
  1473. * Input: NONE
  1474. *
  1475. * Output: NONE
  1476. *
  1477. * Return: NONE
  1478. *
  1479. * Revised History:
  1480. * When Who Remark
  1481. * 05/15/2008 amy Create Version 0 porting from windows code.
  1482. *
  1483. *---------------------------------------------------------------------------*/
  1484. static void dm_dig_init(struct net_device *dev)
  1485. {
  1486. struct r8192_priv *priv = ieee80211_priv(dev);
  1487. /* 2007/10/05 MH Disable DIG scheme now. Not tested. */
  1488. dm_digtable.dig_enable_flag = true;
  1489. dm_digtable.dig_algorithm = DIG_ALGO_BY_RSSI;
  1490. dm_digtable.dbg_mode = DM_DBG_OFF; /* off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig */
  1491. dm_digtable.dig_algorithm_switch = 0;
  1492. /* 2007/10/04 MH Define init gain threshold. */
  1493. dm_digtable.dig_state = DM_STA_DIG_MAX;
  1494. dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
  1495. dm_digtable.initialgain_lowerbound_state = false;
  1496. dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW;
  1497. dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH;
  1498. dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW;
  1499. dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH;
  1500. dm_digtable.rssi_val = 50; /* for new dig debug rssi value */
  1501. dm_digtable.backoff_val = DM_DIG_BACKOFF;
  1502. dm_digtable.rx_gain_range_max = DM_DIG_MAX;
  1503. if (priv->CustomerID == RT_CID_819x_Netcore)
  1504. dm_digtable.rx_gain_range_min = DM_DIG_MIN_Netcore;
  1505. else
  1506. dm_digtable.rx_gain_range_min = DM_DIG_MIN;
  1507. } /* dm_dig_init */
  1508. /*-----------------------------------------------------------------------------
  1509. * Function: dm_ctrl_initgain_byrssi()
  1510. *
  1511. * Overview: Driver must monitor RSSI and notify firmware to change initial
  1512. * gain according to different threshold. BB team provide the
  1513. * suggested solution.
  1514. *
  1515. * Input: struct net_device *dev
  1516. *
  1517. * Output: NONE
  1518. *
  1519. * Return: NONE
  1520. *
  1521. * Revised History:
  1522. * When Who Remark
  1523. * 05/27/2008 amy Create Version 0 porting from windows code.
  1524. *---------------------------------------------------------------------------*/
  1525. static void dm_ctrl_initgain_byrssi(struct net_device *dev)
  1526. {
  1527. if (!dm_digtable.dig_enable_flag)
  1528. return;
  1529. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
  1530. dm_ctrl_initgain_byrssi_by_fwfalse_alarm(dev);
  1531. else if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
  1532. dm_ctrl_initgain_byrssi_by_driverrssi(dev);
  1533. /* ; */
  1534. else
  1535. return;
  1536. }
  1537. static void dm_ctrl_initgain_byrssi_by_driverrssi(
  1538. struct net_device *dev)
  1539. {
  1540. struct r8192_priv *priv = ieee80211_priv(dev);
  1541. u8 i;
  1542. static u8 fw_dig;
  1543. if (!dm_digtable.dig_enable_flag)
  1544. return;
  1545. /*DbgPrint("Dig by Sw Rssi\n");*/
  1546. if (dm_digtable.dig_algorithm_switch) /* if switched algorithm, we have to disable FW Dig. */
  1547. fw_dig = 0;
  1548. if (fw_dig <= 3) { /* execute several times to make sure the FW Dig is disabled */
  1549. /* FW DIG Off */
  1550. for (i = 0; i < 3; i++)
  1551. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); /* Only clear byte 1 and rewrite. */
  1552. fw_dig++;
  1553. dm_digtable.dig_state = DM_STA_DIG_OFF; /* fw dig off. */
  1554. }
  1555. if (priv->ieee80211->state == IEEE80211_LINKED)
  1556. dm_digtable.cur_connect_state = DIG_CONNECT;
  1557. else
  1558. dm_digtable.cur_connect_state = DIG_DISCONNECT;
  1559. /*DbgPrint("DM_DigTable.PreConnectState = %d, DM_DigTable.CurConnectState = %d\n",
  1560. DM_DigTable.PreConnectState, DM_DigTable.CurConnectState);*/
  1561. if (dm_digtable.dbg_mode == DM_DBG_OFF)
  1562. dm_digtable.rssi_val = priv->undecorated_smoothed_pwdb;
  1563. /*DbgPrint("DM_DigTable.Rssi_val = %d\n", DM_DigTable.Rssi_val);*/
  1564. dm_initial_gain(dev);
  1565. dm_pd_th(dev);
  1566. dm_cs_ratio(dev);
  1567. if (dm_digtable.dig_algorithm_switch)
  1568. dm_digtable.dig_algorithm_switch = 0;
  1569. dm_digtable.pre_connect_state = dm_digtable.cur_connect_state;
  1570. } /* dm_CtrlInitGainByRssi */
  1571. static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
  1572. struct net_device *dev)
  1573. {
  1574. struct r8192_priv *priv = ieee80211_priv(dev);
  1575. static u32 reset_cnt;
  1576. u8 i;
  1577. if (!dm_digtable.dig_enable_flag)
  1578. return;
  1579. if (dm_digtable.dig_algorithm_switch) {
  1580. dm_digtable.dig_state = DM_STA_DIG_MAX;
  1581. /* Fw DIG On. */
  1582. for (i = 0; i < 3; i++)
  1583. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); /* Only clear byte 1 and rewrite.*/
  1584. dm_digtable.dig_algorithm_switch = 0;
  1585. }
  1586. if (priv->ieee80211->state != IEEE80211_LINKED)
  1587. return;
  1588. /* For smooth, we can not change DIG state. */
  1589. if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_low_thresh) &&
  1590. (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_thresh))
  1591. return;
  1592. /*DbgPrint("Dig by Fw False Alarm\n");*/
  1593. /*if (DM_DigTable.Dig_State == DM_STA_DIG_OFF)*/
  1594. /*DbgPrint("DIG Check\n\r RSSI=%d LOW=%d HIGH=%d STATE=%d",
  1595. pHalData->UndecoratedSmoothedPWDB, DM_DigTable.RssiLowThresh,
  1596. DM_DigTable.RssiHighThresh, DM_DigTable.Dig_State);*/
  1597. /* 1. When RSSI decrease, We have to judge if it is smaller than a threshold
  1598. and then execute the step below. */
  1599. if (priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh) {
  1600. /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
  1601. will be reset to init value. We must prevent the condition. */
  1602. if (dm_digtable.dig_state == DM_STA_DIG_OFF &&
  1603. (priv->reset_count == reset_cnt)) {
  1604. return;
  1605. }
  1606. reset_cnt = priv->reset_count;
  1607. /* If DIG is off, DIG high power state must reset. */
  1608. dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
  1609. dm_digtable.dig_state = DM_STA_DIG_OFF;
  1610. /* 1.1 DIG Off. */
  1611. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); /* Only clear byte 1 and rewrite. */
  1612. /* 1.2 Set initial gain. */
  1613. write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x17);
  1614. write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x17);
  1615. write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x17);
  1616. write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x17);
  1617. /* 1.3 Lower PD_TH for OFDM. */
  1618. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1619. /*
  1620. * 2008/01/11 MH 40MHZ 90/92 register are not the same.
  1621. * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
  1622. */
  1623. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
  1624. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1625. write_nic_byte(pAdapter, rOFDM0_RxDetector1, 0x40);
  1626. else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
  1627. else
  1628. PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x40);
  1629. */
  1630. } else
  1631. write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
  1632. /* 1.4 Lower CS ratio for CCK. */
  1633. write_nic_byte(dev, 0xa0a, 0x08);
  1634. /* 1.5 Higher EDCCA. */
  1635. /*PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x325);*/
  1636. return;
  1637. }
  1638. /* 2. When RSSI increase, We have to judge if it is larger than a threshold
  1639. and then execute the step below. */
  1640. if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) {
  1641. u8 reset_flag = 0;
  1642. if (dm_digtable.dig_state == DM_STA_DIG_ON &&
  1643. (priv->reset_count == reset_cnt)) {
  1644. dm_ctrl_initgain_byrssi_highpwr(dev);
  1645. return;
  1646. }
  1647. if (priv->reset_count != reset_cnt)
  1648. reset_flag = 1;
  1649. reset_cnt = priv->reset_count;
  1650. dm_digtable.dig_state = DM_STA_DIG_ON;
  1651. /*DbgPrint("DIG ON\n\r");*/
  1652. /*
  1653. * 2.1 Set initial gain.
  1654. * 2008/02/26 MH SD3-Jerry suggest to prevent dirty environment.
  1655. */
  1656. if (reset_flag == 1) {
  1657. write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x2c);
  1658. write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x2c);
  1659. write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x2c);
  1660. write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x2c);
  1661. } else {
  1662. write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x20);
  1663. write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x20);
  1664. write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x20);
  1665. write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x20);
  1666. }
  1667. /* 2.2 Higher PD_TH for OFDM. */
  1668. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1669. /*
  1670. * 2008/01/11 MH 40MHZ 90/92 register are not the same.
  1671. * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
  1672. */
  1673. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
  1674. /*
  1675. else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1676. write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
  1677. else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
  1678. else
  1679. PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x42);
  1680. */
  1681. } else
  1682. write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
  1683. /* 2.3 Higher CS ratio for CCK. */
  1684. write_nic_byte(dev, 0xa0a, 0xcd);
  1685. /*
  1686. * 2.4 Lower EDCCA.
  1687. * 2008/01/11 MH 90/92 series are the same.
  1688. */
  1689. /*PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x346);*/
  1690. /* 2.5 DIG On. */
  1691. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); /* Only clear byte 1 and rewrite. */
  1692. }
  1693. dm_ctrl_initgain_byrssi_highpwr(dev);
  1694. } /* dm_CtrlInitGainByRssi */
  1695. /*-----------------------------------------------------------------------------
  1696. * Function: dm_ctrl_initgain_byrssi_highpwr()
  1697. *
  1698. * Overview:
  1699. *
  1700. * Input: NONE
  1701. *
  1702. * Output: NONE
  1703. *
  1704. * Return: NONE
  1705. *
  1706. * Revised History:
  1707. * When Who Remark
  1708. * 05/28/2008 amy Create Version 0 porting from windows code.
  1709. *
  1710. *---------------------------------------------------------------------------*/
  1711. static void dm_ctrl_initgain_byrssi_highpwr(
  1712. struct net_device *dev)
  1713. {
  1714. struct r8192_priv *priv = ieee80211_priv(dev);
  1715. static u32 reset_cnt_highpwr;
  1716. /* For smooth, we can not change high power DIG state in the range. */
  1717. if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) &&
  1718. (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_highthresh))
  1719. return;
  1720. /*
  1721. * 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
  1722. * it is larger than a threshold and then execute the step below.
  1723. *
  1724. * 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
  1725. */
  1726. if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_power_highthresh) {
  1727. if (dm_digtable.dig_highpwr_state == DM_STA_DIG_ON &&
  1728. (priv->reset_count == reset_cnt_highpwr))
  1729. return;
  1730. dm_digtable.dig_highpwr_state = DM_STA_DIG_ON;
  1731. /* 3.1 Higher PD_TH for OFDM for high power state. */
  1732. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1733. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10);
  1734. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1735. write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
  1736. */
  1737. } else
  1738. write_nic_byte(dev, rOFDM0_RxDetector1, 0x43);
  1739. } else {
  1740. if (dm_digtable.dig_highpwr_state == DM_STA_DIG_OFF &&
  1741. (priv->reset_count == reset_cnt_highpwr))
  1742. return;
  1743. dm_digtable.dig_highpwr_state = DM_STA_DIG_OFF;
  1744. if (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_lowthresh &&
  1745. priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) {
  1746. /* 3.2 Recover PD_TH for OFDM for normal power region. */
  1747. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1748. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
  1749. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1750. write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
  1751. */
  1752. } else
  1753. write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
  1754. }
  1755. }
  1756. reset_cnt_highpwr = priv->reset_count;
  1757. } /* dm_CtrlInitGainByRssiHighPwr */
  1758. static void dm_initial_gain(
  1759. struct net_device *dev)
  1760. {
  1761. struct r8192_priv *priv = ieee80211_priv(dev);
  1762. u8 initial_gain = 0;
  1763. static u8 initialized, force_write;
  1764. static u32 reset_cnt;
  1765. u8 tmp;
  1766. if (dm_digtable.dig_algorithm_switch) {
  1767. initialized = 0;
  1768. reset_cnt = 0;
  1769. }
  1770. if (dm_digtable.pre_connect_state == dm_digtable.cur_connect_state) {
  1771. if (dm_digtable.cur_connect_state == DIG_CONNECT) {
  1772. if ((dm_digtable.rssi_val+10-dm_digtable.backoff_val) > dm_digtable.rx_gain_range_max)
  1773. dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_max;
  1774. else if ((dm_digtable.rssi_val+10-dm_digtable.backoff_val) < dm_digtable.rx_gain_range_min)
  1775. dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_min;
  1776. else
  1777. dm_digtable.cur_ig_value = dm_digtable.rssi_val+10-dm_digtable.backoff_val;
  1778. } else { /* current state is disconnected */
  1779. if (dm_digtable.cur_ig_value == 0)
  1780. dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
  1781. else
  1782. dm_digtable.cur_ig_value = dm_digtable.pre_ig_value;
  1783. }
  1784. } else { /* disconnected -> connected or connected -> disconnected */
  1785. dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
  1786. dm_digtable.pre_ig_value = 0;
  1787. }
  1788. /*DbgPrint("DM_DigTable.CurIGValue = 0x%x, DM_DigTable.PreIGValue = 0x%x\n", DM_DigTable.CurIGValue, DM_DigTable.PreIGValue);*/
  1789. /* if silent reset happened, we should rewrite the values back */
  1790. if (priv->reset_count != reset_cnt) {
  1791. force_write = 1;
  1792. reset_cnt = priv->reset_count;
  1793. }
  1794. read_nic_byte(dev, rOFDM0_XAAGCCore1, &tmp);
  1795. if (dm_digtable.pre_ig_value != tmp)
  1796. force_write = 1;
  1797. {
  1798. if ((dm_digtable.pre_ig_value != dm_digtable.cur_ig_value)
  1799. || !initialized || force_write) {
  1800. initial_gain = (u8)dm_digtable.cur_ig_value;
  1801. /*DbgPrint("Write initial gain = 0x%x\n", initial_gain);*/
  1802. /* Set initial gain. */
  1803. write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
  1804. write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
  1805. write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
  1806. write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
  1807. dm_digtable.pre_ig_value = dm_digtable.cur_ig_value;
  1808. initialized = 1;
  1809. force_write = 0;
  1810. }
  1811. }
  1812. }
  1813. static void dm_pd_th(
  1814. struct net_device *dev)
  1815. {
  1816. struct r8192_priv *priv = ieee80211_priv(dev);
  1817. static u8 initialized, force_write;
  1818. static u32 reset_cnt;
  1819. if (dm_digtable.dig_algorithm_switch) {
  1820. initialized = 0;
  1821. reset_cnt = 0;
  1822. }
  1823. if (dm_digtable.pre_connect_state == dm_digtable.cur_connect_state) {
  1824. if (dm_digtable.cur_connect_state == DIG_CONNECT) {
  1825. if (dm_digtable.rssi_val >= dm_digtable.rssi_high_power_highthresh)
  1826. dm_digtable.curpd_thstate = DIG_PD_AT_HIGH_POWER;
  1827. else if (dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh)
  1828. dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
  1829. else if ((dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh) &&
  1830. (dm_digtable.rssi_val < dm_digtable.rssi_high_power_lowthresh))
  1831. dm_digtable.curpd_thstate = DIG_PD_AT_NORMAL_POWER;
  1832. else
  1833. dm_digtable.curpd_thstate = dm_digtable.prepd_thstate;
  1834. } else {
  1835. dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
  1836. }
  1837. } else { /* disconnected -> connected or connected -> disconnected */
  1838. dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
  1839. }
  1840. /* if silent reset happened, we should rewrite the values back */
  1841. if (priv->reset_count != reset_cnt) {
  1842. force_write = 1;
  1843. reset_cnt = priv->reset_count;
  1844. }
  1845. {
  1846. if ((dm_digtable.prepd_thstate != dm_digtable.curpd_thstate) ||
  1847. (initialized <= 3) || force_write) {
  1848. /*DbgPrint("Write PD_TH state = %d\n", DM_DigTable.CurPD_THState);*/
  1849. if (dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER) {
  1850. /* Lower PD_TH for OFDM. */
  1851. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1852. /*
  1853. * 2008/01/11 MH 40MHZ 90/92 register are not the same.
  1854. * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
  1855. */
  1856. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
  1857. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1858. write_nic_byte(dev, rOFDM0_RxDetector1, 0x40);
  1859. */
  1860. } else
  1861. write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
  1862. } else if (dm_digtable.curpd_thstate == DIG_PD_AT_NORMAL_POWER) {
  1863. /* Higher PD_TH for OFDM. */
  1864. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1865. /*
  1866. * 2008/01/11 MH 40MHZ 90/92 register are not the same.
  1867. * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
  1868. */
  1869. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
  1870. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1871. write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
  1872. */
  1873. } else
  1874. write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
  1875. } else if (dm_digtable.curpd_thstate == DIG_PD_AT_HIGH_POWER) {
  1876. /* Higher PD_TH for OFDM for high power state. */
  1877. if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
  1878. write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10);
  1879. /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
  1880. write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
  1881. */
  1882. } else
  1883. write_nic_byte(dev, rOFDM0_RxDetector1, 0x43);
  1884. }
  1885. dm_digtable.prepd_thstate = dm_digtable.curpd_thstate;
  1886. if (initialized <= 3)
  1887. initialized++;
  1888. force_write = 0;
  1889. }
  1890. }
  1891. }
  1892. static void dm_cs_ratio(
  1893. struct net_device *dev)
  1894. {
  1895. struct r8192_priv *priv = ieee80211_priv(dev);
  1896. static u8 initialized, force_write;
  1897. static u32 reset_cnt;
  1898. if (dm_digtable.dig_algorithm_switch) {
  1899. initialized = 0;
  1900. reset_cnt = 0;
  1901. }
  1902. if (dm_digtable.pre_connect_state == dm_digtable.cur_connect_state) {
  1903. if (dm_digtable.cur_connect_state == DIG_CONNECT) {
  1904. if (dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh)
  1905. dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
  1906. else if (dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh)
  1907. dm_digtable.curcs_ratio_state = DIG_CS_RATIO_HIGHER;
  1908. else
  1909. dm_digtable.curcs_ratio_state = dm_digtable.precs_ratio_state;
  1910. } else {
  1911. dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
  1912. }
  1913. } else /* disconnected -> connected or connected -> disconnected */
  1914. dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
  1915. /* if silent reset happened, we should rewrite the values back */
  1916. if (priv->reset_count != reset_cnt) {
  1917. force_write = 1;
  1918. reset_cnt = priv->reset_count;
  1919. }
  1920. {
  1921. if ((dm_digtable.precs_ratio_state != dm_digtable.curcs_ratio_state) ||
  1922. !initialized || force_write) {
  1923. /*DbgPrint("Write CS_ratio state = %d\n", DM_DigTable.CurCS_ratioState);*/
  1924. if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_LOWER) {
  1925. /* Lower CS ratio for CCK. */
  1926. write_nic_byte(dev, 0xa0a, 0x08);
  1927. } else if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_HIGHER) {
  1928. /* Higher CS ratio for CCK. */
  1929. write_nic_byte(dev, 0xa0a, 0xcd);
  1930. }
  1931. dm_digtable.precs_ratio_state = dm_digtable.curcs_ratio_state;
  1932. initialized = 1;
  1933. force_write = 0;
  1934. }
  1935. }
  1936. }
  1937. void dm_init_edca_turbo(struct net_device *dev)
  1938. {
  1939. struct r8192_priv *priv = ieee80211_priv(dev);
  1940. priv->bcurrent_turbo_EDCA = false;
  1941. priv->ieee80211->bis_any_nonbepkts = false;
  1942. priv->bis_cur_rdlstate = false;
  1943. } /* dm_init_edca_turbo */
  1944. static void dm_check_edca_turbo(
  1945. struct net_device *dev)
  1946. {
  1947. struct r8192_priv *priv = ieee80211_priv(dev);
  1948. PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
  1949. /*PSTA_QOS pStaQos = pMgntInfo->pStaQos;*/
  1950. /* Keep past Tx/Rx packet count for RT-to-RT EDCA turbo. */
  1951. static unsigned long lastTxOkCnt;
  1952. static unsigned long lastRxOkCnt;
  1953. unsigned long curTxOkCnt = 0;
  1954. unsigned long curRxOkCnt = 0;
  1955. /*
  1956. * Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
  1957. * should follow the settings from QAP. By Bruce, 2007-12-07.
  1958. */
  1959. if (priv->ieee80211->state != IEEE80211_LINKED)
  1960. goto dm_CheckEdcaTurbo_EXIT;
  1961. /* We do not turn on EDCA turbo mode for some AP that has IOT issue */
  1962. if (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_EDCA_TURBO)
  1963. goto dm_CheckEdcaTurbo_EXIT;
  1964. /*printk("========>%s():bis_any_nonbepkts is %d\n", __func__, priv->bis_any_nonbepkts);*/
  1965. /* Check the status for current condition. */
  1966. if (!priv->ieee80211->bis_any_nonbepkts) {
  1967. curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
  1968. curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
  1969. /* For RT-AP, we needs to turn it on when Rx>Tx */
  1970. if (curRxOkCnt > 4*curTxOkCnt) {
  1971. /*printk("%s():curRxOkCnt > 4*curTxOkCnt\n");*/
  1972. if (!priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA) {
  1973. write_nic_dword(dev, EDCAPARA_BE, edca_setting_DL[pHTInfo->IOTPeer]);
  1974. priv->bis_cur_rdlstate = true;
  1975. }
  1976. } else {
  1977. /*printk("%s():curRxOkCnt < 4*curTxOkCnt\n");*/
  1978. if (priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA) {
  1979. write_nic_dword(dev, EDCAPARA_BE, edca_setting_UL[pHTInfo->IOTPeer]);
  1980. priv->bis_cur_rdlstate = false;
  1981. }
  1982. }
  1983. priv->bcurrent_turbo_EDCA = true;
  1984. } else {
  1985. /*
  1986. * Turn Off EDCA turbo here.
  1987. * Restore original EDCA according to the declaration of AP.
  1988. */
  1989. if (priv->bcurrent_turbo_EDCA) {
  1990. {
  1991. u8 u1bAIFS;
  1992. u32 u4bAcParam;
  1993. struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
  1994. u8 mode = priv->ieee80211->mode;
  1995. /* For Each time updating EDCA parameter, reset EDCA turbo mode status. */
  1996. dm_init_edca_turbo(dev);
  1997. u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
  1998. u4bAcParam = (((u32)(qos_parameters->tx_op_limit[0])) << AC_PARAM_TXOP_LIMIT_OFFSET)|
  1999. (((u32)(qos_parameters->cw_max[0])) << AC_PARAM_ECW_MAX_OFFSET)|
  2000. (((u32)(qos_parameters->cw_min[0])) << AC_PARAM_ECW_MIN_OFFSET)|
  2001. ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET);
  2002. /*write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);*/
  2003. write_nic_dword(dev, EDCAPARA_BE, u4bAcParam);
  2004. /*
  2005. * Check ACM bit.
  2006. * If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
  2007. */
  2008. {
  2009. /* TODO: Modified this part and try to set acm control in only 1 IO processing!! */
  2010. PACI_AIFSN pAciAifsn = (PACI_AIFSN)&(qos_parameters->aifs[0]);
  2011. u8 AcmCtrl;
  2012. read_nic_byte(dev, AcmHwCtrl, &AcmCtrl);
  2013. if (pAciAifsn->f.ACM) { /* ACM bit is 1. */
  2014. AcmCtrl |= AcmHw_BeqEn;
  2015. } else { /* ACM bit is 0. */
  2016. AcmCtrl &= (~AcmHw_BeqEn);
  2017. }
  2018. RT_TRACE(COMP_QOS, "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
  2019. write_nic_byte(dev, AcmHwCtrl, AcmCtrl);
  2020. }
  2021. }
  2022. priv->bcurrent_turbo_EDCA = false;
  2023. }
  2024. }
  2025. dm_CheckEdcaTurbo_EXIT:
  2026. /* Set variables for next time. */
  2027. priv->ieee80211->bis_any_nonbepkts = false;
  2028. lastTxOkCnt = priv->stats.txbytesunicast;
  2029. lastRxOkCnt = priv->stats.rxbytesunicast;
  2030. } /* dm_CheckEdcaTurbo */
  2031. static void dm_init_ctstoself(struct net_device *dev)
  2032. {
  2033. struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
  2034. priv->ieee80211->bCTSToSelfEnable = true;
  2035. priv->ieee80211->CTSToSelfTH = CTSToSelfTHVal;
  2036. }
  2037. static void dm_ctstoself(struct net_device *dev)
  2038. {
  2039. struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
  2040. PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
  2041. static unsigned long lastTxOkCnt;
  2042. static unsigned long lastRxOkCnt;
  2043. unsigned long curTxOkCnt = 0;
  2044. unsigned long curRxOkCnt = 0;
  2045. if (priv->ieee80211->bCTSToSelfEnable != true) {
  2046. pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
  2047. return;
  2048. }
  2049. /*
  2050. 1. Uplink
  2051. 2. Linksys350/Linksys300N
  2052. 3. <50 disable, >55 enable
  2053. */
  2054. if (pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) {
  2055. curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
  2056. curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
  2057. if (curRxOkCnt > 4*curTxOkCnt) { /* downlink, disable CTS to self */
  2058. pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
  2059. /*DbgPrint("dm_CTSToSelf() ==> CTS to self disabled -- downlink\n");*/
  2060. } else { /* uplink */
  2061. pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_CTS2SELF;
  2062. }
  2063. lastTxOkCnt = priv->stats.txbytesunicast;
  2064. lastRxOkCnt = priv->stats.rxbytesunicast;
  2065. }
  2066. }
  2067. /*-----------------------------------------------------------------------------
  2068. * Function: dm_check_pbc_gpio()
  2069. *
  2070. * Overview: Check if PBC button is pressed.
  2071. *
  2072. * Input: NONE
  2073. *
  2074. * Output: NONE
  2075. *
  2076. * Return: NONE
  2077. *
  2078. * Revised History:
  2079. * When Who Remark
  2080. * 05/28/2008 amy Create Version 0 porting from windows code.
  2081. *
  2082. *---------------------------------------------------------------------------*/
  2083. static void dm_check_pbc_gpio(struct net_device *dev)
  2084. {
  2085. struct r8192_priv *priv = ieee80211_priv(dev);
  2086. u8 tmp1byte;
  2087. read_nic_byte(dev, GPI, &tmp1byte);
  2088. if (tmp1byte == 0xff)
  2089. return;
  2090. if (tmp1byte & BIT(6) || tmp1byte & BIT(0)) {
  2091. /*
  2092. * Here we only set bPbcPressed to TRUE
  2093. * After trigger PBC, the variable will be set to FALSE
  2094. */
  2095. RT_TRACE(COMP_IO, "CheckPbcGPIO - PBC is pressed\n");
  2096. priv->bpbc_pressed = true;
  2097. }
  2098. }
  2099. /*-----------------------------------------------------------------------------
  2100. * Function: DM_RFPathCheckWorkItemCallBack()
  2101. *
  2102. * Overview: Check if Current RF RX path is enabled
  2103. *
  2104. * Input: NONE
  2105. *
  2106. * Output: NONE
  2107. *
  2108. * Return: NONE
  2109. *
  2110. * Revised History:
  2111. * When Who Remark
  2112. * 01/30/2008 MHC Create Version 0.
  2113. *
  2114. *---------------------------------------------------------------------------*/
  2115. void dm_rf_pathcheck_workitemcallback(struct work_struct *work)
  2116. {
  2117. struct delayed_work *dwork = container_of(work, struct delayed_work, work);
  2118. struct r8192_priv *priv = container_of(dwork, struct r8192_priv, rfpath_check_wq);
  2119. struct net_device *dev = priv->ieee80211->dev;
  2120. /*bool bactually_set = false;*/
  2121. u8 rfpath = 0, i;
  2122. /* 2008/01/30 MH After discussing with SD3 Jerry, 0xc04/0xd04 register will
  2123. always be the same. We only read 0xc04 now. */
  2124. read_nic_byte(dev, 0xc04, &rfpath);
  2125. /* Check Bit 0-3, it means if RF A-D is enabled. */
  2126. for (i = 0; i < RF90_PATH_MAX; i++) {
  2127. if (rfpath & (0x01<<i))
  2128. priv->brfpath_rxenable[i] = true;
  2129. else
  2130. priv->brfpath_rxenable[i] = false;
  2131. }
  2132. if (!DM_RxPathSelTable.Enable)
  2133. return;
  2134. dm_rxpath_sel_byrssi(dev);
  2135. } /* DM_RFPathCheckWorkItemCallBack */
  2136. static void dm_init_rxpath_selection(struct net_device *dev)
  2137. {
  2138. u8 i;
  2139. struct r8192_priv *priv = ieee80211_priv(dev);
  2140. DM_RxPathSelTable.Enable = 1; /* default enabled */
  2141. DM_RxPathSelTable.SS_TH_low = RxPathSelection_SS_TH_low;
  2142. DM_RxPathSelTable.diff_TH = RxPathSelection_diff_TH;
  2143. if (priv->CustomerID == RT_CID_819x_Netcore)
  2144. DM_RxPathSelTable.cck_method = CCK_Rx_Version_2;
  2145. else
  2146. DM_RxPathSelTable.cck_method = CCK_Rx_Version_1;
  2147. DM_RxPathSelTable.DbgMode = DM_DBG_OFF;
  2148. DM_RxPathSelTable.disabledRF = 0;
  2149. for (i = 0; i < 4; i++) {
  2150. DM_RxPathSelTable.rf_rssi[i] = 50;
  2151. DM_RxPathSelTable.cck_pwdb_sta[i] = -64;
  2152. DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
  2153. }
  2154. }
  2155. static void dm_rxpath_sel_byrssi(struct net_device *dev)
  2156. {
  2157. struct r8192_priv *priv = ieee80211_priv(dev);
  2158. u8 i, max_rssi_index = 0, min_rssi_index = 0, sec_rssi_index = 0, rf_num = 0;
  2159. u8 tmp_max_rssi = 0, tmp_min_rssi = 0, tmp_sec_rssi = 0;
  2160. u8 cck_default_Rx = 0x2; /* RF-C */
  2161. u8 cck_optional_Rx = 0x3; /* RF-D */
  2162. long tmp_cck_max_pwdb = 0, tmp_cck_min_pwdb = 0, tmp_cck_sec_pwdb = 0;
  2163. u8 cck_rx_ver2_max_index = 0, cck_rx_ver2_min_index = 0, cck_rx_ver2_sec_index = 0;
  2164. u8 cur_rf_rssi;
  2165. long cur_cck_pwdb;
  2166. static u8 disabled_rf_cnt, cck_Rx_Path_initialized;
  2167. u8 update_cck_rx_path;
  2168. if (priv->rf_type != RF_2T4R)
  2169. return;
  2170. if (!cck_Rx_Path_initialized) {
  2171. read_nic_byte(dev, 0xa07, &DM_RxPathSelTable.cck_Rx_path);
  2172. DM_RxPathSelTable.cck_Rx_path &= 0xf;
  2173. cck_Rx_Path_initialized = 1;
  2174. }
  2175. read_nic_byte(dev, 0xc04, &DM_RxPathSelTable.disabledRF);
  2176. DM_RxPathSelTable.disabledRF = ~DM_RxPathSelTable.disabledRF & 0xf;
  2177. if (priv->ieee80211->mode == WIRELESS_MODE_B) {
  2178. DM_RxPathSelTable.cck_method = CCK_Rx_Version_2; /* pure B mode, fixed cck version2 */
  2179. /*DbgPrint("Pure B mode, use cck rx version2\n");*/
  2180. }
  2181. /* decide max/sec/min rssi index */
  2182. for (i = 0; i < RF90_PATH_MAX; i++) {
  2183. if (!DM_RxPathSelTable.DbgMode)
  2184. DM_RxPathSelTable.rf_rssi[i] = priv->stats.rx_rssi_percentage[i];
  2185. if (priv->brfpath_rxenable[i]) {
  2186. rf_num++;
  2187. cur_rf_rssi = DM_RxPathSelTable.rf_rssi[i];
  2188. if (rf_num == 1) { /* find first enabled rf path and the rssi values */
  2189. /* initialize, set all rssi index to the same one */
  2190. max_rssi_index = min_rssi_index = sec_rssi_index = i;
  2191. tmp_max_rssi = tmp_min_rssi = tmp_sec_rssi = cur_rf_rssi;
  2192. } else if (rf_num == 2) { /* we pick up the max index first, and let sec and min to be the same one */
  2193. if (cur_rf_rssi >= tmp_max_rssi) {
  2194. tmp_max_rssi = cur_rf_rssi;
  2195. max_rssi_index = i;
  2196. } else {
  2197. tmp_sec_rssi = tmp_min_rssi = cur_rf_rssi;
  2198. sec_rssi_index = min_rssi_index = i;
  2199. }
  2200. } else {
  2201. if (cur_rf_rssi > tmp_max_rssi) {
  2202. tmp_sec_rssi = tmp_max_rssi;
  2203. sec_rssi_index = max_rssi_index;
  2204. tmp_max_rssi = cur_rf_rssi;
  2205. max_rssi_index = i;
  2206. } else if (cur_rf_rssi == tmp_max_rssi) { /* let sec and min point to the different index */
  2207. tmp_sec_rssi = cur_rf_rssi;
  2208. sec_rssi_index = i;
  2209. } else if ((cur_rf_rssi < tmp_max_rssi) && (cur_rf_rssi > tmp_sec_rssi)) {
  2210. tmp_sec_rssi = cur_rf_rssi;
  2211. sec_rssi_index = i;
  2212. } else if (cur_rf_rssi == tmp_sec_rssi) {
  2213. if (tmp_sec_rssi == tmp_min_rssi) {
  2214. /* let sec and min point to the different index */
  2215. tmp_sec_rssi = cur_rf_rssi;
  2216. sec_rssi_index = i;
  2217. } else {
  2218. /* This case we don't need to set any index */
  2219. }
  2220. } else if ((cur_rf_rssi < tmp_sec_rssi) && (cur_rf_rssi > tmp_min_rssi)) {
  2221. /* This case we don't need to set any index */
  2222. } else if (cur_rf_rssi == tmp_min_rssi) {
  2223. if (tmp_sec_rssi == tmp_min_rssi) {
  2224. /* let sec and min point to the different index */
  2225. tmp_min_rssi = cur_rf_rssi;
  2226. min_rssi_index = i;
  2227. } else {
  2228. /* This case we don't need to set any index */
  2229. }
  2230. } else if (cur_rf_rssi < tmp_min_rssi) {
  2231. tmp_min_rssi = cur_rf_rssi;
  2232. min_rssi_index = i;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. rf_num = 0;
  2238. /* decide max/sec/min cck pwdb index */
  2239. if (DM_RxPathSelTable.cck_method == CCK_Rx_Version_2) {
  2240. for (i = 0; i < RF90_PATH_MAX; i++) {
  2241. if (priv->brfpath_rxenable[i]) {
  2242. rf_num++;
  2243. cur_cck_pwdb = DM_RxPathSelTable.cck_pwdb_sta[i];
  2244. if (rf_num == 1) { /* find first enabled rf path and the rssi values */
  2245. /* initialize, set all rssi index to the same one */
  2246. cck_rx_ver2_max_index = cck_rx_ver2_min_index = cck_rx_ver2_sec_index = i;
  2247. tmp_cck_max_pwdb = tmp_cck_min_pwdb = tmp_cck_sec_pwdb = cur_cck_pwdb;
  2248. } else if (rf_num == 2) { /* we pick up the max index first, and let sec and min to be the same one */
  2249. if (cur_cck_pwdb >= tmp_cck_max_pwdb) {
  2250. tmp_cck_max_pwdb = cur_cck_pwdb;
  2251. cck_rx_ver2_max_index = i;
  2252. } else {
  2253. tmp_cck_sec_pwdb = tmp_cck_min_pwdb = cur_cck_pwdb;
  2254. cck_rx_ver2_sec_index = cck_rx_ver2_min_index = i;
  2255. }
  2256. } else {
  2257. if (cur_cck_pwdb > tmp_cck_max_pwdb) {
  2258. tmp_cck_sec_pwdb = tmp_cck_max_pwdb;
  2259. cck_rx_ver2_sec_index = cck_rx_ver2_max_index;
  2260. tmp_cck_max_pwdb = cur_cck_pwdb;
  2261. cck_rx_ver2_max_index = i;
  2262. } else if (cur_cck_pwdb == tmp_cck_max_pwdb) {
  2263. /* let sec and min point to the different index */
  2264. tmp_cck_sec_pwdb = cur_cck_pwdb;
  2265. cck_rx_ver2_sec_index = i;
  2266. } else if ((cur_cck_pwdb < tmp_cck_max_pwdb) && (cur_cck_pwdb > tmp_cck_sec_pwdb)) {
  2267. tmp_cck_sec_pwdb = cur_cck_pwdb;
  2268. cck_rx_ver2_sec_index = i;
  2269. } else if (cur_cck_pwdb == tmp_cck_sec_pwdb && tmp_cck_sec_pwdb == tmp_cck_min_pwdb) {
  2270. /* let sec and min point to the different index */
  2271. tmp_cck_sec_pwdb = cur_cck_pwdb;
  2272. cck_rx_ver2_sec_index = i;
  2273. /* otherwise we don't need to set any index */
  2274. } else if ((cur_cck_pwdb < tmp_cck_sec_pwdb) && (cur_cck_pwdb > tmp_cck_min_pwdb)) {
  2275. /* This case we don't need to set any index */
  2276. } else if (cur_cck_pwdb == tmp_cck_min_pwdb && tmp_cck_sec_pwdb == tmp_cck_min_pwdb) {
  2277. /* let sec and min point to the different index */
  2278. tmp_cck_min_pwdb = cur_cck_pwdb;
  2279. cck_rx_ver2_min_index = i;
  2280. /* otherwise we don't need to set any index */
  2281. } else if (cur_cck_pwdb < tmp_cck_min_pwdb) {
  2282. tmp_cck_min_pwdb = cur_cck_pwdb;
  2283. cck_rx_ver2_min_index = i;
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. /*
  2290. * Set CCK Rx path
  2291. * reg0xA07[3:2]=cck default rx path, reg0xa07[1:0]=cck optional rx path.
  2292. */
  2293. update_cck_rx_path = 0;
  2294. if (DM_RxPathSelTable.cck_method == CCK_Rx_Version_2) {
  2295. cck_default_Rx = cck_rx_ver2_max_index;
  2296. cck_optional_Rx = cck_rx_ver2_sec_index;
  2297. if (tmp_cck_max_pwdb != -64)
  2298. update_cck_rx_path = 1;
  2299. }
  2300. if (tmp_min_rssi < DM_RxPathSelTable.SS_TH_low && disabled_rf_cnt < 2) {
  2301. if ((tmp_max_rssi - tmp_min_rssi) >= DM_RxPathSelTable.diff_TH) {
  2302. /* record the enabled rssi threshold */
  2303. DM_RxPathSelTable.rf_enable_rssi_th[min_rssi_index] = tmp_max_rssi+5;
  2304. /* disable the BB Rx path, OFDM */
  2305. rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x1<<min_rssi_index, 0x0); /* 0xc04[3:0] */
  2306. rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x1<<min_rssi_index, 0x0); /* 0xd04[3:0] */
  2307. disabled_rf_cnt++;
  2308. }
  2309. if (DM_RxPathSelTable.cck_method == CCK_Rx_Version_1) {
  2310. cck_default_Rx = max_rssi_index;
  2311. cck_optional_Rx = sec_rssi_index;
  2312. if (tmp_max_rssi)
  2313. update_cck_rx_path = 1;
  2314. }
  2315. }
  2316. if (update_cck_rx_path) {
  2317. DM_RxPathSelTable.cck_Rx_path = (cck_default_Rx<<2)|(cck_optional_Rx);
  2318. rtl8192_setBBreg(dev, rCCK0_AFESetting, 0x0f000000, DM_RxPathSelTable.cck_Rx_path);
  2319. }
  2320. if (DM_RxPathSelTable.disabledRF) {
  2321. for (i = 0; i < 4; i++) {
  2322. if ((DM_RxPathSelTable.disabledRF>>i) & 0x1) { /* disabled rf */
  2323. if (tmp_max_rssi >= DM_RxPathSelTable.rf_enable_rssi_th[i]) {
  2324. /* enable the BB Rx path */
  2325. /*DbgPrint("RF-%d is enabled.\n", 0x1<<i);*/
  2326. rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x1<<i, 0x1); /* 0xc04[3:0] */
  2327. rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x1<<i, 0x1); /* 0xd04[3:0] */
  2328. DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
  2329. disabled_rf_cnt--;
  2330. }
  2331. }
  2332. }
  2333. }
  2334. }
  2335. /*-----------------------------------------------------------------------------
  2336. * Function: dm_check_rx_path_selection()
  2337. *
  2338. * Overview: Call a workitem to check current RXRF path and Rx Path selection by RSSI.
  2339. *
  2340. * Input: NONE
  2341. *
  2342. * Output: NONE
  2343. *
  2344. * Return: NONE
  2345. *
  2346. * Revised History:
  2347. * When Who Remark
  2348. * 05/28/2008 amy Create Version 0 porting from windows code.
  2349. *
  2350. *---------------------------------------------------------------------------*/
  2351. static void dm_check_rx_path_selection(struct net_device *dev)
  2352. {
  2353. struct r8192_priv *priv = ieee80211_priv(dev);
  2354. queue_delayed_work(priv->priv_wq, &priv->rfpath_check_wq, 0);
  2355. } /* dm_CheckRxRFPath */
  2356. static void dm_init_fsync(struct net_device *dev)
  2357. {
  2358. struct r8192_priv *priv = ieee80211_priv(dev);
  2359. priv->ieee80211->fsync_time_interval = 500;
  2360. priv->ieee80211->fsync_rate_bitmap = 0x0f000800;
  2361. priv->ieee80211->fsync_rssi_threshold = 30;
  2362. priv->ieee80211->bfsync_enable = false;
  2363. priv->ieee80211->fsync_multiple_timeinterval = 3;
  2364. priv->ieee80211->fsync_firstdiff_ratethreshold = 100;
  2365. priv->ieee80211->fsync_seconddiff_ratethreshold = 200;
  2366. priv->ieee80211->fsync_state = Default_Fsync;
  2367. priv->framesyncMonitor = 1; /* current default 0xc38 monitor on */
  2368. setup_timer(&priv->fsync_timer, dm_fsync_timer_callback,
  2369. (unsigned long)dev);
  2370. }
  2371. static void dm_deInit_fsync(struct net_device *dev)
  2372. {
  2373. struct r8192_priv *priv = ieee80211_priv(dev);
  2374. del_timer_sync(&priv->fsync_timer);
  2375. }
  2376. void dm_fsync_timer_callback(unsigned long data)
  2377. {
  2378. struct net_device *dev = (struct net_device *)data;
  2379. struct r8192_priv *priv = ieee80211_priv((struct net_device *)data);
  2380. u32 rate_index, rate_count = 0, rate_count_diff = 0;
  2381. bool bSwitchFromCountDiff = false;
  2382. bool bDoubleTimeInterval = false;
  2383. if (priv->ieee80211->state == IEEE80211_LINKED &&
  2384. priv->ieee80211->bfsync_enable &&
  2385. (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC)) {
  2386. /* Count rate 54, MCS [7], [12, 13, 14, 15] */
  2387. u32 rate_bitmap;
  2388. for (rate_index = 0; rate_index <= 27; rate_index++) {
  2389. rate_bitmap = 1 << rate_index;
  2390. if (priv->ieee80211->fsync_rate_bitmap & rate_bitmap)
  2391. rate_count += priv->stats.received_rate_histogram[1][rate_index];
  2392. }
  2393. if (rate_count < priv->rate_record)
  2394. rate_count_diff = 0xffffffff - rate_count + priv->rate_record;
  2395. else
  2396. rate_count_diff = rate_count - priv->rate_record;
  2397. if (rate_count_diff < priv->rateCountDiffRecord) {
  2398. u32 DiffNum = priv->rateCountDiffRecord - rate_count_diff;
  2399. /* Continue count */
  2400. if (DiffNum >= priv->ieee80211->fsync_seconddiff_ratethreshold)
  2401. priv->ContinueDiffCount++;
  2402. else
  2403. priv->ContinueDiffCount = 0;
  2404. /* Continue count over */
  2405. if (priv->ContinueDiffCount >= 2) {
  2406. bSwitchFromCountDiff = true;
  2407. priv->ContinueDiffCount = 0;
  2408. }
  2409. } else {
  2410. /* Stop the continued count */
  2411. priv->ContinueDiffCount = 0;
  2412. }
  2413. /* If Count diff <= FsyncRateCountThreshold */
  2414. if (rate_count_diff <= priv->ieee80211->fsync_firstdiff_ratethreshold) {
  2415. bSwitchFromCountDiff = true;
  2416. priv->ContinueDiffCount = 0;
  2417. }
  2418. priv->rate_record = rate_count;
  2419. priv->rateCountDiffRecord = rate_count_diff;
  2420. RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff, priv->bswitch_fsync);
  2421. /* if we never receive those mcs rate and rssi > 30 % then switch fsyn */
  2422. if (priv->undecorated_smoothed_pwdb > priv->ieee80211->fsync_rssi_threshold && bSwitchFromCountDiff) {
  2423. bDoubleTimeInterval = true;
  2424. priv->bswitch_fsync = !priv->bswitch_fsync;
  2425. if (priv->bswitch_fsync) {
  2426. write_nic_byte(dev, 0xC36, 0x1c);
  2427. write_nic_byte(dev, 0xC3e, 0x90);
  2428. } else {
  2429. write_nic_byte(dev, 0xC36, 0x5c);
  2430. write_nic_byte(dev, 0xC3e, 0x96);
  2431. }
  2432. } else if (priv->undecorated_smoothed_pwdb <= priv->ieee80211->fsync_rssi_threshold) {
  2433. if (priv->bswitch_fsync) {
  2434. priv->bswitch_fsync = false;
  2435. write_nic_byte(dev, 0xC36, 0x5c);
  2436. write_nic_byte(dev, 0xC3e, 0x96);
  2437. }
  2438. }
  2439. if (bDoubleTimeInterval) {
  2440. if (timer_pending(&priv->fsync_timer))
  2441. del_timer_sync(&priv->fsync_timer);
  2442. priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval*priv->ieee80211->fsync_multiple_timeinterval);
  2443. add_timer(&priv->fsync_timer);
  2444. } else {
  2445. if (timer_pending(&priv->fsync_timer))
  2446. del_timer_sync(&priv->fsync_timer);
  2447. priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
  2448. add_timer(&priv->fsync_timer);
  2449. }
  2450. } else {
  2451. /* Let Register return to default value; */
  2452. if (priv->bswitch_fsync) {
  2453. priv->bswitch_fsync = false;
  2454. write_nic_byte(dev, 0xC36, 0x5c);
  2455. write_nic_byte(dev, 0xC3e, 0x96);
  2456. }
  2457. priv->ContinueDiffCount = 0;
  2458. write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
  2459. }
  2460. RT_TRACE(COMP_HALDM, "ContinueDiffCount %d\n", priv->ContinueDiffCount);
  2461. RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff, priv->bswitch_fsync);
  2462. }
  2463. static void dm_StartHWFsync(struct net_device *dev)
  2464. {
  2465. RT_TRACE(COMP_HALDM, "%s\n", __func__);
  2466. write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cf);
  2467. write_nic_byte(dev, 0xc3b, 0x41);
  2468. }
  2469. static void dm_EndSWFsync(struct net_device *dev)
  2470. {
  2471. struct r8192_priv *priv = ieee80211_priv(dev);
  2472. RT_TRACE(COMP_HALDM, "%s\n", __func__);
  2473. del_timer_sync(&(priv->fsync_timer));
  2474. /* Let Register return to default value; */
  2475. if (priv->bswitch_fsync) {
  2476. priv->bswitch_fsync = false;
  2477. write_nic_byte(dev, 0xC36, 0x5c);
  2478. write_nic_byte(dev, 0xC3e, 0x96);
  2479. }
  2480. priv->ContinueDiffCount = 0;
  2481. write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
  2482. }
  2483. static void dm_StartSWFsync(struct net_device *dev)
  2484. {
  2485. struct r8192_priv *priv = ieee80211_priv(dev);
  2486. u32 rateIndex;
  2487. u32 rateBitmap;
  2488. RT_TRACE(COMP_HALDM, "%s\n", __func__);
  2489. /* Initial rate record to zero, start to record. */
  2490. priv->rate_record = 0;
  2491. /* Initialize continue diff count to zero, start to record. */
  2492. priv->ContinueDiffCount = 0;
  2493. priv->rateCountDiffRecord = 0;
  2494. priv->bswitch_fsync = false;
  2495. if (priv->ieee80211->mode == WIRELESS_MODE_N_24G) {
  2496. priv->ieee80211->fsync_firstdiff_ratethreshold = 600;
  2497. priv->ieee80211->fsync_seconddiff_ratethreshold = 0xffff;
  2498. } else {
  2499. priv->ieee80211->fsync_firstdiff_ratethreshold = 200;
  2500. priv->ieee80211->fsync_seconddiff_ratethreshold = 200;
  2501. }
  2502. for (rateIndex = 0; rateIndex <= 27; rateIndex++) {
  2503. rateBitmap = 1 << rateIndex;
  2504. if (priv->ieee80211->fsync_rate_bitmap & rateBitmap)
  2505. priv->rate_record += priv->stats.received_rate_histogram[1][rateIndex];
  2506. }
  2507. if (timer_pending(&priv->fsync_timer))
  2508. del_timer_sync(&priv->fsync_timer);
  2509. priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
  2510. add_timer(&priv->fsync_timer);
  2511. write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cd);
  2512. }
  2513. static void dm_EndHWFsync(struct net_device *dev)
  2514. {
  2515. RT_TRACE(COMP_HALDM, "%s\n", __func__);
  2516. write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
  2517. write_nic_byte(dev, 0xc3b, 0x49);
  2518. }
  2519. void dm_check_fsync(struct net_device *dev)
  2520. {
  2521. #define RegC38_Default 0
  2522. #define RegC38_NonFsync_Other_AP 1
  2523. #define RegC38_Fsync_AP_BCM 2
  2524. struct r8192_priv *priv = ieee80211_priv(dev);
  2525. /*u32 framesyncC34;*/
  2526. static u8 reg_c38_State = RegC38_Default;
  2527. static u32 reset_cnt;
  2528. RT_TRACE(COMP_HALDM, "RSSI %d TimeInterval %d MultipleTimeInterval %d\n", priv->ieee80211->fsync_rssi_threshold, priv->ieee80211->fsync_time_interval, priv->ieee80211->fsync_multiple_timeinterval);
  2529. RT_TRACE(COMP_HALDM, "RateBitmap 0x%x FirstDiffRateThreshold %d SecondDiffRateThreshold %d\n", priv->ieee80211->fsync_rate_bitmap, priv->ieee80211->fsync_firstdiff_ratethreshold, priv->ieee80211->fsync_seconddiff_ratethreshold);
  2530. if (priv->ieee80211->state == IEEE80211_LINKED &&
  2531. (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC)) {
  2532. if (priv->ieee80211->bfsync_enable == 0) {
  2533. switch (priv->ieee80211->fsync_state) {
  2534. case Default_Fsync:
  2535. dm_StartHWFsync(dev);
  2536. priv->ieee80211->fsync_state = HW_Fsync;
  2537. break;
  2538. case SW_Fsync:
  2539. dm_EndSWFsync(dev);
  2540. dm_StartHWFsync(dev);
  2541. priv->ieee80211->fsync_state = HW_Fsync;
  2542. break;
  2543. case HW_Fsync:
  2544. default:
  2545. break;
  2546. }
  2547. } else {
  2548. switch (priv->ieee80211->fsync_state) {
  2549. case Default_Fsync:
  2550. dm_StartSWFsync(dev);
  2551. priv->ieee80211->fsync_state = SW_Fsync;
  2552. break;
  2553. case HW_Fsync:
  2554. dm_EndHWFsync(dev);
  2555. dm_StartSWFsync(dev);
  2556. priv->ieee80211->fsync_state = SW_Fsync;
  2557. break;
  2558. case SW_Fsync:
  2559. default:
  2560. break;
  2561. }
  2562. }
  2563. if (priv->framesyncMonitor) {
  2564. if (reg_c38_State != RegC38_Fsync_AP_BCM) {
  2565. /* For broadcom AP we write different default value */
  2566. write_nic_byte(dev, rOFDM0_RxDetector3, 0x95);
  2567. reg_c38_State = RegC38_Fsync_AP_BCM;
  2568. }
  2569. }
  2570. } else {
  2571. switch (priv->ieee80211->fsync_state) {
  2572. case HW_Fsync:
  2573. dm_EndHWFsync(dev);
  2574. priv->ieee80211->fsync_state = Default_Fsync;
  2575. break;
  2576. case SW_Fsync:
  2577. dm_EndSWFsync(dev);
  2578. priv->ieee80211->fsync_state = Default_Fsync;
  2579. break;
  2580. case Default_Fsync:
  2581. default:
  2582. break;
  2583. }
  2584. if (priv->framesyncMonitor) {
  2585. if (priv->ieee80211->state == IEEE80211_LINKED) {
  2586. if (priv->undecorated_smoothed_pwdb <= RegC38_TH) {
  2587. if (reg_c38_State != RegC38_NonFsync_Other_AP) {
  2588. write_nic_byte(dev, rOFDM0_RxDetector3, 0x90);
  2589. reg_c38_State = RegC38_NonFsync_Other_AP;
  2590. }
  2591. } else if (priv->undecorated_smoothed_pwdb >= (RegC38_TH+5)) {
  2592. if (reg_c38_State) {
  2593. write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
  2594. reg_c38_State = RegC38_Default;
  2595. /*DbgPrint("Fsync is idle, rssi>=40, write 0xc38 = 0x%x\n", pHalData->framesync);*/
  2596. }
  2597. }
  2598. } else {
  2599. if (reg_c38_State) {
  2600. write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
  2601. reg_c38_State = RegC38_Default;
  2602. /*DbgPrint("Fsync is idle, not connected, write 0xc38 = 0x%x\n", pHalData->framesync);*/
  2603. }
  2604. }
  2605. }
  2606. }
  2607. if (priv->framesyncMonitor) {
  2608. if (priv->reset_count != reset_cnt) { /* After silent reset, the reg_c38_State will be returned to default value */
  2609. write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
  2610. reg_c38_State = RegC38_Default;
  2611. reset_cnt = priv->reset_count;
  2612. /*DbgPrint("reg_c38_State = 0 for silent reset.\n");*/
  2613. }
  2614. } else {
  2615. if (reg_c38_State) {
  2616. write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
  2617. reg_c38_State = RegC38_Default;
  2618. /*DbgPrint("framesync no monitor, write 0xc38 = 0x%x\n", pHalData->framesync);*/
  2619. }
  2620. }
  2621. }
  2622. /*-----------------------------------------------------------------------------
  2623. * Function: dm_shadow_init()
  2624. *
  2625. * Overview: Store all NIC MAC/BB register content.
  2626. *
  2627. * Input: NONE
  2628. *
  2629. * Output: NONE
  2630. *
  2631. * Return: NONE
  2632. *
  2633. * Revised History:
  2634. * When Who Remark
  2635. * 05/29/2008 amy Create Version 0 porting from windows code.
  2636. *
  2637. *---------------------------------------------------------------------------*/
  2638. void dm_shadow_init(struct net_device *dev)
  2639. {
  2640. u8 page;
  2641. u16 offset;
  2642. for (page = 0; page < 5; page++)
  2643. for (offset = 0; offset < 256; offset++) {
  2644. read_nic_byte(dev, offset+page*256, &dm_shadow[page][offset]);
  2645. /*DbgPrint("P-%d/O-%02x=%02x\r\n", page, offset, DM_Shadow[page][offset]);*/
  2646. }
  2647. for (page = 8; page < 11; page++)
  2648. for (offset = 0; offset < 256; offset++)
  2649. read_nic_byte(dev, offset+page*256, &dm_shadow[page][offset]);
  2650. for (page = 12; page < 15; page++)
  2651. for (offset = 0; offset < 256; offset++)
  2652. read_nic_byte(dev, offset+page*256, &dm_shadow[page][offset]);
  2653. } /* dm_shadow_init */
  2654. /*---------------------------Define function prototype------------------------*/
  2655. /*-----------------------------------------------------------------------------
  2656. * Function: DM_DynamicTxPower()
  2657. *
  2658. * Overview: Detect Signal strength to control TX Registry
  2659. Tx Power Control For Near/Far Range
  2660. *
  2661. * Input: NONE
  2662. *
  2663. * Output: NONE
  2664. *
  2665. * Return: NONE
  2666. *
  2667. * Revised History:
  2668. * When Who Remark
  2669. * 03/06/2008 Jacken Create Version 0.
  2670. *
  2671. *---------------------------------------------------------------------------*/
  2672. static void dm_init_dynamic_txpower(struct net_device *dev)
  2673. {
  2674. struct r8192_priv *priv = ieee80211_priv(dev);
  2675. /* Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code. */
  2676. priv->ieee80211->bdynamic_txpower_enable = true; /* Default to enable Tx Power Control */
  2677. priv->bLastDTPFlag_High = false;
  2678. priv->bLastDTPFlag_Low = false;
  2679. priv->bDynamicTxHighPower = false;
  2680. priv->bDynamicTxLowPower = false;
  2681. }
  2682. static void dm_dynamic_txpower(struct net_device *dev)
  2683. {
  2684. struct r8192_priv *priv = ieee80211_priv(dev);
  2685. unsigned int txhipower_threshhold = 0;
  2686. unsigned int txlowpower_threshold = 0;
  2687. if (priv->ieee80211->bdynamic_txpower_enable != true) {
  2688. priv->bDynamicTxHighPower = false;
  2689. priv->bDynamicTxLowPower = false;
  2690. return;
  2691. }
  2692. /*printk("priv->ieee80211->current_network.unknown_cap_exist is %d , priv->ieee80211->current_network.broadcom_cap_exist is %d\n", priv->ieee80211->current_network.unknown_cap_exist, priv->ieee80211->current_network.broadcom_cap_exist);*/
  2693. if ((priv->ieee80211->current_network.atheros_cap_exist) && (priv->ieee80211->mode == IEEE_G)) {
  2694. txhipower_threshhold = TX_POWER_ATHEROAP_THRESH_HIGH;
  2695. txlowpower_threshold = TX_POWER_ATHEROAP_THRESH_LOW;
  2696. } else {
  2697. txhipower_threshhold = TX_POWER_NEAR_FIELD_THRESH_HIGH;
  2698. txlowpower_threshold = TX_POWER_NEAR_FIELD_THRESH_LOW;
  2699. }
  2700. /*printk("=======>%s(): txhipower_threshhold is %d, txlowpower_threshold is %d\n", __func__, txhipower_threshhold, txlowpower_threshold);*/
  2701. RT_TRACE(COMP_TXAGC, "priv->undecorated_smoothed_pwdb = %ld\n", priv->undecorated_smoothed_pwdb);
  2702. if (priv->ieee80211->state == IEEE80211_LINKED) {
  2703. if (priv->undecorated_smoothed_pwdb >= txhipower_threshhold) {
  2704. priv->bDynamicTxHighPower = true;
  2705. priv->bDynamicTxLowPower = false;
  2706. } else {
  2707. /* high power state check */
  2708. if (priv->undecorated_smoothed_pwdb < txlowpower_threshold && priv->bDynamicTxHighPower)
  2709. priv->bDynamicTxHighPower = false;
  2710. /* low power state check */
  2711. if (priv->undecorated_smoothed_pwdb < 35)
  2712. priv->bDynamicTxLowPower = true;
  2713. else if (priv->undecorated_smoothed_pwdb >= 40)
  2714. priv->bDynamicTxLowPower = false;
  2715. }
  2716. } else {
  2717. /*pHalData->bTXPowerCtrlforNearFarRange = !pHalData->bTXPowerCtrlforNearFarRange;*/
  2718. priv->bDynamicTxHighPower = false;
  2719. priv->bDynamicTxLowPower = false;
  2720. }
  2721. if ((priv->bDynamicTxHighPower != priv->bLastDTPFlag_High) ||
  2722. (priv->bDynamicTxLowPower != priv->bLastDTPFlag_Low)) {
  2723. RT_TRACE(COMP_TXAGC, "SetTxPowerLevel8190() channel = %d\n", priv->ieee80211->current_network.channel);
  2724. #if defined(RTL8190P) || defined(RTL8192E)
  2725. SetTxPowerLevel8190(Adapter, pHalData->CurrentChannel);
  2726. #endif
  2727. rtl8192_phy_setTxPower(dev, priv->ieee80211->current_network.channel);
  2728. /*pHalData->bStartTxCtrlByTPCNFR = FALSE; Clear th flag of Set TX Power from Sitesurvey*/
  2729. }
  2730. priv->bLastDTPFlag_High = priv->bDynamicTxHighPower;
  2731. priv->bLastDTPFlag_Low = priv->bDynamicTxLowPower;
  2732. } /* dm_dynamic_txpower */
  2733. /* added by vivi, for read tx rate and retrycount */
  2734. static void dm_check_txrateandretrycount(struct net_device *dev)
  2735. {
  2736. struct r8192_priv *priv = ieee80211_priv(dev);
  2737. struct ieee80211_device *ieee = priv->ieee80211;
  2738. /* for 11n tx rate */
  2739. /*priv->stats.CurrentShowTxate = read_nic_byte(dev, Current_Tx_Rate_Reg);*/
  2740. read_nic_byte(dev, Current_Tx_Rate_Reg, &ieee->softmac_stats.CurrentShowTxate);
  2741. /*printk("=============>tx_rate_reg:%x\n", ieee->softmac_stats.CurrentShowTxate);*/
  2742. /* for initial tx rate */
  2743. /*priv->stats.last_packet_rate = read_nic_byte(dev, Initial_Tx_Rate_Reg);*/
  2744. read_nic_byte(dev, Initial_Tx_Rate_Reg, &ieee->softmac_stats.last_packet_rate);
  2745. /* for tx tx retry count */
  2746. /*priv->stats.txretrycount = read_nic_dword(dev, Tx_Retry_Count_Reg);*/
  2747. read_nic_dword(dev, Tx_Retry_Count_Reg, &ieee->softmac_stats.txretrycount);
  2748. }
  2749. static void dm_send_rssi_tofw(struct net_device *dev)
  2750. {
  2751. struct r8192_priv *priv = ieee80211_priv(dev);
  2752. /*
  2753. * If we test chariot, we should stop the TX command ?
  2754. * Because 92E will always silent reset when we send tx command. We use register
  2755. * 0x1e0(byte) to notify driver.
  2756. */
  2757. write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);
  2758. }
  2759. /*---------------------------Define function prototype------------------------*/