iwl4965-base.c 122 KB

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