iwl4965-base.c 122 KB

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