iwl4965-base.c 128 KB

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