iwl-agn.c 123 KB

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