r8192U_core.c 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223
  1. /******************************************************************************
  2. * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
  3. * Linux device driver for RTL8192U
  4. *
  5. * Based on the r8187 driver, which is:
  6. * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * The full GNU General Public License is included in this distribution in the
  21. * file called LICENSE.
  22. *
  23. * Contact Information:
  24. * Jerry chuang <wlanfae@realtek.com>
  25. */
  26. #ifndef CONFIG_FORCE_HARD_FLOAT
  27. double __floatsidf(int i)
  28. {
  29. return i;
  30. }
  31. unsigned int __fixunsdfsi(double d)
  32. {
  33. return d;
  34. }
  35. double __adddf3(double a, double b)
  36. {
  37. return a + b;
  38. }
  39. double __addsf3(float a, float b)
  40. {
  41. return a + b;
  42. }
  43. double __subdf3(double a, double b)
  44. {
  45. return a - b;
  46. }
  47. double __extendsfdf2(float a)
  48. {
  49. return a;
  50. }
  51. #endif
  52. #define CONFIG_RTL8192_IO_MAP
  53. #include <linux/uaccess.h>
  54. #include "r8192U_hw.h"
  55. #include "r8192U.h"
  56. #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
  57. #include "r8180_93cx6.h" /* Card EEPROM */
  58. #include "r8192U_wx.h"
  59. #include "r819xU_phy.h"
  60. #include "r819xU_phyreg.h"
  61. #include "r819xU_cmdpkt.h"
  62. #include "r8192U_dm.h"
  63. #include <linux/usb.h>
  64. #include <linux/slab.h>
  65. #include <linux/proc_fs.h>
  66. #include <linux/seq_file.h>
  67. /* FIXME: check if 2.6.7 is ok */
  68. #include "dot11d.h"
  69. /* set here to open your trace code. */
  70. u32 rt_global_debug_component = COMP_DOWN |
  71. COMP_SEC |
  72. COMP_ERR; /* always open err flags on */
  73. #define TOTAL_CAM_ENTRY 32
  74. #define CAM_CONTENT_COUNT 8
  75. static const struct usb_device_id rtl8192_usb_id_tbl[] = {
  76. /* Realtek */
  77. {USB_DEVICE(0x0bda, 0x8709)},
  78. /* Corega */
  79. {USB_DEVICE(0x07aa, 0x0043)},
  80. /* Belkin */
  81. {USB_DEVICE(0x050d, 0x805E)},
  82. /* Sitecom */
  83. {USB_DEVICE(0x0df6, 0x0031)},
  84. /* EnGenius */
  85. {USB_DEVICE(0x1740, 0x9201)},
  86. /* Dlink */
  87. {USB_DEVICE(0x2001, 0x3301)},
  88. /* Zinwell */
  89. {USB_DEVICE(0x5a57, 0x0290)},
  90. /* LG */
  91. {USB_DEVICE(0x043e, 0x7a01)},
  92. {}
  93. };
  94. MODULE_LICENSE("GPL");
  95. MODULE_VERSION("V 1.1");
  96. MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
  97. MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
  98. static char *ifname = "wlan%d";
  99. static int hwwep = 1; /* default use hw. set 0 to use software security */
  100. static int channels = 0x3fff;
  101. module_param(ifname, charp, S_IRUGO | S_IWUSR);
  102. module_param(hwwep, int, S_IRUGO | S_IWUSR);
  103. module_param(channels, int, S_IRUGO | S_IWUSR);
  104. MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
  105. MODULE_PARM_DESC(hwwep, " Try to use hardware security support. ");
  106. MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");
  107. static int rtl8192_usb_probe(struct usb_interface *intf,
  108. const struct usb_device_id *id);
  109. static void rtl8192_usb_disconnect(struct usb_interface *intf);
  110. static struct usb_driver rtl8192_usb_driver = {
  111. .name = RTL819xU_MODULE_NAME, /* Driver name */
  112. .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
  113. .probe = rtl8192_usb_probe, /* probe fn */
  114. .disconnect = rtl8192_usb_disconnect, /* remove fn */
  115. .suspend = NULL, /* PM suspend fn */
  116. .resume = NULL, /* PM resume fn */
  117. };
  118. struct CHANNEL_LIST {
  119. u8 Channel[32];
  120. u8 Len;
  121. };
  122. static struct CHANNEL_LIST ChannelPlan[] = {
  123. /* FCC */
  124. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165}, 24},
  125. /* IC */
  126. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},
  127. /* ETSI */
  128. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21},
  129. /* Spain. Change to ETSI. */
  130. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  131. /* France. Change to ETSI. */
  132. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  133. /* MKK */
  134. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
  135. /* MKK1 */
  136. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
  137. /* Israel. */
  138. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  139. /* For 11a , TELEC */
  140. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
  141. /* MIC */
  142. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
  143. /* For Global Domain. 1-11:active scan, 12-14 passive scan. */
  144. {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}
  145. };
  146. static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
  147. {
  148. int i, max_chan = -1, min_chan = -1;
  149. struct ieee80211_device *ieee = priv->ieee80211;
  150. switch (channel_plan) {
  151. case COUNTRY_CODE_FCC:
  152. case COUNTRY_CODE_IC:
  153. case COUNTRY_CODE_ETSI:
  154. case COUNTRY_CODE_SPAIN:
  155. case COUNTRY_CODE_FRANCE:
  156. case COUNTRY_CODE_MKK:
  157. case COUNTRY_CODE_MKK1:
  158. case COUNTRY_CODE_ISRAEL:
  159. case COUNTRY_CODE_TELEC:
  160. case COUNTRY_CODE_MIC:
  161. Dot11d_Init(ieee);
  162. ieee->bGlobalDomain = false;
  163. /* actually 8225 & 8256 rf chips only support B,G,24N mode */
  164. if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
  165. min_chan = 1;
  166. max_chan = 14;
  167. } else {
  168. RT_TRACE(COMP_ERR,
  169. "unknown rf chip, can't set channel map in function:%s()\n",
  170. __func__);
  171. }
  172. if (ChannelPlan[channel_plan].Len != 0) {
  173. /* Clear old channel map */
  174. memset(GET_DOT11D_INFO(ieee)->channel_map, 0,
  175. sizeof(GET_DOT11D_INFO(ieee)->channel_map));
  176. /* Set new channel map */
  177. for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
  178. if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
  179. break;
  180. GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
  181. }
  182. }
  183. break;
  184. case COUNTRY_CODE_GLOBAL_DOMAIN:
  185. /* this flag enabled to follow 11d country IE setting,
  186. * otherwise, it shall follow global domain settings.
  187. */
  188. GET_DOT11D_INFO(ieee)->bEnabled = 0;
  189. Dot11d_Reset(ieee);
  190. ieee->bGlobalDomain = true;
  191. break;
  192. default:
  193. break;
  194. }
  195. }
  196. static void CamResetAllEntry(struct net_device *dev)
  197. {
  198. u32 ulcommand = 0;
  199. /* In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA
  200. * associate to AP. However, ResetKey is called on
  201. * OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest. In this
  202. * condition, Cam can not be reset because upper layer will not set
  203. * this static key again.
  204. */
  205. ulcommand |= BIT(31) | BIT(30);
  206. write_nic_dword(dev, RWCAM, ulcommand);
  207. }
  208. void write_cam(struct net_device *dev, u8 addr, u32 data)
  209. {
  210. write_nic_dword(dev, WCAMI, data);
  211. write_nic_dword(dev, RWCAM, BIT(31) | BIT(16) | (addr & 0xff));
  212. }
  213. u32 read_cam(struct net_device *dev, u8 addr)
  214. {
  215. u32 data;
  216. write_nic_dword(dev, RWCAM, 0x80000000 | (addr & 0xff));
  217. read_nic_dword(dev, 0xa8, &data);
  218. return data;
  219. }
  220. void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
  221. {
  222. int status;
  223. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  224. struct usb_device *udev = priv->udev;
  225. u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
  226. if (!usbdata)
  227. return;
  228. *usbdata = data;
  229. status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  230. RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
  231. indx | 0xfe00, 0, usbdata, 1, HZ / 2);
  232. kfree(usbdata);
  233. if (status < 0)
  234. netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
  235. status);
  236. }
  237. int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
  238. {
  239. int status;
  240. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  241. struct usb_device *udev = priv->udev;
  242. u8 *usbdata = kzalloc(sizeof(u8), GFP_KERNEL);
  243. if (!usbdata)
  244. return -ENOMEM;
  245. status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  246. RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
  247. indx | 0xfe00, 0, usbdata, 1, HZ / 2);
  248. *data = *usbdata;
  249. kfree(usbdata);
  250. if (status < 0) {
  251. netdev_err(dev, "%s failure status: %d\n", __func__, status);
  252. return status;
  253. }
  254. return 0;
  255. }
  256. /* as 92U has extend page from 4 to 16, so modify functions below. */
  257. void write_nic_byte(struct net_device *dev, int indx, u8 data)
  258. {
  259. int status;
  260. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  261. struct usb_device *udev = priv->udev;
  262. u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
  263. if (!usbdata)
  264. return;
  265. *usbdata = data;
  266. status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  267. RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
  268. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  269. usbdata, 1, HZ / 2);
  270. kfree(usbdata);
  271. if (status < 0)
  272. netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
  273. }
  274. void write_nic_word(struct net_device *dev, int indx, u16 data)
  275. {
  276. int status;
  277. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  278. struct usb_device *udev = priv->udev;
  279. u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
  280. if (!usbdata)
  281. return;
  282. *usbdata = data;
  283. status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  284. RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
  285. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  286. usbdata, 2, HZ / 2);
  287. kfree(usbdata);
  288. if (status < 0)
  289. netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
  290. }
  291. void write_nic_dword(struct net_device *dev, int indx, u32 data)
  292. {
  293. int status;
  294. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  295. struct usb_device *udev = priv->udev;
  296. u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
  297. if (!usbdata)
  298. return;
  299. *usbdata = data;
  300. status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  301. RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
  302. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  303. usbdata, 4, HZ / 2);
  304. kfree(usbdata);
  305. if (status < 0)
  306. netdev_err(dev, "write_nic_dword TimeOut! status: %d\n",
  307. status);
  308. }
  309. int read_nic_byte(struct net_device *dev, int indx, u8 *data)
  310. {
  311. int status;
  312. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  313. struct usb_device *udev = priv->udev;
  314. u8 *usbdata = kzalloc(sizeof(u8), GFP_KERNEL);
  315. if (!usbdata)
  316. return -ENOMEM;
  317. status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  318. RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
  319. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  320. usbdata, 1, HZ / 2);
  321. *data = *usbdata;
  322. kfree(usbdata);
  323. if (status < 0) {
  324. netdev_err(dev, "%s failure status: %d\n", __func__, status);
  325. return status;
  326. }
  327. return 0;
  328. }
  329. int read_nic_word(struct net_device *dev, int indx, u16 *data)
  330. {
  331. int status;
  332. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  333. struct usb_device *udev = priv->udev;
  334. u16 *usbdata = kzalloc(sizeof(u16), GFP_KERNEL);
  335. if (!usbdata)
  336. return -ENOMEM;
  337. status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  338. RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
  339. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  340. usbdata, 2, HZ / 2);
  341. *data = *usbdata;
  342. kfree(usbdata);
  343. if (status < 0) {
  344. netdev_err(dev, "%s failure status: %d\n", __func__, status);
  345. return status;
  346. }
  347. return 0;
  348. }
  349. static int read_nic_word_E(struct net_device *dev, int indx, u16 *data)
  350. {
  351. int status;
  352. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  353. struct usb_device *udev = priv->udev;
  354. u16 *usbdata = kzalloc(sizeof(u16), GFP_KERNEL);
  355. if (!usbdata)
  356. return -ENOMEM;
  357. status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  358. RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
  359. indx | 0xfe00, 0, usbdata, 2, HZ / 2);
  360. *data = *usbdata;
  361. kfree(usbdata);
  362. if (status < 0) {
  363. netdev_err(dev, "%s failure status: %d\n", __func__, status);
  364. return status;
  365. }
  366. return 0;
  367. }
  368. int read_nic_dword(struct net_device *dev, int indx, u32 *data)
  369. {
  370. int status;
  371. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  372. struct usb_device *udev = priv->udev;
  373. u32 *usbdata = kzalloc(sizeof(u32), GFP_KERNEL);
  374. if (!usbdata)
  375. return -ENOMEM;
  376. status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  377. RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
  378. (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
  379. usbdata, 4, HZ / 2);
  380. *data = *usbdata;
  381. kfree(usbdata);
  382. if (status < 0) {
  383. netdev_err(dev, "%s failure status: %d\n", __func__, status);
  384. return status;
  385. }
  386. return 0;
  387. }
  388. /* u8 read_phy_cck(struct net_device *dev, u8 adr); */
  389. /* u8 read_phy_ofdm(struct net_device *dev, u8 adr); */
  390. /* this might still called in what was the PHY rtl8185/rtl8192 common code
  391. * plans are to possibility turn it again in one common code...
  392. */
  393. inline void force_pci_posting(struct net_device *dev)
  394. {
  395. }
  396. static struct net_device_stats *rtl8192_stats(struct net_device *dev);
  397. static void rtl8192_restart(struct work_struct *work);
  398. static void watch_dog_timer_callback(unsigned long data);
  399. /****************************************************************************
  400. * -----------------------------PROCFS STUFF-------------------------
  401. *****************************************************************************
  402. */
  403. static struct proc_dir_entry *rtl8192_proc;
  404. static int proc_get_stats_ap(struct seq_file *m, void *v)
  405. {
  406. struct net_device *dev = m->private;
  407. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  408. struct ieee80211_device *ieee = priv->ieee80211;
  409. struct ieee80211_network *target;
  410. list_for_each_entry(target, &ieee->network_list, list) {
  411. const char *wpa = "non_WPA";
  412. if (target->wpa_ie_len > 0 || target->rsn_ie_len > 0)
  413. wpa = "WPA";
  414. seq_printf(m, "%s %s\n", target->ssid, wpa);
  415. }
  416. return 0;
  417. }
  418. static int proc_get_registers(struct seq_file *m, void *v)
  419. {
  420. struct net_device *dev = m->private;
  421. int i, n, max = 0xff;
  422. u8 byte_rd;
  423. seq_puts(m, "\n####################page 0##################\n ");
  424. for (n = 0; n <= max;) {
  425. seq_printf(m, "\nD: %2x > ", n);
  426. for (i = 0; i < 16 && n <= max; i++, n++) {
  427. read_nic_byte(dev, 0x000 | n, &byte_rd);
  428. seq_printf(m, "%2x ", byte_rd);
  429. }
  430. }
  431. seq_puts(m, "\n####################page 1##################\n ");
  432. for (n = 0; n <= max;) {
  433. seq_printf(m, "\nD: %2x > ", n);
  434. for (i = 0; i < 16 && n <= max; i++, n++) {
  435. read_nic_byte(dev, 0x100 | n, &byte_rd);
  436. seq_printf(m, "%2x ", byte_rd);
  437. }
  438. }
  439. seq_puts(m, "\n####################page 3##################\n ");
  440. for (n = 0; n <= max;) {
  441. seq_printf(m, "\nD: %2x > ", n);
  442. for (i = 0; i < 16 && n <= max; i++, n++) {
  443. read_nic_byte(dev, 0x300 | n, &byte_rd);
  444. seq_printf(m, "%2x ", byte_rd);
  445. }
  446. }
  447. seq_putc(m, '\n');
  448. return 0;
  449. }
  450. static int proc_get_stats_tx(struct seq_file *m, void *v)
  451. {
  452. struct net_device *dev = m->private;
  453. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  454. seq_printf(m,
  455. "TX VI priority ok int: %lu\n"
  456. "TX VI priority error int: %lu\n"
  457. "TX VO priority ok int: %lu\n"
  458. "TX VO priority error int: %lu\n"
  459. "TX BE priority ok int: %lu\n"
  460. "TX BE priority error int: %lu\n"
  461. "TX BK priority ok int: %lu\n"
  462. "TX BK priority error int: %lu\n"
  463. "TX MANAGE priority ok int: %lu\n"
  464. "TX MANAGE priority error int: %lu\n"
  465. "TX BEACON priority ok int: %lu\n"
  466. "TX BEACON priority error int: %lu\n"
  467. "TX queue resume: %lu\n"
  468. "TX queue stopped?: %d\n"
  469. "TX fifo overflow: %lu\n"
  470. "TX VI queue: %d\n"
  471. "TX VO queue: %d\n"
  472. "TX BE queue: %d\n"
  473. "TX BK queue: %d\n"
  474. "TX VI dropped: %lu\n"
  475. "TX VO dropped: %lu\n"
  476. "TX BE dropped: %lu\n"
  477. "TX BK dropped: %lu\n"
  478. "TX total data packets %lu\n",
  479. priv->stats.txviokint,
  480. priv->stats.txvierr,
  481. priv->stats.txvookint,
  482. priv->stats.txvoerr,
  483. priv->stats.txbeokint,
  484. priv->stats.txbeerr,
  485. priv->stats.txbkokint,
  486. priv->stats.txbkerr,
  487. priv->stats.txmanageokint,
  488. priv->stats.txmanageerr,
  489. priv->stats.txbeaconokint,
  490. priv->stats.txbeaconerr,
  491. priv->stats.txresumed,
  492. netif_queue_stopped(dev),
  493. priv->stats.txoverflow,
  494. atomic_read(&(priv->tx_pending[VI_PRIORITY])),
  495. atomic_read(&(priv->tx_pending[VO_PRIORITY])),
  496. atomic_read(&(priv->tx_pending[BE_PRIORITY])),
  497. atomic_read(&(priv->tx_pending[BK_PRIORITY])),
  498. priv->stats.txvidrop,
  499. priv->stats.txvodrop,
  500. priv->stats.txbedrop,
  501. priv->stats.txbkdrop,
  502. priv->stats.txdatapkt
  503. );
  504. return 0;
  505. }
  506. static int proc_get_stats_rx(struct seq_file *m, void *v)
  507. {
  508. struct net_device *dev = m->private;
  509. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  510. seq_printf(m,
  511. "RX packets: %lu\n"
  512. "RX urb status error: %lu\n"
  513. "RX invalid urb error: %lu\n",
  514. priv->stats.rxoktotal,
  515. priv->stats.rxstaterr,
  516. priv->stats.rxurberr);
  517. return 0;
  518. }
  519. static void rtl8192_proc_module_init(void)
  520. {
  521. RT_TRACE(COMP_INIT, "Initializing proc filesystem");
  522. rtl8192_proc = proc_mkdir(RTL819xU_MODULE_NAME, init_net.proc_net);
  523. }
  524. /*
  525. * seq_file wrappers for procfile show routines.
  526. */
  527. static int rtl8192_proc_open(struct inode *inode, struct file *file)
  528. {
  529. struct net_device *dev = proc_get_parent_data(inode);
  530. int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
  531. return single_open(file, show, dev);
  532. }
  533. static const struct file_operations rtl8192_proc_fops = {
  534. .open = rtl8192_proc_open,
  535. .read = seq_read,
  536. .llseek = seq_lseek,
  537. .release = single_release,
  538. };
  539. /*
  540. * Table of proc files we need to create.
  541. */
  542. struct rtl8192_proc_file {
  543. char name[12];
  544. int (*show)(struct seq_file *, void *);
  545. };
  546. static const struct rtl8192_proc_file rtl8192_proc_files[] = {
  547. { "stats-rx", &proc_get_stats_rx },
  548. { "stats-tx", &proc_get_stats_tx },
  549. { "stats-ap", &proc_get_stats_ap },
  550. { "registers", &proc_get_registers },
  551. { "" }
  552. };
  553. static void rtl8192_proc_init_one(struct net_device *dev)
  554. {
  555. const struct rtl8192_proc_file *f;
  556. struct proc_dir_entry *dir;
  557. if (rtl8192_proc) {
  558. dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
  559. if (!dir) {
  560. RT_TRACE(COMP_ERR,
  561. "Unable to initialize /proc/net/rtl8192/%s\n",
  562. dev->name);
  563. return;
  564. }
  565. for (f = rtl8192_proc_files; f->name[0]; f++) {
  566. if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
  567. &rtl8192_proc_fops, f->show)) {
  568. RT_TRACE(COMP_ERR,
  569. "Unable to initialize /proc/net/rtl8192/%s/%s\n",
  570. dev->name, f->name);
  571. return;
  572. }
  573. }
  574. }
  575. }
  576. static void rtl8192_proc_remove_one(struct net_device *dev)
  577. {
  578. remove_proc_subtree(dev->name, rtl8192_proc);
  579. }
  580. /****************************************************************************
  581. -----------------------------MISC STUFF-------------------------
  582. *****************************************************************************/
  583. short check_nic_enough_desc(struct net_device *dev, int queue_index)
  584. {
  585. struct r8192_priv *priv = ieee80211_priv(dev);
  586. int used = atomic_read(&priv->tx_pending[queue_index]);
  587. return (used < MAX_TX_URB);
  588. }
  589. static void tx_timeout(struct net_device *dev)
  590. {
  591. struct r8192_priv *priv = ieee80211_priv(dev);
  592. schedule_work(&priv->reset_wq);
  593. }
  594. void rtl8192_update_msr(struct net_device *dev)
  595. {
  596. struct r8192_priv *priv = ieee80211_priv(dev);
  597. u8 msr;
  598. read_nic_byte(dev, MSR, &msr);
  599. msr &= ~MSR_LINK_MASK;
  600. /* do not change in link_state != WLAN_LINK_ASSOCIATED.
  601. * msr must be updated if the state is ASSOCIATING.
  602. * this is intentional and make sense for ad-hoc and
  603. * master (see the create BSS/IBSS func)
  604. */
  605. if (priv->ieee80211->state == IEEE80211_LINKED) {
  606. if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
  607. msr |= (MSR_LINK_MANAGED << MSR_LINK_SHIFT);
  608. else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
  609. msr |= (MSR_LINK_ADHOC << MSR_LINK_SHIFT);
  610. else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
  611. msr |= (MSR_LINK_MASTER << MSR_LINK_SHIFT);
  612. } else {
  613. msr |= (MSR_LINK_NONE << MSR_LINK_SHIFT);
  614. }
  615. write_nic_byte(dev, MSR, msr);
  616. }
  617. void rtl8192_set_chan(struct net_device *dev, short ch)
  618. {
  619. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  620. RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
  621. priv->chan = ch;
  622. /* this hack should avoid frame TX during channel setting*/
  623. /* need to implement rf set channel here */
  624. if (priv->rf_set_chan)
  625. priv->rf_set_chan(dev, priv->chan);
  626. mdelay(10);
  627. }
  628. static void rtl8192_rx_isr(struct urb *urb);
  629. static u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
  630. {
  631. return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
  632. + pstats->RxBufShift);
  633. }
  634. static int rtl8192_rx_initiate(struct net_device *dev)
  635. {
  636. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  637. struct urb *entry;
  638. struct sk_buff *skb;
  639. struct rtl8192_rx_info *info;
  640. /* nomal packet rx procedure */
  641. while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB) {
  642. skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
  643. if (!skb)
  644. break;
  645. entry = usb_alloc_urb(0, GFP_KERNEL);
  646. if (!entry) {
  647. kfree_skb(skb);
  648. break;
  649. }
  650. usb_fill_bulk_urb(entry, priv->udev,
  651. usb_rcvbulkpipe(priv->udev, 3),
  652. skb_tail_pointer(skb),
  653. RX_URB_SIZE, rtl8192_rx_isr, skb);
  654. info = (struct rtl8192_rx_info *)skb->cb;
  655. info->urb = entry;
  656. info->dev = dev;
  657. info->out_pipe = 3; /* denote rx normal packet queue */
  658. skb_queue_tail(&priv->rx_queue, skb);
  659. usb_submit_urb(entry, GFP_KERNEL);
  660. }
  661. /* command packet rx procedure */
  662. while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
  663. skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
  664. if (!skb)
  665. break;
  666. entry = usb_alloc_urb(0, GFP_KERNEL);
  667. if (!entry) {
  668. kfree_skb(skb);
  669. break;
  670. }
  671. usb_fill_bulk_urb(entry, priv->udev,
  672. usb_rcvbulkpipe(priv->udev, 9),
  673. skb_tail_pointer(skb),
  674. RX_URB_SIZE, rtl8192_rx_isr, skb);
  675. info = (struct rtl8192_rx_info *)skb->cb;
  676. info->urb = entry;
  677. info->dev = dev;
  678. info->out_pipe = 9; /* denote rx cmd packet queue */
  679. skb_queue_tail(&priv->rx_queue, skb);
  680. usb_submit_urb(entry, GFP_KERNEL);
  681. }
  682. return 0;
  683. }
  684. void rtl8192_set_rxconf(struct net_device *dev)
  685. {
  686. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  687. u32 rxconf;
  688. read_nic_dword(dev, RCR, &rxconf);
  689. rxconf = rxconf & ~MAC_FILTER_MASK;
  690. rxconf = rxconf | RCR_AMF;
  691. rxconf = rxconf | RCR_ADF;
  692. rxconf = rxconf | RCR_AB;
  693. rxconf = rxconf | RCR_AM;
  694. if (dev->flags & IFF_PROMISC)
  695. DMESG("NIC in promisc mode");
  696. if (priv->ieee80211->iw_mode == IW_MODE_MONITOR ||
  697. dev->flags & IFF_PROMISC) {
  698. rxconf = rxconf | RCR_AAP;
  699. } else {
  700. rxconf = rxconf | RCR_APM;
  701. rxconf = rxconf | RCR_CBSSID;
  702. }
  703. if (priv->ieee80211->iw_mode == IW_MODE_MONITOR) {
  704. rxconf = rxconf | RCR_AICV;
  705. rxconf = rxconf | RCR_APWRMGT;
  706. }
  707. if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
  708. rxconf = rxconf | RCR_ACRC32;
  709. rxconf = rxconf & ~RX_FIFO_THRESHOLD_MASK;
  710. rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE << RX_FIFO_THRESHOLD_SHIFT);
  711. rxconf = rxconf & ~MAX_RX_DMA_MASK;
  712. rxconf = rxconf | ((u32)7 << RCR_MXDMA_OFFSET);
  713. rxconf = rxconf | RCR_ONLYERLPKT;
  714. write_nic_dword(dev, RCR, rxconf);
  715. }
  716. /* wait to be removed */
  717. void rtl8192_rx_enable(struct net_device *dev)
  718. {
  719. rtl8192_rx_initiate(dev);
  720. }
  721. void rtl8192_tx_enable(struct net_device *dev)
  722. {
  723. }
  724. void rtl8192_rtx_disable(struct net_device *dev)
  725. {
  726. u8 cmd;
  727. struct r8192_priv *priv = ieee80211_priv(dev);
  728. struct sk_buff *skb;
  729. struct rtl8192_rx_info *info;
  730. read_nic_byte(dev, CMDR, &cmd);
  731. write_nic_byte(dev, CMDR, cmd & ~(CR_TE | CR_RE));
  732. force_pci_posting(dev);
  733. mdelay(10);
  734. while ((skb = __skb_dequeue(&priv->rx_queue))) {
  735. info = (struct rtl8192_rx_info *)skb->cb;
  736. if (!info->urb)
  737. continue;
  738. usb_kill_urb(info->urb);
  739. kfree_skb(skb);
  740. }
  741. if (skb_queue_len(&priv->skb_queue))
  742. netdev_warn(dev, "skb_queue not empty\n");
  743. skb_queue_purge(&priv->skb_queue);
  744. }
  745. inline u16 ieeerate2rtlrate(int rate)
  746. {
  747. switch (rate) {
  748. case 10:
  749. return 0;
  750. case 20:
  751. return 1;
  752. case 55:
  753. return 2;
  754. case 110:
  755. return 3;
  756. case 60:
  757. return 4;
  758. case 90:
  759. return 5;
  760. case 120:
  761. return 6;
  762. case 180:
  763. return 7;
  764. case 240:
  765. return 8;
  766. case 360:
  767. return 9;
  768. case 480:
  769. return 10;
  770. case 540:
  771. return 11;
  772. default:
  773. return 3;
  774. }
  775. }
  776. static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
  777. inline u16 rtl8192_rate2rate(short rate)
  778. {
  779. if (rate > 11)
  780. return 0;
  781. return rtl_rate[rate];
  782. }
  783. /* The prototype of rx_isr has changed since one version of Linux Kernel */
  784. static void rtl8192_rx_isr(struct urb *urb)
  785. {
  786. struct sk_buff *skb = (struct sk_buff *)urb->context;
  787. struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
  788. struct net_device *dev = info->dev;
  789. struct r8192_priv *priv = ieee80211_priv(dev);
  790. int out_pipe = info->out_pipe;
  791. int err;
  792. if (!priv->up)
  793. return;
  794. if (unlikely(urb->status)) {
  795. info->urb = NULL;
  796. priv->stats.rxstaterr++;
  797. priv->ieee80211->stats.rx_errors++;
  798. usb_free_urb(urb);
  799. return;
  800. }
  801. skb_unlink(skb, &priv->rx_queue);
  802. skb_put(skb, urb->actual_length);
  803. skb_queue_tail(&priv->skb_queue, skb);
  804. tasklet_schedule(&priv->irq_rx_tasklet);
  805. skb = dev_alloc_skb(RX_URB_SIZE);
  806. if (unlikely(!skb)) {
  807. usb_free_urb(urb);
  808. netdev_err(dev, "%s(): can't alloc skb\n", __func__);
  809. /* TODO check rx queue length and refill *somewhere* */
  810. return;
  811. }
  812. usb_fill_bulk_urb(urb, priv->udev,
  813. usb_rcvbulkpipe(priv->udev, out_pipe),
  814. skb_tail_pointer(skb),
  815. RX_URB_SIZE, rtl8192_rx_isr, skb);
  816. info = (struct rtl8192_rx_info *)skb->cb;
  817. info->urb = urb;
  818. info->dev = dev;
  819. info->out_pipe = out_pipe;
  820. urb->transfer_buffer = skb_tail_pointer(skb);
  821. urb->context = skb;
  822. skb_queue_tail(&priv->rx_queue, skb);
  823. err = usb_submit_urb(urb, GFP_ATOMIC);
  824. if (err && err != EPERM)
  825. netdev_err(dev,
  826. "can not submit rxurb, err is %x, URB status is %x\n",
  827. err, urb->status);
  828. }
  829. static u32 rtl819xusb_rx_command_packet(struct net_device *dev,
  830. struct ieee80211_rx_stats *pstats)
  831. {
  832. u32 status;
  833. status = cmpk_message_handle_rx(dev, pstats);
  834. if (status)
  835. DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
  836. return status;
  837. }
  838. static void rtl8192_data_hard_stop(struct net_device *dev)
  839. {
  840. /* FIXME !! */
  841. }
  842. static void rtl8192_data_hard_resume(struct net_device *dev)
  843. {
  844. /* FIXME !! */
  845. }
  846. /* this function TX data frames when the ieee80211 stack requires this.
  847. * It checks also if we need to stop the ieee tx queue, eventually do it
  848. */
  849. static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
  850. int rate)
  851. {
  852. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  853. int ret;
  854. unsigned long flags;
  855. cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  856. u8 queue_index = tcb_desc->queue_index;
  857. /* shall not be referred by command packet */
  858. RTL8192U_ASSERT(queue_index != TXCMD_QUEUE);
  859. spin_lock_irqsave(&priv->tx_lock, flags);
  860. memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
  861. tcb_desc->bTxEnableFwCalcDur = 1;
  862. skb_push(skb, priv->ieee80211->tx_headroom);
  863. ret = rtl8192_tx(dev, skb);
  864. spin_unlock_irqrestore(&priv->tx_lock, flags);
  865. }
  866. /* This is a rough attempt to TX a frame
  867. * This is called by the ieee 80211 stack to TX management frames.
  868. * If the ring is full packet are dropped (for data frame the queue
  869. * is stopped before this can happen).
  870. */
  871. static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  872. {
  873. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  874. int ret;
  875. unsigned long flags;
  876. cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  877. u8 queue_index = tcb_desc->queue_index;
  878. spin_lock_irqsave(&priv->tx_lock, flags);
  879. memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
  880. if (queue_index == TXCMD_QUEUE) {
  881. skb_push(skb, USB_HWDESC_HEADER_LEN);
  882. rtl819xU_tx_cmd(dev, skb);
  883. ret = 1;
  884. } else {
  885. skb_push(skb, priv->ieee80211->tx_headroom);
  886. ret = rtl8192_tx(dev, skb);
  887. }
  888. spin_unlock_irqrestore(&priv->tx_lock, flags);
  889. return ret;
  890. }
  891. static void rtl8192_tx_isr(struct urb *tx_urb)
  892. {
  893. struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
  894. struct net_device *dev = (struct net_device *)(skb->cb);
  895. struct r8192_priv *priv = NULL;
  896. cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  897. u8 queue_index = tcb_desc->queue_index;
  898. priv = ieee80211_priv(dev);
  899. if (tcb_desc->queue_index != TXCMD_QUEUE) {
  900. if (tx_urb->status == 0) {
  901. dev->trans_start = jiffies;
  902. priv->stats.txoktotal++;
  903. priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
  904. priv->stats.txbytesunicast +=
  905. (skb->len - priv->ieee80211->tx_headroom);
  906. } else {
  907. priv->ieee80211->stats.tx_errors++;
  908. /* TODO */
  909. }
  910. }
  911. /* free skb and tx_urb */
  912. if (skb != NULL) {
  913. dev_kfree_skb_any(skb);
  914. usb_free_urb(tx_urb);
  915. atomic_dec(&priv->tx_pending[queue_index]);
  916. }
  917. /*
  918. * Handle HW Beacon:
  919. * We had transfer our beacon frame to host controller at this moment.
  920. *
  921. *
  922. * Caution:
  923. * Handling the wait queue of command packets.
  924. * For Tx command packets, we must not do TCB fragment because it is
  925. * not handled right now. We must cut the packets to match the size of
  926. * TX_CMD_PKT before we send it.
  927. */
  928. /* Handle MPDU in wait queue. */
  929. if (queue_index != BEACON_QUEUE) {
  930. /* Don't send data frame during scanning.*/
  931. if ((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0) &&
  932. (!(priv->ieee80211->queue_stop))) {
  933. skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]));
  934. if (skb)
  935. priv->ieee80211->softmac_hard_start_xmit(skb,
  936. dev);
  937. return; /* avoid further processing AMSDU */
  938. }
  939. }
  940. }
  941. static void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
  942. {
  943. struct r8192_priv *priv = ieee80211_priv(dev);
  944. struct ieee80211_network *net;
  945. u8 i = 0, basic_rate = 0;
  946. net = &priv->ieee80211->current_network;
  947. for (i = 0; i < net->rates_len; i++) {
  948. basic_rate = net->rates[i] & 0x7f;
  949. switch (basic_rate) {
  950. case MGN_1M:
  951. *rate_config |= RRSR_1M;
  952. break;
  953. case MGN_2M:
  954. *rate_config |= RRSR_2M;
  955. break;
  956. case MGN_5_5M:
  957. *rate_config |= RRSR_5_5M;
  958. break;
  959. case MGN_11M:
  960. *rate_config |= RRSR_11M;
  961. break;
  962. case MGN_6M:
  963. *rate_config |= RRSR_6M;
  964. break;
  965. case MGN_9M:
  966. *rate_config |= RRSR_9M;
  967. break;
  968. case MGN_12M:
  969. *rate_config |= RRSR_12M;
  970. break;
  971. case MGN_18M:
  972. *rate_config |= RRSR_18M;
  973. break;
  974. case MGN_24M:
  975. *rate_config |= RRSR_24M;
  976. break;
  977. case MGN_36M:
  978. *rate_config |= RRSR_36M;
  979. break;
  980. case MGN_48M:
  981. *rate_config |= RRSR_48M;
  982. break;
  983. case MGN_54M:
  984. *rate_config |= RRSR_54M;
  985. break;
  986. }
  987. }
  988. for (i = 0; i < net->rates_ex_len; i++) {
  989. basic_rate = net->rates_ex[i] & 0x7f;
  990. switch (basic_rate) {
  991. case MGN_1M:
  992. *rate_config |= RRSR_1M;
  993. break;
  994. case MGN_2M:
  995. *rate_config |= RRSR_2M;
  996. break;
  997. case MGN_5_5M:
  998. *rate_config |= RRSR_5_5M;
  999. break;
  1000. case MGN_11M:
  1001. *rate_config |= RRSR_11M;
  1002. break;
  1003. case MGN_6M:
  1004. *rate_config |= RRSR_6M;
  1005. break;
  1006. case MGN_9M:
  1007. *rate_config |= RRSR_9M;
  1008. break;
  1009. case MGN_12M:
  1010. *rate_config |= RRSR_12M;
  1011. break;
  1012. case MGN_18M:
  1013. *rate_config |= RRSR_18M;
  1014. break;
  1015. case MGN_24M:
  1016. *rate_config |= RRSR_24M;
  1017. break;
  1018. case MGN_36M:
  1019. *rate_config |= RRSR_36M;
  1020. break;
  1021. case MGN_48M:
  1022. *rate_config |= RRSR_48M;
  1023. break;
  1024. case MGN_54M:
  1025. *rate_config |= RRSR_54M;
  1026. break;
  1027. }
  1028. }
  1029. }
  1030. #define SHORT_SLOT_TIME 9
  1031. #define NON_SHORT_SLOT_TIME 20
  1032. static void rtl8192_update_cap(struct net_device *dev, u16 cap)
  1033. {
  1034. u32 tmp = 0;
  1035. struct r8192_priv *priv = ieee80211_priv(dev);
  1036. struct ieee80211_network *net = &priv->ieee80211->current_network;
  1037. priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
  1038. tmp = priv->basic_rate;
  1039. if (priv->short_preamble)
  1040. tmp |= BRSR_AckShortPmb;
  1041. write_nic_dword(dev, RRSR, tmp);
  1042. if (net->mode & (IEEE_G | IEEE_N_24G)) {
  1043. u8 slot_time = 0;
  1044. if ((cap & WLAN_CAPABILITY_SHORT_SLOT) &&
  1045. (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
  1046. /* short slot time */
  1047. slot_time = SHORT_SLOT_TIME;
  1048. else /* long slot time */
  1049. slot_time = NON_SHORT_SLOT_TIME;
  1050. priv->slot_time = slot_time;
  1051. write_nic_byte(dev, SLOT_TIME, slot_time);
  1052. }
  1053. }
  1054. static void rtl8192_net_update(struct net_device *dev)
  1055. {
  1056. struct r8192_priv *priv = ieee80211_priv(dev);
  1057. struct ieee80211_network *net;
  1058. u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
  1059. u16 rate_config = 0;
  1060. net = &priv->ieee80211->current_network;
  1061. rtl8192_config_rate(dev, &rate_config);
  1062. priv->basic_rate = rate_config & 0x15f;
  1063. write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
  1064. write_nic_word(dev, BSSIDR + 4, ((u16 *)net->bssid)[2]);
  1065. rtl8192_update_msr(dev);
  1066. if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
  1067. write_nic_word(dev, ATIMWND, 2);
  1068. write_nic_word(dev, BCN_DMATIME, 1023);
  1069. write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
  1070. write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
  1071. write_nic_byte(dev, BCN_ERR_THRESH, 100);
  1072. BcnTimeCfg |= (BcnCW << BCN_TCFG_CW_SHIFT);
  1073. /* TODO: BcnIFS may required to be changed on ASIC */
  1074. BcnTimeCfg |= BcnIFS << BCN_TCFG_IFS;
  1075. write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
  1076. }
  1077. }
  1078. /* temporary hw beacon is not used any more.
  1079. * open it when necessary
  1080. */
  1081. void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate)
  1082. {
  1083. }
  1084. inline u8 rtl8192_IsWirelessBMode(u16 rate)
  1085. {
  1086. if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
  1087. return 1;
  1088. else
  1089. return 0;
  1090. }
  1091. short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
  1092. {
  1093. struct r8192_priv *priv = ieee80211_priv(dev);
  1094. int status;
  1095. struct urb *tx_urb;
  1096. unsigned int idx_pipe;
  1097. tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
  1098. cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  1099. u8 queue_index = tcb_desc->queue_index;
  1100. atomic_inc(&priv->tx_pending[queue_index]);
  1101. tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
  1102. if (!tx_urb) {
  1103. dev_kfree_skb(skb);
  1104. return -ENOMEM;
  1105. }
  1106. memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
  1107. /* Tx descriptor ought to be set according to the skb->cb */
  1108. pdesc->FirstSeg = 1;
  1109. pdesc->LastSeg = 1;
  1110. pdesc->CmdInit = tcb_desc->bCmdOrInit;
  1111. pdesc->TxBufferSize = tcb_desc->txbuf_size;
  1112. pdesc->OWN = 1;
  1113. pdesc->LINIP = tcb_desc->bLastIniPkt;
  1114. /*---------------------------------------------------------------------
  1115. * Fill up USB_OUT_CONTEXT.
  1116. *---------------------------------------------------------------------
  1117. */
  1118. idx_pipe = 0x04;
  1119. usb_fill_bulk_urb(tx_urb, priv->udev,
  1120. usb_sndbulkpipe(priv->udev, idx_pipe),
  1121. skb->data, skb->len, rtl8192_tx_isr, skb);
  1122. status = usb_submit_urb(tx_urb, GFP_ATOMIC);
  1123. if (!status)
  1124. return 0;
  1125. DMESGE("Error TX CMD URB, error %d", status);
  1126. return -1;
  1127. }
  1128. /*
  1129. * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
  1130. * in TxFwInfo data structure
  1131. * 2006.10.30 by Emily
  1132. *
  1133. * \param QUEUEID Software Queue
  1134. */
  1135. static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
  1136. {
  1137. u8 QueueSelect = 0x0; /* defualt set to */
  1138. switch (QueueID) {
  1139. case BE_QUEUE:
  1140. QueueSelect = QSLT_BE;
  1141. break;
  1142. case BK_QUEUE:
  1143. QueueSelect = QSLT_BK;
  1144. break;
  1145. case VO_QUEUE:
  1146. QueueSelect = QSLT_VO;
  1147. break;
  1148. case VI_QUEUE:
  1149. QueueSelect = QSLT_VI;
  1150. break;
  1151. case MGNT_QUEUE:
  1152. QueueSelect = QSLT_MGNT;
  1153. break;
  1154. case BEACON_QUEUE:
  1155. QueueSelect = QSLT_BEACON;
  1156. break;
  1157. /* TODO: mark other queue selection until we verify it is OK */
  1158. /* TODO: Remove Assertions */
  1159. case TXCMD_QUEUE:
  1160. QueueSelect = QSLT_CMD;
  1161. break;
  1162. case HIGH_QUEUE:
  1163. QueueSelect = QSLT_HIGH;
  1164. break;
  1165. default:
  1166. RT_TRACE(COMP_ERR,
  1167. "TransmitTCB(): Impossible Queue Selection: %d\n",
  1168. QueueID);
  1169. break;
  1170. }
  1171. return QueueSelect;
  1172. }
  1173. static u8 MRateToHwRate8190Pci(u8 rate)
  1174. {
  1175. u8 ret = DESC90_RATE1M;
  1176. switch (rate) {
  1177. case MGN_1M:
  1178. ret = DESC90_RATE1M;
  1179. break;
  1180. case MGN_2M:
  1181. ret = DESC90_RATE2M;
  1182. break;
  1183. case MGN_5_5M:
  1184. ret = DESC90_RATE5_5M;
  1185. break;
  1186. case MGN_11M:
  1187. ret = DESC90_RATE11M;
  1188. break;
  1189. case MGN_6M:
  1190. ret = DESC90_RATE6M;
  1191. break;
  1192. case MGN_9M:
  1193. ret = DESC90_RATE9M;
  1194. break;
  1195. case MGN_12M:
  1196. ret = DESC90_RATE12M;
  1197. break;
  1198. case MGN_18M:
  1199. ret = DESC90_RATE18M;
  1200. break;
  1201. case MGN_24M:
  1202. ret = DESC90_RATE24M;
  1203. break;
  1204. case MGN_36M:
  1205. ret = DESC90_RATE36M;
  1206. break;
  1207. case MGN_48M:
  1208. ret = DESC90_RATE48M;
  1209. break;
  1210. case MGN_54M:
  1211. ret = DESC90_RATE54M;
  1212. break;
  1213. /* HT rate since here */
  1214. case MGN_MCS0:
  1215. ret = DESC90_RATEMCS0;
  1216. break;
  1217. case MGN_MCS1:
  1218. ret = DESC90_RATEMCS1;
  1219. break;
  1220. case MGN_MCS2:
  1221. ret = DESC90_RATEMCS2;
  1222. break;
  1223. case MGN_MCS3:
  1224. ret = DESC90_RATEMCS3;
  1225. break;
  1226. case MGN_MCS4:
  1227. ret = DESC90_RATEMCS4;
  1228. break;
  1229. case MGN_MCS5:
  1230. ret = DESC90_RATEMCS5;
  1231. break;
  1232. case MGN_MCS6:
  1233. ret = DESC90_RATEMCS6;
  1234. break;
  1235. case MGN_MCS7:
  1236. ret = DESC90_RATEMCS7;
  1237. break;
  1238. case MGN_MCS8:
  1239. ret = DESC90_RATEMCS8;
  1240. break;
  1241. case MGN_MCS9:
  1242. ret = DESC90_RATEMCS9;
  1243. break;
  1244. case MGN_MCS10:
  1245. ret = DESC90_RATEMCS10;
  1246. break;
  1247. case MGN_MCS11:
  1248. ret = DESC90_RATEMCS11;
  1249. break;
  1250. case MGN_MCS12:
  1251. ret = DESC90_RATEMCS12;
  1252. break;
  1253. case MGN_MCS13:
  1254. ret = DESC90_RATEMCS13;
  1255. break;
  1256. case MGN_MCS14:
  1257. ret = DESC90_RATEMCS14;
  1258. break;
  1259. case MGN_MCS15:
  1260. ret = DESC90_RATEMCS15;
  1261. break;
  1262. case (0x80 | 0x20):
  1263. ret = DESC90_RATEMCS32;
  1264. break;
  1265. default:
  1266. break;
  1267. }
  1268. return ret;
  1269. }
  1270. static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
  1271. {
  1272. u8 tmp_Short;
  1273. tmp_Short = (TxHT == 1) ?
  1274. ((tcb_desc->bUseShortGI) ? 1 : 0) :
  1275. ((tcb_desc->bUseShortPreamble) ? 1 : 0);
  1276. if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
  1277. tmp_Short = 0;
  1278. return tmp_Short;
  1279. }
  1280. static void tx_zero_isr(struct urb *tx_urb)
  1281. {
  1282. }
  1283. /*
  1284. * The tx procedure is just as following,
  1285. * skb->cb will contain all the following information,
  1286. * priority, morefrag, rate, &dev.
  1287. * */
  1288. short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
  1289. {
  1290. struct r8192_priv *priv = ieee80211_priv(dev);
  1291. cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  1292. tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
  1293. tx_fwinfo_819x_usb *tx_fwinfo =
  1294. (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
  1295. struct usb_device *udev = priv->udev;
  1296. int pend;
  1297. int status;
  1298. struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
  1299. unsigned int idx_pipe;
  1300. pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
  1301. /* we are locked here so the two atomic_read and inc are executed
  1302. * without interleaves
  1303. * !!! For debug purpose
  1304. */
  1305. if (pend > MAX_TX_URB) {
  1306. netdev_dbg(dev, "To discard skb packet!\n");
  1307. dev_kfree_skb_any(skb);
  1308. return -1;
  1309. }
  1310. tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
  1311. if (!tx_urb) {
  1312. dev_kfree_skb_any(skb);
  1313. return -ENOMEM;
  1314. }
  1315. /* Fill Tx firmware info */
  1316. memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
  1317. /* DWORD 0 */
  1318. tx_fwinfo->TxHT = (tcb_desc->data_rate & 0x80) ? 1 : 0;
  1319. tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
  1320. tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
  1321. tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate,
  1322. tcb_desc);
  1323. if (tcb_desc->bAMPDUEnable) { /* AMPDU enabled */
  1324. tx_fwinfo->AllowAggregation = 1;
  1325. /* DWORD 1 */
  1326. tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
  1327. tx_fwinfo->RxAMD = tcb_desc->ampdu_density & 0x07;
  1328. } else {
  1329. tx_fwinfo->AllowAggregation = 0;
  1330. /* DWORD 1 */
  1331. tx_fwinfo->RxMF = 0;
  1332. tx_fwinfo->RxAMD = 0;
  1333. }
  1334. /* Protection mode related */
  1335. tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
  1336. tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
  1337. tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
  1338. tx_fwinfo->RtsHT = (tcb_desc->rts_rate & 0x80) ? 1 : 0;
  1339. tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
  1340. tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
  1341. tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
  1342. tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
  1343. (tcb_desc->bRTSUseShortGI ? 1 : 0);
  1344. /* Set Bandwidth and sub-channel settings. */
  1345. if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
  1346. if (tcb_desc->bPacketBW) {
  1347. tx_fwinfo->TxBandwidth = 1;
  1348. /* use duplicated mode */
  1349. tx_fwinfo->TxSubCarrier = 0;
  1350. } else {
  1351. tx_fwinfo->TxBandwidth = 0;
  1352. tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
  1353. }
  1354. } else {
  1355. tx_fwinfo->TxBandwidth = 0;
  1356. tx_fwinfo->TxSubCarrier = 0;
  1357. }
  1358. /* Fill Tx descriptor */
  1359. memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
  1360. /* DWORD 0 */
  1361. tx_desc->LINIP = 0;
  1362. tx_desc->CmdInit = 1;
  1363. tx_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
  1364. tx_desc->PktSize = (skb->len - TX_PACKET_SHIFT_BYTES) & 0xffff;
  1365. /*DWORD 1*/
  1366. tx_desc->SecCAMID = 0;
  1367. tx_desc->RATid = tcb_desc->RATRIndex;
  1368. tx_desc->NoEnc = 1;
  1369. tx_desc->SecType = 0x0;
  1370. if (tcb_desc->bHwSec) {
  1371. switch (priv->ieee80211->pairwise_key_type) {
  1372. case KEY_TYPE_WEP40:
  1373. case KEY_TYPE_WEP104:
  1374. tx_desc->SecType = 0x1;
  1375. tx_desc->NoEnc = 0;
  1376. break;
  1377. case KEY_TYPE_TKIP:
  1378. tx_desc->SecType = 0x2;
  1379. tx_desc->NoEnc = 0;
  1380. break;
  1381. case KEY_TYPE_CCMP:
  1382. tx_desc->SecType = 0x3;
  1383. tx_desc->NoEnc = 0;
  1384. break;
  1385. case KEY_TYPE_NA:
  1386. tx_desc->SecType = 0x0;
  1387. tx_desc->NoEnc = 1;
  1388. break;
  1389. }
  1390. }
  1391. tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
  1392. tx_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
  1393. tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
  1394. tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
  1395. /* Fill fields that are required to be initialized in
  1396. * all of the descriptors
  1397. */
  1398. /* DWORD 0 */
  1399. tx_desc->FirstSeg = 1;
  1400. tx_desc->LastSeg = 1;
  1401. tx_desc->OWN = 1;
  1402. /* DWORD 2 */
  1403. tx_desc->TxBufferSize = (u32)(skb->len - USB_HWDESC_HEADER_LEN);
  1404. idx_pipe = 0x5;
  1405. /* To submit bulk urb */
  1406. usb_fill_bulk_urb(tx_urb, udev,
  1407. usb_sndbulkpipe(udev, idx_pipe), skb->data,
  1408. skb->len, rtl8192_tx_isr, skb);
  1409. status = usb_submit_urb(tx_urb, GFP_ATOMIC);
  1410. if (!status) {
  1411. /* We need to send 0 byte packet whenever
  1412. * 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has
  1413. * been transmitted. Otherwise, it will be halt to wait for
  1414. * another packet.
  1415. */
  1416. bool bSend0Byte = false;
  1417. u8 zero = 0;
  1418. if (udev->speed == USB_SPEED_HIGH) {
  1419. if (skb->len > 0 && skb->len % 512 == 0)
  1420. bSend0Byte = true;
  1421. } else {
  1422. if (skb->len > 0 && skb->len % 64 == 0)
  1423. bSend0Byte = true;
  1424. }
  1425. if (bSend0Byte) {
  1426. tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC);
  1427. if (!tx_urb_zero) {
  1428. RT_TRACE(COMP_ERR,
  1429. "can't alloc urb for zero byte\n");
  1430. return -ENOMEM;
  1431. }
  1432. usb_fill_bulk_urb(tx_urb_zero, udev,
  1433. usb_sndbulkpipe(udev, idx_pipe),
  1434. &zero, 0, tx_zero_isr, dev);
  1435. status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
  1436. if (status) {
  1437. RT_TRACE(COMP_ERR,
  1438. "Error TX URB for zero byte %d, error %d",
  1439. atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
  1440. status);
  1441. return -1;
  1442. }
  1443. }
  1444. dev->trans_start = jiffies;
  1445. atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
  1446. return 0;
  1447. }
  1448. RT_TRACE(COMP_ERR, "Error TX URB %d, error %d",
  1449. atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
  1450. status);
  1451. return -1;
  1452. }
  1453. static short rtl8192_usb_initendpoints(struct net_device *dev)
  1454. {
  1455. struct r8192_priv *priv = ieee80211_priv(dev);
  1456. priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
  1457. GFP_KERNEL);
  1458. if (priv->rx_urb == NULL)
  1459. return -ENOMEM;
  1460. #ifndef JACKSON_NEW_RX
  1461. for (i = 0; i < (MAX_RX_URB + 1); i++) {
  1462. priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  1463. priv->rx_urb[i]->transfer_buffer =
  1464. kmalloc(RX_URB_SIZE, GFP_KERNEL);
  1465. priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
  1466. }
  1467. #endif
  1468. #ifdef THOMAS_BEACON
  1469. {
  1470. long align = 0;
  1471. void *oldaddr, *newaddr;
  1472. priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
  1473. priv->oldaddr = kmalloc(16, GFP_KERNEL);
  1474. if (!priv->oldaddr)
  1475. return -ENOMEM;
  1476. oldaddr = priv->oldaddr;
  1477. align = ((long)oldaddr) & 3;
  1478. if (align) {
  1479. newaddr = oldaddr + 4 - align;
  1480. priv->rx_urb[16]->transfer_buffer_length = 16 - 4 + align;
  1481. } else {
  1482. newaddr = oldaddr;
  1483. priv->rx_urb[16]->transfer_buffer_length = 16;
  1484. }
  1485. priv->rx_urb[16]->transfer_buffer = newaddr;
  1486. }
  1487. #endif
  1488. memset(priv->rx_urb, 0, sizeof(struct urb *) * MAX_RX_URB);
  1489. priv->pp_rxskb = kcalloc(MAX_RX_URB, sizeof(struct sk_buff *),
  1490. GFP_KERNEL);
  1491. if (!priv->pp_rxskb) {
  1492. kfree(priv->rx_urb);
  1493. priv->pp_rxskb = NULL;
  1494. priv->rx_urb = NULL;
  1495. DMESGE("Endpoint Alloc Failure");
  1496. return -ENOMEM;
  1497. }
  1498. netdev_dbg(dev, "End of initendpoints\n");
  1499. return 0;
  1500. }
  1501. #ifdef THOMAS_BEACON
  1502. static void rtl8192_usb_deleteendpoints(struct net_device *dev)
  1503. {
  1504. int i;
  1505. struct r8192_priv *priv = ieee80211_priv(dev);
  1506. if (priv->rx_urb) {
  1507. for (i = 0; i < (MAX_RX_URB + 1); i++) {
  1508. usb_kill_urb(priv->rx_urb[i]);
  1509. usb_free_urb(priv->rx_urb[i]);
  1510. }
  1511. kfree(priv->rx_urb);
  1512. priv->rx_urb = NULL;
  1513. }
  1514. kfree(priv->oldaddr);
  1515. priv->oldaddr = NULL;
  1516. kfree(priv->pp_rxskb);
  1517. priv->pp_rxskb = NULL;
  1518. }
  1519. #else
  1520. void rtl8192_usb_deleteendpoints(struct net_device *dev)
  1521. {
  1522. int i;
  1523. struct r8192_priv *priv = ieee80211_priv(dev);
  1524. #ifndef JACKSON_NEW_RX
  1525. if (priv->rx_urb) {
  1526. for (i = 0; i < (MAX_RX_URB + 1); i++) {
  1527. usb_kill_urb(priv->rx_urb[i]);
  1528. kfree(priv->rx_urb[i]->transfer_buffer);
  1529. usb_free_urb(priv->rx_urb[i]);
  1530. }
  1531. kfree(priv->rx_urb);
  1532. priv->rx_urb = NULL;
  1533. }
  1534. #else
  1535. kfree(priv->rx_urb);
  1536. priv->rx_urb = NULL;
  1537. kfree(priv->oldaddr);
  1538. priv->oldaddr = NULL;
  1539. kfree(priv->pp_rxskb);
  1540. priv->pp_rxskb = 0;
  1541. #endif
  1542. }
  1543. #endif
  1544. static void rtl8192_update_ratr_table(struct net_device *dev);
  1545. static void rtl8192_link_change(struct net_device *dev)
  1546. {
  1547. struct r8192_priv *priv = ieee80211_priv(dev);
  1548. struct ieee80211_device *ieee = priv->ieee80211;
  1549. if (ieee->state == IEEE80211_LINKED) {
  1550. rtl8192_net_update(dev);
  1551. rtl8192_update_ratr_table(dev);
  1552. /* Add this as in pure N mode, wep encryption will use software
  1553. * way, but there is no chance to set this as wep will not set
  1554. * group key in wext.
  1555. */
  1556. if (KEY_TYPE_WEP40 == ieee->pairwise_key_type ||
  1557. KEY_TYPE_WEP104 == ieee->pairwise_key_type)
  1558. EnableHWSecurityConfig8192(dev);
  1559. }
  1560. /*update timing params*/
  1561. if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
  1562. u32 reg = 0;
  1563. read_nic_dword(dev, RCR, &reg);
  1564. if (priv->ieee80211->state == IEEE80211_LINKED)
  1565. priv->ReceiveConfig = reg |= RCR_CBSSID;
  1566. else
  1567. priv->ReceiveConfig = reg &= ~RCR_CBSSID;
  1568. write_nic_dword(dev, RCR, reg);
  1569. }
  1570. }
  1571. static struct ieee80211_qos_parameters def_qos_parameters = {
  1572. {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)},
  1573. {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)},
  1574. {2, 2, 2, 2},/* aifs */
  1575. {0, 0, 0, 0},/* flags */
  1576. {0, 0, 0, 0} /* tx_op_limit */
  1577. };
  1578. static void rtl8192_update_beacon(struct work_struct *work)
  1579. {
  1580. struct r8192_priv *priv = container_of(work, struct r8192_priv,
  1581. update_beacon_wq.work);
  1582. struct net_device *dev = priv->ieee80211->dev;
  1583. struct ieee80211_device *ieee = priv->ieee80211;
  1584. struct ieee80211_network *net = &ieee->current_network;
  1585. if (ieee->pHTInfo->bCurrentHTSupport)
  1586. HTUpdateSelfAndPeerSetting(ieee, net);
  1587. ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
  1588. net->bssht.bdRT2RTLongSlotTime;
  1589. rtl8192_update_cap(dev, net->capability);
  1590. }
  1591. /*
  1592. * background support to run QoS activate functionality
  1593. */
  1594. static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK,
  1595. EDCAPARA_VI, EDCAPARA_VO};
  1596. static void rtl8192_qos_activate(struct work_struct *work)
  1597. {
  1598. struct r8192_priv *priv = container_of(work, struct r8192_priv,
  1599. qos_activate);
  1600. struct net_device *dev = priv->ieee80211->dev;
  1601. struct ieee80211_qos_parameters *qos_parameters =
  1602. &priv->ieee80211->current_network.qos_data.parameters;
  1603. u8 mode = priv->ieee80211->current_network.mode;
  1604. u32 u1bAIFS;
  1605. u32 u4bAcParam;
  1606. u32 op_limit;
  1607. u32 cw_max;
  1608. u32 cw_min;
  1609. int i;
  1610. mutex_lock(&priv->mutex);
  1611. if (priv->ieee80211->state != IEEE80211_LINKED)
  1612. goto success;
  1613. RT_TRACE(COMP_QOS,
  1614. "qos active process with associate response received\n");
  1615. /* It better set slot time at first
  1616. *
  1617. * For we just support b/g mode at present, let the slot time at
  1618. * 9/20 selection
  1619. *
  1620. * update the ac parameter to related registers
  1621. */
  1622. for (i = 0; i < QOS_QUEUE_NUM; i++) {
  1623. /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
  1624. u1bAIFS = qos_parameters->aifs[i] * ((mode & (IEEE_G | IEEE_N_24G)) ? 9 : 20) + aSifsTime;
  1625. u1bAIFS <<= AC_PARAM_AIFS_OFFSET;
  1626. op_limit = (u32)le16_to_cpu(qos_parameters->tx_op_limit[i]);
  1627. op_limit <<= AC_PARAM_TXOP_LIMIT_OFFSET;
  1628. cw_max = (u32)le16_to_cpu(qos_parameters->cw_max[i]);
  1629. cw_max <<= AC_PARAM_ECW_MAX_OFFSET;
  1630. cw_min = (u32)le16_to_cpu(qos_parameters->cw_min[i]);
  1631. cw_min <<= AC_PARAM_ECW_MIN_OFFSET;
  1632. u4bAcParam = op_limit | cw_max | cw_min | u1bAIFS;
  1633. write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
  1634. }
  1635. success:
  1636. mutex_unlock(&priv->mutex);
  1637. }
  1638. static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
  1639. int active_network,
  1640. struct ieee80211_network *network)
  1641. {
  1642. int ret = 0;
  1643. u32 size = sizeof(struct ieee80211_qos_parameters);
  1644. if (priv->ieee80211->state != IEEE80211_LINKED)
  1645. return ret;
  1646. if (priv->ieee80211->iw_mode != IW_MODE_INFRA)
  1647. return ret;
  1648. if (network->flags & NETWORK_HAS_QOS_MASK) {
  1649. if (active_network &&
  1650. (network->flags & NETWORK_HAS_QOS_PARAMETERS))
  1651. network->qos_data.active = network->qos_data.supported;
  1652. if ((network->qos_data.active == 1) && (active_network == 1) &&
  1653. (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
  1654. (network->qos_data.old_param_count !=
  1655. network->qos_data.param_count)) {
  1656. network->qos_data.old_param_count =
  1657. network->qos_data.param_count;
  1658. queue_work(priv->priv_wq, &priv->qos_activate);
  1659. RT_TRACE(COMP_QOS,
  1660. "QoS parameters change call qos_activate\n");
  1661. }
  1662. } else {
  1663. memcpy(&priv->ieee80211->current_network.qos_data.parameters,
  1664. &def_qos_parameters, size);
  1665. if ((network->qos_data.active == 1) && (active_network == 1)) {
  1666. queue_work(priv->priv_wq, &priv->qos_activate);
  1667. RT_TRACE(COMP_QOS,
  1668. "QoS was disabled call qos_activate\n");
  1669. }
  1670. network->qos_data.active = 0;
  1671. network->qos_data.supported = 0;
  1672. }
  1673. return 0;
  1674. }
  1675. /* handle and manage frame from beacon and probe response */
  1676. static int rtl8192_handle_beacon(struct net_device *dev,
  1677. struct ieee80211_beacon *beacon,
  1678. struct ieee80211_network *network)
  1679. {
  1680. struct r8192_priv *priv = ieee80211_priv(dev);
  1681. rtl8192_qos_handle_probe_response(priv, 1, network);
  1682. queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
  1683. return 0;
  1684. }
  1685. /*
  1686. * handling the beaconing responses. if we get different QoS setting
  1687. * off the network from the associated setting, adjust the QoS
  1688. * setting
  1689. */
  1690. static int rtl8192_qos_association_resp(struct r8192_priv *priv,
  1691. struct ieee80211_network *network)
  1692. {
  1693. unsigned long flags;
  1694. u32 size = sizeof(struct ieee80211_qos_parameters);
  1695. int set_qos_param = 0;
  1696. if ((priv == NULL) || (network == NULL))
  1697. return 0;
  1698. if (priv->ieee80211->state != IEEE80211_LINKED)
  1699. return 0;
  1700. if (priv->ieee80211->iw_mode != IW_MODE_INFRA)
  1701. return 0;
  1702. spin_lock_irqsave(&priv->ieee80211->lock, flags);
  1703. if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
  1704. memcpy(&priv->ieee80211->current_network.qos_data.parameters,
  1705. &network->qos_data.parameters,
  1706. sizeof(struct ieee80211_qos_parameters));
  1707. priv->ieee80211->current_network.qos_data.active = 1;
  1708. set_qos_param = 1;
  1709. /* update qos parameter for current network */
  1710. priv->ieee80211->current_network.qos_data.old_param_count =
  1711. priv->ieee80211->current_network.qos_data.param_count;
  1712. priv->ieee80211->current_network.qos_data.param_count =
  1713. network->qos_data.param_count;
  1714. } else {
  1715. memcpy(&priv->ieee80211->current_network.qos_data.parameters,
  1716. &def_qos_parameters, size);
  1717. priv->ieee80211->current_network.qos_data.active = 0;
  1718. priv->ieee80211->current_network.qos_data.supported = 0;
  1719. set_qos_param = 1;
  1720. }
  1721. spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
  1722. RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
  1723. network->flags,
  1724. priv->ieee80211->current_network.qos_data.active);
  1725. if (set_qos_param == 1)
  1726. queue_work(priv->priv_wq, &priv->qos_activate);
  1727. return 0;
  1728. }
  1729. static int rtl8192_handle_assoc_response(
  1730. struct net_device *dev,
  1731. struct ieee80211_assoc_response_frame *resp,
  1732. struct ieee80211_network *network)
  1733. {
  1734. struct r8192_priv *priv = ieee80211_priv(dev);
  1735. rtl8192_qos_association_resp(priv, network);
  1736. return 0;
  1737. }
  1738. static void rtl8192_update_ratr_table(struct net_device *dev)
  1739. {
  1740. struct r8192_priv *priv = ieee80211_priv(dev);
  1741. struct ieee80211_device *ieee = priv->ieee80211;
  1742. u8 *pMcsRate = ieee->dot11HTOperationalRateSet;
  1743. u32 ratr_value = 0;
  1744. u8 rate_index = 0;
  1745. rtl8192_config_rate(dev, (u16 *)(&ratr_value));
  1746. ratr_value |= (*(u16 *)(pMcsRate)) << 12;
  1747. switch (ieee->mode) {
  1748. case IEEE_A:
  1749. ratr_value &= 0x00000FF0;
  1750. break;
  1751. case IEEE_B:
  1752. ratr_value &= 0x0000000F;
  1753. break;
  1754. case IEEE_G:
  1755. ratr_value &= 0x00000FF7;
  1756. break;
  1757. case IEEE_N_24G:
  1758. case IEEE_N_5G:
  1759. if (ieee->pHTInfo->PeerMimoPs == 0) { /* MIMO_PS_STATIC */
  1760. ratr_value &= 0x0007F007;
  1761. } else {
  1762. if (priv->rf_type == RF_1T2R)
  1763. ratr_value &= 0x000FF007;
  1764. else
  1765. ratr_value &= 0x0F81F007;
  1766. }
  1767. break;
  1768. default:
  1769. break;
  1770. }
  1771. ratr_value &= 0x0FFFFFFF;
  1772. if (ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz)
  1773. ratr_value |= 0x80000000;
  1774. else if (!ieee->pHTInfo->bCurTxBW40MHz &&
  1775. ieee->pHTInfo->bCurShortGI20MHz)
  1776. ratr_value |= 0x80000000;
  1777. write_nic_dword(dev, RATR0 + rate_index * 4, ratr_value);
  1778. write_nic_byte(dev, UFWP, 1);
  1779. }
  1780. static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
  1781. static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
  1782. static bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
  1783. {
  1784. struct r8192_priv *priv = ieee80211_priv(dev);
  1785. struct ieee80211_device *ieee = priv->ieee80211;
  1786. struct ieee80211_network *network = &ieee->current_network;
  1787. int wpa_ie_len = ieee->wpa_ie_len;
  1788. struct ieee80211_crypt_data *crypt;
  1789. int encrypt;
  1790. crypt = ieee->crypt[ieee->tx_keyidx];
  1791. /* we use connecting AP's capability instead of only security config
  1792. * on our driver to distinguish whether it should use N mode or G mode
  1793. */
  1794. encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) ||
  1795. (ieee->host_encrypt && crypt && crypt->ops &&
  1796. (0 == strcmp(crypt->ops->name, "WEP")));
  1797. /* simply judge */
  1798. if (encrypt && (wpa_ie_len == 0)) {
  1799. /* wep encryption, no N mode setting */
  1800. return false;
  1801. } else if ((wpa_ie_len != 0)) {
  1802. /* parse pairwise key type */
  1803. if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
  1804. return true;
  1805. else
  1806. return false;
  1807. } else {
  1808. return true;
  1809. }
  1810. return true;
  1811. }
  1812. static bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
  1813. {
  1814. struct r8192_priv *priv = ieee80211_priv(dev);
  1815. return priv->ieee80211->bHalfWirelessN24GMode;
  1816. }
  1817. static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
  1818. {
  1819. struct ieee80211_device *ieee = priv->ieee80211;
  1820. /* We do not consider set support rate for ABG mode, only
  1821. * HT MCS rate is set here.
  1822. */
  1823. if (ieee->mode == WIRELESS_MODE_N_24G ||
  1824. ieee->mode == WIRELESS_MODE_N_5G)
  1825. memcpy(ieee->Regdot11HTOperationalRateSet,
  1826. ieee->RegHTSuppRateSet, 16);
  1827. else
  1828. memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
  1829. }
  1830. static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
  1831. {
  1832. struct r8192_priv *priv = ieee80211_priv(dev);
  1833. u8 ret = 0;
  1834. switch (priv->rf_chip) {
  1835. case RF_8225:
  1836. case RF_8256:
  1837. case RF_PSEUDO_11N:
  1838. ret = WIRELESS_MODE_N_24G | WIRELESS_MODE_G | WIRELESS_MODE_B;
  1839. break;
  1840. case RF_8258:
  1841. ret = WIRELESS_MODE_A | WIRELESS_MODE_N_5G;
  1842. break;
  1843. default:
  1844. ret = WIRELESS_MODE_B;
  1845. break;
  1846. }
  1847. return ret;
  1848. }
  1849. static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
  1850. {
  1851. struct r8192_priv *priv = ieee80211_priv(dev);
  1852. u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
  1853. if (wireless_mode == WIRELESS_MODE_AUTO ||
  1854. (wireless_mode & bSupportMode) == 0) {
  1855. if (bSupportMode & WIRELESS_MODE_N_24G) {
  1856. wireless_mode = WIRELESS_MODE_N_24G;
  1857. } else if (bSupportMode & WIRELESS_MODE_N_5G) {
  1858. wireless_mode = WIRELESS_MODE_N_5G;
  1859. } else if ((bSupportMode & WIRELESS_MODE_A)) {
  1860. wireless_mode = WIRELESS_MODE_A;
  1861. } else if ((bSupportMode & WIRELESS_MODE_G)) {
  1862. wireless_mode = WIRELESS_MODE_G;
  1863. } else if ((bSupportMode & WIRELESS_MODE_B)) {
  1864. wireless_mode = WIRELESS_MODE_B;
  1865. } else {
  1866. RT_TRACE(COMP_ERR,
  1867. "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
  1868. __func__, bSupportMode);
  1869. wireless_mode = WIRELESS_MODE_B;
  1870. }
  1871. }
  1872. #ifdef TO_DO_LIST
  1873. /* TODO: this function doesn't work well at this time,
  1874. * we should wait for FPGA
  1875. */
  1876. ActUpdateChannelAccessSetting(
  1877. pAdapter, pHalData->CurrentWirelessMode,
  1878. &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
  1879. #endif
  1880. priv->ieee80211->mode = wireless_mode;
  1881. if (wireless_mode == WIRELESS_MODE_N_24G ||
  1882. wireless_mode == WIRELESS_MODE_N_5G)
  1883. priv->ieee80211->pHTInfo->bEnableHT = 1;
  1884. else
  1885. priv->ieee80211->pHTInfo->bEnableHT = 0;
  1886. RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
  1887. rtl8192_refresh_supportrate(priv);
  1888. }
  1889. /* init priv variables here. only non_zero value should be initialized here. */
  1890. static void rtl8192_init_priv_variable(struct net_device *dev)
  1891. {
  1892. struct r8192_priv *priv = ieee80211_priv(dev);
  1893. u8 i;
  1894. priv->card_8192 = NIC_8192U;
  1895. priv->chan = 1; /* set to channel 1 */
  1896. priv->ieee80211->mode = WIRELESS_MODE_AUTO; /* SET AUTO */
  1897. priv->ieee80211->iw_mode = IW_MODE_INFRA;
  1898. priv->ieee80211->ieee_up = 0;
  1899. priv->retry_rts = DEFAULT_RETRY_RTS;
  1900. priv->retry_data = DEFAULT_RETRY_DATA;
  1901. priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
  1902. priv->ieee80211->rate = 110; /* 11 mbps */
  1903. priv->ieee80211->short_slot = 1;
  1904. priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
  1905. priv->CckPwEnl = 6;
  1906. /* for silent reset */
  1907. priv->IrpPendingCount = 1;
  1908. priv->ResetProgress = RESET_TYPE_NORESET;
  1909. priv->bForcedSilentReset = false;
  1910. priv->bDisableNormalResetCheck = false;
  1911. priv->force_reset = false;
  1912. /* we don't use FW read/write RF until stable firmware is available. */
  1913. priv->ieee80211->FwRWRF = 0;
  1914. priv->ieee80211->current_network.beacon_interval =
  1915. DEFAULT_BEACONINTERVAL;
  1916. priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
  1917. IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
  1918. IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
  1919. IEEE_SOFTMAC_BEACONS;
  1920. priv->ieee80211->active_scan = 1;
  1921. priv->ieee80211->modulation =
  1922. IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
  1923. priv->ieee80211->host_encrypt = 1;
  1924. priv->ieee80211->host_decrypt = 1;
  1925. priv->ieee80211->start_send_beacons = NULL;
  1926. priv->ieee80211->stop_send_beacons = NULL;
  1927. priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
  1928. priv->ieee80211->set_chan = rtl8192_set_chan;
  1929. priv->ieee80211->link_change = rtl8192_link_change;
  1930. priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
  1931. priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
  1932. priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
  1933. priv->ieee80211->init_wmmparam_flag = 0;
  1934. priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
  1935. priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
  1936. priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
  1937. priv->ieee80211->qos_support = 1;
  1938. priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
  1939. priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
  1940. priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
  1941. priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
  1942. priv->ieee80211->GetHalfNmodeSupportByAPsHandler =
  1943. GetHalfNmodeSupportByAPs819xUsb;
  1944. priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
  1945. priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
  1946. priv->card_type = USB;
  1947. #ifdef TO_DO_LIST
  1948. if (Adapter->bInHctTest) {
  1949. pHalData->ShortRetryLimit = 7;
  1950. pHalData->LongRetryLimit = 7;
  1951. }
  1952. #endif
  1953. priv->ShortRetryLimit = 0x30;
  1954. priv->LongRetryLimit = 0x30;
  1955. priv->EarlyRxThreshold = 7;
  1956. priv->enable_gpio0 = 0;
  1957. priv->TransmitConfig =
  1958. /* Max DMA Burst Size per Tx DMA Burst, 7: reserved. */
  1959. (TCR_MXDMA_2048 << TCR_MXDMA_OFFSET) |
  1960. /* Short retry limit */
  1961. (priv->ShortRetryLimit << TCR_SRL_OFFSET) |
  1962. /* Long retry limit */
  1963. (priv->LongRetryLimit << TCR_LRL_OFFSET) |
  1964. /* FALSE: HW provides PLCP length and LENGEXT
  1965. * TRUE: SW provides them
  1966. */
  1967. (false ? TCR_SAT : 0);
  1968. #ifdef TO_DO_LIST
  1969. if (Adapter->bInHctTest)
  1970. pHalData->ReceiveConfig =
  1971. pHalData->CSMethod |
  1972. /* accept management/data */
  1973. RCR_AMF | RCR_ADF |
  1974. /* accept control frame for SW
  1975. * AP needs PS-poll
  1976. */
  1977. RCR_ACF |
  1978. /* accept BC/MC/UC */
  1979. RCR_AB | RCR_AM | RCR_APM |
  1980. /* accept ICV/CRC error
  1981. * packet
  1982. */
  1983. RCR_AICV | RCR_ACRC32 |
  1984. /* Max DMA Burst Size per Tx
  1985. * DMA Burst, 7: unlimited.
  1986. */
  1987. ((u32)7 << RCR_MXDMA_OFFSET) |
  1988. /* Rx FIFO Threshold,
  1989. * 7: No Rx threshold.
  1990. */
  1991. (pHalData->EarlyRxThreshold << RCR_FIFO_OFFSET) |
  1992. (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
  1993. else
  1994. #endif
  1995. priv->ReceiveConfig =
  1996. /* accept management/data */
  1997. RCR_AMF | RCR_ADF |
  1998. /* accept control frame for SW AP needs PS-poll */
  1999. RCR_ACF |
  2000. /* accept BC/MC/UC */
  2001. RCR_AB | RCR_AM | RCR_APM |
  2002. /* Max DMA Burst Size per Rx DMA Burst, 7: unlimited. */
  2003. ((u32)7 << RCR_MXDMA_OFFSET) |
  2004. /* Rx FIFO Threshold, 7: No Rx threshold. */
  2005. (priv->EarlyRxThreshold << RX_FIFO_THRESHOLD_SHIFT) |
  2006. (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT : 0);
  2007. priv->AcmControl = 0;
  2008. priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL);
  2009. /* rx related queue */
  2010. skb_queue_head_init(&priv->rx_queue);
  2011. skb_queue_head_init(&priv->skb_queue);
  2012. /* Tx related queue */
  2013. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  2014. skb_queue_head_init(&priv->ieee80211->skb_waitQ[i]);
  2015. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  2016. skb_queue_head_init(&priv->ieee80211->skb_aggQ[i]);
  2017. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  2018. skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]);
  2019. priv->rf_set_chan = rtl8192_phy_SwChnl;
  2020. }
  2021. /* init lock here */
  2022. static void rtl8192_init_priv_lock(struct r8192_priv *priv)
  2023. {
  2024. spin_lock_init(&priv->tx_lock);
  2025. spin_lock_init(&priv->irq_lock);
  2026. sema_init(&priv->wx_sem, 1);
  2027. sema_init(&priv->rf_sem, 1);
  2028. mutex_init(&priv->mutex);
  2029. }
  2030. static void rtl819x_watchdog_wqcallback(struct work_struct *work);
  2031. static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
  2032. /* init tasklet and wait_queue here. only 2.6 above kernel is considered */
  2033. #define DRV_NAME "wlan0"
  2034. static void rtl8192_init_priv_task(struct net_device *dev)
  2035. {
  2036. struct r8192_priv *priv = ieee80211_priv(dev);
  2037. priv->priv_wq = create_workqueue(DRV_NAME);
  2038. INIT_WORK(&priv->reset_wq, rtl8192_restart);
  2039. INIT_DELAYED_WORK(&priv->watch_dog_wq,
  2040. rtl819x_watchdog_wqcallback);
  2041. INIT_DELAYED_WORK(&priv->txpower_tracking_wq,
  2042. dm_txpower_trackingcallback);
  2043. INIT_DELAYED_WORK(&priv->rfpath_check_wq,
  2044. dm_rf_pathcheck_workitemcallback);
  2045. INIT_DELAYED_WORK(&priv->update_beacon_wq,
  2046. rtl8192_update_beacon);
  2047. INIT_DELAYED_WORK(&priv->initialgain_operate_wq,
  2048. InitialGainOperateWorkItemCallBack);
  2049. INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
  2050. tasklet_init(&priv->irq_rx_tasklet,
  2051. (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
  2052. (unsigned long)priv);
  2053. }
  2054. static void rtl8192_get_eeprom_size(struct net_device *dev)
  2055. {
  2056. u16 curCR = 0;
  2057. struct r8192_priv *priv = ieee80211_priv(dev);
  2058. RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
  2059. read_nic_word_E(dev, EPROM_CMD, &curCR);
  2060. RT_TRACE(COMP_EPROM,
  2061. "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
  2062. /* whether need I consider BIT(5?) */
  2063. priv->epromtype =
  2064. (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
  2065. RT_TRACE(COMP_EPROM,
  2066. "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
  2067. }
  2068. /* used to swap endian. as ntohl & htonl are not necessary
  2069. * to swap endian, so use this instead.
  2070. */
  2071. static inline u16 endian_swap(u16 *data)
  2072. {
  2073. u16 tmp = *data;
  2074. *data = (tmp >> 8) | (tmp << 8);
  2075. return *data;
  2076. }
  2077. static void rtl8192_read_eeprom_info(struct net_device *dev)
  2078. {
  2079. u16 wEPROM_ID = 0;
  2080. u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
  2081. u8 bLoad_From_EEPOM = false;
  2082. struct r8192_priv *priv = ieee80211_priv(dev);
  2083. u16 tmpValue = 0;
  2084. int i;
  2085. RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
  2086. wEPROM_ID = eprom_read(dev, 0); /* first read EEPROM ID out; */
  2087. RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
  2088. if (wEPROM_ID != RTL8190_EEPROM_ID)
  2089. RT_TRACE(COMP_ERR,
  2090. "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n",
  2091. wEPROM_ID, RTL8190_EEPROM_ID);
  2092. else
  2093. bLoad_From_EEPOM = true;
  2094. if (bLoad_From_EEPOM) {
  2095. tmpValue = eprom_read(dev, EEPROM_VID >> 1);
  2096. priv->eeprom_vid = endian_swap(&tmpValue);
  2097. priv->eeprom_pid = eprom_read(dev, EEPROM_PID >> 1);
  2098. tmpValue = eprom_read(dev, EEPROM_ChannelPlan >> 1);
  2099. priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
  2100. priv->btxpowerdata_readfromEEPORM = true;
  2101. priv->eeprom_CustomerID =
  2102. eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
  2103. } else {
  2104. priv->eeprom_vid = 0;
  2105. priv->eeprom_pid = 0;
  2106. priv->card_8192_version = VERSION_819xU_B;
  2107. priv->eeprom_ChannelPlan = 0;
  2108. priv->eeprom_CustomerID = 0;
  2109. }
  2110. RT_TRACE(COMP_EPROM,
  2111. "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n",
  2112. priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID,
  2113. priv->eeprom_ChannelPlan);
  2114. /* set channelplan from eeprom */
  2115. priv->ChannelPlan = priv->eeprom_ChannelPlan;
  2116. if (bLoad_From_EEPOM) {
  2117. int i;
  2118. for (i = 0; i < 6; i += 2) {
  2119. u16 tmp = 0;
  2120. tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
  2121. *(u16 *)(&dev->dev_addr[i]) = tmp;
  2122. }
  2123. } else {
  2124. memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
  2125. /* should I set IDR0 here? */
  2126. }
  2127. RT_TRACE(COMP_EPROM, "MAC addr:%pM\n", dev->dev_addr);
  2128. priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */
  2129. priv->rf_chip = RF_8256;
  2130. if (priv->card_8192_version == (u8)VERSION_819xU_A) {
  2131. /* read Tx power gain offset of legacy OFDM to HT rate */
  2132. if (bLoad_From_EEPOM)
  2133. priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8;
  2134. else
  2135. priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
  2136. RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
  2137. /* read ThermalMeter from EEPROM */
  2138. if (bLoad_From_EEPOM)
  2139. priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter >> 1)) & 0x00ff);
  2140. else
  2141. priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
  2142. RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
  2143. /* for tx power track */
  2144. priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
  2145. /* read antenna tx power offset of B/C/D to A from EEPROM */
  2146. if (bLoad_From_EEPOM)
  2147. priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 1)) & 0x0f00) >> 8;
  2148. else
  2149. priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
  2150. RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
  2151. /* Read CrystalCap from EEPROM */
  2152. if (bLoad_From_EEPOM)
  2153. priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap >> 1)) & 0x0f);
  2154. else
  2155. priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
  2156. RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
  2157. /* get per-channel Tx power level */
  2158. if (bLoad_From_EEPOM)
  2159. priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)) & 0xff00) >> 8;
  2160. else
  2161. priv->EEPROM_Def_Ver = 1;
  2162. RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
  2163. if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
  2164. int i;
  2165. if (bLoad_From_EEPOM)
  2166. priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)) & 0xff) >> 8;
  2167. else
  2168. priv->EEPROMTxPowerLevelCCK = 0x10;
  2169. RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
  2170. for (i = 0; i < 3; i++) {
  2171. if (bLoad_From_EEPOM) {
  2172. tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
  2173. if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
  2174. tmpValue = tmpValue & 0x00ff;
  2175. else
  2176. tmpValue = (tmpValue & 0xff00) >> 8;
  2177. } else {
  2178. tmpValue = 0x10;
  2179. }
  2180. priv->EEPROMTxPowerLevelOFDM24G[i] = (u8)tmpValue;
  2181. RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
  2182. }
  2183. } else if (priv->EEPROM_Def_Ver == 1) {
  2184. if (bLoad_From_EEPOM) {
  2185. tmpValue = eprom_read(dev,
  2186. EEPROM_TxPwIndex_CCK_V1 >> 1);
  2187. tmpValue = (tmpValue & 0xff00) >> 8;
  2188. } else {
  2189. tmpValue = 0x10;
  2190. }
  2191. priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
  2192. if (bLoad_From_EEPOM)
  2193. tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
  2194. else
  2195. tmpValue = 0x1010;
  2196. *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
  2197. if (bLoad_From_EEPOM)
  2198. tmpValue = eprom_read(dev,
  2199. EEPROM_TxPwIndex_OFDM_24G_V1 >> 1);
  2200. else
  2201. tmpValue = 0x1010;
  2202. *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
  2203. if (bLoad_From_EEPOM)
  2204. tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1);
  2205. else
  2206. tmpValue = 0x10;
  2207. priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
  2208. } /* endif EEPROM_Def_Ver == 1 */
  2209. /* update HAL variables */
  2210. for (i = 0; i < 14; i++) {
  2211. if (i <= 3)
  2212. priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
  2213. else if (i >= 4 && i <= 9)
  2214. priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
  2215. else
  2216. priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
  2217. }
  2218. for (i = 0; i < 14; i++) {
  2219. if (priv->EEPROM_Def_Ver == 0) {
  2220. if (i <= 3)
  2221. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
  2222. else if (i >= 4 && i <= 9)
  2223. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
  2224. else
  2225. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
  2226. } else if (priv->EEPROM_Def_Ver == 1) {
  2227. if (i <= 3)
  2228. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
  2229. else if (i >= 4 && i <= 9)
  2230. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
  2231. else
  2232. priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
  2233. }
  2234. }
  2235. priv->TxPowerDiff = priv->EEPROMPwDiff;
  2236. /* Antenna B gain offset to antenna A, bit0~3 */
  2237. priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
  2238. /* Antenna C gain offset to antenna A, bit4~7 */
  2239. priv->AntennaTxPwDiff[1] =
  2240. (priv->EEPROMTxPowerDiff & 0xf0) >> 4;
  2241. /* CrystalCap, bit12~15 */
  2242. priv->CrystalCap = priv->EEPROMCrystalCap;
  2243. /* ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
  2244. * 92U does not enable TX power tracking.
  2245. */
  2246. priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
  2247. } /* end if VersionID == VERSION_819xU_A */
  2248. /* for dlink led */
  2249. switch (priv->eeprom_CustomerID) {
  2250. case EEPROM_CID_RUNTOP:
  2251. priv->CustomerID = RT_CID_819x_RUNTOP;
  2252. break;
  2253. case EEPROM_CID_DLINK:
  2254. priv->CustomerID = RT_CID_DLINK;
  2255. break;
  2256. default:
  2257. priv->CustomerID = RT_CID_DEFAULT;
  2258. break;
  2259. }
  2260. switch (priv->CustomerID) {
  2261. case RT_CID_819x_RUNTOP:
  2262. priv->LedStrategy = SW_LED_MODE2;
  2263. break;
  2264. case RT_CID_DLINK:
  2265. priv->LedStrategy = SW_LED_MODE4;
  2266. break;
  2267. default:
  2268. priv->LedStrategy = SW_LED_MODE0;
  2269. break;
  2270. }
  2271. if (priv->rf_type == RF_1T2R)
  2272. RT_TRACE(COMP_EPROM, "\n1T2R config\n");
  2273. else
  2274. RT_TRACE(COMP_EPROM, "\n2T4R config\n");
  2275. /* We can only know RF type in the function. So we have to init
  2276. * DIG RATR table again.
  2277. */
  2278. init_rate_adaptive(dev);
  2279. RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
  2280. }
  2281. static short rtl8192_get_channel_map(struct net_device *dev)
  2282. {
  2283. struct r8192_priv *priv = ieee80211_priv(dev);
  2284. if (priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN) {
  2285. netdev_err(dev,
  2286. "rtl8180_init: Error channel plan! Set to default.\n");
  2287. priv->ChannelPlan = 0;
  2288. }
  2289. RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
  2290. rtl819x_set_channel_map(priv->ChannelPlan, priv);
  2291. return 0;
  2292. }
  2293. static short rtl8192_init(struct net_device *dev)
  2294. {
  2295. struct r8192_priv *priv = ieee80211_priv(dev);
  2296. memset(&(priv->stats), 0, sizeof(struct Stats));
  2297. memset(priv->txqueue_to_outpipemap, 0, 9);
  2298. #ifdef PIPE12
  2299. {
  2300. int i = 0;
  2301. u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
  2302. memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
  2303. }
  2304. #else
  2305. {
  2306. u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 0, 4, 4};
  2307. memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
  2308. }
  2309. #endif
  2310. rtl8192_init_priv_variable(dev);
  2311. rtl8192_init_priv_lock(priv);
  2312. rtl8192_init_priv_task(dev);
  2313. rtl8192_get_eeprom_size(dev);
  2314. rtl8192_read_eeprom_info(dev);
  2315. rtl8192_get_channel_map(dev);
  2316. init_hal_dm(dev);
  2317. setup_timer(&priv->watch_dog_timer, watch_dog_timer_callback,
  2318. (unsigned long)dev);
  2319. if (rtl8192_usb_initendpoints(dev) != 0) {
  2320. DMESG("Endopoints initialization failed");
  2321. return -ENOMEM;
  2322. }
  2323. return 0;
  2324. }
  2325. /******************************************************************************
  2326. *function: This function actually only set RRSR, RATR and BW_OPMODE registers
  2327. * not to do all the hw config as its name says
  2328. * input: net_device dev
  2329. * output: none
  2330. * return: none
  2331. * notice: This part need to modified according to the rate set we filtered
  2332. * ****************************************************************************/
  2333. static void rtl8192_hwconfig(struct net_device *dev)
  2334. {
  2335. u32 regRATR = 0, regRRSR = 0;
  2336. u8 regBwOpMode = 0, regTmp = 0;
  2337. struct r8192_priv *priv = ieee80211_priv(dev);
  2338. u32 ratr_value = 0;
  2339. /* Set RRSR, RATR, and BW_OPMODE registers */
  2340. switch (priv->ieee80211->mode) {
  2341. case WIRELESS_MODE_B:
  2342. regBwOpMode = BW_OPMODE_20MHZ;
  2343. regRATR = RATE_ALL_CCK;
  2344. regRRSR = RATE_ALL_CCK;
  2345. break;
  2346. case WIRELESS_MODE_A:
  2347. regBwOpMode = BW_OPMODE_5G | BW_OPMODE_20MHZ;
  2348. regRATR = RATE_ALL_OFDM_AG;
  2349. regRRSR = RATE_ALL_OFDM_AG;
  2350. break;
  2351. case WIRELESS_MODE_G:
  2352. regBwOpMode = BW_OPMODE_20MHZ;
  2353. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2354. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2355. break;
  2356. case WIRELESS_MODE_AUTO:
  2357. #ifdef TO_DO_LIST
  2358. if (Adapter->bInHctTest) {
  2359. regBwOpMode = BW_OPMODE_20MHZ;
  2360. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2361. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2362. } else
  2363. #endif
  2364. {
  2365. regBwOpMode = BW_OPMODE_20MHZ;
  2366. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
  2367. RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  2368. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2369. }
  2370. break;
  2371. case WIRELESS_MODE_N_24G:
  2372. /* It support CCK rate by default. CCK rate will be filtered
  2373. * out only when associated AP does not support it.
  2374. */
  2375. regBwOpMode = BW_OPMODE_20MHZ;
  2376. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
  2377. RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  2378. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  2379. break;
  2380. case WIRELESS_MODE_N_5G:
  2381. regBwOpMode = BW_OPMODE_5G;
  2382. regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS |
  2383. RATE_ALL_OFDM_2SS;
  2384. regRRSR = RATE_ALL_OFDM_AG;
  2385. break;
  2386. }
  2387. write_nic_byte(dev, BW_OPMODE, regBwOpMode);
  2388. ratr_value = regRATR;
  2389. if (priv->rf_type == RF_1T2R)
  2390. ratr_value &= ~(RATE_ALL_OFDM_2SS);
  2391. write_nic_dword(dev, RATR0, ratr_value);
  2392. write_nic_byte(dev, UFWP, 1);
  2393. read_nic_byte(dev, 0x313, &regTmp);
  2394. regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
  2395. write_nic_dword(dev, RRSR, regRRSR);
  2396. /* Set Retry Limit here */
  2397. write_nic_word(dev, RETRY_LIMIT,
  2398. priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
  2399. priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
  2400. /* Set Contention Window here */
  2401. /* Set Tx AGC */
  2402. /* Set Tx Antenna including Feedback control */
  2403. /* Set Auto Rate fallback control */
  2404. }
  2405. /* InitializeAdapter and PhyCfg */
  2406. static bool rtl8192_adapter_start(struct net_device *dev)
  2407. {
  2408. struct r8192_priv *priv = ieee80211_priv(dev);
  2409. u32 dwRegRead = 0;
  2410. bool init_status = true;
  2411. u8 SECR_value = 0x0;
  2412. u8 tmp;
  2413. RT_TRACE(COMP_INIT, "====>%s()\n", __func__);
  2414. priv->Rf_Mode = RF_OP_By_SW_3wire;
  2415. /* for ASIC power on sequence */
  2416. write_nic_byte_E(dev, 0x5f, 0x80);
  2417. mdelay(50);
  2418. write_nic_byte_E(dev, 0x5f, 0xf0);
  2419. write_nic_byte_E(dev, 0x5d, 0x00);
  2420. write_nic_byte_E(dev, 0x5e, 0x80);
  2421. write_nic_byte(dev, 0x17, 0x37);
  2422. mdelay(10);
  2423. priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
  2424. /* config CPUReset Register */
  2425. /* Firmware Reset or not? */
  2426. read_nic_dword(dev, CPU_GEN, &dwRegRead);
  2427. if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
  2428. dwRegRead |= CPU_GEN_SYSTEM_RESET; /* do nothing here? */
  2429. else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
  2430. dwRegRead |= CPU_GEN_FIRMWARE_RESET;
  2431. else
  2432. RT_TRACE(COMP_ERR,
  2433. "ERROR in %s(): undefined firmware state(%d)\n",
  2434. __func__, priv->pFirmware->firmware_status);
  2435. write_nic_dword(dev, CPU_GEN, dwRegRead);
  2436. /* config BB. */
  2437. rtl8192_BBConfig(dev);
  2438. /* Loopback mode or not */
  2439. priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
  2440. read_nic_dword(dev, CPU_GEN, &dwRegRead);
  2441. if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
  2442. dwRegRead = (dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) |
  2443. CPU_GEN_NO_LOOPBACK_SET;
  2444. else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
  2445. dwRegRead |= CPU_CCK_LOOPBACK;
  2446. else
  2447. RT_TRACE(COMP_ERR,
  2448. "Serious error in %s(): wrong loopback mode setting(%d)\n",
  2449. __func__, priv->LoopbackMode);
  2450. write_nic_dword(dev, CPU_GEN, dwRegRead);
  2451. /* after reset cpu, we need wait for a seconds to write in register. */
  2452. udelay(500);
  2453. /* add for new bitfile:usb suspend reset pin set to 1. Do we need? */
  2454. read_nic_byte_E(dev, 0x5f, &tmp);
  2455. write_nic_byte_E(dev, 0x5f, tmp | 0x20);
  2456. /* Set Hardware */
  2457. rtl8192_hwconfig(dev);
  2458. /* turn on Tx/Rx */
  2459. write_nic_byte(dev, CMDR, CR_RE | CR_TE);
  2460. /* set IDR0 here */
  2461. write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
  2462. write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
  2463. /* set RCR */
  2464. write_nic_dword(dev, RCR, priv->ReceiveConfig);
  2465. /* Initialize Number of Reserved Pages in Firmware Queue */
  2466. write_nic_dword(dev, RQPN1,
  2467. NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
  2468. NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
  2469. NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
  2470. NUM_OF_PAGE_IN_FW_QUEUE_VO << RSVD_FW_QUEUE_PAGE_VO_SHIFT);
  2471. write_nic_dword(dev, RQPN2,
  2472. NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
  2473. NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
  2474. write_nic_dword(dev, RQPN3,
  2475. APPLIED_RESERVED_QUEUE_IN_FW |
  2476. NUM_OF_PAGE_IN_FW_QUEUE_BCN << RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
  2477. write_nic_dword(dev, RATR0 + 4 * 7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
  2478. /* Set AckTimeout */
  2479. /* TODO: (it value is only for FPGA version). need to be changed!! */
  2480. write_nic_byte(dev, ACK_TIMEOUT, 0x30);
  2481. if (priv->ResetProgress == RESET_TYPE_NORESET)
  2482. rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
  2483. if (priv->ResetProgress == RESET_TYPE_NORESET) {
  2484. CamResetAllEntry(dev);
  2485. SECR_value |= SCR_TxEncEnable;
  2486. SECR_value |= SCR_RxDecEnable;
  2487. SECR_value |= SCR_NoSKMC;
  2488. write_nic_byte(dev, SECR, SECR_value);
  2489. }
  2490. /* Beacon related */
  2491. write_nic_word(dev, ATIMWND, 2);
  2492. write_nic_word(dev, BCN_INTERVAL, 100);
  2493. #define DEFAULT_EDCA 0x005e4332
  2494. {
  2495. int i;
  2496. for (i = 0; i < QOS_QUEUE_NUM; i++)
  2497. write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
  2498. }
  2499. rtl8192_phy_configmac(dev);
  2500. if (priv->card_8192_version == (u8)VERSION_819xU_A) {
  2501. rtl8192_phy_getTxPower(dev);
  2502. rtl8192_phy_setTxPower(dev, priv->chan);
  2503. }
  2504. /* Firmware download */
  2505. init_status = init_firmware(dev);
  2506. if (!init_status) {
  2507. RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n",
  2508. __func__);
  2509. return init_status;
  2510. }
  2511. RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
  2512. #ifdef TO_DO_LIST
  2513. if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
  2514. if (pMgntInfo->RegRfOff) { /* User disable RF via registry. */
  2515. RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
  2516. ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
  2517. MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
  2518. /* Those actions will be discard in MgntActSet_RF_State
  2519. * because of the same state
  2520. */
  2521. for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
  2522. PHY_SetRFReg(Adapter,
  2523. (RF90_RADIO_PATH_E)eRFPath,
  2524. 0x4, 0xC00, 0x0);
  2525. } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) {
  2526. /* H/W or S/W RF OFF before sleep. */
  2527. RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
  2528. ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n",
  2529. pMgntInfo->RfOffReason));
  2530. MgntActSet_RF_State(Adapter,
  2531. eRfOff,
  2532. pMgntInfo->RfOffReason);
  2533. } else {
  2534. pHalData->eRFPowerState = eRfOn;
  2535. pMgntInfo->RfOffReason = 0;
  2536. RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
  2537. ("InitializeAdapter819xUsb(): RF is on ----------\n"));
  2538. }
  2539. } else {
  2540. if (pHalData->eRFPowerState == eRfOff) {
  2541. MgntActSet_RF_State(Adapter,
  2542. eRfOff,
  2543. pMgntInfo->RfOffReason);
  2544. /* Those actions will be discard in MgntActSet_RF_State
  2545. * because of the same state
  2546. */
  2547. for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
  2548. PHY_SetRFReg(Adapter,
  2549. (RF90_RADIO_PATH_E)eRFPath,
  2550. 0x4, 0xC00, 0x0);
  2551. }
  2552. }
  2553. #endif
  2554. /* config RF. */
  2555. if (priv->ResetProgress == RESET_TYPE_NORESET) {
  2556. rtl8192_phy_RFConfig(dev);
  2557. RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __func__);
  2558. }
  2559. if (priv->ieee80211->FwRWRF)
  2560. /* We can force firmware to do RF-R/W */
  2561. priv->Rf_Mode = RF_OP_By_FW;
  2562. else
  2563. priv->Rf_Mode = RF_OP_By_SW_3wire;
  2564. rtl8192_phy_updateInitGain(dev);
  2565. /*--set CCK and OFDM Block "ON"--*/
  2566. rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
  2567. rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
  2568. if (priv->ResetProgress == RESET_TYPE_NORESET) {
  2569. /* if D or C cut */
  2570. u8 tmpvalue;
  2571. read_nic_byte(dev, 0x301, &tmpvalue);
  2572. if (tmpvalue == 0x03) {
  2573. priv->bDcut = true;
  2574. RT_TRACE(COMP_POWER_TRACKING, "D-cut\n");
  2575. } else {
  2576. priv->bDcut = false;
  2577. RT_TRACE(COMP_POWER_TRACKING, "C-cut\n");
  2578. }
  2579. dm_initialize_txpower_tracking(dev);
  2580. if (priv->bDcut) {
  2581. u32 i, TempCCk;
  2582. u32 tmpRegA = rtl8192_QueryBBReg(dev,
  2583. rOFDM0_XATxIQImbalance,
  2584. bMaskDWord);
  2585. for (i = 0; i < TxBBGainTableLength; i++) {
  2586. if (tmpRegA == priv->txbbgain_table[i].txbbgain_value) {
  2587. priv->rfa_txpowertrackingindex = (u8)i;
  2588. priv->rfa_txpowertrackingindex_real =
  2589. (u8)i;
  2590. priv->rfa_txpowertracking_default =
  2591. priv->rfa_txpowertrackingindex;
  2592. break;
  2593. }
  2594. }
  2595. TempCCk = rtl8192_QueryBBReg(dev,
  2596. rCCK0_TxFilter1,
  2597. bMaskByte2);
  2598. for (i = 0; i < CCKTxBBGainTableLength; i++) {
  2599. if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
  2600. priv->cck_present_attentuation_20Mdefault = (u8)i;
  2601. break;
  2602. }
  2603. }
  2604. priv->cck_present_attentuation_40Mdefault = 0;
  2605. priv->cck_present_attentuation_difference = 0;
  2606. priv->cck_present_attentuation =
  2607. priv->cck_present_attentuation_20Mdefault;
  2608. }
  2609. }
  2610. write_nic_byte(dev, 0x87, 0x0);
  2611. return init_status;
  2612. }
  2613. /* this configures registers for beacon tx and enables it via
  2614. * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
  2615. * be used to stop beacon transmission
  2616. */
  2617. /***************************************************************************
  2618. -------------------------------NET STUFF---------------------------
  2619. ***************************************************************************/
  2620. static struct net_device_stats *rtl8192_stats(struct net_device *dev)
  2621. {
  2622. struct r8192_priv *priv = ieee80211_priv(dev);
  2623. return &priv->ieee80211->stats;
  2624. }
  2625. static bool HalTxCheckStuck819xUsb(struct net_device *dev)
  2626. {
  2627. struct r8192_priv *priv = ieee80211_priv(dev);
  2628. u16 RegTxCounter;
  2629. bool bStuck = false;
  2630. read_nic_word(dev, 0x128, &RegTxCounter);
  2631. RT_TRACE(COMP_RESET,
  2632. "%s():RegTxCounter is %d,TxCounter is %d\n", __func__,
  2633. RegTxCounter, priv->TxCounter);
  2634. if (priv->TxCounter == RegTxCounter)
  2635. bStuck = true;
  2636. priv->TxCounter = RegTxCounter;
  2637. return bStuck;
  2638. }
  2639. /*
  2640. * <Assumption: RT_TX_SPINLOCK is acquired.>
  2641. * First added: 2006.11.19 by emily
  2642. */
  2643. static RESET_TYPE TxCheckStuck(struct net_device *dev)
  2644. {
  2645. struct r8192_priv *priv = ieee80211_priv(dev);
  2646. u8 QueueID;
  2647. bool bCheckFwTxCnt = false;
  2648. /* Decide such threshold according to current power save mode */
  2649. for (QueueID = 0; QueueID <= BEACON_QUEUE; QueueID++) {
  2650. if (QueueID == TXCMD_QUEUE)
  2651. continue;
  2652. if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
  2653. continue;
  2654. bCheckFwTxCnt = true;
  2655. }
  2656. if (bCheckFwTxCnt) {
  2657. if (HalTxCheckStuck819xUsb(dev)) {
  2658. RT_TRACE(COMP_RESET,
  2659. "TxCheckStuck(): Fw indicates no Tx condition!\n");
  2660. return RESET_TYPE_SILENT;
  2661. }
  2662. }
  2663. return RESET_TYPE_NORESET;
  2664. }
  2665. static bool HalRxCheckStuck819xUsb(struct net_device *dev)
  2666. {
  2667. u16 RegRxCounter;
  2668. struct r8192_priv *priv = ieee80211_priv(dev);
  2669. bool bStuck = false;
  2670. static u8 rx_chk_cnt;
  2671. read_nic_word(dev, 0x130, &RegRxCounter);
  2672. RT_TRACE(COMP_RESET,
  2673. "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__,
  2674. RegRxCounter, priv->RxCounter);
  2675. /* If rssi is small, we should check rx for long time because of bad rx.
  2676. * or maybe it will continuous silent reset every 2 seconds.
  2677. */
  2678. rx_chk_cnt++;
  2679. if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High + 5)) {
  2680. rx_chk_cnt = 0; /* high rssi, check rx stuck right now. */
  2681. } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High + 5) &&
  2682. ((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_40M) ||
  2683. (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_20M))) {
  2684. if (rx_chk_cnt < 2)
  2685. return bStuck;
  2686. rx_chk_cnt = 0;
  2687. } else if (((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_40M) ||
  2688. (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_20M)) &&
  2689. priv->undecorated_smoothed_pwdb >= VeryLowRSSI) {
  2690. if (rx_chk_cnt < 4)
  2691. return bStuck;
  2692. rx_chk_cnt = 0;
  2693. } else {
  2694. if (rx_chk_cnt < 8)
  2695. return bStuck;
  2696. rx_chk_cnt = 0;
  2697. }
  2698. if (priv->RxCounter == RegRxCounter)
  2699. bStuck = true;
  2700. priv->RxCounter = RegRxCounter;
  2701. return bStuck;
  2702. }
  2703. static RESET_TYPE RxCheckStuck(struct net_device *dev)
  2704. {
  2705. struct r8192_priv *priv = ieee80211_priv(dev);
  2706. bool bRxCheck = false;
  2707. if (priv->IrpPendingCount > 1)
  2708. bRxCheck = true;
  2709. if (bRxCheck) {
  2710. if (HalRxCheckStuck819xUsb(dev)) {
  2711. RT_TRACE(COMP_RESET, "RxStuck Condition\n");
  2712. return RESET_TYPE_SILENT;
  2713. }
  2714. }
  2715. return RESET_TYPE_NORESET;
  2716. }
  2717. /**
  2718. * This function is called by Checkforhang to check whether we should
  2719. * ask OS to reset driver
  2720. *
  2721. * \param pAdapter The adapter context for this miniport
  2722. *
  2723. * Note:NIC with USB interface sholud not call this function because we
  2724. * cannot scan descriptor to judge whether there is tx stuck.
  2725. * Note: This function may be required to be rewrite for Vista OS.
  2726. * <<<Assumption: Tx spinlock has been acquired >>>
  2727. *
  2728. * 8185 and 8185b does not implement this function.
  2729. */
  2730. static RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
  2731. {
  2732. struct r8192_priv *priv = ieee80211_priv(dev);
  2733. RESET_TYPE TxResetType = RESET_TYPE_NORESET;
  2734. RESET_TYPE RxResetType = RESET_TYPE_NORESET;
  2735. RT_RF_POWER_STATE rfState;
  2736. rfState = priv->ieee80211->eRFPowerState;
  2737. TxResetType = TxCheckStuck(dev);
  2738. if (rfState != eRfOff ||
  2739. (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
  2740. /* If driver is in the status of firmware download failure,
  2741. * driver skips RF initialization and RF is in turned off
  2742. * state. Driver should check whether Rx stuck and do silent
  2743. * reset. And if driver is in firmware download failure status,
  2744. * driver should initialize RF in the following silent reset
  2745. * procedure
  2746. *
  2747. * Driver should not check RX stuck in IBSS mode because it is
  2748. * required to set Check BSSID in order to send beacon,
  2749. * however, if check BSSID is set, STA cannot hear any packet
  2750. * at all.
  2751. */
  2752. RxResetType = RxCheckStuck(dev);
  2753. }
  2754. if (TxResetType == RESET_TYPE_NORMAL ||
  2755. RxResetType == RESET_TYPE_NORMAL) {
  2756. return RESET_TYPE_NORMAL;
  2757. } else if (TxResetType == RESET_TYPE_SILENT ||
  2758. RxResetType == RESET_TYPE_SILENT) {
  2759. RT_TRACE(COMP_RESET, "%s():silent reset\n", __func__);
  2760. return RESET_TYPE_SILENT;
  2761. } else {
  2762. return RESET_TYPE_NORESET;
  2763. }
  2764. }
  2765. static void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
  2766. static int _rtl8192_up(struct net_device *dev);
  2767. static int rtl8192_close(struct net_device *dev);
  2768. static void CamRestoreAllEntry(struct net_device *dev)
  2769. {
  2770. u8 EntryId = 0;
  2771. struct r8192_priv *priv = ieee80211_priv(dev);
  2772. u8 *MacAddr = priv->ieee80211->current_network.bssid;
  2773. static u8 CAM_CONST_ADDR[4][6] = {
  2774. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  2775. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  2776. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  2777. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
  2778. static u8 CAM_CONST_BROAD[] = {
  2779. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2780. RT_TRACE(COMP_SEC, "CamRestoreAllEntry:\n");
  2781. if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
  2782. (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) {
  2783. for (EntryId = 0; EntryId < 4; EntryId++) {
  2784. MacAddr = CAM_CONST_ADDR[EntryId];
  2785. setKey(dev, EntryId, EntryId,
  2786. priv->ieee80211->pairwise_key_type,
  2787. MacAddr, 0, NULL);
  2788. }
  2789. } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
  2790. if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
  2791. setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
  2792. (u8 *)dev->dev_addr, 0, NULL);
  2793. else
  2794. setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
  2795. MacAddr, 0, NULL);
  2796. } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
  2797. if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
  2798. setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
  2799. (u8 *)dev->dev_addr, 0, NULL);
  2800. else
  2801. setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
  2802. MacAddr, 0, NULL);
  2803. }
  2804. if (priv->ieee80211->group_key_type == KEY_TYPE_TKIP) {
  2805. MacAddr = CAM_CONST_BROAD;
  2806. for (EntryId = 1; EntryId < 4; EntryId++) {
  2807. setKey(dev, EntryId, EntryId,
  2808. priv->ieee80211->group_key_type,
  2809. MacAddr, 0, NULL);
  2810. }
  2811. if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
  2812. setKey(dev, 0, 0, priv->ieee80211->group_key_type,
  2813. CAM_CONST_ADDR[0], 0, NULL);
  2814. } else if (priv->ieee80211->group_key_type == KEY_TYPE_CCMP) {
  2815. MacAddr = CAM_CONST_BROAD;
  2816. for (EntryId = 1; EntryId < 4; EntryId++) {
  2817. setKey(dev, EntryId, EntryId,
  2818. priv->ieee80211->group_key_type,
  2819. MacAddr, 0, NULL);
  2820. }
  2821. if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
  2822. setKey(dev, 0, 0, priv->ieee80211->group_key_type,
  2823. CAM_CONST_ADDR[0], 0, NULL);
  2824. }
  2825. }
  2826. /* This function is used to fix Tx/Rx stop bug temporarily.
  2827. * This function will do "system reset" to NIC when Tx or Rx is stuck.
  2828. * The method checking Tx/Rx stuck of this function is supported by FW,
  2829. * which reports Tx and Rx counter to register 0x128 and 0x130.
  2830. */
  2831. static void rtl819x_ifsilentreset(struct net_device *dev)
  2832. {
  2833. struct r8192_priv *priv = ieee80211_priv(dev);
  2834. u8 reset_times = 0;
  2835. int reset_status = 0;
  2836. struct ieee80211_device *ieee = priv->ieee80211;
  2837. /* If we need to check CCK stop, please uncomment this line. */
  2838. /* bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter); */
  2839. if (priv->ResetProgress == RESET_TYPE_NORESET) {
  2840. RESET_START:
  2841. RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
  2842. /* Set the variable for reset. */
  2843. priv->ResetProgress = RESET_TYPE_SILENT;
  2844. down(&priv->wx_sem);
  2845. if (priv->up == 0) {
  2846. RT_TRACE(COMP_ERR,
  2847. "%s():the driver is not up! return\n",
  2848. __func__);
  2849. up(&priv->wx_sem);
  2850. return;
  2851. }
  2852. priv->up = 0;
  2853. RT_TRACE(COMP_RESET,
  2854. "%s():======>start to down the driver\n",
  2855. __func__);
  2856. rtl8192_rtx_disable(dev);
  2857. rtl8192_cancel_deferred_work(priv);
  2858. deinit_hal_dm(dev);
  2859. del_timer_sync(&priv->watch_dog_timer);
  2860. ieee->sync_scan_hurryup = 1;
  2861. if (ieee->state == IEEE80211_LINKED) {
  2862. down(&ieee->wx_sem);
  2863. netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
  2864. ieee80211_stop_send_beacons(priv->ieee80211);
  2865. del_timer_sync(&ieee->associate_timer);
  2866. cancel_delayed_work(&ieee->associate_retry_wq);
  2867. ieee80211_stop_scan(ieee);
  2868. netif_carrier_off(dev);
  2869. up(&ieee->wx_sem);
  2870. } else {
  2871. netdev_dbg(dev, "ieee->state is NOT LINKED\n");
  2872. ieee80211_softmac_stop_protocol(priv->ieee80211);
  2873. }
  2874. up(&priv->wx_sem);
  2875. RT_TRACE(COMP_RESET,
  2876. "%s():<==========down process is finished\n",
  2877. __func__);
  2878. RT_TRACE(COMP_RESET,
  2879. "%s():===========>start up the driver\n",
  2880. __func__);
  2881. reset_status = _rtl8192_up(dev);
  2882. RT_TRACE(COMP_RESET,
  2883. "%s():<===========up process is finished\n",
  2884. __func__);
  2885. if (reset_status == -EAGAIN) {
  2886. if (reset_times < 3) {
  2887. reset_times++;
  2888. goto RESET_START;
  2889. } else {
  2890. RT_TRACE(COMP_ERR,
  2891. " ERR!!! %s(): Reset Failed!!\n",
  2892. __func__);
  2893. }
  2894. }
  2895. ieee->is_silent_reset = 1;
  2896. EnableHWSecurityConfig8192(dev);
  2897. if (ieee->state == IEEE80211_LINKED &&
  2898. ieee->iw_mode == IW_MODE_INFRA) {
  2899. ieee->set_chan(ieee->dev,
  2900. ieee->current_network.channel);
  2901. queue_work(ieee->wq, &ieee->associate_complete_wq);
  2902. } else if (ieee->state == IEEE80211_LINKED &&
  2903. ieee->iw_mode == IW_MODE_ADHOC) {
  2904. ieee->set_chan(ieee->dev,
  2905. ieee->current_network.channel);
  2906. ieee->link_change(ieee->dev);
  2907. ieee80211_start_send_beacons(ieee);
  2908. if (ieee->data_hard_resume)
  2909. ieee->data_hard_resume(ieee->dev);
  2910. netif_carrier_on(ieee->dev);
  2911. }
  2912. CamRestoreAllEntry(dev);
  2913. priv->ResetProgress = RESET_TYPE_NORESET;
  2914. priv->reset_count++;
  2915. priv->bForcedSilentReset = false;
  2916. priv->bResetInProgress = false;
  2917. /* For test --> force write UFWP. */
  2918. write_nic_byte(dev, UFWP, 1);
  2919. RT_TRACE(COMP_RESET,
  2920. "Reset finished!! ====>[%d]\n",
  2921. priv->reset_count);
  2922. }
  2923. }
  2924. static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
  2925. u32 *TotalRxDataNum)
  2926. {
  2927. u16 SlotIndex;
  2928. u8 i;
  2929. *TotalRxBcnNum = 0;
  2930. *TotalRxDataNum = 0;
  2931. SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++) %
  2932. (priv->ieee80211->LinkDetectInfo.SlotNum);
  2933. priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] =
  2934. priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
  2935. priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] =
  2936. priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
  2937. for (i = 0; i < priv->ieee80211->LinkDetectInfo.SlotNum; i++) {
  2938. *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
  2939. *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
  2940. }
  2941. }
  2942. static void rtl819x_watchdog_wqcallback(struct work_struct *work)
  2943. {
  2944. struct delayed_work *dwork = container_of(work,
  2945. struct delayed_work, work);
  2946. struct r8192_priv *priv = container_of(dwork,
  2947. struct r8192_priv, watch_dog_wq);
  2948. struct net_device *dev = priv->ieee80211->dev;
  2949. struct ieee80211_device *ieee = priv->ieee80211;
  2950. RESET_TYPE ResetType = RESET_TYPE_NORESET;
  2951. static u8 check_reset_cnt;
  2952. bool bBusyTraffic = false;
  2953. u32 TotalRxBcnNum = 0;
  2954. u32 TotalRxDataNum = 0;
  2955. if (!priv->up)
  2956. return;
  2957. hal_dm_watchdog(dev);
  2958. /* to get busy traffic condition */
  2959. if (ieee->state == IEEE80211_LINKED) {
  2960. if (ieee->LinkDetectInfo.NumRxOkInPeriod > 666 ||
  2961. ieee->LinkDetectInfo.NumTxOkInPeriod > 666) {
  2962. bBusyTraffic = true;
  2963. }
  2964. ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
  2965. ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
  2966. ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
  2967. }
  2968. /* for AP roaming */
  2969. if (priv->ieee80211->state == IEEE80211_LINKED &&
  2970. priv->ieee80211->iw_mode == IW_MODE_INFRA) {
  2971. rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
  2972. if ((TotalRxBcnNum + TotalRxDataNum) == 0) {
  2973. #ifdef TODO
  2974. if (rfState == eRfOff)
  2975. RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
  2976. #endif
  2977. netdev_dbg(dev,
  2978. "===>%s(): AP is power off, connect another one\n",
  2979. __func__);
  2980. priv->ieee80211->state = IEEE80211_ASSOCIATING;
  2981. notify_wx_assoc_event(priv->ieee80211);
  2982. RemovePeerTS(priv->ieee80211,
  2983. priv->ieee80211->current_network.bssid);
  2984. priv->ieee80211->link_change(dev);
  2985. queue_work(priv->ieee80211->wq,
  2986. &priv->ieee80211->associate_procedure_wq);
  2987. }
  2988. }
  2989. priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
  2990. priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod = 0;
  2991. /* check if reset the driver */
  2992. if (check_reset_cnt++ >= 3) {
  2993. ResetType = rtl819x_ifcheck_resetornot(dev);
  2994. check_reset_cnt = 3;
  2995. }
  2996. /* This is control by OID set in Pomelo */
  2997. if ((priv->force_reset) || (priv->ResetProgress == RESET_TYPE_NORESET &&
  2998. (priv->bForcedSilentReset ||
  2999. (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) {
  3000. RT_TRACE(COMP_RESET,
  3001. "%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n",
  3002. __func__, priv->force_reset, priv->ResetProgress,
  3003. priv->bForcedSilentReset,
  3004. priv->bDisableNormalResetCheck, ResetType);
  3005. rtl819x_ifsilentreset(dev);
  3006. }
  3007. priv->force_reset = false;
  3008. priv->bForcedSilentReset = false;
  3009. priv->bResetInProgress = false;
  3010. RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
  3011. }
  3012. static void watch_dog_timer_callback(unsigned long data)
  3013. {
  3014. struct r8192_priv *priv = ieee80211_priv((struct net_device *)data);
  3015. queue_delayed_work(priv->priv_wq, &priv->watch_dog_wq, 0);
  3016. mod_timer(&priv->watch_dog_timer,
  3017. jiffies + msecs_to_jiffies(IEEE80211_WATCH_DOG_TIME));
  3018. }
  3019. static int _rtl8192_up(struct net_device *dev)
  3020. {
  3021. struct r8192_priv *priv = ieee80211_priv(dev);
  3022. int init_status = 0;
  3023. priv->up = 1;
  3024. priv->ieee80211->ieee_up = 1;
  3025. RT_TRACE(COMP_INIT, "Bringing up iface");
  3026. init_status = rtl8192_adapter_start(dev);
  3027. if (!init_status) {
  3028. RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n",
  3029. __func__);
  3030. priv->up = priv->ieee80211->ieee_up = 0;
  3031. return -EAGAIN;
  3032. }
  3033. RT_TRACE(COMP_INIT, "start adapter finished\n");
  3034. rtl8192_rx_enable(dev);
  3035. if (priv->ieee80211->state != IEEE80211_LINKED)
  3036. ieee80211_softmac_start_protocol(priv->ieee80211);
  3037. ieee80211_reset_queue(priv->ieee80211);
  3038. watch_dog_timer_callback((unsigned long)dev);
  3039. if (!netif_queue_stopped(dev))
  3040. netif_start_queue(dev);
  3041. else
  3042. netif_wake_queue(dev);
  3043. return 0;
  3044. }
  3045. static int rtl8192_open(struct net_device *dev)
  3046. {
  3047. struct r8192_priv *priv = ieee80211_priv(dev);
  3048. int ret;
  3049. down(&priv->wx_sem);
  3050. ret = rtl8192_up(dev);
  3051. up(&priv->wx_sem);
  3052. return ret;
  3053. }
  3054. int rtl8192_up(struct net_device *dev)
  3055. {
  3056. struct r8192_priv *priv = ieee80211_priv(dev);
  3057. if (priv->up == 1)
  3058. return -1;
  3059. return _rtl8192_up(dev);
  3060. }
  3061. static int rtl8192_close(struct net_device *dev)
  3062. {
  3063. struct r8192_priv *priv = ieee80211_priv(dev);
  3064. int ret;
  3065. down(&priv->wx_sem);
  3066. ret = rtl8192_down(dev);
  3067. up(&priv->wx_sem);
  3068. return ret;
  3069. }
  3070. int rtl8192_down(struct net_device *dev)
  3071. {
  3072. struct r8192_priv *priv = ieee80211_priv(dev);
  3073. int i;
  3074. if (priv->up == 0)
  3075. return -1;
  3076. priv->up = 0;
  3077. priv->ieee80211->ieee_up = 0;
  3078. RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
  3079. /* FIXME */
  3080. if (!netif_queue_stopped(dev))
  3081. netif_stop_queue(dev);
  3082. rtl8192_rtx_disable(dev);
  3083. /* Tx related queue release */
  3084. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  3085. skb_queue_purge(&priv->ieee80211->skb_waitQ[i]);
  3086. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  3087. skb_queue_purge(&priv->ieee80211->skb_aggQ[i]);
  3088. for (i = 0; i < MAX_QUEUE_SIZE; i++)
  3089. skb_queue_purge(&priv->ieee80211->skb_drv_aggQ[i]);
  3090. /* as cancel_delayed_work will del work->timer, so if work is not
  3091. * defined as struct delayed_work, it will corrupt
  3092. */
  3093. rtl8192_cancel_deferred_work(priv);
  3094. deinit_hal_dm(dev);
  3095. del_timer_sync(&priv->watch_dog_timer);
  3096. ieee80211_softmac_stop_protocol(priv->ieee80211);
  3097. memset(&priv->ieee80211->current_network, 0,
  3098. offsetof(struct ieee80211_network, list));
  3099. RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
  3100. return 0;
  3101. }
  3102. void rtl8192_commit(struct net_device *dev)
  3103. {
  3104. struct r8192_priv *priv = ieee80211_priv(dev);
  3105. int reset_status = 0;
  3106. if (priv->up == 0)
  3107. return;
  3108. priv->up = 0;
  3109. rtl8192_cancel_deferred_work(priv);
  3110. del_timer_sync(&priv->watch_dog_timer);
  3111. ieee80211_softmac_stop_protocol(priv->ieee80211);
  3112. rtl8192_rtx_disable(dev);
  3113. reset_status = _rtl8192_up(dev);
  3114. }
  3115. static void rtl8192_restart(struct work_struct *work)
  3116. {
  3117. struct r8192_priv *priv = container_of(work, struct r8192_priv,
  3118. reset_wq);
  3119. struct net_device *dev = priv->ieee80211->dev;
  3120. down(&priv->wx_sem);
  3121. rtl8192_commit(dev);
  3122. up(&priv->wx_sem);
  3123. }
  3124. static void r8192_set_multicast(struct net_device *dev)
  3125. {
  3126. struct r8192_priv *priv = ieee80211_priv(dev);
  3127. short promisc;
  3128. /* FIXME FIXME */
  3129. promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
  3130. if (promisc != priv->promisc)
  3131. priv->promisc = promisc;
  3132. }
  3133. static int r8192_set_mac_adr(struct net_device *dev, void *mac)
  3134. {
  3135. struct r8192_priv *priv = ieee80211_priv(dev);
  3136. struct sockaddr *addr = mac;
  3137. down(&priv->wx_sem);
  3138. ether_addr_copy(dev->dev_addr, addr->sa_data);
  3139. schedule_work(&priv->reset_wq);
  3140. up(&priv->wx_sem);
  3141. return 0;
  3142. }
  3143. /* based on ipw2200 driver */
  3144. static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3145. {
  3146. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  3147. struct iwreq *wrq = (struct iwreq *)rq;
  3148. int ret = -1;
  3149. struct ieee80211_device *ieee = priv->ieee80211;
  3150. u32 key[4];
  3151. u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3152. struct iw_point *p = &wrq->u.data;
  3153. struct ieee_param *ipw = NULL;
  3154. down(&priv->wx_sem);
  3155. if (p->length < sizeof(struct ieee_param) || !p->pointer) {
  3156. ret = -EINVAL;
  3157. goto out;
  3158. }
  3159. ipw = memdup_user(p->pointer, p->length);
  3160. if (IS_ERR(ipw)) {
  3161. ret = PTR_ERR(ipw);
  3162. goto out;
  3163. }
  3164. switch (cmd) {
  3165. case RTL_IOCTL_WPA_SUPPLICANT:
  3166. /* parse here for HW security */
  3167. if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
  3168. if (ipw->u.crypt.set_tx) {
  3169. if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
  3170. ieee->pairwise_key_type = KEY_TYPE_CCMP;
  3171. } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
  3172. ieee->pairwise_key_type = KEY_TYPE_TKIP;
  3173. } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
  3174. if (ipw->u.crypt.key_len == 13)
  3175. ieee->pairwise_key_type = KEY_TYPE_WEP104;
  3176. else if (ipw->u.crypt.key_len == 5)
  3177. ieee->pairwise_key_type = KEY_TYPE_WEP40;
  3178. } else {
  3179. ieee->pairwise_key_type = KEY_TYPE_NA;
  3180. }
  3181. if (ieee->pairwise_key_type) {
  3182. memcpy((u8 *)key, ipw->u.crypt.key, 16);
  3183. EnableHWSecurityConfig8192(dev);
  3184. /* We fill both index entry and 4th
  3185. * entry for pairwise key as in IPW
  3186. * interface, adhoc will only get here,
  3187. * so we need index entry for its
  3188. * default key serching!
  3189. */
  3190. setKey(dev, 4, ipw->u.crypt.idx,
  3191. ieee->pairwise_key_type,
  3192. (u8 *)ieee->ap_mac_addr,
  3193. 0, key);
  3194. if (ieee->auth_mode != 2)
  3195. setKey(dev, ipw->u.crypt.idx,
  3196. ipw->u.crypt.idx,
  3197. ieee->pairwise_key_type,
  3198. (u8 *)ieee->ap_mac_addr,
  3199. 0, key);
  3200. }
  3201. } else {
  3202. memcpy((u8 *)key, ipw->u.crypt.key, 16);
  3203. if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
  3204. ieee->group_key_type = KEY_TYPE_CCMP;
  3205. } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
  3206. ieee->group_key_type = KEY_TYPE_TKIP;
  3207. } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
  3208. if (ipw->u.crypt.key_len == 13)
  3209. ieee->group_key_type = KEY_TYPE_WEP104;
  3210. else if (ipw->u.crypt.key_len == 5)
  3211. ieee->group_key_type = KEY_TYPE_WEP40;
  3212. } else {
  3213. ieee->group_key_type = KEY_TYPE_NA;
  3214. }
  3215. if (ieee->group_key_type) {
  3216. setKey(dev, ipw->u.crypt.idx,
  3217. /* KeyIndex */
  3218. ipw->u.crypt.idx,
  3219. /* KeyType */
  3220. ieee->group_key_type,
  3221. /* MacAddr */
  3222. broadcast_addr,
  3223. /* DefaultKey */
  3224. 0,
  3225. /* KeyContent */
  3226. key);
  3227. }
  3228. }
  3229. }
  3230. ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211,
  3231. &wrq->u.data);
  3232. break;
  3233. default:
  3234. ret = -EOPNOTSUPP;
  3235. break;
  3236. }
  3237. kfree(ipw);
  3238. ipw = NULL;
  3239. out:
  3240. up(&priv->wx_sem);
  3241. return ret;
  3242. }
  3243. static u8 HwRateToMRate90(bool bIsHT, u8 rate)
  3244. {
  3245. u8 ret_rate = 0xff;
  3246. if (!bIsHT) {
  3247. switch (rate) {
  3248. case DESC90_RATE1M:
  3249. ret_rate = MGN_1M;
  3250. break;
  3251. case DESC90_RATE2M:
  3252. ret_rate = MGN_2M;
  3253. break;
  3254. case DESC90_RATE5_5M:
  3255. ret_rate = MGN_5_5M;
  3256. break;
  3257. case DESC90_RATE11M:
  3258. ret_rate = MGN_11M;
  3259. break;
  3260. case DESC90_RATE6M:
  3261. ret_rate = MGN_6M;
  3262. break;
  3263. case DESC90_RATE9M:
  3264. ret_rate = MGN_9M;
  3265. break;
  3266. case DESC90_RATE12M:
  3267. ret_rate = MGN_12M;
  3268. break;
  3269. case DESC90_RATE18M:
  3270. ret_rate = MGN_18M;
  3271. break;
  3272. case DESC90_RATE24M:
  3273. ret_rate = MGN_24M;
  3274. break;
  3275. case DESC90_RATE36M:
  3276. ret_rate = MGN_36M;
  3277. break;
  3278. case DESC90_RATE48M:
  3279. ret_rate = MGN_48M;
  3280. break;
  3281. case DESC90_RATE54M:
  3282. ret_rate = MGN_54M;
  3283. break;
  3284. default:
  3285. ret_rate = 0xff;
  3286. RT_TRACE(COMP_RECV,
  3287. "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",
  3288. rate, bIsHT);
  3289. break;
  3290. }
  3291. } else {
  3292. switch (rate) {
  3293. case DESC90_RATEMCS0:
  3294. ret_rate = MGN_MCS0;
  3295. break;
  3296. case DESC90_RATEMCS1:
  3297. ret_rate = MGN_MCS1;
  3298. break;
  3299. case DESC90_RATEMCS2:
  3300. ret_rate = MGN_MCS2;
  3301. break;
  3302. case DESC90_RATEMCS3:
  3303. ret_rate = MGN_MCS3;
  3304. break;
  3305. case DESC90_RATEMCS4:
  3306. ret_rate = MGN_MCS4;
  3307. break;
  3308. case DESC90_RATEMCS5:
  3309. ret_rate = MGN_MCS5;
  3310. break;
  3311. case DESC90_RATEMCS6:
  3312. ret_rate = MGN_MCS6;
  3313. break;
  3314. case DESC90_RATEMCS7:
  3315. ret_rate = MGN_MCS7;
  3316. break;
  3317. case DESC90_RATEMCS8:
  3318. ret_rate = MGN_MCS8;
  3319. break;
  3320. case DESC90_RATEMCS9:
  3321. ret_rate = MGN_MCS9;
  3322. break;
  3323. case DESC90_RATEMCS10:
  3324. ret_rate = MGN_MCS10;
  3325. break;
  3326. case DESC90_RATEMCS11:
  3327. ret_rate = MGN_MCS11;
  3328. break;
  3329. case DESC90_RATEMCS12:
  3330. ret_rate = MGN_MCS12;
  3331. break;
  3332. case DESC90_RATEMCS13:
  3333. ret_rate = MGN_MCS13;
  3334. break;
  3335. case DESC90_RATEMCS14:
  3336. ret_rate = MGN_MCS14;
  3337. break;
  3338. case DESC90_RATEMCS15:
  3339. ret_rate = MGN_MCS15;
  3340. break;
  3341. case DESC90_RATEMCS32:
  3342. ret_rate = 0x80 | 0x20;
  3343. break;
  3344. default:
  3345. ret_rate = 0xff;
  3346. RT_TRACE(COMP_RECV,
  3347. "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",
  3348. rate, bIsHT);
  3349. break;
  3350. }
  3351. }
  3352. return ret_rate;
  3353. }
  3354. /**
  3355. * Function: UpdateRxPktTimeStamp
  3356. * Overview: Record the TSF time stamp when receiving a packet
  3357. *
  3358. * Input:
  3359. * PADAPTER Adapter
  3360. * PRT_RFD pRfd,
  3361. *
  3362. * Output:
  3363. * PRT_RFD pRfd
  3364. * (pRfd->Status.TimeStampHigh is updated)
  3365. * (pRfd->Status.TimeStampLow is updated)
  3366. * Return:
  3367. * None
  3368. */
  3369. static void UpdateRxPktTimeStamp8190(struct net_device *dev,
  3370. struct ieee80211_rx_stats *stats)
  3371. {
  3372. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  3373. if (stats->bIsAMPDU && !stats->bFirstMPDU) {
  3374. stats->mac_time[0] = priv->LastRxDescTSFLow;
  3375. stats->mac_time[1] = priv->LastRxDescTSFHigh;
  3376. } else {
  3377. priv->LastRxDescTSFLow = stats->mac_time[0];
  3378. priv->LastRxDescTSFHigh = stats->mac_time[1];
  3379. }
  3380. }
  3381. /* 0-100 index. */
  3382. static long rtl819x_translate_todbm(u8 signal_strength_index)
  3383. {
  3384. long signal_power; /* in dBm. */
  3385. /* Translate to dBm (x=0.5y-95). */
  3386. signal_power = (long)((signal_strength_index + 1) >> 1);
  3387. signal_power -= 95;
  3388. return signal_power;
  3389. }
  3390. /* We can not declare RSSI/EVM total value of sliding window to
  3391. * be a local static. Otherwise, it may increase when we return from S3/S4. The
  3392. * value will be kept in memory or disk. Declare the value in the adaptor
  3393. * and it will be reinitialized when returned from S3/S4.
  3394. */
  3395. static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
  3396. struct ieee80211_rx_stats *pprevious_stats,
  3397. struct ieee80211_rx_stats *pcurrent_stats)
  3398. {
  3399. bool bcheck = false;
  3400. u8 rfpath;
  3401. u32 nspatial_stream, tmp_val;
  3402. static u32 slide_rssi_index, slide_rssi_statistics;
  3403. static u32 slide_evm_index, slide_evm_statistics;
  3404. static u32 last_rssi, last_evm;
  3405. static u32 slide_beacon_adc_pwdb_index;
  3406. static u32 slide_beacon_adc_pwdb_statistics;
  3407. static u32 last_beacon_adc_pwdb;
  3408. struct rtl_80211_hdr_3addr *hdr;
  3409. u16 sc;
  3410. unsigned int frag, seq;
  3411. hdr = (struct rtl_80211_hdr_3addr *)buffer;
  3412. sc = le16_to_cpu(hdr->seq_ctl);
  3413. frag = WLAN_GET_SEQ_FRAG(sc);
  3414. seq = WLAN_GET_SEQ_SEQ(sc);
  3415. /* to record the sequence number */
  3416. pcurrent_stats->Seq_Num = seq;
  3417. /* Check whether we should take the previous packet into accounting */
  3418. if (!pprevious_stats->bIsAMPDU) {
  3419. /* if previous packet is not aggregated packet */
  3420. bcheck = true;
  3421. }
  3422. if (slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
  3423. slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
  3424. last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
  3425. priv->stats.slide_rssi_total -= last_rssi;
  3426. }
  3427. priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
  3428. priv->stats.slide_signal_strength[slide_rssi_index++] =
  3429. pprevious_stats->SignalStrength;
  3430. if (slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
  3431. slide_rssi_index = 0;
  3432. /* <1> Showed on UI for user, in dbm */
  3433. tmp_val = priv->stats.slide_rssi_total / slide_rssi_statistics;
  3434. priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
  3435. pcurrent_stats->rssi = priv->stats.signal_strength;
  3436. /* If the previous packet does not match the criteria, neglect it */
  3437. if (!pprevious_stats->bPacketMatchBSSID) {
  3438. if (!pprevious_stats->bToSelfBA)
  3439. return;
  3440. }
  3441. if (!bcheck)
  3442. return;
  3443. /* only rtl8190 supported
  3444. * rtl8190_process_cck_rxpathsel(priv,pprevious_stats);
  3445. */
  3446. /* Check RSSI */
  3447. priv->stats.num_process_phyinfo++;
  3448. /* record the general signal strength to the sliding window. */
  3449. /* <2> Showed on UI for engineering
  3450. * hardware does not provide rssi information for each rf path in CCK
  3451. */
  3452. if (!pprevious_stats->bIsCCK &&
  3453. (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
  3454. for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++) {
  3455. if (!rtl8192_phy_CheckIsLegalRFPath(
  3456. priv->ieee80211->dev, rfpath))
  3457. continue;
  3458. if (priv->stats.rx_rssi_percentage[rfpath] == 0)
  3459. priv->stats.rx_rssi_percentage[rfpath] =
  3460. pprevious_stats->RxMIMOSignalStrength[rfpath];
  3461. if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) {
  3462. priv->stats.rx_rssi_percentage[rfpath] =
  3463. ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) +
  3464. (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor);
  3465. priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
  3466. } else {
  3467. priv->stats.rx_rssi_percentage[rfpath] =
  3468. ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) +
  3469. (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor);
  3470. }
  3471. RT_TRACE(COMP_DBG,
  3472. "priv->stats.rx_rssi_percentage[rfPath] = %d\n",
  3473. priv->stats.rx_rssi_percentage[rfpath]);
  3474. }
  3475. }
  3476. /* Check PWDB. */
  3477. RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
  3478. pprevious_stats->bIsCCK ? "CCK" : "OFDM",
  3479. pprevious_stats->RxPWDBAll);
  3480. if (pprevious_stats->bPacketBeacon) {
  3481. /* record the beacon pwdb to the sliding window. */
  3482. if (slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) {
  3483. slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
  3484. last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
  3485. priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
  3486. }
  3487. priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
  3488. priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
  3489. slide_beacon_adc_pwdb_index++;
  3490. if (slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
  3491. slide_beacon_adc_pwdb_index = 0;
  3492. pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total / slide_beacon_adc_pwdb_statistics;
  3493. if (pprevious_stats->RxPWDBAll >= 3)
  3494. pprevious_stats->RxPWDBAll -= 3;
  3495. }
  3496. RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
  3497. pprevious_stats->bIsCCK ? "CCK" : "OFDM",
  3498. pprevious_stats->RxPWDBAll);
  3499. if (pprevious_stats->bPacketToSelf ||
  3500. pprevious_stats->bPacketBeacon ||
  3501. pprevious_stats->bToSelfBA) {
  3502. if (priv->undecorated_smoothed_pwdb < 0)
  3503. /* initialize */
  3504. priv->undecorated_smoothed_pwdb =
  3505. pprevious_stats->RxPWDBAll;
  3506. if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
  3507. priv->undecorated_smoothed_pwdb =
  3508. (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) +
  3509. (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor);
  3510. priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
  3511. } else {
  3512. priv->undecorated_smoothed_pwdb =
  3513. (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) +
  3514. (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor);
  3515. }
  3516. }
  3517. /* Check EVM */
  3518. /* record the general EVM to the sliding window. */
  3519. if (pprevious_stats->SignalQuality) {
  3520. if (pprevious_stats->bPacketToSelf ||
  3521. pprevious_stats->bPacketBeacon ||
  3522. pprevious_stats->bToSelfBA) {
  3523. if (slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
  3524. slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
  3525. last_evm = priv->stats.slide_evm[slide_evm_index];
  3526. priv->stats.slide_evm_total -= last_evm;
  3527. }
  3528. priv->stats.slide_evm_total +=
  3529. pprevious_stats->SignalQuality;
  3530. priv->stats.slide_evm[slide_evm_index++] =
  3531. pprevious_stats->SignalQuality;
  3532. if (slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
  3533. slide_evm_index = 0;
  3534. /* <1> Showed on UI for user, in percentage. */
  3535. tmp_val = priv->stats.slide_evm_total /
  3536. slide_evm_statistics;
  3537. priv->stats.signal_quality = tmp_val;
  3538. /* Showed on UI for user in Windows Vista,
  3539. * for Link quality.
  3540. */
  3541. priv->stats.last_signal_strength_inpercent = tmp_val;
  3542. }
  3543. /* <2> Showed on UI for engineering */
  3544. if (pprevious_stats->bPacketToSelf ||
  3545. pprevious_stats->bPacketBeacon ||
  3546. pprevious_stats->bToSelfBA) {
  3547. for (nspatial_stream = 0; nspatial_stream < 2; nspatial_stream++) { /* 2 spatial stream */
  3548. if (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) {
  3549. if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) /* initialize */
  3550. priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
  3551. priv->stats.rx_evm_percentage[nspatial_stream] =
  3552. ((priv->stats.rx_evm_percentage[nspatial_stream] * (Rx_Smooth_Factor - 1)) +
  3553. (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (Rx_Smooth_Factor);
  3554. }
  3555. }
  3556. }
  3557. }
  3558. }
  3559. /*-----------------------------------------------------------------------------
  3560. * Function: rtl819x_query_rxpwrpercentage()
  3561. *
  3562. * Overview:
  3563. *
  3564. * Input: char antpower
  3565. *
  3566. * Output: NONE
  3567. *
  3568. * Return: 0-100 percentage
  3569. *---------------------------------------------------------------------------*/
  3570. static u8 rtl819x_query_rxpwrpercentage(char antpower)
  3571. {
  3572. if ((antpower <= -100) || (antpower >= 20))
  3573. return 0;
  3574. else if (antpower >= 0)
  3575. return 100;
  3576. else
  3577. return 100 + antpower;
  3578. } /* QueryRxPwrPercentage */
  3579. static u8 rtl819x_evm_dbtopercentage(char value)
  3580. {
  3581. char ret_val;
  3582. ret_val = value;
  3583. if (ret_val >= 0)
  3584. ret_val = 0;
  3585. if (ret_val <= -33)
  3586. ret_val = -33;
  3587. ret_val = 0 - ret_val;
  3588. ret_val *= 3;
  3589. if (ret_val == 99)
  3590. ret_val = 100;
  3591. return ret_val;
  3592. }
  3593. /* We want good-looking for signal strength/quality */
  3594. static long rtl819x_signal_scale_mapping(long currsig)
  3595. {
  3596. long retsig;
  3597. /* Step 1. Scale mapping. */
  3598. if (currsig >= 61 && currsig <= 100)
  3599. retsig = 90 + ((currsig - 60) / 4);
  3600. else if (currsig >= 41 && currsig <= 60)
  3601. retsig = 78 + ((currsig - 40) / 2);
  3602. else if (currsig >= 31 && currsig <= 40)
  3603. retsig = 66 + (currsig - 30);
  3604. else if (currsig >= 21 && currsig <= 30)
  3605. retsig = 54 + (currsig - 20);
  3606. else if (currsig >= 5 && currsig <= 20)
  3607. retsig = 42 + (((currsig - 5) * 2) / 3);
  3608. else if (currsig == 4)
  3609. retsig = 36;
  3610. else if (currsig == 3)
  3611. retsig = 27;
  3612. else if (currsig == 2)
  3613. retsig = 18;
  3614. else if (currsig == 1)
  3615. retsig = 9;
  3616. else
  3617. retsig = currsig;
  3618. return retsig;
  3619. }
  3620. static inline bool rx_hal_is_cck_rate(struct rx_drvinfo_819x_usb *pdrvinfo)
  3621. {
  3622. if (pdrvinfo->RxHT)
  3623. return false;
  3624. switch (pdrvinfo->RxRate) {
  3625. case DESC90_RATE1M:
  3626. case DESC90_RATE2M:
  3627. case DESC90_RATE5_5M:
  3628. case DESC90_RATE11M:
  3629. return true;
  3630. default:
  3631. return false;
  3632. }
  3633. }
  3634. static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
  3635. struct ieee80211_rx_stats *pstats,
  3636. rx_drvinfo_819x_usb *pdrvinfo,
  3637. struct ieee80211_rx_stats *precord_stats,
  3638. bool bpacket_match_bssid,
  3639. bool bpacket_toself,
  3640. bool bPacketBeacon,
  3641. bool bToSelfBA)
  3642. {
  3643. phy_sts_ofdm_819xusb_t *pofdm_buf;
  3644. phy_sts_cck_819xusb_t *pcck_buf;
  3645. phy_ofdm_rx_status_rxsc_sgien_exintfflag *prxsc;
  3646. u8 *prxpkt;
  3647. u8 i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
  3648. char rx_pwr[4], rx_pwr_all = 0;
  3649. char rx_snrX, rx_evmX;
  3650. u8 evm, pwdb_all;
  3651. u32 RSSI, total_rssi = 0;
  3652. u8 is_cck_rate = 0;
  3653. u8 rf_rx_num = 0;
  3654. u8 sq;
  3655. priv->stats.numqry_phystatus++;
  3656. is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
  3657. /* Record it for next packet processing */
  3658. memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
  3659. pstats->bPacketMatchBSSID =
  3660. precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
  3661. pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
  3662. pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;
  3663. pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
  3664. pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
  3665. prxpkt = (u8 *)pdrvinfo;
  3666. /* Move pointer to the 16th bytes. Phy status start address. */
  3667. prxpkt += sizeof(rx_drvinfo_819x_usb);
  3668. /* Initial the cck and ofdm buffer pointer */
  3669. pcck_buf = (phy_sts_cck_819xusb_t *)prxpkt;
  3670. pofdm_buf = (phy_sts_ofdm_819xusb_t *)prxpkt;
  3671. pstats->RxMIMOSignalQuality[0] = -1;
  3672. pstats->RxMIMOSignalQuality[1] = -1;
  3673. precord_stats->RxMIMOSignalQuality[0] = -1;
  3674. precord_stats->RxMIMOSignalQuality[1] = -1;
  3675. if (is_cck_rate) {
  3676. /* (1)Hardware does not provide RSSI for CCK */
  3677. /* (2)PWDB, Average PWDB cacluated by hardware
  3678. * (for rate adaptive)
  3679. */
  3680. u8 report;
  3681. priv->stats.numqry_phystatusCCK++;
  3682. if (!priv->bCckHighPower) {
  3683. report = pcck_buf->cck_agc_rpt & 0xc0;
  3684. report >>= 6;
  3685. switch (report) {
  3686. case 0x3:
  3687. rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
  3688. break;
  3689. case 0x2:
  3690. rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
  3691. break;
  3692. case 0x1:
  3693. rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
  3694. break;
  3695. case 0x0:
  3696. rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
  3697. break;
  3698. }
  3699. } else {
  3700. report = pcck_buf->cck_agc_rpt & 0x60;
  3701. report >>= 5;
  3702. switch (report) {
  3703. case 0x3:
  3704. rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
  3705. break;
  3706. case 0x2:
  3707. rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
  3708. break;
  3709. case 0x1:
  3710. rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
  3711. break;
  3712. case 0x0:
  3713. rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
  3714. break;
  3715. }
  3716. }
  3717. pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
  3718. pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
  3719. pstats->RecvSignalPower = pwdb_all;
  3720. /* (3) Get Signal Quality (EVM) */
  3721. if (pstats->RxPWDBAll > 40) {
  3722. sq = 100;
  3723. } else {
  3724. sq = pcck_buf->sq_rpt;
  3725. if (pcck_buf->sq_rpt > 64)
  3726. sq = 0;
  3727. else if (pcck_buf->sq_rpt < 20)
  3728. sq = 100;
  3729. else
  3730. sq = ((64 - sq) * 100) / 44;
  3731. }
  3732. pstats->SignalQuality = precord_stats->SignalQuality = sq;
  3733. pstats->RxMIMOSignalQuality[0] =
  3734. precord_stats->RxMIMOSignalQuality[0] = sq;
  3735. pstats->RxMIMOSignalQuality[1] =
  3736. precord_stats->RxMIMOSignalQuality[1] = -1;
  3737. } else {
  3738. priv->stats.numqry_phystatusHT++;
  3739. /* (1)Get RSSI for HT rate */
  3740. for (i = RF90_PATH_A; i < priv->NumTotalRFPath; i++) {
  3741. /* We will judge RF RX path now. */
  3742. if (priv->brfpath_rxenable[i])
  3743. rf_rx_num++;
  3744. else
  3745. continue;
  3746. if (!rtl8192_phy_CheckIsLegalRFPath(
  3747. priv->ieee80211->dev, i))
  3748. continue;
  3749. rx_pwr[i] =
  3750. ((pofdm_buf->trsw_gain_X[i] & 0x3F) * 2) - 106;
  3751. /* Get Rx snr value in DB */
  3752. tmp_rxsnr = pofdm_buf->rxsnr_X[i];
  3753. rx_snrX = (char)(tmp_rxsnr);
  3754. rx_snrX /= 2;
  3755. priv->stats.rxSNRdB[i] = (long)rx_snrX;
  3756. /* Translate DBM to percentage. */
  3757. RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
  3758. total_rssi += RSSI;
  3759. /* Record Signal Strength for next packet */
  3760. pstats->RxMIMOSignalStrength[i] = (u8)RSSI;
  3761. precord_stats->RxMIMOSignalStrength[i] = (u8)RSSI;
  3762. }
  3763. /* (2)PWDB, Average PWDB cacluated by hardware
  3764. * (for rate adaptive)
  3765. */
  3766. rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1) & 0x7f) - 106;
  3767. pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
  3768. pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
  3769. pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
  3770. /* (3)EVM of HT rate */
  3771. if (pdrvinfo->RxHT && pdrvinfo->RxRate >= DESC90_RATEMCS8 &&
  3772. pdrvinfo->RxRate <= DESC90_RATEMCS15)
  3773. /* both spatial stream make sense */
  3774. max_spatial_stream = 2;
  3775. else
  3776. /* only spatial stream 1 makes sense */
  3777. max_spatial_stream = 1;
  3778. for (i = 0; i < max_spatial_stream; i++) {
  3779. tmp_rxevm = pofdm_buf->rxevm_X[i];
  3780. rx_evmX = (char)(tmp_rxevm);
  3781. /* Do not use shift operation like "rx_evmX >>= 1"
  3782. * because the compiler of free build environment will
  3783. * set the most significant bit to "zero" when doing
  3784. * shifting operation which may change a negative value
  3785. * to positive one, then the dbm value (which is
  3786. * supposed to be negative) is not correct anymore.
  3787. */
  3788. rx_evmX /= 2; /* dbm */
  3789. evm = rtl819x_evm_dbtopercentage(rx_evmX);
  3790. if (i == 0)
  3791. /* Fill value in RFD, Get the first spatial
  3792. * stream only
  3793. */
  3794. pstats->SignalQuality =
  3795. precord_stats->SignalQuality =
  3796. (u8)(evm & 0xff);
  3797. pstats->RxMIMOSignalQuality[i] =
  3798. precord_stats->RxMIMOSignalQuality[i] =
  3799. (u8)(evm & 0xff);
  3800. }
  3801. /* record rx statistics for debug */
  3802. rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
  3803. prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)
  3804. &rxsc_sgien_exflg;
  3805. if (pdrvinfo->BW) /* 40M channel */
  3806. priv->stats.received_bwtype[1 + prxsc->rxsc]++;
  3807. else /* 20M channel */
  3808. priv->stats.received_bwtype[0]++;
  3809. }
  3810. /* UI BSS List signal strength(in percentage), make it good looking,
  3811. * from 0~100. It is assigned to the BSS List in
  3812. * GetValueFromBeaconOrProbeRsp().
  3813. */
  3814. if (is_cck_rate) {
  3815. pstats->SignalStrength =
  3816. precord_stats->SignalStrength =
  3817. (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
  3818. } else {
  3819. /* We can judge RX path number now. */
  3820. if (rf_rx_num != 0) {
  3821. pstats->SignalStrength =
  3822. precord_stats->SignalStrength =
  3823. (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
  3824. }
  3825. }
  3826. } /* QueryRxPhyStatus8190Pci */
  3827. static void rtl8192_record_rxdesc_forlateruse(
  3828. struct ieee80211_rx_stats *psrc_stats,
  3829. struct ieee80211_rx_stats *ptarget_stats)
  3830. {
  3831. ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
  3832. ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
  3833. ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
  3834. }
  3835. static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
  3836. struct ieee80211_rx_stats *pstats,
  3837. rx_drvinfo_819x_usb *pdrvinfo)
  3838. {
  3839. /* TODO: We must only check packet for current MAC address.
  3840. * Not finish
  3841. */
  3842. struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
  3843. struct net_device *dev = info->dev;
  3844. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  3845. bool bpacket_match_bssid, bpacket_toself;
  3846. bool bPacketBeacon = false, bToSelfBA = false;
  3847. static struct ieee80211_rx_stats previous_stats;
  3848. struct rtl_80211_hdr_3addr *hdr;
  3849. u16 fc, type;
  3850. /* Get Signal Quality for only RX data queue (but not command queue) */
  3851. u8 *tmp_buf;
  3852. u8 *praddr;
  3853. /* Get MAC frame start address. */
  3854. tmp_buf = (u8 *)skb->data;
  3855. hdr = (struct rtl_80211_hdr_3addr *)tmp_buf;
  3856. fc = le16_to_cpu(hdr->frame_ctl);
  3857. type = WLAN_FC_GET_TYPE(fc);
  3858. praddr = hdr->addr1;
  3859. /* Check if the received packet is acceptable. */
  3860. bpacket_match_bssid = (IEEE80211_FTYPE_CTL != type) &&
  3861. (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
  3862. && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV);
  3863. bpacket_toself = bpacket_match_bssid &
  3864. (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
  3865. if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
  3866. bPacketBeacon = true;
  3867. if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) {
  3868. if ((eqMacAddr(praddr, dev->dev_addr)))
  3869. bToSelfBA = true;
  3870. }
  3871. if (bpacket_match_bssid)
  3872. priv->stats.numpacket_matchbssid++;
  3873. if (bpacket_toself)
  3874. priv->stats.numpacket_toself++;
  3875. /* Process PHY information for previous packet (RSSI/PWDB/EVM)
  3876. * Because phy information is contained in the last packet of AMPDU
  3877. * only, so driver should process phy information of previous packet
  3878. */
  3879. rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
  3880. rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats,
  3881. bpacket_match_bssid, bpacket_toself,
  3882. bPacketBeacon, bToSelfBA);
  3883. rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
  3884. }
  3885. /**
  3886. * Function: UpdateReceivedRateHistogramStatistics
  3887. * Overview: Record the received data rate
  3888. *
  3889. * Input:
  3890. * struct net_device *dev
  3891. * struct ieee80211_rx_stats *stats
  3892. *
  3893. * Output:
  3894. *
  3895. * (priv->stats.ReceivedRateHistogram[] is updated)
  3896. * Return:
  3897. * None
  3898. */
  3899. static void
  3900. UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
  3901. struct ieee80211_rx_stats *stats)
  3902. {
  3903. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  3904. /* 0: Total, 1:OK, 2:CRC, 3:ICV */
  3905. u32 rcvType = 1;
  3906. u32 rateIndex;
  3907. /* 1: short preamble/GI, 0: long preamble/GI */
  3908. u32 preamble_guardinterval;
  3909. if (stats->bCRC)
  3910. rcvType = 2;
  3911. else if (stats->bICV)
  3912. rcvType = 3;
  3913. if (stats->bShortPreamble)
  3914. preamble_guardinterval = 1; /* short */
  3915. else
  3916. preamble_guardinterval = 0; /* long */
  3917. switch (stats->rate) {
  3918. /* CCK rate */
  3919. case MGN_1M:
  3920. rateIndex = 0;
  3921. break;
  3922. case MGN_2M:
  3923. rateIndex = 1;
  3924. break;
  3925. case MGN_5_5M:
  3926. rateIndex = 2;
  3927. break;
  3928. case MGN_11M:
  3929. rateIndex = 3;
  3930. break;
  3931. /* Legacy OFDM rate */
  3932. case MGN_6M:
  3933. rateIndex = 4;
  3934. break;
  3935. case MGN_9M:
  3936. rateIndex = 5;
  3937. break;
  3938. case MGN_12M:
  3939. rateIndex = 6;
  3940. break;
  3941. case MGN_18M:
  3942. rateIndex = 7;
  3943. break;
  3944. case MGN_24M:
  3945. rateIndex = 8;
  3946. break;
  3947. case MGN_36M:
  3948. rateIndex = 9;
  3949. break;
  3950. case MGN_48M:
  3951. rateIndex = 10;
  3952. break;
  3953. case MGN_54M:
  3954. rateIndex = 11;
  3955. break;
  3956. /* 11n High throughput rate */
  3957. case MGN_MCS0:
  3958. rateIndex = 12;
  3959. break;
  3960. case MGN_MCS1:
  3961. rateIndex = 13;
  3962. break;
  3963. case MGN_MCS2:
  3964. rateIndex = 14;
  3965. break;
  3966. case MGN_MCS3:
  3967. rateIndex = 15;
  3968. break;
  3969. case MGN_MCS4:
  3970. rateIndex = 16;
  3971. break;
  3972. case MGN_MCS5:
  3973. rateIndex = 17;
  3974. break;
  3975. case MGN_MCS6:
  3976. rateIndex = 18;
  3977. break;
  3978. case MGN_MCS7:
  3979. rateIndex = 19;
  3980. break;
  3981. case MGN_MCS8:
  3982. rateIndex = 20;
  3983. break;
  3984. case MGN_MCS9:
  3985. rateIndex = 21;
  3986. break;
  3987. case MGN_MCS10:
  3988. rateIndex = 22;
  3989. break;
  3990. case MGN_MCS11:
  3991. rateIndex = 23;
  3992. break;
  3993. case MGN_MCS12:
  3994. rateIndex = 24;
  3995. break;
  3996. case MGN_MCS13:
  3997. rateIndex = 25;
  3998. break;
  3999. case MGN_MCS14:
  4000. rateIndex = 26;
  4001. break;
  4002. case MGN_MCS15:
  4003. rateIndex = 27;
  4004. break;
  4005. default:
  4006. rateIndex = 28;
  4007. break;
  4008. }
  4009. priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
  4010. priv->stats.received_rate_histogram[0][rateIndex]++; /* total */
  4011. priv->stats.received_rate_histogram[rcvType][rateIndex]++;
  4012. }
  4013. static void query_rxdesc_status(struct sk_buff *skb,
  4014. struct ieee80211_rx_stats *stats,
  4015. bool bIsRxAggrSubframe)
  4016. {
  4017. struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
  4018. struct net_device *dev = info->dev;
  4019. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  4020. rx_drvinfo_819x_usb *driver_info = NULL;
  4021. /* Get Rx Descriptor Information */
  4022. rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
  4023. stats->Length = desc->Length;
  4024. stats->RxDrvInfoSize = desc->RxDrvInfoSize;
  4025. stats->RxBufShift = 0;
  4026. stats->bICV = desc->ICV;
  4027. stats->bCRC = desc->CRC32;
  4028. stats->bHwError = stats->bCRC | stats->bICV;
  4029. /* RTL8190 set this bit to indicate that Hw does not decrypt packet */
  4030. stats->Decrypted = !desc->SWDec;
  4031. if ((priv->ieee80211->pHTInfo->bCurrentHTSupport) &&
  4032. (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
  4033. stats->bHwError = false;
  4034. else
  4035. stats->bHwError = stats->bCRC | stats->bICV;
  4036. if (stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
  4037. stats->bHwError |= 1;
  4038. /* Get Driver Info */
  4039. /* TODO: Need to verify it on FGPA platform
  4040. * Driver info are written to the RxBuffer following rx desc
  4041. */
  4042. if (stats->RxDrvInfoSize != 0) {
  4043. driver_info = (rx_drvinfo_819x_usb *)(
  4044. skb->data
  4045. + sizeof(rx_desc_819x_usb)
  4046. + stats->RxBufShift
  4047. );
  4048. /* unit: 0.5M */
  4049. /* TODO */
  4050. if (!stats->bHwError) {
  4051. u8 ret_rate;
  4052. ret_rate = HwRateToMRate90(driver_info->RxHT,
  4053. driver_info->RxRate);
  4054. if (ret_rate == 0xff) {
  4055. /* Abnormal Case: Receive CRC OK packet with Rx
  4056. * descriptor indicating non supported rate.
  4057. * Special Error Handling here
  4058. */
  4059. stats->bHwError = 1;
  4060. /* Set 1M rate by default */
  4061. stats->rate = MGN_1M;
  4062. } else {
  4063. stats->rate = ret_rate;
  4064. }
  4065. } else {
  4066. stats->rate = 0x02;
  4067. }
  4068. stats->bShortPreamble = driver_info->SPLCP;
  4069. UpdateReceivedRateHistogramStatistics8190(dev, stats);
  4070. stats->bIsAMPDU = (driver_info->PartAggr == 1);
  4071. stats->bFirstMPDU = (driver_info->PartAggr == 1) &&
  4072. (driver_info->FirstAGGR == 1);
  4073. stats->TimeStampLow = driver_info->TSFL;
  4074. UpdateRxPktTimeStamp8190(dev, stats);
  4075. /* Rx A-MPDU */
  4076. if (driver_info->FirstAGGR == 1 || driver_info->PartAggr == 1)
  4077. RT_TRACE(COMP_RXDESC,
  4078. "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
  4079. driver_info->FirstAGGR, driver_info->PartAggr);
  4080. }
  4081. skb_pull(skb, sizeof(rx_desc_819x_usb));
  4082. /* Get Total offset of MPDU Frame Body */
  4083. if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
  4084. stats->bShift = 1;
  4085. skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
  4086. }
  4087. if (driver_info) {
  4088. stats->RxIs40MHzPacket = driver_info->BW;
  4089. TranslateRxSignalStuff819xUsb(skb, stats, driver_info);
  4090. }
  4091. }
  4092. static void rtl8192_rx_nomal(struct sk_buff *skb)
  4093. {
  4094. struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
  4095. struct net_device *dev = info->dev;
  4096. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  4097. struct ieee80211_rx_stats stats = {
  4098. .signal = 0,
  4099. .noise = 0x100 - 98,
  4100. .rate = 0,
  4101. .freq = IEEE80211_24GHZ_BAND,
  4102. };
  4103. u32 rx_pkt_len = 0;
  4104. struct rtl_80211_hdr_1addr *ieee80211_hdr = NULL;
  4105. bool unicast_packet = false;
  4106. /* 20 is for ps-poll */
  4107. if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
  4108. /* first packet should not contain Rx aggregation header */
  4109. query_rxdesc_status(skb, &stats, false);
  4110. /* TODO */
  4111. /* hardware related info */
  4112. /* Process the MPDU received */
  4113. skb_trim(skb, skb->len - 4/*sCrcLng*/);
  4114. rx_pkt_len = skb->len;
  4115. ieee80211_hdr = (struct rtl_80211_hdr_1addr *)skb->data;
  4116. unicast_packet = false;
  4117. if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
  4118. /* TODO */
  4119. } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
  4120. /* TODO */
  4121. } else {
  4122. /* unicast packet */
  4123. unicast_packet = true;
  4124. }
  4125. if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
  4126. dev_kfree_skb_any(skb);
  4127. } else {
  4128. priv->stats.rxoktotal++;
  4129. if (unicast_packet)
  4130. priv->stats.rxbytesunicast += rx_pkt_len;
  4131. }
  4132. } else {
  4133. priv->stats.rxurberr++;
  4134. netdev_dbg(dev, "actual_length: %d\n", skb->len);
  4135. dev_kfree_skb_any(skb);
  4136. }
  4137. }
  4138. static void rtl819xusb_process_received_packet(
  4139. struct net_device *dev,
  4140. struct ieee80211_rx_stats *pstats)
  4141. {
  4142. u8 *frame;
  4143. u16 frame_len = 0;
  4144. struct r8192_priv *priv = ieee80211_priv(dev);
  4145. /* Get shifted bytes of Starting address of 802.11 header. */
  4146. pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
  4147. frame = pstats->virtual_address;
  4148. frame_len = pstats->packetlength;
  4149. #ifdef TODO /* about HCT */
  4150. if (!Adapter->bInHctTest)
  4151. CountRxErrStatistics(Adapter, pRfd);
  4152. #endif
  4153. #ifdef ENABLE_PS /* for adding ps function in future */
  4154. RT_RF_POWER_STATE rtState;
  4155. /* When RF is off, we should not count the packet for hw/sw synchronize
  4156. * reason, ie. there may be a duration while sw switch is changed and
  4157. * hw switch is being changed.
  4158. */
  4159. Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE,
  4160. (u8 *)(&rtState));
  4161. if (rtState == eRfOff)
  4162. return;
  4163. #endif
  4164. priv->stats.rxframgment++;
  4165. #ifdef TODO
  4166. RmMonitorSignalStrength(Adapter, pRfd);
  4167. #endif
  4168. /* We have to release RFD and return if rx pkt is cmd pkt. */
  4169. if (rtl819xusb_rx_command_packet(dev, pstats))
  4170. return;
  4171. #ifdef SW_CRC_CHECK
  4172. SwCrcCheck();
  4173. #endif
  4174. }
  4175. static void query_rx_cmdpkt_desc_status(struct sk_buff *skb,
  4176. struct ieee80211_rx_stats *stats)
  4177. {
  4178. rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
  4179. /* Get Rx Descriptor Information */
  4180. stats->virtual_address = (u8 *)skb->data;
  4181. stats->Length = desc->Length;
  4182. stats->RxDrvInfoSize = 0;
  4183. stats->RxBufShift = 0;
  4184. stats->packetlength = stats->Length - scrclng;
  4185. stats->fraglength = stats->packetlength;
  4186. stats->fragoffset = 0;
  4187. stats->ntotalfrag = 1;
  4188. }
  4189. static void rtl8192_rx_cmd(struct sk_buff *skb)
  4190. {
  4191. struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
  4192. struct net_device *dev = info->dev;
  4193. /* TODO */
  4194. struct ieee80211_rx_stats stats = {
  4195. .signal = 0,
  4196. .noise = 0x100 - 98,
  4197. .rate = 0,
  4198. .freq = IEEE80211_24GHZ_BAND,
  4199. };
  4200. if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
  4201. query_rx_cmdpkt_desc_status(skb, &stats);
  4202. /* prfd->queue_id = 1; */
  4203. /* Process the command packet received. */
  4204. rtl819xusb_process_received_packet(dev, &stats);
  4205. dev_kfree_skb_any(skb);
  4206. }
  4207. }
  4208. static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
  4209. {
  4210. struct sk_buff *skb;
  4211. struct rtl8192_rx_info *info;
  4212. while (NULL != (skb = skb_dequeue(&priv->skb_queue))) {
  4213. info = (struct rtl8192_rx_info *)skb->cb;
  4214. switch (info->out_pipe) {
  4215. /* Nomal packet pipe */
  4216. case 3:
  4217. priv->IrpPendingCount--;
  4218. rtl8192_rx_nomal(skb);
  4219. break;
  4220. /* Command packet pipe */
  4221. case 9:
  4222. RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",
  4223. info->out_pipe);
  4224. rtl8192_rx_cmd(skb);
  4225. break;
  4226. default: /* should never get here! */
  4227. RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",
  4228. info->out_pipe);
  4229. dev_kfree_skb(skb);
  4230. break;
  4231. }
  4232. }
  4233. }
  4234. static const struct net_device_ops rtl8192_netdev_ops = {
  4235. .ndo_open = rtl8192_open,
  4236. .ndo_stop = rtl8192_close,
  4237. .ndo_get_stats = rtl8192_stats,
  4238. .ndo_tx_timeout = tx_timeout,
  4239. .ndo_do_ioctl = rtl8192_ioctl,
  4240. .ndo_set_rx_mode = r8192_set_multicast,
  4241. .ndo_set_mac_address = r8192_set_mac_adr,
  4242. .ndo_validate_addr = eth_validate_addr,
  4243. .ndo_change_mtu = eth_change_mtu,
  4244. .ndo_start_xmit = ieee80211_xmit,
  4245. };
  4246. /****************************************************************************
  4247. ---------------------------- USB_STUFF---------------------------
  4248. *****************************************************************************/
  4249. static int rtl8192_usb_probe(struct usb_interface *intf,
  4250. const struct usb_device_id *id)
  4251. {
  4252. struct net_device *dev = NULL;
  4253. struct r8192_priv *priv = NULL;
  4254. struct usb_device *udev = interface_to_usbdev(intf);
  4255. int ret;
  4256. RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
  4257. dev = alloc_ieee80211(sizeof(struct r8192_priv));
  4258. if (dev == NULL)
  4259. return -ENOMEM;
  4260. usb_set_intfdata(intf, dev);
  4261. SET_NETDEV_DEV(dev, &intf->dev);
  4262. priv = ieee80211_priv(dev);
  4263. priv->ieee80211 = netdev_priv(dev);
  4264. priv->udev = udev;
  4265. dev->netdev_ops = &rtl8192_netdev_ops;
  4266. dev->wireless_handlers =
  4267. (struct iw_handler_def *)&r8192_wx_handlers_def;
  4268. dev->type = ARPHRD_ETHER;
  4269. dev->watchdog_timeo = HZ * 3;
  4270. if (dev_alloc_name(dev, ifname) < 0) {
  4271. RT_TRACE(COMP_INIT,
  4272. "Oops: devname already taken! Trying wlan%%d...\n");
  4273. ifname = "wlan%d";
  4274. dev_alloc_name(dev, ifname);
  4275. }
  4276. RT_TRACE(COMP_INIT, "Driver probe completed1\n");
  4277. if (rtl8192_init(dev) != 0) {
  4278. RT_TRACE(COMP_ERR, "Initialization failed");
  4279. ret = -ENODEV;
  4280. goto fail;
  4281. }
  4282. netif_carrier_off(dev);
  4283. netif_stop_queue(dev);
  4284. ret = register_netdev(dev);
  4285. if (ret)
  4286. goto fail2;
  4287. RT_TRACE(COMP_INIT, "dev name=======> %s\n", dev->name);
  4288. rtl8192_proc_init_one(dev);
  4289. RT_TRACE(COMP_INIT, "Driver probe completed\n");
  4290. return 0;
  4291. fail2:
  4292. rtl8192_down(dev);
  4293. kfree(priv->pFirmware);
  4294. priv->pFirmware = NULL;
  4295. rtl8192_usb_deleteendpoints(dev);
  4296. destroy_workqueue(priv->priv_wq);
  4297. mdelay(10);
  4298. fail:
  4299. free_ieee80211(dev);
  4300. RT_TRACE(COMP_ERR, "wlan driver load failed\n");
  4301. return ret;
  4302. }
  4303. /* detach all the work and timer structure declared or inititialize
  4304. * in r8192U_init function.
  4305. */
  4306. static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
  4307. {
  4308. cancel_work_sync(&priv->reset_wq);
  4309. cancel_delayed_work(&priv->watch_dog_wq);
  4310. cancel_delayed_work(&priv->update_beacon_wq);
  4311. cancel_work_sync(&priv->qos_activate);
  4312. }
  4313. static void rtl8192_usb_disconnect(struct usb_interface *intf)
  4314. {
  4315. struct net_device *dev = usb_get_intfdata(intf);
  4316. struct r8192_priv *priv = ieee80211_priv(dev);
  4317. if (dev) {
  4318. unregister_netdev(dev);
  4319. RT_TRACE(COMP_DOWN,
  4320. "=============>wlan driver to be removed\n");
  4321. rtl8192_proc_remove_one(dev);
  4322. rtl8192_down(dev);
  4323. kfree(priv->pFirmware);
  4324. priv->pFirmware = NULL;
  4325. rtl8192_usb_deleteendpoints(dev);
  4326. destroy_workqueue(priv->priv_wq);
  4327. mdelay(10);
  4328. }
  4329. free_ieee80211(dev);
  4330. RT_TRACE(COMP_DOWN, "wlan driver removed\n");
  4331. }
  4332. static int __init rtl8192_usb_module_init(void)
  4333. {
  4334. int ret;
  4335. #ifdef CONFIG_IEEE80211_DEBUG
  4336. ret = ieee80211_debug_init();
  4337. if (ret) {
  4338. pr_err("ieee80211_debug_init() failed %d\n", ret);
  4339. return ret;
  4340. }
  4341. #endif
  4342. ret = ieee80211_crypto_init();
  4343. if (ret) {
  4344. pr_err("ieee80211_crypto_init() failed %d\n", ret);
  4345. return ret;
  4346. }
  4347. ret = ieee80211_crypto_tkip_init();
  4348. if (ret) {
  4349. pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
  4350. return ret;
  4351. }
  4352. ret = ieee80211_crypto_ccmp_init();
  4353. if (ret) {
  4354. pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
  4355. return ret;
  4356. }
  4357. ret = ieee80211_crypto_wep_init();
  4358. if (ret) {
  4359. pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
  4360. return ret;
  4361. }
  4362. pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n");
  4363. pr_info("Copyright (c) 2007-2008, Realsil Wlan\n");
  4364. RT_TRACE(COMP_INIT, "Initializing module");
  4365. RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
  4366. rtl8192_proc_module_init();
  4367. return usb_register(&rtl8192_usb_driver);
  4368. }
  4369. static void __exit rtl8192_usb_module_exit(void)
  4370. {
  4371. usb_deregister(&rtl8192_usb_driver);
  4372. RT_TRACE(COMP_DOWN, "Exiting");
  4373. }
  4374. void rtl8192_try_wake_queue(struct net_device *dev, int pri)
  4375. {
  4376. unsigned long flags;
  4377. short enough_desc;
  4378. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  4379. spin_lock_irqsave(&priv->tx_lock, flags);
  4380. enough_desc = check_nic_enough_desc(dev, pri);
  4381. spin_unlock_irqrestore(&priv->tx_lock, flags);
  4382. if (enough_desc)
  4383. ieee80211_wake_queue(priv->ieee80211);
  4384. }
  4385. void EnableHWSecurityConfig8192(struct net_device *dev)
  4386. {
  4387. u8 SECR_value = 0x0;
  4388. struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
  4389. struct ieee80211_device *ieee = priv->ieee80211;
  4390. SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
  4391. if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) {
  4392. SECR_value |= SCR_RxUseDK;
  4393. SECR_value |= SCR_TxUseDK;
  4394. } else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) {
  4395. SECR_value |= SCR_RxUseDK;
  4396. SECR_value |= SCR_TxUseDK;
  4397. }
  4398. /* add HWSec active enable here.
  4399. * default using hwsec. when peer AP is in N mode only and
  4400. * pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates
  4401. * it), use software security. when peer AP is in b,g,n mode mixed and
  4402. * pairwise_key_type is none_aes, use g mode hw security.
  4403. */
  4404. ieee->hwsec_active = 1;
  4405. /* add hwsec_support flag to totol control hw_sec on/off */
  4406. if ((ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE) || !hwwep) {
  4407. ieee->hwsec_active = 0;
  4408. SECR_value &= ~SCR_RxDecEnable;
  4409. }
  4410. RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n",
  4411. __func__, ieee->hwsec_active, ieee->pairwise_key_type,
  4412. SECR_value);
  4413. write_nic_byte(dev, SECR, SECR_value);
  4414. }
  4415. void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
  4416. u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
  4417. {
  4418. u32 TargetCommand = 0;
  4419. u32 TargetContent = 0;
  4420. u16 usConfig = 0;
  4421. u8 i;
  4422. if (EntryNo >= TOTAL_CAM_ENTRY)
  4423. RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
  4424. RT_TRACE(COMP_SEC,
  4425. "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n",
  4426. dev, EntryNo, KeyIndex, KeyType, MacAddr);
  4427. if (DefaultKey)
  4428. usConfig |= BIT(15) | (KeyType << 2);
  4429. else
  4430. usConfig |= BIT(15) | (KeyType << 2) | KeyIndex;
  4431. for (i = 0; i < CAM_CONTENT_COUNT; i++) {
  4432. TargetCommand = i + CAM_CONTENT_COUNT * EntryNo;
  4433. TargetCommand |= BIT(31) | BIT(16);
  4434. if (i == 0) { /* MAC|Config */
  4435. TargetContent = (u32)(*(MacAddr + 0)) << 16 |
  4436. (u32)(*(MacAddr + 1)) << 24 |
  4437. (u32)usConfig;
  4438. write_nic_dword(dev, WCAMI, TargetContent);
  4439. write_nic_dword(dev, RWCAM, TargetCommand);
  4440. } else if (i == 1) { /* MAC */
  4441. TargetContent = (u32)(*(MacAddr + 2)) |
  4442. (u32)(*(MacAddr + 3)) << 8 |
  4443. (u32)(*(MacAddr + 4)) << 16 |
  4444. (u32)(*(MacAddr + 5)) << 24;
  4445. write_nic_dword(dev, WCAMI, TargetContent);
  4446. write_nic_dword(dev, RWCAM, TargetCommand);
  4447. } else {
  4448. /* Key Material */
  4449. if (KeyContent != NULL) {
  4450. write_nic_dword(dev, WCAMI, (u32)(*(KeyContent + i - 2)));
  4451. write_nic_dword(dev, RWCAM, TargetCommand);
  4452. }
  4453. }
  4454. }
  4455. }
  4456. /***************************************************************************
  4457. ------------------- module init / exit stubs ----------------
  4458. ****************************************************************************/
  4459. module_init(rtl8192_usb_module_init);
  4460. module_exit(rtl8192_usb_module_exit);