iwl4965-base.c 150 KB

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