4965-mac.c 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/if_arp.h>
  44. #include <net/mac80211.h>
  45. #include <asm/div64.h>
  46. #define DRV_NAME "iwl4965"
  47. #include "common.h"
  48. #include "4965.h"
  49. /******************************************************************************
  50. *
  51. * module boiler plate
  52. *
  53. ******************************************************************************/
  54. /*
  55. * module name, copyright, version, etc.
  56. */
  57. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux"
  58. #ifdef CONFIG_IWLEGACY_DEBUG
  59. #define VD "d"
  60. #else
  61. #define VD
  62. #endif
  63. #define DRV_VERSION IWLWIFI_VERSION VD
  64. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  65. MODULE_VERSION(DRV_VERSION);
  66. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS("iwl4965");
  69. void
  70. il4965_check_abort_status(struct il_priv *il, u8 frame_count, u32 status)
  71. {
  72. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  73. IL_ERR("Tx flush command to flush out all frames\n");
  74. if (!test_bit(S_EXIT_PENDING, &il->status))
  75. queue_work(il->workqueue, &il->tx_flush);
  76. }
  77. }
  78. /*
  79. * EEPROM
  80. */
  81. struct il_mod_params il4965_mod_params = {
  82. .amsdu_size_8K = 1,
  83. .restart_fw = 1,
  84. /* the rest are 0 by default */
  85. };
  86. void
  87. il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq)
  88. {
  89. unsigned long flags;
  90. int i;
  91. spin_lock_irqsave(&rxq->lock, flags);
  92. INIT_LIST_HEAD(&rxq->rx_free);
  93. INIT_LIST_HEAD(&rxq->rx_used);
  94. /* Fill the rx_used queue with _all_ of the Rx buffers */
  95. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  96. /* In the reset function, these buffers may have been allocated
  97. * to an SKB, so we need to unmap and free potential storage */
  98. if (rxq->pool[i].page != NULL) {
  99. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  100. PAGE_SIZE << il->hw_params.rx_page_order,
  101. PCI_DMA_FROMDEVICE);
  102. __il_free_pages(il, rxq->pool[i].page);
  103. rxq->pool[i].page = NULL;
  104. }
  105. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  106. }
  107. for (i = 0; i < RX_QUEUE_SIZE; i++)
  108. rxq->queue[i] = NULL;
  109. /* Set us so that we have processed and used all buffers, but have
  110. * not restocked the Rx queue with fresh buffers */
  111. rxq->read = rxq->write = 0;
  112. rxq->write_actual = 0;
  113. rxq->free_count = 0;
  114. spin_unlock_irqrestore(&rxq->lock, flags);
  115. }
  116. int
  117. il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
  118. {
  119. u32 rb_size;
  120. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  121. u32 rb_timeout = 0;
  122. if (il->cfg->mod_params->amsdu_size_8K)
  123. rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  124. else
  125. rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  126. /* Stop Rx DMA */
  127. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  128. /* Reset driver's Rx queue write idx */
  129. il_wr(il, FH49_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  130. /* Tell device where to find RBD circular buffer in DRAM */
  131. il_wr(il, FH49_RSCSR_CHNL0_RBDCB_BASE_REG, (u32) (rxq->bd_dma >> 8));
  132. /* Tell device where in DRAM to update its Rx status */
  133. il_wr(il, FH49_RSCSR_CHNL0_STTS_WPTR_REG, rxq->rb_stts_dma >> 4);
  134. /* Enable Rx DMA
  135. * Direct rx interrupts to hosts
  136. * Rx buffer size 4 or 8k
  137. * RB timeout 0x10
  138. * 256 RBDs
  139. */
  140. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG,
  141. FH49_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  142. FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  143. FH49_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  144. rb_size |
  145. (rb_timeout << FH49_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) |
  146. (rfdnlog << FH49_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  147. /* Set interrupt coalescing timer to default (2048 usecs) */
  148. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_TIMEOUT_DEF);
  149. return 0;
  150. }
  151. static void
  152. il4965_set_pwr_vmain(struct il_priv *il)
  153. {
  154. /*
  155. * (for documentation purposes)
  156. * to set power to V_AUX, do:
  157. if (pci_pme_capable(il->pci_dev, PCI_D3cold))
  158. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  159. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  160. ~APMG_PS_CTRL_MSK_PWR_SRC);
  161. */
  162. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  163. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  164. ~APMG_PS_CTRL_MSK_PWR_SRC);
  165. }
  166. int
  167. il4965_hw_nic_init(struct il_priv *il)
  168. {
  169. unsigned long flags;
  170. struct il_rx_queue *rxq = &il->rxq;
  171. int ret;
  172. /* nic_init */
  173. spin_lock_irqsave(&il->lock, flags);
  174. il->ops->lib->apm_ops.init(il);
  175. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  176. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_CALIB_TIMEOUT_DEF);
  177. spin_unlock_irqrestore(&il->lock, flags);
  178. il4965_set_pwr_vmain(il);
  179. il->ops->lib->apm_ops.config(il);
  180. /* Allocate the RX queue, or reset if it is already allocated */
  181. if (!rxq->bd) {
  182. ret = il_rx_queue_alloc(il);
  183. if (ret) {
  184. IL_ERR("Unable to initialize Rx queue\n");
  185. return -ENOMEM;
  186. }
  187. } else
  188. il4965_rx_queue_reset(il, rxq);
  189. il4965_rx_replenish(il);
  190. il4965_rx_init(il, rxq);
  191. spin_lock_irqsave(&il->lock, flags);
  192. rxq->need_update = 1;
  193. il_rx_queue_update_write_ptr(il, rxq);
  194. spin_unlock_irqrestore(&il->lock, flags);
  195. /* Allocate or reset and init all Tx and Command queues */
  196. if (!il->txq) {
  197. ret = il4965_txq_ctx_alloc(il);
  198. if (ret)
  199. return ret;
  200. } else
  201. il4965_txq_ctx_reset(il);
  202. set_bit(S_INIT, &il->status);
  203. return 0;
  204. }
  205. /**
  206. * il4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  207. */
  208. static inline __le32
  209. il4965_dma_addr2rbd_ptr(struct il_priv *il, dma_addr_t dma_addr)
  210. {
  211. return cpu_to_le32((u32) (dma_addr >> 8));
  212. }
  213. /**
  214. * il4965_rx_queue_restock - refill RX queue from pre-allocated pool
  215. *
  216. * If there are slots in the RX queue that need to be restocked,
  217. * and we have free pre-allocated buffers, fill the ranks as much
  218. * as we can, pulling from rx_free.
  219. *
  220. * This moves the 'write' idx forward to catch up with 'processed', and
  221. * also updates the memory address in the firmware to reference the new
  222. * target buffer.
  223. */
  224. void
  225. il4965_rx_queue_restock(struct il_priv *il)
  226. {
  227. struct il_rx_queue *rxq = &il->rxq;
  228. struct list_head *element;
  229. struct il_rx_buf *rxb;
  230. unsigned long flags;
  231. spin_lock_irqsave(&rxq->lock, flags);
  232. while (il_rx_queue_space(rxq) > 0 && rxq->free_count) {
  233. /* The overwritten rxb must be a used one */
  234. rxb = rxq->queue[rxq->write];
  235. BUG_ON(rxb && rxb->page);
  236. /* Get next free Rx buffer, remove from free list */
  237. element = rxq->rx_free.next;
  238. rxb = list_entry(element, struct il_rx_buf, list);
  239. list_del(element);
  240. /* Point to Rx buffer via next RBD in circular buffer */
  241. rxq->bd[rxq->write] =
  242. il4965_dma_addr2rbd_ptr(il, rxb->page_dma);
  243. rxq->queue[rxq->write] = rxb;
  244. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  245. rxq->free_count--;
  246. }
  247. spin_unlock_irqrestore(&rxq->lock, flags);
  248. /* If the pre-allocated buffer pool is dropping low, schedule to
  249. * refill it */
  250. if (rxq->free_count <= RX_LOW_WATERMARK)
  251. queue_work(il->workqueue, &il->rx_replenish);
  252. /* If we've added more space for the firmware to place data, tell it.
  253. * Increment device's write pointer in multiples of 8. */
  254. if (rxq->write_actual != (rxq->write & ~0x7)) {
  255. spin_lock_irqsave(&rxq->lock, flags);
  256. rxq->need_update = 1;
  257. spin_unlock_irqrestore(&rxq->lock, flags);
  258. il_rx_queue_update_write_ptr(il, rxq);
  259. }
  260. }
  261. /**
  262. * il4965_rx_replenish - Move all used packet from rx_used to rx_free
  263. *
  264. * When moving to rx_free an SKB is allocated for the slot.
  265. *
  266. * Also restock the Rx queue via il_rx_queue_restock.
  267. * This is called as a scheduled work item (except for during initialization)
  268. */
  269. static void
  270. il4965_rx_allocate(struct il_priv *il, gfp_t priority)
  271. {
  272. struct il_rx_queue *rxq = &il->rxq;
  273. struct list_head *element;
  274. struct il_rx_buf *rxb;
  275. struct page *page;
  276. unsigned long flags;
  277. gfp_t gfp_mask = priority;
  278. while (1) {
  279. spin_lock_irqsave(&rxq->lock, flags);
  280. if (list_empty(&rxq->rx_used)) {
  281. spin_unlock_irqrestore(&rxq->lock, flags);
  282. return;
  283. }
  284. spin_unlock_irqrestore(&rxq->lock, flags);
  285. if (rxq->free_count > RX_LOW_WATERMARK)
  286. gfp_mask |= __GFP_NOWARN;
  287. if (il->hw_params.rx_page_order > 0)
  288. gfp_mask |= __GFP_COMP;
  289. /* Alloc a new receive buffer */
  290. page = alloc_pages(gfp_mask, il->hw_params.rx_page_order);
  291. if (!page) {
  292. if (net_ratelimit())
  293. D_INFO("alloc_pages failed, " "order: %d\n",
  294. il->hw_params.rx_page_order);
  295. if (rxq->free_count <= RX_LOW_WATERMARK &&
  296. net_ratelimit())
  297. IL_ERR("Failed to alloc_pages with %s. "
  298. "Only %u free buffers remaining.\n",
  299. priority ==
  300. GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  301. rxq->free_count);
  302. /* We don't reschedule replenish work here -- we will
  303. * call the restock method and if it still needs
  304. * more buffers it will schedule replenish */
  305. return;
  306. }
  307. spin_lock_irqsave(&rxq->lock, flags);
  308. if (list_empty(&rxq->rx_used)) {
  309. spin_unlock_irqrestore(&rxq->lock, flags);
  310. __free_pages(page, il->hw_params.rx_page_order);
  311. return;
  312. }
  313. element = rxq->rx_used.next;
  314. rxb = list_entry(element, struct il_rx_buf, list);
  315. list_del(element);
  316. spin_unlock_irqrestore(&rxq->lock, flags);
  317. BUG_ON(rxb->page);
  318. rxb->page = page;
  319. /* Get physical address of the RB */
  320. rxb->page_dma =
  321. pci_map_page(il->pci_dev, page, 0,
  322. PAGE_SIZE << il->hw_params.rx_page_order,
  323. PCI_DMA_FROMDEVICE);
  324. /* dma address must be no more than 36 bits */
  325. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  326. /* and also 256 byte aligned! */
  327. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  328. spin_lock_irqsave(&rxq->lock, flags);
  329. list_add_tail(&rxb->list, &rxq->rx_free);
  330. rxq->free_count++;
  331. il->alloc_rxb_page++;
  332. spin_unlock_irqrestore(&rxq->lock, flags);
  333. }
  334. }
  335. void
  336. il4965_rx_replenish(struct il_priv *il)
  337. {
  338. unsigned long flags;
  339. il4965_rx_allocate(il, GFP_KERNEL);
  340. spin_lock_irqsave(&il->lock, flags);
  341. il4965_rx_queue_restock(il);
  342. spin_unlock_irqrestore(&il->lock, flags);
  343. }
  344. void
  345. il4965_rx_replenish_now(struct il_priv *il)
  346. {
  347. il4965_rx_allocate(il, GFP_ATOMIC);
  348. il4965_rx_queue_restock(il);
  349. }
  350. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  351. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  352. * This free routine walks the list of POOL entries and if SKB is set to
  353. * non NULL it is unmapped and freed
  354. */
  355. void
  356. il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq)
  357. {
  358. int i;
  359. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  360. if (rxq->pool[i].page != NULL) {
  361. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  362. PAGE_SIZE << il->hw_params.rx_page_order,
  363. PCI_DMA_FROMDEVICE);
  364. __il_free_pages(il, rxq->pool[i].page);
  365. rxq->pool[i].page = NULL;
  366. }
  367. }
  368. dma_free_coherent(&il->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  369. rxq->bd_dma);
  370. dma_free_coherent(&il->pci_dev->dev, sizeof(struct il_rb_status),
  371. rxq->rb_stts, rxq->rb_stts_dma);
  372. rxq->bd = NULL;
  373. rxq->rb_stts = NULL;
  374. }
  375. int
  376. il4965_rxq_stop(struct il_priv *il)
  377. {
  378. /* stop Rx DMA */
  379. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  380. il_poll_bit(il, FH49_MEM_RSSR_RX_STATUS_REG,
  381. FH49_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  382. return 0;
  383. }
  384. int
  385. il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  386. {
  387. int idx = 0;
  388. int band_offset = 0;
  389. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  390. if (rate_n_flags & RATE_MCS_HT_MSK) {
  391. idx = (rate_n_flags & 0xff);
  392. return idx;
  393. /* Legacy rate format, search for match in table */
  394. } else {
  395. if (band == IEEE80211_BAND_5GHZ)
  396. band_offset = IL_FIRST_OFDM_RATE;
  397. for (idx = band_offset; idx < RATE_COUNT_LEGACY; idx++)
  398. if (il_rates[idx].plcp == (rate_n_flags & 0xFF))
  399. return idx - band_offset;
  400. }
  401. return -1;
  402. }
  403. static int
  404. il4965_calc_rssi(struct il_priv *il, struct il_rx_phy_res *rx_resp)
  405. {
  406. /* data from PHY/DSP regarding signal strength, etc.,
  407. * contents are always there, not configurable by host. */
  408. struct il4965_rx_non_cfg_phy *ncphy =
  409. (struct il4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  410. u32 agc =
  411. (le16_to_cpu(ncphy->agc_info) & IL49_AGC_DB_MASK) >>
  412. IL49_AGC_DB_POS;
  413. u32 valid_antennae =
  414. (le16_to_cpu(rx_resp->phy_flags) & IL49_RX_PHY_FLAGS_ANTENNAE_MASK)
  415. >> IL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
  416. u8 max_rssi = 0;
  417. u32 i;
  418. /* Find max rssi among 3 possible receivers.
  419. * These values are measured by the digital signal processor (DSP).
  420. * They should stay fairly constant even as the signal strength varies,
  421. * if the radio's automatic gain control (AGC) is working right.
  422. * AGC value (see below) will provide the "interesting" info. */
  423. for (i = 0; i < 3; i++)
  424. if (valid_antennae & (1 << i))
  425. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  426. D_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  427. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  428. max_rssi, agc);
  429. /* dBm = max_rssi dB - agc dB - constant.
  430. * Higher AGC (higher radio gain) means lower signal. */
  431. return max_rssi - agc - IL4965_RSSI_OFFSET;
  432. }
  433. static u32
  434. il4965_translate_rx_status(struct il_priv *il, u32 decrypt_in)
  435. {
  436. u32 decrypt_out = 0;
  437. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  438. RX_RES_STATUS_STATION_FOUND)
  439. decrypt_out |=
  440. (RX_RES_STATUS_STATION_FOUND |
  441. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  442. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  443. /* packet was not encrypted */
  444. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  445. RX_RES_STATUS_SEC_TYPE_NONE)
  446. return decrypt_out;
  447. /* packet was encrypted with unknown alg */
  448. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  449. RX_RES_STATUS_SEC_TYPE_ERR)
  450. return decrypt_out;
  451. /* decryption was not done in HW */
  452. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  453. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  454. return decrypt_out;
  455. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  456. case RX_RES_STATUS_SEC_TYPE_CCMP:
  457. /* alg is CCM: check MIC only */
  458. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  459. /* Bad MIC */
  460. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  461. else
  462. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  463. break;
  464. case RX_RES_STATUS_SEC_TYPE_TKIP:
  465. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  466. /* Bad TTAK */
  467. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  468. break;
  469. }
  470. /* fall through if TTAK OK */
  471. default:
  472. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  473. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  474. else
  475. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  476. break;
  477. }
  478. D_RX("decrypt_in:0x%x decrypt_out = 0x%x\n", decrypt_in, decrypt_out);
  479. return decrypt_out;
  480. }
  481. static void
  482. il4965_pass_packet_to_mac80211(struct il_priv *il, struct ieee80211_hdr *hdr,
  483. u16 len, u32 ampdu_status, struct il_rx_buf *rxb,
  484. struct ieee80211_rx_status *stats)
  485. {
  486. struct sk_buff *skb;
  487. __le16 fc = hdr->frame_control;
  488. /* We only process data packets if the interface is open */
  489. if (unlikely(!il->is_open)) {
  490. D_DROP("Dropping packet while interface is not open.\n");
  491. return;
  492. }
  493. /* In case of HW accelerated crypto and bad decryption, drop */
  494. if (!il->cfg->mod_params->sw_crypto &&
  495. il_set_decrypted_flag(il, hdr, ampdu_status, stats))
  496. return;
  497. skb = dev_alloc_skb(128);
  498. if (!skb) {
  499. IL_ERR("dev_alloc_skb failed\n");
  500. return;
  501. }
  502. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  503. il_update_stats(il, false, fc, len);
  504. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  505. ieee80211_rx(il->hw, skb);
  506. il->alloc_rxb_page--;
  507. rxb->page = NULL;
  508. }
  509. /* Called for N_RX (legacy ABG frames), or
  510. * N_RX_MPDU (HT high-throughput N frames). */
  511. void
  512. il4965_hdl_rx(struct il_priv *il, struct il_rx_buf *rxb)
  513. {
  514. struct ieee80211_hdr *header;
  515. struct ieee80211_rx_status rx_status;
  516. struct il_rx_pkt *pkt = rxb_addr(rxb);
  517. struct il_rx_phy_res *phy_res;
  518. __le32 rx_pkt_status;
  519. struct il_rx_mpdu_res_start *amsdu;
  520. u32 len;
  521. u32 ampdu_status;
  522. u32 rate_n_flags;
  523. /**
  524. * N_RX and N_RX_MPDU are handled differently.
  525. * N_RX: physical layer info is in this buffer
  526. * N_RX_MPDU: physical layer info was sent in separate
  527. * command and cached in il->last_phy_res
  528. *
  529. * Here we set up local variables depending on which command is
  530. * received.
  531. */
  532. if (pkt->hdr.cmd == N_RX) {
  533. phy_res = (struct il_rx_phy_res *)pkt->u.raw;
  534. header =
  535. (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res) +
  536. phy_res->cfg_phy_cnt);
  537. len = le16_to_cpu(phy_res->byte_count);
  538. rx_pkt_status =
  539. *(__le32 *) (pkt->u.raw + sizeof(*phy_res) +
  540. phy_res->cfg_phy_cnt + len);
  541. ampdu_status = le32_to_cpu(rx_pkt_status);
  542. } else {
  543. if (!il->_4965.last_phy_res_valid) {
  544. IL_ERR("MPDU frame without cached PHY data\n");
  545. return;
  546. }
  547. phy_res = &il->_4965.last_phy_res;
  548. amsdu = (struct il_rx_mpdu_res_start *)pkt->u.raw;
  549. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  550. len = le16_to_cpu(amsdu->byte_count);
  551. rx_pkt_status = *(__le32 *) (pkt->u.raw + sizeof(*amsdu) + len);
  552. ampdu_status =
  553. il4965_translate_rx_status(il, le32_to_cpu(rx_pkt_status));
  554. }
  555. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  556. D_DROP("dsp size out of range [0,20]: %d/n",
  557. phy_res->cfg_phy_cnt);
  558. return;
  559. }
  560. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  561. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  562. D_RX("Bad CRC or FIFO: 0x%08X.\n", le32_to_cpu(rx_pkt_status));
  563. return;
  564. }
  565. /* This will be used in several places later */
  566. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  567. /* rx_status carries information about the packet to mac80211 */
  568. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  569. rx_status.band =
  570. (phy_res->
  571. phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? IEEE80211_BAND_2GHZ :
  572. IEEE80211_BAND_5GHZ;
  573. rx_status.freq =
  574. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  575. rx_status.band);
  576. rx_status.rate_idx =
  577. il4965_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  578. rx_status.flag = 0;
  579. /* TSF isn't reliable. In order to allow smooth user experience,
  580. * this W/A doesn't propagate it to the mac80211 */
  581. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU; */
  582. il->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  583. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  584. rx_status.signal = il4965_calc_rssi(il, phy_res);
  585. il_dbg_log_rx_data_frame(il, len, header);
  586. D_STATS("Rssi %d, TSF %llu\n", rx_status.signal,
  587. (unsigned long long)rx_status.mactime);
  588. /*
  589. * "antenna number"
  590. *
  591. * It seems that the antenna field in the phy flags value
  592. * is actually a bit field. This is undefined by radiotap,
  593. * it wants an actual antenna number but I always get "7"
  594. * for most legacy frames I receive indicating that the
  595. * same frame was received on all three RX chains.
  596. *
  597. * I think this field should be removed in favor of a
  598. * new 802.11n radiotap field "RX chains" that is defined
  599. * as a bitmask.
  600. */
  601. rx_status.antenna =
  602. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) >>
  603. RX_RES_PHY_FLAGS_ANTENNA_POS;
  604. /* set the preamble flag if appropriate */
  605. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  606. rx_status.flag |= RX_FLAG_SHORTPRE;
  607. /* Set up the HT phy flags */
  608. if (rate_n_flags & RATE_MCS_HT_MSK)
  609. rx_status.flag |= RX_FLAG_HT;
  610. if (rate_n_flags & RATE_MCS_HT40_MSK)
  611. rx_status.flag |= RX_FLAG_40MHZ;
  612. if (rate_n_flags & RATE_MCS_SGI_MSK)
  613. rx_status.flag |= RX_FLAG_SHORT_GI;
  614. il4965_pass_packet_to_mac80211(il, header, len, ampdu_status, rxb,
  615. &rx_status);
  616. }
  617. /* Cache phy data (Rx signal strength, etc) for HT frame (N_RX_PHY).
  618. * This will be used later in il_hdl_rx() for N_RX_MPDU. */
  619. void
  620. il4965_hdl_rx_phy(struct il_priv *il, struct il_rx_buf *rxb)
  621. {
  622. struct il_rx_pkt *pkt = rxb_addr(rxb);
  623. il->_4965.last_phy_res_valid = true;
  624. memcpy(&il->_4965.last_phy_res, pkt->u.raw,
  625. sizeof(struct il_rx_phy_res));
  626. }
  627. static int
  628. il4965_get_channels_for_scan(struct il_priv *il, struct ieee80211_vif *vif,
  629. enum ieee80211_band band, u8 is_active,
  630. u8 n_probes, struct il_scan_channel *scan_ch)
  631. {
  632. struct ieee80211_channel *chan;
  633. const struct ieee80211_supported_band *sband;
  634. const struct il_channel_info *ch_info;
  635. u16 passive_dwell = 0;
  636. u16 active_dwell = 0;
  637. int added, i;
  638. u16 channel;
  639. sband = il_get_hw_mode(il, band);
  640. if (!sband)
  641. return 0;
  642. active_dwell = il_get_active_dwell_time(il, band, n_probes);
  643. passive_dwell = il_get_passive_dwell_time(il, band, vif);
  644. if (passive_dwell <= active_dwell)
  645. passive_dwell = active_dwell + 1;
  646. for (i = 0, added = 0; i < il->scan_request->n_channels; i++) {
  647. chan = il->scan_request->channels[i];
  648. if (chan->band != band)
  649. continue;
  650. channel = chan->hw_value;
  651. scan_ch->channel = cpu_to_le16(channel);
  652. ch_info = il_get_channel_info(il, band, channel);
  653. if (!il_is_channel_valid(ch_info)) {
  654. D_SCAN("Channel %d is INVALID for this band.\n",
  655. channel);
  656. continue;
  657. }
  658. if (!is_active || il_is_channel_passive(ch_info) ||
  659. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  660. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  661. else
  662. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  663. if (n_probes)
  664. scan_ch->type |= IL_SCAN_PROBE_MASK(n_probes);
  665. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  666. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  667. /* Set txpower levels to defaults */
  668. scan_ch->dsp_atten = 110;
  669. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  670. * power level:
  671. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  672. */
  673. if (band == IEEE80211_BAND_5GHZ)
  674. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  675. else
  676. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  677. D_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n", channel,
  678. le32_to_cpu(scan_ch->type),
  679. (scan_ch->
  680. type & SCAN_CHANNEL_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE",
  681. (scan_ch->
  682. type & SCAN_CHANNEL_TYPE_ACTIVE) ? active_dwell :
  683. passive_dwell);
  684. scan_ch++;
  685. added++;
  686. }
  687. D_SCAN("total channels to scan %d\n", added);
  688. return added;
  689. }
  690. static void
  691. il4965_toggle_tx_ant(struct il_priv *il, u8 *ant, u8 valid)
  692. {
  693. int i;
  694. u8 ind = *ant;
  695. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  696. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  697. if (valid & BIT(ind)) {
  698. *ant = ind;
  699. return;
  700. }
  701. }
  702. }
  703. int
  704. il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif)
  705. {
  706. struct il_host_cmd cmd = {
  707. .id = C_SCAN,
  708. .len = sizeof(struct il_scan_cmd),
  709. .flags = CMD_SIZE_HUGE,
  710. };
  711. struct il_scan_cmd *scan;
  712. u32 rate_flags = 0;
  713. u16 cmd_len;
  714. u16 rx_chain = 0;
  715. enum ieee80211_band band;
  716. u8 n_probes = 0;
  717. u8 rx_ant = il->hw_params.valid_rx_ant;
  718. u8 rate;
  719. bool is_active = false;
  720. int chan_mod;
  721. u8 active_chains;
  722. u8 scan_tx_antennas = il->hw_params.valid_tx_ant;
  723. int ret;
  724. lockdep_assert_held(&il->mutex);
  725. if (!il->scan_cmd) {
  726. il->scan_cmd =
  727. kmalloc(sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE,
  728. GFP_KERNEL);
  729. if (!il->scan_cmd) {
  730. D_SCAN("fail to allocate memory for scan\n");
  731. return -ENOMEM;
  732. }
  733. }
  734. scan = il->scan_cmd;
  735. memset(scan, 0, sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE);
  736. scan->quiet_plcp_th = IL_PLCP_QUIET_THRESH;
  737. scan->quiet_time = IL_ACTIVE_QUIET_TIME;
  738. if (il_is_any_associated(il)) {
  739. u16 interval;
  740. u32 extra;
  741. u32 suspend_time = 100;
  742. u32 scan_suspend_time = 100;
  743. D_INFO("Scanning while associated...\n");
  744. interval = vif->bss_conf.beacon_int;
  745. scan->suspend_time = 0;
  746. scan->max_out_time = cpu_to_le32(200 * 1024);
  747. if (!interval)
  748. interval = suspend_time;
  749. extra = (suspend_time / interval) << 22;
  750. scan_suspend_time =
  751. (extra | ((suspend_time % interval) * 1024));
  752. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  753. D_SCAN("suspend_time 0x%X beacon interval %d\n",
  754. scan_suspend_time, interval);
  755. }
  756. if (il->scan_request->n_ssids) {
  757. int i, p = 0;
  758. D_SCAN("Kicking off active scan\n");
  759. for (i = 0; i < il->scan_request->n_ssids; i++) {
  760. /* always does wildcard anyway */
  761. if (!il->scan_request->ssids[i].ssid_len)
  762. continue;
  763. scan->direct_scan[p].id = WLAN_EID_SSID;
  764. scan->direct_scan[p].len =
  765. il->scan_request->ssids[i].ssid_len;
  766. memcpy(scan->direct_scan[p].ssid,
  767. il->scan_request->ssids[i].ssid,
  768. il->scan_request->ssids[i].ssid_len);
  769. n_probes++;
  770. p++;
  771. }
  772. is_active = true;
  773. } else
  774. D_SCAN("Start passive scan.\n");
  775. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  776. scan->tx_cmd.sta_id = il->hw_params.bcast_id;
  777. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  778. switch (il->scan_band) {
  779. case IEEE80211_BAND_2GHZ:
  780. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  781. chan_mod =
  782. le32_to_cpu(il->active.flags & RXON_FLG_CHANNEL_MODE_MSK) >>
  783. RXON_FLG_CHANNEL_MODE_POS;
  784. if (chan_mod == CHANNEL_MODE_PURE_40) {
  785. rate = RATE_6M_PLCP;
  786. } else {
  787. rate = RATE_1M_PLCP;
  788. rate_flags = RATE_MCS_CCK_MSK;
  789. }
  790. break;
  791. case IEEE80211_BAND_5GHZ:
  792. rate = RATE_6M_PLCP;
  793. break;
  794. default:
  795. IL_WARN("Invalid scan band\n");
  796. return -EIO;
  797. }
  798. /*
  799. * If active scanning is requested but a certain channel is
  800. * marked passive, we can do active scanning if we detect
  801. * transmissions.
  802. *
  803. * There is an issue with some firmware versions that triggers
  804. * a sysassert on a "good CRC threshold" of zero (== disabled),
  805. * on a radar channel even though this means that we should NOT
  806. * send probes.
  807. *
  808. * The "good CRC threshold" is the number of frames that we
  809. * need to receive during our dwell time on a channel before
  810. * sending out probes -- setting this to a huge value will
  811. * mean we never reach it, but at the same time work around
  812. * the aforementioned issue. Thus use IL_GOOD_CRC_TH_NEVER
  813. * here instead of IL_GOOD_CRC_TH_DISABLED.
  814. */
  815. scan->good_CRC_th =
  816. is_active ? IL_GOOD_CRC_TH_DEFAULT : IL_GOOD_CRC_TH_NEVER;
  817. band = il->scan_band;
  818. if (il->cfg->scan_rx_antennas[band])
  819. rx_ant = il->cfg->scan_rx_antennas[band];
  820. il4965_toggle_tx_ant(il, &il->scan_tx_ant[band], scan_tx_antennas);
  821. rate_flags |= BIT(il->scan_tx_ant[band]) << RATE_MCS_ANT_POS;
  822. scan->tx_cmd.rate_n_flags = cpu_to_le32(rate | rate_flags);
  823. /* In power save mode use one chain, otherwise use all chains */
  824. if (test_bit(S_POWER_PMI, &il->status)) {
  825. /* rx_ant has been set to all valid chains previously */
  826. active_chains =
  827. rx_ant & ((u8) (il->chain_noise_data.active_chains));
  828. if (!active_chains)
  829. active_chains = rx_ant;
  830. D_SCAN("chain_noise_data.active_chains: %u\n",
  831. il->chain_noise_data.active_chains);
  832. rx_ant = il4965_first_antenna(active_chains);
  833. }
  834. /* MIMO is not used here, but value is required */
  835. rx_chain |= il->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  836. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  837. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  838. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  839. scan->rx_chain = cpu_to_le16(rx_chain);
  840. cmd_len =
  841. il_fill_probe_req(il, (struct ieee80211_mgmt *)scan->data,
  842. vif->addr, il->scan_request->ie,
  843. il->scan_request->ie_len,
  844. IL_MAX_SCAN_SIZE - sizeof(*scan));
  845. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  846. scan->filter_flags |=
  847. (RXON_FILTER_ACCEPT_GRP_MSK | RXON_FILTER_BCON_AWARE_MSK);
  848. scan->channel_count =
  849. il4965_get_channels_for_scan(il, vif, band, is_active, n_probes,
  850. (void *)&scan->data[cmd_len]);
  851. if (scan->channel_count == 0) {
  852. D_SCAN("channel count %d\n", scan->channel_count);
  853. return -EIO;
  854. }
  855. cmd.len +=
  856. le16_to_cpu(scan->tx_cmd.len) +
  857. scan->channel_count * sizeof(struct il_scan_channel);
  858. cmd.data = scan;
  859. scan->len = cpu_to_le16(cmd.len);
  860. set_bit(S_SCAN_HW, &il->status);
  861. ret = il_send_cmd_sync(il, &cmd);
  862. if (ret)
  863. clear_bit(S_SCAN_HW, &il->status);
  864. return ret;
  865. }
  866. int
  867. il4965_manage_ibss_station(struct il_priv *il, struct ieee80211_vif *vif,
  868. bool add)
  869. {
  870. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  871. if (add)
  872. return il4965_add_bssid_station(il, vif->bss_conf.bssid,
  873. &vif_priv->ibss_bssid_sta_id);
  874. return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
  875. vif->bss_conf.bssid);
  876. }
  877. void
  878. il4965_free_tfds_in_queue(struct il_priv *il, int sta_id, int tid, int freed)
  879. {
  880. lockdep_assert_held(&il->sta_lock);
  881. if (il->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  882. il->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  883. else {
  884. D_TX("free more than tfds_in_queue (%u:%d)\n",
  885. il->stations[sta_id].tid[tid].tfds_in_queue, freed);
  886. il->stations[sta_id].tid[tid].tfds_in_queue = 0;
  887. }
  888. }
  889. #define IL_TX_QUEUE_MSK 0xfffff
  890. static bool
  891. il4965_is_single_rx_stream(struct il_priv *il)
  892. {
  893. return il->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  894. il->current_ht_config.single_chain_sufficient;
  895. }
  896. #define IL_NUM_RX_CHAINS_MULTIPLE 3
  897. #define IL_NUM_RX_CHAINS_SINGLE 2
  898. #define IL_NUM_IDLE_CHAINS_DUAL 2
  899. #define IL_NUM_IDLE_CHAINS_SINGLE 1
  900. /*
  901. * Determine how many receiver/antenna chains to use.
  902. *
  903. * More provides better reception via diversity. Fewer saves power
  904. * at the expense of throughput, but only when not in powersave to
  905. * start with.
  906. *
  907. * MIMO (dual stream) requires at least 2, but works better with 3.
  908. * This does not determine *which* chains to use, just how many.
  909. */
  910. static int
  911. il4965_get_active_rx_chain_count(struct il_priv *il)
  912. {
  913. /* # of Rx chains to use when expecting MIMO. */
  914. if (il4965_is_single_rx_stream(il))
  915. return IL_NUM_RX_CHAINS_SINGLE;
  916. else
  917. return IL_NUM_RX_CHAINS_MULTIPLE;
  918. }
  919. /*
  920. * When we are in power saving mode, unless device support spatial
  921. * multiplexing power save, use the active count for rx chain count.
  922. */
  923. static int
  924. il4965_get_idle_rx_chain_count(struct il_priv *il, int active_cnt)
  925. {
  926. /* # Rx chains when idling, depending on SMPS mode */
  927. switch (il->current_ht_config.smps) {
  928. case IEEE80211_SMPS_STATIC:
  929. case IEEE80211_SMPS_DYNAMIC:
  930. return IL_NUM_IDLE_CHAINS_SINGLE;
  931. case IEEE80211_SMPS_OFF:
  932. return active_cnt;
  933. default:
  934. WARN(1, "invalid SMPS mode %d", il->current_ht_config.smps);
  935. return active_cnt;
  936. }
  937. }
  938. /* up to 4 chains */
  939. static u8
  940. il4965_count_chain_bitmap(u32 chain_bitmap)
  941. {
  942. u8 res;
  943. res = (chain_bitmap & BIT(0)) >> 0;
  944. res += (chain_bitmap & BIT(1)) >> 1;
  945. res += (chain_bitmap & BIT(2)) >> 2;
  946. res += (chain_bitmap & BIT(3)) >> 3;
  947. return res;
  948. }
  949. /**
  950. * il4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  951. *
  952. * Selects how many and which Rx receivers/antennas/chains to use.
  953. * This should not be used for scan command ... it puts data in wrong place.
  954. */
  955. void
  956. il4965_set_rxon_chain(struct il_priv *il)
  957. {
  958. bool is_single = il4965_is_single_rx_stream(il);
  959. bool is_cam = !test_bit(S_POWER_PMI, &il->status);
  960. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  961. u32 active_chains;
  962. u16 rx_chain;
  963. /* Tell uCode which antennas are actually connected.
  964. * Before first association, we assume all antennas are connected.
  965. * Just after first association, il4965_chain_noise_calibration()
  966. * checks which antennas actually *are* connected. */
  967. if (il->chain_noise_data.active_chains)
  968. active_chains = il->chain_noise_data.active_chains;
  969. else
  970. active_chains = il->hw_params.valid_rx_ant;
  971. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  972. /* How many receivers should we use? */
  973. active_rx_cnt = il4965_get_active_rx_chain_count(il);
  974. idle_rx_cnt = il4965_get_idle_rx_chain_count(il, active_rx_cnt);
  975. /* correct rx chain count according hw settings
  976. * and chain noise calibration
  977. */
  978. valid_rx_cnt = il4965_count_chain_bitmap(active_chains);
  979. if (valid_rx_cnt < active_rx_cnt)
  980. active_rx_cnt = valid_rx_cnt;
  981. if (valid_rx_cnt < idle_rx_cnt)
  982. idle_rx_cnt = valid_rx_cnt;
  983. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  984. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  985. il->staging.rx_chain = cpu_to_le16(rx_chain);
  986. if (!is_single && active_rx_cnt >= IL_NUM_RX_CHAINS_SINGLE && is_cam)
  987. il->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  988. else
  989. il->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  990. D_ASSOC("rx_chain=0x%X active=%d idle=%d\n", il->staging.rx_chain,
  991. active_rx_cnt, idle_rx_cnt);
  992. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  993. active_rx_cnt < idle_rx_cnt);
  994. }
  995. static const char *
  996. il4965_get_fh_string(int cmd)
  997. {
  998. switch (cmd) {
  999. IL_CMD(FH49_RSCSR_CHNL0_STTS_WPTR_REG);
  1000. IL_CMD(FH49_RSCSR_CHNL0_RBDCB_BASE_REG);
  1001. IL_CMD(FH49_RSCSR_CHNL0_WPTR);
  1002. IL_CMD(FH49_MEM_RCSR_CHNL0_CONFIG_REG);
  1003. IL_CMD(FH49_MEM_RSSR_SHARED_CTRL_REG);
  1004. IL_CMD(FH49_MEM_RSSR_RX_STATUS_REG);
  1005. IL_CMD(FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1006. IL_CMD(FH49_TSSR_TX_STATUS_REG);
  1007. IL_CMD(FH49_TSSR_TX_ERROR_REG);
  1008. default:
  1009. return "UNKNOWN";
  1010. }
  1011. }
  1012. int
  1013. il4965_dump_fh(struct il_priv *il, char **buf, bool display)
  1014. {
  1015. int i;
  1016. #ifdef CONFIG_IWLEGACY_DEBUG
  1017. int pos = 0;
  1018. size_t bufsz = 0;
  1019. #endif
  1020. static const u32 fh_tbl[] = {
  1021. FH49_RSCSR_CHNL0_STTS_WPTR_REG,
  1022. FH49_RSCSR_CHNL0_RBDCB_BASE_REG,
  1023. FH49_RSCSR_CHNL0_WPTR,
  1024. FH49_MEM_RCSR_CHNL0_CONFIG_REG,
  1025. FH49_MEM_RSSR_SHARED_CTRL_REG,
  1026. FH49_MEM_RSSR_RX_STATUS_REG,
  1027. FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1028. FH49_TSSR_TX_STATUS_REG,
  1029. FH49_TSSR_TX_ERROR_REG
  1030. };
  1031. #ifdef CONFIG_IWLEGACY_DEBUG
  1032. if (display) {
  1033. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1034. *buf = kmalloc(bufsz, GFP_KERNEL);
  1035. if (!*buf)
  1036. return -ENOMEM;
  1037. pos +=
  1038. scnprintf(*buf + pos, bufsz - pos, "FH register values:\n");
  1039. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1040. pos +=
  1041. scnprintf(*buf + pos, bufsz - pos,
  1042. " %34s: 0X%08x\n",
  1043. il4965_get_fh_string(fh_tbl[i]),
  1044. il_rd(il, fh_tbl[i]));
  1045. }
  1046. return pos;
  1047. }
  1048. #endif
  1049. IL_ERR("FH register values:\n");
  1050. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1051. IL_ERR(" %34s: 0X%08x\n", il4965_get_fh_string(fh_tbl[i]),
  1052. il_rd(il, fh_tbl[i]));
  1053. }
  1054. return 0;
  1055. }
  1056. void
  1057. il4965_hdl_missed_beacon(struct il_priv *il, struct il_rx_buf *rxb)
  1058. {
  1059. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1060. struct il_missed_beacon_notif *missed_beacon;
  1061. missed_beacon = &pkt->u.missed_beacon;
  1062. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  1063. il->missed_beacon_threshold) {
  1064. D_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  1065. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  1066. le32_to_cpu(missed_beacon->total_missed_becons),
  1067. le32_to_cpu(missed_beacon->num_recvd_beacons),
  1068. le32_to_cpu(missed_beacon->num_expected_beacons));
  1069. if (!test_bit(S_SCANNING, &il->status))
  1070. il4965_init_sensitivity(il);
  1071. }
  1072. }
  1073. /* Calculate noise level, based on measurements during network silence just
  1074. * before arriving beacon. This measurement can be done only if we know
  1075. * exactly when to expect beacons, therefore only when we're associated. */
  1076. static void
  1077. il4965_rx_calc_noise(struct il_priv *il)
  1078. {
  1079. struct stats_rx_non_phy *rx_info;
  1080. int num_active_rx = 0;
  1081. int total_silence = 0;
  1082. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  1083. int last_rx_noise;
  1084. rx_info = &(il->_4965.stats.rx.general);
  1085. bcn_silence_a =
  1086. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  1087. bcn_silence_b =
  1088. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  1089. bcn_silence_c =
  1090. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  1091. if (bcn_silence_a) {
  1092. total_silence += bcn_silence_a;
  1093. num_active_rx++;
  1094. }
  1095. if (bcn_silence_b) {
  1096. total_silence += bcn_silence_b;
  1097. num_active_rx++;
  1098. }
  1099. if (bcn_silence_c) {
  1100. total_silence += bcn_silence_c;
  1101. num_active_rx++;
  1102. }
  1103. /* Average among active antennas */
  1104. if (num_active_rx)
  1105. last_rx_noise = (total_silence / num_active_rx) - 107;
  1106. else
  1107. last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE;
  1108. D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", bcn_silence_a,
  1109. bcn_silence_b, bcn_silence_c, last_rx_noise);
  1110. }
  1111. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1112. /*
  1113. * based on the assumption of all stats counter are in DWORD
  1114. * FIXME: This function is for debugging, do not deal with
  1115. * the case of counters roll-over.
  1116. */
  1117. static void
  1118. il4965_accumulative_stats(struct il_priv *il, __le32 * stats)
  1119. {
  1120. int i, size;
  1121. __le32 *prev_stats;
  1122. u32 *accum_stats;
  1123. u32 *delta, *max_delta;
  1124. struct stats_general_common *general, *accum_general;
  1125. struct stats_tx *tx, *accum_tx;
  1126. prev_stats = (__le32 *) &il->_4965.stats;
  1127. accum_stats = (u32 *) &il->_4965.accum_stats;
  1128. size = sizeof(struct il_notif_stats);
  1129. general = &il->_4965.stats.general.common;
  1130. accum_general = &il->_4965.accum_stats.general.common;
  1131. tx = &il->_4965.stats.tx;
  1132. accum_tx = &il->_4965.accum_stats.tx;
  1133. delta = (u32 *) &il->_4965.delta_stats;
  1134. max_delta = (u32 *) &il->_4965.max_delta;
  1135. for (i = sizeof(__le32); i < size;
  1136. i +=
  1137. sizeof(__le32), stats++, prev_stats++, delta++, max_delta++,
  1138. accum_stats++) {
  1139. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  1140. *delta =
  1141. (le32_to_cpu(*stats) - le32_to_cpu(*prev_stats));
  1142. *accum_stats += *delta;
  1143. if (*delta > *max_delta)
  1144. *max_delta = *delta;
  1145. }
  1146. }
  1147. /* reset accumulative stats for "no-counter" type stats */
  1148. accum_general->temperature = general->temperature;
  1149. accum_general->ttl_timestamp = general->ttl_timestamp;
  1150. }
  1151. #endif
  1152. #define REG_RECALIB_PERIOD (60)
  1153. void
  1154. il4965_hdl_stats(struct il_priv *il, struct il_rx_buf *rxb)
  1155. {
  1156. int change;
  1157. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1158. D_RX("Statistics notification received (%d vs %d).\n",
  1159. (int)sizeof(struct il_notif_stats),
  1160. le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK);
  1161. change =
  1162. ((il->_4965.stats.general.common.temperature !=
  1163. pkt->u.stats.general.common.temperature) ||
  1164. ((il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK) !=
  1165. (pkt->u.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK)));
  1166. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1167. il4965_accumulative_stats(il, (__le32 *) &pkt->u.stats);
  1168. #endif
  1169. /* TODO: reading some of stats is unneeded */
  1170. memcpy(&il->_4965.stats, &pkt->u.stats, sizeof(il->_4965.stats));
  1171. set_bit(S_STATS, &il->status);
  1172. /* Reschedule the stats timer to occur in
  1173. * REG_RECALIB_PERIOD seconds to ensure we get a
  1174. * thermal update even if the uCode doesn't give
  1175. * us one */
  1176. mod_timer(&il->stats_periodic,
  1177. jiffies + msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  1178. if (unlikely(!test_bit(S_SCANNING, &il->status)) &&
  1179. (pkt->hdr.cmd == N_STATS)) {
  1180. il4965_rx_calc_noise(il);
  1181. queue_work(il->workqueue, &il->run_time_calib_work);
  1182. }
  1183. if (il->ops->lib->temp_ops.temperature && change)
  1184. il->ops->lib->temp_ops.temperature(il);
  1185. }
  1186. void
  1187. il4965_hdl_c_stats(struct il_priv *il, struct il_rx_buf *rxb)
  1188. {
  1189. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1190. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATS_CLEAR_MSK) {
  1191. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1192. memset(&il->_4965.accum_stats, 0,
  1193. sizeof(struct il_notif_stats));
  1194. memset(&il->_4965.delta_stats, 0,
  1195. sizeof(struct il_notif_stats));
  1196. memset(&il->_4965.max_delta, 0, sizeof(struct il_notif_stats));
  1197. #endif
  1198. D_RX("Statistics have been cleared\n");
  1199. }
  1200. il4965_hdl_stats(il, rxb);
  1201. }
  1202. /*
  1203. * mac80211 queues, ACs, hardware queues, FIFOs.
  1204. *
  1205. * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
  1206. *
  1207. * Mac80211 uses the following numbers, which we get as from it
  1208. * by way of skb_get_queue_mapping(skb):
  1209. *
  1210. * VO 0
  1211. * VI 1
  1212. * BE 2
  1213. * BK 3
  1214. *
  1215. *
  1216. * Regular (not A-MPDU) frames are put into hardware queues corresponding
  1217. * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their
  1218. * own queue per aggregation session (RA/TID combination), such queues are
  1219. * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In
  1220. * order to map frames to the right queue, we also need an AC->hw queue
  1221. * mapping. This is implemented here.
  1222. *
  1223. * Due to the way hw queues are set up (by the hw specific modules like
  1224. * 4965.c), the AC->hw queue mapping is the identity
  1225. * mapping.
  1226. */
  1227. static const u8 tid_to_ac[] = {
  1228. IEEE80211_AC_BE,
  1229. IEEE80211_AC_BK,
  1230. IEEE80211_AC_BK,
  1231. IEEE80211_AC_BE,
  1232. IEEE80211_AC_VI,
  1233. IEEE80211_AC_VI,
  1234. IEEE80211_AC_VO,
  1235. IEEE80211_AC_VO
  1236. };
  1237. static inline int
  1238. il4965_get_ac_from_tid(u16 tid)
  1239. {
  1240. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1241. return tid_to_ac[tid];
  1242. /* no support for TIDs 8-15 yet */
  1243. return -EINVAL;
  1244. }
  1245. static inline int
  1246. il4965_get_fifo_from_tid(u16 tid)
  1247. {
  1248. const u8 ac_to_fifo[] = {
  1249. IL_TX_FIFO_VO,
  1250. IL_TX_FIFO_VI,
  1251. IL_TX_FIFO_BE,
  1252. IL_TX_FIFO_BK,
  1253. };
  1254. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1255. return ac_to_fifo[tid_to_ac[tid]];
  1256. /* no support for TIDs 8-15 yet */
  1257. return -EINVAL;
  1258. }
  1259. /*
  1260. * handle build C_TX command notification.
  1261. */
  1262. static void
  1263. il4965_tx_cmd_build_basic(struct il_priv *il, struct sk_buff *skb,
  1264. struct il_tx_cmd *tx_cmd,
  1265. struct ieee80211_tx_info *info,
  1266. struct ieee80211_hdr *hdr, u8 std_id)
  1267. {
  1268. __le16 fc = hdr->frame_control;
  1269. __le32 tx_flags = tx_cmd->tx_flags;
  1270. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1271. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  1272. tx_flags |= TX_CMD_FLG_ACK_MSK;
  1273. if (ieee80211_is_mgmt(fc))
  1274. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1275. if (ieee80211_is_probe_resp(fc) &&
  1276. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  1277. tx_flags |= TX_CMD_FLG_TSF_MSK;
  1278. } else {
  1279. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  1280. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1281. }
  1282. if (ieee80211_is_back_req(fc))
  1283. tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
  1284. tx_cmd->sta_id = std_id;
  1285. if (ieee80211_has_morefrags(fc))
  1286. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  1287. if (ieee80211_is_data_qos(fc)) {
  1288. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1289. tx_cmd->tid_tspec = qc[0] & 0xf;
  1290. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  1291. } else {
  1292. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1293. }
  1294. il_tx_cmd_protection(il, info, fc, &tx_flags);
  1295. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  1296. if (ieee80211_is_mgmt(fc)) {
  1297. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  1298. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  1299. else
  1300. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  1301. } else {
  1302. tx_cmd->timeout.pm_frame_timeout = 0;
  1303. }
  1304. tx_cmd->driver_txop = 0;
  1305. tx_cmd->tx_flags = tx_flags;
  1306. tx_cmd->next_frame_len = 0;
  1307. }
  1308. static void
  1309. il4965_tx_cmd_build_rate(struct il_priv *il, struct il_tx_cmd *tx_cmd,
  1310. struct ieee80211_tx_info *info, __le16 fc)
  1311. {
  1312. const u8 rts_retry_limit = 60;
  1313. u32 rate_flags;
  1314. int rate_idx;
  1315. u8 data_retry_limit;
  1316. u8 rate_plcp;
  1317. /* Set retry limit on DATA packets and Probe Responses */
  1318. if (ieee80211_is_probe_resp(fc))
  1319. data_retry_limit = 3;
  1320. else
  1321. data_retry_limit = IL4965_DEFAULT_TX_RETRY;
  1322. tx_cmd->data_retry_limit = data_retry_limit;
  1323. /* Set retry limit on RTS packets */
  1324. tx_cmd->rts_retry_limit = min(data_retry_limit, rts_retry_limit);
  1325. /* DATA packets will use the uCode station table for rate/antenna
  1326. * selection */
  1327. if (ieee80211_is_data(fc)) {
  1328. tx_cmd->initial_rate_idx = 0;
  1329. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  1330. return;
  1331. }
  1332. /**
  1333. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  1334. * not really a TX rate. Thus, we use the lowest supported rate for
  1335. * this band. Also use the lowest supported rate if the stored rate
  1336. * idx is invalid.
  1337. */
  1338. rate_idx = info->control.rates[0].idx;
  1339. if ((info->control.rates[0].flags & IEEE80211_TX_RC_MCS) || rate_idx < 0
  1340. || rate_idx > RATE_COUNT_LEGACY)
  1341. rate_idx =
  1342. rate_lowest_index(&il->bands[info->band],
  1343. info->control.sta);
  1344. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  1345. if (info->band == IEEE80211_BAND_5GHZ)
  1346. rate_idx += IL_FIRST_OFDM_RATE;
  1347. /* Get PLCP rate for tx_cmd->rate_n_flags */
  1348. rate_plcp = il_rates[rate_idx].plcp;
  1349. /* Zero out flags for this packet */
  1350. rate_flags = 0;
  1351. /* Set CCK flag as needed */
  1352. if (rate_idx >= IL_FIRST_CCK_RATE && rate_idx <= IL_LAST_CCK_RATE)
  1353. rate_flags |= RATE_MCS_CCK_MSK;
  1354. /* Set up antennas */
  1355. il4965_toggle_tx_ant(il, &il->mgmt_tx_ant, il->hw_params.valid_tx_ant);
  1356. rate_flags |= BIT(il->mgmt_tx_ant) << RATE_MCS_ANT_POS;
  1357. /* Set the rate in the TX cmd */
  1358. tx_cmd->rate_n_flags = cpu_to_le32(rate_plcp | rate_flags);
  1359. }
  1360. static void
  1361. il4965_tx_cmd_build_hwcrypto(struct il_priv *il, struct ieee80211_tx_info *info,
  1362. struct il_tx_cmd *tx_cmd, struct sk_buff *skb_frag,
  1363. int sta_id)
  1364. {
  1365. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  1366. switch (keyconf->cipher) {
  1367. case WLAN_CIPHER_SUITE_CCMP:
  1368. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  1369. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  1370. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1371. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  1372. D_TX("tx_cmd with AES hwcrypto\n");
  1373. break;
  1374. case WLAN_CIPHER_SUITE_TKIP:
  1375. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  1376. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  1377. D_TX("tx_cmd with tkip hwcrypto\n");
  1378. break;
  1379. case WLAN_CIPHER_SUITE_WEP104:
  1380. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  1381. /* fall through */
  1382. case WLAN_CIPHER_SUITE_WEP40:
  1383. tx_cmd->sec_ctl |=
  1384. (TX_CMD_SEC_WEP | (keyconf->keyidx & TX_CMD_SEC_MSK) <<
  1385. TX_CMD_SEC_SHIFT);
  1386. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  1387. D_TX("Configuring packet for WEP encryption " "with key %d\n",
  1388. keyconf->keyidx);
  1389. break;
  1390. default:
  1391. IL_ERR("Unknown encode cipher %x\n", keyconf->cipher);
  1392. break;
  1393. }
  1394. }
  1395. /*
  1396. * start C_TX command process
  1397. */
  1398. int
  1399. il4965_tx_skb(struct il_priv *il, struct sk_buff *skb)
  1400. {
  1401. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1402. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1403. struct ieee80211_sta *sta = info->control.sta;
  1404. struct il_station_priv *sta_priv = NULL;
  1405. struct il_tx_queue *txq;
  1406. struct il_queue *q;
  1407. struct il_device_cmd *out_cmd;
  1408. struct il_cmd_meta *out_meta;
  1409. struct il_tx_cmd *tx_cmd;
  1410. int txq_id;
  1411. dma_addr_t phys_addr;
  1412. dma_addr_t txcmd_phys;
  1413. dma_addr_t scratch_phys;
  1414. u16 len, firstlen, secondlen;
  1415. u16 seq_number = 0;
  1416. __le16 fc;
  1417. u8 hdr_len;
  1418. u8 sta_id;
  1419. u8 wait_write_ptr = 0;
  1420. u8 tid = 0;
  1421. u8 *qc = NULL;
  1422. unsigned long flags;
  1423. bool is_agg = false;
  1424. spin_lock_irqsave(&il->lock, flags);
  1425. if (il_is_rfkill(il)) {
  1426. D_DROP("Dropping - RF KILL\n");
  1427. goto drop_unlock;
  1428. }
  1429. fc = hdr->frame_control;
  1430. #ifdef CONFIG_IWLEGACY_DEBUG
  1431. if (ieee80211_is_auth(fc))
  1432. D_TX("Sending AUTH frame\n");
  1433. else if (ieee80211_is_assoc_req(fc))
  1434. D_TX("Sending ASSOC frame\n");
  1435. else if (ieee80211_is_reassoc_req(fc))
  1436. D_TX("Sending REASSOC frame\n");
  1437. #endif
  1438. hdr_len = ieee80211_hdrlen(fc);
  1439. /* For management frames use broadcast id to do not break aggregation */
  1440. if (!ieee80211_is_data(fc))
  1441. sta_id = il->hw_params.bcast_id;
  1442. else {
  1443. /* Find idx into station table for destination station */
  1444. sta_id = il_sta_id_or_broadcast(il, info->control.sta);
  1445. if (sta_id == IL_INVALID_STATION) {
  1446. D_DROP("Dropping - INVALID STATION: %pM\n", hdr->addr1);
  1447. goto drop_unlock;
  1448. }
  1449. }
  1450. D_TX("station Id %d\n", sta_id);
  1451. if (sta)
  1452. sta_priv = (void *)sta->drv_priv;
  1453. if (sta_priv && sta_priv->asleep &&
  1454. (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) {
  1455. /*
  1456. * This sends an asynchronous command to the device,
  1457. * but we can rely on it being processed before the
  1458. * next frame is processed -- and the next frame to
  1459. * this station is the one that will consume this
  1460. * counter.
  1461. * For now set the counter to just 1 since we do not
  1462. * support uAPSD yet.
  1463. */
  1464. il4965_sta_modify_sleep_tx_count(il, sta_id, 1);
  1465. }
  1466. /* FIXME: remove me ? */
  1467. WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM);
  1468. /* Access category (AC) is also the queue number */
  1469. txq_id = skb_get_queue_mapping(skb);
  1470. /* irqs already disabled/saved above when locking il->lock */
  1471. spin_lock(&il->sta_lock);
  1472. if (ieee80211_is_data_qos(fc)) {
  1473. qc = ieee80211_get_qos_ctl(hdr);
  1474. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  1475. if (WARN_ON_ONCE(tid >= MAX_TID_COUNT)) {
  1476. spin_unlock(&il->sta_lock);
  1477. goto drop_unlock;
  1478. }
  1479. seq_number = il->stations[sta_id].tid[tid].seq_number;
  1480. seq_number &= IEEE80211_SCTL_SEQ;
  1481. hdr->seq_ctrl =
  1482. hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG);
  1483. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  1484. seq_number += 0x10;
  1485. /* aggregation is on for this <sta,tid> */
  1486. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  1487. il->stations[sta_id].tid[tid].agg.state == IL_AGG_ON) {
  1488. txq_id = il->stations[sta_id].tid[tid].agg.txq_id;
  1489. is_agg = true;
  1490. }
  1491. }
  1492. txq = &il->txq[txq_id];
  1493. q = &txq->q;
  1494. if (unlikely(il_queue_space(q) < q->high_mark)) {
  1495. spin_unlock(&il->sta_lock);
  1496. goto drop_unlock;
  1497. }
  1498. if (ieee80211_is_data_qos(fc)) {
  1499. il->stations[sta_id].tid[tid].tfds_in_queue++;
  1500. if (!ieee80211_has_morefrags(fc))
  1501. il->stations[sta_id].tid[tid].seq_number = seq_number;
  1502. }
  1503. spin_unlock(&il->sta_lock);
  1504. txq->skbs[q->write_ptr] = skb;
  1505. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  1506. out_cmd = txq->cmd[q->write_ptr];
  1507. out_meta = &txq->meta[q->write_ptr];
  1508. tx_cmd = &out_cmd->cmd.tx;
  1509. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  1510. memset(tx_cmd, 0, sizeof(struct il_tx_cmd));
  1511. /*
  1512. * Set up the Tx-command (not MAC!) header.
  1513. * Store the chosen Tx queue and TFD idx within the sequence field;
  1514. * after Tx, uCode's Tx response will return this value so driver can
  1515. * locate the frame within the tx queue and do post-tx processing.
  1516. */
  1517. out_cmd->hdr.cmd = C_TX;
  1518. out_cmd->hdr.sequence =
  1519. cpu_to_le16((u16)
  1520. (QUEUE_TO_SEQ(txq_id) | IDX_TO_SEQ(q->write_ptr)));
  1521. /* Copy MAC header from skb into command buffer */
  1522. memcpy(tx_cmd->hdr, hdr, hdr_len);
  1523. /* Total # bytes to be transmitted */
  1524. len = (u16) skb->len;
  1525. tx_cmd->len = cpu_to_le16(len);
  1526. if (info->control.hw_key)
  1527. il4965_tx_cmd_build_hwcrypto(il, info, tx_cmd, skb, sta_id);
  1528. /* TODO need this for burst mode later on */
  1529. il4965_tx_cmd_build_basic(il, skb, tx_cmd, info, hdr, sta_id);
  1530. il_dbg_log_tx_data_frame(il, len, hdr);
  1531. il4965_tx_cmd_build_rate(il, tx_cmd, info, fc);
  1532. il_update_stats(il, true, fc, len);
  1533. /*
  1534. * Use the first empty entry in this queue's command buffer array
  1535. * to contain the Tx command and MAC header concatenated together
  1536. * (payload data will be in another buffer).
  1537. * Size of this varies, due to varying MAC header length.
  1538. * If end is not dword aligned, we'll have 2 extra bytes at the end
  1539. * of the MAC header (device reads on dword boundaries).
  1540. * We'll tell device about this padding later.
  1541. */
  1542. len = sizeof(struct il_tx_cmd) + sizeof(struct il_cmd_header) + hdr_len;
  1543. firstlen = (len + 3) & ~3;
  1544. /* Tell NIC about any 2-byte padding after MAC header */
  1545. if (firstlen != len)
  1546. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  1547. /* Physical address of this Tx command's header (not MAC header!),
  1548. * within command buffer array. */
  1549. txcmd_phys =
  1550. pci_map_single(il->pci_dev, &out_cmd->hdr, firstlen,
  1551. PCI_DMA_BIDIRECTIONAL);
  1552. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  1553. dma_unmap_len_set(out_meta, len, firstlen);
  1554. /* Add buffer containing Tx command and MAC(!) header to TFD's
  1555. * first entry */
  1556. il->ops->lib->txq_attach_buf_to_tfd(il, txq, txcmd_phys, firstlen, 1, 0);
  1557. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  1558. txq->need_update = 1;
  1559. } else {
  1560. wait_write_ptr = 1;
  1561. txq->need_update = 0;
  1562. }
  1563. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  1564. * if any (802.11 null frames have no payload). */
  1565. secondlen = skb->len - hdr_len;
  1566. if (secondlen > 0) {
  1567. phys_addr =
  1568. pci_map_single(il->pci_dev, skb->data + hdr_len, secondlen,
  1569. PCI_DMA_TODEVICE);
  1570. il->ops->lib->txq_attach_buf_to_tfd(il, txq, phys_addr,
  1571. secondlen, 0, 0);
  1572. }
  1573. scratch_phys =
  1574. txcmd_phys + sizeof(struct il_cmd_header) +
  1575. offsetof(struct il_tx_cmd, scratch);
  1576. /* take back ownership of DMA buffer to enable update */
  1577. pci_dma_sync_single_for_cpu(il->pci_dev, txcmd_phys, firstlen,
  1578. PCI_DMA_BIDIRECTIONAL);
  1579. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  1580. tx_cmd->dram_msb_ptr = il_get_dma_hi_addr(scratch_phys);
  1581. D_TX("sequence nr = 0X%x\n", le16_to_cpu(out_cmd->hdr.sequence));
  1582. D_TX("tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  1583. il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd, sizeof(*tx_cmd));
  1584. il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd->hdr, hdr_len);
  1585. /* Set up entry for this TFD in Tx byte-count array */
  1586. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1587. il->ops->lib->txq_update_byte_cnt_tbl(il, txq,
  1588. le16_to_cpu(tx_cmd->len));
  1589. pci_dma_sync_single_for_device(il->pci_dev, txcmd_phys, firstlen,
  1590. PCI_DMA_BIDIRECTIONAL);
  1591. /* Tell device the write idx *just past* this latest filled TFD */
  1592. q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd);
  1593. il_txq_update_write_ptr(il, txq);
  1594. spin_unlock_irqrestore(&il->lock, flags);
  1595. /*
  1596. * At this point the frame is "transmitted" successfully
  1597. * and we will get a TX status notification eventually,
  1598. * regardless of the value of ret. "ret" only indicates
  1599. * whether or not we should update the write pointer.
  1600. */
  1601. /*
  1602. * Avoid atomic ops if it isn't an associated client.
  1603. * Also, if this is a packet for aggregation, don't
  1604. * increase the counter because the ucode will stop
  1605. * aggregation queues when their respective station
  1606. * goes to sleep.
  1607. */
  1608. if (sta_priv && sta_priv->client && !is_agg)
  1609. atomic_inc(&sta_priv->pending_frames);
  1610. if (il_queue_space(q) < q->high_mark && il->mac80211_registered) {
  1611. if (wait_write_ptr) {
  1612. spin_lock_irqsave(&il->lock, flags);
  1613. txq->need_update = 1;
  1614. il_txq_update_write_ptr(il, txq);
  1615. spin_unlock_irqrestore(&il->lock, flags);
  1616. } else {
  1617. il_stop_queue(il, txq);
  1618. }
  1619. }
  1620. return 0;
  1621. drop_unlock:
  1622. spin_unlock_irqrestore(&il->lock, flags);
  1623. return -1;
  1624. }
  1625. static inline int
  1626. il4965_alloc_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr, size_t size)
  1627. {
  1628. ptr->addr =
  1629. dma_alloc_coherent(&il->pci_dev->dev, size, &ptr->dma, GFP_KERNEL);
  1630. if (!ptr->addr)
  1631. return -ENOMEM;
  1632. ptr->size = size;
  1633. return 0;
  1634. }
  1635. static inline void
  1636. il4965_free_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr)
  1637. {
  1638. if (unlikely(!ptr->addr))
  1639. return;
  1640. dma_free_coherent(&il->pci_dev->dev, ptr->size, ptr->addr, ptr->dma);
  1641. memset(ptr, 0, sizeof(*ptr));
  1642. }
  1643. /**
  1644. * il4965_hw_txq_ctx_free - Free TXQ Context
  1645. *
  1646. * Destroy all TX DMA queues and structures
  1647. */
  1648. void
  1649. il4965_hw_txq_ctx_free(struct il_priv *il)
  1650. {
  1651. int txq_id;
  1652. /* Tx queues */
  1653. if (il->txq) {
  1654. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1655. if (txq_id == il->cmd_queue)
  1656. il_cmd_queue_free(il);
  1657. else
  1658. il_tx_queue_free(il, txq_id);
  1659. }
  1660. il4965_free_dma_ptr(il, &il->kw);
  1661. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1662. /* free tx queue structure */
  1663. il_txq_mem(il);
  1664. }
  1665. /**
  1666. * il4965_txq_ctx_alloc - allocate TX queue context
  1667. * Allocate all Tx DMA structures and initialize them
  1668. *
  1669. * @param il
  1670. * @return error code
  1671. */
  1672. int
  1673. il4965_txq_ctx_alloc(struct il_priv *il)
  1674. {
  1675. int ret;
  1676. int txq_id, slots_num;
  1677. unsigned long flags;
  1678. /* Free all tx/cmd queues and keep-warm buffer */
  1679. il4965_hw_txq_ctx_free(il);
  1680. ret =
  1681. il4965_alloc_dma_ptr(il, &il->scd_bc_tbls,
  1682. il->hw_params.scd_bc_tbls_size);
  1683. if (ret) {
  1684. IL_ERR("Scheduler BC Table allocation failed\n");
  1685. goto error_bc_tbls;
  1686. }
  1687. /* Alloc keep-warm buffer */
  1688. ret = il4965_alloc_dma_ptr(il, &il->kw, IL_KW_SIZE);
  1689. if (ret) {
  1690. IL_ERR("Keep Warm allocation failed\n");
  1691. goto error_kw;
  1692. }
  1693. /* allocate tx queue structure */
  1694. ret = il_alloc_txq_mem(il);
  1695. if (ret)
  1696. goto error;
  1697. spin_lock_irqsave(&il->lock, flags);
  1698. /* Turn off all Tx DMA fifos */
  1699. il4965_txq_set_sched(il, 0);
  1700. /* Tell NIC where to find the "keep warm" buffer */
  1701. il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1702. spin_unlock_irqrestore(&il->lock, flags);
  1703. /* Alloc and init all Tx queues, including the command queue (#4/#9) */
  1704. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1705. slots_num =
  1706. (txq_id ==
  1707. il->cmd_queue) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1708. ret = il_tx_queue_init(il, &il->txq[txq_id], slots_num, txq_id);
  1709. if (ret) {
  1710. IL_ERR("Tx %d queue init failed\n", txq_id);
  1711. goto error;
  1712. }
  1713. }
  1714. return ret;
  1715. error:
  1716. il4965_hw_txq_ctx_free(il);
  1717. il4965_free_dma_ptr(il, &il->kw);
  1718. error_kw:
  1719. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1720. error_bc_tbls:
  1721. return ret;
  1722. }
  1723. void
  1724. il4965_txq_ctx_reset(struct il_priv *il)
  1725. {
  1726. int txq_id, slots_num;
  1727. unsigned long flags;
  1728. spin_lock_irqsave(&il->lock, flags);
  1729. /* Turn off all Tx DMA fifos */
  1730. il4965_txq_set_sched(il, 0);
  1731. /* Tell NIC where to find the "keep warm" buffer */
  1732. il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1733. spin_unlock_irqrestore(&il->lock, flags);
  1734. /* Alloc and init all Tx queues, including the command queue (#4) */
  1735. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1736. slots_num =
  1737. txq_id == il->cmd_queue ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1738. il_tx_queue_reset(il, &il->txq[txq_id], slots_num, txq_id);
  1739. }
  1740. }
  1741. /**
  1742. * il4965_txq_ctx_stop - Stop all Tx DMA channels
  1743. */
  1744. void
  1745. il4965_txq_ctx_stop(struct il_priv *il)
  1746. {
  1747. int ch, txq_id;
  1748. unsigned long flags;
  1749. /* Turn off all Tx DMA fifos */
  1750. spin_lock_irqsave(&il->lock, flags);
  1751. il4965_txq_set_sched(il, 0);
  1752. /* Stop each Tx DMA channel, and wait for it to be idle */
  1753. for (ch = 0; ch < il->hw_params.dma_chnl_num; ch++) {
  1754. il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
  1755. if (il_poll_bit
  1756. (il, FH49_TSSR_TX_STATUS_REG,
  1757. FH49_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1000))
  1758. IL_ERR("Failing on timeout while stopping"
  1759. " DMA channel %d [0x%08x]", ch,
  1760. il_rd(il, FH49_TSSR_TX_STATUS_REG));
  1761. }
  1762. spin_unlock_irqrestore(&il->lock, flags);
  1763. if (!il->txq)
  1764. return;
  1765. /* Unmap DMA from host system and free skb's */
  1766. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1767. if (txq_id == il->cmd_queue)
  1768. il_cmd_queue_unmap(il);
  1769. else
  1770. il_tx_queue_unmap(il, txq_id);
  1771. }
  1772. /*
  1773. * Find first available (lowest unused) Tx Queue, mark it "active".
  1774. * Called only when finding queue for aggregation.
  1775. * Should never return anything < 7, because they should already
  1776. * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
  1777. */
  1778. static int
  1779. il4965_txq_ctx_activate_free(struct il_priv *il)
  1780. {
  1781. int txq_id;
  1782. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1783. if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk))
  1784. return txq_id;
  1785. return -1;
  1786. }
  1787. /**
  1788. * il4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  1789. */
  1790. static void
  1791. il4965_tx_queue_stop_scheduler(struct il_priv *il, u16 txq_id)
  1792. {
  1793. /* Simply stop the queue, but don't change any configuration;
  1794. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  1795. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  1796. (0 << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  1797. (1 << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  1798. }
  1799. /**
  1800. * il4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  1801. */
  1802. static int
  1803. il4965_tx_queue_set_q2ratid(struct il_priv *il, u16 ra_tid, u16 txq_id)
  1804. {
  1805. u32 tbl_dw_addr;
  1806. u32 tbl_dw;
  1807. u16 scd_q2ratid;
  1808. scd_q2ratid = ra_tid & IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  1809. tbl_dw_addr =
  1810. il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  1811. tbl_dw = il_read_targ_mem(il, tbl_dw_addr);
  1812. if (txq_id & 0x1)
  1813. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  1814. else
  1815. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  1816. il_write_targ_mem(il, tbl_dw_addr, tbl_dw);
  1817. return 0;
  1818. }
  1819. /**
  1820. * il4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  1821. *
  1822. * NOTE: txq_id must be greater than IL49_FIRST_AMPDU_QUEUE,
  1823. * i.e. it must be one of the higher queues used for aggregation
  1824. */
  1825. static int
  1826. il4965_txq_agg_enable(struct il_priv *il, int txq_id, int tx_fifo, int sta_id,
  1827. int tid, u16 ssn_idx)
  1828. {
  1829. unsigned long flags;
  1830. u16 ra_tid;
  1831. int ret;
  1832. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1833. (IL49_FIRST_AMPDU_QUEUE +
  1834. il->cfg->num_of_ampdu_queues <= txq_id)) {
  1835. IL_WARN("queue number out of range: %d, must be %d to %d\n",
  1836. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1837. IL49_FIRST_AMPDU_QUEUE +
  1838. il->cfg->num_of_ampdu_queues - 1);
  1839. return -EINVAL;
  1840. }
  1841. ra_tid = BUILD_RAxTID(sta_id, tid);
  1842. /* Modify device's station table to Tx this TID */
  1843. ret = il4965_sta_tx_modify_enable_tid(il, sta_id, tid);
  1844. if (ret)
  1845. return ret;
  1846. spin_lock_irqsave(&il->lock, flags);
  1847. /* Stop this Tx queue before configuring it */
  1848. il4965_tx_queue_stop_scheduler(il, txq_id);
  1849. /* Map receiver-address / traffic-ID to this queue */
  1850. il4965_tx_queue_set_q2ratid(il, ra_tid, txq_id);
  1851. /* Set this queue as a chain-building queue */
  1852. il_set_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1853. /* Place first TFD at idx corresponding to start sequence number.
  1854. * Assumes that ssn_idx is valid (!= 0xFFF) */
  1855. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1856. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1857. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1858. /* Set up Tx win size and frame limit for this queue */
  1859. il_write_targ_mem(il,
  1860. il->scd_base_addr +
  1861. IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  1862. (SCD_WIN_SIZE << IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS)
  1863. & IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1864. il_write_targ_mem(il,
  1865. il->scd_base_addr +
  1866. IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  1867. (SCD_FRAME_LIMIT <<
  1868. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1869. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1870. il_set_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1871. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  1872. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 1);
  1873. spin_unlock_irqrestore(&il->lock, flags);
  1874. return 0;
  1875. }
  1876. int
  1877. il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif,
  1878. struct ieee80211_sta *sta, u16 tid, u16 * ssn)
  1879. {
  1880. int sta_id;
  1881. int tx_fifo;
  1882. int txq_id;
  1883. int ret;
  1884. unsigned long flags;
  1885. struct il_tid_data *tid_data;
  1886. /* FIXME: warning if tx fifo not found ? */
  1887. tx_fifo = il4965_get_fifo_from_tid(tid);
  1888. if (unlikely(tx_fifo < 0))
  1889. return tx_fifo;
  1890. D_HT("%s on ra = %pM tid = %d\n", __func__, sta->addr, tid);
  1891. sta_id = il_sta_id(sta);
  1892. if (sta_id == IL_INVALID_STATION) {
  1893. IL_ERR("Start AGG on invalid station\n");
  1894. return -ENXIO;
  1895. }
  1896. if (unlikely(tid >= MAX_TID_COUNT))
  1897. return -EINVAL;
  1898. if (il->stations[sta_id].tid[tid].agg.state != IL_AGG_OFF) {
  1899. IL_ERR("Start AGG when state is not IL_AGG_OFF !\n");
  1900. return -ENXIO;
  1901. }
  1902. txq_id = il4965_txq_ctx_activate_free(il);
  1903. if (txq_id == -1) {
  1904. IL_ERR("No free aggregation queue available\n");
  1905. return -ENXIO;
  1906. }
  1907. spin_lock_irqsave(&il->sta_lock, flags);
  1908. tid_data = &il->stations[sta_id].tid[tid];
  1909. *ssn = SEQ_TO_SN(tid_data->seq_number);
  1910. tid_data->agg.txq_id = txq_id;
  1911. il_set_swq_id(&il->txq[txq_id], il4965_get_ac_from_tid(tid), txq_id);
  1912. spin_unlock_irqrestore(&il->sta_lock, flags);
  1913. ret = il4965_txq_agg_enable(il, txq_id, tx_fifo, sta_id, tid, *ssn);
  1914. if (ret)
  1915. return ret;
  1916. spin_lock_irqsave(&il->sta_lock, flags);
  1917. tid_data = &il->stations[sta_id].tid[tid];
  1918. if (tid_data->tfds_in_queue == 0) {
  1919. D_HT("HW queue is empty\n");
  1920. tid_data->agg.state = IL_AGG_ON;
  1921. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1922. } else {
  1923. D_HT("HW queue is NOT empty: %d packets in HW queue\n",
  1924. tid_data->tfds_in_queue);
  1925. tid_data->agg.state = IL_EMPTYING_HW_QUEUE_ADDBA;
  1926. }
  1927. spin_unlock_irqrestore(&il->sta_lock, flags);
  1928. return ret;
  1929. }
  1930. /**
  1931. * txq_id must be greater than IL49_FIRST_AMPDU_QUEUE
  1932. * il->lock must be held by the caller
  1933. */
  1934. static int
  1935. il4965_txq_agg_disable(struct il_priv *il, u16 txq_id, u16 ssn_idx, u8 tx_fifo)
  1936. {
  1937. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1938. (IL49_FIRST_AMPDU_QUEUE +
  1939. il->cfg->num_of_ampdu_queues <= txq_id)) {
  1940. IL_WARN("queue number out of range: %d, must be %d to %d\n",
  1941. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1942. IL49_FIRST_AMPDU_QUEUE +
  1943. il->cfg->num_of_ampdu_queues - 1);
  1944. return -EINVAL;
  1945. }
  1946. il4965_tx_queue_stop_scheduler(il, txq_id);
  1947. il_clear_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1948. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1949. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1950. /* supposes that ssn_idx is valid (!= 0xFFF) */
  1951. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1952. il_clear_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1953. il_txq_ctx_deactivate(il, txq_id);
  1954. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 0);
  1955. return 0;
  1956. }
  1957. int
  1958. il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif,
  1959. struct ieee80211_sta *sta, u16 tid)
  1960. {
  1961. int tx_fifo_id, txq_id, sta_id, ssn;
  1962. struct il_tid_data *tid_data;
  1963. int write_ptr, read_ptr;
  1964. unsigned long flags;
  1965. /* FIXME: warning if tx_fifo_id not found ? */
  1966. tx_fifo_id = il4965_get_fifo_from_tid(tid);
  1967. if (unlikely(tx_fifo_id < 0))
  1968. return tx_fifo_id;
  1969. sta_id = il_sta_id(sta);
  1970. if (sta_id == IL_INVALID_STATION) {
  1971. IL_ERR("Invalid station for AGG tid %d\n", tid);
  1972. return -ENXIO;
  1973. }
  1974. spin_lock_irqsave(&il->sta_lock, flags);
  1975. tid_data = &il->stations[sta_id].tid[tid];
  1976. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  1977. txq_id = tid_data->agg.txq_id;
  1978. switch (il->stations[sta_id].tid[tid].agg.state) {
  1979. case IL_EMPTYING_HW_QUEUE_ADDBA:
  1980. /*
  1981. * This can happen if the peer stops aggregation
  1982. * again before we've had a chance to drain the
  1983. * queue we selected previously, i.e. before the
  1984. * session was really started completely.
  1985. */
  1986. D_HT("AGG stop before setup done\n");
  1987. goto turn_off;
  1988. case IL_AGG_ON:
  1989. break;
  1990. default:
  1991. IL_WARN("Stopping AGG while state not ON or starting\n");
  1992. }
  1993. write_ptr = il->txq[txq_id].q.write_ptr;
  1994. read_ptr = il->txq[txq_id].q.read_ptr;
  1995. /* The queue is not empty */
  1996. if (write_ptr != read_ptr) {
  1997. D_HT("Stopping a non empty AGG HW QUEUE\n");
  1998. il->stations[sta_id].tid[tid].agg.state =
  1999. IL_EMPTYING_HW_QUEUE_DELBA;
  2000. spin_unlock_irqrestore(&il->sta_lock, flags);
  2001. return 0;
  2002. }
  2003. D_HT("HW queue is empty\n");
  2004. turn_off:
  2005. il->stations[sta_id].tid[tid].agg.state = IL_AGG_OFF;
  2006. /* do not restore/save irqs */
  2007. spin_unlock(&il->sta_lock);
  2008. spin_lock(&il->lock);
  2009. /*
  2010. * the only reason this call can fail is queue number out of range,
  2011. * which can happen if uCode is reloaded and all the station
  2012. * information are lost. if it is outside the range, there is no need
  2013. * to deactivate the uCode queue, just return "success" to allow
  2014. * mac80211 to clean up it own data.
  2015. */
  2016. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo_id);
  2017. spin_unlock_irqrestore(&il->lock, flags);
  2018. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2019. return 0;
  2020. }
  2021. int
  2022. il4965_txq_check_empty(struct il_priv *il, int sta_id, u8 tid, int txq_id)
  2023. {
  2024. struct il_queue *q = &il->txq[txq_id].q;
  2025. u8 *addr = il->stations[sta_id].sta.sta.addr;
  2026. struct il_tid_data *tid_data = &il->stations[sta_id].tid[tid];
  2027. lockdep_assert_held(&il->sta_lock);
  2028. switch (il->stations[sta_id].tid[tid].agg.state) {
  2029. case IL_EMPTYING_HW_QUEUE_DELBA:
  2030. /* We are reclaiming the last packet of the */
  2031. /* aggregated HW queue */
  2032. if (txq_id == tid_data->agg.txq_id &&
  2033. q->read_ptr == q->write_ptr) {
  2034. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  2035. int tx_fifo = il4965_get_fifo_from_tid(tid);
  2036. D_HT("HW queue empty: continue DELBA flow\n");
  2037. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo);
  2038. tid_data->agg.state = IL_AGG_OFF;
  2039. ieee80211_stop_tx_ba_cb_irqsafe(il->vif, addr, tid);
  2040. }
  2041. break;
  2042. case IL_EMPTYING_HW_QUEUE_ADDBA:
  2043. /* We are reclaiming the last packet of the queue */
  2044. if (tid_data->tfds_in_queue == 0) {
  2045. D_HT("HW queue empty: continue ADDBA flow\n");
  2046. tid_data->agg.state = IL_AGG_ON;
  2047. ieee80211_start_tx_ba_cb_irqsafe(il->vif, addr, tid);
  2048. }
  2049. break;
  2050. }
  2051. return 0;
  2052. }
  2053. static void
  2054. il4965_non_agg_tx_status(struct il_priv *il, const u8 *addr1)
  2055. {
  2056. struct ieee80211_sta *sta;
  2057. struct il_station_priv *sta_priv;
  2058. rcu_read_lock();
  2059. sta = ieee80211_find_sta(il->vif, addr1);
  2060. if (sta) {
  2061. sta_priv = (void *)sta->drv_priv;
  2062. /* avoid atomic ops if this isn't a client */
  2063. if (sta_priv->client &&
  2064. atomic_dec_return(&sta_priv->pending_frames) == 0)
  2065. ieee80211_sta_block_awake(il->hw, sta, false);
  2066. }
  2067. rcu_read_unlock();
  2068. }
  2069. static void
  2070. il4965_tx_status(struct il_priv *il, struct sk_buff *skb, bool is_agg)
  2071. {
  2072. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2073. if (!is_agg)
  2074. il4965_non_agg_tx_status(il, hdr->addr1);
  2075. ieee80211_tx_status_irqsafe(il->hw, skb);
  2076. }
  2077. int
  2078. il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx)
  2079. {
  2080. struct il_tx_queue *txq = &il->txq[txq_id];
  2081. struct il_queue *q = &txq->q;
  2082. int nfreed = 0;
  2083. struct ieee80211_hdr *hdr;
  2084. struct sk_buff *skb;
  2085. if (idx >= q->n_bd || il_queue_used(q, idx) == 0) {
  2086. IL_ERR("Read idx for DMA queue txq id (%d), idx %d, "
  2087. "is out of range [0-%d] %d %d.\n", txq_id, idx, q->n_bd,
  2088. q->write_ptr, q->read_ptr);
  2089. return 0;
  2090. }
  2091. for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  2092. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2093. skb = txq->skbs[txq->q.read_ptr];
  2094. if (WARN_ON_ONCE(skb == NULL))
  2095. continue;
  2096. hdr = (struct ieee80211_hdr *) skb->data;
  2097. if (ieee80211_is_data_qos(hdr->frame_control))
  2098. nfreed++;
  2099. il4965_tx_status(il, skb, txq_id >= IL4965_FIRST_AMPDU_QUEUE);
  2100. txq->skbs[txq->q.read_ptr] = NULL;
  2101. il->ops->lib->txq_free_tfd(il, txq);
  2102. }
  2103. return nfreed;
  2104. }
  2105. /**
  2106. * il4965_tx_status_reply_compressed_ba - Update tx status from block-ack
  2107. *
  2108. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  2109. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  2110. */
  2111. static int
  2112. il4965_tx_status_reply_compressed_ba(struct il_priv *il, struct il_ht_agg *agg,
  2113. struct il_compressed_ba_resp *ba_resp)
  2114. {
  2115. int i, sh, ack;
  2116. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  2117. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2118. int successes = 0;
  2119. struct ieee80211_tx_info *info;
  2120. u64 bitmap, sent_bitmap;
  2121. if (unlikely(!agg->wait_for_ba)) {
  2122. if (unlikely(ba_resp->bitmap))
  2123. IL_ERR("Received BA when not expected\n");
  2124. return -EINVAL;
  2125. }
  2126. /* Mark that the expected block-ack response arrived */
  2127. agg->wait_for_ba = 0;
  2128. D_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
  2129. /* Calculate shift to align block-ack bits with our Tx win bits */
  2130. sh = agg->start_idx - SEQ_TO_IDX(seq_ctl >> 4);
  2131. if (sh < 0) /* tbw something is wrong with indices */
  2132. sh += 0x100;
  2133. if (agg->frame_count > (64 - sh)) {
  2134. D_TX_REPLY("more frames than bitmap size");
  2135. return -1;
  2136. }
  2137. /* don't use 64-bit values for now */
  2138. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  2139. /* check for success or failure according to the
  2140. * transmitted bitmap and block-ack bitmap */
  2141. sent_bitmap = bitmap & agg->bitmap;
  2142. /* For each frame attempted in aggregation,
  2143. * update driver's record of tx frame's status. */
  2144. i = 0;
  2145. while (sent_bitmap) {
  2146. ack = sent_bitmap & 1ULL;
  2147. successes += ack;
  2148. D_TX_REPLY("%s ON i=%d idx=%d raw=%d\n", ack ? "ACK" : "NACK",
  2149. i, (agg->start_idx + i) & 0xff, agg->start_idx + i);
  2150. sent_bitmap >>= 1;
  2151. ++i;
  2152. }
  2153. D_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
  2154. info = IEEE80211_SKB_CB(il->txq[scd_flow].skbs[agg->start_idx]);
  2155. memset(&info->status, 0, sizeof(info->status));
  2156. info->flags |= IEEE80211_TX_STAT_ACK;
  2157. info->flags |= IEEE80211_TX_STAT_AMPDU;
  2158. info->status.ampdu_ack_len = successes;
  2159. info->status.ampdu_len = agg->frame_count;
  2160. il4965_hwrate_to_tx_control(il, agg->rate_n_flags, info);
  2161. return 0;
  2162. }
  2163. /**
  2164. * translate ucode response to mac80211 tx status control values
  2165. */
  2166. void
  2167. il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags,
  2168. struct ieee80211_tx_info *info)
  2169. {
  2170. struct ieee80211_tx_rate *r = &info->control.rates[0];
  2171. info->antenna_sel_tx =
  2172. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  2173. if (rate_n_flags & RATE_MCS_HT_MSK)
  2174. r->flags |= IEEE80211_TX_RC_MCS;
  2175. if (rate_n_flags & RATE_MCS_GF_MSK)
  2176. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2177. if (rate_n_flags & RATE_MCS_HT40_MSK)
  2178. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2179. if (rate_n_flags & RATE_MCS_DUP_MSK)
  2180. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  2181. if (rate_n_flags & RATE_MCS_SGI_MSK)
  2182. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  2183. r->idx = il4965_hwrate_to_mac80211_idx(rate_n_flags, info->band);
  2184. }
  2185. /**
  2186. * il4965_hdl_compressed_ba - Handler for N_COMPRESSED_BA
  2187. *
  2188. * Handles block-acknowledge notification from device, which reports success
  2189. * of frames sent via aggregation.
  2190. */
  2191. void
  2192. il4965_hdl_compressed_ba(struct il_priv *il, struct il_rx_buf *rxb)
  2193. {
  2194. struct il_rx_pkt *pkt = rxb_addr(rxb);
  2195. struct il_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  2196. struct il_tx_queue *txq = NULL;
  2197. struct il_ht_agg *agg;
  2198. int idx;
  2199. int sta_id;
  2200. int tid;
  2201. unsigned long flags;
  2202. /* "flow" corresponds to Tx queue */
  2203. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2204. /* "ssn" is start of block-ack Tx win, corresponds to idx
  2205. * (in Tx queue's circular buffer) of first TFD/frame in win */
  2206. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  2207. if (scd_flow >= il->hw_params.max_txq_num) {
  2208. IL_ERR("BUG_ON scd_flow is bigger than number of queues\n");
  2209. return;
  2210. }
  2211. txq = &il->txq[scd_flow];
  2212. sta_id = ba_resp->sta_id;
  2213. tid = ba_resp->tid;
  2214. agg = &il->stations[sta_id].tid[tid].agg;
  2215. if (unlikely(agg->txq_id != scd_flow)) {
  2216. /*
  2217. * FIXME: this is a uCode bug which need to be addressed,
  2218. * log the information and return for now!
  2219. * since it is possible happen very often and in order
  2220. * not to fill the syslog, don't enable the logging by default
  2221. */
  2222. D_TX_REPLY("BA scd_flow %d does not match txq_id %d\n",
  2223. scd_flow, agg->txq_id);
  2224. return;
  2225. }
  2226. /* Find idx just before block-ack win */
  2227. idx = il_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  2228. spin_lock_irqsave(&il->sta_lock, flags);
  2229. D_TX_REPLY("N_COMPRESSED_BA [%d] Received from %pM, " "sta_id = %d\n",
  2230. agg->wait_for_ba, (u8 *) &ba_resp->sta_addr_lo32,
  2231. ba_resp->sta_id);
  2232. D_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx," "scd_flow = "
  2233. "%d, scd_ssn = %d\n", ba_resp->tid, ba_resp->seq_ctl,
  2234. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  2235. ba_resp->scd_flow, ba_resp->scd_ssn);
  2236. D_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx\n", agg->start_idx,
  2237. (unsigned long long)agg->bitmap);
  2238. /* Update driver's record of ACK vs. not for each frame in win */
  2239. il4965_tx_status_reply_compressed_ba(il, agg, ba_resp);
  2240. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  2241. * block-ack win (we assume that they've been successfully
  2242. * transmitted ... if not, it's too late anyway). */
  2243. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  2244. /* calculate mac80211 ampdu sw queue to wake */
  2245. int freed = il4965_tx_queue_reclaim(il, scd_flow, idx);
  2246. il4965_free_tfds_in_queue(il, sta_id, tid, freed);
  2247. if (il_queue_space(&txq->q) > txq->q.low_mark &&
  2248. il->mac80211_registered &&
  2249. agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
  2250. il_wake_queue(il, txq);
  2251. il4965_txq_check_empty(il, sta_id, tid, scd_flow);
  2252. }
  2253. spin_unlock_irqrestore(&il->sta_lock, flags);
  2254. }
  2255. #ifdef CONFIG_IWLEGACY_DEBUG
  2256. const char *
  2257. il4965_get_tx_fail_reason(u32 status)
  2258. {
  2259. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  2260. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  2261. switch (status & TX_STATUS_MSK) {
  2262. case TX_STATUS_SUCCESS:
  2263. return "SUCCESS";
  2264. TX_STATUS_POSTPONE(DELAY);
  2265. TX_STATUS_POSTPONE(FEW_BYTES);
  2266. TX_STATUS_POSTPONE(QUIET_PERIOD);
  2267. TX_STATUS_POSTPONE(CALC_TTAK);
  2268. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  2269. TX_STATUS_FAIL(SHORT_LIMIT);
  2270. TX_STATUS_FAIL(LONG_LIMIT);
  2271. TX_STATUS_FAIL(FIFO_UNDERRUN);
  2272. TX_STATUS_FAIL(DRAIN_FLOW);
  2273. TX_STATUS_FAIL(RFKILL_FLUSH);
  2274. TX_STATUS_FAIL(LIFE_EXPIRE);
  2275. TX_STATUS_FAIL(DEST_PS);
  2276. TX_STATUS_FAIL(HOST_ABORTED);
  2277. TX_STATUS_FAIL(BT_RETRY);
  2278. TX_STATUS_FAIL(STA_INVALID);
  2279. TX_STATUS_FAIL(FRAG_DROPPED);
  2280. TX_STATUS_FAIL(TID_DISABLE);
  2281. TX_STATUS_FAIL(FIFO_FLUSHED);
  2282. TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
  2283. TX_STATUS_FAIL(PASSIVE_NO_RX);
  2284. TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
  2285. }
  2286. return "UNKNOWN";
  2287. #undef TX_STATUS_FAIL
  2288. #undef TX_STATUS_POSTPONE
  2289. }
  2290. #endif /* CONFIG_IWLEGACY_DEBUG */
  2291. static struct il_link_quality_cmd *
  2292. il4965_sta_alloc_lq(struct il_priv *il, u8 sta_id)
  2293. {
  2294. int i, r;
  2295. struct il_link_quality_cmd *link_cmd;
  2296. u32 rate_flags = 0;
  2297. __le32 rate_n_flags;
  2298. link_cmd = kzalloc(sizeof(struct il_link_quality_cmd), GFP_KERNEL);
  2299. if (!link_cmd) {
  2300. IL_ERR("Unable to allocate memory for LQ cmd.\n");
  2301. return NULL;
  2302. }
  2303. /* Set up the rate scaling to start at selected rate, fall back
  2304. * all the way down to 1M in IEEE order, and then spin on 1M */
  2305. if (il->band == IEEE80211_BAND_5GHZ)
  2306. r = RATE_6M_IDX;
  2307. else
  2308. r = RATE_1M_IDX;
  2309. if (r >= IL_FIRST_CCK_RATE && r <= IL_LAST_CCK_RATE)
  2310. rate_flags |= RATE_MCS_CCK_MSK;
  2311. rate_flags |=
  2312. il4965_first_antenna(il->hw_params.
  2313. valid_tx_ant) << RATE_MCS_ANT_POS;
  2314. rate_n_flags = cpu_to_le32(il_rates[r].plcp | rate_flags);
  2315. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  2316. link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
  2317. link_cmd->general_params.single_stream_ant_msk =
  2318. il4965_first_antenna(il->hw_params.valid_tx_ant);
  2319. link_cmd->general_params.dual_stream_ant_msk =
  2320. il->hw_params.valid_tx_ant & ~il4965_first_antenna(il->hw_params.
  2321. valid_tx_ant);
  2322. if (!link_cmd->general_params.dual_stream_ant_msk) {
  2323. link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
  2324. } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) {
  2325. link_cmd->general_params.dual_stream_ant_msk =
  2326. il->hw_params.valid_tx_ant;
  2327. }
  2328. link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2329. link_cmd->agg_params.agg_time_limit =
  2330. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2331. link_cmd->sta_id = sta_id;
  2332. return link_cmd;
  2333. }
  2334. /*
  2335. * il4965_add_bssid_station - Add the special IBSS BSSID station
  2336. *
  2337. * Function sleeps.
  2338. */
  2339. int
  2340. il4965_add_bssid_station(struct il_priv *il, const u8 *addr, u8 *sta_id_r)
  2341. {
  2342. int ret;
  2343. u8 sta_id;
  2344. struct il_link_quality_cmd *link_cmd;
  2345. unsigned long flags;
  2346. if (sta_id_r)
  2347. *sta_id_r = IL_INVALID_STATION;
  2348. ret = il_add_station_common(il, addr, 0, NULL, &sta_id);
  2349. if (ret) {
  2350. IL_ERR("Unable to add station %pM\n", addr);
  2351. return ret;
  2352. }
  2353. if (sta_id_r)
  2354. *sta_id_r = sta_id;
  2355. spin_lock_irqsave(&il->sta_lock, flags);
  2356. il->stations[sta_id].used |= IL_STA_LOCAL;
  2357. spin_unlock_irqrestore(&il->sta_lock, flags);
  2358. /* Set up default rate scaling table in device's station table */
  2359. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2360. if (!link_cmd) {
  2361. IL_ERR("Unable to initialize rate scaling for station %pM.\n",
  2362. addr);
  2363. return -ENOMEM;
  2364. }
  2365. ret = il_send_lq_cmd(il, link_cmd, CMD_SYNC, true);
  2366. if (ret)
  2367. IL_ERR("Link quality command failed (%d)\n", ret);
  2368. spin_lock_irqsave(&il->sta_lock, flags);
  2369. il->stations[sta_id].lq = link_cmd;
  2370. spin_unlock_irqrestore(&il->sta_lock, flags);
  2371. return 0;
  2372. }
  2373. static int
  2374. il4965_static_wepkey_cmd(struct il_priv *il, bool send_if_empty)
  2375. {
  2376. int i;
  2377. u8 buff[sizeof(struct il_wep_cmd) +
  2378. sizeof(struct il_wep_key) * WEP_KEYS_MAX];
  2379. struct il_wep_cmd *wep_cmd = (struct il_wep_cmd *)buff;
  2380. size_t cmd_size = sizeof(struct il_wep_cmd);
  2381. struct il_host_cmd cmd = {
  2382. .id = C_WEPKEY,
  2383. .data = wep_cmd,
  2384. .flags = CMD_SYNC,
  2385. };
  2386. bool not_empty = false;
  2387. might_sleep();
  2388. memset(wep_cmd, 0,
  2389. cmd_size + (sizeof(struct il_wep_key) * WEP_KEYS_MAX));
  2390. for (i = 0; i < WEP_KEYS_MAX; i++) {
  2391. u8 key_size = il->_4965.wep_keys[i].key_size;
  2392. wep_cmd->key[i].key_idx = i;
  2393. if (key_size) {
  2394. wep_cmd->key[i].key_offset = i;
  2395. not_empty = true;
  2396. } else
  2397. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  2398. wep_cmd->key[i].key_size = key_size;
  2399. memcpy(&wep_cmd->key[i].key[3], il->_4965.wep_keys[i].key, key_size);
  2400. }
  2401. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  2402. wep_cmd->num_keys = WEP_KEYS_MAX;
  2403. cmd_size += sizeof(struct il_wep_key) * WEP_KEYS_MAX;
  2404. cmd.len = cmd_size;
  2405. if (not_empty || send_if_empty)
  2406. return il_send_cmd(il, &cmd);
  2407. else
  2408. return 0;
  2409. }
  2410. int
  2411. il4965_restore_default_wep_keys(struct il_priv *il)
  2412. {
  2413. lockdep_assert_held(&il->mutex);
  2414. return il4965_static_wepkey_cmd(il, false);
  2415. }
  2416. int
  2417. il4965_remove_default_wep_key(struct il_priv *il,
  2418. struct ieee80211_key_conf *keyconf)
  2419. {
  2420. int ret;
  2421. int idx = keyconf->keyidx;
  2422. lockdep_assert_held(&il->mutex);
  2423. D_WEP("Removing default WEP key: idx=%d\n", idx);
  2424. memset(&il->_4965.wep_keys[idx], 0, sizeof(struct il_wep_key));
  2425. if (il_is_rfkill(il)) {
  2426. D_WEP("Not sending C_WEPKEY command due to RFKILL.\n");
  2427. /* but keys in device are clear anyway so return success */
  2428. return 0;
  2429. }
  2430. ret = il4965_static_wepkey_cmd(il, 1);
  2431. D_WEP("Remove default WEP key: idx=%d ret=%d\n", idx, ret);
  2432. return ret;
  2433. }
  2434. int
  2435. il4965_set_default_wep_key(struct il_priv *il,
  2436. struct ieee80211_key_conf *keyconf)
  2437. {
  2438. int ret;
  2439. int len = keyconf->keylen;
  2440. int idx = keyconf->keyidx;
  2441. lockdep_assert_held(&il->mutex);
  2442. if (len != WEP_KEY_LEN_128 && len != WEP_KEY_LEN_64) {
  2443. D_WEP("Bad WEP key length %d\n", keyconf->keylen);
  2444. return -EINVAL;
  2445. }
  2446. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2447. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  2448. il->stations[IL_AP_ID].keyinfo.cipher = keyconf->cipher;
  2449. il->_4965.wep_keys[idx].key_size = len;
  2450. memcpy(&il->_4965.wep_keys[idx].key, &keyconf->key, len);
  2451. ret = il4965_static_wepkey_cmd(il, false);
  2452. D_WEP("Set default WEP key: len=%d idx=%d ret=%d\n", len, idx, ret);
  2453. return ret;
  2454. }
  2455. static int
  2456. il4965_set_wep_dynamic_key_info(struct il_priv *il,
  2457. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2458. {
  2459. unsigned long flags;
  2460. __le16 key_flags = 0;
  2461. struct il_addsta_cmd sta_cmd;
  2462. lockdep_assert_held(&il->mutex);
  2463. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2464. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  2465. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2466. key_flags &= ~STA_KEY_FLG_INVALID;
  2467. if (keyconf->keylen == WEP_KEY_LEN_128)
  2468. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  2469. if (sta_id == il->hw_params.bcast_id)
  2470. key_flags |= STA_KEY_MULTICAST_MSK;
  2471. spin_lock_irqsave(&il->sta_lock, flags);
  2472. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2473. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2474. il->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  2475. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen);
  2476. memcpy(&il->stations[sta_id].sta.key.key[3], keyconf->key,
  2477. keyconf->keylen);
  2478. if ((il->stations[sta_id].sta.key.
  2479. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2480. il->stations[sta_id].sta.key.key_offset =
  2481. il_get_free_ucode_key_idx(il);
  2482. /* else, we are overriding an existing key => no need to allocated room
  2483. * in uCode. */
  2484. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2485. "no space for a new key");
  2486. il->stations[sta_id].sta.key.key_flags = key_flags;
  2487. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2488. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2489. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2490. sizeof(struct il_addsta_cmd));
  2491. spin_unlock_irqrestore(&il->sta_lock, flags);
  2492. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2493. }
  2494. static int
  2495. il4965_set_ccmp_dynamic_key_info(struct il_priv *il,
  2496. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2497. {
  2498. unsigned long flags;
  2499. __le16 key_flags = 0;
  2500. struct il_addsta_cmd sta_cmd;
  2501. lockdep_assert_held(&il->mutex);
  2502. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  2503. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2504. key_flags &= ~STA_KEY_FLG_INVALID;
  2505. if (sta_id == il->hw_params.bcast_id)
  2506. key_flags |= STA_KEY_MULTICAST_MSK;
  2507. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2508. spin_lock_irqsave(&il->sta_lock, flags);
  2509. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2510. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2511. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen);
  2512. memcpy(il->stations[sta_id].sta.key.key, keyconf->key, keyconf->keylen);
  2513. if ((il->stations[sta_id].sta.key.
  2514. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2515. il->stations[sta_id].sta.key.key_offset =
  2516. il_get_free_ucode_key_idx(il);
  2517. /* else, we are overriding an existing key => no need to allocated room
  2518. * in uCode. */
  2519. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2520. "no space for a new key");
  2521. il->stations[sta_id].sta.key.key_flags = key_flags;
  2522. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2523. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2524. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2525. sizeof(struct il_addsta_cmd));
  2526. spin_unlock_irqrestore(&il->sta_lock, flags);
  2527. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2528. }
  2529. static int
  2530. il4965_set_tkip_dynamic_key_info(struct il_priv *il,
  2531. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2532. {
  2533. unsigned long flags;
  2534. int ret = 0;
  2535. __le16 key_flags = 0;
  2536. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  2537. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2538. key_flags &= ~STA_KEY_FLG_INVALID;
  2539. if (sta_id == il->hw_params.bcast_id)
  2540. key_flags |= STA_KEY_MULTICAST_MSK;
  2541. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2542. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2543. spin_lock_irqsave(&il->sta_lock, flags);
  2544. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2545. il->stations[sta_id].keyinfo.keylen = 16;
  2546. if ((il->stations[sta_id].sta.key.
  2547. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2548. il->stations[sta_id].sta.key.key_offset =
  2549. il_get_free_ucode_key_idx(il);
  2550. /* else, we are overriding an existing key => no need to allocated room
  2551. * in uCode. */
  2552. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2553. "no space for a new key");
  2554. il->stations[sta_id].sta.key.key_flags = key_flags;
  2555. /* This copy is acutally not needed: we get the key with each TX */
  2556. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, 16);
  2557. memcpy(il->stations[sta_id].sta.key.key, keyconf->key, 16);
  2558. spin_unlock_irqrestore(&il->sta_lock, flags);
  2559. return ret;
  2560. }
  2561. void
  2562. il4965_update_tkip_key(struct il_priv *il, struct ieee80211_key_conf *keyconf,
  2563. struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
  2564. {
  2565. u8 sta_id;
  2566. unsigned long flags;
  2567. int i;
  2568. if (il_scan_cancel(il)) {
  2569. /* cancel scan failed, just live w/ bad key and rely
  2570. briefly on SW decryption */
  2571. return;
  2572. }
  2573. sta_id = il_sta_id_or_broadcast(il, sta);
  2574. if (sta_id == IL_INVALID_STATION)
  2575. return;
  2576. spin_lock_irqsave(&il->sta_lock, flags);
  2577. il->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  2578. for (i = 0; i < 5; i++)
  2579. il->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  2580. cpu_to_le16(phase1key[i]);
  2581. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2582. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2583. il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC);
  2584. spin_unlock_irqrestore(&il->sta_lock, flags);
  2585. }
  2586. int
  2587. il4965_remove_dynamic_key(struct il_priv *il,
  2588. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2589. {
  2590. unsigned long flags;
  2591. u16 key_flags;
  2592. u8 keyidx;
  2593. struct il_addsta_cmd sta_cmd;
  2594. lockdep_assert_held(&il->mutex);
  2595. il->_4965.key_mapping_keys--;
  2596. spin_lock_irqsave(&il->sta_lock, flags);
  2597. key_flags = le16_to_cpu(il->stations[sta_id].sta.key.key_flags);
  2598. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  2599. D_WEP("Remove dynamic key: idx=%d sta=%d\n", keyconf->keyidx, sta_id);
  2600. if (keyconf->keyidx != keyidx) {
  2601. /* We need to remove a key with idx different that the one
  2602. * in the uCode. This means that the key we need to remove has
  2603. * been replaced by another one with different idx.
  2604. * Don't do anything and return ok
  2605. */
  2606. spin_unlock_irqrestore(&il->sta_lock, flags);
  2607. return 0;
  2608. }
  2609. if (il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  2610. IL_WARN("Removing wrong key %d 0x%x\n", keyconf->keyidx,
  2611. key_flags);
  2612. spin_unlock_irqrestore(&il->sta_lock, flags);
  2613. return 0;
  2614. }
  2615. if (!test_and_clear_bit
  2616. (il->stations[sta_id].sta.key.key_offset, &il->ucode_key_table))
  2617. IL_ERR("idx %d not used in uCode key table.\n",
  2618. il->stations[sta_id].sta.key.key_offset);
  2619. memset(&il->stations[sta_id].keyinfo, 0, sizeof(struct il_hw_key));
  2620. memset(&il->stations[sta_id].sta.key, 0, sizeof(struct il4965_keyinfo));
  2621. il->stations[sta_id].sta.key.key_flags =
  2622. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  2623. il->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  2624. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2625. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2626. if (il_is_rfkill(il)) {
  2627. D_WEP
  2628. ("Not sending C_ADD_STA command because RFKILL enabled.\n");
  2629. spin_unlock_irqrestore(&il->sta_lock, flags);
  2630. return 0;
  2631. }
  2632. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2633. sizeof(struct il_addsta_cmd));
  2634. spin_unlock_irqrestore(&il->sta_lock, flags);
  2635. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2636. }
  2637. int
  2638. il4965_set_dynamic_key(struct il_priv *il, struct ieee80211_key_conf *keyconf,
  2639. u8 sta_id)
  2640. {
  2641. int ret;
  2642. lockdep_assert_held(&il->mutex);
  2643. il->_4965.key_mapping_keys++;
  2644. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  2645. switch (keyconf->cipher) {
  2646. case WLAN_CIPHER_SUITE_CCMP:
  2647. ret =
  2648. il4965_set_ccmp_dynamic_key_info(il, keyconf, sta_id);
  2649. break;
  2650. case WLAN_CIPHER_SUITE_TKIP:
  2651. ret =
  2652. il4965_set_tkip_dynamic_key_info(il, keyconf, sta_id);
  2653. break;
  2654. case WLAN_CIPHER_SUITE_WEP40:
  2655. case WLAN_CIPHER_SUITE_WEP104:
  2656. ret = il4965_set_wep_dynamic_key_info(il, keyconf, sta_id);
  2657. break;
  2658. default:
  2659. IL_ERR("Unknown alg: %s cipher = %x\n", __func__,
  2660. keyconf->cipher);
  2661. ret = -EINVAL;
  2662. }
  2663. D_WEP("Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
  2664. keyconf->cipher, keyconf->keylen, keyconf->keyidx, sta_id, ret);
  2665. return ret;
  2666. }
  2667. /**
  2668. * il4965_alloc_bcast_station - add broadcast station into driver's station table.
  2669. *
  2670. * This adds the broadcast station into the driver's station table
  2671. * and marks it driver active, so that it will be restored to the
  2672. * device at the next best time.
  2673. */
  2674. int
  2675. il4965_alloc_bcast_station(struct il_priv *il)
  2676. {
  2677. struct il_link_quality_cmd *link_cmd;
  2678. unsigned long flags;
  2679. u8 sta_id;
  2680. spin_lock_irqsave(&il->sta_lock, flags);
  2681. sta_id = il_prep_station(il, il_bcast_addr, false, NULL);
  2682. if (sta_id == IL_INVALID_STATION) {
  2683. IL_ERR("Unable to prepare broadcast station\n");
  2684. spin_unlock_irqrestore(&il->sta_lock, flags);
  2685. return -EINVAL;
  2686. }
  2687. il->stations[sta_id].used |= IL_STA_DRIVER_ACTIVE;
  2688. il->stations[sta_id].used |= IL_STA_BCAST;
  2689. spin_unlock_irqrestore(&il->sta_lock, flags);
  2690. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2691. if (!link_cmd) {
  2692. IL_ERR
  2693. ("Unable to initialize rate scaling for bcast station.\n");
  2694. return -ENOMEM;
  2695. }
  2696. spin_lock_irqsave(&il->sta_lock, flags);
  2697. il->stations[sta_id].lq = link_cmd;
  2698. spin_unlock_irqrestore(&il->sta_lock, flags);
  2699. return 0;
  2700. }
  2701. /**
  2702. * il4965_update_bcast_station - update broadcast station's LQ command
  2703. *
  2704. * Only used by iwl4965. Placed here to have all bcast station management
  2705. * code together.
  2706. */
  2707. static int
  2708. il4965_update_bcast_station(struct il_priv *il)
  2709. {
  2710. unsigned long flags;
  2711. struct il_link_quality_cmd *link_cmd;
  2712. u8 sta_id = il->hw_params.bcast_id;
  2713. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2714. if (!link_cmd) {
  2715. IL_ERR("Unable to initialize rate scaling for bcast sta.\n");
  2716. return -ENOMEM;
  2717. }
  2718. spin_lock_irqsave(&il->sta_lock, flags);
  2719. if (il->stations[sta_id].lq)
  2720. kfree(il->stations[sta_id].lq);
  2721. else
  2722. D_INFO("Bcast sta rate scaling has not been initialized.\n");
  2723. il->stations[sta_id].lq = link_cmd;
  2724. spin_unlock_irqrestore(&il->sta_lock, flags);
  2725. return 0;
  2726. }
  2727. int
  2728. il4965_update_bcast_stations(struct il_priv *il)
  2729. {
  2730. return il4965_update_bcast_station(il);
  2731. }
  2732. /**
  2733. * il4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  2734. */
  2735. int
  2736. il4965_sta_tx_modify_enable_tid(struct il_priv *il, int sta_id, int tid)
  2737. {
  2738. unsigned long flags;
  2739. struct il_addsta_cmd sta_cmd;
  2740. lockdep_assert_held(&il->mutex);
  2741. /* Remove "disable" flag, to enable Tx for this TID */
  2742. spin_lock_irqsave(&il->sta_lock, flags);
  2743. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  2744. il->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  2745. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2746. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2747. sizeof(struct il_addsta_cmd));
  2748. spin_unlock_irqrestore(&il->sta_lock, flags);
  2749. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2750. }
  2751. int
  2752. il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta, int tid,
  2753. u16 ssn)
  2754. {
  2755. unsigned long flags;
  2756. int sta_id;
  2757. struct il_addsta_cmd sta_cmd;
  2758. lockdep_assert_held(&il->mutex);
  2759. sta_id = il_sta_id(sta);
  2760. if (sta_id == IL_INVALID_STATION)
  2761. return -ENXIO;
  2762. spin_lock_irqsave(&il->sta_lock, flags);
  2763. il->stations[sta_id].sta.station_flags_msk = 0;
  2764. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  2765. il->stations[sta_id].sta.add_immediate_ba_tid = (u8) tid;
  2766. il->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  2767. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2768. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2769. sizeof(struct il_addsta_cmd));
  2770. spin_unlock_irqrestore(&il->sta_lock, flags);
  2771. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2772. }
  2773. int
  2774. il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta, int tid)
  2775. {
  2776. unsigned long flags;
  2777. int sta_id;
  2778. struct il_addsta_cmd sta_cmd;
  2779. lockdep_assert_held(&il->mutex);
  2780. sta_id = il_sta_id(sta);
  2781. if (sta_id == IL_INVALID_STATION) {
  2782. IL_ERR("Invalid station for AGG tid %d\n", tid);
  2783. return -ENXIO;
  2784. }
  2785. spin_lock_irqsave(&il->sta_lock, flags);
  2786. il->stations[sta_id].sta.station_flags_msk = 0;
  2787. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  2788. il->stations[sta_id].sta.remove_immediate_ba_tid = (u8) tid;
  2789. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2790. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2791. sizeof(struct il_addsta_cmd));
  2792. spin_unlock_irqrestore(&il->sta_lock, flags);
  2793. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2794. }
  2795. void
  2796. il4965_sta_modify_sleep_tx_count(struct il_priv *il, int sta_id, int cnt)
  2797. {
  2798. unsigned long flags;
  2799. spin_lock_irqsave(&il->sta_lock, flags);
  2800. il->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  2801. il->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  2802. il->stations[sta_id].sta.sta.modify_mask =
  2803. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  2804. il->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  2805. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2806. il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC);
  2807. spin_unlock_irqrestore(&il->sta_lock, flags);
  2808. }
  2809. void
  2810. il4965_update_chain_flags(struct il_priv *il)
  2811. {
  2812. if (il->ops->hcmd->set_rxon_chain) {
  2813. il->ops->hcmd->set_rxon_chain(il);
  2814. if (il->active.rx_chain != il->staging.rx_chain)
  2815. il_commit_rxon(il);
  2816. }
  2817. }
  2818. static void
  2819. il4965_clear_free_frames(struct il_priv *il)
  2820. {
  2821. struct list_head *element;
  2822. D_INFO("%d frames on pre-allocated heap on clear.\n", il->frames_count);
  2823. while (!list_empty(&il->free_frames)) {
  2824. element = il->free_frames.next;
  2825. list_del(element);
  2826. kfree(list_entry(element, struct il_frame, list));
  2827. il->frames_count--;
  2828. }
  2829. if (il->frames_count) {
  2830. IL_WARN("%d frames still in use. Did we lose one?\n",
  2831. il->frames_count);
  2832. il->frames_count = 0;
  2833. }
  2834. }
  2835. static struct il_frame *
  2836. il4965_get_free_frame(struct il_priv *il)
  2837. {
  2838. struct il_frame *frame;
  2839. struct list_head *element;
  2840. if (list_empty(&il->free_frames)) {
  2841. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  2842. if (!frame) {
  2843. IL_ERR("Could not allocate frame!\n");
  2844. return NULL;
  2845. }
  2846. il->frames_count++;
  2847. return frame;
  2848. }
  2849. element = il->free_frames.next;
  2850. list_del(element);
  2851. return list_entry(element, struct il_frame, list);
  2852. }
  2853. static void
  2854. il4965_free_frame(struct il_priv *il, struct il_frame *frame)
  2855. {
  2856. memset(frame, 0, sizeof(*frame));
  2857. list_add(&frame->list, &il->free_frames);
  2858. }
  2859. static u32
  2860. il4965_fill_beacon_frame(struct il_priv *il, struct ieee80211_hdr *hdr,
  2861. int left)
  2862. {
  2863. lockdep_assert_held(&il->mutex);
  2864. if (!il->beacon_skb)
  2865. return 0;
  2866. if (il->beacon_skb->len > left)
  2867. return 0;
  2868. memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len);
  2869. return il->beacon_skb->len;
  2870. }
  2871. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  2872. static void
  2873. il4965_set_beacon_tim(struct il_priv *il,
  2874. struct il_tx_beacon_cmd *tx_beacon_cmd, u8 * beacon,
  2875. u32 frame_size)
  2876. {
  2877. u16 tim_idx;
  2878. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  2879. /*
  2880. * The idx is relative to frame start but we start looking at the
  2881. * variable-length part of the beacon.
  2882. */
  2883. tim_idx = mgmt->u.beacon.variable - beacon;
  2884. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  2885. while ((tim_idx < (frame_size - 2)) &&
  2886. (beacon[tim_idx] != WLAN_EID_TIM))
  2887. tim_idx += beacon[tim_idx + 1] + 2;
  2888. /* If TIM field was found, set variables */
  2889. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  2890. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  2891. tx_beacon_cmd->tim_size = beacon[tim_idx + 1];
  2892. } else
  2893. IL_WARN("Unable to find TIM Element in beacon\n");
  2894. }
  2895. static unsigned int
  2896. il4965_hw_get_beacon_cmd(struct il_priv *il, struct il_frame *frame)
  2897. {
  2898. struct il_tx_beacon_cmd *tx_beacon_cmd;
  2899. u32 frame_size;
  2900. u32 rate_flags;
  2901. u32 rate;
  2902. /*
  2903. * We have to set up the TX command, the TX Beacon command, and the
  2904. * beacon contents.
  2905. */
  2906. lockdep_assert_held(&il->mutex);
  2907. if (!il->beacon_enabled) {
  2908. IL_ERR("Trying to build beacon without beaconing enabled\n");
  2909. return 0;
  2910. }
  2911. /* Initialize memory */
  2912. tx_beacon_cmd = &frame->u.beacon;
  2913. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2914. /* Set up TX beacon contents */
  2915. frame_size =
  2916. il4965_fill_beacon_frame(il, tx_beacon_cmd->frame,
  2917. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2918. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  2919. return 0;
  2920. if (!frame_size)
  2921. return 0;
  2922. /* Set up TX command fields */
  2923. tx_beacon_cmd->tx.len = cpu_to_le16((u16) frame_size);
  2924. tx_beacon_cmd->tx.sta_id = il->hw_params.bcast_id;
  2925. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2926. tx_beacon_cmd->tx.tx_flags =
  2927. TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK |
  2928. TX_CMD_FLG_STA_RATE_MSK;
  2929. /* Set up TX beacon command fields */
  2930. il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *) tx_beacon_cmd->frame,
  2931. frame_size);
  2932. /* Set up packet rate and flags */
  2933. rate = il_get_lowest_plcp(il);
  2934. il4965_toggle_tx_ant(il, &il->mgmt_tx_ant, il->hw_params.valid_tx_ant);
  2935. rate_flags = BIT(il->mgmt_tx_ant) << RATE_MCS_ANT_POS;
  2936. if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE))
  2937. rate_flags |= RATE_MCS_CCK_MSK;
  2938. tx_beacon_cmd->tx.rate_n_flags = cpu_to_le32(rate | rate_flags);
  2939. return sizeof(*tx_beacon_cmd) + frame_size;
  2940. }
  2941. int
  2942. il4965_send_beacon_cmd(struct il_priv *il)
  2943. {
  2944. struct il_frame *frame;
  2945. unsigned int frame_size;
  2946. int rc;
  2947. frame = il4965_get_free_frame(il);
  2948. if (!frame) {
  2949. IL_ERR("Could not obtain free frame buffer for beacon "
  2950. "command.\n");
  2951. return -ENOMEM;
  2952. }
  2953. frame_size = il4965_hw_get_beacon_cmd(il, frame);
  2954. if (!frame_size) {
  2955. IL_ERR("Error configuring the beacon command\n");
  2956. il4965_free_frame(il, frame);
  2957. return -EINVAL;
  2958. }
  2959. rc = il_send_cmd_pdu(il, C_TX_BEACON, frame_size, &frame->u.cmd[0]);
  2960. il4965_free_frame(il, frame);
  2961. return rc;
  2962. }
  2963. static inline dma_addr_t
  2964. il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx)
  2965. {
  2966. struct il_tfd_tb *tb = &tfd->tbs[idx];
  2967. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  2968. if (sizeof(dma_addr_t) > sizeof(u32))
  2969. addr |=
  2970. ((dma_addr_t) (le16_to_cpu(tb->hi_n_len) & 0xF) << 16) <<
  2971. 16;
  2972. return addr;
  2973. }
  2974. static inline u16
  2975. il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx)
  2976. {
  2977. struct il_tfd_tb *tb = &tfd->tbs[idx];
  2978. return le16_to_cpu(tb->hi_n_len) >> 4;
  2979. }
  2980. static inline void
  2981. il4965_tfd_set_tb(struct il_tfd *tfd, u8 idx, dma_addr_t addr, u16 len)
  2982. {
  2983. struct il_tfd_tb *tb = &tfd->tbs[idx];
  2984. u16 hi_n_len = len << 4;
  2985. put_unaligned_le32(addr, &tb->lo);
  2986. if (sizeof(dma_addr_t) > sizeof(u32))
  2987. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  2988. tb->hi_n_len = cpu_to_le16(hi_n_len);
  2989. tfd->num_tbs = idx + 1;
  2990. }
  2991. static inline u8
  2992. il4965_tfd_get_num_tbs(struct il_tfd *tfd)
  2993. {
  2994. return tfd->num_tbs & 0x1f;
  2995. }
  2996. /**
  2997. * il4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  2998. * @il - driver ilate data
  2999. * @txq - tx queue
  3000. *
  3001. * Does NOT advance any TFD circular buffer read/write idxes
  3002. * Does NOT free the TFD itself (which is within circular buffer)
  3003. */
  3004. void
  3005. il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
  3006. {
  3007. struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds;
  3008. struct il_tfd *tfd;
  3009. struct pci_dev *dev = il->pci_dev;
  3010. int idx = txq->q.read_ptr;
  3011. int i;
  3012. int num_tbs;
  3013. tfd = &tfd_tmp[idx];
  3014. /* Sanity check on number of chunks */
  3015. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3016. if (num_tbs >= IL_NUM_OF_TBS) {
  3017. IL_ERR("Too many chunks: %i\n", num_tbs);
  3018. /* @todo issue fatal error, it is quite serious situation */
  3019. return;
  3020. }
  3021. /* Unmap tx_cmd */
  3022. if (num_tbs)
  3023. pci_unmap_single(dev, dma_unmap_addr(&txq->meta[idx], mapping),
  3024. dma_unmap_len(&txq->meta[idx], len),
  3025. PCI_DMA_BIDIRECTIONAL);
  3026. /* Unmap chunks, if any. */
  3027. for (i = 1; i < num_tbs; i++)
  3028. pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i),
  3029. il4965_tfd_tb_get_len(tfd, i),
  3030. PCI_DMA_TODEVICE);
  3031. /* free SKB */
  3032. if (txq->skbs) {
  3033. struct sk_buff *skb = txq->skbs[txq->q.read_ptr];
  3034. /* can be called from irqs-disabled context */
  3035. if (skb) {
  3036. dev_kfree_skb_any(skb);
  3037. txq->skbs[txq->q.read_ptr] = NULL;
  3038. }
  3039. }
  3040. }
  3041. int
  3042. il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il, struct il_tx_queue *txq,
  3043. dma_addr_t addr, u16 len, u8 reset, u8 pad)
  3044. {
  3045. struct il_queue *q;
  3046. struct il_tfd *tfd, *tfd_tmp;
  3047. u32 num_tbs;
  3048. q = &txq->q;
  3049. tfd_tmp = (struct il_tfd *)txq->tfds;
  3050. tfd = &tfd_tmp[q->write_ptr];
  3051. if (reset)
  3052. memset(tfd, 0, sizeof(*tfd));
  3053. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3054. /* Each TFD can point to a maximum 20 Tx buffers */
  3055. if (num_tbs >= IL_NUM_OF_TBS) {
  3056. IL_ERR("Error can not send more than %d chunks\n",
  3057. IL_NUM_OF_TBS);
  3058. return -EINVAL;
  3059. }
  3060. BUG_ON(addr & ~DMA_BIT_MASK(36));
  3061. if (unlikely(addr & ~IL_TX_DMA_MASK))
  3062. IL_ERR("Unaligned address = %llx\n", (unsigned long long)addr);
  3063. il4965_tfd_set_tb(tfd, num_tbs, addr, len);
  3064. return 0;
  3065. }
  3066. /*
  3067. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  3068. * given Tx queue, and enable the DMA channel used for that queue.
  3069. *
  3070. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  3071. * channels supported in hardware.
  3072. */
  3073. int
  3074. il4965_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq)
  3075. {
  3076. int txq_id = txq->q.id;
  3077. /* Circular buffer (TFD queue in DRAM) physical base address */
  3078. il_wr(il, FH49_MEM_CBBC_QUEUE(txq_id), txq->q.dma_addr >> 8);
  3079. return 0;
  3080. }
  3081. /******************************************************************************
  3082. *
  3083. * Generic RX handler implementations
  3084. *
  3085. ******************************************************************************/
  3086. static void
  3087. il4965_hdl_alive(struct il_priv *il, struct il_rx_buf *rxb)
  3088. {
  3089. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3090. struct il_alive_resp *palive;
  3091. struct delayed_work *pwork;
  3092. palive = &pkt->u.alive_frame;
  3093. D_INFO("Alive ucode status 0x%08X revision " "0x%01X 0x%01X\n",
  3094. palive->is_valid, palive->ver_type, palive->ver_subtype);
  3095. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  3096. D_INFO("Initialization Alive received.\n");
  3097. memcpy(&il->card_alive_init, &pkt->u.alive_frame,
  3098. sizeof(struct il_init_alive_resp));
  3099. pwork = &il->init_alive_start;
  3100. } else {
  3101. D_INFO("Runtime Alive received.\n");
  3102. memcpy(&il->card_alive, &pkt->u.alive_frame,
  3103. sizeof(struct il_alive_resp));
  3104. pwork = &il->alive_start;
  3105. }
  3106. /* We delay the ALIVE response by 5ms to
  3107. * give the HW RF Kill time to activate... */
  3108. if (palive->is_valid == UCODE_VALID_OK)
  3109. queue_delayed_work(il->workqueue, pwork, msecs_to_jiffies(5));
  3110. else
  3111. IL_WARN("uCode did not respond OK.\n");
  3112. }
  3113. /**
  3114. * il4965_bg_stats_periodic - Timer callback to queue stats
  3115. *
  3116. * This callback is provided in order to send a stats request.
  3117. *
  3118. * This timer function is continually reset to execute within
  3119. * REG_RECALIB_PERIOD seconds since the last N_STATS
  3120. * was received. We need to ensure we receive the stats in order
  3121. * to update the temperature used for calibrating the TXPOWER.
  3122. */
  3123. static void
  3124. il4965_bg_stats_periodic(unsigned long data)
  3125. {
  3126. struct il_priv *il = (struct il_priv *)data;
  3127. if (test_bit(S_EXIT_PENDING, &il->status))
  3128. return;
  3129. /* dont send host command if rf-kill is on */
  3130. if (!il_is_ready_rf(il))
  3131. return;
  3132. il_send_stats_request(il, CMD_ASYNC, false);
  3133. }
  3134. static void
  3135. il4965_hdl_beacon(struct il_priv *il, struct il_rx_buf *rxb)
  3136. {
  3137. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3138. struct il4965_beacon_notif *beacon =
  3139. (struct il4965_beacon_notif *)pkt->u.raw;
  3140. #ifdef CONFIG_IWLEGACY_DEBUG
  3141. u8 rate = il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  3142. D_RX("beacon status %x retries %d iss %d tsf:0x%.8x%.8x rate %d\n",
  3143. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  3144. beacon->beacon_notify_hdr.failure_frame,
  3145. le32_to_cpu(beacon->ibss_mgr_status),
  3146. le32_to_cpu(beacon->high_tsf), le32_to_cpu(beacon->low_tsf), rate);
  3147. #endif
  3148. il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  3149. }
  3150. static void
  3151. il4965_perform_ct_kill_task(struct il_priv *il)
  3152. {
  3153. unsigned long flags;
  3154. D_POWER("Stop all queues\n");
  3155. if (il->mac80211_registered)
  3156. ieee80211_stop_queues(il->hw);
  3157. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3158. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  3159. _il_rd(il, CSR_UCODE_DRV_GP1);
  3160. spin_lock_irqsave(&il->reg_lock, flags);
  3161. if (!_il_grab_nic_access(il))
  3162. _il_release_nic_access(il);
  3163. spin_unlock_irqrestore(&il->reg_lock, flags);
  3164. }
  3165. /* Handle notification from uCode that card's power state is changing
  3166. * due to software, hardware, or critical temperature RFKILL */
  3167. static void
  3168. il4965_hdl_card_state(struct il_priv *il, struct il_rx_buf *rxb)
  3169. {
  3170. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3171. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  3172. unsigned long status = il->status;
  3173. D_RF_KILL("Card state received: HW:%s SW:%s CT:%s\n",
  3174. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  3175. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  3176. (flags & CT_CARD_DISABLED) ? "Reached" : "Not reached");
  3177. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | CT_CARD_DISABLED)) {
  3178. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3179. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3180. il_wr(il, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3181. if (!(flags & RXON_CARD_DISABLED)) {
  3182. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  3183. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3184. il_wr(il, HBUS_TARG_MBX_C,
  3185. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3186. }
  3187. }
  3188. if (flags & CT_CARD_DISABLED)
  3189. il4965_perform_ct_kill_task(il);
  3190. if (flags & HW_CARD_DISABLED)
  3191. set_bit(S_RF_KILL_HW, &il->status);
  3192. else
  3193. clear_bit(S_RF_KILL_HW, &il->status);
  3194. if (!(flags & RXON_CARD_DISABLED))
  3195. il_scan_cancel(il);
  3196. if ((test_bit(S_RF_KILL_HW, &status) !=
  3197. test_bit(S_RF_KILL_HW, &il->status)))
  3198. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  3199. test_bit(S_RF_KILL_HW, &il->status));
  3200. else
  3201. wake_up(&il->wait_command_queue);
  3202. }
  3203. /**
  3204. * il4965_setup_handlers - Initialize Rx handler callbacks
  3205. *
  3206. * Setup the RX handlers for each of the reply types sent from the uCode
  3207. * to the host.
  3208. *
  3209. * This function chains into the hardware specific files for them to setup
  3210. * any hardware specific handlers as well.
  3211. */
  3212. static void
  3213. il4965_setup_handlers(struct il_priv *il)
  3214. {
  3215. il->handlers[N_ALIVE] = il4965_hdl_alive;
  3216. il->handlers[N_ERROR] = il_hdl_error;
  3217. il->handlers[N_CHANNEL_SWITCH] = il_hdl_csa;
  3218. il->handlers[N_SPECTRUM_MEASUREMENT] = il_hdl_spectrum_measurement;
  3219. il->handlers[N_PM_SLEEP] = il_hdl_pm_sleep;
  3220. il->handlers[N_PM_DEBUG_STATS] = il_hdl_pm_debug_stats;
  3221. il->handlers[N_BEACON] = il4965_hdl_beacon;
  3222. /*
  3223. * The same handler is used for both the REPLY to a discrete
  3224. * stats request from the host as well as for the periodic
  3225. * stats notifications (after received beacons) from the uCode.
  3226. */
  3227. il->handlers[C_STATS] = il4965_hdl_c_stats;
  3228. il->handlers[N_STATS] = il4965_hdl_stats;
  3229. il_setup_rx_scan_handlers(il);
  3230. /* status change handler */
  3231. il->handlers[N_CARD_STATE] = il4965_hdl_card_state;
  3232. il->handlers[N_MISSED_BEACONS] = il4965_hdl_missed_beacon;
  3233. /* Rx handlers */
  3234. il->handlers[N_RX_PHY] = il4965_hdl_rx_phy;
  3235. il->handlers[N_RX_MPDU] = il4965_hdl_rx;
  3236. /* block ack */
  3237. il->handlers[N_COMPRESSED_BA] = il4965_hdl_compressed_ba;
  3238. /* Set up hardware specific Rx handlers */
  3239. il->ops->lib->handler_setup(il);
  3240. }
  3241. /**
  3242. * il4965_rx_handle - Main entry function for receiving responses from uCode
  3243. *
  3244. * Uses the il->handlers callback function array to invoke
  3245. * the appropriate handlers, including command responses,
  3246. * frame-received notifications, and other notifications.
  3247. */
  3248. void
  3249. il4965_rx_handle(struct il_priv *il)
  3250. {
  3251. struct il_rx_buf *rxb;
  3252. struct il_rx_pkt *pkt;
  3253. struct il_rx_queue *rxq = &il->rxq;
  3254. u32 r, i;
  3255. int reclaim;
  3256. unsigned long flags;
  3257. u8 fill_rx = 0;
  3258. u32 count = 8;
  3259. int total_empty;
  3260. /* uCode's read idx (stored in shared DRAM) indicates the last Rx
  3261. * buffer that the driver may process (last buffer filled by ucode). */
  3262. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  3263. i = rxq->read;
  3264. /* Rx interrupt, but nothing sent from uCode */
  3265. if (i == r)
  3266. D_RX("r = %d, i = %d\n", r, i);
  3267. /* calculate total frames need to be restock after handling RX */
  3268. total_empty = r - rxq->write_actual;
  3269. if (total_empty < 0)
  3270. total_empty += RX_QUEUE_SIZE;
  3271. if (total_empty > (RX_QUEUE_SIZE / 2))
  3272. fill_rx = 1;
  3273. while (i != r) {
  3274. int len;
  3275. rxb = rxq->queue[i];
  3276. /* If an RXB doesn't have a Rx queue slot associated with it,
  3277. * then a bug has been introduced in the queue refilling
  3278. * routines -- catch it here */
  3279. BUG_ON(rxb == NULL);
  3280. rxq->queue[i] = NULL;
  3281. pci_unmap_page(il->pci_dev, rxb->page_dma,
  3282. PAGE_SIZE << il->hw_params.rx_page_order,
  3283. PCI_DMA_FROMDEVICE);
  3284. pkt = rxb_addr(rxb);
  3285. len = le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK;
  3286. len += sizeof(u32); /* account for status word */
  3287. /* Reclaim a command buffer only if this packet is a response
  3288. * to a (driver-originated) command.
  3289. * If the packet (e.g. Rx frame) originated from uCode,
  3290. * there is no command buffer to reclaim.
  3291. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3292. * but apparently a few don't get set; catch them here. */
  3293. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3294. (pkt->hdr.cmd != N_RX_PHY) && (pkt->hdr.cmd != N_RX) &&
  3295. (pkt->hdr.cmd != N_RX_MPDU) &&
  3296. (pkt->hdr.cmd != N_COMPRESSED_BA) &&
  3297. (pkt->hdr.cmd != N_STATS) && (pkt->hdr.cmd != C_TX);
  3298. /* Based on type of command response or notification,
  3299. * handle those that need handling via function in
  3300. * handlers table. See il4965_setup_handlers() */
  3301. if (il->handlers[pkt->hdr.cmd]) {
  3302. D_RX("r = %d, i = %d, %s, 0x%02x\n", r, i,
  3303. il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3304. il->isr_stats.handlers[pkt->hdr.cmd]++;
  3305. il->handlers[pkt->hdr.cmd] (il, rxb);
  3306. } else {
  3307. /* No handling needed */
  3308. D_RX("r %d i %d No handler needed for %s, 0x%02x\n", r,
  3309. i, il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3310. }
  3311. /*
  3312. * XXX: After here, we should always check rxb->page
  3313. * against NULL before touching it or its virtual
  3314. * memory (pkt). Because some handler might have
  3315. * already taken or freed the pages.
  3316. */
  3317. if (reclaim) {
  3318. /* Invoke any callbacks, transfer the buffer to caller,
  3319. * and fire off the (possibly) blocking il_send_cmd()
  3320. * as we reclaim the driver command queue */
  3321. if (rxb->page)
  3322. il_tx_cmd_complete(il, rxb);
  3323. else
  3324. IL_WARN("Claim null rxb?\n");
  3325. }
  3326. /* Reuse the page if possible. For notification packets and
  3327. * SKBs that fail to Rx correctly, add them back into the
  3328. * rx_free list for reuse later. */
  3329. spin_lock_irqsave(&rxq->lock, flags);
  3330. if (rxb->page != NULL) {
  3331. rxb->page_dma =
  3332. pci_map_page(il->pci_dev, rxb->page, 0,
  3333. PAGE_SIZE << il->hw_params.
  3334. rx_page_order, PCI_DMA_FROMDEVICE);
  3335. list_add_tail(&rxb->list, &rxq->rx_free);
  3336. rxq->free_count++;
  3337. } else
  3338. list_add_tail(&rxb->list, &rxq->rx_used);
  3339. spin_unlock_irqrestore(&rxq->lock, flags);
  3340. i = (i + 1) & RX_QUEUE_MASK;
  3341. /* If there are a lot of unused frames,
  3342. * restock the Rx queue so ucode wont assert. */
  3343. if (fill_rx) {
  3344. count++;
  3345. if (count >= 8) {
  3346. rxq->read = i;
  3347. il4965_rx_replenish_now(il);
  3348. count = 0;
  3349. }
  3350. }
  3351. }
  3352. /* Backtrack one entry */
  3353. rxq->read = i;
  3354. if (fill_rx)
  3355. il4965_rx_replenish_now(il);
  3356. else
  3357. il4965_rx_queue_restock(il);
  3358. }
  3359. /* call this function to flush any scheduled tasklet */
  3360. static inline void
  3361. il4965_synchronize_irq(struct il_priv *il)
  3362. {
  3363. /* wait to make sure we flush pending tasklet */
  3364. synchronize_irq(il->pci_dev->irq);
  3365. tasklet_kill(&il->irq_tasklet);
  3366. }
  3367. static void
  3368. il4965_irq_tasklet(struct il_priv *il)
  3369. {
  3370. u32 inta, handled = 0;
  3371. u32 inta_fh;
  3372. unsigned long flags;
  3373. u32 i;
  3374. #ifdef CONFIG_IWLEGACY_DEBUG
  3375. u32 inta_mask;
  3376. #endif
  3377. spin_lock_irqsave(&il->lock, flags);
  3378. /* Ack/clear/reset pending uCode interrupts.
  3379. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  3380. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  3381. inta = _il_rd(il, CSR_INT);
  3382. _il_wr(il, CSR_INT, inta);
  3383. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  3384. * Any new interrupts that happen after this, either while we're
  3385. * in this tasklet, or later, will show up in next ISR/tasklet. */
  3386. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3387. _il_wr(il, CSR_FH_INT_STATUS, inta_fh);
  3388. #ifdef CONFIG_IWLEGACY_DEBUG
  3389. if (il_get_debug_level(il) & IL_DL_ISR) {
  3390. /* just for debug */
  3391. inta_mask = _il_rd(il, CSR_INT_MASK);
  3392. D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta,
  3393. inta_mask, inta_fh);
  3394. }
  3395. #endif
  3396. spin_unlock_irqrestore(&il->lock, flags);
  3397. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  3398. * atomic, make sure that inta covers all the interrupts that
  3399. * we've discovered, even if FH interrupt came in just after
  3400. * reading CSR_INT. */
  3401. if (inta_fh & CSR49_FH_INT_RX_MASK)
  3402. inta |= CSR_INT_BIT_FH_RX;
  3403. if (inta_fh & CSR49_FH_INT_TX_MASK)
  3404. inta |= CSR_INT_BIT_FH_TX;
  3405. /* Now service all interrupt bits discovered above. */
  3406. if (inta & CSR_INT_BIT_HW_ERR) {
  3407. IL_ERR("Hardware error detected. Restarting.\n");
  3408. /* Tell the device to stop sending interrupts */
  3409. il_disable_interrupts(il);
  3410. il->isr_stats.hw++;
  3411. il_irq_handle_error(il);
  3412. handled |= CSR_INT_BIT_HW_ERR;
  3413. return;
  3414. }
  3415. #ifdef CONFIG_IWLEGACY_DEBUG
  3416. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3417. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  3418. if (inta & CSR_INT_BIT_SCD) {
  3419. D_ISR("Scheduler finished to transmit "
  3420. "the frame/frames.\n");
  3421. il->isr_stats.sch++;
  3422. }
  3423. /* Alive notification via Rx interrupt will do the real work */
  3424. if (inta & CSR_INT_BIT_ALIVE) {
  3425. D_ISR("Alive interrupt\n");
  3426. il->isr_stats.alive++;
  3427. }
  3428. }
  3429. #endif
  3430. /* Safely ignore these bits for debug checks below */
  3431. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  3432. /* HW RF KILL switch toggled */
  3433. if (inta & CSR_INT_BIT_RF_KILL) {
  3434. int hw_rf_kill = 0;
  3435. if (!
  3436. (_il_rd(il, CSR_GP_CNTRL) &
  3437. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  3438. hw_rf_kill = 1;
  3439. IL_WARN("RF_KILL bit toggled to %s.\n",
  3440. hw_rf_kill ? "disable radio" : "enable radio");
  3441. il->isr_stats.rfkill++;
  3442. /* driver only loads ucode once setting the interface up.
  3443. * the driver allows loading the ucode even if the radio
  3444. * is killed. Hence update the killswitch state here. The
  3445. * rfkill handler will care about restarting if needed.
  3446. */
  3447. if (!test_bit(S_ALIVE, &il->status)) {
  3448. if (hw_rf_kill)
  3449. set_bit(S_RF_KILL_HW, &il->status);
  3450. else
  3451. clear_bit(S_RF_KILL_HW, &il->status);
  3452. wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill);
  3453. }
  3454. handled |= CSR_INT_BIT_RF_KILL;
  3455. }
  3456. /* Chip got too hot and stopped itself */
  3457. if (inta & CSR_INT_BIT_CT_KILL) {
  3458. IL_ERR("Microcode CT kill error detected.\n");
  3459. il->isr_stats.ctkill++;
  3460. handled |= CSR_INT_BIT_CT_KILL;
  3461. }
  3462. /* Error detected by uCode */
  3463. if (inta & CSR_INT_BIT_SW_ERR) {
  3464. IL_ERR("Microcode SW error detected. " " Restarting 0x%X.\n",
  3465. inta);
  3466. il->isr_stats.sw++;
  3467. il_irq_handle_error(il);
  3468. handled |= CSR_INT_BIT_SW_ERR;
  3469. }
  3470. /*
  3471. * uCode wakes up after power-down sleep.
  3472. * Tell device about any new tx or host commands enqueued,
  3473. * and about any Rx buffers made available while asleep.
  3474. */
  3475. if (inta & CSR_INT_BIT_WAKEUP) {
  3476. D_ISR("Wakeup interrupt\n");
  3477. il_rx_queue_update_write_ptr(il, &il->rxq);
  3478. for (i = 0; i < il->hw_params.max_txq_num; i++)
  3479. il_txq_update_write_ptr(il, &il->txq[i]);
  3480. il->isr_stats.wakeup++;
  3481. handled |= CSR_INT_BIT_WAKEUP;
  3482. }
  3483. /* All uCode command responses, including Tx command responses,
  3484. * Rx "responses" (frame-received notification), and other
  3485. * notifications from uCode come through here*/
  3486. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  3487. il4965_rx_handle(il);
  3488. il->isr_stats.rx++;
  3489. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  3490. }
  3491. /* This "Tx" DMA channel is used only for loading uCode */
  3492. if (inta & CSR_INT_BIT_FH_TX) {
  3493. D_ISR("uCode load interrupt\n");
  3494. il->isr_stats.tx++;
  3495. handled |= CSR_INT_BIT_FH_TX;
  3496. /* Wake up uCode load routine, now that load is complete */
  3497. il->ucode_write_complete = 1;
  3498. wake_up(&il->wait_command_queue);
  3499. }
  3500. if (inta & ~handled) {
  3501. IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  3502. il->isr_stats.unhandled++;
  3503. }
  3504. if (inta & ~(il->inta_mask)) {
  3505. IL_WARN("Disabled INTA bits 0x%08x were pending\n",
  3506. inta & ~il->inta_mask);
  3507. IL_WARN(" with FH49_INT = 0x%08x\n", inta_fh);
  3508. }
  3509. /* Re-enable all interrupts */
  3510. /* only Re-enable if disabled by irq */
  3511. if (test_bit(S_INT_ENABLED, &il->status))
  3512. il_enable_interrupts(il);
  3513. /* Re-enable RF_KILL if it occurred */
  3514. else if (handled & CSR_INT_BIT_RF_KILL)
  3515. il_enable_rfkill_int(il);
  3516. #ifdef CONFIG_IWLEGACY_DEBUG
  3517. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3518. inta = _il_rd(il, CSR_INT);
  3519. inta_mask = _il_rd(il, CSR_INT_MASK);
  3520. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3521. D_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  3522. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  3523. }
  3524. #endif
  3525. }
  3526. /*****************************************************************************
  3527. *
  3528. * sysfs attributes
  3529. *
  3530. *****************************************************************************/
  3531. #ifdef CONFIG_IWLEGACY_DEBUG
  3532. /*
  3533. * The following adds a new attribute to the sysfs representation
  3534. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  3535. * used for controlling the debug level.
  3536. *
  3537. * See the level definitions in iwl for details.
  3538. *
  3539. * The debug_level being managed using sysfs below is a per device debug
  3540. * level that is used instead of the global debug level if it (the per
  3541. * device debug level) is set.
  3542. */
  3543. static ssize_t
  3544. il4965_show_debug_level(struct device *d, struct device_attribute *attr,
  3545. char *buf)
  3546. {
  3547. struct il_priv *il = dev_get_drvdata(d);
  3548. return sprintf(buf, "0x%08X\n", il_get_debug_level(il));
  3549. }
  3550. static ssize_t
  3551. il4965_store_debug_level(struct device *d, struct device_attribute *attr,
  3552. const char *buf, size_t count)
  3553. {
  3554. struct il_priv *il = dev_get_drvdata(d);
  3555. unsigned long val;
  3556. int ret;
  3557. ret = strict_strtoul(buf, 0, &val);
  3558. if (ret)
  3559. IL_ERR("%s is not in hex or decimal form.\n", buf);
  3560. else {
  3561. il->debug_level = val;
  3562. if (il_alloc_traffic_mem(il))
  3563. IL_ERR("Not enough memory to generate traffic log\n");
  3564. }
  3565. return strnlen(buf, count);
  3566. }
  3567. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, il4965_show_debug_level,
  3568. il4965_store_debug_level);
  3569. #endif /* CONFIG_IWLEGACY_DEBUG */
  3570. static ssize_t
  3571. il4965_show_temperature(struct device *d, struct device_attribute *attr,
  3572. char *buf)
  3573. {
  3574. struct il_priv *il = dev_get_drvdata(d);
  3575. if (!il_is_alive(il))
  3576. return -EAGAIN;
  3577. return sprintf(buf, "%d\n", il->temperature);
  3578. }
  3579. static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL);
  3580. static ssize_t
  3581. il4965_show_tx_power(struct device *d, struct device_attribute *attr, char *buf)
  3582. {
  3583. struct il_priv *il = dev_get_drvdata(d);
  3584. if (!il_is_ready_rf(il))
  3585. return sprintf(buf, "off\n");
  3586. else
  3587. return sprintf(buf, "%d\n", il->tx_power_user_lmt);
  3588. }
  3589. static ssize_t
  3590. il4965_store_tx_power(struct device *d, struct device_attribute *attr,
  3591. const char *buf, size_t count)
  3592. {
  3593. struct il_priv *il = dev_get_drvdata(d);
  3594. unsigned long val;
  3595. int ret;
  3596. ret = strict_strtoul(buf, 10, &val);
  3597. if (ret)
  3598. IL_INFO("%s is not in decimal form.\n", buf);
  3599. else {
  3600. ret = il_set_tx_power(il, val, false);
  3601. if (ret)
  3602. IL_ERR("failed setting tx power (0x%d).\n", ret);
  3603. else
  3604. ret = count;
  3605. }
  3606. return ret;
  3607. }
  3608. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, il4965_show_tx_power,
  3609. il4965_store_tx_power);
  3610. static struct attribute *il_sysfs_entries[] = {
  3611. &dev_attr_temperature.attr,
  3612. &dev_attr_tx_power.attr,
  3613. #ifdef CONFIG_IWLEGACY_DEBUG
  3614. &dev_attr_debug_level.attr,
  3615. #endif
  3616. NULL
  3617. };
  3618. static struct attribute_group il_attribute_group = {
  3619. .name = NULL, /* put in device directory */
  3620. .attrs = il_sysfs_entries,
  3621. };
  3622. /******************************************************************************
  3623. *
  3624. * uCode download functions
  3625. *
  3626. ******************************************************************************/
  3627. static void
  3628. il4965_dealloc_ucode_pci(struct il_priv *il)
  3629. {
  3630. il_free_fw_desc(il->pci_dev, &il->ucode_code);
  3631. il_free_fw_desc(il->pci_dev, &il->ucode_data);
  3632. il_free_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3633. il_free_fw_desc(il->pci_dev, &il->ucode_init);
  3634. il_free_fw_desc(il->pci_dev, &il->ucode_init_data);
  3635. il_free_fw_desc(il->pci_dev, &il->ucode_boot);
  3636. }
  3637. static void
  3638. il4965_nic_start(struct il_priv *il)
  3639. {
  3640. /* Remove all resets to allow NIC to operate */
  3641. _il_wr(il, CSR_RESET, 0);
  3642. }
  3643. static void il4965_ucode_callback(const struct firmware *ucode_raw,
  3644. void *context);
  3645. static int il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length);
  3646. static int __must_check
  3647. il4965_request_firmware(struct il_priv *il, bool first)
  3648. {
  3649. const char *name_pre = il->cfg->fw_name_pre;
  3650. char tag[8];
  3651. if (first) {
  3652. il->fw_idx = il->cfg->ucode_api_max;
  3653. sprintf(tag, "%d", il->fw_idx);
  3654. } else {
  3655. il->fw_idx--;
  3656. sprintf(tag, "%d", il->fw_idx);
  3657. }
  3658. if (il->fw_idx < il->cfg->ucode_api_min) {
  3659. IL_ERR("no suitable firmware found!\n");
  3660. return -ENOENT;
  3661. }
  3662. sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  3663. D_INFO("attempting to load firmware '%s'\n", il->firmware_name);
  3664. return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name,
  3665. &il->pci_dev->dev, GFP_KERNEL, il,
  3666. il4965_ucode_callback);
  3667. }
  3668. struct il4965_firmware_pieces {
  3669. const void *inst, *data, *init, *init_data, *boot;
  3670. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  3671. };
  3672. static int
  3673. il4965_load_firmware(struct il_priv *il, const struct firmware *ucode_raw,
  3674. struct il4965_firmware_pieces *pieces)
  3675. {
  3676. struct il_ucode_header *ucode = (void *)ucode_raw->data;
  3677. u32 api_ver, hdr_size;
  3678. const u8 *src;
  3679. il->ucode_ver = le32_to_cpu(ucode->ver);
  3680. api_ver = IL_UCODE_API(il->ucode_ver);
  3681. switch (api_ver) {
  3682. default:
  3683. case 0:
  3684. case 1:
  3685. case 2:
  3686. hdr_size = 24;
  3687. if (ucode_raw->size < hdr_size) {
  3688. IL_ERR("File size too small!\n");
  3689. return -EINVAL;
  3690. }
  3691. pieces->inst_size = le32_to_cpu(ucode->v1.inst_size);
  3692. pieces->data_size = le32_to_cpu(ucode->v1.data_size);
  3693. pieces->init_size = le32_to_cpu(ucode->v1.init_size);
  3694. pieces->init_data_size = le32_to_cpu(ucode->v1.init_data_size);
  3695. pieces->boot_size = le32_to_cpu(ucode->v1.boot_size);
  3696. src = ucode->v1.data;
  3697. break;
  3698. }
  3699. /* Verify size of file vs. image size info in file's header */
  3700. if (ucode_raw->size !=
  3701. hdr_size + pieces->inst_size + pieces->data_size +
  3702. pieces->init_size + pieces->init_data_size + pieces->boot_size) {
  3703. IL_ERR("uCode file size %d does not match expected size\n",
  3704. (int)ucode_raw->size);
  3705. return -EINVAL;
  3706. }
  3707. pieces->inst = src;
  3708. src += pieces->inst_size;
  3709. pieces->data = src;
  3710. src += pieces->data_size;
  3711. pieces->init = src;
  3712. src += pieces->init_size;
  3713. pieces->init_data = src;
  3714. src += pieces->init_data_size;
  3715. pieces->boot = src;
  3716. src += pieces->boot_size;
  3717. return 0;
  3718. }
  3719. /**
  3720. * il4965_ucode_callback - callback when firmware was loaded
  3721. *
  3722. * If loaded successfully, copies the firmware into buffers
  3723. * for the card to fetch (via DMA).
  3724. */
  3725. static void
  3726. il4965_ucode_callback(const struct firmware *ucode_raw, void *context)
  3727. {
  3728. struct il_priv *il = context;
  3729. struct il_ucode_header *ucode;
  3730. int err;
  3731. struct il4965_firmware_pieces pieces;
  3732. const unsigned int api_max = il->cfg->ucode_api_max;
  3733. const unsigned int api_min = il->cfg->ucode_api_min;
  3734. u32 api_ver;
  3735. u32 max_probe_length = 200;
  3736. u32 standard_phy_calibration_size =
  3737. IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  3738. memset(&pieces, 0, sizeof(pieces));
  3739. if (!ucode_raw) {
  3740. if (il->fw_idx <= il->cfg->ucode_api_max)
  3741. IL_ERR("request for firmware file '%s' failed.\n",
  3742. il->firmware_name);
  3743. goto try_again;
  3744. }
  3745. D_INFO("Loaded firmware file '%s' (%zd bytes).\n", il->firmware_name,
  3746. ucode_raw->size);
  3747. /* Make sure that we got at least the API version number */
  3748. if (ucode_raw->size < 4) {
  3749. IL_ERR("File size way too small!\n");
  3750. goto try_again;
  3751. }
  3752. /* Data from ucode file: header followed by uCode images */
  3753. ucode = (struct il_ucode_header *)ucode_raw->data;
  3754. err = il4965_load_firmware(il, ucode_raw, &pieces);
  3755. if (err)
  3756. goto try_again;
  3757. api_ver = IL_UCODE_API(il->ucode_ver);
  3758. /*
  3759. * api_ver should match the api version forming part of the
  3760. * firmware filename ... but we don't check for that and only rely
  3761. * on the API version read from firmware header from here on forward
  3762. */
  3763. if (api_ver < api_min || api_ver > api_max) {
  3764. IL_ERR("Driver unable to support your firmware API. "
  3765. "Driver supports v%u, firmware is v%u.\n", api_max,
  3766. api_ver);
  3767. goto try_again;
  3768. }
  3769. if (api_ver != api_max)
  3770. IL_ERR("Firmware has old API version. Expected v%u, "
  3771. "got v%u. New firmware can be obtained "
  3772. "from http://www.intellinuxwireless.org.\n", api_max,
  3773. api_ver);
  3774. IL_INFO("loaded firmware version %u.%u.%u.%u\n",
  3775. IL_UCODE_MAJOR(il->ucode_ver), IL_UCODE_MINOR(il->ucode_ver),
  3776. IL_UCODE_API(il->ucode_ver), IL_UCODE_SERIAL(il->ucode_ver));
  3777. snprintf(il->hw->wiphy->fw_version, sizeof(il->hw->wiphy->fw_version),
  3778. "%u.%u.%u.%u", IL_UCODE_MAJOR(il->ucode_ver),
  3779. IL_UCODE_MINOR(il->ucode_ver), IL_UCODE_API(il->ucode_ver),
  3780. IL_UCODE_SERIAL(il->ucode_ver));
  3781. /*
  3782. * For any of the failures below (before allocating pci memory)
  3783. * we will try to load a version with a smaller API -- maybe the
  3784. * user just got a corrupted version of the latest API.
  3785. */
  3786. D_INFO("f/w package hdr ucode version raw = 0x%x\n", il->ucode_ver);
  3787. D_INFO("f/w package hdr runtime inst size = %Zd\n", pieces.inst_size);
  3788. D_INFO("f/w package hdr runtime data size = %Zd\n", pieces.data_size);
  3789. D_INFO("f/w package hdr init inst size = %Zd\n", pieces.init_size);
  3790. D_INFO("f/w package hdr init data size = %Zd\n", pieces.init_data_size);
  3791. D_INFO("f/w package hdr boot inst size = %Zd\n", pieces.boot_size);
  3792. /* Verify that uCode images will fit in card's SRAM */
  3793. if (pieces.inst_size > il->hw_params.max_inst_size) {
  3794. IL_ERR("uCode instr len %Zd too large to fit in\n",
  3795. pieces.inst_size);
  3796. goto try_again;
  3797. }
  3798. if (pieces.data_size > il->hw_params.max_data_size) {
  3799. IL_ERR("uCode data len %Zd too large to fit in\n",
  3800. pieces.data_size);
  3801. goto try_again;
  3802. }
  3803. if (pieces.init_size > il->hw_params.max_inst_size) {
  3804. IL_ERR("uCode init instr len %Zd too large to fit in\n",
  3805. pieces.init_size);
  3806. goto try_again;
  3807. }
  3808. if (pieces.init_data_size > il->hw_params.max_data_size) {
  3809. IL_ERR("uCode init data len %Zd too large to fit in\n",
  3810. pieces.init_data_size);
  3811. goto try_again;
  3812. }
  3813. if (pieces.boot_size > il->hw_params.max_bsm_size) {
  3814. IL_ERR("uCode boot instr len %Zd too large to fit in\n",
  3815. pieces.boot_size);
  3816. goto try_again;
  3817. }
  3818. /* Allocate ucode buffers for card's bus-master loading ... */
  3819. /* Runtime instructions and 2 copies of data:
  3820. * 1) unmodified from disk
  3821. * 2) backup cache for save/restore during power-downs */
  3822. il->ucode_code.len = pieces.inst_size;
  3823. il_alloc_fw_desc(il->pci_dev, &il->ucode_code);
  3824. il->ucode_data.len = pieces.data_size;
  3825. il_alloc_fw_desc(il->pci_dev, &il->ucode_data);
  3826. il->ucode_data_backup.len = pieces.data_size;
  3827. il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3828. if (!il->ucode_code.v_addr || !il->ucode_data.v_addr ||
  3829. !il->ucode_data_backup.v_addr)
  3830. goto err_pci_alloc;
  3831. /* Initialization instructions and data */
  3832. if (pieces.init_size && pieces.init_data_size) {
  3833. il->ucode_init.len = pieces.init_size;
  3834. il_alloc_fw_desc(il->pci_dev, &il->ucode_init);
  3835. il->ucode_init_data.len = pieces.init_data_size;
  3836. il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data);
  3837. if (!il->ucode_init.v_addr || !il->ucode_init_data.v_addr)
  3838. goto err_pci_alloc;
  3839. }
  3840. /* Bootstrap (instructions only, no data) */
  3841. if (pieces.boot_size) {
  3842. il->ucode_boot.len = pieces.boot_size;
  3843. il_alloc_fw_desc(il->pci_dev, &il->ucode_boot);
  3844. if (!il->ucode_boot.v_addr)
  3845. goto err_pci_alloc;
  3846. }
  3847. /* Now that we can no longer fail, copy information */
  3848. il->sta_key_max_num = STA_KEY_MAX_NUM;
  3849. /* Copy images into buffers for card's bus-master reads ... */
  3850. /* Runtime instructions (first block of data in file) */
  3851. D_INFO("Copying (but not loading) uCode instr len %Zd\n",
  3852. pieces.inst_size);
  3853. memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  3854. D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  3855. il->ucode_code.v_addr, (u32) il->ucode_code.p_addr);
  3856. /*
  3857. * Runtime data
  3858. * NOTE: Copy into backup buffer will be done in il_up()
  3859. */
  3860. D_INFO("Copying (but not loading) uCode data len %Zd\n",
  3861. pieces.data_size);
  3862. memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size);
  3863. memcpy(il->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  3864. /* Initialization instructions */
  3865. if (pieces.init_size) {
  3866. D_INFO("Copying (but not loading) init instr len %Zd\n",
  3867. pieces.init_size);
  3868. memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size);
  3869. }
  3870. /* Initialization data */
  3871. if (pieces.init_data_size) {
  3872. D_INFO("Copying (but not loading) init data len %Zd\n",
  3873. pieces.init_data_size);
  3874. memcpy(il->ucode_init_data.v_addr, pieces.init_data,
  3875. pieces.init_data_size);
  3876. }
  3877. /* Bootstrap instructions */
  3878. D_INFO("Copying (but not loading) boot instr len %Zd\n",
  3879. pieces.boot_size);
  3880. memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  3881. /*
  3882. * figure out the offset of chain noise reset and gain commands
  3883. * base on the size of standard phy calibration commands table size
  3884. */
  3885. il->_4965.phy_calib_chain_noise_reset_cmd =
  3886. standard_phy_calibration_size;
  3887. il->_4965.phy_calib_chain_noise_gain_cmd =
  3888. standard_phy_calibration_size + 1;
  3889. /**************************************************
  3890. * This is still part of probe() in a sense...
  3891. *
  3892. * 9. Setup and register with mac80211 and debugfs
  3893. **************************************************/
  3894. err = il4965_mac_setup_register(il, max_probe_length);
  3895. if (err)
  3896. goto out_unbind;
  3897. err = il_dbgfs_register(il, DRV_NAME);
  3898. if (err)
  3899. IL_ERR("failed to create debugfs files. Ignoring error: %d\n",
  3900. err);
  3901. err = sysfs_create_group(&il->pci_dev->dev.kobj, &il_attribute_group);
  3902. if (err) {
  3903. IL_ERR("failed to create sysfs device attributes\n");
  3904. goto out_unbind;
  3905. }
  3906. /* We have our copies now, allow OS release its copies */
  3907. release_firmware(ucode_raw);
  3908. complete(&il->_4965.firmware_loading_complete);
  3909. return;
  3910. try_again:
  3911. /* try next, if any */
  3912. if (il4965_request_firmware(il, false))
  3913. goto out_unbind;
  3914. release_firmware(ucode_raw);
  3915. return;
  3916. err_pci_alloc:
  3917. IL_ERR("failed to allocate pci memory\n");
  3918. il4965_dealloc_ucode_pci(il);
  3919. out_unbind:
  3920. complete(&il->_4965.firmware_loading_complete);
  3921. device_release_driver(&il->pci_dev->dev);
  3922. release_firmware(ucode_raw);
  3923. }
  3924. static const char *const desc_lookup_text[] = {
  3925. "OK",
  3926. "FAIL",
  3927. "BAD_PARAM",
  3928. "BAD_CHECKSUM",
  3929. "NMI_INTERRUPT_WDG",
  3930. "SYSASSERT",
  3931. "FATAL_ERROR",
  3932. "BAD_COMMAND",
  3933. "HW_ERROR_TUNE_LOCK",
  3934. "HW_ERROR_TEMPERATURE",
  3935. "ILLEGAL_CHAN_FREQ",
  3936. "VCC_NOT_STBL",
  3937. "FH49_ERROR",
  3938. "NMI_INTERRUPT_HOST",
  3939. "NMI_INTERRUPT_ACTION_PT",
  3940. "NMI_INTERRUPT_UNKNOWN",
  3941. "UCODE_VERSION_MISMATCH",
  3942. "HW_ERROR_ABS_LOCK",
  3943. "HW_ERROR_CAL_LOCK_FAIL",
  3944. "NMI_INTERRUPT_INST_ACTION_PT",
  3945. "NMI_INTERRUPT_DATA_ACTION_PT",
  3946. "NMI_TRM_HW_ER",
  3947. "NMI_INTERRUPT_TRM",
  3948. "NMI_INTERRUPT_BREAK_POINT",
  3949. "DEBUG_0",
  3950. "DEBUG_1",
  3951. "DEBUG_2",
  3952. "DEBUG_3",
  3953. };
  3954. static struct {
  3955. char *name;
  3956. u8 num;
  3957. } advanced_lookup[] = {
  3958. {
  3959. "NMI_INTERRUPT_WDG", 0x34}, {
  3960. "SYSASSERT", 0x35}, {
  3961. "UCODE_VERSION_MISMATCH", 0x37}, {
  3962. "BAD_COMMAND", 0x38}, {
  3963. "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C}, {
  3964. "FATAL_ERROR", 0x3D}, {
  3965. "NMI_TRM_HW_ERR", 0x46}, {
  3966. "NMI_INTERRUPT_TRM", 0x4C}, {
  3967. "NMI_INTERRUPT_BREAK_POINT", 0x54}, {
  3968. "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C}, {
  3969. "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64}, {
  3970. "NMI_INTERRUPT_HOST", 0x66}, {
  3971. "NMI_INTERRUPT_ACTION_PT", 0x7C}, {
  3972. "NMI_INTERRUPT_UNKNOWN", 0x84}, {
  3973. "NMI_INTERRUPT_INST_ACTION_PT", 0x86}, {
  3974. "ADVANCED_SYSASSERT", 0},};
  3975. static const char *
  3976. il4965_desc_lookup(u32 num)
  3977. {
  3978. int i;
  3979. int max = ARRAY_SIZE(desc_lookup_text);
  3980. if (num < max)
  3981. return desc_lookup_text[num];
  3982. max = ARRAY_SIZE(advanced_lookup) - 1;
  3983. for (i = 0; i < max; i++) {
  3984. if (advanced_lookup[i].num == num)
  3985. break;
  3986. }
  3987. return advanced_lookup[i].name;
  3988. }
  3989. #define ERROR_START_OFFSET (1 * sizeof(u32))
  3990. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  3991. void
  3992. il4965_dump_nic_error_log(struct il_priv *il)
  3993. {
  3994. u32 data2, line;
  3995. u32 desc, time, count, base, data1;
  3996. u32 blink1, blink2, ilink1, ilink2;
  3997. u32 pc, hcmd;
  3998. if (il->ucode_type == UCODE_INIT)
  3999. base = le32_to_cpu(il->card_alive_init.error_event_table_ptr);
  4000. else
  4001. base = le32_to_cpu(il->card_alive.error_event_table_ptr);
  4002. if (!il->ops->lib->is_valid_rtc_data_addr(base)) {
  4003. IL_ERR("Not valid error log pointer 0x%08X for %s uCode\n",
  4004. base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT");
  4005. return;
  4006. }
  4007. count = il_read_targ_mem(il, base);
  4008. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  4009. IL_ERR("Start IWL Error Log Dump:\n");
  4010. IL_ERR("Status: 0x%08lX, count: %d\n", il->status, count);
  4011. }
  4012. desc = il_read_targ_mem(il, base + 1 * sizeof(u32));
  4013. il->isr_stats.err_code = desc;
  4014. pc = il_read_targ_mem(il, base + 2 * sizeof(u32));
  4015. blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32));
  4016. blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32));
  4017. ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32));
  4018. ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32));
  4019. data1 = il_read_targ_mem(il, base + 7 * sizeof(u32));
  4020. data2 = il_read_targ_mem(il, base + 8 * sizeof(u32));
  4021. line = il_read_targ_mem(il, base + 9 * sizeof(u32));
  4022. time = il_read_targ_mem(il, base + 11 * sizeof(u32));
  4023. hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32));
  4024. IL_ERR("Desc Time "
  4025. "data1 data2 line\n");
  4026. IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  4027. il4965_desc_lookup(desc), desc, time, data1, data2, line);
  4028. IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n");
  4029. IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n", pc, blink1,
  4030. blink2, ilink1, ilink2, hcmd);
  4031. }
  4032. static void
  4033. il4965_rf_kill_ct_config(struct il_priv *il)
  4034. {
  4035. struct il_ct_kill_config cmd;
  4036. unsigned long flags;
  4037. int ret = 0;
  4038. spin_lock_irqsave(&il->lock, flags);
  4039. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  4040. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  4041. spin_unlock_irqrestore(&il->lock, flags);
  4042. cmd.critical_temperature_R =
  4043. cpu_to_le32(il->hw_params.ct_kill_threshold);
  4044. ret = il_send_cmd_pdu(il, C_CT_KILL_CONFIG, sizeof(cmd), &cmd);
  4045. if (ret)
  4046. IL_ERR("C_CT_KILL_CONFIG failed\n");
  4047. else
  4048. D_INFO("C_CT_KILL_CONFIG " "succeeded, "
  4049. "critical temperature is %d\n",
  4050. il->hw_params.ct_kill_threshold);
  4051. }
  4052. static const s8 default_queue_to_tx_fifo[] = {
  4053. IL_TX_FIFO_VO,
  4054. IL_TX_FIFO_VI,
  4055. IL_TX_FIFO_BE,
  4056. IL_TX_FIFO_BK,
  4057. IL49_CMD_FIFO_NUM,
  4058. IL_TX_FIFO_UNUSED,
  4059. IL_TX_FIFO_UNUSED,
  4060. };
  4061. #define IL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
  4062. static int
  4063. il4965_alive_notify(struct il_priv *il)
  4064. {
  4065. u32 a;
  4066. unsigned long flags;
  4067. int i, chan;
  4068. u32 reg_val;
  4069. spin_lock_irqsave(&il->lock, flags);
  4070. /* Clear 4965's internal Tx Scheduler data base */
  4071. il->scd_base_addr = il_rd_prph(il, IL49_SCD_SRAM_BASE_ADDR);
  4072. a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET;
  4073. for (; a < il->scd_base_addr + IL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  4074. il_write_targ_mem(il, a, 0);
  4075. for (; a < il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  4076. il_write_targ_mem(il, a, 0);
  4077. for (;
  4078. a <
  4079. il->scd_base_addr +
  4080. IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num);
  4081. a += 4)
  4082. il_write_targ_mem(il, a, 0);
  4083. /* Tel 4965 where to find Tx byte count tables */
  4084. il_wr_prph(il, IL49_SCD_DRAM_BASE_ADDR, il->scd_bc_tbls.dma >> 10);
  4085. /* Enable DMA channel */
  4086. for (chan = 0; chan < FH49_TCSR_CHNL_NUM; chan++)
  4087. il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(chan),
  4088. FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  4089. FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  4090. /* Update FH chicken bits */
  4091. reg_val = il_rd(il, FH49_TX_CHICKEN_BITS_REG);
  4092. il_wr(il, FH49_TX_CHICKEN_BITS_REG,
  4093. reg_val | FH49_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  4094. /* Disable chain mode for all queues */
  4095. il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0);
  4096. /* Initialize each Tx queue (including the command queue) */
  4097. for (i = 0; i < il->hw_params.max_txq_num; i++) {
  4098. /* TFD circular buffer read/write idxes */
  4099. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0);
  4100. il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8));
  4101. /* Max Tx Window size for Scheduler-ACK mode */
  4102. il_write_targ_mem(il,
  4103. il->scd_base_addr +
  4104. IL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  4105. (SCD_WIN_SIZE <<
  4106. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  4107. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  4108. /* Frame limit */
  4109. il_write_targ_mem(il,
  4110. il->scd_base_addr +
  4111. IL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  4112. sizeof(u32),
  4113. (SCD_FRAME_LIMIT <<
  4114. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  4115. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  4116. }
  4117. il_wr_prph(il, IL49_SCD_INTERRUPT_MASK,
  4118. (1 << il->hw_params.max_txq_num) - 1);
  4119. /* Activate all Tx DMA/FIFO channels */
  4120. il4965_txq_set_sched(il, IL_MASK(0, 6));
  4121. il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0);
  4122. /* make sure all queue are not stopped */
  4123. memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped));
  4124. for (i = 0; i < 4; i++)
  4125. atomic_set(&il->queue_stop_count[i], 0);
  4126. /* reset to 0 to enable all the queue first */
  4127. il->txq_ctx_active_msk = 0;
  4128. /* Map each Tx/cmd queue to its corresponding fifo */
  4129. BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
  4130. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  4131. int ac = default_queue_to_tx_fifo[i];
  4132. il_txq_ctx_activate(il, i);
  4133. if (ac == IL_TX_FIFO_UNUSED)
  4134. continue;
  4135. il4965_tx_queue_set_status(il, &il->txq[i], ac, 0);
  4136. }
  4137. spin_unlock_irqrestore(&il->lock, flags);
  4138. return 0;
  4139. }
  4140. /**
  4141. * il4965_alive_start - called after N_ALIVE notification received
  4142. * from protocol/runtime uCode (initialization uCode's
  4143. * Alive gets handled by il_init_alive_start()).
  4144. */
  4145. static void
  4146. il4965_alive_start(struct il_priv *il)
  4147. {
  4148. int ret = 0;
  4149. D_INFO("Runtime Alive received.\n");
  4150. if (il->card_alive.is_valid != UCODE_VALID_OK) {
  4151. /* We had an error bringing up the hardware, so take it
  4152. * all the way back down so we can try again */
  4153. D_INFO("Alive failed.\n");
  4154. goto restart;
  4155. }
  4156. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  4157. * This is a paranoid check, because we would not have gotten the
  4158. * "runtime" alive if code weren't properly loaded. */
  4159. if (il4965_verify_ucode(il)) {
  4160. /* Runtime instruction load was bad;
  4161. * take it all the way back down so we can try again */
  4162. D_INFO("Bad runtime uCode load.\n");
  4163. goto restart;
  4164. }
  4165. ret = il4965_alive_notify(il);
  4166. if (ret) {
  4167. IL_WARN("Could not complete ALIVE transition [ntf]: %d\n", ret);
  4168. goto restart;
  4169. }
  4170. /* After the ALIVE response, we can send host commands to the uCode */
  4171. set_bit(S_ALIVE, &il->status);
  4172. /* Enable watchdog to monitor the driver tx queues */
  4173. il_setup_watchdog(il);
  4174. if (il_is_rfkill(il))
  4175. return;
  4176. ieee80211_wake_queues(il->hw);
  4177. il->active_rate = RATES_MASK;
  4178. if (il_is_associated(il)) {
  4179. struct il_rxon_cmd *active_rxon =
  4180. (struct il_rxon_cmd *)&il->active;
  4181. /* apply any changes in staging */
  4182. il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  4183. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4184. } else {
  4185. /* Initialize our rx_config data */
  4186. il_connection_init_rx_config(il);
  4187. if (il->ops->hcmd->set_rxon_chain)
  4188. il->ops->hcmd->set_rxon_chain(il);
  4189. }
  4190. /* Configure bluetooth coexistence if enabled */
  4191. il_send_bt_config(il);
  4192. il4965_reset_run_time_calib(il);
  4193. set_bit(S_READY, &il->status);
  4194. /* Configure the adapter for unassociated operation */
  4195. il_commit_rxon(il);
  4196. /* At this point, the NIC is initialized and operational */
  4197. il4965_rf_kill_ct_config(il);
  4198. D_INFO("ALIVE processing complete.\n");
  4199. wake_up(&il->wait_command_queue);
  4200. il_power_update_mode(il, true);
  4201. D_INFO("Updated power mode\n");
  4202. return;
  4203. restart:
  4204. queue_work(il->workqueue, &il->restart);
  4205. }
  4206. static void il4965_cancel_deferred_work(struct il_priv *il);
  4207. static void
  4208. __il4965_down(struct il_priv *il)
  4209. {
  4210. unsigned long flags;
  4211. int exit_pending;
  4212. D_INFO(DRV_NAME " is going down\n");
  4213. il_scan_cancel_timeout(il, 200);
  4214. exit_pending = test_and_set_bit(S_EXIT_PENDING, &il->status);
  4215. /* Stop TX queues watchdog. We need to have S_EXIT_PENDING bit set
  4216. * to prevent rearm timer */
  4217. del_timer_sync(&il->watchdog);
  4218. il_clear_ucode_stations(il);
  4219. /* FIXME: race conditions ? */
  4220. spin_lock_irq(&il->sta_lock);
  4221. /*
  4222. * Remove all key information that is not stored as part
  4223. * of station information since mac80211 may not have had
  4224. * a chance to remove all the keys. When device is
  4225. * reconfigured by mac80211 after an error all keys will
  4226. * be reconfigured.
  4227. */
  4228. memset(il->_4965.wep_keys, 0, sizeof(il->_4965.wep_keys));
  4229. il->_4965.key_mapping_keys = 0;
  4230. spin_unlock_irq(&il->sta_lock);
  4231. il_dealloc_bcast_stations(il);
  4232. il_clear_driver_stations(il);
  4233. /* Unblock any waiting calls */
  4234. wake_up_all(&il->wait_command_queue);
  4235. /* Wipe out the EXIT_PENDING status bit if we are not actually
  4236. * exiting the module */
  4237. if (!exit_pending)
  4238. clear_bit(S_EXIT_PENDING, &il->status);
  4239. /* stop and reset the on-board processor */
  4240. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  4241. /* tell the device to stop sending interrupts */
  4242. spin_lock_irqsave(&il->lock, flags);
  4243. il_disable_interrupts(il);
  4244. spin_unlock_irqrestore(&il->lock, flags);
  4245. il4965_synchronize_irq(il);
  4246. if (il->mac80211_registered)
  4247. ieee80211_stop_queues(il->hw);
  4248. /* If we have not previously called il_init() then
  4249. * clear all bits but the RF Kill bit and return */
  4250. if (!il_is_init(il)) {
  4251. il->status =
  4252. test_bit(S_RF_KILL_HW,
  4253. &il->
  4254. status) << S_RF_KILL_HW |
  4255. test_bit(S_GEO_CONFIGURED,
  4256. &il->
  4257. status) << S_GEO_CONFIGURED |
  4258. test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING;
  4259. goto exit;
  4260. }
  4261. /* ...otherwise clear out all the status bits but the RF Kill
  4262. * bit and continue taking the NIC down. */
  4263. il->status &=
  4264. test_bit(S_RF_KILL_HW,
  4265. &il->status) << S_RF_KILL_HW | test_bit(S_GEO_CONFIGURED,
  4266. &il->
  4267. status) <<
  4268. S_GEO_CONFIGURED | test_bit(S_FW_ERROR,
  4269. &il->
  4270. status) << S_FW_ERROR |
  4271. test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING;
  4272. il4965_txq_ctx_stop(il);
  4273. il4965_rxq_stop(il);
  4274. /* Power-down device's busmaster DMA clocks */
  4275. il_wr_prph(il, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  4276. udelay(5);
  4277. /* Make sure (redundant) we've released our request to stay awake */
  4278. il_clear_bit(il, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  4279. /* Stop the device, and put it in low power state */
  4280. il_apm_stop(il);
  4281. exit:
  4282. memset(&il->card_alive, 0, sizeof(struct il_alive_resp));
  4283. dev_kfree_skb(il->beacon_skb);
  4284. il->beacon_skb = NULL;
  4285. /* clear out any free frames */
  4286. il4965_clear_free_frames(il);
  4287. }
  4288. static void
  4289. il4965_down(struct il_priv *il)
  4290. {
  4291. mutex_lock(&il->mutex);
  4292. __il4965_down(il);
  4293. mutex_unlock(&il->mutex);
  4294. il4965_cancel_deferred_work(il);
  4295. }
  4296. #define HW_READY_TIMEOUT (50)
  4297. static int
  4298. il4965_set_hw_ready(struct il_priv *il)
  4299. {
  4300. int ret = 0;
  4301. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  4302. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  4303. /* See if we got it */
  4304. ret =
  4305. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4306. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  4307. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, HW_READY_TIMEOUT);
  4308. if (ret != -ETIMEDOUT)
  4309. il->hw_ready = true;
  4310. else
  4311. il->hw_ready = false;
  4312. D_INFO("hardware %s\n", (il->hw_ready == 1) ? "ready" : "not ready");
  4313. return ret;
  4314. }
  4315. static int
  4316. il4965_prepare_card_hw(struct il_priv *il)
  4317. {
  4318. int ret = 0;
  4319. D_INFO("il4965_prepare_card_hw enter\n");
  4320. ret = il4965_set_hw_ready(il);
  4321. if (il->hw_ready)
  4322. return ret;
  4323. /* If HW is not ready, prepare the conditions to check again */
  4324. il_set_bit(il, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_PREPARE);
  4325. ret =
  4326. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4327. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  4328. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  4329. /* HW should be ready by now, check again. */
  4330. if (ret != -ETIMEDOUT)
  4331. il4965_set_hw_ready(il);
  4332. return ret;
  4333. }
  4334. #define MAX_HW_RESTARTS 5
  4335. static int
  4336. __il4965_up(struct il_priv *il)
  4337. {
  4338. int i;
  4339. int ret;
  4340. if (test_bit(S_EXIT_PENDING, &il->status)) {
  4341. IL_WARN("Exit pending; will not bring the NIC up\n");
  4342. return -EIO;
  4343. }
  4344. if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) {
  4345. IL_ERR("ucode not available for device bringup\n");
  4346. return -EIO;
  4347. }
  4348. ret = il4965_alloc_bcast_station(il);
  4349. if (ret) {
  4350. il_dealloc_bcast_stations(il);
  4351. return ret;
  4352. }
  4353. il4965_prepare_card_hw(il);
  4354. if (!il->hw_ready) {
  4355. IL_WARN("Exit HW not ready\n");
  4356. return -EIO;
  4357. }
  4358. /* If platform's RF_KILL switch is NOT set to KILL */
  4359. if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  4360. clear_bit(S_RF_KILL_HW, &il->status);
  4361. else
  4362. set_bit(S_RF_KILL_HW, &il->status);
  4363. if (il_is_rfkill(il)) {
  4364. wiphy_rfkill_set_hw_state(il->hw->wiphy, true);
  4365. il_enable_interrupts(il);
  4366. IL_WARN("Radio disabled by HW RF Kill switch\n");
  4367. return 0;
  4368. }
  4369. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4370. /* must be initialised before il_hw_nic_init */
  4371. il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM;
  4372. ret = il4965_hw_nic_init(il);
  4373. if (ret) {
  4374. IL_ERR("Unable to init nic\n");
  4375. return ret;
  4376. }
  4377. /* make sure rfkill handshake bits are cleared */
  4378. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4379. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  4380. /* clear (again), then enable host interrupts */
  4381. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4382. il_enable_interrupts(il);
  4383. /* really make sure rfkill handshake bits are cleared */
  4384. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4385. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4386. /* Copy original ucode data image from disk into backup cache.
  4387. * This will be used to initialize the on-board processor's
  4388. * data SRAM for a clean start when the runtime program first loads. */
  4389. memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr,
  4390. il->ucode_data.len);
  4391. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  4392. /* load bootstrap state machine,
  4393. * load bootstrap program into processor's memory,
  4394. * prepare to load the "initialize" uCode */
  4395. ret = il->ops->lib->load_ucode(il);
  4396. if (ret) {
  4397. IL_ERR("Unable to set up bootstrap uCode: %d\n", ret);
  4398. continue;
  4399. }
  4400. /* start card; "initialize" will load runtime ucode */
  4401. il4965_nic_start(il);
  4402. D_INFO(DRV_NAME " is coming up\n");
  4403. return 0;
  4404. }
  4405. set_bit(S_EXIT_PENDING, &il->status);
  4406. __il4965_down(il);
  4407. clear_bit(S_EXIT_PENDING, &il->status);
  4408. /* tried to restart and config the device for as long as our
  4409. * patience could withstand */
  4410. IL_ERR("Unable to initialize device after %d attempts.\n", i);
  4411. return -EIO;
  4412. }
  4413. /*****************************************************************************
  4414. *
  4415. * Workqueue callbacks
  4416. *
  4417. *****************************************************************************/
  4418. static void
  4419. il4965_bg_init_alive_start(struct work_struct *data)
  4420. {
  4421. struct il_priv *il =
  4422. container_of(data, struct il_priv, init_alive_start.work);
  4423. mutex_lock(&il->mutex);
  4424. if (test_bit(S_EXIT_PENDING, &il->status))
  4425. goto out;
  4426. il->ops->lib->init_alive_start(il);
  4427. out:
  4428. mutex_unlock(&il->mutex);
  4429. }
  4430. static void
  4431. il4965_bg_alive_start(struct work_struct *data)
  4432. {
  4433. struct il_priv *il =
  4434. container_of(data, struct il_priv, alive_start.work);
  4435. mutex_lock(&il->mutex);
  4436. if (test_bit(S_EXIT_PENDING, &il->status))
  4437. goto out;
  4438. il4965_alive_start(il);
  4439. out:
  4440. mutex_unlock(&il->mutex);
  4441. }
  4442. static void
  4443. il4965_bg_run_time_calib_work(struct work_struct *work)
  4444. {
  4445. struct il_priv *il = container_of(work, struct il_priv,
  4446. run_time_calib_work);
  4447. mutex_lock(&il->mutex);
  4448. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4449. test_bit(S_SCANNING, &il->status)) {
  4450. mutex_unlock(&il->mutex);
  4451. return;
  4452. }
  4453. if (il->start_calib) {
  4454. il4965_chain_noise_calibration(il, (void *)&il->_4965.stats);
  4455. il4965_sensitivity_calibration(il, (void *)&il->_4965.stats);
  4456. }
  4457. mutex_unlock(&il->mutex);
  4458. }
  4459. static void
  4460. il4965_bg_restart(struct work_struct *data)
  4461. {
  4462. struct il_priv *il = container_of(data, struct il_priv, restart);
  4463. if (test_bit(S_EXIT_PENDING, &il->status))
  4464. return;
  4465. if (test_and_clear_bit(S_FW_ERROR, &il->status)) {
  4466. mutex_lock(&il->mutex);
  4467. /* FIXME: do we dereference vif without mutex locked ? */
  4468. il->vif = NULL;
  4469. il->is_open = 0;
  4470. __il4965_down(il);
  4471. mutex_unlock(&il->mutex);
  4472. il4965_cancel_deferred_work(il);
  4473. ieee80211_restart_hw(il->hw);
  4474. } else {
  4475. il4965_down(il);
  4476. mutex_lock(&il->mutex);
  4477. if (test_bit(S_EXIT_PENDING, &il->status)) {
  4478. mutex_unlock(&il->mutex);
  4479. return;
  4480. }
  4481. __il4965_up(il);
  4482. mutex_unlock(&il->mutex);
  4483. }
  4484. }
  4485. static void
  4486. il4965_bg_rx_replenish(struct work_struct *data)
  4487. {
  4488. struct il_priv *il = container_of(data, struct il_priv, rx_replenish);
  4489. if (test_bit(S_EXIT_PENDING, &il->status))
  4490. return;
  4491. mutex_lock(&il->mutex);
  4492. il4965_rx_replenish(il);
  4493. mutex_unlock(&il->mutex);
  4494. }
  4495. /*****************************************************************************
  4496. *
  4497. * mac80211 entry point functions
  4498. *
  4499. *****************************************************************************/
  4500. #define UCODE_READY_TIMEOUT (4 * HZ)
  4501. /*
  4502. * Not a mac80211 entry point function, but it fits in with all the
  4503. * other mac80211 functions grouped here.
  4504. */
  4505. static int
  4506. il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length)
  4507. {
  4508. int ret;
  4509. struct ieee80211_hw *hw = il->hw;
  4510. hw->rate_control_algorithm = "iwl-4965-rs";
  4511. /* Tell mac80211 our characteristics */
  4512. hw->flags =
  4513. IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_AMPDU_AGGREGATION |
  4514. IEEE80211_HW_NEED_DTIM_PERIOD | IEEE80211_HW_SPECTRUM_MGMT |
  4515. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  4516. if (il->cfg->sku & IL_SKU_N)
  4517. hw->flags |=
  4518. IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  4519. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  4520. hw->sta_data_size = sizeof(struct il_station_priv);
  4521. hw->vif_data_size = sizeof(struct il_vif_priv);
  4522. hw->wiphy->interface_modes =
  4523. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
  4524. hw->wiphy->flags |=
  4525. WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS;
  4526. /*
  4527. * For now, disable PS by default because it affects
  4528. * RX performance significantly.
  4529. */
  4530. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4531. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  4532. /* we create the 802.11 header and a zero-length SSID element */
  4533. hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2;
  4534. /* Default value; 4 EDCA QOS priorities */
  4535. hw->queues = 4;
  4536. hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL;
  4537. if (il->bands[IEEE80211_BAND_2GHZ].n_channels)
  4538. il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4539. &il->bands[IEEE80211_BAND_2GHZ];
  4540. if (il->bands[IEEE80211_BAND_5GHZ].n_channels)
  4541. il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4542. &il->bands[IEEE80211_BAND_5GHZ];
  4543. il_leds_init(il);
  4544. ret = ieee80211_register_hw(il->hw);
  4545. if (ret) {
  4546. IL_ERR("Failed to register hw (error %d)\n", ret);
  4547. return ret;
  4548. }
  4549. il->mac80211_registered = 1;
  4550. return 0;
  4551. }
  4552. int
  4553. il4965_mac_start(struct ieee80211_hw *hw)
  4554. {
  4555. struct il_priv *il = hw->priv;
  4556. int ret;
  4557. D_MAC80211("enter\n");
  4558. /* we should be verifying the device is ready to be opened */
  4559. mutex_lock(&il->mutex);
  4560. ret = __il4965_up(il);
  4561. mutex_unlock(&il->mutex);
  4562. if (ret)
  4563. return ret;
  4564. if (il_is_rfkill(il))
  4565. goto out;
  4566. D_INFO("Start UP work done.\n");
  4567. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  4568. * mac80211 will not be run successfully. */
  4569. ret = wait_event_timeout(il->wait_command_queue,
  4570. test_bit(S_READY, &il->status),
  4571. UCODE_READY_TIMEOUT);
  4572. if (!ret) {
  4573. if (!test_bit(S_READY, &il->status)) {
  4574. IL_ERR("START_ALIVE timeout after %dms.\n",
  4575. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  4576. return -ETIMEDOUT;
  4577. }
  4578. }
  4579. il4965_led_enable(il);
  4580. out:
  4581. il->is_open = 1;
  4582. D_MAC80211("leave\n");
  4583. return 0;
  4584. }
  4585. void
  4586. il4965_mac_stop(struct ieee80211_hw *hw)
  4587. {
  4588. struct il_priv *il = hw->priv;
  4589. D_MAC80211("enter\n");
  4590. if (!il->is_open)
  4591. return;
  4592. il->is_open = 0;
  4593. il4965_down(il);
  4594. flush_workqueue(il->workqueue);
  4595. /* User space software may expect getting rfkill changes
  4596. * even if interface is down */
  4597. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4598. il_enable_rfkill_int(il);
  4599. D_MAC80211("leave\n");
  4600. }
  4601. void
  4602. il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  4603. {
  4604. struct il_priv *il = hw->priv;
  4605. D_MACDUMP("enter\n");
  4606. D_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  4607. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  4608. if (il4965_tx_skb(il, skb))
  4609. dev_kfree_skb_any(skb);
  4610. D_MACDUMP("leave\n");
  4611. }
  4612. void
  4613. il4965_mac_update_tkip_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4614. struct ieee80211_key_conf *keyconf,
  4615. struct ieee80211_sta *sta, u32 iv32, u16 * phase1key)
  4616. {
  4617. struct il_priv *il = hw->priv;
  4618. D_MAC80211("enter\n");
  4619. il4965_update_tkip_key(il, keyconf, sta, iv32, phase1key);
  4620. D_MAC80211("leave\n");
  4621. }
  4622. int
  4623. il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  4624. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  4625. struct ieee80211_key_conf *key)
  4626. {
  4627. struct il_priv *il = hw->priv;
  4628. int ret;
  4629. u8 sta_id;
  4630. bool is_default_wep_key = false;
  4631. D_MAC80211("enter\n");
  4632. if (il->cfg->mod_params->sw_crypto) {
  4633. D_MAC80211("leave - hwcrypto disabled\n");
  4634. return -EOPNOTSUPP;
  4635. }
  4636. sta_id = il_sta_id_or_broadcast(il, sta);
  4637. if (sta_id == IL_INVALID_STATION)
  4638. return -EINVAL;
  4639. mutex_lock(&il->mutex);
  4640. il_scan_cancel_timeout(il, 100);
  4641. /*
  4642. * If we are getting WEP group key and we didn't receive any key mapping
  4643. * so far, we are in legacy wep mode (group key only), otherwise we are
  4644. * in 1X mode.
  4645. * In legacy wep mode, we use another host command to the uCode.
  4646. */
  4647. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  4648. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  4649. if (cmd == SET_KEY)
  4650. is_default_wep_key = !il->_4965.key_mapping_keys;
  4651. else
  4652. is_default_wep_key =
  4653. (key->hw_key_idx == HW_KEY_DEFAULT);
  4654. }
  4655. switch (cmd) {
  4656. case SET_KEY:
  4657. if (is_default_wep_key)
  4658. ret = il4965_set_default_wep_key(il, key);
  4659. else
  4660. ret = il4965_set_dynamic_key(il, key, sta_id);
  4661. D_MAC80211("enable hwcrypto key\n");
  4662. break;
  4663. case DISABLE_KEY:
  4664. if (is_default_wep_key)
  4665. ret = il4965_remove_default_wep_key(il, key);
  4666. else
  4667. ret = il4965_remove_dynamic_key(il, key, sta_id);
  4668. D_MAC80211("disable hwcrypto key\n");
  4669. break;
  4670. default:
  4671. ret = -EINVAL;
  4672. }
  4673. mutex_unlock(&il->mutex);
  4674. D_MAC80211("leave\n");
  4675. return ret;
  4676. }
  4677. int
  4678. il4965_mac_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4679. enum ieee80211_ampdu_mlme_action action,
  4680. struct ieee80211_sta *sta, u16 tid, u16 * ssn,
  4681. u8 buf_size)
  4682. {
  4683. struct il_priv *il = hw->priv;
  4684. int ret = -EINVAL;
  4685. D_HT("A-MPDU action on addr %pM tid %d\n", sta->addr, tid);
  4686. if (!(il->cfg->sku & IL_SKU_N))
  4687. return -EACCES;
  4688. mutex_lock(&il->mutex);
  4689. switch (action) {
  4690. case IEEE80211_AMPDU_RX_START:
  4691. D_HT("start Rx\n");
  4692. ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn);
  4693. break;
  4694. case IEEE80211_AMPDU_RX_STOP:
  4695. D_HT("stop Rx\n");
  4696. ret = il4965_sta_rx_agg_stop(il, sta, tid);
  4697. if (test_bit(S_EXIT_PENDING, &il->status))
  4698. ret = 0;
  4699. break;
  4700. case IEEE80211_AMPDU_TX_START:
  4701. D_HT("start Tx\n");
  4702. ret = il4965_tx_agg_start(il, vif, sta, tid, ssn);
  4703. break;
  4704. case IEEE80211_AMPDU_TX_STOP:
  4705. D_HT("stop Tx\n");
  4706. ret = il4965_tx_agg_stop(il, vif, sta, tid);
  4707. if (test_bit(S_EXIT_PENDING, &il->status))
  4708. ret = 0;
  4709. break;
  4710. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4711. ret = 0;
  4712. break;
  4713. }
  4714. mutex_unlock(&il->mutex);
  4715. return ret;
  4716. }
  4717. int
  4718. il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4719. struct ieee80211_sta *sta)
  4720. {
  4721. struct il_priv *il = hw->priv;
  4722. struct il_station_priv *sta_priv = (void *)sta->drv_priv;
  4723. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  4724. int ret;
  4725. u8 sta_id;
  4726. D_INFO("received request to add station %pM\n", sta->addr);
  4727. mutex_lock(&il->mutex);
  4728. D_INFO("proceeding to add station %pM\n", sta->addr);
  4729. sta_priv->common.sta_id = IL_INVALID_STATION;
  4730. atomic_set(&sta_priv->pending_frames, 0);
  4731. ret =
  4732. il_add_station_common(il, sta->addr, is_ap, sta, &sta_id);
  4733. if (ret) {
  4734. IL_ERR("Unable to add station %pM (%d)\n", sta->addr, ret);
  4735. /* Should we return success if return code is EEXIST ? */
  4736. mutex_unlock(&il->mutex);
  4737. return ret;
  4738. }
  4739. sta_priv->common.sta_id = sta_id;
  4740. /* Initialize rate scaling */
  4741. D_INFO("Initializing rate scaling for station %pM\n", sta->addr);
  4742. il4965_rs_rate_init(il, sta, sta_id);
  4743. mutex_unlock(&il->mutex);
  4744. return 0;
  4745. }
  4746. void
  4747. il4965_mac_channel_switch(struct ieee80211_hw *hw,
  4748. struct ieee80211_channel_switch *ch_switch)
  4749. {
  4750. struct il_priv *il = hw->priv;
  4751. const struct il_channel_info *ch_info;
  4752. struct ieee80211_conf *conf = &hw->conf;
  4753. struct ieee80211_channel *channel = ch_switch->channel;
  4754. struct il_ht_config *ht_conf = &il->current_ht_config;
  4755. u16 ch;
  4756. D_MAC80211("enter\n");
  4757. mutex_lock(&il->mutex);
  4758. if (il_is_rfkill(il))
  4759. goto out;
  4760. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4761. test_bit(S_SCANNING, &il->status) ||
  4762. test_bit(S_CHANNEL_SWITCH_PENDING, &il->status))
  4763. goto out;
  4764. if (!il_is_associated(il))
  4765. goto out;
  4766. if (!il->ops->lib->set_channel_switch)
  4767. goto out;
  4768. ch = channel->hw_value;
  4769. if (le16_to_cpu(il->active.channel) == ch)
  4770. goto out;
  4771. ch_info = il_get_channel_info(il, channel->band, ch);
  4772. if (!il_is_channel_valid(ch_info)) {
  4773. D_MAC80211("invalid channel\n");
  4774. goto out;
  4775. }
  4776. spin_lock_irq(&il->lock);
  4777. il->current_ht_config.smps = conf->smps_mode;
  4778. /* Configure HT40 channels */
  4779. il->ht.enabled = conf_is_ht(conf);
  4780. if (il->ht.enabled) {
  4781. if (conf_is_ht40_minus(conf)) {
  4782. il->ht.extension_chan_offset =
  4783. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  4784. il->ht.is_40mhz = true;
  4785. } else if (conf_is_ht40_plus(conf)) {
  4786. il->ht.extension_chan_offset =
  4787. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  4788. il->ht.is_40mhz = true;
  4789. } else {
  4790. il->ht.extension_chan_offset =
  4791. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  4792. il->ht.is_40mhz = false;
  4793. }
  4794. } else
  4795. il->ht.is_40mhz = false;
  4796. if ((le16_to_cpu(il->staging.channel) != ch))
  4797. il->staging.flags = 0;
  4798. il_set_rxon_channel(il, channel);
  4799. il_set_rxon_ht(il, ht_conf);
  4800. il_set_flags_for_band(il, channel->band, il->vif);
  4801. spin_unlock_irq(&il->lock);
  4802. il_set_rate(il);
  4803. /*
  4804. * at this point, staging_rxon has the
  4805. * configuration for channel switch
  4806. */
  4807. set_bit(S_CHANNEL_SWITCH_PENDING, &il->status);
  4808. il->switch_channel = cpu_to_le16(ch);
  4809. if (il->ops->lib->set_channel_switch(il, ch_switch)) {
  4810. clear_bit(S_CHANNEL_SWITCH_PENDING, &il->status);
  4811. il->switch_channel = 0;
  4812. ieee80211_chswitch_done(il->vif, false);
  4813. }
  4814. out:
  4815. mutex_unlock(&il->mutex);
  4816. D_MAC80211("leave\n");
  4817. }
  4818. void
  4819. il4965_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  4820. unsigned int *total_flags, u64 multicast)
  4821. {
  4822. struct il_priv *il = hw->priv;
  4823. __le32 filter_or = 0, filter_nand = 0;
  4824. #define CHK(test, flag) do { \
  4825. if (*total_flags & (test)) \
  4826. filter_or |= (flag); \
  4827. else \
  4828. filter_nand |= (flag); \
  4829. } while (0)
  4830. D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", changed_flags,
  4831. *total_flags);
  4832. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  4833. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  4834. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  4835. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  4836. #undef CHK
  4837. mutex_lock(&il->mutex);
  4838. il->staging.filter_flags &= ~filter_nand;
  4839. il->staging.filter_flags |= filter_or;
  4840. /*
  4841. * Not committing directly because hardware can perform a scan,
  4842. * but we'll eventually commit the filter flags change anyway.
  4843. */
  4844. mutex_unlock(&il->mutex);
  4845. /*
  4846. * Receiving all multicast frames is always enabled by the
  4847. * default flags setup in il_connection_init_rx_config()
  4848. * since we currently do not support programming multicast
  4849. * filters into the device.
  4850. */
  4851. *total_flags &=
  4852. FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  4853. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  4854. }
  4855. /*****************************************************************************
  4856. *
  4857. * driver setup and teardown
  4858. *
  4859. *****************************************************************************/
  4860. static void
  4861. il4965_bg_txpower_work(struct work_struct *work)
  4862. {
  4863. struct il_priv *il = container_of(work, struct il_priv,
  4864. txpower_work);
  4865. mutex_lock(&il->mutex);
  4866. /* If a scan happened to start before we got here
  4867. * then just return; the stats notification will
  4868. * kick off another scheduled work to compensate for
  4869. * any temperature delta we missed here. */
  4870. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4871. test_bit(S_SCANNING, &il->status))
  4872. goto out;
  4873. /* Regardless of if we are associated, we must reconfigure the
  4874. * TX power since frames can be sent on non-radar channels while
  4875. * not associated */
  4876. il->ops->lib->send_tx_power(il);
  4877. /* Update last_temperature to keep is_calib_needed from running
  4878. * when it isn't needed... */
  4879. il->last_temperature = il->temperature;
  4880. out:
  4881. mutex_unlock(&il->mutex);
  4882. }
  4883. static void
  4884. il4965_setup_deferred_work(struct il_priv *il)
  4885. {
  4886. il->workqueue = create_singlethread_workqueue(DRV_NAME);
  4887. init_waitqueue_head(&il->wait_command_queue);
  4888. INIT_WORK(&il->restart, il4965_bg_restart);
  4889. INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish);
  4890. INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work);
  4891. INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start);
  4892. INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start);
  4893. il_setup_scan_deferred_work(il);
  4894. INIT_WORK(&il->txpower_work, il4965_bg_txpower_work);
  4895. init_timer(&il->stats_periodic);
  4896. il->stats_periodic.data = (unsigned long)il;
  4897. il->stats_periodic.function = il4965_bg_stats_periodic;
  4898. init_timer(&il->watchdog);
  4899. il->watchdog.data = (unsigned long)il;
  4900. il->watchdog.function = il_bg_watchdog;
  4901. tasklet_init(&il->irq_tasklet,
  4902. (void (*)(unsigned long))il4965_irq_tasklet,
  4903. (unsigned long)il);
  4904. }
  4905. static void
  4906. il4965_cancel_deferred_work(struct il_priv *il)
  4907. {
  4908. cancel_work_sync(&il->txpower_work);
  4909. cancel_delayed_work_sync(&il->init_alive_start);
  4910. cancel_delayed_work(&il->alive_start);
  4911. cancel_work_sync(&il->run_time_calib_work);
  4912. il_cancel_scan_deferred_work(il);
  4913. del_timer_sync(&il->stats_periodic);
  4914. }
  4915. static void
  4916. il4965_init_hw_rates(struct il_priv *il, struct ieee80211_rate *rates)
  4917. {
  4918. int i;
  4919. for (i = 0; i < RATE_COUNT_LEGACY; i++) {
  4920. rates[i].bitrate = il_rates[i].ieee * 5;
  4921. rates[i].hw_value = i; /* Rate scaling will work on idxes */
  4922. rates[i].hw_value_short = i;
  4923. rates[i].flags = 0;
  4924. if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) {
  4925. /*
  4926. * If CCK != 1M then set short preamble rate flag.
  4927. */
  4928. rates[i].flags |=
  4929. (il_rates[i].plcp ==
  4930. RATE_1M_PLCP) ? 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  4931. }
  4932. }
  4933. }
  4934. /*
  4935. * Acquire il->lock before calling this function !
  4936. */
  4937. void
  4938. il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx)
  4939. {
  4940. il_wr(il, HBUS_TARG_WRPTR, (idx & 0xff) | (txq_id << 8));
  4941. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx);
  4942. }
  4943. void
  4944. il4965_tx_queue_set_status(struct il_priv *il, struct il_tx_queue *txq,
  4945. int tx_fifo_id, int scd_retry)
  4946. {
  4947. int txq_id = txq->q.id;
  4948. /* Find out whether to activate Tx queue */
  4949. int active = test_bit(txq_id, &il->txq_ctx_active_msk) ? 1 : 0;
  4950. /* Set up and activate */
  4951. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  4952. (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  4953. (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  4954. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  4955. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  4956. IL49_SCD_QUEUE_STTS_REG_MSK);
  4957. txq->sched_retry = scd_retry;
  4958. D_INFO("%s %s Queue %d on AC %d\n", active ? "Activate" : "Deactivate",
  4959. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  4960. }
  4961. const struct ieee80211_ops il4965_mac_ops = {
  4962. .tx = il4965_mac_tx,
  4963. .start = il4965_mac_start,
  4964. .stop = il4965_mac_stop,
  4965. .add_interface = il_mac_add_interface,
  4966. .remove_interface = il_mac_remove_interface,
  4967. .change_interface = il_mac_change_interface,
  4968. .config = il_mac_config,
  4969. .configure_filter = il4965_configure_filter,
  4970. .set_key = il4965_mac_set_key,
  4971. .update_tkip_key = il4965_mac_update_tkip_key,
  4972. .conf_tx = il_mac_conf_tx,
  4973. .reset_tsf = il_mac_reset_tsf,
  4974. .bss_info_changed = il_mac_bss_info_changed,
  4975. .ampdu_action = il4965_mac_ampdu_action,
  4976. .hw_scan = il_mac_hw_scan,
  4977. .sta_add = il4965_mac_sta_add,
  4978. .sta_remove = il_mac_sta_remove,
  4979. .channel_switch = il4965_mac_channel_switch,
  4980. .tx_last_beacon = il_mac_tx_last_beacon,
  4981. };
  4982. static int
  4983. il4965_init_drv(struct il_priv *il)
  4984. {
  4985. int ret;
  4986. spin_lock_init(&il->sta_lock);
  4987. spin_lock_init(&il->hcmd_lock);
  4988. INIT_LIST_HEAD(&il->free_frames);
  4989. mutex_init(&il->mutex);
  4990. il->ieee_channels = NULL;
  4991. il->ieee_rates = NULL;
  4992. il->band = IEEE80211_BAND_2GHZ;
  4993. il->iw_mode = NL80211_IFTYPE_STATION;
  4994. il->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  4995. il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
  4996. /* initialize force reset */
  4997. il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD;
  4998. /* Choose which receivers/antennas to use */
  4999. if (il->ops->hcmd->set_rxon_chain)
  5000. il->ops->hcmd->set_rxon_chain(il);
  5001. il_init_scan_params(il);
  5002. ret = il_init_channel_map(il);
  5003. if (ret) {
  5004. IL_ERR("initializing regulatory failed: %d\n", ret);
  5005. goto err;
  5006. }
  5007. ret = il_init_geos(il);
  5008. if (ret) {
  5009. IL_ERR("initializing geos failed: %d\n", ret);
  5010. goto err_free_channel_map;
  5011. }
  5012. il4965_init_hw_rates(il, il->ieee_rates);
  5013. return 0;
  5014. err_free_channel_map:
  5015. il_free_channel_map(il);
  5016. err:
  5017. return ret;
  5018. }
  5019. static void
  5020. il4965_uninit_drv(struct il_priv *il)
  5021. {
  5022. il4965_calib_free_results(il);
  5023. il_free_geos(il);
  5024. il_free_channel_map(il);
  5025. kfree(il->scan_cmd);
  5026. }
  5027. static void
  5028. il4965_hw_detect(struct il_priv *il)
  5029. {
  5030. il->hw_rev = _il_rd(il, CSR_HW_REV);
  5031. il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG);
  5032. il->rev_id = il->pci_dev->revision;
  5033. D_INFO("HW Revision ID = 0x%X\n", il->rev_id);
  5034. }
  5035. static struct il_sensitivity_ranges il4965_sensitivity = {
  5036. .min_nrg_cck = 97,
  5037. .max_nrg_cck = 0, /* not used, set to 0 */
  5038. .auto_corr_min_ofdm = 85,
  5039. .auto_corr_min_ofdm_mrc = 170,
  5040. .auto_corr_min_ofdm_x1 = 105,
  5041. .auto_corr_min_ofdm_mrc_x1 = 220,
  5042. .auto_corr_max_ofdm = 120,
  5043. .auto_corr_max_ofdm_mrc = 210,
  5044. .auto_corr_max_ofdm_x1 = 140,
  5045. .auto_corr_max_ofdm_mrc_x1 = 270,
  5046. .auto_corr_min_cck = 125,
  5047. .auto_corr_max_cck = 200,
  5048. .auto_corr_min_cck_mrc = 200,
  5049. .auto_corr_max_cck_mrc = 400,
  5050. .nrg_th_cck = 100,
  5051. .nrg_th_ofdm = 100,
  5052. .barker_corr_th_min = 190,
  5053. .barker_corr_th_min_mrc = 390,
  5054. .nrg_th_cca = 62,
  5055. };
  5056. static void
  5057. il4965_set_hw_params(struct il_priv *il)
  5058. {
  5059. il->hw_params.bcast_id = IL4965_BROADCAST_ID;
  5060. il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  5061. il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  5062. if (il->cfg->mod_params->amsdu_size_8K)
  5063. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_8K);
  5064. else
  5065. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_4K);
  5066. il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL;
  5067. if (il->cfg->mod_params->disable_11n)
  5068. il->cfg->sku &= ~IL_SKU_N;
  5069. if (il->cfg->mod_params->num_of_queues >= IL_MIN_NUM_QUEUES &&
  5070. il->cfg->mod_params->num_of_queues <= IL49_NUM_QUEUES)
  5071. il->cfg->num_of_queues =
  5072. il->cfg->mod_params->num_of_queues;
  5073. il->hw_params.max_txq_num = il->cfg->num_of_queues;
  5074. il->hw_params.dma_chnl_num = FH49_TCSR_CHNL_NUM;
  5075. il->hw_params.scd_bc_tbls_size =
  5076. il->cfg->num_of_queues *
  5077. sizeof(struct il4965_scd_bc_tbl);
  5078. il->hw_params.tfd_size = sizeof(struct il_tfd);
  5079. il->hw_params.max_stations = IL4965_STATION_COUNT;
  5080. il->hw_params.max_data_size = IL49_RTC_DATA_SIZE;
  5081. il->hw_params.max_inst_size = IL49_RTC_INST_SIZE;
  5082. il->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  5083. il->hw_params.ht40_channel = BIT(IEEE80211_BAND_5GHZ);
  5084. il->hw_params.rx_wrt_ptr_reg = FH49_RSCSR_CHNL0_WPTR;
  5085. il->hw_params.tx_chains_num = il4965_num_of_ant(il->cfg->valid_tx_ant);
  5086. il->hw_params.rx_chains_num = il4965_num_of_ant(il->cfg->valid_rx_ant);
  5087. il->hw_params.valid_tx_ant = il->cfg->valid_tx_ant;
  5088. il->hw_params.valid_rx_ant = il->cfg->valid_rx_ant;
  5089. il->hw_params.ct_kill_threshold =
  5090. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY);
  5091. il->hw_params.sens = &il4965_sensitivity;
  5092. il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS;
  5093. }
  5094. static int
  5095. il4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5096. {
  5097. int err = 0;
  5098. struct il_priv *il;
  5099. struct ieee80211_hw *hw;
  5100. struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data);
  5101. unsigned long flags;
  5102. u16 pci_cmd;
  5103. /************************
  5104. * 1. Allocating HW data
  5105. ************************/
  5106. hw = ieee80211_alloc_hw(sizeof(struct il_priv), &il4965_mac_ops);
  5107. if (!hw) {
  5108. err = -ENOMEM;
  5109. goto out;
  5110. }
  5111. il = hw->priv;
  5112. il->hw = hw;
  5113. SET_IEEE80211_DEV(hw, &pdev->dev);
  5114. D_INFO("*** LOAD DRIVER ***\n");
  5115. il->cfg = cfg;
  5116. il->ops = &il4965_ops;
  5117. il->pci_dev = pdev;
  5118. il->inta_mask = CSR_INI_SET_MASK;
  5119. if (il_alloc_traffic_mem(il))
  5120. IL_ERR("Not enough memory to generate traffic log\n");
  5121. /**************************
  5122. * 2. Initializing PCI bus
  5123. **************************/
  5124. pci_disable_link_state(pdev,
  5125. PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  5126. PCIE_LINK_STATE_CLKPM);
  5127. if (pci_enable_device(pdev)) {
  5128. err = -ENODEV;
  5129. goto out_ieee80211_free_hw;
  5130. }
  5131. pci_set_master(pdev);
  5132. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  5133. if (!err)
  5134. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  5135. if (err) {
  5136. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  5137. if (!err)
  5138. err =
  5139. pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  5140. /* both attempts failed: */
  5141. if (err) {
  5142. IL_WARN("No suitable DMA available.\n");
  5143. goto out_pci_disable_device;
  5144. }
  5145. }
  5146. err = pci_request_regions(pdev, DRV_NAME);
  5147. if (err)
  5148. goto out_pci_disable_device;
  5149. pci_set_drvdata(pdev, il);
  5150. /***********************
  5151. * 3. Read REV register
  5152. ***********************/
  5153. il->hw_base = pci_iomap(pdev, 0, 0);
  5154. if (!il->hw_base) {
  5155. err = -ENODEV;
  5156. goto out_pci_release_regions;
  5157. }
  5158. D_INFO("pci_resource_len = 0x%08llx\n",
  5159. (unsigned long long)pci_resource_len(pdev, 0));
  5160. D_INFO("pci_resource_base = %p\n", il->hw_base);
  5161. /* these spin locks will be used in apm_ops.init and EEPROM access
  5162. * we should init now
  5163. */
  5164. spin_lock_init(&il->reg_lock);
  5165. spin_lock_init(&il->lock);
  5166. /*
  5167. * stop and reset the on-board processor just in case it is in a
  5168. * strange state ... like being left stranded by a primary kernel
  5169. * and this is now the kdump kernel trying to start up
  5170. */
  5171. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  5172. il4965_hw_detect(il);
  5173. IL_INFO("Detected %s, REV=0x%X\n", il->cfg->name, il->hw_rev);
  5174. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5175. * PCI Tx retries from interfering with C3 CPU state */
  5176. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  5177. il4965_prepare_card_hw(il);
  5178. if (!il->hw_ready) {
  5179. IL_WARN("Failed, HW not ready\n");
  5180. goto out_iounmap;
  5181. }
  5182. /*****************
  5183. * 4. Read EEPROM
  5184. *****************/
  5185. /* Read the EEPROM */
  5186. err = il_eeprom_init(il);
  5187. if (err) {
  5188. IL_ERR("Unable to init EEPROM\n");
  5189. goto out_iounmap;
  5190. }
  5191. err = il4965_eeprom_check_version(il);
  5192. if (err)
  5193. goto out_free_eeprom;
  5194. if (err)
  5195. goto out_free_eeprom;
  5196. /* extract MAC Address */
  5197. il4965_eeprom_get_mac(il, il->addresses[0].addr);
  5198. D_INFO("MAC address: %pM\n", il->addresses[0].addr);
  5199. il->hw->wiphy->addresses = il->addresses;
  5200. il->hw->wiphy->n_addresses = 1;
  5201. /************************
  5202. * 5. Setup HW constants
  5203. ************************/
  5204. il4965_set_hw_params(il);
  5205. /*******************
  5206. * 6. Setup il
  5207. *******************/
  5208. err = il4965_init_drv(il);
  5209. if (err)
  5210. goto out_free_eeprom;
  5211. /* At this point both hw and il are initialized. */
  5212. /********************
  5213. * 7. Setup services
  5214. ********************/
  5215. spin_lock_irqsave(&il->lock, flags);
  5216. il_disable_interrupts(il);
  5217. spin_unlock_irqrestore(&il->lock, flags);
  5218. pci_enable_msi(il->pci_dev);
  5219. err = request_irq(il->pci_dev->irq, il_isr, IRQF_SHARED, DRV_NAME, il);
  5220. if (err) {
  5221. IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq);
  5222. goto out_disable_msi;
  5223. }
  5224. il4965_setup_deferred_work(il);
  5225. il4965_setup_handlers(il);
  5226. /*********************************************
  5227. * 8. Enable interrupts and read RFKILL state
  5228. *********************************************/
  5229. /* enable rfkill interrupt: hw bug w/a */
  5230. pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd);
  5231. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  5232. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  5233. pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd);
  5234. }
  5235. il_enable_rfkill_int(il);
  5236. /* If platform's RF_KILL switch is NOT set to KILL */
  5237. if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  5238. clear_bit(S_RF_KILL_HW, &il->status);
  5239. else
  5240. set_bit(S_RF_KILL_HW, &il->status);
  5241. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  5242. test_bit(S_RF_KILL_HW, &il->status));
  5243. il_power_initialize(il);
  5244. init_completion(&il->_4965.firmware_loading_complete);
  5245. err = il4965_request_firmware(il, true);
  5246. if (err)
  5247. goto out_destroy_workqueue;
  5248. return 0;
  5249. out_destroy_workqueue:
  5250. destroy_workqueue(il->workqueue);
  5251. il->workqueue = NULL;
  5252. free_irq(il->pci_dev->irq, il);
  5253. out_disable_msi:
  5254. pci_disable_msi(il->pci_dev);
  5255. il4965_uninit_drv(il);
  5256. out_free_eeprom:
  5257. il_eeprom_free(il);
  5258. out_iounmap:
  5259. pci_iounmap(pdev, il->hw_base);
  5260. out_pci_release_regions:
  5261. pci_set_drvdata(pdev, NULL);
  5262. pci_release_regions(pdev);
  5263. out_pci_disable_device:
  5264. pci_disable_device(pdev);
  5265. out_ieee80211_free_hw:
  5266. il_free_traffic_mem(il);
  5267. ieee80211_free_hw(il->hw);
  5268. out:
  5269. return err;
  5270. }
  5271. static void __devexit
  5272. il4965_pci_remove(struct pci_dev *pdev)
  5273. {
  5274. struct il_priv *il = pci_get_drvdata(pdev);
  5275. unsigned long flags;
  5276. if (!il)
  5277. return;
  5278. wait_for_completion(&il->_4965.firmware_loading_complete);
  5279. D_INFO("*** UNLOAD DRIVER ***\n");
  5280. il_dbgfs_unregister(il);
  5281. sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group);
  5282. /* ieee80211_unregister_hw call wil cause il_mac_stop to
  5283. * to be called and il4965_down since we are removing the device
  5284. * we need to set S_EXIT_PENDING bit.
  5285. */
  5286. set_bit(S_EXIT_PENDING, &il->status);
  5287. il_leds_exit(il);
  5288. if (il->mac80211_registered) {
  5289. ieee80211_unregister_hw(il->hw);
  5290. il->mac80211_registered = 0;
  5291. } else {
  5292. il4965_down(il);
  5293. }
  5294. /*
  5295. * Make sure device is reset to low power before unloading driver.
  5296. * This may be redundant with il4965_down(), but there are paths to
  5297. * run il4965_down() without calling apm_ops.stop(), and there are
  5298. * paths to avoid running il4965_down() at all before leaving driver.
  5299. * This (inexpensive) call *makes sure* device is reset.
  5300. */
  5301. il_apm_stop(il);
  5302. /* make sure we flush any pending irq or
  5303. * tasklet for the driver
  5304. */
  5305. spin_lock_irqsave(&il->lock, flags);
  5306. il_disable_interrupts(il);
  5307. spin_unlock_irqrestore(&il->lock, flags);
  5308. il4965_synchronize_irq(il);
  5309. il4965_dealloc_ucode_pci(il);
  5310. if (il->rxq.bd)
  5311. il4965_rx_queue_free(il, &il->rxq);
  5312. il4965_hw_txq_ctx_free(il);
  5313. il_eeprom_free(il);
  5314. /*netif_stop_queue(dev); */
  5315. flush_workqueue(il->workqueue);
  5316. /* ieee80211_unregister_hw calls il_mac_stop, which flushes
  5317. * il->workqueue... so we can't take down the workqueue
  5318. * until now... */
  5319. destroy_workqueue(il->workqueue);
  5320. il->workqueue = NULL;
  5321. il_free_traffic_mem(il);
  5322. free_irq(il->pci_dev->irq, il);
  5323. pci_disable_msi(il->pci_dev);
  5324. pci_iounmap(pdev, il->hw_base);
  5325. pci_release_regions(pdev);
  5326. pci_disable_device(pdev);
  5327. pci_set_drvdata(pdev, NULL);
  5328. il4965_uninit_drv(il);
  5329. dev_kfree_skb(il->beacon_skb);
  5330. ieee80211_free_hw(il->hw);
  5331. }
  5332. /*
  5333. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  5334. * must be called under il->lock and mac access
  5335. */
  5336. void
  5337. il4965_txq_set_sched(struct il_priv *il, u32 mask)
  5338. {
  5339. il_wr_prph(il, IL49_SCD_TXFACT, mask);
  5340. }
  5341. /*****************************************************************************
  5342. *
  5343. * driver and module entry point
  5344. *
  5345. *****************************************************************************/
  5346. /* Hardware specific file defines the PCI IDs table for that hardware module */
  5347. static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = {
  5348. {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)},
  5349. {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)},
  5350. {0}
  5351. };
  5352. MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids);
  5353. static struct pci_driver il4965_driver = {
  5354. .name = DRV_NAME,
  5355. .id_table = il4965_hw_card_ids,
  5356. .probe = il4965_pci_probe,
  5357. .remove = __devexit_p(il4965_pci_remove),
  5358. .driver.pm = IL_LEGACY_PM_OPS,
  5359. };
  5360. static int __init
  5361. il4965_init(void)
  5362. {
  5363. int ret;
  5364. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  5365. pr_info(DRV_COPYRIGHT "\n");
  5366. ret = il4965_rate_control_register();
  5367. if (ret) {
  5368. pr_err("Unable to register rate control algorithm: %d\n", ret);
  5369. return ret;
  5370. }
  5371. ret = pci_register_driver(&il4965_driver);
  5372. if (ret) {
  5373. pr_err("Unable to initialize PCI module\n");
  5374. goto error_register;
  5375. }
  5376. return ret;
  5377. error_register:
  5378. il4965_rate_control_unregister();
  5379. return ret;
  5380. }
  5381. static void __exit
  5382. il4965_exit(void)
  5383. {
  5384. pci_unregister_driver(&il4965_driver);
  5385. il4965_rate_control_unregister();
  5386. }
  5387. module_exit(il4965_exit);
  5388. module_init(il4965_init);
  5389. #ifdef CONFIG_IWLEGACY_DEBUG
  5390. module_param_named(debug, il_debug_level, uint, S_IRUGO | S_IWUSR);
  5391. MODULE_PARM_DESC(debug, "debug output mask");
  5392. #endif
  5393. module_param_named(swcrypto, il4965_mod_params.sw_crypto, int, S_IRUGO);
  5394. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  5395. module_param_named(queues_num, il4965_mod_params.num_of_queues, int, S_IRUGO);
  5396. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  5397. module_param_named(11n_disable, il4965_mod_params.disable_11n, int, S_IRUGO);
  5398. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  5399. module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K, int,
  5400. S_IRUGO);
  5401. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  5402. module_param_named(fw_restart, il4965_mod_params.restart_fw, int, S_IRUGO);
  5403. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");