iwl4965-base.c 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #include "iwl-eeprom.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-helpers.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-calib.h"
  51. /******************************************************************************
  52. *
  53. * module boiler plate
  54. *
  55. ******************************************************************************/
  56. /*
  57. * module name, copyright, version, etc.
  58. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  67. #define VS "s"
  68. #else
  69. #define VS
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD VS
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT);
  75. MODULE_LICENSE("GPL");
  76. static int iwl4965_is_empty_essid(const char *essid, int essid_len)
  77. {
  78. /* Single white space is for Linksys APs */
  79. if (essid_len == 1 && essid[0] == ' ')
  80. return 1;
  81. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  82. while (essid_len) {
  83. essid_len--;
  84. if (essid[essid_len] != '\0')
  85. return 0;
  86. }
  87. return 1;
  88. }
  89. static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
  90. {
  91. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  92. const char *s = essid;
  93. char *d = escaped;
  94. if (iwl4965_is_empty_essid(essid, essid_len)) {
  95. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  96. return escaped;
  97. }
  98. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  99. while (essid_len--) {
  100. if (*s == '\0') {
  101. *d++ = '\\';
  102. *d++ = '0';
  103. s++;
  104. } else
  105. *d++ = *s++;
  106. }
  107. *d = '\0';
  108. return escaped;
  109. }
  110. /*************** STATION TABLE MANAGEMENT ****
  111. * mac80211 should be examined to determine if sta_info is duplicating
  112. * the functionality provided here
  113. */
  114. /**************************************************************/
  115. static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  116. {
  117. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  118. if (hw_decrypt)
  119. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  120. else
  121. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  122. }
  123. /**
  124. * iwl4965_check_rxon_cmd - validate RXON structure is valid
  125. *
  126. * NOTE: This is really only useful during development and can eventually
  127. * be #ifdef'd out once the driver is stable and folks aren't actively
  128. * making changes
  129. */
  130. static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
  131. {
  132. int error = 0;
  133. int counter = 1;
  134. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  135. error |= le32_to_cpu(rxon->flags &
  136. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  137. RXON_FLG_RADAR_DETECT_MSK));
  138. if (error)
  139. IWL_WARNING("check 24G fields %d | %d\n",
  140. counter++, error);
  141. } else {
  142. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  143. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  144. if (error)
  145. IWL_WARNING("check 52 fields %d | %d\n",
  146. counter++, error);
  147. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  148. if (error)
  149. IWL_WARNING("check 52 CCK %d | %d\n",
  150. counter++, error);
  151. }
  152. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  153. if (error)
  154. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  155. /* make sure basic rates 6Mbps and 1Mbps are supported */
  156. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  157. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  158. if (error)
  159. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  160. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  161. if (error)
  162. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  163. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  164. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  165. if (error)
  166. IWL_WARNING("check CCK and short slot %d | %d\n",
  167. counter++, error);
  168. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  169. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  170. if (error)
  171. IWL_WARNING("check CCK & auto detect %d | %d\n",
  172. counter++, error);
  173. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  174. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  175. if (error)
  176. IWL_WARNING("check TGG and auto detect %d | %d\n",
  177. counter++, error);
  178. if (error)
  179. IWL_WARNING("Tuning to channel %d\n",
  180. le16_to_cpu(rxon->channel));
  181. if (error) {
  182. IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
  183. return -1;
  184. }
  185. return 0;
  186. }
  187. /**
  188. * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  189. * @priv: staging_rxon is compared to active_rxon
  190. *
  191. * If the RXON structure is changing enough to require a new tune,
  192. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  193. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  194. */
  195. static int iwl4965_full_rxon_required(struct iwl_priv *priv)
  196. {
  197. /* These items are only settable from the full RXON command */
  198. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  199. compare_ether_addr(priv->staging_rxon.bssid_addr,
  200. priv->active_rxon.bssid_addr) ||
  201. compare_ether_addr(priv->staging_rxon.node_addr,
  202. priv->active_rxon.node_addr) ||
  203. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  204. priv->active_rxon.wlap_bssid_addr) ||
  205. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  206. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  207. (priv->staging_rxon.air_propagation !=
  208. priv->active_rxon.air_propagation) ||
  209. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  210. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  211. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  212. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  213. (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
  214. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  215. return 1;
  216. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  217. * be updated with the RXON_ASSOC command -- however only some
  218. * flag transitions are allowed using RXON_ASSOC */
  219. /* Check if we are not switching bands */
  220. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  221. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  222. return 1;
  223. /* Check if we are switching association toggle */
  224. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  225. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  226. return 1;
  227. return 0;
  228. }
  229. /**
  230. * iwl4965_commit_rxon - commit staging_rxon to hardware
  231. *
  232. * The RXON command in staging_rxon is committed to the hardware and
  233. * the active_rxon structure is updated with the new data. This
  234. * function correctly transitions out of the RXON_ASSOC_MSK state if
  235. * a HW tune is required based on the RXON structure changes.
  236. */
  237. static int iwl4965_commit_rxon(struct iwl_priv *priv)
  238. {
  239. /* cast away the const for active_rxon in this function */
  240. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  241. DECLARE_MAC_BUF(mac);
  242. int rc = 0;
  243. if (!iwl_is_alive(priv))
  244. return -1;
  245. /* always get timestamp with Rx frame */
  246. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  247. rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
  248. if (rc) {
  249. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  250. return -EINVAL;
  251. }
  252. /* If we don't need to send a full RXON, we can use
  253. * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
  254. * and other flags for the current radio configuration. */
  255. if (!iwl4965_full_rxon_required(priv)) {
  256. rc = iwl_send_rxon_assoc(priv);
  257. if (rc) {
  258. IWL_ERROR("Error setting RXON_ASSOC "
  259. "configuration (%d).\n", rc);
  260. return rc;
  261. }
  262. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  263. return 0;
  264. }
  265. /* station table will be cleared */
  266. priv->assoc_station_added = 0;
  267. /* If we are currently associated and the new config requires
  268. * an RXON_ASSOC and the new config wants the associated mask enabled,
  269. * we must clear the associated from the active configuration
  270. * before we apply the new config */
  271. if (iwl_is_associated(priv) &&
  272. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  273. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  274. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  275. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  276. sizeof(struct iwl_rxon_cmd),
  277. &priv->active_rxon);
  278. /* If the mask clearing failed then we set
  279. * active_rxon back to what it was previously */
  280. if (rc) {
  281. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  282. IWL_ERROR("Error clearing ASSOC_MSK on current "
  283. "configuration (%d).\n", rc);
  284. return rc;
  285. }
  286. }
  287. IWL_DEBUG_INFO("Sending RXON\n"
  288. "* with%s RXON_FILTER_ASSOC_MSK\n"
  289. "* channel = %d\n"
  290. "* bssid = %s\n",
  291. ((priv->staging_rxon.filter_flags &
  292. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  293. le16_to_cpu(priv->staging_rxon.channel),
  294. print_mac(mac, priv->staging_rxon.bssid_addr));
  295. iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
  296. /* Apply the new configuration */
  297. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  298. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  299. if (rc) {
  300. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  301. return rc;
  302. }
  303. iwl_remove_station(priv, iwl_bcast_addr, 0);
  304. iwlcore_clear_stations_table(priv);
  305. if (!priv->error_recovering)
  306. priv->start_calib = 0;
  307. iwl_init_sensitivity(priv);
  308. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  309. /* If we issue a new RXON command which required a tune then we must
  310. * send a new TXPOWER command or we won't be able to Tx any frames */
  311. rc = iwl4965_hw_reg_send_txpower(priv);
  312. if (rc) {
  313. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  314. return rc;
  315. }
  316. /* Add the broadcast address so we can send broadcast frames */
  317. if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
  318. IWL_INVALID_STATION) {
  319. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  320. return -EIO;
  321. }
  322. /* If we have set the ASSOC_MSK and we are in BSS mode then
  323. * add the IWL_AP_ID to the station rate table */
  324. if (iwl_is_associated(priv) &&
  325. (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
  326. if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
  327. == IWL_INVALID_STATION) {
  328. IWL_ERROR("Error adding AP address for transmit.\n");
  329. return -EIO;
  330. }
  331. priv->assoc_station_added = 1;
  332. if (priv->default_wep_key &&
  333. iwl_send_static_wepkey_cmd(priv, 0))
  334. IWL_ERROR("Could not send WEP static key.\n");
  335. }
  336. return 0;
  337. }
  338. void iwl4965_update_chain_flags(struct iwl_priv *priv)
  339. {
  340. iwl_set_rxon_chain(priv);
  341. iwl4965_commit_rxon(priv);
  342. }
  343. static int iwl4965_send_bt_config(struct iwl_priv *priv)
  344. {
  345. struct iwl4965_bt_cmd bt_cmd = {
  346. .flags = 3,
  347. .lead_time = 0xAA,
  348. .max_kill = 1,
  349. .kill_ack_mask = 0,
  350. .kill_cts_mask = 0,
  351. };
  352. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  353. sizeof(struct iwl4965_bt_cmd), &bt_cmd);
  354. }
  355. static int iwl4965_send_scan_abort(struct iwl_priv *priv)
  356. {
  357. int ret = 0;
  358. struct iwl_rx_packet *res;
  359. struct iwl_host_cmd cmd = {
  360. .id = REPLY_SCAN_ABORT_CMD,
  361. .meta.flags = CMD_WANT_SKB,
  362. };
  363. /* If there isn't a scan actively going on in the hardware
  364. * then we are in between scan bands and not actually
  365. * actively scanning, so don't send the abort command */
  366. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  367. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  368. return 0;
  369. }
  370. ret = iwl_send_cmd_sync(priv, &cmd);
  371. if (ret) {
  372. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  373. return ret;
  374. }
  375. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  376. if (res->u.status != CAN_ABORT_STATUS) {
  377. /* The scan abort will return 1 for success or
  378. * 2 for "failure". A failure condition can be
  379. * due to simply not being in an active scan which
  380. * can occur if we send the scan abort before we
  381. * the microcode has notified us that a scan is
  382. * completed. */
  383. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  384. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  385. clear_bit(STATUS_SCAN_HW, &priv->status);
  386. }
  387. dev_kfree_skb_any(cmd.meta.u.skb);
  388. return ret;
  389. }
  390. /*
  391. * CARD_STATE_CMD
  392. *
  393. * Use: Sets the device's internal card state to enable, disable, or halt
  394. *
  395. * When in the 'enable' state the card operates as normal.
  396. * When in the 'disable' state, the card enters into a low power mode.
  397. * When in the 'halt' state, the card is shut down and must be fully
  398. * restarted to come back on.
  399. */
  400. static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  401. {
  402. struct iwl_host_cmd cmd = {
  403. .id = REPLY_CARD_STATE_CMD,
  404. .len = sizeof(u32),
  405. .data = &flags,
  406. .meta.flags = meta_flag,
  407. };
  408. return iwl_send_cmd(priv, &cmd);
  409. }
  410. static void iwl_clear_free_frames(struct iwl_priv *priv)
  411. {
  412. struct list_head *element;
  413. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  414. priv->frames_count);
  415. while (!list_empty(&priv->free_frames)) {
  416. element = priv->free_frames.next;
  417. list_del(element);
  418. kfree(list_entry(element, struct iwl_frame, list));
  419. priv->frames_count--;
  420. }
  421. if (priv->frames_count) {
  422. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  423. priv->frames_count);
  424. priv->frames_count = 0;
  425. }
  426. }
  427. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  428. {
  429. struct iwl_frame *frame;
  430. struct list_head *element;
  431. if (list_empty(&priv->free_frames)) {
  432. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  433. if (!frame) {
  434. IWL_ERROR("Could not allocate frame!\n");
  435. return NULL;
  436. }
  437. priv->frames_count++;
  438. return frame;
  439. }
  440. element = priv->free_frames.next;
  441. list_del(element);
  442. return list_entry(element, struct iwl_frame, list);
  443. }
  444. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  445. {
  446. memset(frame, 0, sizeof(*frame));
  447. list_add(&frame->list, &priv->free_frames);
  448. }
  449. unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  450. struct ieee80211_hdr *hdr,
  451. const u8 *dest, int left)
  452. {
  453. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  454. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  455. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  456. return 0;
  457. if (priv->ibss_beacon->len > left)
  458. return 0;
  459. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  460. return priv->ibss_beacon->len;
  461. }
  462. static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
  463. {
  464. int i;
  465. int rate_mask;
  466. /* Set rate mask*/
  467. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  468. rate_mask = priv->active_rate_basic & 0xF;
  469. else
  470. rate_mask = priv->active_rate_basic & 0xFF0;
  471. /* Find lowest valid rate */
  472. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  473. i = iwl_rates[i].next_ieee) {
  474. if (rate_mask & (1 << i))
  475. return iwl_rates[i].plcp;
  476. }
  477. /* No valid rate was found. Assign the lowest one */
  478. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  479. return IWL_RATE_1M_PLCP;
  480. else
  481. return IWL_RATE_6M_PLCP;
  482. }
  483. static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  484. {
  485. struct iwl_frame *frame;
  486. unsigned int frame_size;
  487. int rc;
  488. u8 rate;
  489. frame = iwl_get_free_frame(priv);
  490. if (!frame) {
  491. IWL_ERROR("Could not obtain free frame buffer for beacon "
  492. "command.\n");
  493. return -ENOMEM;
  494. }
  495. rate = iwl4965_rate_get_lowest_plcp(priv);
  496. frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
  497. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  498. &frame->u.cmd[0]);
  499. iwl_free_frame(priv, frame);
  500. return rc;
  501. }
  502. /******************************************************************************
  503. *
  504. * Misc. internal state and helper functions
  505. *
  506. ******************************************************************************/
  507. /**
  508. * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
  509. *
  510. * return : set the bit for each supported rate insert in ie
  511. */
  512. static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  513. u16 basic_rate, int *left)
  514. {
  515. u16 ret_rates = 0, bit;
  516. int i;
  517. u8 *cnt = ie;
  518. u8 *rates = ie + 1;
  519. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  520. if (bit & supported_rate) {
  521. ret_rates |= bit;
  522. rates[*cnt] = iwl_rates[i].ieee |
  523. ((bit & basic_rate) ? 0x80 : 0x00);
  524. (*cnt)++;
  525. (*left)--;
  526. if ((*left <= 0) ||
  527. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  528. break;
  529. }
  530. }
  531. return ret_rates;
  532. }
  533. static void iwl4965_ht_conf(struct iwl_priv *priv,
  534. struct ieee80211_bss_conf *bss_conf)
  535. {
  536. struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
  537. struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
  538. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  539. IWL_DEBUG_MAC80211("enter: \n");
  540. iwl_conf->is_ht = bss_conf->assoc_ht;
  541. if (!iwl_conf->is_ht)
  542. return;
  543. priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  544. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  545. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  546. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  547. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  548. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  549. iwl_conf->max_amsdu_size =
  550. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  551. iwl_conf->supported_chan_width =
  552. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
  553. iwl_conf->extension_chan_offset =
  554. ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
  555. /* If no above or below channel supplied disable FAT channel */
  556. if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
  557. iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
  558. iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
  559. iwl_conf->supported_chan_width = 0;
  560. }
  561. iwl_conf->tx_mimo_ps_mode =
  562. (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  563. memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
  564. iwl_conf->control_channel = ht_bss_conf->primary_channel;
  565. iwl_conf->tx_chan_width =
  566. !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
  567. iwl_conf->ht_protection =
  568. ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
  569. iwl_conf->non_GF_STA_present =
  570. !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
  571. IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
  572. IWL_DEBUG_MAC80211("leave\n");
  573. }
  574. static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  575. u8 *pos, int *left)
  576. {
  577. struct ieee80211_ht_cap *ht_cap;
  578. if (!sband || !sband->ht_info.ht_supported)
  579. return;
  580. if (*left < sizeof(struct ieee80211_ht_cap))
  581. return;
  582. *pos++ = sizeof(struct ieee80211_ht_cap);
  583. ht_cap = (struct ieee80211_ht_cap *) pos;
  584. ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
  585. memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
  586. ht_cap->ampdu_params_info =
  587. (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
  588. ((sband->ht_info.ampdu_density << 2) &
  589. IEEE80211_HT_CAP_AMPDU_DENSITY);
  590. *left -= sizeof(struct ieee80211_ht_cap);
  591. }
  592. /**
  593. * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
  594. */
  595. static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
  596. enum ieee80211_band band,
  597. struct ieee80211_mgmt *frame,
  598. int left, int is_direct)
  599. {
  600. int len = 0;
  601. u8 *pos = NULL;
  602. u16 active_rates, ret_rates, cck_rates, active_rate_basic;
  603. const struct ieee80211_supported_band *sband =
  604. iwl_get_hw_mode(priv, band);
  605. /* Make sure there is enough space for the probe request,
  606. * two mandatory IEs and the data */
  607. left -= 24;
  608. if (left < 0)
  609. return 0;
  610. len += 24;
  611. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  612. memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
  613. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  614. memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
  615. frame->seq_ctrl = 0;
  616. /* fill in our indirect SSID IE */
  617. /* ...next IE... */
  618. left -= 2;
  619. if (left < 0)
  620. return 0;
  621. len += 2;
  622. pos = &(frame->u.probe_req.variable[0]);
  623. *pos++ = WLAN_EID_SSID;
  624. *pos++ = 0;
  625. /* fill in our direct SSID IE... */
  626. if (is_direct) {
  627. /* ...next IE... */
  628. left -= 2 + priv->essid_len;
  629. if (left < 0)
  630. return 0;
  631. /* ... fill it in... */
  632. *pos++ = WLAN_EID_SSID;
  633. *pos++ = priv->essid_len;
  634. memcpy(pos, priv->essid, priv->essid_len);
  635. pos += priv->essid_len;
  636. len += 2 + priv->essid_len;
  637. }
  638. /* fill in supported rate */
  639. /* ...next IE... */
  640. left -= 2;
  641. if (left < 0)
  642. return 0;
  643. /* ... fill it in... */
  644. *pos++ = WLAN_EID_SUPP_RATES;
  645. *pos = 0;
  646. /* exclude 60M rate */
  647. active_rates = priv->rates_mask;
  648. active_rates &= ~IWL_RATE_60M_MASK;
  649. active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
  650. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  651. ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
  652. active_rate_basic, &left);
  653. active_rates &= ~ret_rates;
  654. ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
  655. active_rate_basic, &left);
  656. active_rates &= ~ret_rates;
  657. len += 2 + *pos;
  658. pos += (*pos) + 1;
  659. if (active_rates == 0)
  660. goto fill_end;
  661. /* fill in supported extended rate */
  662. /* ...next IE... */
  663. left -= 2;
  664. if (left < 0)
  665. return 0;
  666. /* ... fill it in... */
  667. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  668. *pos = 0;
  669. iwl4965_supported_rate_to_ie(pos, active_rates,
  670. active_rate_basic, &left);
  671. if (*pos > 0)
  672. len += 2 + *pos;
  673. fill_end:
  674. /* fill in HT IE */
  675. left -= 2;
  676. if (left < 0)
  677. return 0;
  678. *pos++ = WLAN_EID_HT_CAPABILITY;
  679. *pos = 0;
  680. iwl_ht_cap_to_ie(sband, pos, &left);
  681. if (*pos > 0)
  682. len += 2 + *pos;
  683. return (u16)len;
  684. }
  685. /*
  686. * QoS support
  687. */
  688. static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
  689. struct iwl4965_qosparam_cmd *qos)
  690. {
  691. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  692. sizeof(struct iwl4965_qosparam_cmd), qos);
  693. }
  694. static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
  695. {
  696. unsigned long flags;
  697. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  698. return;
  699. if (!priv->qos_data.qos_enable)
  700. return;
  701. spin_lock_irqsave(&priv->lock, flags);
  702. priv->qos_data.def_qos_parm.qos_flags = 0;
  703. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  704. !priv->qos_data.qos_cap.q_AP.txop_request)
  705. priv->qos_data.def_qos_parm.qos_flags |=
  706. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  707. if (priv->qos_data.qos_active)
  708. priv->qos_data.def_qos_parm.qos_flags |=
  709. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  710. if (priv->current_ht_config.is_ht)
  711. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  712. spin_unlock_irqrestore(&priv->lock, flags);
  713. if (force || iwl_is_associated(priv)) {
  714. IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  715. priv->qos_data.qos_active,
  716. priv->qos_data.def_qos_parm.qos_flags);
  717. iwl4965_send_qos_params_command(priv,
  718. &(priv->qos_data.def_qos_parm));
  719. }
  720. }
  721. int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  722. {
  723. /* Filter incoming packets to determine if they are targeted toward
  724. * this network, discarding packets coming from ourselves */
  725. switch (priv->iw_mode) {
  726. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  727. /* packets from our adapter are dropped (echo) */
  728. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  729. return 0;
  730. /* {broad,multi}cast packets to our IBSS go through */
  731. if (is_multicast_ether_addr(header->addr1))
  732. return !compare_ether_addr(header->addr3, priv->bssid);
  733. /* packets to our adapter go through */
  734. return !compare_ether_addr(header->addr1, priv->mac_addr);
  735. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  736. /* packets from our adapter are dropped (echo) */
  737. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  738. return 0;
  739. /* {broad,multi}cast packets to our BSS go through */
  740. if (is_multicast_ether_addr(header->addr1))
  741. return !compare_ether_addr(header->addr2, priv->bssid);
  742. /* packets to our adapter go through */
  743. return !compare_ether_addr(header->addr1, priv->mac_addr);
  744. default:
  745. break;
  746. }
  747. return 1;
  748. }
  749. /**
  750. * iwl4965_scan_cancel - Cancel any currently executing HW scan
  751. *
  752. * NOTE: priv->mutex is not required before calling this function
  753. */
  754. static int iwl4965_scan_cancel(struct iwl_priv *priv)
  755. {
  756. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  757. clear_bit(STATUS_SCANNING, &priv->status);
  758. return 0;
  759. }
  760. if (test_bit(STATUS_SCANNING, &priv->status)) {
  761. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  762. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  763. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  764. queue_work(priv->workqueue, &priv->abort_scan);
  765. } else
  766. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  767. return test_bit(STATUS_SCANNING, &priv->status);
  768. }
  769. return 0;
  770. }
  771. /**
  772. * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
  773. * @ms: amount of time to wait (in milliseconds) for scan to abort
  774. *
  775. * NOTE: priv->mutex must be held before calling this function
  776. */
  777. static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
  778. {
  779. unsigned long now = jiffies;
  780. int ret;
  781. ret = iwl4965_scan_cancel(priv);
  782. if (ret && ms) {
  783. mutex_unlock(&priv->mutex);
  784. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  785. test_bit(STATUS_SCANNING, &priv->status))
  786. msleep(1);
  787. mutex_lock(&priv->mutex);
  788. return test_bit(STATUS_SCANNING, &priv->status);
  789. }
  790. return ret;
  791. }
  792. static void iwl4965_sequence_reset(struct iwl_priv *priv)
  793. {
  794. /* Reset ieee stats */
  795. /* We don't reset the net_device_stats (ieee->stats) on
  796. * re-association */
  797. priv->last_seq_num = -1;
  798. priv->last_frag_num = -1;
  799. priv->last_packet_time = 0;
  800. iwl4965_scan_cancel(priv);
  801. }
  802. #define MAX_UCODE_BEACON_INTERVAL 4096
  803. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  804. static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
  805. {
  806. u16 new_val = 0;
  807. u16 beacon_factor = 0;
  808. beacon_factor =
  809. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  810. / MAX_UCODE_BEACON_INTERVAL;
  811. new_val = beacon_val / beacon_factor;
  812. return cpu_to_le16(new_val);
  813. }
  814. static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
  815. {
  816. u64 interval_tm_unit;
  817. u64 tsf, result;
  818. unsigned long flags;
  819. struct ieee80211_conf *conf = NULL;
  820. u16 beacon_int = 0;
  821. conf = ieee80211_get_hw_conf(priv->hw);
  822. spin_lock_irqsave(&priv->lock, flags);
  823. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
  824. priv->rxon_timing.timestamp.dw[0] =
  825. cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
  826. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  827. tsf = priv->timestamp;
  828. beacon_int = priv->beacon_int;
  829. spin_unlock_irqrestore(&priv->lock, flags);
  830. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  831. if (beacon_int == 0) {
  832. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  833. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  834. } else {
  835. priv->rxon_timing.beacon_interval =
  836. cpu_to_le16(beacon_int);
  837. priv->rxon_timing.beacon_interval =
  838. iwl4965_adjust_beacon_interval(
  839. le16_to_cpu(priv->rxon_timing.beacon_interval));
  840. }
  841. priv->rxon_timing.atim_window = 0;
  842. } else {
  843. priv->rxon_timing.beacon_interval =
  844. iwl4965_adjust_beacon_interval(conf->beacon_int);
  845. /* TODO: we need to get atim_window from upper stack
  846. * for now we set to 0 */
  847. priv->rxon_timing.atim_window = 0;
  848. }
  849. interval_tm_unit =
  850. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  851. result = do_div(tsf, interval_tm_unit);
  852. priv->rxon_timing.beacon_init_val =
  853. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  854. IWL_DEBUG_ASSOC
  855. ("beacon interval %d beacon timer %d beacon tim %d\n",
  856. le16_to_cpu(priv->rxon_timing.beacon_interval),
  857. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  858. le16_to_cpu(priv->rxon_timing.atim_window));
  859. }
  860. static int iwl4965_scan_initiate(struct iwl_priv *priv)
  861. {
  862. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  863. IWL_ERROR("APs don't scan.\n");
  864. return 0;
  865. }
  866. if (!iwl_is_ready_rf(priv)) {
  867. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  868. return -EIO;
  869. }
  870. if (test_bit(STATUS_SCANNING, &priv->status)) {
  871. IWL_DEBUG_SCAN("Scan already in progress.\n");
  872. return -EAGAIN;
  873. }
  874. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  875. IWL_DEBUG_SCAN("Scan request while abort pending. "
  876. "Queuing.\n");
  877. return -EAGAIN;
  878. }
  879. IWL_DEBUG_INFO("Starting scan...\n");
  880. priv->scan_bands = 2;
  881. set_bit(STATUS_SCANNING, &priv->status);
  882. priv->scan_start = jiffies;
  883. priv->scan_pass_start = priv->scan_start;
  884. queue_work(priv->workqueue, &priv->request_scan);
  885. return 0;
  886. }
  887. static void iwl_set_flags_for_band(struct iwl_priv *priv,
  888. enum ieee80211_band band)
  889. {
  890. if (band == IEEE80211_BAND_5GHZ) {
  891. priv->staging_rxon.flags &=
  892. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  893. | RXON_FLG_CCK_MSK);
  894. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  895. } else {
  896. /* Copied from iwl4965_post_associate() */
  897. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  898. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  899. else
  900. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  901. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  902. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  903. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  904. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  905. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  906. }
  907. }
  908. /*
  909. * initialize rxon structure with default values from eeprom
  910. */
  911. static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
  912. {
  913. const struct iwl_channel_info *ch_info;
  914. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  915. switch (priv->iw_mode) {
  916. case IEEE80211_IF_TYPE_AP:
  917. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  918. break;
  919. case IEEE80211_IF_TYPE_STA:
  920. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  921. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  922. break;
  923. case IEEE80211_IF_TYPE_IBSS:
  924. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  925. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  926. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  927. RXON_FILTER_ACCEPT_GRP_MSK;
  928. break;
  929. case IEEE80211_IF_TYPE_MNTR:
  930. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  931. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  932. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  933. break;
  934. default:
  935. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  936. break;
  937. }
  938. #if 0
  939. /* TODO: Figure out when short_preamble would be set and cache from
  940. * that */
  941. if (!hw_to_local(priv->hw)->short_preamble)
  942. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  943. else
  944. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  945. #endif
  946. ch_info = iwl_get_channel_info(priv, priv->band,
  947. le16_to_cpu(priv->staging_rxon.channel));
  948. if (!ch_info)
  949. ch_info = &priv->channel_info[0];
  950. /*
  951. * in some case A channels are all non IBSS
  952. * in this case force B/G channel
  953. */
  954. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  955. !(is_channel_ibss(ch_info)))
  956. ch_info = &priv->channel_info[0];
  957. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  958. priv->band = ch_info->band;
  959. iwl_set_flags_for_band(priv, priv->band);
  960. priv->staging_rxon.ofdm_basic_rates =
  961. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  962. priv->staging_rxon.cck_basic_rates =
  963. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  964. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  965. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  966. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  967. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  968. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  969. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  970. iwl_set_rxon_chain(priv);
  971. }
  972. static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
  973. {
  974. if (mode == IEEE80211_IF_TYPE_IBSS) {
  975. const struct iwl_channel_info *ch_info;
  976. ch_info = iwl_get_channel_info(priv,
  977. priv->band,
  978. le16_to_cpu(priv->staging_rxon.channel));
  979. if (!ch_info || !is_channel_ibss(ch_info)) {
  980. IWL_ERROR("channel %d not IBSS channel\n",
  981. le16_to_cpu(priv->staging_rxon.channel));
  982. return -EINVAL;
  983. }
  984. }
  985. priv->iw_mode = mode;
  986. iwl4965_connection_init_rx_config(priv);
  987. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  988. iwlcore_clear_stations_table(priv);
  989. /* dont commit rxon if rf-kill is on*/
  990. if (!iwl_is_ready_rf(priv))
  991. return -EAGAIN;
  992. cancel_delayed_work(&priv->scan_check);
  993. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  994. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  995. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  996. return -EAGAIN;
  997. }
  998. iwl4965_commit_rxon(priv);
  999. return 0;
  1000. }
  1001. static void iwl4965_set_rate(struct iwl_priv *priv)
  1002. {
  1003. const struct ieee80211_supported_band *hw = NULL;
  1004. struct ieee80211_rate *rate;
  1005. int i;
  1006. hw = iwl_get_hw_mode(priv, priv->band);
  1007. if (!hw) {
  1008. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  1009. return;
  1010. }
  1011. priv->active_rate = 0;
  1012. priv->active_rate_basic = 0;
  1013. for (i = 0; i < hw->n_bitrates; i++) {
  1014. rate = &(hw->bitrates[i]);
  1015. if (rate->hw_value < IWL_RATE_COUNT)
  1016. priv->active_rate |= (1 << rate->hw_value);
  1017. }
  1018. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  1019. priv->active_rate, priv->active_rate_basic);
  1020. /*
  1021. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1022. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1023. * OFDM
  1024. */
  1025. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1026. priv->staging_rxon.cck_basic_rates =
  1027. ((priv->active_rate_basic &
  1028. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1029. else
  1030. priv->staging_rxon.cck_basic_rates =
  1031. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1032. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1033. priv->staging_rxon.ofdm_basic_rates =
  1034. ((priv->active_rate_basic &
  1035. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1036. IWL_FIRST_OFDM_RATE) & 0xFF;
  1037. else
  1038. priv->staging_rxon.ofdm_basic_rates =
  1039. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1040. }
  1041. int iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  1042. {
  1043. unsigned long flags;
  1044. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  1045. return 0;
  1046. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  1047. disable_radio ? "OFF" : "ON");
  1048. if (disable_radio) {
  1049. iwl4965_scan_cancel(priv);
  1050. /* FIXME: This is a workaround for AP */
  1051. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  1052. spin_lock_irqsave(&priv->lock, flags);
  1053. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1054. CSR_UCODE_SW_BIT_RFKILL);
  1055. spin_unlock_irqrestore(&priv->lock, flags);
  1056. /* call the host command only if no hw rf-kill set */
  1057. if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
  1058. iwl_is_ready(priv))
  1059. iwl4965_send_card_state(priv,
  1060. CARD_STATE_CMD_DISABLE,
  1061. 0);
  1062. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1063. /* make sure mac80211 stop sending Tx frame */
  1064. if (priv->mac80211_registered)
  1065. ieee80211_stop_queues(priv->hw);
  1066. }
  1067. return 0;
  1068. }
  1069. spin_lock_irqsave(&priv->lock, flags);
  1070. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1071. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1072. spin_unlock_irqrestore(&priv->lock, flags);
  1073. /* wake up ucode */
  1074. msleep(10);
  1075. spin_lock_irqsave(&priv->lock, flags);
  1076. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1077. if (!iwl_grab_nic_access(priv))
  1078. iwl_release_nic_access(priv);
  1079. spin_unlock_irqrestore(&priv->lock, flags);
  1080. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  1081. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  1082. "disabled by HW switch\n");
  1083. return 0;
  1084. }
  1085. queue_work(priv->workqueue, &priv->restart);
  1086. return 1;
  1087. }
  1088. #define IWL_PACKET_RETRY_TIME HZ
  1089. int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  1090. {
  1091. u16 sc = le16_to_cpu(header->seq_ctrl);
  1092. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1093. u16 frag = sc & IEEE80211_SCTL_FRAG;
  1094. u16 *last_seq, *last_frag;
  1095. unsigned long *last_time;
  1096. switch (priv->iw_mode) {
  1097. case IEEE80211_IF_TYPE_IBSS:{
  1098. struct list_head *p;
  1099. struct iwl4965_ibss_seq *entry = NULL;
  1100. u8 *mac = header->addr2;
  1101. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  1102. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  1103. entry = list_entry(p, struct iwl4965_ibss_seq, list);
  1104. if (!compare_ether_addr(entry->mac, mac))
  1105. break;
  1106. }
  1107. if (p == &priv->ibss_mac_hash[index]) {
  1108. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  1109. if (!entry) {
  1110. IWL_ERROR("Cannot malloc new mac entry\n");
  1111. return 0;
  1112. }
  1113. memcpy(entry->mac, mac, ETH_ALEN);
  1114. entry->seq_num = seq;
  1115. entry->frag_num = frag;
  1116. entry->packet_time = jiffies;
  1117. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  1118. return 0;
  1119. }
  1120. last_seq = &entry->seq_num;
  1121. last_frag = &entry->frag_num;
  1122. last_time = &entry->packet_time;
  1123. break;
  1124. }
  1125. case IEEE80211_IF_TYPE_STA:
  1126. last_seq = &priv->last_seq_num;
  1127. last_frag = &priv->last_frag_num;
  1128. last_time = &priv->last_packet_time;
  1129. break;
  1130. default:
  1131. return 0;
  1132. }
  1133. if ((*last_seq == seq) &&
  1134. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  1135. if (*last_frag == frag)
  1136. goto drop;
  1137. if (*last_frag + 1 != frag)
  1138. /* out-of-order fragment */
  1139. goto drop;
  1140. } else
  1141. *last_seq = seq;
  1142. *last_frag = frag;
  1143. *last_time = jiffies;
  1144. return 0;
  1145. drop:
  1146. return 1;
  1147. }
  1148. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1149. #include "iwl-spectrum.h"
  1150. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1151. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1152. #define TIME_UNIT 1024
  1153. /*
  1154. * extended beacon time format
  1155. * time in usec will be changed into a 32-bit value in 8:24 format
  1156. * the high 1 byte is the beacon counts
  1157. * the lower 3 bytes is the time in usec within one beacon interval
  1158. */
  1159. static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1160. {
  1161. u32 quot;
  1162. u32 rem;
  1163. u32 interval = beacon_interval * 1024;
  1164. if (!interval || !usec)
  1165. return 0;
  1166. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1167. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1168. return (quot << 24) + rem;
  1169. }
  1170. /* base is usually what we get from ucode with each received frame,
  1171. * the same as HW timer counter counting down
  1172. */
  1173. static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1174. {
  1175. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1176. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1177. u32 interval = beacon_interval * TIME_UNIT;
  1178. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1179. (addon & BEACON_TIME_MASK_HIGH);
  1180. if (base_low > addon_low)
  1181. res += base_low - addon_low;
  1182. else if (base_low < addon_low) {
  1183. res += interval + base_low - addon_low;
  1184. res += (1 << 24);
  1185. } else
  1186. res += (1 << 24);
  1187. return cpu_to_le32(res);
  1188. }
  1189. static int iwl4965_get_measurement(struct iwl_priv *priv,
  1190. struct ieee80211_measurement_params *params,
  1191. u8 type)
  1192. {
  1193. struct iwl4965_spectrum_cmd spectrum;
  1194. struct iwl_rx_packet *res;
  1195. struct iwl_host_cmd cmd = {
  1196. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1197. .data = (void *)&spectrum,
  1198. .meta.flags = CMD_WANT_SKB,
  1199. };
  1200. u32 add_time = le64_to_cpu(params->start_time);
  1201. int rc;
  1202. int spectrum_resp_status;
  1203. int duration = le16_to_cpu(params->duration);
  1204. if (iwl_is_associated(priv))
  1205. add_time =
  1206. iwl4965_usecs_to_beacons(
  1207. le64_to_cpu(params->start_time) - priv->last_tsf,
  1208. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1209. memset(&spectrum, 0, sizeof(spectrum));
  1210. spectrum.channel_count = cpu_to_le16(1);
  1211. spectrum.flags =
  1212. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1213. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1214. cmd.len = sizeof(spectrum);
  1215. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1216. if (iwl_is_associated(priv))
  1217. spectrum.start_time =
  1218. iwl4965_add_beacon_time(priv->last_beacon_time,
  1219. add_time,
  1220. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1221. else
  1222. spectrum.start_time = 0;
  1223. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1224. spectrum.channels[0].channel = params->channel;
  1225. spectrum.channels[0].type = type;
  1226. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1227. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1228. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1229. rc = iwl_send_cmd_sync(priv, &cmd);
  1230. if (rc)
  1231. return rc;
  1232. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1233. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1234. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  1235. rc = -EIO;
  1236. }
  1237. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1238. switch (spectrum_resp_status) {
  1239. case 0: /* Command will be handled */
  1240. if (res->u.spectrum.id != 0xff) {
  1241. IWL_DEBUG_INFO
  1242. ("Replaced existing measurement: %d\n",
  1243. res->u.spectrum.id);
  1244. priv->measurement_status &= ~MEASUREMENT_READY;
  1245. }
  1246. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1247. rc = 0;
  1248. break;
  1249. case 1: /* Command will not be handled */
  1250. rc = -EAGAIN;
  1251. break;
  1252. }
  1253. dev_kfree_skb_any(cmd.meta.u.skb);
  1254. return rc;
  1255. }
  1256. #endif
  1257. /******************************************************************************
  1258. *
  1259. * Generic RX handler implementations
  1260. *
  1261. ******************************************************************************/
  1262. static void iwl_rx_reply_alive(struct iwl_priv *priv,
  1263. struct iwl_rx_mem_buffer *rxb)
  1264. {
  1265. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1266. struct iwl_alive_resp *palive;
  1267. struct delayed_work *pwork;
  1268. palive = &pkt->u.alive_frame;
  1269. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  1270. "0x%01X 0x%01X\n",
  1271. palive->is_valid, palive->ver_type,
  1272. palive->ver_subtype);
  1273. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1274. IWL_DEBUG_INFO("Initialization Alive received.\n");
  1275. memcpy(&priv->card_alive_init,
  1276. &pkt->u.alive_frame,
  1277. sizeof(struct iwl_init_alive_resp));
  1278. pwork = &priv->init_alive_start;
  1279. } else {
  1280. IWL_DEBUG_INFO("Runtime Alive received.\n");
  1281. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1282. sizeof(struct iwl_alive_resp));
  1283. pwork = &priv->alive_start;
  1284. }
  1285. /* We delay the ALIVE response by 5ms to
  1286. * give the HW RF Kill time to activate... */
  1287. if (palive->is_valid == UCODE_VALID_OK)
  1288. queue_delayed_work(priv->workqueue, pwork,
  1289. msecs_to_jiffies(5));
  1290. else
  1291. IWL_WARNING("uCode did not respond OK.\n");
  1292. }
  1293. static void iwl4965_rx_reply_error(struct iwl_priv *priv,
  1294. struct iwl_rx_mem_buffer *rxb)
  1295. {
  1296. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1297. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  1298. "seq 0x%04X ser 0x%08X\n",
  1299. le32_to_cpu(pkt->u.err_resp.error_type),
  1300. get_cmd_string(pkt->u.err_resp.cmd_id),
  1301. pkt->u.err_resp.cmd_id,
  1302. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1303. le32_to_cpu(pkt->u.err_resp.error_info));
  1304. }
  1305. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1306. static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1307. {
  1308. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1309. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1310. struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
  1311. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  1312. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1313. rxon->channel = csa->channel;
  1314. priv->staging_rxon.channel = csa->channel;
  1315. }
  1316. static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1317. struct iwl_rx_mem_buffer *rxb)
  1318. {
  1319. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1320. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1321. struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1322. if (!report->state) {
  1323. IWL_DEBUG(IWL_DL_11H,
  1324. "Spectrum Measure Notification: Start\n");
  1325. return;
  1326. }
  1327. memcpy(&priv->measure_report, report, sizeof(*report));
  1328. priv->measurement_status |= MEASUREMENT_READY;
  1329. #endif
  1330. }
  1331. static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
  1332. struct iwl_rx_mem_buffer *rxb)
  1333. {
  1334. #ifdef CONFIG_IWLWIFI_DEBUG
  1335. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1336. struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1337. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  1338. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1339. #endif
  1340. }
  1341. static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1342. struct iwl_rx_mem_buffer *rxb)
  1343. {
  1344. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1345. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  1346. "notification for %s:\n",
  1347. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1348. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1349. }
  1350. static void iwl4965_bg_beacon_update(struct work_struct *work)
  1351. {
  1352. struct iwl_priv *priv =
  1353. container_of(work, struct iwl_priv, beacon_update);
  1354. struct sk_buff *beacon;
  1355. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1356. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1357. if (!beacon) {
  1358. IWL_ERROR("update beacon failed\n");
  1359. return;
  1360. }
  1361. mutex_lock(&priv->mutex);
  1362. /* new beacon skb is allocated every time; dispose previous.*/
  1363. if (priv->ibss_beacon)
  1364. dev_kfree_skb(priv->ibss_beacon);
  1365. priv->ibss_beacon = beacon;
  1366. mutex_unlock(&priv->mutex);
  1367. iwl4965_send_beacon_cmd(priv);
  1368. }
  1369. /**
  1370. * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  1371. *
  1372. * This callback is provided in order to send a statistics request.
  1373. *
  1374. * This timer function is continually reset to execute within
  1375. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  1376. * was received. We need to ensure we receive the statistics in order
  1377. * to update the temperature used for calibrating the TXPOWER.
  1378. */
  1379. static void iwl4965_bg_statistics_periodic(unsigned long data)
  1380. {
  1381. struct iwl_priv *priv = (struct iwl_priv *)data;
  1382. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1383. return;
  1384. iwl_send_statistics_request(priv, CMD_ASYNC);
  1385. }
  1386. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  1387. struct iwl_rx_mem_buffer *rxb)
  1388. {
  1389. #ifdef CONFIG_IWLWIFI_DEBUG
  1390. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1391. struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
  1392. u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  1393. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  1394. "tsf %d %d rate %d\n",
  1395. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1396. beacon->beacon_notify_hdr.failure_frame,
  1397. le32_to_cpu(beacon->ibss_mgr_status),
  1398. le32_to_cpu(beacon->high_tsf),
  1399. le32_to_cpu(beacon->low_tsf), rate);
  1400. #endif
  1401. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  1402. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1403. queue_work(priv->workqueue, &priv->beacon_update);
  1404. }
  1405. /* Service response to REPLY_SCAN_CMD (0x80) */
  1406. static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
  1407. struct iwl_rx_mem_buffer *rxb)
  1408. {
  1409. #ifdef CONFIG_IWLWIFI_DEBUG
  1410. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1411. struct iwl4965_scanreq_notification *notif =
  1412. (struct iwl4965_scanreq_notification *)pkt->u.raw;
  1413. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  1414. #endif
  1415. }
  1416. /* Service SCAN_START_NOTIFICATION (0x82) */
  1417. static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
  1418. struct iwl_rx_mem_buffer *rxb)
  1419. {
  1420. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1421. struct iwl4965_scanstart_notification *notif =
  1422. (struct iwl4965_scanstart_notification *)pkt->u.raw;
  1423. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  1424. IWL_DEBUG_SCAN("Scan start: "
  1425. "%d [802.11%s] "
  1426. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  1427. notif->channel,
  1428. notif->band ? "bg" : "a",
  1429. notif->tsf_high,
  1430. notif->tsf_low, notif->status, notif->beacon_timer);
  1431. }
  1432. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  1433. static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
  1434. struct iwl_rx_mem_buffer *rxb)
  1435. {
  1436. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1437. struct iwl4965_scanresults_notification *notif =
  1438. (struct iwl4965_scanresults_notification *)pkt->u.raw;
  1439. IWL_DEBUG_SCAN("Scan ch.res: "
  1440. "%d [802.11%s] "
  1441. "(TSF: 0x%08X:%08X) - %d "
  1442. "elapsed=%lu usec (%dms since last)\n",
  1443. notif->channel,
  1444. notif->band ? "bg" : "a",
  1445. le32_to_cpu(notif->tsf_high),
  1446. le32_to_cpu(notif->tsf_low),
  1447. le32_to_cpu(notif->statistics[0]),
  1448. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  1449. jiffies_to_msecs(elapsed_jiffies
  1450. (priv->last_scan_jiffies, jiffies)));
  1451. priv->last_scan_jiffies = jiffies;
  1452. priv->next_scan_jiffies = 0;
  1453. }
  1454. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  1455. static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
  1456. struct iwl_rx_mem_buffer *rxb)
  1457. {
  1458. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1459. struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  1460. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  1461. scan_notif->scanned_channels,
  1462. scan_notif->tsf_low,
  1463. scan_notif->tsf_high, scan_notif->status);
  1464. /* The HW is no longer scanning */
  1465. clear_bit(STATUS_SCAN_HW, &priv->status);
  1466. /* The scan completion notification came in, so kill that timer... */
  1467. cancel_delayed_work(&priv->scan_check);
  1468. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  1469. (priv->scan_bands == 2) ? "2.4" : "5.2",
  1470. jiffies_to_msecs(elapsed_jiffies
  1471. (priv->scan_pass_start, jiffies)));
  1472. /* Remove this scanned band from the list
  1473. * of pending bands to scan */
  1474. priv->scan_bands--;
  1475. /* If a request to abort was given, or the scan did not succeed
  1476. * then we reset the scan state machine and terminate,
  1477. * re-queuing another scan if one has been requested */
  1478. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1479. IWL_DEBUG_INFO("Aborted scan completed.\n");
  1480. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1481. } else {
  1482. /* If there are more bands on this scan pass reschedule */
  1483. if (priv->scan_bands > 0)
  1484. goto reschedule;
  1485. }
  1486. priv->last_scan_jiffies = jiffies;
  1487. priv->next_scan_jiffies = 0;
  1488. IWL_DEBUG_INFO("Setting scan to off\n");
  1489. clear_bit(STATUS_SCANNING, &priv->status);
  1490. IWL_DEBUG_INFO("Scan took %dms\n",
  1491. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  1492. queue_work(priv->workqueue, &priv->scan_completed);
  1493. return;
  1494. reschedule:
  1495. priv->scan_pass_start = jiffies;
  1496. queue_work(priv->workqueue, &priv->request_scan);
  1497. }
  1498. /* Handle notification from uCode that card's power state is changing
  1499. * due to software, hardware, or critical temperature RFKILL */
  1500. static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
  1501. struct iwl_rx_mem_buffer *rxb)
  1502. {
  1503. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1504. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1505. unsigned long status = priv->status;
  1506. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  1507. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1508. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1509. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  1510. RF_CARD_DISABLED)) {
  1511. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1512. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1513. if (!iwl_grab_nic_access(priv)) {
  1514. iwl_write_direct32(
  1515. priv, HBUS_TARG_MBX_C,
  1516. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1517. iwl_release_nic_access(priv);
  1518. }
  1519. if (!(flags & RXON_CARD_DISABLED)) {
  1520. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1521. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1522. if (!iwl_grab_nic_access(priv)) {
  1523. iwl_write_direct32(
  1524. priv, HBUS_TARG_MBX_C,
  1525. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1526. iwl_release_nic_access(priv);
  1527. }
  1528. }
  1529. if (flags & RF_CARD_DISABLED) {
  1530. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1531. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1532. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1533. if (!iwl_grab_nic_access(priv))
  1534. iwl_release_nic_access(priv);
  1535. }
  1536. }
  1537. if (flags & HW_CARD_DISABLED)
  1538. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1539. else
  1540. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1541. if (flags & SW_CARD_DISABLED)
  1542. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1543. else
  1544. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1545. if (!(flags & RXON_CARD_DISABLED))
  1546. iwl4965_scan_cancel(priv);
  1547. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1548. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1549. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1550. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1551. queue_work(priv->workqueue, &priv->rf_kill);
  1552. else
  1553. wake_up_interruptible(&priv->wait_command_queue);
  1554. }
  1555. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  1556. * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  1557. static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
  1558. struct iwl_rx_mem_buffer *rxb)
  1559. {
  1560. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1561. priv->last_phy_res[0] = 1;
  1562. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  1563. sizeof(struct iwl4965_rx_phy_res));
  1564. }
  1565. /**
  1566. * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
  1567. *
  1568. * Setup the RX handlers for each of the reply types sent from the uCode
  1569. * to the host.
  1570. *
  1571. * This function chains into the hardware specific files for them to setup
  1572. * any hardware specific handlers as well.
  1573. */
  1574. static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
  1575. {
  1576. priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
  1577. priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
  1578. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
  1579. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1580. iwl4965_rx_spectrum_measure_notif;
  1581. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
  1582. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1583. iwl4965_rx_pm_debug_statistics_notif;
  1584. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  1585. /*
  1586. * The same handler is used for both the REPLY to a discrete
  1587. * statistics request from the host as well as for the periodic
  1588. * statistics notifications (after received beacons) from the uCode.
  1589. */
  1590. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
  1591. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
  1592. /* scan handlers */
  1593. priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
  1594. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
  1595. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  1596. iwl4965_rx_scan_results_notif;
  1597. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  1598. iwl4965_rx_scan_complete_notif;
  1599. /* status change handler */
  1600. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
  1601. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  1602. iwl_rx_missed_beacon_notif;
  1603. /* Rx handlers */
  1604. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  1605. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  1606. /* Set up hardware specific Rx handlers */
  1607. priv->cfg->ops->lib->rx_handler_setup(priv);
  1608. }
  1609. /*
  1610. * this should be called while priv->lock is locked
  1611. */
  1612. static void __iwl_rx_replenish(struct iwl_priv *priv)
  1613. {
  1614. iwl_rx_allocate(priv);
  1615. iwl_rx_queue_restock(priv);
  1616. }
  1617. /**
  1618. * iwl_rx_handle - Main entry function for receiving responses from uCode
  1619. *
  1620. * Uses the priv->rx_handlers callback function array to invoke
  1621. * the appropriate handlers, including command responses,
  1622. * frame-received notifications, and other notifications.
  1623. */
  1624. void iwl_rx_handle(struct iwl_priv *priv)
  1625. {
  1626. struct iwl_rx_mem_buffer *rxb;
  1627. struct iwl_rx_packet *pkt;
  1628. struct iwl_rx_queue *rxq = &priv->rxq;
  1629. u32 r, i;
  1630. int reclaim;
  1631. unsigned long flags;
  1632. u8 fill_rx = 0;
  1633. u32 count = 8;
  1634. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1635. * buffer that the driver may process (last buffer filled by ucode). */
  1636. r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
  1637. i = rxq->read;
  1638. /* Rx interrupt, but nothing sent from uCode */
  1639. if (i == r)
  1640. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
  1641. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  1642. fill_rx = 1;
  1643. while (i != r) {
  1644. rxb = rxq->queue[i];
  1645. /* If an RXB doesn't have a Rx queue slot associated with it,
  1646. * then a bug has been introduced in the queue refilling
  1647. * routines -- catch it here */
  1648. BUG_ON(rxb == NULL);
  1649. rxq->queue[i] = NULL;
  1650. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  1651. priv->hw_params.rx_buf_size,
  1652. PCI_DMA_FROMDEVICE);
  1653. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1654. /* Reclaim a command buffer only if this packet is a response
  1655. * to a (driver-originated) command.
  1656. * If the packet (e.g. Rx frame) originated from uCode,
  1657. * there is no command buffer to reclaim.
  1658. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1659. * but apparently a few don't get set; catch them here. */
  1660. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1661. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  1662. (pkt->hdr.cmd != REPLY_RX) &&
  1663. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  1664. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1665. (pkt->hdr.cmd != REPLY_TX);
  1666. /* Based on type of command response or notification,
  1667. * handle those that need handling via function in
  1668. * rx_handlers table. See iwl4965_setup_rx_handlers() */
  1669. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1670. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
  1671. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1672. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1673. } else {
  1674. /* No handling needed */
  1675. IWL_DEBUG(IWL_DL_RX,
  1676. "r %d i %d No handler needed for %s, 0x%02x\n",
  1677. r, i, get_cmd_string(pkt->hdr.cmd),
  1678. pkt->hdr.cmd);
  1679. }
  1680. if (reclaim) {
  1681. /* Invoke any callbacks, transfer the skb to caller, and
  1682. * fire off the (possibly) blocking iwl_send_cmd()
  1683. * as we reclaim the driver command queue */
  1684. if (rxb && rxb->skb)
  1685. iwl_tx_cmd_complete(priv, rxb);
  1686. else
  1687. IWL_WARNING("Claim null rxb?\n");
  1688. }
  1689. /* For now we just don't re-use anything. We can tweak this
  1690. * later to try and re-use notification packets and SKBs that
  1691. * fail to Rx correctly */
  1692. if (rxb->skb != NULL) {
  1693. priv->alloc_rxb_skb--;
  1694. dev_kfree_skb_any(rxb->skb);
  1695. rxb->skb = NULL;
  1696. }
  1697. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  1698. priv->hw_params.rx_buf_size,
  1699. PCI_DMA_FROMDEVICE);
  1700. spin_lock_irqsave(&rxq->lock, flags);
  1701. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  1702. spin_unlock_irqrestore(&rxq->lock, flags);
  1703. i = (i + 1) & RX_QUEUE_MASK;
  1704. /* If there are a lot of unused frames,
  1705. * restock the Rx queue so ucode wont assert. */
  1706. if (fill_rx) {
  1707. count++;
  1708. if (count >= 8) {
  1709. priv->rxq.read = i;
  1710. __iwl_rx_replenish(priv);
  1711. count = 0;
  1712. }
  1713. }
  1714. }
  1715. /* Backtrack one entry */
  1716. priv->rxq.read = i;
  1717. iwl_rx_queue_restock(priv);
  1718. }
  1719. /* Convert linear signal-to-noise ratio into dB */
  1720. static u8 ratio2dB[100] = {
  1721. /* 0 1 2 3 4 5 6 7 8 9 */
  1722. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1723. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1724. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1725. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1726. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1727. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1728. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1729. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1730. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1731. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1732. };
  1733. /* Calculates a relative dB value from a ratio of linear
  1734. * (i.e. not dB) signal levels.
  1735. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1736. int iwl4965_calc_db_from_ratio(int sig_ratio)
  1737. {
  1738. /* 1000:1 or higher just report as 60 dB */
  1739. if (sig_ratio >= 1000)
  1740. return 60;
  1741. /* 100:1 or higher, divide by 10 and use table,
  1742. * add 20 dB to make up for divide by 10 */
  1743. if (sig_ratio >= 100)
  1744. return (20 + (int)ratio2dB[sig_ratio/10]);
  1745. /* We shouldn't see this */
  1746. if (sig_ratio < 1)
  1747. return 0;
  1748. /* Use table for ratios 1:1 - 99:1 */
  1749. return (int)ratio2dB[sig_ratio];
  1750. }
  1751. #define PERFECT_RSSI (-20) /* dBm */
  1752. #define WORST_RSSI (-95) /* dBm */
  1753. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  1754. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  1755. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  1756. * about formulas used below. */
  1757. int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
  1758. {
  1759. int sig_qual;
  1760. int degradation = PERFECT_RSSI - rssi_dbm;
  1761. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  1762. * as indicator; formula is (signal dbm - noise dbm).
  1763. * SNR at or above 40 is a great signal (100%).
  1764. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  1765. * Weakest usable signal is usually 10 - 15 dB SNR. */
  1766. if (noise_dbm) {
  1767. if (rssi_dbm - noise_dbm >= 40)
  1768. return 100;
  1769. else if (rssi_dbm < noise_dbm)
  1770. return 0;
  1771. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  1772. /* Else use just the signal level.
  1773. * This formula is a least squares fit of data points collected and
  1774. * compared with a reference system that had a percentage (%) display
  1775. * for signal quality. */
  1776. } else
  1777. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  1778. (15 * RSSI_RANGE + 62 * degradation)) /
  1779. (RSSI_RANGE * RSSI_RANGE);
  1780. if (sig_qual > 100)
  1781. sig_qual = 100;
  1782. else if (sig_qual < 1)
  1783. sig_qual = 0;
  1784. return sig_qual;
  1785. }
  1786. #ifdef CONFIG_IWLWIFI_DEBUG
  1787. static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
  1788. {
  1789. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  1790. DECLARE_MAC_BUF(mac);
  1791. IWL_DEBUG_RADIO("RX CONFIG:\n");
  1792. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  1793. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  1794. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  1795. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  1796. le32_to_cpu(rxon->filter_flags));
  1797. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  1798. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  1799. rxon->ofdm_basic_rates);
  1800. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  1801. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  1802. print_mac(mac, rxon->node_addr));
  1803. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  1804. print_mac(mac, rxon->bssid_addr));
  1805. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  1806. }
  1807. #endif
  1808. static void iwl4965_enable_interrupts(struct iwl_priv *priv)
  1809. {
  1810. IWL_DEBUG_ISR("Enabling interrupts\n");
  1811. set_bit(STATUS_INT_ENABLED, &priv->status);
  1812. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  1813. }
  1814. /* call this function to flush any scheduled tasklet */
  1815. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1816. {
  1817. /* wait to make sure we flush pedding tasklet*/
  1818. synchronize_irq(priv->pci_dev->irq);
  1819. tasklet_kill(&priv->irq_tasklet);
  1820. }
  1821. static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
  1822. {
  1823. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1824. /* disable interrupts from uCode/NIC to host */
  1825. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1826. /* acknowledge/clear/reset any interrupts still pending
  1827. * from uCode or flow handler (Rx/Tx DMA) */
  1828. iwl_write32(priv, CSR_INT, 0xffffffff);
  1829. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1830. IWL_DEBUG_ISR("Disabled interrupts\n");
  1831. }
  1832. /**
  1833. * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
  1834. */
  1835. static void iwl4965_irq_handle_error(struct iwl_priv *priv)
  1836. {
  1837. /* Set the FW error flag -- cleared on iwl4965_down */
  1838. set_bit(STATUS_FW_ERROR, &priv->status);
  1839. /* Cancel currently queued command. */
  1840. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1841. #ifdef CONFIG_IWLWIFI_DEBUG
  1842. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  1843. iwl_dump_nic_error_log(priv);
  1844. iwl_dump_nic_event_log(priv);
  1845. iwl4965_print_rx_config_cmd(priv);
  1846. }
  1847. #endif
  1848. wake_up_interruptible(&priv->wait_command_queue);
  1849. /* Keep the restart process from trying to send host
  1850. * commands by clearing the INIT status bit */
  1851. clear_bit(STATUS_READY, &priv->status);
  1852. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1853. IWL_DEBUG(IWL_DL_FW_ERRORS,
  1854. "Restarting adapter due to uCode error.\n");
  1855. if (iwl_is_associated(priv)) {
  1856. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  1857. sizeof(priv->recovery_rxon));
  1858. priv->error_recovering = 1;
  1859. }
  1860. if (priv->cfg->mod_params->restart_fw)
  1861. queue_work(priv->workqueue, &priv->restart);
  1862. }
  1863. }
  1864. static void iwl4965_error_recovery(struct iwl_priv *priv)
  1865. {
  1866. unsigned long flags;
  1867. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  1868. sizeof(priv->staging_rxon));
  1869. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1870. iwl4965_commit_rxon(priv);
  1871. iwl_rxon_add_station(priv, priv->bssid, 1);
  1872. spin_lock_irqsave(&priv->lock, flags);
  1873. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  1874. priv->error_recovering = 0;
  1875. spin_unlock_irqrestore(&priv->lock, flags);
  1876. }
  1877. static void iwl4965_irq_tasklet(struct iwl_priv *priv)
  1878. {
  1879. u32 inta, handled = 0;
  1880. u32 inta_fh;
  1881. unsigned long flags;
  1882. #ifdef CONFIG_IWLWIFI_DEBUG
  1883. u32 inta_mask;
  1884. #endif
  1885. spin_lock_irqsave(&priv->lock, flags);
  1886. /* Ack/clear/reset pending uCode interrupts.
  1887. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1888. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1889. inta = iwl_read32(priv, CSR_INT);
  1890. iwl_write32(priv, CSR_INT, inta);
  1891. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1892. * Any new interrupts that happen after this, either while we're
  1893. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1894. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1895. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1896. #ifdef CONFIG_IWLWIFI_DEBUG
  1897. if (priv->debug_level & IWL_DL_ISR) {
  1898. /* just for debug */
  1899. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1900. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1901. inta, inta_mask, inta_fh);
  1902. }
  1903. #endif
  1904. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1905. * atomic, make sure that inta covers all the interrupts that
  1906. * we've discovered, even if FH interrupt came in just after
  1907. * reading CSR_INT. */
  1908. if (inta_fh & CSR49_FH_INT_RX_MASK)
  1909. inta |= CSR_INT_BIT_FH_RX;
  1910. if (inta_fh & CSR49_FH_INT_TX_MASK)
  1911. inta |= CSR_INT_BIT_FH_TX;
  1912. /* Now service all interrupt bits discovered above. */
  1913. if (inta & CSR_INT_BIT_HW_ERR) {
  1914. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  1915. /* Tell the device to stop sending interrupts */
  1916. iwl4965_disable_interrupts(priv);
  1917. iwl4965_irq_handle_error(priv);
  1918. handled |= CSR_INT_BIT_HW_ERR;
  1919. spin_unlock_irqrestore(&priv->lock, flags);
  1920. return;
  1921. }
  1922. #ifdef CONFIG_IWLWIFI_DEBUG
  1923. if (priv->debug_level & (IWL_DL_ISR)) {
  1924. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1925. if (inta & CSR_INT_BIT_SCD)
  1926. IWL_DEBUG_ISR("Scheduler finished to transmit "
  1927. "the frame/frames.\n");
  1928. /* Alive notification via Rx interrupt will do the real work */
  1929. if (inta & CSR_INT_BIT_ALIVE)
  1930. IWL_DEBUG_ISR("Alive interrupt\n");
  1931. }
  1932. #endif
  1933. /* Safely ignore these bits for debug checks below */
  1934. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1935. /* HW RF KILL switch toggled */
  1936. if (inta & CSR_INT_BIT_RF_KILL) {
  1937. int hw_rf_kill = 0;
  1938. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1939. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1940. hw_rf_kill = 1;
  1941. IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
  1942. hw_rf_kill ? "disable radio":"enable radio");
  1943. /* Queue restart only if RF_KILL switch was set to "kill"
  1944. * when we loaded driver, and is now set to "enable".
  1945. * After we're Alive, RF_KILL gets handled by
  1946. * iwl4965_rx_card_state_notif() */
  1947. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  1948. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1949. queue_work(priv->workqueue, &priv->restart);
  1950. }
  1951. handled |= CSR_INT_BIT_RF_KILL;
  1952. }
  1953. /* Chip got too hot and stopped itself */
  1954. if (inta & CSR_INT_BIT_CT_KILL) {
  1955. IWL_ERROR("Microcode CT kill error detected.\n");
  1956. handled |= CSR_INT_BIT_CT_KILL;
  1957. }
  1958. /* Error detected by uCode */
  1959. if (inta & CSR_INT_BIT_SW_ERR) {
  1960. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  1961. inta);
  1962. iwl4965_irq_handle_error(priv);
  1963. handled |= CSR_INT_BIT_SW_ERR;
  1964. }
  1965. /* uCode wakes up after power-down sleep */
  1966. if (inta & CSR_INT_BIT_WAKEUP) {
  1967. IWL_DEBUG_ISR("Wakeup interrupt\n");
  1968. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1969. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1970. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1971. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1972. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1973. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1974. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1975. handled |= CSR_INT_BIT_WAKEUP;
  1976. }
  1977. /* All uCode command responses, including Tx command responses,
  1978. * Rx "responses" (frame-received notification), and other
  1979. * notifications from uCode come through here*/
  1980. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1981. iwl_rx_handle(priv);
  1982. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1983. }
  1984. if (inta & CSR_INT_BIT_FH_TX) {
  1985. IWL_DEBUG_ISR("Tx interrupt\n");
  1986. handled |= CSR_INT_BIT_FH_TX;
  1987. /* FH finished to write, send event */
  1988. priv->ucode_write_complete = 1;
  1989. wake_up_interruptible(&priv->wait_command_queue);
  1990. }
  1991. if (inta & ~handled)
  1992. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1993. if (inta & ~CSR_INI_SET_MASK) {
  1994. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  1995. inta & ~CSR_INI_SET_MASK);
  1996. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  1997. }
  1998. /* Re-enable all interrupts */
  1999. /* only Re-enable if diabled by irq */
  2000. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2001. iwl4965_enable_interrupts(priv);
  2002. #ifdef CONFIG_IWLWIFI_DEBUG
  2003. if (priv->debug_level & (IWL_DL_ISR)) {
  2004. inta = iwl_read32(priv, CSR_INT);
  2005. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2006. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2007. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  2008. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  2009. }
  2010. #endif
  2011. spin_unlock_irqrestore(&priv->lock, flags);
  2012. }
  2013. static irqreturn_t iwl4965_isr(int irq, void *data)
  2014. {
  2015. struct iwl_priv *priv = data;
  2016. u32 inta, inta_mask;
  2017. u32 inta_fh;
  2018. if (!priv)
  2019. return IRQ_NONE;
  2020. spin_lock(&priv->lock);
  2021. /* Disable (but don't clear!) interrupts here to avoid
  2022. * back-to-back ISRs and sporadic interrupts from our NIC.
  2023. * If we have something to service, the tasklet will re-enable ints.
  2024. * If we *don't* have something, we'll re-enable before leaving here. */
  2025. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2026. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2027. /* Discover which interrupts are active/pending */
  2028. inta = iwl_read32(priv, CSR_INT);
  2029. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2030. /* Ignore interrupt if there's nothing in NIC to service.
  2031. * This may be due to IRQ shared with another device,
  2032. * or due to sporadic interrupts thrown from our NIC. */
  2033. if (!inta && !inta_fh) {
  2034. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  2035. goto none;
  2036. }
  2037. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2038. /* Hardware disappeared. It might have already raised
  2039. * an interrupt */
  2040. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  2041. goto unplugged;
  2042. }
  2043. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2044. inta, inta_mask, inta_fh);
  2045. inta &= ~CSR_INT_BIT_SCD;
  2046. /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
  2047. if (likely(inta || inta_fh))
  2048. tasklet_schedule(&priv->irq_tasklet);
  2049. unplugged:
  2050. spin_unlock(&priv->lock);
  2051. return IRQ_HANDLED;
  2052. none:
  2053. /* re-enable interrupts here since we don't have anything to service. */
  2054. /* only Re-enable if diabled by irq */
  2055. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2056. iwl4965_enable_interrupts(priv);
  2057. spin_unlock(&priv->lock);
  2058. return IRQ_NONE;
  2059. }
  2060. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  2061. * sending probe req. This should be set long enough to hear probe responses
  2062. * from more than one AP. */
  2063. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  2064. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  2065. /* For faster active scanning, scan will move to the next channel if fewer than
  2066. * PLCP_QUIET_THRESH packets are heard on this channel within
  2067. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  2068. * time if it's a quiet channel (nothing responded to our probe, and there's
  2069. * no other traffic).
  2070. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  2071. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  2072. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  2073. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  2074. * Must be set longer than active dwell time.
  2075. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  2076. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  2077. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  2078. #define IWL_PASSIVE_DWELL_BASE (100)
  2079. #define IWL_CHANNEL_TUNE_TIME 5
  2080. static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
  2081. enum ieee80211_band band)
  2082. {
  2083. if (band == IEEE80211_BAND_5GHZ)
  2084. return IWL_ACTIVE_DWELL_TIME_52;
  2085. else
  2086. return IWL_ACTIVE_DWELL_TIME_24;
  2087. }
  2088. static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
  2089. enum ieee80211_band band)
  2090. {
  2091. u16 active = iwl4965_get_active_dwell_time(priv, band);
  2092. u16 passive = (band != IEEE80211_BAND_5GHZ) ?
  2093. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  2094. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  2095. if (iwl_is_associated(priv)) {
  2096. /* If we're associated, we clamp the maximum passive
  2097. * dwell time to be 98% of the beacon interval (minus
  2098. * 2 * channel tune time) */
  2099. passive = priv->beacon_int;
  2100. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  2101. passive = IWL_PASSIVE_DWELL_BASE;
  2102. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  2103. }
  2104. if (passive <= active)
  2105. passive = active + 1;
  2106. return passive;
  2107. }
  2108. static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
  2109. enum ieee80211_band band,
  2110. u8 is_active, u8 direct_mask,
  2111. struct iwl4965_scan_channel *scan_ch)
  2112. {
  2113. const struct ieee80211_channel *channels = NULL;
  2114. const struct ieee80211_supported_band *sband;
  2115. const struct iwl_channel_info *ch_info;
  2116. u16 passive_dwell = 0;
  2117. u16 active_dwell = 0;
  2118. int added, i;
  2119. sband = iwl_get_hw_mode(priv, band);
  2120. if (!sband)
  2121. return 0;
  2122. channels = sband->channels;
  2123. active_dwell = iwl4965_get_active_dwell_time(priv, band);
  2124. passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
  2125. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2126. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2127. continue;
  2128. scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
  2129. ch_info = iwl_get_channel_info(priv, band,
  2130. scan_ch->channel);
  2131. if (!is_channel_valid(ch_info)) {
  2132. IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
  2133. scan_ch->channel);
  2134. continue;
  2135. }
  2136. if (!is_active || is_channel_passive(ch_info) ||
  2137. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
  2138. scan_ch->type = 0; /* passive */
  2139. else
  2140. scan_ch->type = 1; /* active */
  2141. if (scan_ch->type & 1)
  2142. scan_ch->type |= (direct_mask << 1);
  2143. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2144. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2145. /* Set txpower levels to defaults */
  2146. scan_ch->tpc.dsp_atten = 110;
  2147. /* scan_pwr_info->tpc.dsp_atten; */
  2148. /*scan_pwr_info->tpc.tx_gain; */
  2149. if (band == IEEE80211_BAND_5GHZ)
  2150. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2151. else {
  2152. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2153. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2154. * power level:
  2155. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2156. */
  2157. }
  2158. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  2159. scan_ch->channel,
  2160. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2161. (scan_ch->type & 1) ?
  2162. active_dwell : passive_dwell);
  2163. scan_ch++;
  2164. added++;
  2165. }
  2166. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  2167. return added;
  2168. }
  2169. /******************************************************************************
  2170. *
  2171. * uCode download functions
  2172. *
  2173. ******************************************************************************/
  2174. static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
  2175. {
  2176. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2177. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2178. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2179. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2180. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2181. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2182. }
  2183. static void iwl4965_nic_start(struct iwl_priv *priv)
  2184. {
  2185. /* Remove all resets to allow NIC to operate */
  2186. iwl_write32(priv, CSR_RESET, 0);
  2187. }
  2188. /**
  2189. * iwl4965_read_ucode - Read uCode images from disk file.
  2190. *
  2191. * Copy into buffers for card to fetch via bus-mastering
  2192. */
  2193. static int iwl4965_read_ucode(struct iwl_priv *priv)
  2194. {
  2195. struct iwl4965_ucode *ucode;
  2196. int ret;
  2197. const struct firmware *ucode_raw;
  2198. const char *name = priv->cfg->fw_name;
  2199. u8 *src;
  2200. size_t len;
  2201. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2202. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2203. * request_firmware() is synchronous, file is in memory on return. */
  2204. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  2205. if (ret < 0) {
  2206. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  2207. name, ret);
  2208. goto error;
  2209. }
  2210. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  2211. name, ucode_raw->size);
  2212. /* Make sure that we got at least our header! */
  2213. if (ucode_raw->size < sizeof(*ucode)) {
  2214. IWL_ERROR("File size way too small!\n");
  2215. ret = -EINVAL;
  2216. goto err_release;
  2217. }
  2218. /* Data from ucode file: header followed by uCode images */
  2219. ucode = (void *)ucode_raw->data;
  2220. ver = le32_to_cpu(ucode->ver);
  2221. inst_size = le32_to_cpu(ucode->inst_size);
  2222. data_size = le32_to_cpu(ucode->data_size);
  2223. init_size = le32_to_cpu(ucode->init_size);
  2224. init_data_size = le32_to_cpu(ucode->init_data_size);
  2225. boot_size = le32_to_cpu(ucode->boot_size);
  2226. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  2227. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
  2228. inst_size);
  2229. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
  2230. data_size);
  2231. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
  2232. init_size);
  2233. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
  2234. init_data_size);
  2235. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
  2236. boot_size);
  2237. /* Verify size of file vs. image size info in file's header */
  2238. if (ucode_raw->size < sizeof(*ucode) +
  2239. inst_size + data_size + init_size +
  2240. init_data_size + boot_size) {
  2241. IWL_DEBUG_INFO("uCode file size %d too small\n",
  2242. (int)ucode_raw->size);
  2243. ret = -EINVAL;
  2244. goto err_release;
  2245. }
  2246. /* Verify that uCode images will fit in card's SRAM */
  2247. if (inst_size > priv->hw_params.max_inst_size) {
  2248. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  2249. inst_size);
  2250. ret = -EINVAL;
  2251. goto err_release;
  2252. }
  2253. if (data_size > priv->hw_params.max_data_size) {
  2254. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  2255. data_size);
  2256. ret = -EINVAL;
  2257. goto err_release;
  2258. }
  2259. if (init_size > priv->hw_params.max_inst_size) {
  2260. IWL_DEBUG_INFO
  2261. ("uCode init instr len %d too large to fit in\n",
  2262. init_size);
  2263. ret = -EINVAL;
  2264. goto err_release;
  2265. }
  2266. if (init_data_size > priv->hw_params.max_data_size) {
  2267. IWL_DEBUG_INFO
  2268. ("uCode init data len %d too large to fit in\n",
  2269. init_data_size);
  2270. ret = -EINVAL;
  2271. goto err_release;
  2272. }
  2273. if (boot_size > priv->hw_params.max_bsm_size) {
  2274. IWL_DEBUG_INFO
  2275. ("uCode boot instr len %d too large to fit in\n",
  2276. boot_size);
  2277. ret = -EINVAL;
  2278. goto err_release;
  2279. }
  2280. /* Allocate ucode buffers for card's bus-master loading ... */
  2281. /* Runtime instructions and 2 copies of data:
  2282. * 1) unmodified from disk
  2283. * 2) backup cache for save/restore during power-downs */
  2284. priv->ucode_code.len = inst_size;
  2285. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  2286. priv->ucode_data.len = data_size;
  2287. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  2288. priv->ucode_data_backup.len = data_size;
  2289. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2290. /* Initialization instructions and data */
  2291. if (init_size && init_data_size) {
  2292. priv->ucode_init.len = init_size;
  2293. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  2294. priv->ucode_init_data.len = init_data_size;
  2295. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2296. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  2297. goto err_pci_alloc;
  2298. }
  2299. /* Bootstrap (instructions only, no data) */
  2300. if (boot_size) {
  2301. priv->ucode_boot.len = boot_size;
  2302. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2303. if (!priv->ucode_boot.v_addr)
  2304. goto err_pci_alloc;
  2305. }
  2306. /* Copy images into buffers for card's bus-master reads ... */
  2307. /* Runtime instructions (first block of data in file) */
  2308. src = &ucode->data[0];
  2309. len = priv->ucode_code.len;
  2310. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  2311. memcpy(priv->ucode_code.v_addr, src, len);
  2312. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  2313. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  2314. /* Runtime data (2nd block)
  2315. * NOTE: Copy into backup buffer will be done in iwl4965_up() */
  2316. src = &ucode->data[inst_size];
  2317. len = priv->ucode_data.len;
  2318. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  2319. memcpy(priv->ucode_data.v_addr, src, len);
  2320. memcpy(priv->ucode_data_backup.v_addr, src, len);
  2321. /* Initialization instructions (3rd block) */
  2322. if (init_size) {
  2323. src = &ucode->data[inst_size + data_size];
  2324. len = priv->ucode_init.len;
  2325. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  2326. len);
  2327. memcpy(priv->ucode_init.v_addr, src, len);
  2328. }
  2329. /* Initialization data (4th block) */
  2330. if (init_data_size) {
  2331. src = &ucode->data[inst_size + data_size + init_size];
  2332. len = priv->ucode_init_data.len;
  2333. IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
  2334. len);
  2335. memcpy(priv->ucode_init_data.v_addr, src, len);
  2336. }
  2337. /* Bootstrap instructions (5th block) */
  2338. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  2339. len = priv->ucode_boot.len;
  2340. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
  2341. memcpy(priv->ucode_boot.v_addr, src, len);
  2342. /* We have our copies now, allow OS release its copies */
  2343. release_firmware(ucode_raw);
  2344. return 0;
  2345. err_pci_alloc:
  2346. IWL_ERROR("failed to allocate pci memory\n");
  2347. ret = -ENOMEM;
  2348. iwl4965_dealloc_ucode_pci(priv);
  2349. err_release:
  2350. release_firmware(ucode_raw);
  2351. error:
  2352. return ret;
  2353. }
  2354. /**
  2355. * iwl_alive_start - called after REPLY_ALIVE notification received
  2356. * from protocol/runtime uCode (initialization uCode's
  2357. * Alive gets handled by iwl_init_alive_start()).
  2358. */
  2359. static void iwl_alive_start(struct iwl_priv *priv)
  2360. {
  2361. int ret = 0;
  2362. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2363. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2364. /* We had an error bringing up the hardware, so take it
  2365. * all the way back down so we can try again */
  2366. IWL_DEBUG_INFO("Alive failed.\n");
  2367. goto restart;
  2368. }
  2369. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2370. * This is a paranoid check, because we would not have gotten the
  2371. * "runtime" alive if code weren't properly loaded. */
  2372. if (iwl_verify_ucode(priv)) {
  2373. /* Runtime instruction load was bad;
  2374. * take it all the way back down so we can try again */
  2375. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  2376. goto restart;
  2377. }
  2378. iwlcore_clear_stations_table(priv);
  2379. ret = priv->cfg->ops->lib->alive_notify(priv);
  2380. if (ret) {
  2381. IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
  2382. ret);
  2383. goto restart;
  2384. }
  2385. /* After the ALIVE response, we can send host commands to 4965 uCode */
  2386. set_bit(STATUS_ALIVE, &priv->status);
  2387. if (iwl_is_rfkill(priv))
  2388. return;
  2389. ieee80211_wake_queues(priv->hw);
  2390. priv->active_rate = priv->rates_mask;
  2391. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  2392. if (iwl_is_associated(priv)) {
  2393. struct iwl_rxon_cmd *active_rxon =
  2394. (struct iwl_rxon_cmd *)&priv->active_rxon;
  2395. memcpy(&priv->staging_rxon, &priv->active_rxon,
  2396. sizeof(priv->staging_rxon));
  2397. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2398. } else {
  2399. /* Initialize our rx_config data */
  2400. iwl4965_connection_init_rx_config(priv);
  2401. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2402. }
  2403. /* Configure Bluetooth device coexistence support */
  2404. iwl4965_send_bt_config(priv);
  2405. iwl_reset_run_time_calib(priv);
  2406. /* Configure the adapter for unassociated operation */
  2407. iwl4965_commit_rxon(priv);
  2408. /* At this point, the NIC is initialized and operational */
  2409. iwl4965_rf_kill_ct_config(priv);
  2410. iwl_leds_register(priv);
  2411. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  2412. set_bit(STATUS_READY, &priv->status);
  2413. wake_up_interruptible(&priv->wait_command_queue);
  2414. if (priv->error_recovering)
  2415. iwl4965_error_recovery(priv);
  2416. iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
  2417. ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
  2418. if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
  2419. iwl4965_set_mode(priv, priv->iw_mode);
  2420. return;
  2421. restart:
  2422. queue_work(priv->workqueue, &priv->restart);
  2423. }
  2424. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  2425. static void __iwl4965_down(struct iwl_priv *priv)
  2426. {
  2427. unsigned long flags;
  2428. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2429. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  2430. if (!exit_pending)
  2431. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2432. iwl_leds_unregister(priv);
  2433. iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
  2434. iwlcore_clear_stations_table(priv);
  2435. /* Unblock any waiting calls */
  2436. wake_up_interruptible_all(&priv->wait_command_queue);
  2437. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2438. * exiting the module */
  2439. if (!exit_pending)
  2440. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2441. /* stop and reset the on-board processor */
  2442. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2443. /* tell the device to stop sending interrupts */
  2444. spin_lock_irqsave(&priv->lock, flags);
  2445. iwl4965_disable_interrupts(priv);
  2446. spin_unlock_irqrestore(&priv->lock, flags);
  2447. iwl_synchronize_irq(priv);
  2448. if (priv->mac80211_registered)
  2449. ieee80211_stop_queues(priv->hw);
  2450. /* If we have not previously called iwl4965_init() then
  2451. * clear all bits but the RF Kill and SUSPEND bits and return */
  2452. if (!iwl_is_init(priv)) {
  2453. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2454. STATUS_RF_KILL_HW |
  2455. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2456. STATUS_RF_KILL_SW |
  2457. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2458. STATUS_GEO_CONFIGURED |
  2459. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2460. STATUS_IN_SUSPEND;
  2461. goto exit;
  2462. }
  2463. /* ...otherwise clear out all the status bits but the RF Kill and
  2464. * SUSPEND bits and continue taking the NIC down. */
  2465. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2466. STATUS_RF_KILL_HW |
  2467. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2468. STATUS_RF_KILL_SW |
  2469. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2470. STATUS_GEO_CONFIGURED |
  2471. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2472. STATUS_IN_SUSPEND |
  2473. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2474. STATUS_FW_ERROR;
  2475. spin_lock_irqsave(&priv->lock, flags);
  2476. iwl_clear_bit(priv, CSR_GP_CNTRL,
  2477. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2478. spin_unlock_irqrestore(&priv->lock, flags);
  2479. iwl_txq_ctx_stop(priv);
  2480. iwl_rxq_stop(priv);
  2481. spin_lock_irqsave(&priv->lock, flags);
  2482. if (!iwl_grab_nic_access(priv)) {
  2483. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  2484. APMG_CLK_VAL_DMA_CLK_RQT);
  2485. iwl_release_nic_access(priv);
  2486. }
  2487. spin_unlock_irqrestore(&priv->lock, flags);
  2488. udelay(5);
  2489. /* FIXME: apm_ops.suspend(priv) */
  2490. priv->cfg->ops->lib->apm_ops.reset(priv);
  2491. priv->cfg->ops->lib->free_shared_mem(priv);
  2492. exit:
  2493. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2494. if (priv->ibss_beacon)
  2495. dev_kfree_skb(priv->ibss_beacon);
  2496. priv->ibss_beacon = NULL;
  2497. /* clear out any free frames */
  2498. iwl_clear_free_frames(priv);
  2499. }
  2500. static void iwl4965_down(struct iwl_priv *priv)
  2501. {
  2502. mutex_lock(&priv->mutex);
  2503. __iwl4965_down(priv);
  2504. mutex_unlock(&priv->mutex);
  2505. iwl_cancel_deferred_work(priv);
  2506. }
  2507. #define MAX_HW_RESTARTS 5
  2508. static int __iwl4965_up(struct iwl_priv *priv)
  2509. {
  2510. int i;
  2511. int ret;
  2512. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2513. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  2514. return -EIO;
  2515. }
  2516. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2517. IWL_ERROR("ucode not available for device bringup\n");
  2518. return -EIO;
  2519. }
  2520. /* If platform's RF_KILL switch is NOT set to KILL */
  2521. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2522. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2523. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2524. else {
  2525. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2526. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2527. iwl_rfkill_set_hw_state(priv);
  2528. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  2529. return -ENODEV;
  2530. }
  2531. }
  2532. iwl_rfkill_set_hw_state(priv);
  2533. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2534. ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
  2535. if (ret) {
  2536. IWL_ERROR("Unable to allocate shared memory\n");
  2537. return ret;
  2538. }
  2539. ret = iwl_hw_nic_init(priv);
  2540. if (ret) {
  2541. IWL_ERROR("Unable to init nic\n");
  2542. return ret;
  2543. }
  2544. /* make sure rfkill handshake bits are cleared */
  2545. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2546. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2547. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2548. /* clear (again), then enable host interrupts */
  2549. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2550. iwl4965_enable_interrupts(priv);
  2551. /* really make sure rfkill handshake bits are cleared */
  2552. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2553. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2554. /* Copy original ucode data image from disk into backup cache.
  2555. * This will be used to initialize the on-board processor's
  2556. * data SRAM for a clean start when the runtime program first loads. */
  2557. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2558. priv->ucode_data.len);
  2559. /* We return success when we resume from suspend and rf_kill is on. */
  2560. if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
  2561. test_bit(STATUS_RF_KILL_SW, &priv->status))
  2562. return 0;
  2563. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2564. iwlcore_clear_stations_table(priv);
  2565. /* load bootstrap state machine,
  2566. * load bootstrap program into processor's memory,
  2567. * prepare to load the "initialize" uCode */
  2568. ret = priv->cfg->ops->lib->load_ucode(priv);
  2569. if (ret) {
  2570. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
  2571. continue;
  2572. }
  2573. /* Clear out the uCode error bit if it is set */
  2574. clear_bit(STATUS_FW_ERROR, &priv->status);
  2575. /* start card; "initialize" will load runtime ucode */
  2576. iwl4965_nic_start(priv);
  2577. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  2578. return 0;
  2579. }
  2580. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2581. __iwl4965_down(priv);
  2582. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2583. /* tried to restart and config the device for as long as our
  2584. * patience could withstand */
  2585. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  2586. return -EIO;
  2587. }
  2588. /*****************************************************************************
  2589. *
  2590. * Workqueue callbacks
  2591. *
  2592. *****************************************************************************/
  2593. static void iwl_bg_init_alive_start(struct work_struct *data)
  2594. {
  2595. struct iwl_priv *priv =
  2596. container_of(data, struct iwl_priv, init_alive_start.work);
  2597. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2598. return;
  2599. mutex_lock(&priv->mutex);
  2600. priv->cfg->ops->lib->init_alive_start(priv);
  2601. mutex_unlock(&priv->mutex);
  2602. }
  2603. static void iwl_bg_alive_start(struct work_struct *data)
  2604. {
  2605. struct iwl_priv *priv =
  2606. container_of(data, struct iwl_priv, alive_start.work);
  2607. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2608. return;
  2609. mutex_lock(&priv->mutex);
  2610. iwl_alive_start(priv);
  2611. mutex_unlock(&priv->mutex);
  2612. }
  2613. static void iwl4965_bg_rf_kill(struct work_struct *work)
  2614. {
  2615. struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
  2616. wake_up_interruptible(&priv->wait_command_queue);
  2617. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2618. return;
  2619. mutex_lock(&priv->mutex);
  2620. if (!iwl_is_rfkill(priv)) {
  2621. IWL_DEBUG(IWL_DL_RF_KILL,
  2622. "HW and/or SW RF Kill no longer active, restarting "
  2623. "device\n");
  2624. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2625. queue_work(priv->workqueue, &priv->restart);
  2626. } else {
  2627. /* make sure mac80211 stop sending Tx frame */
  2628. if (priv->mac80211_registered)
  2629. ieee80211_stop_queues(priv->hw);
  2630. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  2631. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2632. "disabled by SW switch\n");
  2633. else
  2634. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  2635. "Kill switch must be turned off for "
  2636. "wireless networking to work.\n");
  2637. }
  2638. iwl_rfkill_set_hw_state(priv);
  2639. mutex_unlock(&priv->mutex);
  2640. }
  2641. static void iwl4965_bg_set_monitor(struct work_struct *work)
  2642. {
  2643. struct iwl_priv *priv = container_of(work,
  2644. struct iwl_priv, set_monitor);
  2645. int ret;
  2646. IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
  2647. mutex_lock(&priv->mutex);
  2648. ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
  2649. if (ret) {
  2650. if (ret == -EAGAIN)
  2651. IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
  2652. else
  2653. IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
  2654. }
  2655. mutex_unlock(&priv->mutex);
  2656. }
  2657. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  2658. static void iwl4965_bg_scan_check(struct work_struct *data)
  2659. {
  2660. struct iwl_priv *priv =
  2661. container_of(data, struct iwl_priv, scan_check.work);
  2662. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2663. return;
  2664. mutex_lock(&priv->mutex);
  2665. if (test_bit(STATUS_SCANNING, &priv->status) ||
  2666. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2667. IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting "
  2668. "adapter (%dms)\n",
  2669. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  2670. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2671. iwl4965_send_scan_abort(priv);
  2672. }
  2673. mutex_unlock(&priv->mutex);
  2674. }
  2675. static void iwl4965_bg_request_scan(struct work_struct *data)
  2676. {
  2677. struct iwl_priv *priv =
  2678. container_of(data, struct iwl_priv, request_scan);
  2679. struct iwl_host_cmd cmd = {
  2680. .id = REPLY_SCAN_CMD,
  2681. .len = sizeof(struct iwl4965_scan_cmd),
  2682. .meta.flags = CMD_SIZE_HUGE,
  2683. };
  2684. struct iwl4965_scan_cmd *scan;
  2685. struct ieee80211_conf *conf = NULL;
  2686. u16 cmd_len;
  2687. enum ieee80211_band band;
  2688. u8 direct_mask;
  2689. int ret = 0;
  2690. conf = ieee80211_get_hw_conf(priv->hw);
  2691. mutex_lock(&priv->mutex);
  2692. if (!iwl_is_ready(priv)) {
  2693. IWL_WARNING("request scan called when driver not ready.\n");
  2694. goto done;
  2695. }
  2696. /* Make sure the scan wasn't cancelled before this queued work
  2697. * was given the chance to run... */
  2698. if (!test_bit(STATUS_SCANNING, &priv->status))
  2699. goto done;
  2700. /* This should never be called or scheduled if there is currently
  2701. * a scan active in the hardware. */
  2702. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2703. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  2704. "Ignoring second request.\n");
  2705. ret = -EIO;
  2706. goto done;
  2707. }
  2708. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2709. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  2710. goto done;
  2711. }
  2712. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2713. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  2714. goto done;
  2715. }
  2716. if (iwl_is_rfkill(priv)) {
  2717. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  2718. goto done;
  2719. }
  2720. if (!test_bit(STATUS_READY, &priv->status)) {
  2721. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  2722. goto done;
  2723. }
  2724. if (!priv->scan_bands) {
  2725. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  2726. goto done;
  2727. }
  2728. if (!priv->scan) {
  2729. priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
  2730. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2731. if (!priv->scan) {
  2732. ret = -ENOMEM;
  2733. goto done;
  2734. }
  2735. }
  2736. scan = priv->scan;
  2737. memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2738. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2739. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2740. if (iwl_is_associated(priv)) {
  2741. u16 interval = 0;
  2742. u32 extra;
  2743. u32 suspend_time = 100;
  2744. u32 scan_suspend_time = 100;
  2745. unsigned long flags;
  2746. IWL_DEBUG_INFO("Scanning while associated...\n");
  2747. spin_lock_irqsave(&priv->lock, flags);
  2748. interval = priv->beacon_int;
  2749. spin_unlock_irqrestore(&priv->lock, flags);
  2750. scan->suspend_time = 0;
  2751. scan->max_out_time = cpu_to_le32(200 * 1024);
  2752. if (!interval)
  2753. interval = suspend_time;
  2754. extra = (suspend_time / interval) << 22;
  2755. scan_suspend_time = (extra |
  2756. ((suspend_time % interval) * 1024));
  2757. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2758. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  2759. scan_suspend_time, interval);
  2760. }
  2761. /* We should add the ability for user to lock to PASSIVE ONLY */
  2762. if (priv->one_direct_scan) {
  2763. IWL_DEBUG_SCAN
  2764. ("Kicking off one direct scan for '%s'\n",
  2765. iwl4965_escape_essid(priv->direct_ssid,
  2766. priv->direct_ssid_len));
  2767. scan->direct_scan[0].id = WLAN_EID_SSID;
  2768. scan->direct_scan[0].len = priv->direct_ssid_len;
  2769. memcpy(scan->direct_scan[0].ssid,
  2770. priv->direct_ssid, priv->direct_ssid_len);
  2771. direct_mask = 1;
  2772. } else if (!iwl_is_associated(priv) && priv->essid_len) {
  2773. IWL_DEBUG_SCAN
  2774. ("Kicking off one direct scan for '%s' when not associated\n",
  2775. iwl4965_escape_essid(priv->essid, priv->essid_len));
  2776. scan->direct_scan[0].id = WLAN_EID_SSID;
  2777. scan->direct_scan[0].len = priv->essid_len;
  2778. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  2779. direct_mask = 1;
  2780. } else {
  2781. IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
  2782. direct_mask = 0;
  2783. }
  2784. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2785. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  2786. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2787. switch (priv->scan_bands) {
  2788. case 2:
  2789. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  2790. scan->tx_cmd.rate_n_flags =
  2791. iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
  2792. RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
  2793. scan->good_CRC_th = 0;
  2794. band = IEEE80211_BAND_2GHZ;
  2795. break;
  2796. case 1:
  2797. scan->tx_cmd.rate_n_flags =
  2798. iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
  2799. RATE_MCS_ANT_B_MSK);
  2800. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  2801. band = IEEE80211_BAND_5GHZ;
  2802. break;
  2803. default:
  2804. IWL_WARNING("Invalid scan band count\n");
  2805. goto done;
  2806. }
  2807. /* We don't build a direct scan probe request; the uCode will do
  2808. * that based on the direct_mask added to each channel entry */
  2809. cmd_len = iwl4965_fill_probe_req(priv, band,
  2810. (struct ieee80211_mgmt *)scan->data,
  2811. IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
  2812. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  2813. /* select Rx chains */
  2814. /* Force use of chains B and C (0x6) for scan Rx.
  2815. * Avoid A (0x1) because of its off-channel reception on A-band.
  2816. * MIMO is not used here, but value is required to make uCode happy. */
  2817. scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
  2818. cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
  2819. (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
  2820. (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
  2821. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  2822. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  2823. if (direct_mask)
  2824. scan->channel_count =
  2825. iwl4965_get_channels_for_scan(
  2826. priv, band, 1, /* active */
  2827. direct_mask,
  2828. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  2829. else
  2830. scan->channel_count =
  2831. iwl4965_get_channels_for_scan(
  2832. priv, band, 0, /* passive */
  2833. direct_mask,
  2834. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  2835. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  2836. RXON_FILTER_BCON_AWARE_MSK);
  2837. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  2838. scan->channel_count * sizeof(struct iwl4965_scan_channel);
  2839. cmd.data = scan;
  2840. scan->len = cpu_to_le16(cmd.len);
  2841. set_bit(STATUS_SCAN_HW, &priv->status);
  2842. ret = iwl_send_cmd_sync(priv, &cmd);
  2843. if (ret)
  2844. goto done;
  2845. queue_delayed_work(priv->workqueue, &priv->scan_check,
  2846. IWL_SCAN_CHECK_WATCHDOG);
  2847. mutex_unlock(&priv->mutex);
  2848. return;
  2849. done:
  2850. /* inform mac80211 scan aborted */
  2851. queue_work(priv->workqueue, &priv->scan_completed);
  2852. mutex_unlock(&priv->mutex);
  2853. }
  2854. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  2855. {
  2856. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2857. run_time_calib_work);
  2858. mutex_lock(&priv->mutex);
  2859. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2860. test_bit(STATUS_SCANNING, &priv->status)) {
  2861. mutex_unlock(&priv->mutex);
  2862. return;
  2863. }
  2864. if (priv->start_calib) {
  2865. iwl_chain_noise_calibration(priv, &priv->statistics);
  2866. iwl_sensitivity_calibration(priv, &priv->statistics);
  2867. }
  2868. mutex_unlock(&priv->mutex);
  2869. return;
  2870. }
  2871. static void iwl4965_bg_up(struct work_struct *data)
  2872. {
  2873. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  2874. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2875. return;
  2876. mutex_lock(&priv->mutex);
  2877. __iwl4965_up(priv);
  2878. mutex_unlock(&priv->mutex);
  2879. }
  2880. static void iwl4965_bg_restart(struct work_struct *data)
  2881. {
  2882. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2883. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2884. return;
  2885. iwl4965_down(priv);
  2886. queue_work(priv->workqueue, &priv->up);
  2887. }
  2888. static void iwl4965_bg_rx_replenish(struct work_struct *data)
  2889. {
  2890. struct iwl_priv *priv =
  2891. container_of(data, struct iwl_priv, rx_replenish);
  2892. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2893. return;
  2894. mutex_lock(&priv->mutex);
  2895. iwl_rx_replenish(priv);
  2896. mutex_unlock(&priv->mutex);
  2897. }
  2898. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  2899. static void iwl4965_post_associate(struct iwl_priv *priv)
  2900. {
  2901. struct ieee80211_conf *conf = NULL;
  2902. int ret = 0;
  2903. DECLARE_MAC_BUF(mac);
  2904. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  2905. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  2906. return;
  2907. }
  2908. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  2909. priv->assoc_id,
  2910. print_mac(mac, priv->active_rxon.bssid_addr));
  2911. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2912. return;
  2913. if (!priv->vif || !priv->is_open)
  2914. return;
  2915. iwl4965_scan_cancel_timeout(priv, 200);
  2916. conf = ieee80211_get_hw_conf(priv->hw);
  2917. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2918. iwl4965_commit_rxon(priv);
  2919. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  2920. iwl4965_setup_rxon_timing(priv);
  2921. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  2922. sizeof(priv->rxon_timing), &priv->rxon_timing);
  2923. if (ret)
  2924. IWL_WARNING("REPLY_RXON_TIMING failed - "
  2925. "Attempting to continue.\n");
  2926. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2927. if (priv->current_ht_config.is_ht)
  2928. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  2929. iwl_set_rxon_chain(priv);
  2930. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  2931. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  2932. priv->assoc_id, priv->beacon_int);
  2933. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2934. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2935. else
  2936. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2937. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2938. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2939. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2940. else
  2941. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2942. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2943. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2944. }
  2945. iwl4965_commit_rxon(priv);
  2946. switch (priv->iw_mode) {
  2947. case IEEE80211_IF_TYPE_STA:
  2948. iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
  2949. break;
  2950. case IEEE80211_IF_TYPE_IBSS:
  2951. /* assume default assoc id */
  2952. priv->assoc_id = 1;
  2953. iwl_rxon_add_station(priv, priv->bssid, 0);
  2954. iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
  2955. iwl4965_send_beacon_cmd(priv);
  2956. break;
  2957. default:
  2958. IWL_ERROR("%s Should not be called in %d mode\n",
  2959. __FUNCTION__, priv->iw_mode);
  2960. break;
  2961. }
  2962. iwl4965_sequence_reset(priv);
  2963. /* Enable Rx differential gain and sensitivity calibrations */
  2964. iwl_chain_noise_reset(priv);
  2965. priv->start_calib = 1;
  2966. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2967. priv->assoc_station_added = 1;
  2968. iwl4965_activate_qos(priv, 0);
  2969. iwl_power_update_mode(priv, 0);
  2970. /* we have just associated, don't start scan too early */
  2971. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  2972. }
  2973. static void iwl4965_bg_post_associate(struct work_struct *data)
  2974. {
  2975. struct iwl_priv *priv = container_of(data, struct iwl_priv,
  2976. post_associate.work);
  2977. mutex_lock(&priv->mutex);
  2978. iwl4965_post_associate(priv);
  2979. mutex_unlock(&priv->mutex);
  2980. }
  2981. static void iwl4965_bg_abort_scan(struct work_struct *work)
  2982. {
  2983. struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
  2984. if (!iwl_is_ready(priv))
  2985. return;
  2986. mutex_lock(&priv->mutex);
  2987. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  2988. iwl4965_send_scan_abort(priv);
  2989. mutex_unlock(&priv->mutex);
  2990. }
  2991. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  2992. static void iwl4965_bg_scan_completed(struct work_struct *work)
  2993. {
  2994. struct iwl_priv *priv =
  2995. container_of(work, struct iwl_priv, scan_completed);
  2996. IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n");
  2997. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2998. return;
  2999. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  3000. iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  3001. ieee80211_scan_completed(priv->hw);
  3002. /* Since setting the TXPOWER may have been deferred while
  3003. * performing the scan, fire one off */
  3004. mutex_lock(&priv->mutex);
  3005. iwl4965_hw_reg_send_txpower(priv);
  3006. mutex_unlock(&priv->mutex);
  3007. }
  3008. /*****************************************************************************
  3009. *
  3010. * mac80211 entry point functions
  3011. *
  3012. *****************************************************************************/
  3013. #define UCODE_READY_TIMEOUT (2 * HZ)
  3014. static int iwl4965_mac_start(struct ieee80211_hw *hw)
  3015. {
  3016. struct iwl_priv *priv = hw->priv;
  3017. int ret;
  3018. IWL_DEBUG_MAC80211("enter\n");
  3019. if (pci_enable_device(priv->pci_dev)) {
  3020. IWL_ERROR("Fail to pci_enable_device\n");
  3021. return -ENODEV;
  3022. }
  3023. pci_restore_state(priv->pci_dev);
  3024. pci_enable_msi(priv->pci_dev);
  3025. ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
  3026. DRV_NAME, priv);
  3027. if (ret) {
  3028. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  3029. goto out_disable_msi;
  3030. }
  3031. /* we should be verifying the device is ready to be opened */
  3032. mutex_lock(&priv->mutex);
  3033. memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
  3034. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3035. * ucode filename and max sizes are card-specific. */
  3036. if (!priv->ucode_code.len) {
  3037. ret = iwl4965_read_ucode(priv);
  3038. if (ret) {
  3039. IWL_ERROR("Could not read microcode: %d\n", ret);
  3040. mutex_unlock(&priv->mutex);
  3041. goto out_release_irq;
  3042. }
  3043. }
  3044. ret = __iwl4965_up(priv);
  3045. mutex_unlock(&priv->mutex);
  3046. if (ret)
  3047. goto out_release_irq;
  3048. IWL_DEBUG_INFO("Start UP work done.\n");
  3049. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3050. return 0;
  3051. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  3052. * mac80211 will not be run successfully. */
  3053. if (priv->ucode_type == UCODE_RT) {
  3054. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3055. test_bit(STATUS_READY, &priv->status),
  3056. UCODE_READY_TIMEOUT);
  3057. if (!ret) {
  3058. if (!test_bit(STATUS_READY, &priv->status)) {
  3059. IWL_ERROR("START_ALIVE timeout after %dms.\n",
  3060. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3061. ret = -ETIMEDOUT;
  3062. goto out_release_irq;
  3063. }
  3064. }
  3065. priv->is_open = 1;
  3066. }
  3067. IWL_DEBUG_MAC80211("leave\n");
  3068. return 0;
  3069. out_release_irq:
  3070. free_irq(priv->pci_dev->irq, priv);
  3071. out_disable_msi:
  3072. pci_disable_msi(priv->pci_dev);
  3073. pci_disable_device(priv->pci_dev);
  3074. priv->is_open = 0;
  3075. IWL_DEBUG_MAC80211("leave - failed\n");
  3076. return ret;
  3077. }
  3078. static void iwl4965_mac_stop(struct ieee80211_hw *hw)
  3079. {
  3080. struct iwl_priv *priv = hw->priv;
  3081. IWL_DEBUG_MAC80211("enter\n");
  3082. if (!priv->is_open) {
  3083. IWL_DEBUG_MAC80211("leave - skip\n");
  3084. return;
  3085. }
  3086. priv->is_open = 0;
  3087. if (iwl_is_ready_rf(priv)) {
  3088. /* stop mac, cancel any scan request and clear
  3089. * RXON_FILTER_ASSOC_MSK BIT
  3090. */
  3091. mutex_lock(&priv->mutex);
  3092. iwl4965_scan_cancel_timeout(priv, 100);
  3093. cancel_delayed_work(&priv->post_associate);
  3094. mutex_unlock(&priv->mutex);
  3095. }
  3096. iwl4965_down(priv);
  3097. flush_workqueue(priv->workqueue);
  3098. free_irq(priv->pci_dev->irq, priv);
  3099. pci_disable_msi(priv->pci_dev);
  3100. pci_save_state(priv->pci_dev);
  3101. pci_disable_device(priv->pci_dev);
  3102. IWL_DEBUG_MAC80211("leave\n");
  3103. }
  3104. static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3105. {
  3106. struct iwl_priv *priv = hw->priv;
  3107. IWL_DEBUG_MAC80211("enter\n");
  3108. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  3109. IWL_DEBUG_MAC80211("leave - monitor\n");
  3110. return -1;
  3111. }
  3112. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3113. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3114. if (iwl_tx_skb(priv, skb))
  3115. dev_kfree_skb_any(skb);
  3116. IWL_DEBUG_MAC80211("leave\n");
  3117. return 0;
  3118. }
  3119. static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
  3120. struct ieee80211_if_init_conf *conf)
  3121. {
  3122. struct iwl_priv *priv = hw->priv;
  3123. unsigned long flags;
  3124. DECLARE_MAC_BUF(mac);
  3125. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  3126. if (priv->vif) {
  3127. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  3128. return -EOPNOTSUPP;
  3129. }
  3130. spin_lock_irqsave(&priv->lock, flags);
  3131. priv->vif = conf->vif;
  3132. spin_unlock_irqrestore(&priv->lock, flags);
  3133. mutex_lock(&priv->mutex);
  3134. if (conf->mac_addr) {
  3135. IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
  3136. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3137. }
  3138. if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
  3139. /* we are not ready, will run again when ready */
  3140. set_bit(STATUS_MODE_PENDING, &priv->status);
  3141. mutex_unlock(&priv->mutex);
  3142. IWL_DEBUG_MAC80211("leave\n");
  3143. return 0;
  3144. }
  3145. /**
  3146. * iwl4965_mac_config - mac80211 config callback
  3147. *
  3148. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3149. * be set inappropriately and the driver currently sets the hardware up to
  3150. * use it whenever needed.
  3151. */
  3152. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  3153. {
  3154. struct iwl_priv *priv = hw->priv;
  3155. const struct iwl_channel_info *ch_info;
  3156. unsigned long flags;
  3157. int ret = 0;
  3158. u16 channel;
  3159. mutex_lock(&priv->mutex);
  3160. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  3161. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  3162. if (priv->cfg->ops->lib->radio_kill_sw &&
  3163. priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled)) {
  3164. IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
  3165. mutex_unlock(&priv->mutex);
  3166. }
  3167. if (!iwl_is_ready(priv)) {
  3168. IWL_DEBUG_MAC80211("leave - not ready\n");
  3169. ret = -EIO;
  3170. goto out;
  3171. }
  3172. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  3173. test_bit(STATUS_SCANNING, &priv->status))) {
  3174. IWL_DEBUG_MAC80211("leave - scanning\n");
  3175. set_bit(STATUS_CONF_PENDING, &priv->status);
  3176. mutex_unlock(&priv->mutex);
  3177. return 0;
  3178. }
  3179. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  3180. ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
  3181. if (!is_channel_valid(ch_info)) {
  3182. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  3183. ret = -EINVAL;
  3184. goto out;
  3185. }
  3186. spin_lock_irqsave(&priv->lock, flags);
  3187. /* if we are switching from ht to 2.4 clear flags
  3188. * from any ht related info since 2.4 does not
  3189. * support ht */
  3190. if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
  3191. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3192. && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
  3193. #endif
  3194. )
  3195. priv->staging_rxon.flags = 0;
  3196. iwl_set_rxon_channel(priv, conf->channel->band, channel);
  3197. iwl_set_flags_for_band(priv, conf->channel->band);
  3198. /* The list of supported rates and rate mask can be different
  3199. * for each band; since the band may have changed, reset
  3200. * the rate mask to what mac80211 lists */
  3201. iwl4965_set_rate(priv);
  3202. spin_unlock_irqrestore(&priv->lock, flags);
  3203. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3204. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3205. iwl4965_hw_channel_switch(priv, conf->channel);
  3206. goto out;
  3207. }
  3208. #endif
  3209. if (!conf->radio_enabled) {
  3210. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  3211. goto out;
  3212. }
  3213. if (iwl_is_rfkill(priv)) {
  3214. IWL_DEBUG_MAC80211("leave - RF kill\n");
  3215. ret = -EIO;
  3216. goto out;
  3217. }
  3218. iwl4965_set_rate(priv);
  3219. if (memcmp(&priv->active_rxon,
  3220. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  3221. iwl4965_commit_rxon(priv);
  3222. else
  3223. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  3224. IWL_DEBUG_MAC80211("leave\n");
  3225. out:
  3226. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3227. mutex_unlock(&priv->mutex);
  3228. return ret;
  3229. }
  3230. static void iwl4965_config_ap(struct iwl_priv *priv)
  3231. {
  3232. int ret = 0;
  3233. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3234. return;
  3235. /* The following should be done only at AP bring up */
  3236. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  3237. /* RXON - unassoc (to set timing command) */
  3238. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3239. iwl4965_commit_rxon(priv);
  3240. /* RXON Timing */
  3241. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  3242. iwl4965_setup_rxon_timing(priv);
  3243. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3244. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3245. if (ret)
  3246. IWL_WARNING("REPLY_RXON_TIMING failed - "
  3247. "Attempting to continue.\n");
  3248. iwl_set_rxon_chain(priv);
  3249. /* FIXME: what should be the assoc_id for AP? */
  3250. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3251. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3252. priv->staging_rxon.flags |=
  3253. RXON_FLG_SHORT_PREAMBLE_MSK;
  3254. else
  3255. priv->staging_rxon.flags &=
  3256. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3257. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3258. if (priv->assoc_capability &
  3259. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3260. priv->staging_rxon.flags |=
  3261. RXON_FLG_SHORT_SLOT_MSK;
  3262. else
  3263. priv->staging_rxon.flags &=
  3264. ~RXON_FLG_SHORT_SLOT_MSK;
  3265. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  3266. priv->staging_rxon.flags &=
  3267. ~RXON_FLG_SHORT_SLOT_MSK;
  3268. }
  3269. /* restore RXON assoc */
  3270. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3271. iwl4965_commit_rxon(priv);
  3272. iwl4965_activate_qos(priv, 1);
  3273. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  3274. }
  3275. iwl4965_send_beacon_cmd(priv);
  3276. /* FIXME - we need to add code here to detect a totally new
  3277. * configuration, reset the AP, unassoc, rxon timing, assoc,
  3278. * clear sta table, add BCAST sta... */
  3279. }
  3280. static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
  3281. struct ieee80211_vif *vif,
  3282. struct ieee80211_if_conf *conf)
  3283. {
  3284. struct iwl_priv *priv = hw->priv;
  3285. DECLARE_MAC_BUF(mac);
  3286. unsigned long flags;
  3287. int rc;
  3288. if (conf == NULL)
  3289. return -EIO;
  3290. if (priv->vif != vif) {
  3291. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  3292. return 0;
  3293. }
  3294. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  3295. (!conf->beacon || !conf->ssid_len)) {
  3296. IWL_DEBUG_MAC80211
  3297. ("Leaving in AP mode because HostAPD is not ready.\n");
  3298. return 0;
  3299. }
  3300. if (!iwl_is_alive(priv))
  3301. return -EAGAIN;
  3302. mutex_lock(&priv->mutex);
  3303. if (conf->bssid)
  3304. IWL_DEBUG_MAC80211("bssid: %s\n",
  3305. print_mac(mac, conf->bssid));
  3306. /*
  3307. * very dubious code was here; the probe filtering flag is never set:
  3308. *
  3309. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  3310. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  3311. */
  3312. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  3313. if (!conf->bssid) {
  3314. conf->bssid = priv->mac_addr;
  3315. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  3316. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  3317. print_mac(mac, conf->bssid));
  3318. }
  3319. if (priv->ibss_beacon)
  3320. dev_kfree_skb(priv->ibss_beacon);
  3321. priv->ibss_beacon = conf->beacon;
  3322. }
  3323. if (iwl_is_rfkill(priv))
  3324. goto done;
  3325. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  3326. !is_multicast_ether_addr(conf->bssid)) {
  3327. /* If there is currently a HW scan going on in the background
  3328. * then we need to cancel it else the RXON below will fail. */
  3329. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  3330. IWL_WARNING("Aborted scan still in progress "
  3331. "after 100ms\n");
  3332. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  3333. mutex_unlock(&priv->mutex);
  3334. return -EAGAIN;
  3335. }
  3336. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  3337. /* TODO: Audit driver for usage of these members and see
  3338. * if mac80211 deprecates them (priv->bssid looks like it
  3339. * shouldn't be there, but I haven't scanned the IBSS code
  3340. * to verify) - jpk */
  3341. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  3342. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3343. iwl4965_config_ap(priv);
  3344. else {
  3345. rc = iwl4965_commit_rxon(priv);
  3346. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  3347. iwl_rxon_add_station(
  3348. priv, priv->active_rxon.bssid_addr, 1);
  3349. }
  3350. } else {
  3351. iwl4965_scan_cancel_timeout(priv, 100);
  3352. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3353. iwl4965_commit_rxon(priv);
  3354. }
  3355. done:
  3356. spin_lock_irqsave(&priv->lock, flags);
  3357. if (!conf->ssid_len)
  3358. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3359. else
  3360. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  3361. priv->essid_len = conf->ssid_len;
  3362. spin_unlock_irqrestore(&priv->lock, flags);
  3363. IWL_DEBUG_MAC80211("leave\n");
  3364. mutex_unlock(&priv->mutex);
  3365. return 0;
  3366. }
  3367. static void iwl4965_configure_filter(struct ieee80211_hw *hw,
  3368. unsigned int changed_flags,
  3369. unsigned int *total_flags,
  3370. int mc_count, struct dev_addr_list *mc_list)
  3371. {
  3372. /*
  3373. * XXX: dummy
  3374. * see also iwl4965_connection_init_rx_config
  3375. */
  3376. struct iwl_priv *priv = hw->priv;
  3377. int new_flags = 0;
  3378. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3379. if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3380. IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
  3381. IEEE80211_IF_TYPE_MNTR,
  3382. changed_flags, *total_flags);
  3383. /* queue work 'cuz mac80211 is holding a lock which
  3384. * prevents us from issuing (synchronous) f/w cmds */
  3385. queue_work(priv->workqueue, &priv->set_monitor);
  3386. new_flags &= FIF_PROMISC_IN_BSS |
  3387. FIF_OTHER_BSS |
  3388. FIF_ALLMULTI;
  3389. }
  3390. }
  3391. *total_flags = new_flags;
  3392. }
  3393. static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
  3394. struct ieee80211_if_init_conf *conf)
  3395. {
  3396. struct iwl_priv *priv = hw->priv;
  3397. IWL_DEBUG_MAC80211("enter\n");
  3398. mutex_lock(&priv->mutex);
  3399. if (iwl_is_ready_rf(priv)) {
  3400. iwl4965_scan_cancel_timeout(priv, 100);
  3401. cancel_delayed_work(&priv->post_associate);
  3402. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3403. iwl4965_commit_rxon(priv);
  3404. }
  3405. if (priv->vif == conf->vif) {
  3406. priv->vif = NULL;
  3407. memset(priv->bssid, 0, ETH_ALEN);
  3408. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3409. priv->essid_len = 0;
  3410. }
  3411. mutex_unlock(&priv->mutex);
  3412. IWL_DEBUG_MAC80211("leave\n");
  3413. }
  3414. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  3415. static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
  3416. struct ieee80211_vif *vif,
  3417. struct ieee80211_bss_conf *bss_conf,
  3418. u32 changes)
  3419. {
  3420. struct iwl_priv *priv = hw->priv;
  3421. IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
  3422. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  3423. IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
  3424. bss_conf->use_short_preamble);
  3425. if (bss_conf->use_short_preamble)
  3426. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3427. else
  3428. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3429. }
  3430. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  3431. IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
  3432. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  3433. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  3434. else
  3435. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  3436. }
  3437. if (changes & BSS_CHANGED_HT) {
  3438. IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
  3439. iwl4965_ht_conf(priv, bss_conf);
  3440. iwl_set_rxon_chain(priv);
  3441. }
  3442. if (changes & BSS_CHANGED_ASSOC) {
  3443. IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
  3444. /* This should never happen as this function should
  3445. * never be called from interrupt context. */
  3446. if (WARN_ON_ONCE(in_interrupt()))
  3447. return;
  3448. if (bss_conf->assoc) {
  3449. priv->assoc_id = bss_conf->aid;
  3450. priv->beacon_int = bss_conf->beacon_int;
  3451. priv->timestamp = bss_conf->timestamp;
  3452. priv->assoc_capability = bss_conf->assoc_capability;
  3453. priv->next_scan_jiffies = jiffies +
  3454. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  3455. mutex_lock(&priv->mutex);
  3456. iwl4965_post_associate(priv);
  3457. mutex_unlock(&priv->mutex);
  3458. } else {
  3459. priv->assoc_id = 0;
  3460. IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
  3461. }
  3462. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  3463. IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
  3464. iwl_send_rxon_assoc(priv);
  3465. }
  3466. }
  3467. static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  3468. {
  3469. int rc = 0;
  3470. unsigned long flags;
  3471. struct iwl_priv *priv = hw->priv;
  3472. IWL_DEBUG_MAC80211("enter\n");
  3473. mutex_lock(&priv->mutex);
  3474. spin_lock_irqsave(&priv->lock, flags);
  3475. if (!iwl_is_ready_rf(priv)) {
  3476. rc = -EIO;
  3477. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  3478. goto out_unlock;
  3479. }
  3480. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  3481. rc = -EIO;
  3482. IWL_ERROR("ERROR: APs don't scan\n");
  3483. goto out_unlock;
  3484. }
  3485. /* we don't schedule scan within next_scan_jiffies period */
  3486. if (priv->next_scan_jiffies &&
  3487. time_after(priv->next_scan_jiffies, jiffies)) {
  3488. rc = -EAGAIN;
  3489. goto out_unlock;
  3490. }
  3491. /* if we just finished scan ask for delay */
  3492. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  3493. IWL_DELAY_NEXT_SCAN, jiffies)) {
  3494. rc = -EAGAIN;
  3495. goto out_unlock;
  3496. }
  3497. if (len) {
  3498. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  3499. iwl4965_escape_essid(ssid, len), (int)len);
  3500. priv->one_direct_scan = 1;
  3501. priv->direct_ssid_len = (u8)
  3502. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  3503. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  3504. } else
  3505. priv->one_direct_scan = 0;
  3506. rc = iwl4965_scan_initiate(priv);
  3507. IWL_DEBUG_MAC80211("leave\n");
  3508. out_unlock:
  3509. spin_unlock_irqrestore(&priv->lock, flags);
  3510. mutex_unlock(&priv->mutex);
  3511. return rc;
  3512. }
  3513. static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  3514. struct ieee80211_key_conf *keyconf, const u8 *addr,
  3515. u32 iv32, u16 *phase1key)
  3516. {
  3517. struct iwl_priv *priv = hw->priv;
  3518. u8 sta_id = IWL_INVALID_STATION;
  3519. unsigned long flags;
  3520. __le16 key_flags = 0;
  3521. int i;
  3522. DECLARE_MAC_BUF(mac);
  3523. IWL_DEBUG_MAC80211("enter\n");
  3524. sta_id = iwl_find_station(priv, addr);
  3525. if (sta_id == IWL_INVALID_STATION) {
  3526. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3527. print_mac(mac, addr));
  3528. return;
  3529. }
  3530. iwl4965_scan_cancel_timeout(priv, 100);
  3531. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  3532. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  3533. key_flags &= ~STA_KEY_FLG_INVALID;
  3534. if (sta_id == priv->hw_params.bcast_sta_id)
  3535. key_flags |= STA_KEY_MULTICAST_MSK;
  3536. spin_lock_irqsave(&priv->sta_lock, flags);
  3537. priv->stations[sta_id].sta.key.key_flags = key_flags;
  3538. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  3539. for (i = 0; i < 5; i++)
  3540. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  3541. cpu_to_le16(phase1key[i]);
  3542. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  3543. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3544. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3545. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3546. IWL_DEBUG_MAC80211("leave\n");
  3547. }
  3548. static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3549. const u8 *local_addr, const u8 *addr,
  3550. struct ieee80211_key_conf *key)
  3551. {
  3552. struct iwl_priv *priv = hw->priv;
  3553. DECLARE_MAC_BUF(mac);
  3554. int ret = 0;
  3555. u8 sta_id = IWL_INVALID_STATION;
  3556. u8 is_default_wep_key = 0;
  3557. IWL_DEBUG_MAC80211("enter\n");
  3558. if (priv->hw_params.sw_crypto) {
  3559. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  3560. return -EOPNOTSUPP;
  3561. }
  3562. if (is_zero_ether_addr(addr))
  3563. /* only support pairwise keys */
  3564. return -EOPNOTSUPP;
  3565. sta_id = iwl_find_station(priv, addr);
  3566. if (sta_id == IWL_INVALID_STATION) {
  3567. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3568. print_mac(mac, addr));
  3569. return -EINVAL;
  3570. }
  3571. mutex_lock(&priv->mutex);
  3572. iwl4965_scan_cancel_timeout(priv, 100);
  3573. mutex_unlock(&priv->mutex);
  3574. /* If we are getting WEP group key and we didn't receive any key mapping
  3575. * so far, we are in legacy wep mode (group key only), otherwise we are
  3576. * in 1X mode.
  3577. * In legacy wep mode, we use another host command to the uCode */
  3578. if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
  3579. priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3580. if (cmd == SET_KEY)
  3581. is_default_wep_key = !priv->key_mapping_key;
  3582. else
  3583. is_default_wep_key =
  3584. (key->hw_key_idx == HW_KEY_DEFAULT);
  3585. }
  3586. switch (cmd) {
  3587. case SET_KEY:
  3588. if (is_default_wep_key)
  3589. ret = iwl_set_default_wep_key(priv, key);
  3590. else
  3591. ret = iwl_set_dynamic_key(priv, key, sta_id);
  3592. IWL_DEBUG_MAC80211("enable hwcrypto key\n");
  3593. break;
  3594. case DISABLE_KEY:
  3595. if (is_default_wep_key)
  3596. ret = iwl_remove_default_wep_key(priv, key);
  3597. else
  3598. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  3599. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  3600. break;
  3601. default:
  3602. ret = -EINVAL;
  3603. }
  3604. IWL_DEBUG_MAC80211("leave\n");
  3605. return ret;
  3606. }
  3607. static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3608. const struct ieee80211_tx_queue_params *params)
  3609. {
  3610. struct iwl_priv *priv = hw->priv;
  3611. unsigned long flags;
  3612. int q;
  3613. IWL_DEBUG_MAC80211("enter\n");
  3614. if (!iwl_is_ready_rf(priv)) {
  3615. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3616. return -EIO;
  3617. }
  3618. if (queue >= AC_NUM) {
  3619. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  3620. return 0;
  3621. }
  3622. if (!priv->qos_data.qos_enable) {
  3623. priv->qos_data.qos_active = 0;
  3624. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  3625. return 0;
  3626. }
  3627. q = AC_NUM - 1 - queue;
  3628. spin_lock_irqsave(&priv->lock, flags);
  3629. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  3630. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  3631. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  3632. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  3633. cpu_to_le16((params->txop * 32));
  3634. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  3635. priv->qos_data.qos_active = 1;
  3636. spin_unlock_irqrestore(&priv->lock, flags);
  3637. mutex_lock(&priv->mutex);
  3638. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3639. iwl4965_activate_qos(priv, 1);
  3640. else if (priv->assoc_id && iwl_is_associated(priv))
  3641. iwl4965_activate_qos(priv, 0);
  3642. mutex_unlock(&priv->mutex);
  3643. IWL_DEBUG_MAC80211("leave\n");
  3644. return 0;
  3645. }
  3646. static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
  3647. struct ieee80211_tx_queue_stats *stats)
  3648. {
  3649. struct iwl_priv *priv = hw->priv;
  3650. int i, avail;
  3651. struct iwl_tx_queue *txq;
  3652. struct iwl_queue *q;
  3653. unsigned long flags;
  3654. IWL_DEBUG_MAC80211("enter\n");
  3655. if (!iwl_is_ready_rf(priv)) {
  3656. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3657. return -EIO;
  3658. }
  3659. spin_lock_irqsave(&priv->lock, flags);
  3660. for (i = 0; i < AC_NUM; i++) {
  3661. txq = &priv->txq[i];
  3662. q = &txq->q;
  3663. avail = iwl_queue_space(q);
  3664. stats[i].len = q->n_window - avail;
  3665. stats[i].limit = q->n_window - q->high_mark;
  3666. stats[i].count = q->n_window;
  3667. }
  3668. spin_unlock_irqrestore(&priv->lock, flags);
  3669. IWL_DEBUG_MAC80211("leave\n");
  3670. return 0;
  3671. }
  3672. static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
  3673. struct ieee80211_low_level_stats *stats)
  3674. {
  3675. struct iwl_priv *priv = hw->priv;
  3676. priv = hw->priv;
  3677. IWL_DEBUG_MAC80211("enter\n");
  3678. IWL_DEBUG_MAC80211("leave\n");
  3679. return 0;
  3680. }
  3681. static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
  3682. {
  3683. struct iwl_priv *priv;
  3684. priv = hw->priv;
  3685. IWL_DEBUG_MAC80211("enter\n");
  3686. IWL_DEBUG_MAC80211("leave\n");
  3687. return 0;
  3688. }
  3689. static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
  3690. {
  3691. struct iwl_priv *priv = hw->priv;
  3692. unsigned long flags;
  3693. mutex_lock(&priv->mutex);
  3694. IWL_DEBUG_MAC80211("enter\n");
  3695. priv->lq_mngr.lq_ready = 0;
  3696. spin_lock_irqsave(&priv->lock, flags);
  3697. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  3698. spin_unlock_irqrestore(&priv->lock, flags);
  3699. iwl_reset_qos(priv);
  3700. cancel_delayed_work(&priv->post_associate);
  3701. spin_lock_irqsave(&priv->lock, flags);
  3702. priv->assoc_id = 0;
  3703. priv->assoc_capability = 0;
  3704. priv->assoc_station_added = 0;
  3705. /* new association get rid of ibss beacon skb */
  3706. if (priv->ibss_beacon)
  3707. dev_kfree_skb(priv->ibss_beacon);
  3708. priv->ibss_beacon = NULL;
  3709. priv->beacon_int = priv->hw->conf.beacon_int;
  3710. priv->timestamp = 0;
  3711. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  3712. priv->beacon_int = 0;
  3713. spin_unlock_irqrestore(&priv->lock, flags);
  3714. if (!iwl_is_ready_rf(priv)) {
  3715. IWL_DEBUG_MAC80211("leave - not ready\n");
  3716. mutex_unlock(&priv->mutex);
  3717. return;
  3718. }
  3719. /* we are restarting association process
  3720. * clear RXON_FILTER_ASSOC_MSK bit
  3721. */
  3722. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3723. iwl4965_scan_cancel_timeout(priv, 100);
  3724. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3725. iwl4965_commit_rxon(priv);
  3726. }
  3727. iwl_power_update_mode(priv, 0);
  3728. /* Per mac80211.h: This is only used in IBSS mode... */
  3729. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3730. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  3731. mutex_unlock(&priv->mutex);
  3732. return;
  3733. }
  3734. iwl4965_set_rate(priv);
  3735. mutex_unlock(&priv->mutex);
  3736. IWL_DEBUG_MAC80211("leave\n");
  3737. }
  3738. static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  3739. {
  3740. struct iwl_priv *priv = hw->priv;
  3741. unsigned long flags;
  3742. mutex_lock(&priv->mutex);
  3743. IWL_DEBUG_MAC80211("enter\n");
  3744. if (!iwl_is_ready_rf(priv)) {
  3745. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3746. mutex_unlock(&priv->mutex);
  3747. return -EIO;
  3748. }
  3749. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3750. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  3751. mutex_unlock(&priv->mutex);
  3752. return -EIO;
  3753. }
  3754. spin_lock_irqsave(&priv->lock, flags);
  3755. if (priv->ibss_beacon)
  3756. dev_kfree_skb(priv->ibss_beacon);
  3757. priv->ibss_beacon = skb;
  3758. priv->assoc_id = 0;
  3759. IWL_DEBUG_MAC80211("leave\n");
  3760. spin_unlock_irqrestore(&priv->lock, flags);
  3761. iwl_reset_qos(priv);
  3762. iwl4965_post_associate(priv);
  3763. mutex_unlock(&priv->mutex);
  3764. return 0;
  3765. }
  3766. /*****************************************************************************
  3767. *
  3768. * sysfs attributes
  3769. *
  3770. *****************************************************************************/
  3771. #ifdef CONFIG_IWLWIFI_DEBUG
  3772. /*
  3773. * The following adds a new attribute to the sysfs representation
  3774. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  3775. * used for controlling the debug level.
  3776. *
  3777. * See the level definitions in iwl for details.
  3778. */
  3779. static ssize_t show_debug_level(struct device *d,
  3780. struct device_attribute *attr, char *buf)
  3781. {
  3782. struct iwl_priv *priv = d->driver_data;
  3783. return sprintf(buf, "0x%08X\n", priv->debug_level);
  3784. }
  3785. static ssize_t store_debug_level(struct device *d,
  3786. struct device_attribute *attr,
  3787. const char *buf, size_t count)
  3788. {
  3789. struct iwl_priv *priv = d->driver_data;
  3790. char *p = (char *)buf;
  3791. u32 val;
  3792. val = simple_strtoul(p, &p, 0);
  3793. if (p == buf)
  3794. printk(KERN_INFO DRV_NAME
  3795. ": %s is not in hex or decimal form.\n", buf);
  3796. else
  3797. priv->debug_level = val;
  3798. return strnlen(buf, count);
  3799. }
  3800. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3801. show_debug_level, store_debug_level);
  3802. #endif /* CONFIG_IWLWIFI_DEBUG */
  3803. static ssize_t show_version(struct device *d,
  3804. struct device_attribute *attr, char *buf)
  3805. {
  3806. struct iwl_priv *priv = d->driver_data;
  3807. struct iwl_alive_resp *palive = &priv->card_alive;
  3808. if (palive->is_valid)
  3809. return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
  3810. "fw type: 0x%01X 0x%01X\n",
  3811. palive->ucode_major, palive->ucode_minor,
  3812. palive->sw_rev[0], palive->sw_rev[1],
  3813. palive->ver_type, palive->ver_subtype);
  3814. else
  3815. return sprintf(buf, "fw not loaded\n");
  3816. }
  3817. static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
  3818. static ssize_t show_temperature(struct device *d,
  3819. struct device_attribute *attr, char *buf)
  3820. {
  3821. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3822. if (!iwl_is_alive(priv))
  3823. return -EAGAIN;
  3824. return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
  3825. }
  3826. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  3827. static ssize_t show_rs_window(struct device *d,
  3828. struct device_attribute *attr,
  3829. char *buf)
  3830. {
  3831. struct iwl_priv *priv = d->driver_data;
  3832. return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  3833. }
  3834. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  3835. static ssize_t show_tx_power(struct device *d,
  3836. struct device_attribute *attr, char *buf)
  3837. {
  3838. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3839. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  3840. }
  3841. static ssize_t store_tx_power(struct device *d,
  3842. struct device_attribute *attr,
  3843. const char *buf, size_t count)
  3844. {
  3845. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3846. char *p = (char *)buf;
  3847. u32 val;
  3848. val = simple_strtoul(p, &p, 10);
  3849. if (p == buf)
  3850. printk(KERN_INFO DRV_NAME
  3851. ": %s is not in decimal form.\n", buf);
  3852. else
  3853. iwl4965_hw_reg_set_txpower(priv, val);
  3854. return count;
  3855. }
  3856. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  3857. static ssize_t show_flags(struct device *d,
  3858. struct device_attribute *attr, char *buf)
  3859. {
  3860. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3861. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  3862. }
  3863. static ssize_t store_flags(struct device *d,
  3864. struct device_attribute *attr,
  3865. const char *buf, size_t count)
  3866. {
  3867. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3868. u32 flags = simple_strtoul(buf, NULL, 0);
  3869. mutex_lock(&priv->mutex);
  3870. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  3871. /* Cancel any currently running scans... */
  3872. if (iwl4965_scan_cancel_timeout(priv, 100))
  3873. IWL_WARNING("Could not cancel scan.\n");
  3874. else {
  3875. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  3876. flags);
  3877. priv->staging_rxon.flags = cpu_to_le32(flags);
  3878. iwl4965_commit_rxon(priv);
  3879. }
  3880. }
  3881. mutex_unlock(&priv->mutex);
  3882. return count;
  3883. }
  3884. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  3885. static ssize_t show_filter_flags(struct device *d,
  3886. struct device_attribute *attr, char *buf)
  3887. {
  3888. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3889. return sprintf(buf, "0x%04X\n",
  3890. le32_to_cpu(priv->active_rxon.filter_flags));
  3891. }
  3892. static ssize_t store_filter_flags(struct device *d,
  3893. struct device_attribute *attr,
  3894. const char *buf, size_t count)
  3895. {
  3896. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3897. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3898. mutex_lock(&priv->mutex);
  3899. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  3900. /* Cancel any currently running scans... */
  3901. if (iwl4965_scan_cancel_timeout(priv, 100))
  3902. IWL_WARNING("Could not cancel scan.\n");
  3903. else {
  3904. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  3905. "0x%04X\n", filter_flags);
  3906. priv->staging_rxon.filter_flags =
  3907. cpu_to_le32(filter_flags);
  3908. iwl4965_commit_rxon(priv);
  3909. }
  3910. }
  3911. mutex_unlock(&priv->mutex);
  3912. return count;
  3913. }
  3914. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3915. store_filter_flags);
  3916. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  3917. static ssize_t show_measurement(struct device *d,
  3918. struct device_attribute *attr, char *buf)
  3919. {
  3920. struct iwl_priv *priv = dev_get_drvdata(d);
  3921. struct iwl4965_spectrum_notification measure_report;
  3922. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3923. u8 *data = (u8 *) & measure_report;
  3924. unsigned long flags;
  3925. spin_lock_irqsave(&priv->lock, flags);
  3926. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3927. spin_unlock_irqrestore(&priv->lock, flags);
  3928. return 0;
  3929. }
  3930. memcpy(&measure_report, &priv->measure_report, size);
  3931. priv->measurement_status = 0;
  3932. spin_unlock_irqrestore(&priv->lock, flags);
  3933. while (size && (PAGE_SIZE - len)) {
  3934. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3935. PAGE_SIZE - len, 1);
  3936. len = strlen(buf);
  3937. if (PAGE_SIZE - len)
  3938. buf[len++] = '\n';
  3939. ofs += 16;
  3940. size -= min(size, 16U);
  3941. }
  3942. return len;
  3943. }
  3944. static ssize_t store_measurement(struct device *d,
  3945. struct device_attribute *attr,
  3946. const char *buf, size_t count)
  3947. {
  3948. struct iwl_priv *priv = dev_get_drvdata(d);
  3949. struct ieee80211_measurement_params params = {
  3950. .channel = le16_to_cpu(priv->active_rxon.channel),
  3951. .start_time = cpu_to_le64(priv->last_tsf),
  3952. .duration = cpu_to_le16(1),
  3953. };
  3954. u8 type = IWL_MEASURE_BASIC;
  3955. u8 buffer[32];
  3956. u8 channel;
  3957. if (count) {
  3958. char *p = buffer;
  3959. strncpy(buffer, buf, min(sizeof(buffer), count));
  3960. channel = simple_strtoul(p, NULL, 0);
  3961. if (channel)
  3962. params.channel = channel;
  3963. p = buffer;
  3964. while (*p && *p != ' ')
  3965. p++;
  3966. if (*p)
  3967. type = simple_strtoul(p + 1, NULL, 0);
  3968. }
  3969. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  3970. "channel %d (for '%s')\n", type, params.channel, buf);
  3971. iwl4965_get_measurement(priv, &params, type);
  3972. return count;
  3973. }
  3974. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3975. show_measurement, store_measurement);
  3976. #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
  3977. static ssize_t store_retry_rate(struct device *d,
  3978. struct device_attribute *attr,
  3979. const char *buf, size_t count)
  3980. {
  3981. struct iwl_priv *priv = dev_get_drvdata(d);
  3982. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3983. if (priv->retry_rate <= 0)
  3984. priv->retry_rate = 1;
  3985. return count;
  3986. }
  3987. static ssize_t show_retry_rate(struct device *d,
  3988. struct device_attribute *attr, char *buf)
  3989. {
  3990. struct iwl_priv *priv = dev_get_drvdata(d);
  3991. return sprintf(buf, "%d", priv->retry_rate);
  3992. }
  3993. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3994. store_retry_rate);
  3995. static ssize_t store_power_level(struct device *d,
  3996. struct device_attribute *attr,
  3997. const char *buf, size_t count)
  3998. {
  3999. struct iwl_priv *priv = dev_get_drvdata(d);
  4000. int rc;
  4001. int mode;
  4002. mode = simple_strtoul(buf, NULL, 0);
  4003. mutex_lock(&priv->mutex);
  4004. if (!iwl_is_ready(priv)) {
  4005. rc = -EAGAIN;
  4006. goto out;
  4007. }
  4008. rc = iwl_power_set_user_mode(priv, mode);
  4009. if (rc) {
  4010. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  4011. goto out;
  4012. }
  4013. rc = count;
  4014. out:
  4015. mutex_unlock(&priv->mutex);
  4016. return rc;
  4017. }
  4018. #define MAX_WX_STRING 80
  4019. /* Values are in microsecond */
  4020. static const s32 timeout_duration[] = {
  4021. 350000,
  4022. 250000,
  4023. 75000,
  4024. 37000,
  4025. 25000,
  4026. };
  4027. static const s32 period_duration[] = {
  4028. 400000,
  4029. 700000,
  4030. 1000000,
  4031. 1000000,
  4032. 1000000
  4033. };
  4034. static ssize_t show_power_level(struct device *d,
  4035. struct device_attribute *attr, char *buf)
  4036. {
  4037. struct iwl_priv *priv = dev_get_drvdata(d);
  4038. int level = priv->power_data.power_mode;
  4039. char *p = buf;
  4040. p += sprintf(p, "%d ", level);
  4041. switch (level) {
  4042. case IWL_POWER_MODE_CAM:
  4043. case IWL_POWER_AC:
  4044. p += sprintf(p, "(AC)");
  4045. break;
  4046. case IWL_POWER_BATTERY:
  4047. p += sprintf(p, "(BATTERY)");
  4048. break;
  4049. default:
  4050. p += sprintf(p,
  4051. "(Timeout %dms, Period %dms)",
  4052. timeout_duration[level - 1] / 1000,
  4053. period_duration[level - 1] / 1000);
  4054. }
  4055. /*
  4056. if (!(priv->power_mode & IWL_POWER_ENABLED))
  4057. p += sprintf(p, " OFF\n");
  4058. else
  4059. p += sprintf(p, " \n");
  4060. */
  4061. p += sprintf(p, " \n");
  4062. return (p - buf + 1);
  4063. }
  4064. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  4065. store_power_level);
  4066. static ssize_t show_channels(struct device *d,
  4067. struct device_attribute *attr, char *buf)
  4068. {
  4069. /* all this shit doesn't belong into sysfs anyway */
  4070. return 0;
  4071. }
  4072. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  4073. static ssize_t show_statistics(struct device *d,
  4074. struct device_attribute *attr, char *buf)
  4075. {
  4076. struct iwl_priv *priv = dev_get_drvdata(d);
  4077. u32 size = sizeof(struct iwl4965_notif_statistics);
  4078. u32 len = 0, ofs = 0;
  4079. u8 *data = (u8 *) & priv->statistics;
  4080. int rc = 0;
  4081. if (!iwl_is_alive(priv))
  4082. return -EAGAIN;
  4083. mutex_lock(&priv->mutex);
  4084. rc = iwl_send_statistics_request(priv, 0);
  4085. mutex_unlock(&priv->mutex);
  4086. if (rc) {
  4087. len = sprintf(buf,
  4088. "Error sending statistics request: 0x%08X\n", rc);
  4089. return len;
  4090. }
  4091. while (size && (PAGE_SIZE - len)) {
  4092. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4093. PAGE_SIZE - len, 1);
  4094. len = strlen(buf);
  4095. if (PAGE_SIZE - len)
  4096. buf[len++] = '\n';
  4097. ofs += 16;
  4098. size -= min(size, 16U);
  4099. }
  4100. return len;
  4101. }
  4102. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  4103. static ssize_t show_status(struct device *d,
  4104. struct device_attribute *attr, char *buf)
  4105. {
  4106. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4107. if (!iwl_is_alive(priv))
  4108. return -EAGAIN;
  4109. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4110. }
  4111. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4112. /*****************************************************************************
  4113. *
  4114. * driver setup and teardown
  4115. *
  4116. *****************************************************************************/
  4117. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  4118. {
  4119. priv->workqueue = create_workqueue(DRV_NAME);
  4120. init_waitqueue_head(&priv->wait_command_queue);
  4121. INIT_WORK(&priv->up, iwl4965_bg_up);
  4122. INIT_WORK(&priv->restart, iwl4965_bg_restart);
  4123. INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
  4124. INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
  4125. INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
  4126. INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
  4127. INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
  4128. INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
  4129. INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
  4130. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  4131. INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
  4132. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  4133. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  4134. INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
  4135. if (priv->cfg->ops->lib->setup_deferred_work)
  4136. priv->cfg->ops->lib->setup_deferred_work(priv);
  4137. init_timer(&priv->statistics_periodic);
  4138. priv->statistics_periodic.data = (unsigned long)priv;
  4139. priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
  4140. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4141. iwl4965_irq_tasklet, (unsigned long)priv);
  4142. }
  4143. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  4144. {
  4145. if (priv->cfg->ops->lib->cancel_deferred_work)
  4146. priv->cfg->ops->lib->cancel_deferred_work(priv);
  4147. cancel_delayed_work_sync(&priv->init_alive_start);
  4148. cancel_delayed_work(&priv->scan_check);
  4149. cancel_delayed_work(&priv->alive_start);
  4150. cancel_delayed_work(&priv->post_associate);
  4151. cancel_work_sync(&priv->beacon_update);
  4152. del_timer_sync(&priv->statistics_periodic);
  4153. }
  4154. static struct attribute *iwl4965_sysfs_entries[] = {
  4155. &dev_attr_channels.attr,
  4156. &dev_attr_flags.attr,
  4157. &dev_attr_filter_flags.attr,
  4158. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  4159. &dev_attr_measurement.attr,
  4160. #endif
  4161. &dev_attr_power_level.attr,
  4162. &dev_attr_retry_rate.attr,
  4163. &dev_attr_rs_window.attr,
  4164. &dev_attr_statistics.attr,
  4165. &dev_attr_status.attr,
  4166. &dev_attr_temperature.attr,
  4167. &dev_attr_tx_power.attr,
  4168. #ifdef CONFIG_IWLWIFI_DEBUG
  4169. &dev_attr_debug_level.attr,
  4170. #endif
  4171. &dev_attr_version.attr,
  4172. NULL
  4173. };
  4174. static struct attribute_group iwl4965_attribute_group = {
  4175. .name = NULL, /* put in device directory */
  4176. .attrs = iwl4965_sysfs_entries,
  4177. };
  4178. static struct ieee80211_ops iwl4965_hw_ops = {
  4179. .tx = iwl4965_mac_tx,
  4180. .start = iwl4965_mac_start,
  4181. .stop = iwl4965_mac_stop,
  4182. .add_interface = iwl4965_mac_add_interface,
  4183. .remove_interface = iwl4965_mac_remove_interface,
  4184. .config = iwl4965_mac_config,
  4185. .config_interface = iwl4965_mac_config_interface,
  4186. .configure_filter = iwl4965_configure_filter,
  4187. .set_key = iwl4965_mac_set_key,
  4188. .update_tkip_key = iwl4965_mac_update_tkip_key,
  4189. .get_stats = iwl4965_mac_get_stats,
  4190. .get_tx_stats = iwl4965_mac_get_tx_stats,
  4191. .conf_tx = iwl4965_mac_conf_tx,
  4192. .get_tsf = iwl4965_mac_get_tsf,
  4193. .reset_tsf = iwl4965_mac_reset_tsf,
  4194. .beacon_update = iwl4965_mac_beacon_update,
  4195. .bss_info_changed = iwl4965_bss_info_changed,
  4196. .ampdu_action = iwl4965_mac_ampdu_action,
  4197. .hw_scan = iwl4965_mac_hw_scan
  4198. };
  4199. static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4200. {
  4201. int err = 0;
  4202. struct iwl_priv *priv;
  4203. struct ieee80211_hw *hw;
  4204. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4205. unsigned long flags;
  4206. DECLARE_MAC_BUF(mac);
  4207. /************************
  4208. * 1. Allocating HW data
  4209. ************************/
  4210. /* Disabling hardware scan means that mac80211 will perform scans
  4211. * "the hard way", rather than using device's scan. */
  4212. if (cfg->mod_params->disable_hw_scan) {
  4213. if (cfg->mod_params->debug & IWL_DL_INFO)
  4214. dev_printk(KERN_DEBUG, &(pdev->dev),
  4215. "Disabling hw_scan\n");
  4216. iwl4965_hw_ops.hw_scan = NULL;
  4217. }
  4218. hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
  4219. if (!hw) {
  4220. err = -ENOMEM;
  4221. goto out;
  4222. }
  4223. priv = hw->priv;
  4224. /* At this point both hw and priv are allocated. */
  4225. SET_IEEE80211_DEV(hw, &pdev->dev);
  4226. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  4227. priv->cfg = cfg;
  4228. priv->pci_dev = pdev;
  4229. #ifdef CONFIG_IWLWIFI_DEBUG
  4230. priv->debug_level = priv->cfg->mod_params->debug;
  4231. atomic_set(&priv->restrict_refcnt, 0);
  4232. #endif
  4233. /**************************
  4234. * 2. Initializing PCI bus
  4235. **************************/
  4236. if (pci_enable_device(pdev)) {
  4237. err = -ENODEV;
  4238. goto out_ieee80211_free_hw;
  4239. }
  4240. pci_set_master(pdev);
  4241. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  4242. if (!err)
  4243. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  4244. if (err) {
  4245. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4246. if (!err)
  4247. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  4248. /* both attempts failed: */
  4249. if (err) {
  4250. printk(KERN_WARNING "%s: No suitable DMA available.\n",
  4251. DRV_NAME);
  4252. goto out_pci_disable_device;
  4253. }
  4254. }
  4255. err = pci_request_regions(pdev, DRV_NAME);
  4256. if (err)
  4257. goto out_pci_disable_device;
  4258. pci_set_drvdata(pdev, priv);
  4259. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  4260. * PCI Tx retries from interfering with C3 CPU state */
  4261. pci_write_config_byte(pdev, 0x41, 0x00);
  4262. /***********************
  4263. * 3. Read REV register
  4264. ***********************/
  4265. priv->hw_base = pci_iomap(pdev, 0, 0);
  4266. if (!priv->hw_base) {
  4267. err = -ENODEV;
  4268. goto out_pci_release_regions;
  4269. }
  4270. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  4271. (unsigned long long) pci_resource_len(pdev, 0));
  4272. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  4273. iwl_hw_detect(priv);
  4274. printk(KERN_INFO DRV_NAME
  4275. ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
  4276. priv->cfg->name, priv->hw_rev);
  4277. /* amp init */
  4278. err = priv->cfg->ops->lib->apm_ops.init(priv);
  4279. if (err < 0) {
  4280. IWL_DEBUG_INFO("Failed to init APMG\n");
  4281. goto out_iounmap;
  4282. }
  4283. /*****************
  4284. * 4. Read EEPROM
  4285. *****************/
  4286. /* Read the EEPROM */
  4287. err = iwl_eeprom_init(priv);
  4288. if (err) {
  4289. IWL_ERROR("Unable to init EEPROM\n");
  4290. goto out_iounmap;
  4291. }
  4292. err = iwl_eeprom_check_version(priv);
  4293. if (err)
  4294. goto out_iounmap;
  4295. /* extract MAC Address */
  4296. iwl_eeprom_get_mac(priv, priv->mac_addr);
  4297. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  4298. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  4299. /************************
  4300. * 5. Setup HW constants
  4301. ************************/
  4302. /* Device-specific setup */
  4303. if (priv->cfg->ops->lib->set_hw_params(priv)) {
  4304. IWL_ERROR("failed to set hw parameters\n");
  4305. goto out_free_eeprom;
  4306. }
  4307. /*******************
  4308. * 6. Setup priv
  4309. *******************/
  4310. err = iwl_init_drv(priv);
  4311. if (err)
  4312. goto out_free_eeprom;
  4313. /* At this point both hw and priv are initialized. */
  4314. /**********************************
  4315. * 7. Initialize module parameters
  4316. **********************************/
  4317. /* Disable radio (SW RF KILL) via parameter when loading driver */
  4318. if (priv->cfg->mod_params->disable) {
  4319. set_bit(STATUS_RF_KILL_SW, &priv->status);
  4320. IWL_DEBUG_INFO("Radio disabled.\n");
  4321. }
  4322. /********************
  4323. * 8. Setup services
  4324. ********************/
  4325. spin_lock_irqsave(&priv->lock, flags);
  4326. iwl4965_disable_interrupts(priv);
  4327. spin_unlock_irqrestore(&priv->lock, flags);
  4328. err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4329. if (err) {
  4330. IWL_ERROR("failed to create sysfs device attributes\n");
  4331. goto out_uninit_drv;
  4332. }
  4333. iwl_setup_deferred_work(priv);
  4334. iwl4965_setup_rx_handlers(priv);
  4335. /********************
  4336. * 9. Conclude
  4337. ********************/
  4338. pci_save_state(pdev);
  4339. pci_disable_device(pdev);
  4340. /**********************************
  4341. * 10. Setup and register mac80211
  4342. **********************************/
  4343. err = iwl_setup_mac(priv);
  4344. if (err)
  4345. goto out_remove_sysfs;
  4346. err = iwl_dbgfs_register(priv, DRV_NAME);
  4347. if (err)
  4348. IWL_ERROR("failed to create debugfs files\n");
  4349. /* notify iwlcore to init */
  4350. iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
  4351. return 0;
  4352. out_remove_sysfs:
  4353. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4354. out_uninit_drv:
  4355. iwl_uninit_drv(priv);
  4356. out_free_eeprom:
  4357. iwl_eeprom_free(priv);
  4358. out_iounmap:
  4359. pci_iounmap(pdev, priv->hw_base);
  4360. out_pci_release_regions:
  4361. pci_release_regions(pdev);
  4362. pci_set_drvdata(pdev, NULL);
  4363. out_pci_disable_device:
  4364. pci_disable_device(pdev);
  4365. out_ieee80211_free_hw:
  4366. ieee80211_free_hw(priv->hw);
  4367. out:
  4368. return err;
  4369. }
  4370. static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
  4371. {
  4372. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4373. struct list_head *p, *q;
  4374. int i;
  4375. unsigned long flags;
  4376. if (!priv)
  4377. return;
  4378. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  4379. iwl_dbgfs_unregister(priv);
  4380. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4381. if (priv->mac80211_registered) {
  4382. ieee80211_unregister_hw(priv->hw);
  4383. priv->mac80211_registered = 0;
  4384. }
  4385. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4386. iwl4965_down(priv);
  4387. /* make sure we flush any pending irq or
  4388. * tasklet for the driver
  4389. */
  4390. spin_lock_irqsave(&priv->lock, flags);
  4391. iwl4965_disable_interrupts(priv);
  4392. spin_unlock_irqrestore(&priv->lock, flags);
  4393. iwl_synchronize_irq(priv);
  4394. /* Free MAC hash list for ADHOC */
  4395. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  4396. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  4397. list_del(p);
  4398. kfree(list_entry(p, struct iwl4965_ibss_seq, list));
  4399. }
  4400. }
  4401. iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
  4402. iwl4965_dealloc_ucode_pci(priv);
  4403. if (priv->rxq.bd)
  4404. iwl_rx_queue_free(priv, &priv->rxq);
  4405. iwl_hw_txq_ctx_free(priv);
  4406. iwlcore_clear_stations_table(priv);
  4407. iwl_eeprom_free(priv);
  4408. /*netif_stop_queue(dev); */
  4409. flush_workqueue(priv->workqueue);
  4410. /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
  4411. * priv->workqueue... so we can't take down the workqueue
  4412. * until now... */
  4413. destroy_workqueue(priv->workqueue);
  4414. priv->workqueue = NULL;
  4415. pci_iounmap(pdev, priv->hw_base);
  4416. pci_release_regions(pdev);
  4417. pci_disable_device(pdev);
  4418. pci_set_drvdata(pdev, NULL);
  4419. iwl_uninit_drv(priv);
  4420. if (priv->ibss_beacon)
  4421. dev_kfree_skb(priv->ibss_beacon);
  4422. ieee80211_free_hw(priv->hw);
  4423. }
  4424. #ifdef CONFIG_PM
  4425. static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4426. {
  4427. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4428. if (priv->is_open) {
  4429. set_bit(STATUS_IN_SUSPEND, &priv->status);
  4430. iwl4965_mac_stop(priv->hw);
  4431. priv->is_open = 1;
  4432. }
  4433. pci_set_power_state(pdev, PCI_D3hot);
  4434. return 0;
  4435. }
  4436. static int iwl4965_pci_resume(struct pci_dev *pdev)
  4437. {
  4438. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4439. pci_set_power_state(pdev, PCI_D0);
  4440. if (priv->is_open)
  4441. iwl4965_mac_start(priv->hw);
  4442. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  4443. return 0;
  4444. }
  4445. #endif /* CONFIG_PM */
  4446. /*****************************************************************************
  4447. *
  4448. * driver and module entry point
  4449. *
  4450. *****************************************************************************/
  4451. /* Hardware specific file defines the PCI IDs table for that hardware module */
  4452. static struct pci_device_id iwl_hw_card_ids[] = {
  4453. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  4454. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  4455. #ifdef CONFIG_IWL5000
  4456. {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
  4457. {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
  4458. {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
  4459. #endif /* CONFIG_IWL5000 */
  4460. {0}
  4461. };
  4462. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  4463. static struct pci_driver iwl_driver = {
  4464. .name = DRV_NAME,
  4465. .id_table = iwl_hw_card_ids,
  4466. .probe = iwl4965_pci_probe,
  4467. .remove = __devexit_p(iwl4965_pci_remove),
  4468. #ifdef CONFIG_PM
  4469. .suspend = iwl4965_pci_suspend,
  4470. .resume = iwl4965_pci_resume,
  4471. #endif
  4472. };
  4473. static int __init iwl4965_init(void)
  4474. {
  4475. int ret;
  4476. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  4477. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  4478. ret = iwl4965_rate_control_register();
  4479. if (ret) {
  4480. IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
  4481. return ret;
  4482. }
  4483. ret = pci_register_driver(&iwl_driver);
  4484. if (ret) {
  4485. IWL_ERROR("Unable to initialize PCI module\n");
  4486. goto error_register;
  4487. }
  4488. return ret;
  4489. error_register:
  4490. iwl4965_rate_control_unregister();
  4491. return ret;
  4492. }
  4493. static void __exit iwl4965_exit(void)
  4494. {
  4495. pci_unregister_driver(&iwl_driver);
  4496. iwl4965_rate_control_unregister();
  4497. }
  4498. module_exit(iwl4965_exit);
  4499. module_init(iwl4965_init);