iwl4965-base.c 150 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #include "iwl-eeprom.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-helpers.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-calib.h"
  51. /******************************************************************************
  52. *
  53. * module boiler plate
  54. *
  55. ******************************************************************************/
  56. /*
  57. * module name, copyright, version, etc.
  58. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  67. #define VS "s"
  68. #else
  69. #define VS
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD VS
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT);
  75. MODULE_LICENSE("GPL");
  76. static int iwl4965_is_empty_essid(const char *essid, int essid_len)
  77. {
  78. /* Single white space is for Linksys APs */
  79. if (essid_len == 1 && essid[0] == ' ')
  80. return 1;
  81. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  82. while (essid_len) {
  83. essid_len--;
  84. if (essid[essid_len] != '\0')
  85. return 0;
  86. }
  87. return 1;
  88. }
  89. static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
  90. {
  91. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  92. const char *s = essid;
  93. char *d = escaped;
  94. if (iwl4965_is_empty_essid(essid, essid_len)) {
  95. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  96. return escaped;
  97. }
  98. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  99. while (essid_len--) {
  100. if (*s == '\0') {
  101. *d++ = '\\';
  102. *d++ = '0';
  103. s++;
  104. } else
  105. *d++ = *s++;
  106. }
  107. *d = '\0';
  108. return escaped;
  109. }
  110. /*************** STATION TABLE MANAGEMENT ****
  111. * mac80211 should be examined to determine if sta_info is duplicating
  112. * the functionality provided here
  113. */
  114. /**************************************************************/
  115. static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  116. {
  117. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  118. if (hw_decrypt)
  119. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  120. else
  121. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  122. }
  123. /**
  124. * iwl4965_check_rxon_cmd - validate RXON structure is valid
  125. *
  126. * NOTE: This is really only useful during development and can eventually
  127. * be #ifdef'd out once the driver is stable and folks aren't actively
  128. * making changes
  129. */
  130. static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
  131. {
  132. int error = 0;
  133. int counter = 1;
  134. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  135. error |= le32_to_cpu(rxon->flags &
  136. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  137. RXON_FLG_RADAR_DETECT_MSK));
  138. if (error)
  139. IWL_WARNING("check 24G fields %d | %d\n",
  140. counter++, error);
  141. } else {
  142. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  143. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  144. if (error)
  145. IWL_WARNING("check 52 fields %d | %d\n",
  146. counter++, error);
  147. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  148. if (error)
  149. IWL_WARNING("check 52 CCK %d | %d\n",
  150. counter++, error);
  151. }
  152. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  153. if (error)
  154. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  155. /* make sure basic rates 6Mbps and 1Mbps are supported */
  156. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  157. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  158. if (error)
  159. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  160. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  161. if (error)
  162. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  163. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  164. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  165. if (error)
  166. IWL_WARNING("check CCK and short slot %d | %d\n",
  167. counter++, error);
  168. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  169. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  170. if (error)
  171. IWL_WARNING("check CCK & auto detect %d | %d\n",
  172. counter++, error);
  173. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  174. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  175. if (error)
  176. IWL_WARNING("check TGG and auto detect %d | %d\n",
  177. counter++, error);
  178. if (error)
  179. IWL_WARNING("Tuning to channel %d\n",
  180. le16_to_cpu(rxon->channel));
  181. if (error) {
  182. IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
  183. return -1;
  184. }
  185. return 0;
  186. }
  187. /**
  188. * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  189. * @priv: staging_rxon is compared to active_rxon
  190. *
  191. * If the RXON structure is changing enough to require a new tune,
  192. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  193. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  194. */
  195. static int iwl4965_full_rxon_required(struct iwl_priv *priv)
  196. {
  197. /* These items are only settable from the full RXON command */
  198. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  199. compare_ether_addr(priv->staging_rxon.bssid_addr,
  200. priv->active_rxon.bssid_addr) ||
  201. compare_ether_addr(priv->staging_rxon.node_addr,
  202. priv->active_rxon.node_addr) ||
  203. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  204. priv->active_rxon.wlap_bssid_addr) ||
  205. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  206. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  207. (priv->staging_rxon.air_propagation !=
  208. priv->active_rxon.air_propagation) ||
  209. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  210. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  211. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  212. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  213. (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
  214. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  215. return 1;
  216. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  217. * be updated with the RXON_ASSOC command -- however only some
  218. * flag transitions are allowed using RXON_ASSOC */
  219. /* Check if we are not switching bands */
  220. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  221. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  222. return 1;
  223. /* Check if we are switching association toggle */
  224. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  225. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  226. return 1;
  227. return 0;
  228. }
  229. /**
  230. * iwl4965_commit_rxon - commit staging_rxon to hardware
  231. *
  232. * The RXON command in staging_rxon is committed to the hardware and
  233. * the active_rxon structure is updated with the new data. This
  234. * function correctly transitions out of the RXON_ASSOC_MSK state if
  235. * a HW tune is required based on the RXON structure changes.
  236. */
  237. static int iwl4965_commit_rxon(struct iwl_priv *priv)
  238. {
  239. /* cast away the const for active_rxon in this function */
  240. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  241. DECLARE_MAC_BUF(mac);
  242. int rc = 0;
  243. if (!iwl_is_alive(priv))
  244. return -1;
  245. /* always get timestamp with Rx frame */
  246. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  247. rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
  248. if (rc) {
  249. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  250. return -EINVAL;
  251. }
  252. /* If we don't need to send a full RXON, we can use
  253. * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
  254. * and other flags for the current radio configuration. */
  255. if (!iwl4965_full_rxon_required(priv)) {
  256. rc = iwl_send_rxon_assoc(priv);
  257. if (rc) {
  258. IWL_ERROR("Error setting RXON_ASSOC "
  259. "configuration (%d).\n", rc);
  260. return rc;
  261. }
  262. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  263. return 0;
  264. }
  265. /* station table will be cleared */
  266. priv->assoc_station_added = 0;
  267. /* If we are currently associated and the new config requires
  268. * an RXON_ASSOC and the new config wants the associated mask enabled,
  269. * we must clear the associated from the active configuration
  270. * before we apply the new config */
  271. if (iwl_is_associated(priv) &&
  272. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  273. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  274. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  275. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  276. sizeof(struct iwl_rxon_cmd),
  277. &priv->active_rxon);
  278. /* If the mask clearing failed then we set
  279. * active_rxon back to what it was previously */
  280. if (rc) {
  281. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  282. IWL_ERROR("Error clearing ASSOC_MSK on current "
  283. "configuration (%d).\n", rc);
  284. return rc;
  285. }
  286. }
  287. IWL_DEBUG_INFO("Sending RXON\n"
  288. "* with%s RXON_FILTER_ASSOC_MSK\n"
  289. "* channel = %d\n"
  290. "* bssid = %s\n",
  291. ((priv->staging_rxon.filter_flags &
  292. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  293. le16_to_cpu(priv->staging_rxon.channel),
  294. print_mac(mac, priv->staging_rxon.bssid_addr));
  295. iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
  296. /* Apply the new configuration */
  297. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  298. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  299. if (rc) {
  300. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  301. return rc;
  302. }
  303. iwl_remove_station(priv, iwl_bcast_addr, 0);
  304. iwlcore_clear_stations_table(priv);
  305. if (!priv->error_recovering)
  306. priv->start_calib = 0;
  307. iwl_init_sensitivity(priv);
  308. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  309. /* If we issue a new RXON command which required a tune then we must
  310. * send a new TXPOWER command or we won't be able to Tx any frames */
  311. rc = iwl4965_hw_reg_send_txpower(priv);
  312. if (rc) {
  313. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  314. return rc;
  315. }
  316. /* Add the broadcast address so we can send broadcast frames */
  317. if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
  318. IWL_INVALID_STATION) {
  319. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  320. return -EIO;
  321. }
  322. /* If we have set the ASSOC_MSK and we are in BSS mode then
  323. * add the IWL_AP_ID to the station rate table */
  324. if (iwl_is_associated(priv) &&
  325. (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
  326. if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
  327. == IWL_INVALID_STATION) {
  328. IWL_ERROR("Error adding AP address for transmit.\n");
  329. return -EIO;
  330. }
  331. priv->assoc_station_added = 1;
  332. if (priv->default_wep_key &&
  333. iwl_send_static_wepkey_cmd(priv, 0))
  334. IWL_ERROR("Could not send WEP static key.\n");
  335. }
  336. return 0;
  337. }
  338. void iwl4965_update_chain_flags(struct iwl_priv *priv)
  339. {
  340. iwl_set_rxon_chain(priv);
  341. iwl4965_commit_rxon(priv);
  342. }
  343. static int iwl4965_send_bt_config(struct iwl_priv *priv)
  344. {
  345. struct iwl4965_bt_cmd bt_cmd = {
  346. .flags = 3,
  347. .lead_time = 0xAA,
  348. .max_kill = 1,
  349. .kill_ack_mask = 0,
  350. .kill_cts_mask = 0,
  351. };
  352. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  353. sizeof(struct iwl4965_bt_cmd), &bt_cmd);
  354. }
  355. static int iwl4965_send_scan_abort(struct iwl_priv *priv)
  356. {
  357. int ret = 0;
  358. struct iwl_rx_packet *res;
  359. struct iwl_host_cmd cmd = {
  360. .id = REPLY_SCAN_ABORT_CMD,
  361. .meta.flags = CMD_WANT_SKB,
  362. };
  363. /* If there isn't a scan actively going on in the hardware
  364. * then we are in between scan bands and not actually
  365. * actively scanning, so don't send the abort command */
  366. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  367. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  368. return 0;
  369. }
  370. ret = iwl_send_cmd_sync(priv, &cmd);
  371. if (ret) {
  372. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  373. return ret;
  374. }
  375. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  376. if (res->u.status != CAN_ABORT_STATUS) {
  377. /* The scan abort will return 1 for success or
  378. * 2 for "failure". A failure condition can be
  379. * due to simply not being in an active scan which
  380. * can occur if we send the scan abort before we
  381. * the microcode has notified us that a scan is
  382. * completed. */
  383. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  384. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  385. clear_bit(STATUS_SCAN_HW, &priv->status);
  386. }
  387. dev_kfree_skb_any(cmd.meta.u.skb);
  388. return ret;
  389. }
  390. /*
  391. * CARD_STATE_CMD
  392. *
  393. * Use: Sets the device's internal card state to enable, disable, or halt
  394. *
  395. * When in the 'enable' state the card operates as normal.
  396. * When in the 'disable' state, the card enters into a low power mode.
  397. * When in the 'halt' state, the card is shut down and must be fully
  398. * restarted to come back on.
  399. */
  400. static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  401. {
  402. struct iwl_host_cmd cmd = {
  403. .id = REPLY_CARD_STATE_CMD,
  404. .len = sizeof(u32),
  405. .data = &flags,
  406. .meta.flags = meta_flag,
  407. };
  408. return iwl_send_cmd(priv, &cmd);
  409. }
  410. static void iwl_clear_free_frames(struct iwl_priv *priv)
  411. {
  412. struct list_head *element;
  413. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  414. priv->frames_count);
  415. while (!list_empty(&priv->free_frames)) {
  416. element = priv->free_frames.next;
  417. list_del(element);
  418. kfree(list_entry(element, struct iwl_frame, list));
  419. priv->frames_count--;
  420. }
  421. if (priv->frames_count) {
  422. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  423. priv->frames_count);
  424. priv->frames_count = 0;
  425. }
  426. }
  427. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  428. {
  429. struct iwl_frame *frame;
  430. struct list_head *element;
  431. if (list_empty(&priv->free_frames)) {
  432. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  433. if (!frame) {
  434. IWL_ERROR("Could not allocate frame!\n");
  435. return NULL;
  436. }
  437. priv->frames_count++;
  438. return frame;
  439. }
  440. element = priv->free_frames.next;
  441. list_del(element);
  442. return list_entry(element, struct iwl_frame, list);
  443. }
  444. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  445. {
  446. memset(frame, 0, sizeof(*frame));
  447. list_add(&frame->list, &priv->free_frames);
  448. }
  449. unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  450. struct ieee80211_hdr *hdr,
  451. const u8 *dest, int left)
  452. {
  453. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  454. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  455. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  456. return 0;
  457. if (priv->ibss_beacon->len > left)
  458. return 0;
  459. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  460. return priv->ibss_beacon->len;
  461. }
  462. static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
  463. {
  464. int i;
  465. int rate_mask;
  466. /* Set rate mask*/
  467. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  468. rate_mask = priv->active_rate_basic & 0xF;
  469. else
  470. rate_mask = priv->active_rate_basic & 0xFF0;
  471. /* Find lowest valid rate */
  472. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  473. i = iwl_rates[i].next_ieee) {
  474. if (rate_mask & (1 << i))
  475. return iwl_rates[i].plcp;
  476. }
  477. /* No valid rate was found. Assign the lowest one */
  478. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  479. return IWL_RATE_1M_PLCP;
  480. else
  481. return IWL_RATE_6M_PLCP;
  482. }
  483. static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  484. {
  485. struct iwl_frame *frame;
  486. unsigned int frame_size;
  487. int rc;
  488. u8 rate;
  489. frame = iwl_get_free_frame(priv);
  490. if (!frame) {
  491. IWL_ERROR("Could not obtain free frame buffer for beacon "
  492. "command.\n");
  493. return -ENOMEM;
  494. }
  495. rate = iwl4965_rate_get_lowest_plcp(priv);
  496. frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
  497. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  498. &frame->u.cmd[0]);
  499. iwl_free_frame(priv, frame);
  500. return rc;
  501. }
  502. /******************************************************************************
  503. *
  504. * Misc. internal state and helper functions
  505. *
  506. ******************************************************************************/
  507. /**
  508. * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
  509. *
  510. * return : set the bit for each supported rate insert in ie
  511. */
  512. static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  513. u16 basic_rate, int *left)
  514. {
  515. u16 ret_rates = 0, bit;
  516. int i;
  517. u8 *cnt = ie;
  518. u8 *rates = ie + 1;
  519. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  520. if (bit & supported_rate) {
  521. ret_rates |= bit;
  522. rates[*cnt] = iwl_rates[i].ieee |
  523. ((bit & basic_rate) ? 0x80 : 0x00);
  524. (*cnt)++;
  525. (*left)--;
  526. if ((*left <= 0) ||
  527. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  528. break;
  529. }
  530. }
  531. return ret_rates;
  532. }
  533. #ifdef CONFIG_IWL4965_HT
  534. static void iwl4965_ht_conf(struct iwl_priv *priv,
  535. struct ieee80211_bss_conf *bss_conf)
  536. {
  537. struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
  538. struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
  539. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  540. IWL_DEBUG_MAC80211("enter: \n");
  541. iwl_conf->is_ht = bss_conf->assoc_ht;
  542. if (!iwl_conf->is_ht)
  543. return;
  544. priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  545. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  546. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  547. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  548. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  549. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  550. iwl_conf->max_amsdu_size =
  551. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  552. iwl_conf->supported_chan_width =
  553. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
  554. iwl_conf->extension_chan_offset =
  555. ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
  556. /* If no above or below channel supplied disable FAT channel */
  557. if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
  558. iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
  559. iwl_conf->supported_chan_width = 0;
  560. iwl_conf->tx_mimo_ps_mode =
  561. (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  562. memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
  563. iwl_conf->control_channel = ht_bss_conf->primary_channel;
  564. iwl_conf->tx_chan_width =
  565. !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
  566. iwl_conf->ht_protection =
  567. ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
  568. iwl_conf->non_GF_STA_present =
  569. !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
  570. IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
  571. IWL_DEBUG_MAC80211("leave\n");
  572. }
  573. static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  574. u8 *pos, int *left)
  575. {
  576. struct ieee80211_ht_cap *ht_cap;
  577. if (!sband || !sband->ht_info.ht_supported)
  578. return;
  579. if (*left < sizeof(struct ieee80211_ht_cap))
  580. return;
  581. *pos++ = sizeof(struct ieee80211_ht_cap);
  582. ht_cap = (struct ieee80211_ht_cap *) pos;
  583. ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
  584. memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
  585. ht_cap->ampdu_params_info =
  586. (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
  587. ((sband->ht_info.ampdu_density << 2) &
  588. IEEE80211_HT_CAP_AMPDU_DENSITY);
  589. *left -= sizeof(struct ieee80211_ht_cap);
  590. }
  591. #else
  592. static inline void iwl4965_ht_conf(struct iwl_priv *priv,
  593. struct ieee80211_bss_conf *bss_conf)
  594. {
  595. }
  596. static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  597. u8 *pos, int *left)
  598. {
  599. }
  600. #endif
  601. /**
  602. * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
  603. */
  604. static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
  605. enum ieee80211_band band,
  606. struct ieee80211_mgmt *frame,
  607. int left, int is_direct)
  608. {
  609. int len = 0;
  610. u8 *pos = NULL;
  611. u16 active_rates, ret_rates, cck_rates, active_rate_basic;
  612. const struct ieee80211_supported_band *sband =
  613. iwl_get_hw_mode(priv, band);
  614. /* Make sure there is enough space for the probe request,
  615. * two mandatory IEs and the data */
  616. left -= 24;
  617. if (left < 0)
  618. return 0;
  619. len += 24;
  620. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  621. memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
  622. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  623. memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
  624. frame->seq_ctrl = 0;
  625. /* fill in our indirect SSID IE */
  626. /* ...next IE... */
  627. left -= 2;
  628. if (left < 0)
  629. return 0;
  630. len += 2;
  631. pos = &(frame->u.probe_req.variable[0]);
  632. *pos++ = WLAN_EID_SSID;
  633. *pos++ = 0;
  634. /* fill in our direct SSID IE... */
  635. if (is_direct) {
  636. /* ...next IE... */
  637. left -= 2 + priv->essid_len;
  638. if (left < 0)
  639. return 0;
  640. /* ... fill it in... */
  641. *pos++ = WLAN_EID_SSID;
  642. *pos++ = priv->essid_len;
  643. memcpy(pos, priv->essid, priv->essid_len);
  644. pos += priv->essid_len;
  645. len += 2 + priv->essid_len;
  646. }
  647. /* fill in supported rate */
  648. /* ...next IE... */
  649. left -= 2;
  650. if (left < 0)
  651. return 0;
  652. /* ... fill it in... */
  653. *pos++ = WLAN_EID_SUPP_RATES;
  654. *pos = 0;
  655. /* exclude 60M rate */
  656. active_rates = priv->rates_mask;
  657. active_rates &= ~IWL_RATE_60M_MASK;
  658. active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
  659. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  660. ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
  661. active_rate_basic, &left);
  662. active_rates &= ~ret_rates;
  663. ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
  664. active_rate_basic, &left);
  665. active_rates &= ~ret_rates;
  666. len += 2 + *pos;
  667. pos += (*pos) + 1;
  668. if (active_rates == 0)
  669. goto fill_end;
  670. /* fill in supported extended rate */
  671. /* ...next IE... */
  672. left -= 2;
  673. if (left < 0)
  674. return 0;
  675. /* ... fill it in... */
  676. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  677. *pos = 0;
  678. iwl4965_supported_rate_to_ie(pos, active_rates,
  679. active_rate_basic, &left);
  680. if (*pos > 0)
  681. len += 2 + *pos;
  682. fill_end:
  683. /* fill in HT IE */
  684. left -= 2;
  685. if (left < 0)
  686. return 0;
  687. *pos++ = WLAN_EID_HT_CAPABILITY;
  688. *pos = 0;
  689. iwl_ht_cap_to_ie(sband, pos, &left);
  690. if (*pos > 0)
  691. len += 2 + *pos;
  692. return (u16)len;
  693. }
  694. /*
  695. * QoS support
  696. */
  697. static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
  698. struct iwl4965_qosparam_cmd *qos)
  699. {
  700. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  701. sizeof(struct iwl4965_qosparam_cmd), qos);
  702. }
  703. static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
  704. {
  705. unsigned long flags;
  706. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  707. return;
  708. if (!priv->qos_data.qos_enable)
  709. return;
  710. spin_lock_irqsave(&priv->lock, flags);
  711. priv->qos_data.def_qos_parm.qos_flags = 0;
  712. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  713. !priv->qos_data.qos_cap.q_AP.txop_request)
  714. priv->qos_data.def_qos_parm.qos_flags |=
  715. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  716. if (priv->qos_data.qos_active)
  717. priv->qos_data.def_qos_parm.qos_flags |=
  718. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  719. #ifdef CONFIG_IWL4965_HT
  720. if (priv->current_ht_config.is_ht)
  721. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  722. #endif /* CONFIG_IWL4965_HT */
  723. spin_unlock_irqrestore(&priv->lock, flags);
  724. if (force || iwl_is_associated(priv)) {
  725. IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  726. priv->qos_data.qos_active,
  727. priv->qos_data.def_qos_parm.qos_flags);
  728. iwl4965_send_qos_params_command(priv,
  729. &(priv->qos_data.def_qos_parm));
  730. }
  731. }
  732. int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  733. {
  734. /* Filter incoming packets to determine if they are targeted toward
  735. * this network, discarding packets coming from ourselves */
  736. switch (priv->iw_mode) {
  737. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  738. /* packets from our adapter are dropped (echo) */
  739. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  740. return 0;
  741. /* {broad,multi}cast packets to our IBSS go through */
  742. if (is_multicast_ether_addr(header->addr1))
  743. return !compare_ether_addr(header->addr3, priv->bssid);
  744. /* packets to our adapter go through */
  745. return !compare_ether_addr(header->addr1, priv->mac_addr);
  746. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  747. /* packets from our adapter are dropped (echo) */
  748. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  749. return 0;
  750. /* {broad,multi}cast packets to our BSS go through */
  751. if (is_multicast_ether_addr(header->addr1))
  752. return !compare_ether_addr(header->addr2, priv->bssid);
  753. /* packets to our adapter go through */
  754. return !compare_ether_addr(header->addr1, priv->mac_addr);
  755. default:
  756. break;
  757. }
  758. return 1;
  759. }
  760. /**
  761. * iwl4965_scan_cancel - Cancel any currently executing HW scan
  762. *
  763. * NOTE: priv->mutex is not required before calling this function
  764. */
  765. static int iwl4965_scan_cancel(struct iwl_priv *priv)
  766. {
  767. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  768. clear_bit(STATUS_SCANNING, &priv->status);
  769. return 0;
  770. }
  771. if (test_bit(STATUS_SCANNING, &priv->status)) {
  772. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  773. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  774. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  775. queue_work(priv->workqueue, &priv->abort_scan);
  776. } else
  777. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  778. return test_bit(STATUS_SCANNING, &priv->status);
  779. }
  780. return 0;
  781. }
  782. /**
  783. * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
  784. * @ms: amount of time to wait (in milliseconds) for scan to abort
  785. *
  786. * NOTE: priv->mutex must be held before calling this function
  787. */
  788. static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
  789. {
  790. unsigned long now = jiffies;
  791. int ret;
  792. ret = iwl4965_scan_cancel(priv);
  793. if (ret && ms) {
  794. mutex_unlock(&priv->mutex);
  795. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  796. test_bit(STATUS_SCANNING, &priv->status))
  797. msleep(1);
  798. mutex_lock(&priv->mutex);
  799. return test_bit(STATUS_SCANNING, &priv->status);
  800. }
  801. return ret;
  802. }
  803. static void iwl4965_sequence_reset(struct iwl_priv *priv)
  804. {
  805. /* Reset ieee stats */
  806. /* We don't reset the net_device_stats (ieee->stats) on
  807. * re-association */
  808. priv->last_seq_num = -1;
  809. priv->last_frag_num = -1;
  810. priv->last_packet_time = 0;
  811. iwl4965_scan_cancel(priv);
  812. }
  813. #define MAX_UCODE_BEACON_INTERVAL 4096
  814. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  815. static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
  816. {
  817. u16 new_val = 0;
  818. u16 beacon_factor = 0;
  819. beacon_factor =
  820. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  821. / MAX_UCODE_BEACON_INTERVAL;
  822. new_val = beacon_val / beacon_factor;
  823. return cpu_to_le16(new_val);
  824. }
  825. static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
  826. {
  827. u64 interval_tm_unit;
  828. u64 tsf, result;
  829. unsigned long flags;
  830. struct ieee80211_conf *conf = NULL;
  831. u16 beacon_int = 0;
  832. conf = ieee80211_get_hw_conf(priv->hw);
  833. spin_lock_irqsave(&priv->lock, flags);
  834. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
  835. priv->rxon_timing.timestamp.dw[0] =
  836. cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
  837. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  838. tsf = priv->timestamp;
  839. beacon_int = priv->beacon_int;
  840. spin_unlock_irqrestore(&priv->lock, flags);
  841. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  842. if (beacon_int == 0) {
  843. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  844. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  845. } else {
  846. priv->rxon_timing.beacon_interval =
  847. cpu_to_le16(beacon_int);
  848. priv->rxon_timing.beacon_interval =
  849. iwl4965_adjust_beacon_interval(
  850. le16_to_cpu(priv->rxon_timing.beacon_interval));
  851. }
  852. priv->rxon_timing.atim_window = 0;
  853. } else {
  854. priv->rxon_timing.beacon_interval =
  855. iwl4965_adjust_beacon_interval(conf->beacon_int);
  856. /* TODO: we need to get atim_window from upper stack
  857. * for now we set to 0 */
  858. priv->rxon_timing.atim_window = 0;
  859. }
  860. interval_tm_unit =
  861. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  862. result = do_div(tsf, interval_tm_unit);
  863. priv->rxon_timing.beacon_init_val =
  864. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  865. IWL_DEBUG_ASSOC
  866. ("beacon interval %d beacon timer %d beacon tim %d\n",
  867. le16_to_cpu(priv->rxon_timing.beacon_interval),
  868. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  869. le16_to_cpu(priv->rxon_timing.atim_window));
  870. }
  871. static int iwl4965_scan_initiate(struct iwl_priv *priv)
  872. {
  873. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  874. IWL_ERROR("APs don't scan.\n");
  875. return 0;
  876. }
  877. if (!iwl_is_ready_rf(priv)) {
  878. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  879. return -EIO;
  880. }
  881. if (test_bit(STATUS_SCANNING, &priv->status)) {
  882. IWL_DEBUG_SCAN("Scan already in progress.\n");
  883. return -EAGAIN;
  884. }
  885. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  886. IWL_DEBUG_SCAN("Scan request while abort pending. "
  887. "Queuing.\n");
  888. return -EAGAIN;
  889. }
  890. IWL_DEBUG_INFO("Starting scan...\n");
  891. priv->scan_bands = 2;
  892. set_bit(STATUS_SCANNING, &priv->status);
  893. priv->scan_start = jiffies;
  894. priv->scan_pass_start = priv->scan_start;
  895. queue_work(priv->workqueue, &priv->request_scan);
  896. return 0;
  897. }
  898. static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
  899. enum ieee80211_band band)
  900. {
  901. if (band == IEEE80211_BAND_5GHZ) {
  902. priv->staging_rxon.flags &=
  903. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  904. | RXON_FLG_CCK_MSK);
  905. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  906. } else {
  907. /* Copied from iwl4965_post_associate() */
  908. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  909. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  910. else
  911. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  912. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  913. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  914. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  915. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  916. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  917. }
  918. }
  919. /*
  920. * initialize rxon structure with default values from eeprom
  921. */
  922. static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
  923. {
  924. const struct iwl_channel_info *ch_info;
  925. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  926. switch (priv->iw_mode) {
  927. case IEEE80211_IF_TYPE_AP:
  928. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  929. break;
  930. case IEEE80211_IF_TYPE_STA:
  931. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  932. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  933. break;
  934. case IEEE80211_IF_TYPE_IBSS:
  935. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  936. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  937. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  938. RXON_FILTER_ACCEPT_GRP_MSK;
  939. break;
  940. case IEEE80211_IF_TYPE_MNTR:
  941. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  942. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  943. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  944. break;
  945. default:
  946. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  947. break;
  948. }
  949. #if 0
  950. /* TODO: Figure out when short_preamble would be set and cache from
  951. * that */
  952. if (!hw_to_local(priv->hw)->short_preamble)
  953. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  954. else
  955. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  956. #endif
  957. ch_info = iwl_get_channel_info(priv, priv->band,
  958. le16_to_cpu(priv->staging_rxon.channel));
  959. if (!ch_info)
  960. ch_info = &priv->channel_info[0];
  961. /*
  962. * in some case A channels are all non IBSS
  963. * in this case force B/G channel
  964. */
  965. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  966. !(is_channel_ibss(ch_info)))
  967. ch_info = &priv->channel_info[0];
  968. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  969. priv->band = ch_info->band;
  970. iwl4965_set_flags_for_phymode(priv, priv->band);
  971. priv->staging_rxon.ofdm_basic_rates =
  972. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  973. priv->staging_rxon.cck_basic_rates =
  974. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  975. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  976. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  977. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  978. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  979. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  980. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  981. iwl_set_rxon_chain(priv);
  982. }
  983. static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
  984. {
  985. if (mode == IEEE80211_IF_TYPE_IBSS) {
  986. const struct iwl_channel_info *ch_info;
  987. ch_info = iwl_get_channel_info(priv,
  988. priv->band,
  989. le16_to_cpu(priv->staging_rxon.channel));
  990. if (!ch_info || !is_channel_ibss(ch_info)) {
  991. IWL_ERROR("channel %d not IBSS channel\n",
  992. le16_to_cpu(priv->staging_rxon.channel));
  993. return -EINVAL;
  994. }
  995. }
  996. priv->iw_mode = mode;
  997. iwl4965_connection_init_rx_config(priv);
  998. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  999. iwlcore_clear_stations_table(priv);
  1000. /* dont commit rxon if rf-kill is on*/
  1001. if (!iwl_is_ready_rf(priv))
  1002. return -EAGAIN;
  1003. cancel_delayed_work(&priv->scan_check);
  1004. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  1005. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  1006. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  1007. return -EAGAIN;
  1008. }
  1009. iwl4965_commit_rxon(priv);
  1010. return 0;
  1011. }
  1012. static void iwl4965_set_rate(struct iwl_priv *priv)
  1013. {
  1014. const struct ieee80211_supported_band *hw = NULL;
  1015. struct ieee80211_rate *rate;
  1016. int i;
  1017. hw = iwl_get_hw_mode(priv, priv->band);
  1018. if (!hw) {
  1019. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  1020. return;
  1021. }
  1022. priv->active_rate = 0;
  1023. priv->active_rate_basic = 0;
  1024. for (i = 0; i < hw->n_bitrates; i++) {
  1025. rate = &(hw->bitrates[i]);
  1026. if (rate->hw_value < IWL_RATE_COUNT)
  1027. priv->active_rate |= (1 << rate->hw_value);
  1028. }
  1029. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  1030. priv->active_rate, priv->active_rate_basic);
  1031. /*
  1032. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1033. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1034. * OFDM
  1035. */
  1036. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1037. priv->staging_rxon.cck_basic_rates =
  1038. ((priv->active_rate_basic &
  1039. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1040. else
  1041. priv->staging_rxon.cck_basic_rates =
  1042. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1043. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1044. priv->staging_rxon.ofdm_basic_rates =
  1045. ((priv->active_rate_basic &
  1046. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1047. IWL_FIRST_OFDM_RATE) & 0xFF;
  1048. else
  1049. priv->staging_rxon.ofdm_basic_rates =
  1050. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1051. }
  1052. void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  1053. {
  1054. unsigned long flags;
  1055. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  1056. return;
  1057. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  1058. disable_radio ? "OFF" : "ON");
  1059. if (disable_radio) {
  1060. iwl4965_scan_cancel(priv);
  1061. /* FIXME: This is a workaround for AP */
  1062. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  1063. spin_lock_irqsave(&priv->lock, flags);
  1064. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1065. CSR_UCODE_SW_BIT_RFKILL);
  1066. spin_unlock_irqrestore(&priv->lock, flags);
  1067. /* call the host command only if no hw rf-kill set */
  1068. if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
  1069. iwl_is_ready(priv))
  1070. iwl4965_send_card_state(priv,
  1071. CARD_STATE_CMD_DISABLE,
  1072. 0);
  1073. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1074. /* make sure mac80211 stop sending Tx frame */
  1075. if (priv->mac80211_registered)
  1076. ieee80211_stop_queues(priv->hw);
  1077. }
  1078. return;
  1079. }
  1080. spin_lock_irqsave(&priv->lock, flags);
  1081. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1082. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1083. spin_unlock_irqrestore(&priv->lock, flags);
  1084. /* wake up ucode */
  1085. msleep(10);
  1086. spin_lock_irqsave(&priv->lock, flags);
  1087. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1088. if (!iwl_grab_nic_access(priv))
  1089. iwl_release_nic_access(priv);
  1090. spin_unlock_irqrestore(&priv->lock, flags);
  1091. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  1092. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  1093. "disabled by HW switch\n");
  1094. return;
  1095. }
  1096. queue_work(priv->workqueue, &priv->restart);
  1097. return;
  1098. }
  1099. #define IWL_PACKET_RETRY_TIME HZ
  1100. int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  1101. {
  1102. u16 sc = le16_to_cpu(header->seq_ctrl);
  1103. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1104. u16 frag = sc & IEEE80211_SCTL_FRAG;
  1105. u16 *last_seq, *last_frag;
  1106. unsigned long *last_time;
  1107. switch (priv->iw_mode) {
  1108. case IEEE80211_IF_TYPE_IBSS:{
  1109. struct list_head *p;
  1110. struct iwl4965_ibss_seq *entry = NULL;
  1111. u8 *mac = header->addr2;
  1112. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  1113. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  1114. entry = list_entry(p, struct iwl4965_ibss_seq, list);
  1115. if (!compare_ether_addr(entry->mac, mac))
  1116. break;
  1117. }
  1118. if (p == &priv->ibss_mac_hash[index]) {
  1119. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  1120. if (!entry) {
  1121. IWL_ERROR("Cannot malloc new mac entry\n");
  1122. return 0;
  1123. }
  1124. memcpy(entry->mac, mac, ETH_ALEN);
  1125. entry->seq_num = seq;
  1126. entry->frag_num = frag;
  1127. entry->packet_time = jiffies;
  1128. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  1129. return 0;
  1130. }
  1131. last_seq = &entry->seq_num;
  1132. last_frag = &entry->frag_num;
  1133. last_time = &entry->packet_time;
  1134. break;
  1135. }
  1136. case IEEE80211_IF_TYPE_STA:
  1137. last_seq = &priv->last_seq_num;
  1138. last_frag = &priv->last_frag_num;
  1139. last_time = &priv->last_packet_time;
  1140. break;
  1141. default:
  1142. return 0;
  1143. }
  1144. if ((*last_seq == seq) &&
  1145. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  1146. if (*last_frag == frag)
  1147. goto drop;
  1148. if (*last_frag + 1 != frag)
  1149. /* out-of-order fragment */
  1150. goto drop;
  1151. } else
  1152. *last_seq = seq;
  1153. *last_frag = frag;
  1154. *last_time = jiffies;
  1155. return 0;
  1156. drop:
  1157. return 1;
  1158. }
  1159. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1160. #include "iwl-spectrum.h"
  1161. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1162. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1163. #define TIME_UNIT 1024
  1164. /*
  1165. * extended beacon time format
  1166. * time in usec will be changed into a 32-bit value in 8:24 format
  1167. * the high 1 byte is the beacon counts
  1168. * the lower 3 bytes is the time in usec within one beacon interval
  1169. */
  1170. static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1171. {
  1172. u32 quot;
  1173. u32 rem;
  1174. u32 interval = beacon_interval * 1024;
  1175. if (!interval || !usec)
  1176. return 0;
  1177. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1178. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1179. return (quot << 24) + rem;
  1180. }
  1181. /* base is usually what we get from ucode with each received frame,
  1182. * the same as HW timer counter counting down
  1183. */
  1184. static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1185. {
  1186. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1187. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1188. u32 interval = beacon_interval * TIME_UNIT;
  1189. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1190. (addon & BEACON_TIME_MASK_HIGH);
  1191. if (base_low > addon_low)
  1192. res += base_low - addon_low;
  1193. else if (base_low < addon_low) {
  1194. res += interval + base_low - addon_low;
  1195. res += (1 << 24);
  1196. } else
  1197. res += (1 << 24);
  1198. return cpu_to_le32(res);
  1199. }
  1200. static int iwl4965_get_measurement(struct iwl_priv *priv,
  1201. struct ieee80211_measurement_params *params,
  1202. u8 type)
  1203. {
  1204. struct iwl4965_spectrum_cmd spectrum;
  1205. struct iwl_rx_packet *res;
  1206. struct iwl_host_cmd cmd = {
  1207. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1208. .data = (void *)&spectrum,
  1209. .meta.flags = CMD_WANT_SKB,
  1210. };
  1211. u32 add_time = le64_to_cpu(params->start_time);
  1212. int rc;
  1213. int spectrum_resp_status;
  1214. int duration = le16_to_cpu(params->duration);
  1215. if (iwl_is_associated(priv))
  1216. add_time =
  1217. iwl4965_usecs_to_beacons(
  1218. le64_to_cpu(params->start_time) - priv->last_tsf,
  1219. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1220. memset(&spectrum, 0, sizeof(spectrum));
  1221. spectrum.channel_count = cpu_to_le16(1);
  1222. spectrum.flags =
  1223. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1224. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1225. cmd.len = sizeof(spectrum);
  1226. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1227. if (iwl_is_associated(priv))
  1228. spectrum.start_time =
  1229. iwl4965_add_beacon_time(priv->last_beacon_time,
  1230. add_time,
  1231. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1232. else
  1233. spectrum.start_time = 0;
  1234. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1235. spectrum.channels[0].channel = params->channel;
  1236. spectrum.channels[0].type = type;
  1237. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1238. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1239. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1240. rc = iwl_send_cmd_sync(priv, &cmd);
  1241. if (rc)
  1242. return rc;
  1243. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1244. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1245. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  1246. rc = -EIO;
  1247. }
  1248. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1249. switch (spectrum_resp_status) {
  1250. case 0: /* Command will be handled */
  1251. if (res->u.spectrum.id != 0xff) {
  1252. IWL_DEBUG_INFO
  1253. ("Replaced existing measurement: %d\n",
  1254. res->u.spectrum.id);
  1255. priv->measurement_status &= ~MEASUREMENT_READY;
  1256. }
  1257. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1258. rc = 0;
  1259. break;
  1260. case 1: /* Command will not be handled */
  1261. rc = -EAGAIN;
  1262. break;
  1263. }
  1264. dev_kfree_skb_any(cmd.meta.u.skb);
  1265. return rc;
  1266. }
  1267. #endif
  1268. /******************************************************************************
  1269. *
  1270. * Generic RX handler implementations
  1271. *
  1272. ******************************************************************************/
  1273. static void iwl_rx_reply_alive(struct iwl_priv *priv,
  1274. struct iwl_rx_mem_buffer *rxb)
  1275. {
  1276. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1277. struct iwl_alive_resp *palive;
  1278. struct delayed_work *pwork;
  1279. palive = &pkt->u.alive_frame;
  1280. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  1281. "0x%01X 0x%01X\n",
  1282. palive->is_valid, palive->ver_type,
  1283. palive->ver_subtype);
  1284. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1285. IWL_DEBUG_INFO("Initialization Alive received.\n");
  1286. memcpy(&priv->card_alive_init,
  1287. &pkt->u.alive_frame,
  1288. sizeof(struct iwl_init_alive_resp));
  1289. pwork = &priv->init_alive_start;
  1290. } else {
  1291. IWL_DEBUG_INFO("Runtime Alive received.\n");
  1292. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1293. sizeof(struct iwl_alive_resp));
  1294. pwork = &priv->alive_start;
  1295. }
  1296. /* We delay the ALIVE response by 5ms to
  1297. * give the HW RF Kill time to activate... */
  1298. if (palive->is_valid == UCODE_VALID_OK)
  1299. queue_delayed_work(priv->workqueue, pwork,
  1300. msecs_to_jiffies(5));
  1301. else
  1302. IWL_WARNING("uCode did not respond OK.\n");
  1303. }
  1304. static void iwl4965_rx_reply_error(struct iwl_priv *priv,
  1305. struct iwl_rx_mem_buffer *rxb)
  1306. {
  1307. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1308. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  1309. "seq 0x%04X ser 0x%08X\n",
  1310. le32_to_cpu(pkt->u.err_resp.error_type),
  1311. get_cmd_string(pkt->u.err_resp.cmd_id),
  1312. pkt->u.err_resp.cmd_id,
  1313. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1314. le32_to_cpu(pkt->u.err_resp.error_info));
  1315. }
  1316. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1317. static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1318. {
  1319. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1320. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1321. struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
  1322. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  1323. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1324. rxon->channel = csa->channel;
  1325. priv->staging_rxon.channel = csa->channel;
  1326. }
  1327. static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1328. struct iwl_rx_mem_buffer *rxb)
  1329. {
  1330. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1331. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1332. struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1333. if (!report->state) {
  1334. IWL_DEBUG(IWL_DL_11H,
  1335. "Spectrum Measure Notification: Start\n");
  1336. return;
  1337. }
  1338. memcpy(&priv->measure_report, report, sizeof(*report));
  1339. priv->measurement_status |= MEASUREMENT_READY;
  1340. #endif
  1341. }
  1342. static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
  1343. struct iwl_rx_mem_buffer *rxb)
  1344. {
  1345. #ifdef CONFIG_IWLWIFI_DEBUG
  1346. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1347. struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1348. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  1349. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1350. #endif
  1351. }
  1352. static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1353. struct iwl_rx_mem_buffer *rxb)
  1354. {
  1355. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1356. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  1357. "notification for %s:\n",
  1358. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1359. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1360. }
  1361. static void iwl4965_bg_beacon_update(struct work_struct *work)
  1362. {
  1363. struct iwl_priv *priv =
  1364. container_of(work, struct iwl_priv, beacon_update);
  1365. struct sk_buff *beacon;
  1366. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1367. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1368. if (!beacon) {
  1369. IWL_ERROR("update beacon failed\n");
  1370. return;
  1371. }
  1372. mutex_lock(&priv->mutex);
  1373. /* new beacon skb is allocated every time; dispose previous.*/
  1374. if (priv->ibss_beacon)
  1375. dev_kfree_skb(priv->ibss_beacon);
  1376. priv->ibss_beacon = beacon;
  1377. mutex_unlock(&priv->mutex);
  1378. iwl4965_send_beacon_cmd(priv);
  1379. }
  1380. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  1381. struct iwl_rx_mem_buffer *rxb)
  1382. {
  1383. #ifdef CONFIG_IWLWIFI_DEBUG
  1384. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1385. struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
  1386. u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  1387. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  1388. "tsf %d %d rate %d\n",
  1389. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1390. beacon->beacon_notify_hdr.failure_frame,
  1391. le32_to_cpu(beacon->ibss_mgr_status),
  1392. le32_to_cpu(beacon->high_tsf),
  1393. le32_to_cpu(beacon->low_tsf), rate);
  1394. #endif
  1395. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  1396. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1397. queue_work(priv->workqueue, &priv->beacon_update);
  1398. }
  1399. /* Service response to REPLY_SCAN_CMD (0x80) */
  1400. static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
  1401. struct iwl_rx_mem_buffer *rxb)
  1402. {
  1403. #ifdef CONFIG_IWLWIFI_DEBUG
  1404. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1405. struct iwl4965_scanreq_notification *notif =
  1406. (struct iwl4965_scanreq_notification *)pkt->u.raw;
  1407. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  1408. #endif
  1409. }
  1410. /* Service SCAN_START_NOTIFICATION (0x82) */
  1411. static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
  1412. struct iwl_rx_mem_buffer *rxb)
  1413. {
  1414. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1415. struct iwl4965_scanstart_notification *notif =
  1416. (struct iwl4965_scanstart_notification *)pkt->u.raw;
  1417. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  1418. IWL_DEBUG_SCAN("Scan start: "
  1419. "%d [802.11%s] "
  1420. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  1421. notif->channel,
  1422. notif->band ? "bg" : "a",
  1423. notif->tsf_high,
  1424. notif->tsf_low, notif->status, notif->beacon_timer);
  1425. }
  1426. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  1427. static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
  1428. struct iwl_rx_mem_buffer *rxb)
  1429. {
  1430. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1431. struct iwl4965_scanresults_notification *notif =
  1432. (struct iwl4965_scanresults_notification *)pkt->u.raw;
  1433. IWL_DEBUG_SCAN("Scan ch.res: "
  1434. "%d [802.11%s] "
  1435. "(TSF: 0x%08X:%08X) - %d "
  1436. "elapsed=%lu usec (%dms since last)\n",
  1437. notif->channel,
  1438. notif->band ? "bg" : "a",
  1439. le32_to_cpu(notif->tsf_high),
  1440. le32_to_cpu(notif->tsf_low),
  1441. le32_to_cpu(notif->statistics[0]),
  1442. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  1443. jiffies_to_msecs(elapsed_jiffies
  1444. (priv->last_scan_jiffies, jiffies)));
  1445. priv->last_scan_jiffies = jiffies;
  1446. priv->next_scan_jiffies = 0;
  1447. }
  1448. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  1449. static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
  1450. struct iwl_rx_mem_buffer *rxb)
  1451. {
  1452. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1453. struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  1454. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  1455. scan_notif->scanned_channels,
  1456. scan_notif->tsf_low,
  1457. scan_notif->tsf_high, scan_notif->status);
  1458. /* The HW is no longer scanning */
  1459. clear_bit(STATUS_SCAN_HW, &priv->status);
  1460. /* The scan completion notification came in, so kill that timer... */
  1461. cancel_delayed_work(&priv->scan_check);
  1462. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  1463. (priv->scan_bands == 2) ? "2.4" : "5.2",
  1464. jiffies_to_msecs(elapsed_jiffies
  1465. (priv->scan_pass_start, jiffies)));
  1466. /* Remove this scanned band from the list
  1467. * of pending bands to scan */
  1468. priv->scan_bands--;
  1469. /* If a request to abort was given, or the scan did not succeed
  1470. * then we reset the scan state machine and terminate,
  1471. * re-queuing another scan if one has been requested */
  1472. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1473. IWL_DEBUG_INFO("Aborted scan completed.\n");
  1474. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1475. } else {
  1476. /* If there are more bands on this scan pass reschedule */
  1477. if (priv->scan_bands > 0)
  1478. goto reschedule;
  1479. }
  1480. priv->last_scan_jiffies = jiffies;
  1481. priv->next_scan_jiffies = 0;
  1482. IWL_DEBUG_INFO("Setting scan to off\n");
  1483. clear_bit(STATUS_SCANNING, &priv->status);
  1484. IWL_DEBUG_INFO("Scan took %dms\n",
  1485. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  1486. queue_work(priv->workqueue, &priv->scan_completed);
  1487. return;
  1488. reschedule:
  1489. priv->scan_pass_start = jiffies;
  1490. queue_work(priv->workqueue, &priv->request_scan);
  1491. }
  1492. /* Handle notification from uCode that card's power state is changing
  1493. * due to software, hardware, or critical temperature RFKILL */
  1494. static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
  1495. struct iwl_rx_mem_buffer *rxb)
  1496. {
  1497. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1498. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1499. unsigned long status = priv->status;
  1500. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  1501. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1502. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1503. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  1504. RF_CARD_DISABLED)) {
  1505. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1506. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1507. if (!iwl_grab_nic_access(priv)) {
  1508. iwl_write_direct32(
  1509. priv, HBUS_TARG_MBX_C,
  1510. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1511. iwl_release_nic_access(priv);
  1512. }
  1513. if (!(flags & RXON_CARD_DISABLED)) {
  1514. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1515. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1516. if (!iwl_grab_nic_access(priv)) {
  1517. iwl_write_direct32(
  1518. priv, HBUS_TARG_MBX_C,
  1519. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1520. iwl_release_nic_access(priv);
  1521. }
  1522. }
  1523. if (flags & RF_CARD_DISABLED) {
  1524. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1525. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1526. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1527. if (!iwl_grab_nic_access(priv))
  1528. iwl_release_nic_access(priv);
  1529. }
  1530. }
  1531. if (flags & HW_CARD_DISABLED)
  1532. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1533. else
  1534. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1535. if (flags & SW_CARD_DISABLED)
  1536. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1537. else
  1538. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1539. if (!(flags & RXON_CARD_DISABLED))
  1540. iwl4965_scan_cancel(priv);
  1541. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1542. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1543. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1544. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1545. queue_work(priv->workqueue, &priv->rf_kill);
  1546. else
  1547. wake_up_interruptible(&priv->wait_command_queue);
  1548. }
  1549. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  1550. * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  1551. static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
  1552. struct iwl_rx_mem_buffer *rxb)
  1553. {
  1554. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1555. priv->last_phy_res[0] = 1;
  1556. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  1557. sizeof(struct iwl4965_rx_phy_res));
  1558. }
  1559. /**
  1560. * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
  1561. *
  1562. * Setup the RX handlers for each of the reply types sent from the uCode
  1563. * to the host.
  1564. *
  1565. * This function chains into the hardware specific files for them to setup
  1566. * any hardware specific handlers as well.
  1567. */
  1568. static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
  1569. {
  1570. priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
  1571. priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
  1572. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
  1573. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1574. iwl4965_rx_spectrum_measure_notif;
  1575. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
  1576. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1577. iwl4965_rx_pm_debug_statistics_notif;
  1578. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  1579. /*
  1580. * The same handler is used for both the REPLY to a discrete
  1581. * statistics request from the host as well as for the periodic
  1582. * statistics notifications (after received beacons) from the uCode.
  1583. */
  1584. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
  1585. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
  1586. /* scan handlers */
  1587. priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
  1588. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
  1589. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  1590. iwl4965_rx_scan_results_notif;
  1591. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  1592. iwl4965_rx_scan_complete_notif;
  1593. /* status change handler */
  1594. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
  1595. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  1596. iwl_rx_missed_beacon_notif;
  1597. /* Rx handlers */
  1598. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  1599. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  1600. /* Set up hardware specific Rx handlers */
  1601. priv->cfg->ops->lib->rx_handler_setup(priv);
  1602. }
  1603. /*
  1604. * this should be called while priv->lock is locked
  1605. */
  1606. static void __iwl_rx_replenish(struct iwl_priv *priv)
  1607. {
  1608. iwl_rx_allocate(priv);
  1609. iwl_rx_queue_restock(priv);
  1610. }
  1611. /**
  1612. * iwl_rx_handle - Main entry function for receiving responses from uCode
  1613. *
  1614. * Uses the priv->rx_handlers callback function array to invoke
  1615. * the appropriate handlers, including command responses,
  1616. * frame-received notifications, and other notifications.
  1617. */
  1618. void iwl_rx_handle(struct iwl_priv *priv)
  1619. {
  1620. struct iwl_rx_mem_buffer *rxb;
  1621. struct iwl_rx_packet *pkt;
  1622. struct iwl_rx_queue *rxq = &priv->rxq;
  1623. u32 r, i;
  1624. int reclaim;
  1625. unsigned long flags;
  1626. u8 fill_rx = 0;
  1627. u32 count = 8;
  1628. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1629. * buffer that the driver may process (last buffer filled by ucode). */
  1630. r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
  1631. i = rxq->read;
  1632. /* Rx interrupt, but nothing sent from uCode */
  1633. if (i == r)
  1634. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
  1635. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  1636. fill_rx = 1;
  1637. while (i != r) {
  1638. rxb = rxq->queue[i];
  1639. /* If an RXB doesn't have a Rx queue slot associated with it,
  1640. * then a bug has been introduced in the queue refilling
  1641. * routines -- catch it here */
  1642. BUG_ON(rxb == NULL);
  1643. rxq->queue[i] = NULL;
  1644. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  1645. priv->hw_params.rx_buf_size,
  1646. PCI_DMA_FROMDEVICE);
  1647. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1648. /* Reclaim a command buffer only if this packet is a response
  1649. * to a (driver-originated) command.
  1650. * If the packet (e.g. Rx frame) originated from uCode,
  1651. * there is no command buffer to reclaim.
  1652. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1653. * but apparently a few don't get set; catch them here. */
  1654. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1655. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  1656. (pkt->hdr.cmd != REPLY_RX) &&
  1657. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  1658. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1659. (pkt->hdr.cmd != REPLY_TX);
  1660. /* Based on type of command response or notification,
  1661. * handle those that need handling via function in
  1662. * rx_handlers table. See iwl4965_setup_rx_handlers() */
  1663. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1664. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
  1665. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1666. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1667. } else {
  1668. /* No handling needed */
  1669. IWL_DEBUG(IWL_DL_RX,
  1670. "r %d i %d No handler needed for %s, 0x%02x\n",
  1671. r, i, get_cmd_string(pkt->hdr.cmd),
  1672. pkt->hdr.cmd);
  1673. }
  1674. if (reclaim) {
  1675. /* Invoke any callbacks, transfer the skb to caller, and
  1676. * fire off the (possibly) blocking iwl_send_cmd()
  1677. * as we reclaim the driver command queue */
  1678. if (rxb && rxb->skb)
  1679. iwl_tx_cmd_complete(priv, rxb);
  1680. else
  1681. IWL_WARNING("Claim null rxb?\n");
  1682. }
  1683. /* For now we just don't re-use anything. We can tweak this
  1684. * later to try and re-use notification packets and SKBs that
  1685. * fail to Rx correctly */
  1686. if (rxb->skb != NULL) {
  1687. priv->alloc_rxb_skb--;
  1688. dev_kfree_skb_any(rxb->skb);
  1689. rxb->skb = NULL;
  1690. }
  1691. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  1692. priv->hw_params.rx_buf_size,
  1693. PCI_DMA_FROMDEVICE);
  1694. spin_lock_irqsave(&rxq->lock, flags);
  1695. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  1696. spin_unlock_irqrestore(&rxq->lock, flags);
  1697. i = (i + 1) & RX_QUEUE_MASK;
  1698. /* If there are a lot of unused frames,
  1699. * restock the Rx queue so ucode wont assert. */
  1700. if (fill_rx) {
  1701. count++;
  1702. if (count >= 8) {
  1703. priv->rxq.read = i;
  1704. __iwl_rx_replenish(priv);
  1705. count = 0;
  1706. }
  1707. }
  1708. }
  1709. /* Backtrack one entry */
  1710. priv->rxq.read = i;
  1711. iwl_rx_queue_restock(priv);
  1712. }
  1713. /* Convert linear signal-to-noise ratio into dB */
  1714. static u8 ratio2dB[100] = {
  1715. /* 0 1 2 3 4 5 6 7 8 9 */
  1716. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1717. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1718. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1719. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1720. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1721. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1722. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1723. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1724. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1725. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1726. };
  1727. /* Calculates a relative dB value from a ratio of linear
  1728. * (i.e. not dB) signal levels.
  1729. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1730. int iwl4965_calc_db_from_ratio(int sig_ratio)
  1731. {
  1732. /* 1000:1 or higher just report as 60 dB */
  1733. if (sig_ratio >= 1000)
  1734. return 60;
  1735. /* 100:1 or higher, divide by 10 and use table,
  1736. * add 20 dB to make up for divide by 10 */
  1737. if (sig_ratio >= 100)
  1738. return (20 + (int)ratio2dB[sig_ratio/10]);
  1739. /* We shouldn't see this */
  1740. if (sig_ratio < 1)
  1741. return 0;
  1742. /* Use table for ratios 1:1 - 99:1 */
  1743. return (int)ratio2dB[sig_ratio];
  1744. }
  1745. #define PERFECT_RSSI (-20) /* dBm */
  1746. #define WORST_RSSI (-95) /* dBm */
  1747. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  1748. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  1749. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  1750. * about formulas used below. */
  1751. int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
  1752. {
  1753. int sig_qual;
  1754. int degradation = PERFECT_RSSI - rssi_dbm;
  1755. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  1756. * as indicator; formula is (signal dbm - noise dbm).
  1757. * SNR at or above 40 is a great signal (100%).
  1758. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  1759. * Weakest usable signal is usually 10 - 15 dB SNR. */
  1760. if (noise_dbm) {
  1761. if (rssi_dbm - noise_dbm >= 40)
  1762. return 100;
  1763. else if (rssi_dbm < noise_dbm)
  1764. return 0;
  1765. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  1766. /* Else use just the signal level.
  1767. * This formula is a least squares fit of data points collected and
  1768. * compared with a reference system that had a percentage (%) display
  1769. * for signal quality. */
  1770. } else
  1771. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  1772. (15 * RSSI_RANGE + 62 * degradation)) /
  1773. (RSSI_RANGE * RSSI_RANGE);
  1774. if (sig_qual > 100)
  1775. sig_qual = 100;
  1776. else if (sig_qual < 1)
  1777. sig_qual = 0;
  1778. return sig_qual;
  1779. }
  1780. #ifdef CONFIG_IWLWIFI_DEBUG
  1781. static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
  1782. {
  1783. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  1784. DECLARE_MAC_BUF(mac);
  1785. IWL_DEBUG_RADIO("RX CONFIG:\n");
  1786. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  1787. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  1788. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  1789. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  1790. le32_to_cpu(rxon->filter_flags));
  1791. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  1792. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  1793. rxon->ofdm_basic_rates);
  1794. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  1795. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  1796. print_mac(mac, rxon->node_addr));
  1797. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  1798. print_mac(mac, rxon->bssid_addr));
  1799. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  1800. }
  1801. #endif
  1802. static void iwl4965_enable_interrupts(struct iwl_priv *priv)
  1803. {
  1804. IWL_DEBUG_ISR("Enabling interrupts\n");
  1805. set_bit(STATUS_INT_ENABLED, &priv->status);
  1806. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  1807. }
  1808. /* call this function to flush any scheduled tasklet */
  1809. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1810. {
  1811. /* wait to make sure we flush pedding tasklet*/
  1812. synchronize_irq(priv->pci_dev->irq);
  1813. tasklet_kill(&priv->irq_tasklet);
  1814. }
  1815. static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
  1816. {
  1817. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1818. /* disable interrupts from uCode/NIC to host */
  1819. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1820. /* acknowledge/clear/reset any interrupts still pending
  1821. * from uCode or flow handler (Rx/Tx DMA) */
  1822. iwl_write32(priv, CSR_INT, 0xffffffff);
  1823. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1824. IWL_DEBUG_ISR("Disabled interrupts\n");
  1825. }
  1826. /**
  1827. * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
  1828. */
  1829. static void iwl4965_irq_handle_error(struct iwl_priv *priv)
  1830. {
  1831. /* Set the FW error flag -- cleared on iwl4965_down */
  1832. set_bit(STATUS_FW_ERROR, &priv->status);
  1833. /* Cancel currently queued command. */
  1834. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1835. #ifdef CONFIG_IWLWIFI_DEBUG
  1836. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  1837. iwl_dump_nic_error_log(priv);
  1838. iwl_dump_nic_event_log(priv);
  1839. iwl4965_print_rx_config_cmd(priv);
  1840. }
  1841. #endif
  1842. wake_up_interruptible(&priv->wait_command_queue);
  1843. /* Keep the restart process from trying to send host
  1844. * commands by clearing the INIT status bit */
  1845. clear_bit(STATUS_READY, &priv->status);
  1846. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1847. IWL_DEBUG(IWL_DL_FW_ERRORS,
  1848. "Restarting adapter due to uCode error.\n");
  1849. if (iwl_is_associated(priv)) {
  1850. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  1851. sizeof(priv->recovery_rxon));
  1852. priv->error_recovering = 1;
  1853. }
  1854. if (priv->cfg->mod_params->restart_fw)
  1855. queue_work(priv->workqueue, &priv->restart);
  1856. }
  1857. }
  1858. static void iwl4965_error_recovery(struct iwl_priv *priv)
  1859. {
  1860. unsigned long flags;
  1861. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  1862. sizeof(priv->staging_rxon));
  1863. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1864. iwl4965_commit_rxon(priv);
  1865. iwl_rxon_add_station(priv, priv->bssid, 1);
  1866. spin_lock_irqsave(&priv->lock, flags);
  1867. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  1868. priv->error_recovering = 0;
  1869. spin_unlock_irqrestore(&priv->lock, flags);
  1870. }
  1871. static void iwl4965_irq_tasklet(struct iwl_priv *priv)
  1872. {
  1873. u32 inta, handled = 0;
  1874. u32 inta_fh;
  1875. unsigned long flags;
  1876. #ifdef CONFIG_IWLWIFI_DEBUG
  1877. u32 inta_mask;
  1878. #endif
  1879. spin_lock_irqsave(&priv->lock, flags);
  1880. /* Ack/clear/reset pending uCode interrupts.
  1881. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1882. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1883. inta = iwl_read32(priv, CSR_INT);
  1884. iwl_write32(priv, CSR_INT, inta);
  1885. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1886. * Any new interrupts that happen after this, either while we're
  1887. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1888. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1889. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1890. #ifdef CONFIG_IWLWIFI_DEBUG
  1891. if (priv->debug_level & IWL_DL_ISR) {
  1892. /* just for debug */
  1893. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1894. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1895. inta, inta_mask, inta_fh);
  1896. }
  1897. #endif
  1898. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1899. * atomic, make sure that inta covers all the interrupts that
  1900. * we've discovered, even if FH interrupt came in just after
  1901. * reading CSR_INT. */
  1902. if (inta_fh & CSR49_FH_INT_RX_MASK)
  1903. inta |= CSR_INT_BIT_FH_RX;
  1904. if (inta_fh & CSR49_FH_INT_TX_MASK)
  1905. inta |= CSR_INT_BIT_FH_TX;
  1906. /* Now service all interrupt bits discovered above. */
  1907. if (inta & CSR_INT_BIT_HW_ERR) {
  1908. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  1909. /* Tell the device to stop sending interrupts */
  1910. iwl4965_disable_interrupts(priv);
  1911. iwl4965_irq_handle_error(priv);
  1912. handled |= CSR_INT_BIT_HW_ERR;
  1913. spin_unlock_irqrestore(&priv->lock, flags);
  1914. return;
  1915. }
  1916. #ifdef CONFIG_IWLWIFI_DEBUG
  1917. if (priv->debug_level & (IWL_DL_ISR)) {
  1918. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1919. if (inta & CSR_INT_BIT_SCD)
  1920. IWL_DEBUG_ISR("Scheduler finished to transmit "
  1921. "the frame/frames.\n");
  1922. /* Alive notification via Rx interrupt will do the real work */
  1923. if (inta & CSR_INT_BIT_ALIVE)
  1924. IWL_DEBUG_ISR("Alive interrupt\n");
  1925. }
  1926. #endif
  1927. /* Safely ignore these bits for debug checks below */
  1928. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1929. /* HW RF KILL switch toggled */
  1930. if (inta & CSR_INT_BIT_RF_KILL) {
  1931. int hw_rf_kill = 0;
  1932. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1933. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1934. hw_rf_kill = 1;
  1935. IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
  1936. hw_rf_kill ? "disable radio":"enable radio");
  1937. /* Queue restart only if RF_KILL switch was set to "kill"
  1938. * when we loaded driver, and is now set to "enable".
  1939. * After we're Alive, RF_KILL gets handled by
  1940. * iwl4965_rx_card_state_notif() */
  1941. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  1942. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1943. queue_work(priv->workqueue, &priv->restart);
  1944. }
  1945. handled |= CSR_INT_BIT_RF_KILL;
  1946. }
  1947. /* Chip got too hot and stopped itself */
  1948. if (inta & CSR_INT_BIT_CT_KILL) {
  1949. IWL_ERROR("Microcode CT kill error detected.\n");
  1950. handled |= CSR_INT_BIT_CT_KILL;
  1951. }
  1952. /* Error detected by uCode */
  1953. if (inta & CSR_INT_BIT_SW_ERR) {
  1954. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  1955. inta);
  1956. iwl4965_irq_handle_error(priv);
  1957. handled |= CSR_INT_BIT_SW_ERR;
  1958. }
  1959. /* uCode wakes up after power-down sleep */
  1960. if (inta & CSR_INT_BIT_WAKEUP) {
  1961. IWL_DEBUG_ISR("Wakeup interrupt\n");
  1962. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1963. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1964. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1965. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1966. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1967. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1968. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1969. handled |= CSR_INT_BIT_WAKEUP;
  1970. }
  1971. /* All uCode command responses, including Tx command responses,
  1972. * Rx "responses" (frame-received notification), and other
  1973. * notifications from uCode come through here*/
  1974. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1975. iwl_rx_handle(priv);
  1976. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1977. }
  1978. if (inta & CSR_INT_BIT_FH_TX) {
  1979. IWL_DEBUG_ISR("Tx interrupt\n");
  1980. handled |= CSR_INT_BIT_FH_TX;
  1981. /* FH finished to write, send event */
  1982. priv->ucode_write_complete = 1;
  1983. wake_up_interruptible(&priv->wait_command_queue);
  1984. }
  1985. if (inta & ~handled)
  1986. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1987. if (inta & ~CSR_INI_SET_MASK) {
  1988. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  1989. inta & ~CSR_INI_SET_MASK);
  1990. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  1991. }
  1992. /* Re-enable all interrupts */
  1993. /* only Re-enable if diabled by irq */
  1994. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1995. iwl4965_enable_interrupts(priv);
  1996. #ifdef CONFIG_IWLWIFI_DEBUG
  1997. if (priv->debug_level & (IWL_DL_ISR)) {
  1998. inta = iwl_read32(priv, CSR_INT);
  1999. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2000. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2001. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  2002. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  2003. }
  2004. #endif
  2005. spin_unlock_irqrestore(&priv->lock, flags);
  2006. }
  2007. static irqreturn_t iwl4965_isr(int irq, void *data)
  2008. {
  2009. struct iwl_priv *priv = data;
  2010. u32 inta, inta_mask;
  2011. u32 inta_fh;
  2012. if (!priv)
  2013. return IRQ_NONE;
  2014. spin_lock(&priv->lock);
  2015. /* Disable (but don't clear!) interrupts here to avoid
  2016. * back-to-back ISRs and sporadic interrupts from our NIC.
  2017. * If we have something to service, the tasklet will re-enable ints.
  2018. * If we *don't* have something, we'll re-enable before leaving here. */
  2019. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2020. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2021. /* Discover which interrupts are active/pending */
  2022. inta = iwl_read32(priv, CSR_INT);
  2023. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2024. /* Ignore interrupt if there's nothing in NIC to service.
  2025. * This may be due to IRQ shared with another device,
  2026. * or due to sporadic interrupts thrown from our NIC. */
  2027. if (!inta && !inta_fh) {
  2028. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  2029. goto none;
  2030. }
  2031. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2032. /* Hardware disappeared. It might have already raised
  2033. * an interrupt */
  2034. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  2035. goto unplugged;
  2036. }
  2037. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2038. inta, inta_mask, inta_fh);
  2039. inta &= ~CSR_INT_BIT_SCD;
  2040. /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
  2041. if (likely(inta || inta_fh))
  2042. tasklet_schedule(&priv->irq_tasklet);
  2043. unplugged:
  2044. spin_unlock(&priv->lock);
  2045. return IRQ_HANDLED;
  2046. none:
  2047. /* re-enable interrupts here since we don't have anything to service. */
  2048. /* only Re-enable if diabled by irq */
  2049. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2050. iwl4965_enable_interrupts(priv);
  2051. spin_unlock(&priv->lock);
  2052. return IRQ_NONE;
  2053. }
  2054. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  2055. * sending probe req. This should be set long enough to hear probe responses
  2056. * from more than one AP. */
  2057. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  2058. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  2059. /* For faster active scanning, scan will move to the next channel if fewer than
  2060. * PLCP_QUIET_THRESH packets are heard on this channel within
  2061. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  2062. * time if it's a quiet channel (nothing responded to our probe, and there's
  2063. * no other traffic).
  2064. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  2065. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  2066. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  2067. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  2068. * Must be set longer than active dwell time.
  2069. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  2070. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  2071. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  2072. #define IWL_PASSIVE_DWELL_BASE (100)
  2073. #define IWL_CHANNEL_TUNE_TIME 5
  2074. static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
  2075. enum ieee80211_band band)
  2076. {
  2077. if (band == IEEE80211_BAND_5GHZ)
  2078. return IWL_ACTIVE_DWELL_TIME_52;
  2079. else
  2080. return IWL_ACTIVE_DWELL_TIME_24;
  2081. }
  2082. static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
  2083. enum ieee80211_band band)
  2084. {
  2085. u16 active = iwl4965_get_active_dwell_time(priv, band);
  2086. u16 passive = (band != IEEE80211_BAND_5GHZ) ?
  2087. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  2088. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  2089. if (iwl_is_associated(priv)) {
  2090. /* If we're associated, we clamp the maximum passive
  2091. * dwell time to be 98% of the beacon interval (minus
  2092. * 2 * channel tune time) */
  2093. passive = priv->beacon_int;
  2094. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  2095. passive = IWL_PASSIVE_DWELL_BASE;
  2096. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  2097. }
  2098. if (passive <= active)
  2099. passive = active + 1;
  2100. return passive;
  2101. }
  2102. static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
  2103. enum ieee80211_band band,
  2104. u8 is_active, u8 direct_mask,
  2105. struct iwl4965_scan_channel *scan_ch)
  2106. {
  2107. const struct ieee80211_channel *channels = NULL;
  2108. const struct ieee80211_supported_band *sband;
  2109. const struct iwl_channel_info *ch_info;
  2110. u16 passive_dwell = 0;
  2111. u16 active_dwell = 0;
  2112. int added, i;
  2113. sband = iwl_get_hw_mode(priv, band);
  2114. if (!sband)
  2115. return 0;
  2116. channels = sband->channels;
  2117. active_dwell = iwl4965_get_active_dwell_time(priv, band);
  2118. passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
  2119. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2120. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2121. continue;
  2122. scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
  2123. ch_info = iwl_get_channel_info(priv, band,
  2124. scan_ch->channel);
  2125. if (!is_channel_valid(ch_info)) {
  2126. IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
  2127. scan_ch->channel);
  2128. continue;
  2129. }
  2130. if (!is_active || is_channel_passive(ch_info) ||
  2131. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
  2132. scan_ch->type = 0; /* passive */
  2133. else
  2134. scan_ch->type = 1; /* active */
  2135. if (scan_ch->type & 1)
  2136. scan_ch->type |= (direct_mask << 1);
  2137. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2138. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2139. /* Set txpower levels to defaults */
  2140. scan_ch->tpc.dsp_atten = 110;
  2141. /* scan_pwr_info->tpc.dsp_atten; */
  2142. /*scan_pwr_info->tpc.tx_gain; */
  2143. if (band == IEEE80211_BAND_5GHZ)
  2144. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2145. else {
  2146. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2147. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2148. * power level:
  2149. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2150. */
  2151. }
  2152. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  2153. scan_ch->channel,
  2154. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2155. (scan_ch->type & 1) ?
  2156. active_dwell : passive_dwell);
  2157. scan_ch++;
  2158. added++;
  2159. }
  2160. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  2161. return added;
  2162. }
  2163. /******************************************************************************
  2164. *
  2165. * uCode download functions
  2166. *
  2167. ******************************************************************************/
  2168. static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
  2169. {
  2170. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2171. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2172. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2173. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2174. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2175. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2176. }
  2177. static void iwl4965_nic_start(struct iwl_priv *priv)
  2178. {
  2179. /* Remove all resets to allow NIC to operate */
  2180. iwl_write32(priv, CSR_RESET, 0);
  2181. }
  2182. /**
  2183. * iwl4965_read_ucode - Read uCode images from disk file.
  2184. *
  2185. * Copy into buffers for card to fetch via bus-mastering
  2186. */
  2187. static int iwl4965_read_ucode(struct iwl_priv *priv)
  2188. {
  2189. struct iwl4965_ucode *ucode;
  2190. int ret;
  2191. const struct firmware *ucode_raw;
  2192. const char *name = priv->cfg->fw_name;
  2193. u8 *src;
  2194. size_t len;
  2195. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2196. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2197. * request_firmware() is synchronous, file is in memory on return. */
  2198. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  2199. if (ret < 0) {
  2200. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  2201. name, ret);
  2202. goto error;
  2203. }
  2204. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  2205. name, ucode_raw->size);
  2206. /* Make sure that we got at least our header! */
  2207. if (ucode_raw->size < sizeof(*ucode)) {
  2208. IWL_ERROR("File size way too small!\n");
  2209. ret = -EINVAL;
  2210. goto err_release;
  2211. }
  2212. /* Data from ucode file: header followed by uCode images */
  2213. ucode = (void *)ucode_raw->data;
  2214. ver = le32_to_cpu(ucode->ver);
  2215. inst_size = le32_to_cpu(ucode->inst_size);
  2216. data_size = le32_to_cpu(ucode->data_size);
  2217. init_size = le32_to_cpu(ucode->init_size);
  2218. init_data_size = le32_to_cpu(ucode->init_data_size);
  2219. boot_size = le32_to_cpu(ucode->boot_size);
  2220. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  2221. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
  2222. inst_size);
  2223. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
  2224. data_size);
  2225. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
  2226. init_size);
  2227. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
  2228. init_data_size);
  2229. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
  2230. boot_size);
  2231. /* Verify size of file vs. image size info in file's header */
  2232. if (ucode_raw->size < sizeof(*ucode) +
  2233. inst_size + data_size + init_size +
  2234. init_data_size + boot_size) {
  2235. IWL_DEBUG_INFO("uCode file size %d too small\n",
  2236. (int)ucode_raw->size);
  2237. ret = -EINVAL;
  2238. goto err_release;
  2239. }
  2240. /* Verify that uCode images will fit in card's SRAM */
  2241. if (inst_size > priv->hw_params.max_inst_size) {
  2242. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  2243. inst_size);
  2244. ret = -EINVAL;
  2245. goto err_release;
  2246. }
  2247. if (data_size > priv->hw_params.max_data_size) {
  2248. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  2249. data_size);
  2250. ret = -EINVAL;
  2251. goto err_release;
  2252. }
  2253. if (init_size > priv->hw_params.max_inst_size) {
  2254. IWL_DEBUG_INFO
  2255. ("uCode init instr len %d too large to fit in\n",
  2256. init_size);
  2257. ret = -EINVAL;
  2258. goto err_release;
  2259. }
  2260. if (init_data_size > priv->hw_params.max_data_size) {
  2261. IWL_DEBUG_INFO
  2262. ("uCode init data len %d too large to fit in\n",
  2263. init_data_size);
  2264. ret = -EINVAL;
  2265. goto err_release;
  2266. }
  2267. if (boot_size > priv->hw_params.max_bsm_size) {
  2268. IWL_DEBUG_INFO
  2269. ("uCode boot instr len %d too large to fit in\n",
  2270. boot_size);
  2271. ret = -EINVAL;
  2272. goto err_release;
  2273. }
  2274. /* Allocate ucode buffers for card's bus-master loading ... */
  2275. /* Runtime instructions and 2 copies of data:
  2276. * 1) unmodified from disk
  2277. * 2) backup cache for save/restore during power-downs */
  2278. priv->ucode_code.len = inst_size;
  2279. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  2280. priv->ucode_data.len = data_size;
  2281. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  2282. priv->ucode_data_backup.len = data_size;
  2283. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2284. /* Initialization instructions and data */
  2285. if (init_size && init_data_size) {
  2286. priv->ucode_init.len = init_size;
  2287. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  2288. priv->ucode_init_data.len = init_data_size;
  2289. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2290. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  2291. goto err_pci_alloc;
  2292. }
  2293. /* Bootstrap (instructions only, no data) */
  2294. if (boot_size) {
  2295. priv->ucode_boot.len = boot_size;
  2296. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2297. if (!priv->ucode_boot.v_addr)
  2298. goto err_pci_alloc;
  2299. }
  2300. /* Copy images into buffers for card's bus-master reads ... */
  2301. /* Runtime instructions (first block of data in file) */
  2302. src = &ucode->data[0];
  2303. len = priv->ucode_code.len;
  2304. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  2305. memcpy(priv->ucode_code.v_addr, src, len);
  2306. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  2307. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  2308. /* Runtime data (2nd block)
  2309. * NOTE: Copy into backup buffer will be done in iwl4965_up() */
  2310. src = &ucode->data[inst_size];
  2311. len = priv->ucode_data.len;
  2312. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  2313. memcpy(priv->ucode_data.v_addr, src, len);
  2314. memcpy(priv->ucode_data_backup.v_addr, src, len);
  2315. /* Initialization instructions (3rd block) */
  2316. if (init_size) {
  2317. src = &ucode->data[inst_size + data_size];
  2318. len = priv->ucode_init.len;
  2319. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  2320. len);
  2321. memcpy(priv->ucode_init.v_addr, src, len);
  2322. }
  2323. /* Initialization data (4th block) */
  2324. if (init_data_size) {
  2325. src = &ucode->data[inst_size + data_size + init_size];
  2326. len = priv->ucode_init_data.len;
  2327. IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
  2328. len);
  2329. memcpy(priv->ucode_init_data.v_addr, src, len);
  2330. }
  2331. /* Bootstrap instructions (5th block) */
  2332. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  2333. len = priv->ucode_boot.len;
  2334. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
  2335. memcpy(priv->ucode_boot.v_addr, src, len);
  2336. /* We have our copies now, allow OS release its copies */
  2337. release_firmware(ucode_raw);
  2338. return 0;
  2339. err_pci_alloc:
  2340. IWL_ERROR("failed to allocate pci memory\n");
  2341. ret = -ENOMEM;
  2342. iwl4965_dealloc_ucode_pci(priv);
  2343. err_release:
  2344. release_firmware(ucode_raw);
  2345. error:
  2346. return ret;
  2347. }
  2348. /**
  2349. * iwl_alive_start - called after REPLY_ALIVE notification received
  2350. * from protocol/runtime uCode (initialization uCode's
  2351. * Alive gets handled by iwl_init_alive_start()).
  2352. */
  2353. static void iwl_alive_start(struct iwl_priv *priv)
  2354. {
  2355. int ret = 0;
  2356. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2357. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2358. /* We had an error bringing up the hardware, so take it
  2359. * all the way back down so we can try again */
  2360. IWL_DEBUG_INFO("Alive failed.\n");
  2361. goto restart;
  2362. }
  2363. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2364. * This is a paranoid check, because we would not have gotten the
  2365. * "runtime" alive if code weren't properly loaded. */
  2366. if (iwl_verify_ucode(priv)) {
  2367. /* Runtime instruction load was bad;
  2368. * take it all the way back down so we can try again */
  2369. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  2370. goto restart;
  2371. }
  2372. iwlcore_clear_stations_table(priv);
  2373. ret = priv->cfg->ops->lib->alive_notify(priv);
  2374. if (ret) {
  2375. IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
  2376. ret);
  2377. goto restart;
  2378. }
  2379. /* After the ALIVE response, we can send host commands to 4965 uCode */
  2380. set_bit(STATUS_ALIVE, &priv->status);
  2381. /* Clear out the uCode error bit if it is set */
  2382. clear_bit(STATUS_FW_ERROR, &priv->status);
  2383. if (iwl_is_rfkill(priv))
  2384. return;
  2385. ieee80211_wake_queues(priv->hw);
  2386. priv->active_rate = priv->rates_mask;
  2387. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  2388. if (iwl_is_associated(priv)) {
  2389. struct iwl_rxon_cmd *active_rxon =
  2390. (struct iwl_rxon_cmd *)&priv->active_rxon;
  2391. memcpy(&priv->staging_rxon, &priv->active_rxon,
  2392. sizeof(priv->staging_rxon));
  2393. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2394. } else {
  2395. /* Initialize our rx_config data */
  2396. iwl4965_connection_init_rx_config(priv);
  2397. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2398. }
  2399. /* Configure Bluetooth device coexistence support */
  2400. iwl4965_send_bt_config(priv);
  2401. iwl_reset_run_time_calib(priv);
  2402. /* Configure the adapter for unassociated operation */
  2403. iwl4965_commit_rxon(priv);
  2404. /* At this point, the NIC is initialized and operational */
  2405. iwl4965_rf_kill_ct_config(priv);
  2406. iwl_leds_register(priv);
  2407. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  2408. set_bit(STATUS_READY, &priv->status);
  2409. wake_up_interruptible(&priv->wait_command_queue);
  2410. if (priv->error_recovering)
  2411. iwl4965_error_recovery(priv);
  2412. iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
  2413. ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
  2414. return;
  2415. restart:
  2416. queue_work(priv->workqueue, &priv->restart);
  2417. }
  2418. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
  2419. static void __iwl4965_down(struct iwl_priv *priv)
  2420. {
  2421. unsigned long flags;
  2422. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2423. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  2424. if (!exit_pending)
  2425. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2426. iwl_leds_unregister(priv);
  2427. iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
  2428. iwlcore_clear_stations_table(priv);
  2429. /* Unblock any waiting calls */
  2430. wake_up_interruptible_all(&priv->wait_command_queue);
  2431. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2432. * exiting the module */
  2433. if (!exit_pending)
  2434. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2435. /* stop and reset the on-board processor */
  2436. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2437. /* tell the device to stop sending interrupts */
  2438. spin_lock_irqsave(&priv->lock, flags);
  2439. iwl4965_disable_interrupts(priv);
  2440. spin_unlock_irqrestore(&priv->lock, flags);
  2441. iwl_synchronize_irq(priv);
  2442. if (priv->mac80211_registered)
  2443. ieee80211_stop_queues(priv->hw);
  2444. /* If we have not previously called iwl4965_init() then
  2445. * clear all bits but the RF Kill and SUSPEND bits and return */
  2446. if (!iwl_is_init(priv)) {
  2447. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2448. STATUS_RF_KILL_HW |
  2449. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2450. STATUS_RF_KILL_SW |
  2451. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2452. STATUS_GEO_CONFIGURED |
  2453. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2454. STATUS_IN_SUSPEND;
  2455. goto exit;
  2456. }
  2457. /* ...otherwise clear out all the status bits but the RF Kill and
  2458. * SUSPEND bits and continue taking the NIC down. */
  2459. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2460. STATUS_RF_KILL_HW |
  2461. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2462. STATUS_RF_KILL_SW |
  2463. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2464. STATUS_GEO_CONFIGURED |
  2465. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2466. STATUS_IN_SUSPEND |
  2467. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2468. STATUS_FW_ERROR;
  2469. spin_lock_irqsave(&priv->lock, flags);
  2470. iwl_clear_bit(priv, CSR_GP_CNTRL,
  2471. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2472. spin_unlock_irqrestore(&priv->lock, flags);
  2473. iwl_txq_ctx_stop(priv);
  2474. iwl_rxq_stop(priv);
  2475. spin_lock_irqsave(&priv->lock, flags);
  2476. if (!iwl_grab_nic_access(priv)) {
  2477. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  2478. APMG_CLK_VAL_DMA_CLK_RQT);
  2479. iwl_release_nic_access(priv);
  2480. }
  2481. spin_unlock_irqrestore(&priv->lock, flags);
  2482. udelay(5);
  2483. /* FIXME: apm_ops.suspend(priv) */
  2484. priv->cfg->ops->lib->apm_ops.reset(priv);
  2485. priv->cfg->ops->lib->free_shared_mem(priv);
  2486. exit:
  2487. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2488. if (priv->ibss_beacon)
  2489. dev_kfree_skb(priv->ibss_beacon);
  2490. priv->ibss_beacon = NULL;
  2491. /* clear out any free frames */
  2492. iwl_clear_free_frames(priv);
  2493. }
  2494. static void iwl4965_down(struct iwl_priv *priv)
  2495. {
  2496. mutex_lock(&priv->mutex);
  2497. __iwl4965_down(priv);
  2498. mutex_unlock(&priv->mutex);
  2499. iwl4965_cancel_deferred_work(priv);
  2500. }
  2501. #define MAX_HW_RESTARTS 5
  2502. static int __iwl4965_up(struct iwl_priv *priv)
  2503. {
  2504. int i;
  2505. int ret;
  2506. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2507. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  2508. return -EIO;
  2509. }
  2510. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  2511. IWL_WARNING("Radio disabled by SW RF kill (module "
  2512. "parameter)\n");
  2513. iwl_rfkill_set_hw_state(priv);
  2514. return -ENODEV;
  2515. }
  2516. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2517. IWL_ERROR("ucode not available for device bringup\n");
  2518. return -EIO;
  2519. }
  2520. /* If platform's RF_KILL switch is NOT set to KILL */
  2521. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2522. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2523. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2524. else {
  2525. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2526. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2527. iwl_rfkill_set_hw_state(priv);
  2528. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  2529. return -ENODEV;
  2530. }
  2531. }
  2532. iwl_rfkill_set_hw_state(priv);
  2533. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2534. ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
  2535. if (ret) {
  2536. IWL_ERROR("Unable to allocate shared memory\n");
  2537. return ret;
  2538. }
  2539. ret = iwl_hw_nic_init(priv);
  2540. if (ret) {
  2541. IWL_ERROR("Unable to init nic\n");
  2542. return ret;
  2543. }
  2544. /* make sure rfkill handshake bits are cleared */
  2545. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2546. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2547. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2548. /* clear (again), then enable host interrupts */
  2549. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2550. iwl4965_enable_interrupts(priv);
  2551. /* really make sure rfkill handshake bits are cleared */
  2552. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2553. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2554. /* Copy original ucode data image from disk into backup cache.
  2555. * This will be used to initialize the on-board processor's
  2556. * data SRAM for a clean start when the runtime program first loads. */
  2557. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2558. priv->ucode_data.len);
  2559. /* We return success when we resume from suspend and rf_kill is on. */
  2560. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2561. return 0;
  2562. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2563. iwlcore_clear_stations_table(priv);
  2564. /* load bootstrap state machine,
  2565. * load bootstrap program into processor's memory,
  2566. * prepare to load the "initialize" uCode */
  2567. ret = priv->cfg->ops->lib->load_ucode(priv);
  2568. if (ret) {
  2569. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
  2570. continue;
  2571. }
  2572. /* start card; "initialize" will load runtime ucode */
  2573. iwl4965_nic_start(priv);
  2574. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  2575. return 0;
  2576. }
  2577. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2578. __iwl4965_down(priv);
  2579. /* tried to restart and config the device for as long as our
  2580. * patience could withstand */
  2581. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  2582. return -EIO;
  2583. }
  2584. /*****************************************************************************
  2585. *
  2586. * Workqueue callbacks
  2587. *
  2588. *****************************************************************************/
  2589. static void iwl_bg_init_alive_start(struct work_struct *data)
  2590. {
  2591. struct iwl_priv *priv =
  2592. container_of(data, struct iwl_priv, init_alive_start.work);
  2593. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2594. return;
  2595. mutex_lock(&priv->mutex);
  2596. priv->cfg->ops->lib->init_alive_start(priv);
  2597. mutex_unlock(&priv->mutex);
  2598. }
  2599. static void iwl_bg_alive_start(struct work_struct *data)
  2600. {
  2601. struct iwl_priv *priv =
  2602. container_of(data, struct iwl_priv, alive_start.work);
  2603. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2604. return;
  2605. mutex_lock(&priv->mutex);
  2606. iwl_alive_start(priv);
  2607. mutex_unlock(&priv->mutex);
  2608. }
  2609. static void iwl4965_bg_rf_kill(struct work_struct *work)
  2610. {
  2611. struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
  2612. wake_up_interruptible(&priv->wait_command_queue);
  2613. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2614. return;
  2615. mutex_lock(&priv->mutex);
  2616. if (!iwl_is_rfkill(priv)) {
  2617. IWL_DEBUG(IWL_DL_RF_KILL,
  2618. "HW and/or SW RF Kill no longer active, restarting "
  2619. "device\n");
  2620. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2621. queue_work(priv->workqueue, &priv->restart);
  2622. } else {
  2623. /* make sure mac80211 stop sending Tx frame */
  2624. if (priv->mac80211_registered)
  2625. ieee80211_stop_queues(priv->hw);
  2626. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  2627. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2628. "disabled by SW switch\n");
  2629. else
  2630. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  2631. "Kill switch must be turned off for "
  2632. "wireless networking to work.\n");
  2633. }
  2634. iwl_rfkill_set_hw_state(priv);
  2635. mutex_unlock(&priv->mutex);
  2636. }
  2637. static void iwl4965_bg_set_monitor(struct work_struct *work)
  2638. {
  2639. struct iwl_priv *priv = container_of(work,
  2640. struct iwl_priv, set_monitor);
  2641. IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
  2642. mutex_lock(&priv->mutex);
  2643. if (!iwl_is_ready(priv))
  2644. IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
  2645. else
  2646. if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0)
  2647. IWL_ERROR("iwl4965_set_mode() failed\n");
  2648. mutex_unlock(&priv->mutex);
  2649. }
  2650. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  2651. static void iwl4965_bg_scan_check(struct work_struct *data)
  2652. {
  2653. struct iwl_priv *priv =
  2654. container_of(data, struct iwl_priv, scan_check.work);
  2655. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2656. return;
  2657. mutex_lock(&priv->mutex);
  2658. if (test_bit(STATUS_SCANNING, &priv->status) ||
  2659. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2660. IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting "
  2661. "adapter (%dms)\n",
  2662. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  2663. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2664. iwl4965_send_scan_abort(priv);
  2665. }
  2666. mutex_unlock(&priv->mutex);
  2667. }
  2668. static void iwl4965_bg_request_scan(struct work_struct *data)
  2669. {
  2670. struct iwl_priv *priv =
  2671. container_of(data, struct iwl_priv, request_scan);
  2672. struct iwl_host_cmd cmd = {
  2673. .id = REPLY_SCAN_CMD,
  2674. .len = sizeof(struct iwl4965_scan_cmd),
  2675. .meta.flags = CMD_SIZE_HUGE,
  2676. };
  2677. struct iwl4965_scan_cmd *scan;
  2678. struct ieee80211_conf *conf = NULL;
  2679. u16 cmd_len;
  2680. enum ieee80211_band band;
  2681. u8 direct_mask;
  2682. int ret = 0;
  2683. conf = ieee80211_get_hw_conf(priv->hw);
  2684. mutex_lock(&priv->mutex);
  2685. if (!iwl_is_ready(priv)) {
  2686. IWL_WARNING("request scan called when driver not ready.\n");
  2687. goto done;
  2688. }
  2689. /* Make sure the scan wasn't cancelled before this queued work
  2690. * was given the chance to run... */
  2691. if (!test_bit(STATUS_SCANNING, &priv->status))
  2692. goto done;
  2693. /* This should never be called or scheduled if there is currently
  2694. * a scan active in the hardware. */
  2695. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2696. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  2697. "Ignoring second request.\n");
  2698. ret = -EIO;
  2699. goto done;
  2700. }
  2701. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2702. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  2703. goto done;
  2704. }
  2705. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2706. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  2707. goto done;
  2708. }
  2709. if (iwl_is_rfkill(priv)) {
  2710. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  2711. goto done;
  2712. }
  2713. if (!test_bit(STATUS_READY, &priv->status)) {
  2714. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  2715. goto done;
  2716. }
  2717. if (!priv->scan_bands) {
  2718. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  2719. goto done;
  2720. }
  2721. if (!priv->scan) {
  2722. priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
  2723. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2724. if (!priv->scan) {
  2725. ret = -ENOMEM;
  2726. goto done;
  2727. }
  2728. }
  2729. scan = priv->scan;
  2730. memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2731. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2732. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2733. if (iwl_is_associated(priv)) {
  2734. u16 interval = 0;
  2735. u32 extra;
  2736. u32 suspend_time = 100;
  2737. u32 scan_suspend_time = 100;
  2738. unsigned long flags;
  2739. IWL_DEBUG_INFO("Scanning while associated...\n");
  2740. spin_lock_irqsave(&priv->lock, flags);
  2741. interval = priv->beacon_int;
  2742. spin_unlock_irqrestore(&priv->lock, flags);
  2743. scan->suspend_time = 0;
  2744. scan->max_out_time = cpu_to_le32(200 * 1024);
  2745. if (!interval)
  2746. interval = suspend_time;
  2747. extra = (suspend_time / interval) << 22;
  2748. scan_suspend_time = (extra |
  2749. ((suspend_time % interval) * 1024));
  2750. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2751. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  2752. scan_suspend_time, interval);
  2753. }
  2754. /* We should add the ability for user to lock to PASSIVE ONLY */
  2755. if (priv->one_direct_scan) {
  2756. IWL_DEBUG_SCAN
  2757. ("Kicking off one direct scan for '%s'\n",
  2758. iwl4965_escape_essid(priv->direct_ssid,
  2759. priv->direct_ssid_len));
  2760. scan->direct_scan[0].id = WLAN_EID_SSID;
  2761. scan->direct_scan[0].len = priv->direct_ssid_len;
  2762. memcpy(scan->direct_scan[0].ssid,
  2763. priv->direct_ssid, priv->direct_ssid_len);
  2764. direct_mask = 1;
  2765. } else if (!iwl_is_associated(priv) && priv->essid_len) {
  2766. IWL_DEBUG_SCAN
  2767. ("Kicking off one direct scan for '%s' when not associated\n",
  2768. iwl4965_escape_essid(priv->essid, priv->essid_len));
  2769. scan->direct_scan[0].id = WLAN_EID_SSID;
  2770. scan->direct_scan[0].len = priv->essid_len;
  2771. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  2772. direct_mask = 1;
  2773. } else {
  2774. IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
  2775. direct_mask = 0;
  2776. }
  2777. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2778. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  2779. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2780. switch (priv->scan_bands) {
  2781. case 2:
  2782. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  2783. scan->tx_cmd.rate_n_flags =
  2784. iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
  2785. RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
  2786. scan->good_CRC_th = 0;
  2787. band = IEEE80211_BAND_2GHZ;
  2788. break;
  2789. case 1:
  2790. scan->tx_cmd.rate_n_flags =
  2791. iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
  2792. RATE_MCS_ANT_B_MSK);
  2793. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  2794. band = IEEE80211_BAND_5GHZ;
  2795. break;
  2796. default:
  2797. IWL_WARNING("Invalid scan band count\n");
  2798. goto done;
  2799. }
  2800. /* We don't build a direct scan probe request; the uCode will do
  2801. * that based on the direct_mask added to each channel entry */
  2802. cmd_len = iwl4965_fill_probe_req(priv, band,
  2803. (struct ieee80211_mgmt *)scan->data,
  2804. IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
  2805. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  2806. /* select Rx chains */
  2807. /* Force use of chains B and C (0x6) for scan Rx.
  2808. * Avoid A (0x1) because of its off-channel reception on A-band.
  2809. * MIMO is not used here, but value is required to make uCode happy. */
  2810. scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
  2811. cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
  2812. (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
  2813. (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
  2814. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  2815. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  2816. if (direct_mask)
  2817. scan->channel_count =
  2818. iwl4965_get_channels_for_scan(
  2819. priv, band, 1, /* active */
  2820. direct_mask,
  2821. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  2822. else
  2823. scan->channel_count =
  2824. iwl4965_get_channels_for_scan(
  2825. priv, band, 0, /* passive */
  2826. direct_mask,
  2827. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  2828. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  2829. RXON_FILTER_BCON_AWARE_MSK);
  2830. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  2831. scan->channel_count * sizeof(struct iwl4965_scan_channel);
  2832. cmd.data = scan;
  2833. scan->len = cpu_to_le16(cmd.len);
  2834. set_bit(STATUS_SCAN_HW, &priv->status);
  2835. ret = iwl_send_cmd_sync(priv, &cmd);
  2836. if (ret)
  2837. goto done;
  2838. queue_delayed_work(priv->workqueue, &priv->scan_check,
  2839. IWL_SCAN_CHECK_WATCHDOG);
  2840. mutex_unlock(&priv->mutex);
  2841. return;
  2842. done:
  2843. /* inform mac80211 scan aborted */
  2844. queue_work(priv->workqueue, &priv->scan_completed);
  2845. mutex_unlock(&priv->mutex);
  2846. }
  2847. static void iwl4965_bg_up(struct work_struct *data)
  2848. {
  2849. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  2850. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2851. return;
  2852. mutex_lock(&priv->mutex);
  2853. __iwl4965_up(priv);
  2854. mutex_unlock(&priv->mutex);
  2855. }
  2856. static void iwl4965_bg_restart(struct work_struct *data)
  2857. {
  2858. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2859. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2860. return;
  2861. iwl4965_down(priv);
  2862. queue_work(priv->workqueue, &priv->up);
  2863. }
  2864. static void iwl4965_bg_rx_replenish(struct work_struct *data)
  2865. {
  2866. struct iwl_priv *priv =
  2867. container_of(data, struct iwl_priv, rx_replenish);
  2868. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2869. return;
  2870. mutex_lock(&priv->mutex);
  2871. iwl_rx_replenish(priv);
  2872. mutex_unlock(&priv->mutex);
  2873. }
  2874. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  2875. static void iwl4965_post_associate(struct iwl_priv *priv)
  2876. {
  2877. struct ieee80211_conf *conf = NULL;
  2878. int ret = 0;
  2879. DECLARE_MAC_BUF(mac);
  2880. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  2881. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  2882. return;
  2883. }
  2884. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  2885. priv->assoc_id,
  2886. print_mac(mac, priv->active_rxon.bssid_addr));
  2887. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2888. return;
  2889. if (!priv->vif || !priv->is_open)
  2890. return;
  2891. iwl4965_scan_cancel_timeout(priv, 200);
  2892. conf = ieee80211_get_hw_conf(priv->hw);
  2893. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2894. iwl4965_commit_rxon(priv);
  2895. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  2896. iwl4965_setup_rxon_timing(priv);
  2897. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  2898. sizeof(priv->rxon_timing), &priv->rxon_timing);
  2899. if (ret)
  2900. IWL_WARNING("REPLY_RXON_TIMING failed - "
  2901. "Attempting to continue.\n");
  2902. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2903. #ifdef CONFIG_IWL4965_HT
  2904. if (priv->current_ht_config.is_ht)
  2905. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  2906. #endif /* CONFIG_IWL4965_HT*/
  2907. iwl_set_rxon_chain(priv);
  2908. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  2909. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  2910. priv->assoc_id, priv->beacon_int);
  2911. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2912. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2913. else
  2914. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2915. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2916. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2917. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2918. else
  2919. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2920. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2921. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2922. }
  2923. iwl4965_commit_rxon(priv);
  2924. switch (priv->iw_mode) {
  2925. case IEEE80211_IF_TYPE_STA:
  2926. iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
  2927. break;
  2928. case IEEE80211_IF_TYPE_IBSS:
  2929. /* clear out the station table */
  2930. iwlcore_clear_stations_table(priv);
  2931. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  2932. iwl_rxon_add_station(priv, priv->bssid, 0);
  2933. iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
  2934. iwl4965_send_beacon_cmd(priv);
  2935. break;
  2936. default:
  2937. IWL_ERROR("%s Should not be called in %d mode\n",
  2938. __FUNCTION__, priv->iw_mode);
  2939. break;
  2940. }
  2941. iwl4965_sequence_reset(priv);
  2942. /* Enable Rx differential gain and sensitivity calibrations */
  2943. iwl_chain_noise_reset(priv);
  2944. priv->start_calib = 1;
  2945. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2946. priv->assoc_station_added = 1;
  2947. iwl4965_activate_qos(priv, 0);
  2948. iwl_power_update_mode(priv, 0);
  2949. /* we have just associated, don't start scan too early */
  2950. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  2951. }
  2952. static void iwl4965_bg_post_associate(struct work_struct *data)
  2953. {
  2954. struct iwl_priv *priv = container_of(data, struct iwl_priv,
  2955. post_associate.work);
  2956. mutex_lock(&priv->mutex);
  2957. iwl4965_post_associate(priv);
  2958. mutex_unlock(&priv->mutex);
  2959. }
  2960. static void iwl4965_bg_abort_scan(struct work_struct *work)
  2961. {
  2962. struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
  2963. if (!iwl_is_ready(priv))
  2964. return;
  2965. mutex_lock(&priv->mutex);
  2966. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  2967. iwl4965_send_scan_abort(priv);
  2968. mutex_unlock(&priv->mutex);
  2969. }
  2970. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  2971. static void iwl4965_bg_scan_completed(struct work_struct *work)
  2972. {
  2973. struct iwl_priv *priv =
  2974. container_of(work, struct iwl_priv, scan_completed);
  2975. IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n");
  2976. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2977. return;
  2978. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  2979. iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  2980. ieee80211_scan_completed(priv->hw);
  2981. /* Since setting the TXPOWER may have been deferred while
  2982. * performing the scan, fire one off */
  2983. mutex_lock(&priv->mutex);
  2984. iwl4965_hw_reg_send_txpower(priv);
  2985. mutex_unlock(&priv->mutex);
  2986. }
  2987. /*****************************************************************************
  2988. *
  2989. * mac80211 entry point functions
  2990. *
  2991. *****************************************************************************/
  2992. #define UCODE_READY_TIMEOUT (2 * HZ)
  2993. static int iwl4965_mac_start(struct ieee80211_hw *hw)
  2994. {
  2995. struct iwl_priv *priv = hw->priv;
  2996. int ret;
  2997. IWL_DEBUG_MAC80211("enter\n");
  2998. if (pci_enable_device(priv->pci_dev)) {
  2999. IWL_ERROR("Fail to pci_enable_device\n");
  3000. return -ENODEV;
  3001. }
  3002. pci_restore_state(priv->pci_dev);
  3003. pci_enable_msi(priv->pci_dev);
  3004. ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
  3005. DRV_NAME, priv);
  3006. if (ret) {
  3007. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  3008. goto out_disable_msi;
  3009. }
  3010. /* we should be verifying the device is ready to be opened */
  3011. mutex_lock(&priv->mutex);
  3012. memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
  3013. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3014. * ucode filename and max sizes are card-specific. */
  3015. if (!priv->ucode_code.len) {
  3016. ret = iwl4965_read_ucode(priv);
  3017. if (ret) {
  3018. IWL_ERROR("Could not read microcode: %d\n", ret);
  3019. mutex_unlock(&priv->mutex);
  3020. goto out_release_irq;
  3021. }
  3022. }
  3023. ret = __iwl4965_up(priv);
  3024. mutex_unlock(&priv->mutex);
  3025. if (ret)
  3026. goto out_release_irq;
  3027. IWL_DEBUG_INFO("Start UP work done.\n");
  3028. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3029. return 0;
  3030. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  3031. * mac80211 will not be run successfully. */
  3032. if (priv->ucode_type == UCODE_RT) {
  3033. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3034. test_bit(STATUS_READY, &priv->status),
  3035. UCODE_READY_TIMEOUT);
  3036. if (!ret) {
  3037. if (!test_bit(STATUS_READY, &priv->status)) {
  3038. IWL_ERROR("START_ALIVE timeout after %dms.\n",
  3039. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3040. ret = -ETIMEDOUT;
  3041. goto out_release_irq;
  3042. }
  3043. }
  3044. priv->is_open = 1;
  3045. }
  3046. IWL_DEBUG_MAC80211("leave\n");
  3047. return 0;
  3048. out_release_irq:
  3049. free_irq(priv->pci_dev->irq, priv);
  3050. out_disable_msi:
  3051. pci_disable_msi(priv->pci_dev);
  3052. pci_disable_device(priv->pci_dev);
  3053. priv->is_open = 0;
  3054. IWL_DEBUG_MAC80211("leave - failed\n");
  3055. return ret;
  3056. }
  3057. static void iwl4965_mac_stop(struct ieee80211_hw *hw)
  3058. {
  3059. struct iwl_priv *priv = hw->priv;
  3060. IWL_DEBUG_MAC80211("enter\n");
  3061. if (!priv->is_open) {
  3062. IWL_DEBUG_MAC80211("leave - skip\n");
  3063. return;
  3064. }
  3065. priv->is_open = 0;
  3066. if (iwl_is_ready_rf(priv)) {
  3067. /* stop mac, cancel any scan request and clear
  3068. * RXON_FILTER_ASSOC_MSK BIT
  3069. */
  3070. mutex_lock(&priv->mutex);
  3071. iwl4965_scan_cancel_timeout(priv, 100);
  3072. cancel_delayed_work(&priv->post_associate);
  3073. mutex_unlock(&priv->mutex);
  3074. }
  3075. iwl4965_down(priv);
  3076. flush_workqueue(priv->workqueue);
  3077. free_irq(priv->pci_dev->irq, priv);
  3078. pci_disable_msi(priv->pci_dev);
  3079. pci_save_state(priv->pci_dev);
  3080. pci_disable_device(priv->pci_dev);
  3081. IWL_DEBUG_MAC80211("leave\n");
  3082. }
  3083. static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3084. {
  3085. struct iwl_priv *priv = hw->priv;
  3086. IWL_DEBUG_MAC80211("enter\n");
  3087. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  3088. IWL_DEBUG_MAC80211("leave - monitor\n");
  3089. return -1;
  3090. }
  3091. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3092. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3093. if (iwl_tx_skb(priv, skb))
  3094. dev_kfree_skb_any(skb);
  3095. IWL_DEBUG_MAC80211("leave\n");
  3096. return 0;
  3097. }
  3098. static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
  3099. struct ieee80211_if_init_conf *conf)
  3100. {
  3101. struct iwl_priv *priv = hw->priv;
  3102. unsigned long flags;
  3103. DECLARE_MAC_BUF(mac);
  3104. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  3105. if (priv->vif) {
  3106. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  3107. return -EOPNOTSUPP;
  3108. }
  3109. spin_lock_irqsave(&priv->lock, flags);
  3110. priv->vif = conf->vif;
  3111. spin_unlock_irqrestore(&priv->lock, flags);
  3112. mutex_lock(&priv->mutex);
  3113. if (conf->mac_addr) {
  3114. IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
  3115. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3116. }
  3117. if (iwl_is_ready(priv))
  3118. iwl4965_set_mode(priv, conf->type);
  3119. mutex_unlock(&priv->mutex);
  3120. IWL_DEBUG_MAC80211("leave\n");
  3121. return 0;
  3122. }
  3123. /**
  3124. * iwl4965_mac_config - mac80211 config callback
  3125. *
  3126. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3127. * be set inappropriately and the driver currently sets the hardware up to
  3128. * use it whenever needed.
  3129. */
  3130. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  3131. {
  3132. struct iwl_priv *priv = hw->priv;
  3133. const struct iwl_channel_info *ch_info;
  3134. unsigned long flags;
  3135. int ret = 0;
  3136. mutex_lock(&priv->mutex);
  3137. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  3138. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  3139. if (!iwl_is_ready(priv)) {
  3140. IWL_DEBUG_MAC80211("leave - not ready\n");
  3141. ret = -EIO;
  3142. goto out;
  3143. }
  3144. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  3145. test_bit(STATUS_SCANNING, &priv->status))) {
  3146. IWL_DEBUG_MAC80211("leave - scanning\n");
  3147. set_bit(STATUS_CONF_PENDING, &priv->status);
  3148. mutex_unlock(&priv->mutex);
  3149. return 0;
  3150. }
  3151. spin_lock_irqsave(&priv->lock, flags);
  3152. ch_info = iwl_get_channel_info(priv, conf->channel->band,
  3153. ieee80211_frequency_to_channel(conf->channel->center_freq));
  3154. if (!is_channel_valid(ch_info)) {
  3155. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  3156. spin_unlock_irqrestore(&priv->lock, flags);
  3157. ret = -EINVAL;
  3158. goto out;
  3159. }
  3160. #ifdef CONFIG_IWL4965_HT
  3161. /* if we are switching from ht to 2.4 clear flags
  3162. * from any ht related info since 2.4 does not
  3163. * support ht */
  3164. if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
  3165. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3166. && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
  3167. #endif
  3168. )
  3169. priv->staging_rxon.flags = 0;
  3170. #endif /* CONFIG_IWL4965_HT */
  3171. iwl_set_rxon_channel(priv, conf->channel->band,
  3172. ieee80211_frequency_to_channel(conf->channel->center_freq));
  3173. iwl4965_set_flags_for_phymode(priv, conf->channel->band);
  3174. /* The list of supported rates and rate mask can be different
  3175. * for each band; since the band may have changed, reset
  3176. * the rate mask to what mac80211 lists */
  3177. iwl4965_set_rate(priv);
  3178. spin_unlock_irqrestore(&priv->lock, flags);
  3179. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3180. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3181. iwl4965_hw_channel_switch(priv, conf->channel);
  3182. goto out;
  3183. }
  3184. #endif
  3185. if (priv->cfg->ops->lib->radio_kill_sw)
  3186. priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
  3187. if (!conf->radio_enabled) {
  3188. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  3189. goto out;
  3190. }
  3191. if (iwl_is_rfkill(priv)) {
  3192. IWL_DEBUG_MAC80211("leave - RF kill\n");
  3193. ret = -EIO;
  3194. goto out;
  3195. }
  3196. iwl4965_set_rate(priv);
  3197. if (memcmp(&priv->active_rxon,
  3198. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  3199. iwl4965_commit_rxon(priv);
  3200. else
  3201. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  3202. IWL_DEBUG_MAC80211("leave\n");
  3203. out:
  3204. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3205. mutex_unlock(&priv->mutex);
  3206. return ret;
  3207. }
  3208. static void iwl4965_config_ap(struct iwl_priv *priv)
  3209. {
  3210. int ret = 0;
  3211. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3212. return;
  3213. /* The following should be done only at AP bring up */
  3214. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  3215. /* RXON - unassoc (to set timing command) */
  3216. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3217. iwl4965_commit_rxon(priv);
  3218. /* RXON Timing */
  3219. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  3220. iwl4965_setup_rxon_timing(priv);
  3221. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3222. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3223. if (ret)
  3224. IWL_WARNING("REPLY_RXON_TIMING failed - "
  3225. "Attempting to continue.\n");
  3226. iwl_set_rxon_chain(priv);
  3227. /* FIXME: what should be the assoc_id for AP? */
  3228. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3229. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3230. priv->staging_rxon.flags |=
  3231. RXON_FLG_SHORT_PREAMBLE_MSK;
  3232. else
  3233. priv->staging_rxon.flags &=
  3234. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3235. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3236. if (priv->assoc_capability &
  3237. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3238. priv->staging_rxon.flags |=
  3239. RXON_FLG_SHORT_SLOT_MSK;
  3240. else
  3241. priv->staging_rxon.flags &=
  3242. ~RXON_FLG_SHORT_SLOT_MSK;
  3243. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  3244. priv->staging_rxon.flags &=
  3245. ~RXON_FLG_SHORT_SLOT_MSK;
  3246. }
  3247. /* restore RXON assoc */
  3248. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3249. iwl4965_commit_rxon(priv);
  3250. iwl4965_activate_qos(priv, 1);
  3251. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  3252. }
  3253. iwl4965_send_beacon_cmd(priv);
  3254. /* FIXME - we need to add code here to detect a totally new
  3255. * configuration, reset the AP, unassoc, rxon timing, assoc,
  3256. * clear sta table, add BCAST sta... */
  3257. }
  3258. static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
  3259. struct ieee80211_vif *vif,
  3260. struct ieee80211_if_conf *conf)
  3261. {
  3262. struct iwl_priv *priv = hw->priv;
  3263. DECLARE_MAC_BUF(mac);
  3264. unsigned long flags;
  3265. int rc;
  3266. if (conf == NULL)
  3267. return -EIO;
  3268. if (priv->vif != vif) {
  3269. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  3270. return 0;
  3271. }
  3272. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  3273. (!conf->beacon || !conf->ssid_len)) {
  3274. IWL_DEBUG_MAC80211
  3275. ("Leaving in AP mode because HostAPD is not ready.\n");
  3276. return 0;
  3277. }
  3278. if (!iwl_is_alive(priv))
  3279. return -EAGAIN;
  3280. mutex_lock(&priv->mutex);
  3281. if (conf->bssid)
  3282. IWL_DEBUG_MAC80211("bssid: %s\n",
  3283. print_mac(mac, conf->bssid));
  3284. /*
  3285. * very dubious code was here; the probe filtering flag is never set:
  3286. *
  3287. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  3288. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  3289. */
  3290. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  3291. if (!conf->bssid) {
  3292. conf->bssid = priv->mac_addr;
  3293. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  3294. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  3295. print_mac(mac, conf->bssid));
  3296. }
  3297. if (priv->ibss_beacon)
  3298. dev_kfree_skb(priv->ibss_beacon);
  3299. priv->ibss_beacon = conf->beacon;
  3300. }
  3301. if (iwl_is_rfkill(priv))
  3302. goto done;
  3303. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  3304. !is_multicast_ether_addr(conf->bssid)) {
  3305. /* If there is currently a HW scan going on in the background
  3306. * then we need to cancel it else the RXON below will fail. */
  3307. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  3308. IWL_WARNING("Aborted scan still in progress "
  3309. "after 100ms\n");
  3310. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  3311. mutex_unlock(&priv->mutex);
  3312. return -EAGAIN;
  3313. }
  3314. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  3315. /* TODO: Audit driver for usage of these members and see
  3316. * if mac80211 deprecates them (priv->bssid looks like it
  3317. * shouldn't be there, but I haven't scanned the IBSS code
  3318. * to verify) - jpk */
  3319. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  3320. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3321. iwl4965_config_ap(priv);
  3322. else {
  3323. rc = iwl4965_commit_rxon(priv);
  3324. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  3325. iwl_rxon_add_station(
  3326. priv, priv->active_rxon.bssid_addr, 1);
  3327. }
  3328. } else {
  3329. iwl4965_scan_cancel_timeout(priv, 100);
  3330. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3331. iwl4965_commit_rxon(priv);
  3332. }
  3333. done:
  3334. spin_lock_irqsave(&priv->lock, flags);
  3335. if (!conf->ssid_len)
  3336. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3337. else
  3338. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  3339. priv->essid_len = conf->ssid_len;
  3340. spin_unlock_irqrestore(&priv->lock, flags);
  3341. IWL_DEBUG_MAC80211("leave\n");
  3342. mutex_unlock(&priv->mutex);
  3343. return 0;
  3344. }
  3345. static void iwl4965_configure_filter(struct ieee80211_hw *hw,
  3346. unsigned int changed_flags,
  3347. unsigned int *total_flags,
  3348. int mc_count, struct dev_addr_list *mc_list)
  3349. {
  3350. /*
  3351. * XXX: dummy
  3352. * see also iwl4965_connection_init_rx_config
  3353. */
  3354. struct iwl_priv *priv = hw->priv;
  3355. int new_flags = 0;
  3356. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3357. if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3358. IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
  3359. IEEE80211_IF_TYPE_MNTR,
  3360. changed_flags, *total_flags);
  3361. /* queue work 'cuz mac80211 is holding a lock which
  3362. * prevents us from issuing (synchronous) f/w cmds */
  3363. queue_work(priv->workqueue, &priv->set_monitor);
  3364. new_flags &= FIF_PROMISC_IN_BSS |
  3365. FIF_OTHER_BSS |
  3366. FIF_ALLMULTI;
  3367. }
  3368. }
  3369. *total_flags = new_flags;
  3370. }
  3371. static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
  3372. struct ieee80211_if_init_conf *conf)
  3373. {
  3374. struct iwl_priv *priv = hw->priv;
  3375. IWL_DEBUG_MAC80211("enter\n");
  3376. mutex_lock(&priv->mutex);
  3377. if (iwl_is_ready_rf(priv)) {
  3378. iwl4965_scan_cancel_timeout(priv, 100);
  3379. cancel_delayed_work(&priv->post_associate);
  3380. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3381. iwl4965_commit_rxon(priv);
  3382. }
  3383. if (priv->vif == conf->vif) {
  3384. priv->vif = NULL;
  3385. memset(priv->bssid, 0, ETH_ALEN);
  3386. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3387. priv->essid_len = 0;
  3388. }
  3389. mutex_unlock(&priv->mutex);
  3390. IWL_DEBUG_MAC80211("leave\n");
  3391. }
  3392. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  3393. static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
  3394. struct ieee80211_vif *vif,
  3395. struct ieee80211_bss_conf *bss_conf,
  3396. u32 changes)
  3397. {
  3398. struct iwl_priv *priv = hw->priv;
  3399. IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
  3400. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  3401. IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
  3402. bss_conf->use_short_preamble);
  3403. if (bss_conf->use_short_preamble)
  3404. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3405. else
  3406. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3407. }
  3408. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  3409. IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
  3410. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  3411. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  3412. else
  3413. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  3414. }
  3415. if (changes & BSS_CHANGED_HT) {
  3416. IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
  3417. iwl4965_ht_conf(priv, bss_conf);
  3418. iwl_set_rxon_chain(priv);
  3419. }
  3420. if (changes & BSS_CHANGED_ASSOC) {
  3421. IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
  3422. /* This should never happen as this function should
  3423. * never be called from interrupt context. */
  3424. if (WARN_ON_ONCE(in_interrupt()))
  3425. return;
  3426. if (bss_conf->assoc) {
  3427. priv->assoc_id = bss_conf->aid;
  3428. priv->beacon_int = bss_conf->beacon_int;
  3429. priv->timestamp = bss_conf->timestamp;
  3430. priv->assoc_capability = bss_conf->assoc_capability;
  3431. priv->next_scan_jiffies = jiffies +
  3432. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  3433. mutex_lock(&priv->mutex);
  3434. iwl4965_post_associate(priv);
  3435. mutex_unlock(&priv->mutex);
  3436. } else {
  3437. priv->assoc_id = 0;
  3438. IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
  3439. }
  3440. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  3441. IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
  3442. iwl_send_rxon_assoc(priv);
  3443. }
  3444. }
  3445. static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  3446. {
  3447. int rc = 0;
  3448. unsigned long flags;
  3449. struct iwl_priv *priv = hw->priv;
  3450. IWL_DEBUG_MAC80211("enter\n");
  3451. mutex_lock(&priv->mutex);
  3452. spin_lock_irqsave(&priv->lock, flags);
  3453. if (!iwl_is_ready_rf(priv)) {
  3454. rc = -EIO;
  3455. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  3456. goto out_unlock;
  3457. }
  3458. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  3459. rc = -EIO;
  3460. IWL_ERROR("ERROR: APs don't scan\n");
  3461. goto out_unlock;
  3462. }
  3463. /* we don't schedule scan within next_scan_jiffies period */
  3464. if (priv->next_scan_jiffies &&
  3465. time_after(priv->next_scan_jiffies, jiffies)) {
  3466. rc = -EAGAIN;
  3467. goto out_unlock;
  3468. }
  3469. /* if we just finished scan ask for delay */
  3470. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  3471. IWL_DELAY_NEXT_SCAN, jiffies)) {
  3472. rc = -EAGAIN;
  3473. goto out_unlock;
  3474. }
  3475. if (len) {
  3476. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  3477. iwl4965_escape_essid(ssid, len), (int)len);
  3478. priv->one_direct_scan = 1;
  3479. priv->direct_ssid_len = (u8)
  3480. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  3481. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  3482. } else
  3483. priv->one_direct_scan = 0;
  3484. rc = iwl4965_scan_initiate(priv);
  3485. IWL_DEBUG_MAC80211("leave\n");
  3486. out_unlock:
  3487. spin_unlock_irqrestore(&priv->lock, flags);
  3488. mutex_unlock(&priv->mutex);
  3489. return rc;
  3490. }
  3491. static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  3492. struct ieee80211_key_conf *keyconf, const u8 *addr,
  3493. u32 iv32, u16 *phase1key)
  3494. {
  3495. struct iwl_priv *priv = hw->priv;
  3496. u8 sta_id = IWL_INVALID_STATION;
  3497. unsigned long flags;
  3498. __le16 key_flags = 0;
  3499. int i;
  3500. DECLARE_MAC_BUF(mac);
  3501. IWL_DEBUG_MAC80211("enter\n");
  3502. sta_id = iwl_find_station(priv, addr);
  3503. if (sta_id == IWL_INVALID_STATION) {
  3504. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3505. print_mac(mac, addr));
  3506. return;
  3507. }
  3508. iwl4965_scan_cancel_timeout(priv, 100);
  3509. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  3510. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  3511. key_flags &= ~STA_KEY_FLG_INVALID;
  3512. if (sta_id == priv->hw_params.bcast_sta_id)
  3513. key_flags |= STA_KEY_MULTICAST_MSK;
  3514. spin_lock_irqsave(&priv->sta_lock, flags);
  3515. priv->stations[sta_id].sta.key.key_flags = key_flags;
  3516. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  3517. for (i = 0; i < 5; i++)
  3518. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  3519. cpu_to_le16(phase1key[i]);
  3520. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  3521. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3522. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3523. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3524. IWL_DEBUG_MAC80211("leave\n");
  3525. }
  3526. static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3527. const u8 *local_addr, const u8 *addr,
  3528. struct ieee80211_key_conf *key)
  3529. {
  3530. struct iwl_priv *priv = hw->priv;
  3531. DECLARE_MAC_BUF(mac);
  3532. int ret = 0;
  3533. u8 sta_id = IWL_INVALID_STATION;
  3534. u8 is_default_wep_key = 0;
  3535. IWL_DEBUG_MAC80211("enter\n");
  3536. if (priv->hw_params.sw_crypto) {
  3537. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  3538. return -EOPNOTSUPP;
  3539. }
  3540. if (is_zero_ether_addr(addr))
  3541. /* only support pairwise keys */
  3542. return -EOPNOTSUPP;
  3543. sta_id = iwl_find_station(priv, addr);
  3544. if (sta_id == IWL_INVALID_STATION) {
  3545. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3546. print_mac(mac, addr));
  3547. return -EINVAL;
  3548. }
  3549. mutex_lock(&priv->mutex);
  3550. iwl4965_scan_cancel_timeout(priv, 100);
  3551. mutex_unlock(&priv->mutex);
  3552. /* If we are getting WEP group key and we didn't receive any key mapping
  3553. * so far, we are in legacy wep mode (group key only), otherwise we are
  3554. * in 1X mode.
  3555. * In legacy wep mode, we use another host command to the uCode */
  3556. if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
  3557. priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3558. if (cmd == SET_KEY)
  3559. is_default_wep_key = !priv->key_mapping_key;
  3560. else
  3561. is_default_wep_key =
  3562. (key->hw_key_idx == HW_KEY_DEFAULT);
  3563. }
  3564. switch (cmd) {
  3565. case SET_KEY:
  3566. if (is_default_wep_key)
  3567. ret = iwl_set_default_wep_key(priv, key);
  3568. else
  3569. ret = iwl_set_dynamic_key(priv, key, sta_id);
  3570. IWL_DEBUG_MAC80211("enable hwcrypto key\n");
  3571. break;
  3572. case DISABLE_KEY:
  3573. if (is_default_wep_key)
  3574. ret = iwl_remove_default_wep_key(priv, key);
  3575. else
  3576. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  3577. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  3578. break;
  3579. default:
  3580. ret = -EINVAL;
  3581. }
  3582. IWL_DEBUG_MAC80211("leave\n");
  3583. return ret;
  3584. }
  3585. static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3586. const struct ieee80211_tx_queue_params *params)
  3587. {
  3588. struct iwl_priv *priv = hw->priv;
  3589. unsigned long flags;
  3590. int q;
  3591. IWL_DEBUG_MAC80211("enter\n");
  3592. if (!iwl_is_ready_rf(priv)) {
  3593. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3594. return -EIO;
  3595. }
  3596. if (queue >= AC_NUM) {
  3597. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  3598. return 0;
  3599. }
  3600. if (!priv->qos_data.qos_enable) {
  3601. priv->qos_data.qos_active = 0;
  3602. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  3603. return 0;
  3604. }
  3605. q = AC_NUM - 1 - queue;
  3606. spin_lock_irqsave(&priv->lock, flags);
  3607. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  3608. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  3609. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  3610. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  3611. cpu_to_le16((params->txop * 32));
  3612. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  3613. priv->qos_data.qos_active = 1;
  3614. spin_unlock_irqrestore(&priv->lock, flags);
  3615. mutex_lock(&priv->mutex);
  3616. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3617. iwl4965_activate_qos(priv, 1);
  3618. else if (priv->assoc_id && iwl_is_associated(priv))
  3619. iwl4965_activate_qos(priv, 0);
  3620. mutex_unlock(&priv->mutex);
  3621. IWL_DEBUG_MAC80211("leave\n");
  3622. return 0;
  3623. }
  3624. static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
  3625. struct ieee80211_tx_queue_stats *stats)
  3626. {
  3627. struct iwl_priv *priv = hw->priv;
  3628. int i, avail;
  3629. struct iwl_tx_queue *txq;
  3630. struct iwl_queue *q;
  3631. unsigned long flags;
  3632. IWL_DEBUG_MAC80211("enter\n");
  3633. if (!iwl_is_ready_rf(priv)) {
  3634. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3635. return -EIO;
  3636. }
  3637. spin_lock_irqsave(&priv->lock, flags);
  3638. for (i = 0; i < AC_NUM; i++) {
  3639. txq = &priv->txq[i];
  3640. q = &txq->q;
  3641. avail = iwl_queue_space(q);
  3642. stats[i].len = q->n_window - avail;
  3643. stats[i].limit = q->n_window - q->high_mark;
  3644. stats[i].count = q->n_window;
  3645. }
  3646. spin_unlock_irqrestore(&priv->lock, flags);
  3647. IWL_DEBUG_MAC80211("leave\n");
  3648. return 0;
  3649. }
  3650. static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
  3651. struct ieee80211_low_level_stats *stats)
  3652. {
  3653. struct iwl_priv *priv = hw->priv;
  3654. priv = hw->priv;
  3655. IWL_DEBUG_MAC80211("enter\n");
  3656. IWL_DEBUG_MAC80211("leave\n");
  3657. return 0;
  3658. }
  3659. static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
  3660. {
  3661. struct iwl_priv *priv;
  3662. priv = hw->priv;
  3663. IWL_DEBUG_MAC80211("enter\n");
  3664. IWL_DEBUG_MAC80211("leave\n");
  3665. return 0;
  3666. }
  3667. static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
  3668. {
  3669. struct iwl_priv *priv = hw->priv;
  3670. unsigned long flags;
  3671. mutex_lock(&priv->mutex);
  3672. IWL_DEBUG_MAC80211("enter\n");
  3673. priv->lq_mngr.lq_ready = 0;
  3674. #ifdef CONFIG_IWL4965_HT
  3675. spin_lock_irqsave(&priv->lock, flags);
  3676. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  3677. spin_unlock_irqrestore(&priv->lock, flags);
  3678. #endif /* CONFIG_IWL4965_HT */
  3679. iwl_reset_qos(priv);
  3680. cancel_delayed_work(&priv->post_associate);
  3681. spin_lock_irqsave(&priv->lock, flags);
  3682. priv->assoc_id = 0;
  3683. priv->assoc_capability = 0;
  3684. priv->assoc_station_added = 0;
  3685. /* new association get rid of ibss beacon skb */
  3686. if (priv->ibss_beacon)
  3687. dev_kfree_skb(priv->ibss_beacon);
  3688. priv->ibss_beacon = NULL;
  3689. priv->beacon_int = priv->hw->conf.beacon_int;
  3690. priv->timestamp = 0;
  3691. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  3692. priv->beacon_int = 0;
  3693. spin_unlock_irqrestore(&priv->lock, flags);
  3694. if (!iwl_is_ready_rf(priv)) {
  3695. IWL_DEBUG_MAC80211("leave - not ready\n");
  3696. mutex_unlock(&priv->mutex);
  3697. return;
  3698. }
  3699. /* we are restarting association process
  3700. * clear RXON_FILTER_ASSOC_MSK bit
  3701. */
  3702. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3703. iwl4965_scan_cancel_timeout(priv, 100);
  3704. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3705. iwl4965_commit_rxon(priv);
  3706. }
  3707. iwl_power_update_mode(priv, 0);
  3708. /* Per mac80211.h: This is only used in IBSS mode... */
  3709. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3710. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  3711. mutex_unlock(&priv->mutex);
  3712. return;
  3713. }
  3714. iwl4965_set_rate(priv);
  3715. mutex_unlock(&priv->mutex);
  3716. IWL_DEBUG_MAC80211("leave\n");
  3717. }
  3718. static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  3719. {
  3720. struct iwl_priv *priv = hw->priv;
  3721. unsigned long flags;
  3722. mutex_lock(&priv->mutex);
  3723. IWL_DEBUG_MAC80211("enter\n");
  3724. if (!iwl_is_ready_rf(priv)) {
  3725. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3726. mutex_unlock(&priv->mutex);
  3727. return -EIO;
  3728. }
  3729. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3730. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  3731. mutex_unlock(&priv->mutex);
  3732. return -EIO;
  3733. }
  3734. spin_lock_irqsave(&priv->lock, flags);
  3735. if (priv->ibss_beacon)
  3736. dev_kfree_skb(priv->ibss_beacon);
  3737. priv->ibss_beacon = skb;
  3738. priv->assoc_id = 0;
  3739. IWL_DEBUG_MAC80211("leave\n");
  3740. spin_unlock_irqrestore(&priv->lock, flags);
  3741. iwl_reset_qos(priv);
  3742. queue_work(priv->workqueue, &priv->post_associate.work);
  3743. mutex_unlock(&priv->mutex);
  3744. return 0;
  3745. }
  3746. /*****************************************************************************
  3747. *
  3748. * sysfs attributes
  3749. *
  3750. *****************************************************************************/
  3751. #ifdef CONFIG_IWLWIFI_DEBUG
  3752. /*
  3753. * The following adds a new attribute to the sysfs representation
  3754. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  3755. * used for controlling the debug level.
  3756. *
  3757. * See the level definitions in iwl for details.
  3758. */
  3759. static ssize_t show_debug_level(struct device *d,
  3760. struct device_attribute *attr, char *buf)
  3761. {
  3762. struct iwl_priv *priv = d->driver_data;
  3763. return sprintf(buf, "0x%08X\n", priv->debug_level);
  3764. }
  3765. static ssize_t store_debug_level(struct device *d,
  3766. struct device_attribute *attr,
  3767. const char *buf, size_t count)
  3768. {
  3769. struct iwl_priv *priv = d->driver_data;
  3770. char *p = (char *)buf;
  3771. u32 val;
  3772. val = simple_strtoul(p, &p, 0);
  3773. if (p == buf)
  3774. printk(KERN_INFO DRV_NAME
  3775. ": %s is not in hex or decimal form.\n", buf);
  3776. else
  3777. priv->debug_level = val;
  3778. return strnlen(buf, count);
  3779. }
  3780. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3781. show_debug_level, store_debug_level);
  3782. #endif /* CONFIG_IWLWIFI_DEBUG */
  3783. static ssize_t show_version(struct device *d,
  3784. struct device_attribute *attr, char *buf)
  3785. {
  3786. struct iwl_priv *priv = d->driver_data;
  3787. struct iwl_alive_resp *palive = &priv->card_alive;
  3788. if (palive->is_valid)
  3789. return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
  3790. "fw type: 0x%01X 0x%01X\n",
  3791. palive->ucode_major, palive->ucode_minor,
  3792. palive->sw_rev[0], palive->sw_rev[1],
  3793. palive->ver_type, palive->ver_subtype);
  3794. else
  3795. return sprintf(buf, "fw not loaded\n");
  3796. }
  3797. static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
  3798. static ssize_t show_temperature(struct device *d,
  3799. struct device_attribute *attr, char *buf)
  3800. {
  3801. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3802. if (!iwl_is_alive(priv))
  3803. return -EAGAIN;
  3804. return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
  3805. }
  3806. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  3807. static ssize_t show_rs_window(struct device *d,
  3808. struct device_attribute *attr,
  3809. char *buf)
  3810. {
  3811. struct iwl_priv *priv = d->driver_data;
  3812. return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  3813. }
  3814. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  3815. static ssize_t show_tx_power(struct device *d,
  3816. struct device_attribute *attr, char *buf)
  3817. {
  3818. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3819. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  3820. }
  3821. static ssize_t store_tx_power(struct device *d,
  3822. struct device_attribute *attr,
  3823. const char *buf, size_t count)
  3824. {
  3825. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3826. char *p = (char *)buf;
  3827. u32 val;
  3828. val = simple_strtoul(p, &p, 10);
  3829. if (p == buf)
  3830. printk(KERN_INFO DRV_NAME
  3831. ": %s is not in decimal form.\n", buf);
  3832. else
  3833. iwl4965_hw_reg_set_txpower(priv, val);
  3834. return count;
  3835. }
  3836. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  3837. static ssize_t show_flags(struct device *d,
  3838. struct device_attribute *attr, char *buf)
  3839. {
  3840. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3841. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  3842. }
  3843. static ssize_t store_flags(struct device *d,
  3844. struct device_attribute *attr,
  3845. const char *buf, size_t count)
  3846. {
  3847. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3848. u32 flags = simple_strtoul(buf, NULL, 0);
  3849. mutex_lock(&priv->mutex);
  3850. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  3851. /* Cancel any currently running scans... */
  3852. if (iwl4965_scan_cancel_timeout(priv, 100))
  3853. IWL_WARNING("Could not cancel scan.\n");
  3854. else {
  3855. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  3856. flags);
  3857. priv->staging_rxon.flags = cpu_to_le32(flags);
  3858. iwl4965_commit_rxon(priv);
  3859. }
  3860. }
  3861. mutex_unlock(&priv->mutex);
  3862. return count;
  3863. }
  3864. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  3865. static ssize_t show_filter_flags(struct device *d,
  3866. struct device_attribute *attr, char *buf)
  3867. {
  3868. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3869. return sprintf(buf, "0x%04X\n",
  3870. le32_to_cpu(priv->active_rxon.filter_flags));
  3871. }
  3872. static ssize_t store_filter_flags(struct device *d,
  3873. struct device_attribute *attr,
  3874. const char *buf, size_t count)
  3875. {
  3876. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3877. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3878. mutex_lock(&priv->mutex);
  3879. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  3880. /* Cancel any currently running scans... */
  3881. if (iwl4965_scan_cancel_timeout(priv, 100))
  3882. IWL_WARNING("Could not cancel scan.\n");
  3883. else {
  3884. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  3885. "0x%04X\n", filter_flags);
  3886. priv->staging_rxon.filter_flags =
  3887. cpu_to_le32(filter_flags);
  3888. iwl4965_commit_rxon(priv);
  3889. }
  3890. }
  3891. mutex_unlock(&priv->mutex);
  3892. return count;
  3893. }
  3894. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3895. store_filter_flags);
  3896. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  3897. static ssize_t show_measurement(struct device *d,
  3898. struct device_attribute *attr, char *buf)
  3899. {
  3900. struct iwl_priv *priv = dev_get_drvdata(d);
  3901. struct iwl4965_spectrum_notification measure_report;
  3902. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3903. u8 *data = (u8 *) & measure_report;
  3904. unsigned long flags;
  3905. spin_lock_irqsave(&priv->lock, flags);
  3906. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3907. spin_unlock_irqrestore(&priv->lock, flags);
  3908. return 0;
  3909. }
  3910. memcpy(&measure_report, &priv->measure_report, size);
  3911. priv->measurement_status = 0;
  3912. spin_unlock_irqrestore(&priv->lock, flags);
  3913. while (size && (PAGE_SIZE - len)) {
  3914. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3915. PAGE_SIZE - len, 1);
  3916. len = strlen(buf);
  3917. if (PAGE_SIZE - len)
  3918. buf[len++] = '\n';
  3919. ofs += 16;
  3920. size -= min(size, 16U);
  3921. }
  3922. return len;
  3923. }
  3924. static ssize_t store_measurement(struct device *d,
  3925. struct device_attribute *attr,
  3926. const char *buf, size_t count)
  3927. {
  3928. struct iwl_priv *priv = dev_get_drvdata(d);
  3929. struct ieee80211_measurement_params params = {
  3930. .channel = le16_to_cpu(priv->active_rxon.channel),
  3931. .start_time = cpu_to_le64(priv->last_tsf),
  3932. .duration = cpu_to_le16(1),
  3933. };
  3934. u8 type = IWL_MEASURE_BASIC;
  3935. u8 buffer[32];
  3936. u8 channel;
  3937. if (count) {
  3938. char *p = buffer;
  3939. strncpy(buffer, buf, min(sizeof(buffer), count));
  3940. channel = simple_strtoul(p, NULL, 0);
  3941. if (channel)
  3942. params.channel = channel;
  3943. p = buffer;
  3944. while (*p && *p != ' ')
  3945. p++;
  3946. if (*p)
  3947. type = simple_strtoul(p + 1, NULL, 0);
  3948. }
  3949. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  3950. "channel %d (for '%s')\n", type, params.channel, buf);
  3951. iwl4965_get_measurement(priv, &params, type);
  3952. return count;
  3953. }
  3954. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3955. show_measurement, store_measurement);
  3956. #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
  3957. static ssize_t store_retry_rate(struct device *d,
  3958. struct device_attribute *attr,
  3959. const char *buf, size_t count)
  3960. {
  3961. struct iwl_priv *priv = dev_get_drvdata(d);
  3962. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3963. if (priv->retry_rate <= 0)
  3964. priv->retry_rate = 1;
  3965. return count;
  3966. }
  3967. static ssize_t show_retry_rate(struct device *d,
  3968. struct device_attribute *attr, char *buf)
  3969. {
  3970. struct iwl_priv *priv = dev_get_drvdata(d);
  3971. return sprintf(buf, "%d", priv->retry_rate);
  3972. }
  3973. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3974. store_retry_rate);
  3975. static ssize_t store_power_level(struct device *d,
  3976. struct device_attribute *attr,
  3977. const char *buf, size_t count)
  3978. {
  3979. struct iwl_priv *priv = dev_get_drvdata(d);
  3980. int rc;
  3981. int mode;
  3982. mode = simple_strtoul(buf, NULL, 0);
  3983. mutex_lock(&priv->mutex);
  3984. if (!iwl_is_ready(priv)) {
  3985. rc = -EAGAIN;
  3986. goto out;
  3987. }
  3988. rc = iwl_power_set_user_mode(priv, mode);
  3989. if (rc) {
  3990. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  3991. goto out;
  3992. }
  3993. rc = count;
  3994. out:
  3995. mutex_unlock(&priv->mutex);
  3996. return rc;
  3997. }
  3998. #define MAX_WX_STRING 80
  3999. /* Values are in microsecond */
  4000. static const s32 timeout_duration[] = {
  4001. 350000,
  4002. 250000,
  4003. 75000,
  4004. 37000,
  4005. 25000,
  4006. };
  4007. static const s32 period_duration[] = {
  4008. 400000,
  4009. 700000,
  4010. 1000000,
  4011. 1000000,
  4012. 1000000
  4013. };
  4014. static ssize_t show_power_level(struct device *d,
  4015. struct device_attribute *attr, char *buf)
  4016. {
  4017. struct iwl_priv *priv = dev_get_drvdata(d);
  4018. int level = priv->power_data.power_mode;
  4019. char *p = buf;
  4020. p += sprintf(p, "%d ", level);
  4021. switch (level) {
  4022. case IWL_POWER_MODE_CAM:
  4023. case IWL_POWER_AC:
  4024. p += sprintf(p, "(AC)");
  4025. break;
  4026. case IWL_POWER_BATTERY:
  4027. p += sprintf(p, "(BATTERY)");
  4028. break;
  4029. default:
  4030. p += sprintf(p,
  4031. "(Timeout %dms, Period %dms)",
  4032. timeout_duration[level - 1] / 1000,
  4033. period_duration[level - 1] / 1000);
  4034. }
  4035. /*
  4036. if (!(priv->power_mode & IWL_POWER_ENABLED))
  4037. p += sprintf(p, " OFF\n");
  4038. else
  4039. p += sprintf(p, " \n");
  4040. */
  4041. p += sprintf(p, " \n");
  4042. return (p - buf + 1);
  4043. }
  4044. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  4045. store_power_level);
  4046. static ssize_t show_channels(struct device *d,
  4047. struct device_attribute *attr, char *buf)
  4048. {
  4049. /* all this shit doesn't belong into sysfs anyway */
  4050. return 0;
  4051. }
  4052. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  4053. static ssize_t show_statistics(struct device *d,
  4054. struct device_attribute *attr, char *buf)
  4055. {
  4056. struct iwl_priv *priv = dev_get_drvdata(d);
  4057. u32 size = sizeof(struct iwl4965_notif_statistics);
  4058. u32 len = 0, ofs = 0;
  4059. u8 *data = (u8 *) & priv->statistics;
  4060. int rc = 0;
  4061. if (!iwl_is_alive(priv))
  4062. return -EAGAIN;
  4063. mutex_lock(&priv->mutex);
  4064. rc = iwl_send_statistics_request(priv, 0);
  4065. mutex_unlock(&priv->mutex);
  4066. if (rc) {
  4067. len = sprintf(buf,
  4068. "Error sending statistics request: 0x%08X\n", rc);
  4069. return len;
  4070. }
  4071. while (size && (PAGE_SIZE - len)) {
  4072. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4073. PAGE_SIZE - len, 1);
  4074. len = strlen(buf);
  4075. if (PAGE_SIZE - len)
  4076. buf[len++] = '\n';
  4077. ofs += 16;
  4078. size -= min(size, 16U);
  4079. }
  4080. return len;
  4081. }
  4082. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  4083. static ssize_t show_status(struct device *d,
  4084. struct device_attribute *attr, char *buf)
  4085. {
  4086. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4087. if (!iwl_is_alive(priv))
  4088. return -EAGAIN;
  4089. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4090. }
  4091. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4092. /*****************************************************************************
  4093. *
  4094. * driver setup and teardown
  4095. *
  4096. *****************************************************************************/
  4097. static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
  4098. {
  4099. priv->workqueue = create_workqueue(DRV_NAME);
  4100. init_waitqueue_head(&priv->wait_command_queue);
  4101. INIT_WORK(&priv->up, iwl4965_bg_up);
  4102. INIT_WORK(&priv->restart, iwl4965_bg_restart);
  4103. INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
  4104. INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
  4105. INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
  4106. INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
  4107. INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
  4108. INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
  4109. INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
  4110. INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
  4111. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  4112. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  4113. INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
  4114. iwl4965_hw_setup_deferred_work(priv);
  4115. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4116. iwl4965_irq_tasklet, (unsigned long)priv);
  4117. }
  4118. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
  4119. {
  4120. iwl4965_hw_cancel_deferred_work(priv);
  4121. cancel_delayed_work_sync(&priv->init_alive_start);
  4122. cancel_delayed_work(&priv->scan_check);
  4123. cancel_delayed_work(&priv->alive_start);
  4124. cancel_delayed_work(&priv->post_associate);
  4125. cancel_work_sync(&priv->beacon_update);
  4126. }
  4127. static struct attribute *iwl4965_sysfs_entries[] = {
  4128. &dev_attr_channels.attr,
  4129. &dev_attr_flags.attr,
  4130. &dev_attr_filter_flags.attr,
  4131. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  4132. &dev_attr_measurement.attr,
  4133. #endif
  4134. &dev_attr_power_level.attr,
  4135. &dev_attr_retry_rate.attr,
  4136. &dev_attr_rs_window.attr,
  4137. &dev_attr_statistics.attr,
  4138. &dev_attr_status.attr,
  4139. &dev_attr_temperature.attr,
  4140. &dev_attr_tx_power.attr,
  4141. #ifdef CONFIG_IWLWIFI_DEBUG
  4142. &dev_attr_debug_level.attr,
  4143. #endif
  4144. &dev_attr_version.attr,
  4145. NULL
  4146. };
  4147. static struct attribute_group iwl4965_attribute_group = {
  4148. .name = NULL, /* put in device directory */
  4149. .attrs = iwl4965_sysfs_entries,
  4150. };
  4151. static struct ieee80211_ops iwl4965_hw_ops = {
  4152. .tx = iwl4965_mac_tx,
  4153. .start = iwl4965_mac_start,
  4154. .stop = iwl4965_mac_stop,
  4155. .add_interface = iwl4965_mac_add_interface,
  4156. .remove_interface = iwl4965_mac_remove_interface,
  4157. .config = iwl4965_mac_config,
  4158. .config_interface = iwl4965_mac_config_interface,
  4159. .configure_filter = iwl4965_configure_filter,
  4160. .set_key = iwl4965_mac_set_key,
  4161. .update_tkip_key = iwl4965_mac_update_tkip_key,
  4162. .get_stats = iwl4965_mac_get_stats,
  4163. .get_tx_stats = iwl4965_mac_get_tx_stats,
  4164. .conf_tx = iwl4965_mac_conf_tx,
  4165. .get_tsf = iwl4965_mac_get_tsf,
  4166. .reset_tsf = iwl4965_mac_reset_tsf,
  4167. .beacon_update = iwl4965_mac_beacon_update,
  4168. .bss_info_changed = iwl4965_bss_info_changed,
  4169. #ifdef CONFIG_IWL4965_HT
  4170. .ampdu_action = iwl4965_mac_ampdu_action,
  4171. #endif /* CONFIG_IWL4965_HT */
  4172. .hw_scan = iwl4965_mac_hw_scan
  4173. };
  4174. static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4175. {
  4176. int err = 0;
  4177. struct iwl_priv *priv;
  4178. struct ieee80211_hw *hw;
  4179. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4180. unsigned long flags;
  4181. DECLARE_MAC_BUF(mac);
  4182. /************************
  4183. * 1. Allocating HW data
  4184. ************************/
  4185. /* Disabling hardware scan means that mac80211 will perform scans
  4186. * "the hard way", rather than using device's scan. */
  4187. if (cfg->mod_params->disable_hw_scan) {
  4188. if (cfg->mod_params->debug & IWL_DL_INFO)
  4189. dev_printk(KERN_DEBUG, &(pdev->dev),
  4190. "Disabling hw_scan\n");
  4191. iwl4965_hw_ops.hw_scan = NULL;
  4192. }
  4193. hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
  4194. if (!hw) {
  4195. err = -ENOMEM;
  4196. goto out;
  4197. }
  4198. priv = hw->priv;
  4199. /* At this point both hw and priv are allocated. */
  4200. SET_IEEE80211_DEV(hw, &pdev->dev);
  4201. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  4202. priv->cfg = cfg;
  4203. priv->pci_dev = pdev;
  4204. #ifdef CONFIG_IWLWIFI_DEBUG
  4205. priv->debug_level = priv->cfg->mod_params->debug;
  4206. atomic_set(&priv->restrict_refcnt, 0);
  4207. #endif
  4208. /**************************
  4209. * 2. Initializing PCI bus
  4210. **************************/
  4211. if (pci_enable_device(pdev)) {
  4212. err = -ENODEV;
  4213. goto out_ieee80211_free_hw;
  4214. }
  4215. pci_set_master(pdev);
  4216. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  4217. if (!err)
  4218. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  4219. if (err) {
  4220. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4221. if (!err)
  4222. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  4223. /* both attempts failed: */
  4224. if (err) {
  4225. printk(KERN_WARNING "%s: No suitable DMA available.\n",
  4226. DRV_NAME);
  4227. goto out_pci_disable_device;
  4228. }
  4229. }
  4230. err = pci_request_regions(pdev, DRV_NAME);
  4231. if (err)
  4232. goto out_pci_disable_device;
  4233. pci_set_drvdata(pdev, priv);
  4234. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  4235. * PCI Tx retries from interfering with C3 CPU state */
  4236. pci_write_config_byte(pdev, 0x41, 0x00);
  4237. /***********************
  4238. * 3. Read REV register
  4239. ***********************/
  4240. priv->hw_base = pci_iomap(pdev, 0, 0);
  4241. if (!priv->hw_base) {
  4242. err = -ENODEV;
  4243. goto out_pci_release_regions;
  4244. }
  4245. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  4246. (unsigned long long) pci_resource_len(pdev, 0));
  4247. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  4248. iwl_hw_detect(priv);
  4249. printk(KERN_INFO DRV_NAME
  4250. ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
  4251. priv->cfg->name, priv->hw_rev);
  4252. /* amp init */
  4253. err = priv->cfg->ops->lib->apm_ops.init(priv);
  4254. if (err < 0) {
  4255. IWL_DEBUG_INFO("Failed to init APMG\n");
  4256. goto out_iounmap;
  4257. }
  4258. /*****************
  4259. * 4. Read EEPROM
  4260. *****************/
  4261. /* Read the EEPROM */
  4262. err = iwl_eeprom_init(priv);
  4263. if (err) {
  4264. IWL_ERROR("Unable to init EEPROM\n");
  4265. goto out_iounmap;
  4266. }
  4267. err = iwl_eeprom_check_version(priv);
  4268. if (err)
  4269. goto out_iounmap;
  4270. /* extract MAC Address */
  4271. iwl_eeprom_get_mac(priv, priv->mac_addr);
  4272. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  4273. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  4274. /************************
  4275. * 5. Setup HW constants
  4276. ************************/
  4277. /* Device-specific setup */
  4278. if (priv->cfg->ops->lib->set_hw_params(priv)) {
  4279. IWL_ERROR("failed to set hw parameters\n");
  4280. goto out_free_eeprom;
  4281. }
  4282. /*******************
  4283. * 6. Setup priv
  4284. *******************/
  4285. err = iwl_init_drv(priv);
  4286. if (err)
  4287. goto out_free_eeprom;
  4288. /* At this point both hw and priv are initialized. */
  4289. /**********************************
  4290. * 7. Initialize module parameters
  4291. **********************************/
  4292. /* Disable radio (SW RF KILL) via parameter when loading driver */
  4293. if (priv->cfg->mod_params->disable) {
  4294. set_bit(STATUS_RF_KILL_SW, &priv->status);
  4295. IWL_DEBUG_INFO("Radio disabled.\n");
  4296. }
  4297. /********************
  4298. * 8. Setup services
  4299. ********************/
  4300. spin_lock_irqsave(&priv->lock, flags);
  4301. iwl4965_disable_interrupts(priv);
  4302. spin_unlock_irqrestore(&priv->lock, flags);
  4303. err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4304. if (err) {
  4305. IWL_ERROR("failed to create sysfs device attributes\n");
  4306. goto out_uninit_drv;
  4307. }
  4308. iwl4965_setup_deferred_work(priv);
  4309. iwl4965_setup_rx_handlers(priv);
  4310. /********************
  4311. * 9. Conclude
  4312. ********************/
  4313. pci_save_state(pdev);
  4314. pci_disable_device(pdev);
  4315. /**********************************
  4316. * 10. Setup and register mac80211
  4317. **********************************/
  4318. err = iwl_setup_mac(priv);
  4319. if (err)
  4320. goto out_remove_sysfs;
  4321. err = iwl_dbgfs_register(priv, DRV_NAME);
  4322. if (err)
  4323. IWL_ERROR("failed to create debugfs files\n");
  4324. /* notify iwlcore to init */
  4325. iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
  4326. return 0;
  4327. out_remove_sysfs:
  4328. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4329. out_uninit_drv:
  4330. iwl_uninit_drv(priv);
  4331. out_free_eeprom:
  4332. iwl_eeprom_free(priv);
  4333. out_iounmap:
  4334. pci_iounmap(pdev, priv->hw_base);
  4335. out_pci_release_regions:
  4336. pci_release_regions(pdev);
  4337. pci_set_drvdata(pdev, NULL);
  4338. out_pci_disable_device:
  4339. pci_disable_device(pdev);
  4340. out_ieee80211_free_hw:
  4341. ieee80211_free_hw(priv->hw);
  4342. out:
  4343. return err;
  4344. }
  4345. static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
  4346. {
  4347. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4348. struct list_head *p, *q;
  4349. int i;
  4350. unsigned long flags;
  4351. if (!priv)
  4352. return;
  4353. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  4354. iwl_dbgfs_unregister(priv);
  4355. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4356. if (priv->mac80211_registered) {
  4357. ieee80211_unregister_hw(priv->hw);
  4358. priv->mac80211_registered = 0;
  4359. }
  4360. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4361. iwl4965_down(priv);
  4362. /* make sure we flush any pending irq or
  4363. * tasklet for the driver
  4364. */
  4365. spin_lock_irqsave(&priv->lock, flags);
  4366. iwl4965_disable_interrupts(priv);
  4367. spin_unlock_irqrestore(&priv->lock, flags);
  4368. iwl_synchronize_irq(priv);
  4369. /* Free MAC hash list for ADHOC */
  4370. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  4371. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  4372. list_del(p);
  4373. kfree(list_entry(p, struct iwl4965_ibss_seq, list));
  4374. }
  4375. }
  4376. iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
  4377. iwl4965_dealloc_ucode_pci(priv);
  4378. if (priv->rxq.bd)
  4379. iwl_rx_queue_free(priv, &priv->rxq);
  4380. iwl_hw_txq_ctx_free(priv);
  4381. iwlcore_clear_stations_table(priv);
  4382. iwl_eeprom_free(priv);
  4383. /*netif_stop_queue(dev); */
  4384. flush_workqueue(priv->workqueue);
  4385. /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
  4386. * priv->workqueue... so we can't take down the workqueue
  4387. * until now... */
  4388. destroy_workqueue(priv->workqueue);
  4389. priv->workqueue = NULL;
  4390. pci_iounmap(pdev, priv->hw_base);
  4391. pci_release_regions(pdev);
  4392. pci_disable_device(pdev);
  4393. pci_set_drvdata(pdev, NULL);
  4394. iwl_uninit_drv(priv);
  4395. if (priv->ibss_beacon)
  4396. dev_kfree_skb(priv->ibss_beacon);
  4397. ieee80211_free_hw(priv->hw);
  4398. }
  4399. #ifdef CONFIG_PM
  4400. static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4401. {
  4402. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4403. if (priv->is_open) {
  4404. set_bit(STATUS_IN_SUSPEND, &priv->status);
  4405. iwl4965_mac_stop(priv->hw);
  4406. priv->is_open = 1;
  4407. }
  4408. pci_set_power_state(pdev, PCI_D3hot);
  4409. return 0;
  4410. }
  4411. static int iwl4965_pci_resume(struct pci_dev *pdev)
  4412. {
  4413. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4414. pci_set_power_state(pdev, PCI_D0);
  4415. if (priv->is_open)
  4416. iwl4965_mac_start(priv->hw);
  4417. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  4418. return 0;
  4419. }
  4420. #endif /* CONFIG_PM */
  4421. /*****************************************************************************
  4422. *
  4423. * driver and module entry point
  4424. *
  4425. *****************************************************************************/
  4426. /* Hardware specific file defines the PCI IDs table for that hardware module */
  4427. static struct pci_device_id iwl_hw_card_ids[] = {
  4428. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  4429. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  4430. #ifdef CONFIG_IWL5000
  4431. {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
  4432. {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
  4433. {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
  4434. #endif /* CONFIG_IWL5000 */
  4435. {0}
  4436. };
  4437. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  4438. static struct pci_driver iwl_driver = {
  4439. .name = DRV_NAME,
  4440. .id_table = iwl_hw_card_ids,
  4441. .probe = iwl4965_pci_probe,
  4442. .remove = __devexit_p(iwl4965_pci_remove),
  4443. #ifdef CONFIG_PM
  4444. .suspend = iwl4965_pci_suspend,
  4445. .resume = iwl4965_pci_resume,
  4446. #endif
  4447. };
  4448. static int __init iwl4965_init(void)
  4449. {
  4450. int ret;
  4451. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  4452. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  4453. ret = iwl4965_rate_control_register();
  4454. if (ret) {
  4455. IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
  4456. return ret;
  4457. }
  4458. ret = pci_register_driver(&iwl_driver);
  4459. if (ret) {
  4460. IWL_ERROR("Unable to initialize PCI module\n");
  4461. goto error_register;
  4462. }
  4463. return ret;
  4464. error_register:
  4465. iwl4965_rate_control_unregister();
  4466. return ret;
  4467. }
  4468. static void __exit iwl4965_exit(void)
  4469. {
  4470. pci_unregister_driver(&iwl_driver);
  4471. iwl4965_rate_control_unregister();
  4472. }
  4473. module_exit(iwl4965_exit);
  4474. module_init(iwl4965_init);