iwl4965-base.c 124 KB

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