iwl-agn.c 124 KB

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