iwl3945-base.c 234 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377
  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/ieee80211_radiotap.h>
  43. #include <net/mac80211.h>
  44. #include <asm/div64.h>
  45. #include "iwl-3945-core.h"
  46. #include "iwl-3945.h"
  47. #include "iwl-helpers.h"
  48. #ifdef CONFIG_IWL3945_DEBUG
  49. u32 iwl3945_debug_level;
  50. #endif
  51. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  52. struct iwl3945_tx_queue *txq);
  53. /******************************************************************************
  54. *
  55. * module boiler plate
  56. *
  57. ******************************************************************************/
  58. /* module parameters */
  59. static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */
  60. static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */
  61. static int iwl3945_param_disable; /* def: 0 = enable radio */
  62. static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */
  63. int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */
  64. static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */
  65. int iwl3945_param_queues_num = IWL39_MAX_NUM_QUEUES; /* def: 8 Tx queues */
  66. /*
  67. * module name, copyright, version, etc.
  68. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  69. */
  70. #define DRV_DESCRIPTION \
  71. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  72. #ifdef CONFIG_IWL3945_DEBUG
  73. #define VD "d"
  74. #else
  75. #define VD
  76. #endif
  77. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  78. #define VS "s"
  79. #else
  80. #define VS
  81. #endif
  82. #define IWLWIFI_VERSION "1.2.26k" VD VS
  83. #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
  84. #define DRV_VERSION IWLWIFI_VERSION
  85. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  86. MODULE_VERSION(DRV_VERSION);
  87. MODULE_AUTHOR(DRV_COPYRIGHT);
  88. MODULE_LICENSE("GPL");
  89. static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
  90. {
  91. u16 fc = le16_to_cpu(hdr->frame_control);
  92. int hdr_len = ieee80211_get_hdrlen(fc);
  93. if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
  94. return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
  95. return NULL;
  96. }
  97. static const struct ieee80211_supported_band *iwl3945_get_band(
  98. struct iwl3945_priv *priv, enum ieee80211_band band)
  99. {
  100. return priv->hw->wiphy->bands[band];
  101. }
  102. static int iwl3945_is_empty_essid(const char *essid, int essid_len)
  103. {
  104. /* Single white space is for Linksys APs */
  105. if (essid_len == 1 && essid[0] == ' ')
  106. return 1;
  107. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  108. while (essid_len) {
  109. essid_len--;
  110. if (essid[essid_len] != '\0')
  111. return 0;
  112. }
  113. return 1;
  114. }
  115. static const char *iwl3945_escape_essid(const char *essid, u8 essid_len)
  116. {
  117. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  118. const char *s = essid;
  119. char *d = escaped;
  120. if (iwl3945_is_empty_essid(essid, essid_len)) {
  121. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  122. return escaped;
  123. }
  124. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  125. while (essid_len--) {
  126. if (*s == '\0') {
  127. *d++ = '\\';
  128. *d++ = '0';
  129. s++;
  130. } else
  131. *d++ = *s++;
  132. }
  133. *d = '\0';
  134. return escaped;
  135. }
  136. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  137. * DMA services
  138. *
  139. * Theory of operation
  140. *
  141. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  142. * of buffer descriptors, each of which points to one or more data buffers for
  143. * the device to read from or fill. Driver and device exchange status of each
  144. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  145. * entries in each circular buffer, to protect against confusing empty and full
  146. * queue states.
  147. *
  148. * The device reads or writes the data in the queues via the device's several
  149. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  150. *
  151. * For Tx queue, there are low mark and high mark limits. If, after queuing
  152. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  153. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  154. * Tx queue resumed.
  155. *
  156. * The 3945 operates with six queues: One receive queue, one transmit queue
  157. * (#4) for sending commands to the device firmware, and four transmit queues
  158. * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
  159. ***************************************************/
  160. int iwl3945_queue_space(const struct iwl3945_queue *q)
  161. {
  162. int s = q->read_ptr - q->write_ptr;
  163. if (q->read_ptr > q->write_ptr)
  164. s -= q->n_bd;
  165. if (s <= 0)
  166. s += q->n_window;
  167. /* keep some reserve to not confuse empty and full situations */
  168. s -= 2;
  169. if (s < 0)
  170. s = 0;
  171. return s;
  172. }
  173. int iwl3945_x2_queue_used(const struct iwl3945_queue *q, int i)
  174. {
  175. return q->write_ptr > q->read_ptr ?
  176. (i >= q->read_ptr && i < q->write_ptr) :
  177. !(i < q->read_ptr && i >= q->write_ptr);
  178. }
  179. static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge)
  180. {
  181. /* This is for scan command, the big buffer at end of command array */
  182. if (is_huge)
  183. return q->n_window; /* must be power of 2 */
  184. /* Otherwise, use normal size buffers */
  185. return index & (q->n_window - 1);
  186. }
  187. /**
  188. * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
  189. */
  190. static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q,
  191. int count, int slots_num, u32 id)
  192. {
  193. q->n_bd = count;
  194. q->n_window = slots_num;
  195. q->id = id;
  196. /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
  197. * and iwl_queue_dec_wrap are broken. */
  198. BUG_ON(!is_power_of_2(count));
  199. /* slots_num must be power-of-two size, otherwise
  200. * get_cmd_index is broken. */
  201. BUG_ON(!is_power_of_2(slots_num));
  202. q->low_mark = q->n_window / 4;
  203. if (q->low_mark < 4)
  204. q->low_mark = 4;
  205. q->high_mark = q->n_window / 8;
  206. if (q->high_mark < 2)
  207. q->high_mark = 2;
  208. q->write_ptr = q->read_ptr = 0;
  209. return 0;
  210. }
  211. /**
  212. * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  213. */
  214. static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
  215. struct iwl3945_tx_queue *txq, u32 id)
  216. {
  217. struct pci_dev *dev = priv->pci_dev;
  218. /* Driver private data, only for Tx (not command) queues,
  219. * not shared with device. */
  220. if (id != IWL_CMD_QUEUE_NUM) {
  221. txq->txb = kmalloc(sizeof(txq->txb[0]) *
  222. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  223. if (!txq->txb) {
  224. IWL_ERROR("kmalloc for auxiliary BD "
  225. "structures failed\n");
  226. goto error;
  227. }
  228. } else
  229. txq->txb = NULL;
  230. /* Circular buffer of transmit frame descriptors (TFDs),
  231. * shared with device */
  232. txq->bd = pci_alloc_consistent(dev,
  233. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
  234. &txq->q.dma_addr);
  235. if (!txq->bd) {
  236. IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
  237. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
  238. goto error;
  239. }
  240. txq->q.id = id;
  241. return 0;
  242. error:
  243. if (txq->txb) {
  244. kfree(txq->txb);
  245. txq->txb = NULL;
  246. }
  247. return -ENOMEM;
  248. }
  249. /**
  250. * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
  251. */
  252. int iwl3945_tx_queue_init(struct iwl3945_priv *priv,
  253. struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
  254. {
  255. struct pci_dev *dev = priv->pci_dev;
  256. int len;
  257. int rc = 0;
  258. /*
  259. * Alloc buffer array for commands (Tx or other types of commands).
  260. * For the command queue (#4), allocate command space + one big
  261. * command for scan, since scan command is very huge; the system will
  262. * not have two scans at the same time, so only one is needed.
  263. * For data Tx queues (all other queues), no super-size command
  264. * space is needed.
  265. */
  266. len = sizeof(struct iwl3945_cmd) * slots_num;
  267. if (txq_id == IWL_CMD_QUEUE_NUM)
  268. len += IWL_MAX_SCAN_SIZE;
  269. txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
  270. if (!txq->cmd)
  271. return -ENOMEM;
  272. /* Alloc driver data array and TFD circular buffer */
  273. rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
  274. if (rc) {
  275. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  276. return -ENOMEM;
  277. }
  278. txq->need_update = 0;
  279. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  280. * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
  281. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  282. /* Initialize queue high/low-water, head/tail indexes */
  283. iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  284. /* Tell device where to find queue, enable DMA channel. */
  285. iwl3945_hw_tx_queue_init(priv, txq);
  286. return 0;
  287. }
  288. /**
  289. * iwl3945_tx_queue_free - Deallocate DMA queue.
  290. * @txq: Transmit queue to deallocate.
  291. *
  292. * Empty queue by removing and destroying all BD's.
  293. * Free all buffers.
  294. * 0-fill, but do not free "txq" descriptor structure.
  295. */
  296. void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
  297. {
  298. struct iwl3945_queue *q = &txq->q;
  299. struct pci_dev *dev = priv->pci_dev;
  300. int len;
  301. if (q->n_bd == 0)
  302. return;
  303. /* first, empty all BD's */
  304. for (; q->write_ptr != q->read_ptr;
  305. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
  306. iwl3945_hw_txq_free_tfd(priv, txq);
  307. len = sizeof(struct iwl3945_cmd) * q->n_window;
  308. if (q->id == IWL_CMD_QUEUE_NUM)
  309. len += IWL_MAX_SCAN_SIZE;
  310. /* De-alloc array of command/tx buffers */
  311. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  312. /* De-alloc circular buffer of TFDs */
  313. if (txq->q.n_bd)
  314. pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
  315. txq->q.n_bd, txq->bd, txq->q.dma_addr);
  316. /* De-alloc array of per-TFD driver data */
  317. if (txq->txb) {
  318. kfree(txq->txb);
  319. txq->txb = NULL;
  320. }
  321. /* 0-fill queue descriptor structure */
  322. memset(txq, 0, sizeof(*txq));
  323. }
  324. const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  325. /*************** STATION TABLE MANAGEMENT ****
  326. * mac80211 should be examined to determine if sta_info is duplicating
  327. * the functionality provided here
  328. */
  329. /**************************************************************/
  330. #if 0 /* temporary disable till we add real remove station */
  331. /**
  332. * iwl3945_remove_station - Remove driver's knowledge of station.
  333. *
  334. * NOTE: This does not remove station from device's station table.
  335. */
  336. static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap)
  337. {
  338. int index = IWL_INVALID_STATION;
  339. int i;
  340. unsigned long flags;
  341. spin_lock_irqsave(&priv->sta_lock, flags);
  342. if (is_ap)
  343. index = IWL_AP_ID;
  344. else if (is_broadcast_ether_addr(addr))
  345. index = priv->hw_setting.bcast_sta_id;
  346. else
  347. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
  348. if (priv->stations[i].used &&
  349. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  350. addr)) {
  351. index = i;
  352. break;
  353. }
  354. if (unlikely(index == IWL_INVALID_STATION))
  355. goto out;
  356. if (priv->stations[index].used) {
  357. priv->stations[index].used = 0;
  358. priv->num_stations--;
  359. }
  360. BUG_ON(priv->num_stations < 0);
  361. out:
  362. spin_unlock_irqrestore(&priv->sta_lock, flags);
  363. return 0;
  364. }
  365. #endif
  366. /**
  367. * iwl3945_clear_stations_table - Clear the driver's station table
  368. *
  369. * NOTE: This does not clear or otherwise alter the device's station table.
  370. */
  371. static void iwl3945_clear_stations_table(struct iwl3945_priv *priv)
  372. {
  373. unsigned long flags;
  374. spin_lock_irqsave(&priv->sta_lock, flags);
  375. priv->num_stations = 0;
  376. memset(priv->stations, 0, sizeof(priv->stations));
  377. spin_unlock_irqrestore(&priv->sta_lock, flags);
  378. }
  379. /**
  380. * iwl3945_add_station - Add station to station tables in driver and device
  381. */
  382. u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags)
  383. {
  384. int i;
  385. int index = IWL_INVALID_STATION;
  386. struct iwl3945_station_entry *station;
  387. unsigned long flags_spin;
  388. DECLARE_MAC_BUF(mac);
  389. u8 rate;
  390. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  391. if (is_ap)
  392. index = IWL_AP_ID;
  393. else if (is_broadcast_ether_addr(addr))
  394. index = priv->hw_setting.bcast_sta_id;
  395. else
  396. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
  397. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  398. addr)) {
  399. index = i;
  400. break;
  401. }
  402. if (!priv->stations[i].used &&
  403. index == IWL_INVALID_STATION)
  404. index = i;
  405. }
  406. /* These two conditions has the same outcome but keep them separate
  407. since they have different meaning */
  408. if (unlikely(index == IWL_INVALID_STATION)) {
  409. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  410. return index;
  411. }
  412. if (priv->stations[index].used &&
  413. !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
  414. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  415. return index;
  416. }
  417. IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
  418. station = &priv->stations[index];
  419. station->used = 1;
  420. priv->num_stations++;
  421. /* Set up the REPLY_ADD_STA command to send to device */
  422. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  423. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  424. station->sta.mode = 0;
  425. station->sta.sta.sta_id = index;
  426. station->sta.station_flags = 0;
  427. if (priv->band == IEEE80211_BAND_5GHZ)
  428. rate = IWL_RATE_6M_PLCP;
  429. else
  430. rate = IWL_RATE_1M_PLCP;
  431. /* Turn on both antennas for the station... */
  432. station->sta.rate_n_flags =
  433. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  434. station->current_rate.rate_n_flags =
  435. le16_to_cpu(station->sta.rate_n_flags);
  436. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  437. /* Add station to device's station table */
  438. iwl3945_send_add_station(priv, &station->sta, flags);
  439. return index;
  440. }
  441. /*************** DRIVER STATUS FUNCTIONS *****/
  442. static inline int iwl3945_is_ready(struct iwl3945_priv *priv)
  443. {
  444. /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
  445. * set but EXIT_PENDING is not */
  446. return test_bit(STATUS_READY, &priv->status) &&
  447. test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
  448. !test_bit(STATUS_EXIT_PENDING, &priv->status);
  449. }
  450. static inline int iwl3945_is_alive(struct iwl3945_priv *priv)
  451. {
  452. return test_bit(STATUS_ALIVE, &priv->status);
  453. }
  454. static inline int iwl3945_is_init(struct iwl3945_priv *priv)
  455. {
  456. return test_bit(STATUS_INIT, &priv->status);
  457. }
  458. static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
  459. {
  460. return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
  461. test_bit(STATUS_RF_KILL_SW, &priv->status);
  462. }
  463. static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
  464. {
  465. if (iwl3945_is_rfkill(priv))
  466. return 0;
  467. return iwl3945_is_ready(priv);
  468. }
  469. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  470. #define IWL_CMD(x) case x : return #x
  471. static const char *get_cmd_string(u8 cmd)
  472. {
  473. switch (cmd) {
  474. IWL_CMD(REPLY_ALIVE);
  475. IWL_CMD(REPLY_ERROR);
  476. IWL_CMD(REPLY_RXON);
  477. IWL_CMD(REPLY_RXON_ASSOC);
  478. IWL_CMD(REPLY_QOS_PARAM);
  479. IWL_CMD(REPLY_RXON_TIMING);
  480. IWL_CMD(REPLY_ADD_STA);
  481. IWL_CMD(REPLY_REMOVE_STA);
  482. IWL_CMD(REPLY_REMOVE_ALL_STA);
  483. IWL_CMD(REPLY_3945_RX);
  484. IWL_CMD(REPLY_TX);
  485. IWL_CMD(REPLY_RATE_SCALE);
  486. IWL_CMD(REPLY_LEDS_CMD);
  487. IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
  488. IWL_CMD(RADAR_NOTIFICATION);
  489. IWL_CMD(REPLY_QUIET_CMD);
  490. IWL_CMD(REPLY_CHANNEL_SWITCH);
  491. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  492. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  493. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  494. IWL_CMD(POWER_TABLE_CMD);
  495. IWL_CMD(PM_SLEEP_NOTIFICATION);
  496. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  497. IWL_CMD(REPLY_SCAN_CMD);
  498. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  499. IWL_CMD(SCAN_START_NOTIFICATION);
  500. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  501. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  502. IWL_CMD(BEACON_NOTIFICATION);
  503. IWL_CMD(REPLY_TX_BEACON);
  504. IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
  505. IWL_CMD(QUIET_NOTIFICATION);
  506. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  507. IWL_CMD(MEASURE_ABORT_NOTIFICATION);
  508. IWL_CMD(REPLY_BT_CONFIG);
  509. IWL_CMD(REPLY_STATISTICS_CMD);
  510. IWL_CMD(STATISTICS_NOTIFICATION);
  511. IWL_CMD(REPLY_CARD_STATE_CMD);
  512. IWL_CMD(CARD_STATE_NOTIFICATION);
  513. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  514. default:
  515. return "UNKNOWN";
  516. }
  517. }
  518. #define HOST_COMPLETE_TIMEOUT (HZ / 2)
  519. /**
  520. * iwl3945_enqueue_hcmd - enqueue a uCode command
  521. * @priv: device private data point
  522. * @cmd: a point to the ucode command structure
  523. *
  524. * The function returns < 0 values to indicate the operation is
  525. * failed. On success, it turns the index (> 0) of command in the
  526. * command queue.
  527. */
  528. static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  529. {
  530. struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  531. struct iwl3945_queue *q = &txq->q;
  532. struct iwl3945_tfd_frame *tfd;
  533. u32 *control_flags;
  534. struct iwl3945_cmd *out_cmd;
  535. u32 idx;
  536. u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  537. dma_addr_t phys_addr;
  538. int pad;
  539. u16 count;
  540. int ret;
  541. unsigned long flags;
  542. /* If any of the command structures end up being larger than
  543. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  544. * we will need to increase the size of the TFD entries */
  545. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  546. !(cmd->meta.flags & CMD_SIZE_HUGE));
  547. if (iwl3945_is_rfkill(priv)) {
  548. IWL_DEBUG_INFO("Not sending command - RF KILL");
  549. return -EIO;
  550. }
  551. if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
  552. IWL_ERROR("No space for Tx\n");
  553. return -ENOSPC;
  554. }
  555. spin_lock_irqsave(&priv->hcmd_lock, flags);
  556. tfd = &txq->bd[q->write_ptr];
  557. memset(tfd, 0, sizeof(*tfd));
  558. control_flags = (u32 *) tfd;
  559. idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
  560. out_cmd = &txq->cmd[idx];
  561. out_cmd->hdr.cmd = cmd->id;
  562. memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
  563. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  564. /* At this point, the out_cmd now has all of the incoming cmd
  565. * information */
  566. out_cmd->hdr.flags = 0;
  567. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
  568. INDEX_TO_SEQ(q->write_ptr));
  569. if (out_cmd->meta.flags & CMD_SIZE_HUGE)
  570. out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
  571. phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
  572. offsetof(struct iwl3945_cmd, hdr);
  573. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
  574. pad = U32_PAD(cmd->len);
  575. count = TFD_CTL_COUNT_GET(*control_flags);
  576. *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
  577. IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
  578. "%d bytes at %d[%d]:%d\n",
  579. get_cmd_string(out_cmd->hdr.cmd),
  580. out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
  581. fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  582. txq->need_update = 1;
  583. /* Increment and update queue's write index */
  584. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  585. ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
  586. spin_unlock_irqrestore(&priv->hcmd_lock, flags);
  587. return ret ? ret : idx;
  588. }
  589. static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  590. {
  591. int ret;
  592. BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
  593. /* An asynchronous command can not expect an SKB to be set. */
  594. BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
  595. /* An asynchronous command MUST have a callback. */
  596. BUG_ON(!cmd->meta.u.callback);
  597. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  598. return -EBUSY;
  599. ret = iwl3945_enqueue_hcmd(priv, cmd);
  600. if (ret < 0) {
  601. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  602. get_cmd_string(cmd->id), ret);
  603. return ret;
  604. }
  605. return 0;
  606. }
  607. static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  608. {
  609. int cmd_idx;
  610. int ret;
  611. BUG_ON(cmd->meta.flags & CMD_ASYNC);
  612. /* A synchronous command can not have a callback set. */
  613. BUG_ON(cmd->meta.u.callback != NULL);
  614. if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) {
  615. IWL_ERROR("Error sending %s: Already sending a host command\n",
  616. get_cmd_string(cmd->id));
  617. ret = -EBUSY;
  618. goto out;
  619. }
  620. set_bit(STATUS_HCMD_ACTIVE, &priv->status);
  621. if (cmd->meta.flags & CMD_WANT_SKB)
  622. cmd->meta.source = &cmd->meta;
  623. cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
  624. if (cmd_idx < 0) {
  625. ret = cmd_idx;
  626. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  627. get_cmd_string(cmd->id), ret);
  628. goto out;
  629. }
  630. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  631. !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
  632. HOST_COMPLETE_TIMEOUT);
  633. if (!ret) {
  634. if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
  635. IWL_ERROR("Error sending %s: time out after %dms.\n",
  636. get_cmd_string(cmd->id),
  637. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  638. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  639. ret = -ETIMEDOUT;
  640. goto cancel;
  641. }
  642. }
  643. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  644. IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
  645. get_cmd_string(cmd->id));
  646. ret = -ECANCELED;
  647. goto fail;
  648. }
  649. if (test_bit(STATUS_FW_ERROR, &priv->status)) {
  650. IWL_DEBUG_INFO("Command %s failed: FW Error\n",
  651. get_cmd_string(cmd->id));
  652. ret = -EIO;
  653. goto fail;
  654. }
  655. if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
  656. IWL_ERROR("Error: Response NULL in '%s'\n",
  657. get_cmd_string(cmd->id));
  658. ret = -EIO;
  659. goto out;
  660. }
  661. ret = 0;
  662. goto out;
  663. cancel:
  664. if (cmd->meta.flags & CMD_WANT_SKB) {
  665. struct iwl3945_cmd *qcmd;
  666. /* Cancel the CMD_WANT_SKB flag for the cmd in the
  667. * TX cmd queue. Otherwise in case the cmd comes
  668. * in later, it will possibly set an invalid
  669. * address (cmd->meta.source). */
  670. qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
  671. qcmd->meta.flags &= ~CMD_WANT_SKB;
  672. }
  673. fail:
  674. if (cmd->meta.u.skb) {
  675. dev_kfree_skb_any(cmd->meta.u.skb);
  676. cmd->meta.u.skb = NULL;
  677. }
  678. out:
  679. clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status);
  680. return ret;
  681. }
  682. int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  683. {
  684. if (cmd->meta.flags & CMD_ASYNC)
  685. return iwl3945_send_cmd_async(priv, cmd);
  686. return iwl3945_send_cmd_sync(priv, cmd);
  687. }
  688. int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data)
  689. {
  690. struct iwl3945_host_cmd cmd = {
  691. .id = id,
  692. .len = len,
  693. .data = data,
  694. };
  695. return iwl3945_send_cmd_sync(priv, &cmd);
  696. }
  697. static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val)
  698. {
  699. struct iwl3945_host_cmd cmd = {
  700. .id = id,
  701. .len = sizeof(val),
  702. .data = &val,
  703. };
  704. return iwl3945_send_cmd_sync(priv, &cmd);
  705. }
  706. int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
  707. {
  708. return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
  709. }
  710. /**
  711. * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
  712. * @band: 2.4 or 5 GHz band
  713. * @channel: Any channel valid for the requested band
  714. * In addition to setting the staging RXON, priv->band is also set.
  715. *
  716. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  717. * in the staging RXON flag structure based on the band
  718. */
  719. static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv,
  720. enum ieee80211_band band,
  721. u16 channel)
  722. {
  723. if (!iwl3945_get_channel_info(priv, band, channel)) {
  724. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  725. channel, band);
  726. return -EINVAL;
  727. }
  728. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  729. (priv->band == band))
  730. return 0;
  731. priv->staging_rxon.channel = cpu_to_le16(channel);
  732. if (band == IEEE80211_BAND_5GHZ)
  733. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  734. else
  735. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  736. priv->band = band;
  737. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  738. return 0;
  739. }
  740. /**
  741. * iwl3945_check_rxon_cmd - validate RXON structure is valid
  742. *
  743. * NOTE: This is really only useful during development and can eventually
  744. * be #ifdef'd out once the driver is stable and folks aren't actively
  745. * making changes
  746. */
  747. static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon)
  748. {
  749. int error = 0;
  750. int counter = 1;
  751. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  752. error |= le32_to_cpu(rxon->flags &
  753. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  754. RXON_FLG_RADAR_DETECT_MSK));
  755. if (error)
  756. IWL_WARNING("check 24G fields %d | %d\n",
  757. counter++, error);
  758. } else {
  759. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  760. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  761. if (error)
  762. IWL_WARNING("check 52 fields %d | %d\n",
  763. counter++, error);
  764. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  765. if (error)
  766. IWL_WARNING("check 52 CCK %d | %d\n",
  767. counter++, error);
  768. }
  769. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  770. if (error)
  771. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  772. /* make sure basic rates 6Mbps and 1Mbps are supported */
  773. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  774. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  775. if (error)
  776. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  777. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  778. if (error)
  779. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  780. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  781. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  782. if (error)
  783. IWL_WARNING("check CCK and short slot %d | %d\n",
  784. counter++, error);
  785. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  786. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  787. if (error)
  788. IWL_WARNING("check CCK & auto detect %d | %d\n",
  789. counter++, error);
  790. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  791. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  792. if (error)
  793. IWL_WARNING("check TGG and auto detect %d | %d\n",
  794. counter++, error);
  795. if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
  796. error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
  797. RXON_FLG_ANT_A_MSK)) == 0);
  798. if (error)
  799. IWL_WARNING("check antenna %d %d\n", counter++, error);
  800. if (error)
  801. IWL_WARNING("Tuning to channel %d\n",
  802. le16_to_cpu(rxon->channel));
  803. if (error) {
  804. IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
  805. return -1;
  806. }
  807. return 0;
  808. }
  809. /**
  810. * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  811. * @priv: staging_rxon is compared to active_rxon
  812. *
  813. * If the RXON structure is changing enough to require a new tune,
  814. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  815. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  816. */
  817. static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
  818. {
  819. /* These items are only settable from the full RXON command */
  820. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  821. compare_ether_addr(priv->staging_rxon.bssid_addr,
  822. priv->active_rxon.bssid_addr) ||
  823. compare_ether_addr(priv->staging_rxon.node_addr,
  824. priv->active_rxon.node_addr) ||
  825. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  826. priv->active_rxon.wlap_bssid_addr) ||
  827. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  828. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  829. (priv->staging_rxon.air_propagation !=
  830. priv->active_rxon.air_propagation) ||
  831. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  832. return 1;
  833. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  834. * be updated with the RXON_ASSOC command -- however only some
  835. * flag transitions are allowed using RXON_ASSOC */
  836. /* Check if we are not switching bands */
  837. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  838. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  839. return 1;
  840. /* Check if we are switching association toggle */
  841. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  842. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  843. return 1;
  844. return 0;
  845. }
  846. static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv)
  847. {
  848. int rc = 0;
  849. struct iwl3945_rx_packet *res = NULL;
  850. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  851. struct iwl3945_host_cmd cmd = {
  852. .id = REPLY_RXON_ASSOC,
  853. .len = sizeof(rxon_assoc),
  854. .meta.flags = CMD_WANT_SKB,
  855. .data = &rxon_assoc,
  856. };
  857. const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon;
  858. const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon;
  859. if ((rxon1->flags == rxon2->flags) &&
  860. (rxon1->filter_flags == rxon2->filter_flags) &&
  861. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  862. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  863. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  864. return 0;
  865. }
  866. rxon_assoc.flags = priv->staging_rxon.flags;
  867. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  868. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  869. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  870. rxon_assoc.reserved = 0;
  871. rc = iwl3945_send_cmd_sync(priv, &cmd);
  872. if (rc)
  873. return rc;
  874. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  875. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  876. IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
  877. rc = -EIO;
  878. }
  879. priv->alloc_rxb_skb--;
  880. dev_kfree_skb_any(cmd.meta.u.skb);
  881. return rc;
  882. }
  883. /**
  884. * iwl3945_commit_rxon - commit staging_rxon to hardware
  885. *
  886. * The RXON command in staging_rxon is committed to the hardware and
  887. * the active_rxon structure is updated with the new data. This
  888. * function correctly transitions out of the RXON_ASSOC_MSK state if
  889. * a HW tune is required based on the RXON structure changes.
  890. */
  891. static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
  892. {
  893. /* cast away the const for active_rxon in this function */
  894. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  895. int rc = 0;
  896. DECLARE_MAC_BUF(mac);
  897. if (!iwl3945_is_alive(priv))
  898. return -1;
  899. /* always get timestamp with Rx frame */
  900. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  901. /* select antenna */
  902. priv->staging_rxon.flags &=
  903. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  904. priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv);
  905. rc = iwl3945_check_rxon_cmd(&priv->staging_rxon);
  906. if (rc) {
  907. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  908. return -EINVAL;
  909. }
  910. /* If we don't need to send a full RXON, we can use
  911. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  912. * and other flags for the current radio configuration. */
  913. if (!iwl3945_full_rxon_required(priv)) {
  914. rc = iwl3945_send_rxon_assoc(priv);
  915. if (rc) {
  916. IWL_ERROR("Error setting RXON_ASSOC "
  917. "configuration (%d).\n", rc);
  918. return rc;
  919. }
  920. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  921. return 0;
  922. }
  923. /* If we are currently associated and the new config requires
  924. * an RXON_ASSOC and the new config wants the associated mask enabled,
  925. * we must clear the associated from the active configuration
  926. * before we apply the new config */
  927. if (iwl3945_is_associated(priv) &&
  928. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  929. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  930. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  931. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  932. sizeof(struct iwl3945_rxon_cmd),
  933. &priv->active_rxon);
  934. /* If the mask clearing failed then we set
  935. * active_rxon back to what it was previously */
  936. if (rc) {
  937. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  938. IWL_ERROR("Error clearing ASSOC_MSK on current "
  939. "configuration (%d).\n", rc);
  940. return rc;
  941. }
  942. }
  943. IWL_DEBUG_INFO("Sending RXON\n"
  944. "* with%s RXON_FILTER_ASSOC_MSK\n"
  945. "* channel = %d\n"
  946. "* bssid = %s\n",
  947. ((priv->staging_rxon.filter_flags &
  948. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  949. le16_to_cpu(priv->staging_rxon.channel),
  950. print_mac(mac, priv->staging_rxon.bssid_addr));
  951. /* Apply the new configuration */
  952. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  953. sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon);
  954. if (rc) {
  955. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  956. return rc;
  957. }
  958. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  959. iwl3945_clear_stations_table(priv);
  960. /* If we issue a new RXON command which required a tune then we must
  961. * send a new TXPOWER command or we won't be able to Tx any frames */
  962. rc = iwl3945_hw_reg_send_txpower(priv);
  963. if (rc) {
  964. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  965. return rc;
  966. }
  967. /* Add the broadcast address so we can send broadcast frames */
  968. if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) ==
  969. IWL_INVALID_STATION) {
  970. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  971. return -EIO;
  972. }
  973. /* If we have set the ASSOC_MSK and we are in BSS mode then
  974. * add the IWL_AP_ID to the station rate table */
  975. if (iwl3945_is_associated(priv) &&
  976. (priv->iw_mode == IEEE80211_IF_TYPE_STA))
  977. if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
  978. == IWL_INVALID_STATION) {
  979. IWL_ERROR("Error adding AP address for transmit.\n");
  980. return -EIO;
  981. }
  982. /* Init the hardware's rate fallback order based on the band */
  983. rc = iwl3945_init_hw_rate_table(priv);
  984. if (rc) {
  985. IWL_ERROR("Error setting HW rate table: %02X\n", rc);
  986. return -EIO;
  987. }
  988. return 0;
  989. }
  990. static int iwl3945_send_bt_config(struct iwl3945_priv *priv)
  991. {
  992. struct iwl3945_bt_cmd bt_cmd = {
  993. .flags = 3,
  994. .lead_time = 0xAA,
  995. .max_kill = 1,
  996. .kill_ack_mask = 0,
  997. .kill_cts_mask = 0,
  998. };
  999. return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1000. sizeof(struct iwl3945_bt_cmd), &bt_cmd);
  1001. }
  1002. static int iwl3945_send_scan_abort(struct iwl3945_priv *priv)
  1003. {
  1004. int rc = 0;
  1005. struct iwl3945_rx_packet *res;
  1006. struct iwl3945_host_cmd cmd = {
  1007. .id = REPLY_SCAN_ABORT_CMD,
  1008. .meta.flags = CMD_WANT_SKB,
  1009. };
  1010. /* If there isn't a scan actively going on in the hardware
  1011. * then we are in between scan bands and not actually
  1012. * actively scanning, so don't send the abort command */
  1013. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1014. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1015. return 0;
  1016. }
  1017. rc = iwl3945_send_cmd_sync(priv, &cmd);
  1018. if (rc) {
  1019. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1020. return rc;
  1021. }
  1022. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1023. if (res->u.status != CAN_ABORT_STATUS) {
  1024. /* The scan abort will return 1 for success or
  1025. * 2 for "failure". A failure condition can be
  1026. * due to simply not being in an active scan which
  1027. * can occur if we send the scan abort before we
  1028. * the microcode has notified us that a scan is
  1029. * completed. */
  1030. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  1031. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1032. clear_bit(STATUS_SCAN_HW, &priv->status);
  1033. }
  1034. dev_kfree_skb_any(cmd.meta.u.skb);
  1035. return rc;
  1036. }
  1037. static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv,
  1038. struct iwl3945_cmd *cmd,
  1039. struct sk_buff *skb)
  1040. {
  1041. return 1;
  1042. }
  1043. /*
  1044. * CARD_STATE_CMD
  1045. *
  1046. * Use: Sets the device's internal card state to enable, disable, or halt
  1047. *
  1048. * When in the 'enable' state the card operates as normal.
  1049. * When in the 'disable' state, the card enters into a low power mode.
  1050. * When in the 'halt' state, the card is shut down and must be fully
  1051. * restarted to come back on.
  1052. */
  1053. static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag)
  1054. {
  1055. struct iwl3945_host_cmd cmd = {
  1056. .id = REPLY_CARD_STATE_CMD,
  1057. .len = sizeof(u32),
  1058. .data = &flags,
  1059. .meta.flags = meta_flag,
  1060. };
  1061. if (meta_flag & CMD_ASYNC)
  1062. cmd.meta.u.callback = iwl3945_card_state_sync_callback;
  1063. return iwl3945_send_cmd(priv, &cmd);
  1064. }
  1065. static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv,
  1066. struct iwl3945_cmd *cmd, struct sk_buff *skb)
  1067. {
  1068. struct iwl3945_rx_packet *res = NULL;
  1069. if (!skb) {
  1070. IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
  1071. return 1;
  1072. }
  1073. res = (struct iwl3945_rx_packet *)skb->data;
  1074. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1075. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1076. res->hdr.flags);
  1077. return 1;
  1078. }
  1079. switch (res->u.add_sta.status) {
  1080. case ADD_STA_SUCCESS_MSK:
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. /* We didn't cache the SKB; let the caller free it */
  1086. return 1;
  1087. }
  1088. int iwl3945_send_add_station(struct iwl3945_priv *priv,
  1089. struct iwl3945_addsta_cmd *sta, u8 flags)
  1090. {
  1091. struct iwl3945_rx_packet *res = NULL;
  1092. int rc = 0;
  1093. struct iwl3945_host_cmd cmd = {
  1094. .id = REPLY_ADD_STA,
  1095. .len = sizeof(struct iwl3945_addsta_cmd),
  1096. .meta.flags = flags,
  1097. .data = sta,
  1098. };
  1099. if (flags & CMD_ASYNC)
  1100. cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
  1101. else
  1102. cmd.meta.flags |= CMD_WANT_SKB;
  1103. rc = iwl3945_send_cmd(priv, &cmd);
  1104. if (rc || (flags & CMD_ASYNC))
  1105. return rc;
  1106. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1107. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1108. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1109. res->hdr.flags);
  1110. rc = -EIO;
  1111. }
  1112. if (rc == 0) {
  1113. switch (res->u.add_sta.status) {
  1114. case ADD_STA_SUCCESS_MSK:
  1115. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  1116. break;
  1117. default:
  1118. rc = -EIO;
  1119. IWL_WARNING("REPLY_ADD_STA failed\n");
  1120. break;
  1121. }
  1122. }
  1123. priv->alloc_rxb_skb--;
  1124. dev_kfree_skb_any(cmd.meta.u.skb);
  1125. return rc;
  1126. }
  1127. static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv,
  1128. struct ieee80211_key_conf *keyconf,
  1129. u8 sta_id)
  1130. {
  1131. unsigned long flags;
  1132. __le16 key_flags = 0;
  1133. switch (keyconf->alg) {
  1134. case ALG_CCMP:
  1135. key_flags |= STA_KEY_FLG_CCMP;
  1136. key_flags |= cpu_to_le16(
  1137. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  1138. key_flags &= ~STA_KEY_FLG_INVALID;
  1139. break;
  1140. case ALG_TKIP:
  1141. case ALG_WEP:
  1142. default:
  1143. return -EINVAL;
  1144. }
  1145. spin_lock_irqsave(&priv->sta_lock, flags);
  1146. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  1147. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  1148. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  1149. keyconf->keylen);
  1150. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  1151. keyconf->keylen);
  1152. priv->stations[sta_id].sta.key.key_flags = key_flags;
  1153. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1154. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1155. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1156. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  1157. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1158. return 0;
  1159. }
  1160. static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id)
  1161. {
  1162. unsigned long flags;
  1163. spin_lock_irqsave(&priv->sta_lock, flags);
  1164. memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  1165. memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo));
  1166. priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  1167. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1168. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1169. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1170. IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
  1171. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1172. return 0;
  1173. }
  1174. static void iwl3945_clear_free_frames(struct iwl3945_priv *priv)
  1175. {
  1176. struct list_head *element;
  1177. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  1178. priv->frames_count);
  1179. while (!list_empty(&priv->free_frames)) {
  1180. element = priv->free_frames.next;
  1181. list_del(element);
  1182. kfree(list_entry(element, struct iwl3945_frame, list));
  1183. priv->frames_count--;
  1184. }
  1185. if (priv->frames_count) {
  1186. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  1187. priv->frames_count);
  1188. priv->frames_count = 0;
  1189. }
  1190. }
  1191. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv)
  1192. {
  1193. struct iwl3945_frame *frame;
  1194. struct list_head *element;
  1195. if (list_empty(&priv->free_frames)) {
  1196. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  1197. if (!frame) {
  1198. IWL_ERROR("Could not allocate frame!\n");
  1199. return NULL;
  1200. }
  1201. priv->frames_count++;
  1202. return frame;
  1203. }
  1204. element = priv->free_frames.next;
  1205. list_del(element);
  1206. return list_entry(element, struct iwl3945_frame, list);
  1207. }
  1208. static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame)
  1209. {
  1210. memset(frame, 0, sizeof(*frame));
  1211. list_add(&frame->list, &priv->free_frames);
  1212. }
  1213. unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
  1214. struct ieee80211_hdr *hdr,
  1215. const u8 *dest, int left)
  1216. {
  1217. if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
  1218. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  1219. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  1220. return 0;
  1221. if (priv->ibss_beacon->len > left)
  1222. return 0;
  1223. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  1224. return priv->ibss_beacon->len;
  1225. }
  1226. static u8 iwl3945_rate_get_lowest_plcp(int rate_mask)
  1227. {
  1228. u8 i;
  1229. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  1230. i = iwl3945_rates[i].next_ieee) {
  1231. if (rate_mask & (1 << i))
  1232. return iwl3945_rates[i].plcp;
  1233. }
  1234. return IWL_RATE_INVALID;
  1235. }
  1236. static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv)
  1237. {
  1238. struct iwl3945_frame *frame;
  1239. unsigned int frame_size;
  1240. int rc;
  1241. u8 rate;
  1242. frame = iwl3945_get_free_frame(priv);
  1243. if (!frame) {
  1244. IWL_ERROR("Could not obtain free frame buffer for beacon "
  1245. "command.\n");
  1246. return -ENOMEM;
  1247. }
  1248. if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
  1249. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic &
  1250. 0xFF0);
  1251. if (rate == IWL_INVALID_RATE)
  1252. rate = IWL_RATE_6M_PLCP;
  1253. } else {
  1254. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
  1255. if (rate == IWL_INVALID_RATE)
  1256. rate = IWL_RATE_1M_PLCP;
  1257. }
  1258. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  1259. rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  1260. &frame->u.cmd[0]);
  1261. iwl3945_free_frame(priv, frame);
  1262. return rc;
  1263. }
  1264. /******************************************************************************
  1265. *
  1266. * EEPROM related functions
  1267. *
  1268. ******************************************************************************/
  1269. static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac)
  1270. {
  1271. memcpy(mac, priv->eeprom.mac_address, 6);
  1272. }
  1273. /*
  1274. * Clear the OWNER_MSK, to establish driver (instead of uCode running on
  1275. * embedded controller) as EEPROM reader; each read is a series of pulses
  1276. * to/from the EEPROM chip, not a single event, so even reads could conflict
  1277. * if they weren't arbitrated by some ownership mechanism. Here, the driver
  1278. * simply claims ownership, which should be safe when this function is called
  1279. * (i.e. before loading uCode!).
  1280. */
  1281. static inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv *priv)
  1282. {
  1283. _iwl3945_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
  1284. return 0;
  1285. }
  1286. /**
  1287. * iwl3945_eeprom_init - read EEPROM contents
  1288. *
  1289. * Load the EEPROM contents from adapter into priv->eeprom
  1290. *
  1291. * NOTE: This routine uses the non-debug IO access functions.
  1292. */
  1293. int iwl3945_eeprom_init(struct iwl3945_priv *priv)
  1294. {
  1295. u16 *e = (u16 *)&priv->eeprom;
  1296. u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
  1297. u32 r;
  1298. int sz = sizeof(priv->eeprom);
  1299. int rc;
  1300. int i;
  1301. u16 addr;
  1302. /* The EEPROM structure has several padding buffers within it
  1303. * and when adding new EEPROM maps is subject to programmer errors
  1304. * which may be very difficult to identify without explicitly
  1305. * checking the resulting size of the eeprom map. */
  1306. BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
  1307. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  1308. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  1309. return -ENOENT;
  1310. }
  1311. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  1312. rc = iwl3945_eeprom_acquire_semaphore(priv);
  1313. if (rc < 0) {
  1314. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  1315. return -ENOENT;
  1316. }
  1317. /* eeprom is an array of 16bit values */
  1318. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  1319. _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1);
  1320. _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  1321. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  1322. i += IWL_EEPROM_ACCESS_DELAY) {
  1323. r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
  1324. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  1325. break;
  1326. udelay(IWL_EEPROM_ACCESS_DELAY);
  1327. }
  1328. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  1329. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  1330. return -ETIMEDOUT;
  1331. }
  1332. e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
  1333. }
  1334. return 0;
  1335. }
  1336. static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv)
  1337. {
  1338. if (priv->hw_setting.shared_virt)
  1339. pci_free_consistent(priv->pci_dev,
  1340. sizeof(struct iwl3945_shared),
  1341. priv->hw_setting.shared_virt,
  1342. priv->hw_setting.shared_phys);
  1343. }
  1344. /**
  1345. * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
  1346. *
  1347. * return : set the bit for each supported rate insert in ie
  1348. */
  1349. static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  1350. u16 basic_rate, int *left)
  1351. {
  1352. u16 ret_rates = 0, bit;
  1353. int i;
  1354. u8 *cnt = ie;
  1355. u8 *rates = ie + 1;
  1356. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  1357. if (bit & supported_rate) {
  1358. ret_rates |= bit;
  1359. rates[*cnt] = iwl3945_rates[i].ieee |
  1360. ((bit & basic_rate) ? 0x80 : 0x00);
  1361. (*cnt)++;
  1362. (*left)--;
  1363. if ((*left <= 0) ||
  1364. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  1365. break;
  1366. }
  1367. }
  1368. return ret_rates;
  1369. }
  1370. /**
  1371. * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
  1372. */
  1373. static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
  1374. struct ieee80211_mgmt *frame,
  1375. int left, int is_direct)
  1376. {
  1377. int len = 0;
  1378. u8 *pos = NULL;
  1379. u16 active_rates, ret_rates, cck_rates;
  1380. /* Make sure there is enough space for the probe request,
  1381. * two mandatory IEs and the data */
  1382. left -= 24;
  1383. if (left < 0)
  1384. return 0;
  1385. len += 24;
  1386. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  1387. memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN);
  1388. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  1389. memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN);
  1390. frame->seq_ctrl = 0;
  1391. /* fill in our indirect SSID IE */
  1392. /* ...next IE... */
  1393. left -= 2;
  1394. if (left < 0)
  1395. return 0;
  1396. len += 2;
  1397. pos = &(frame->u.probe_req.variable[0]);
  1398. *pos++ = WLAN_EID_SSID;
  1399. *pos++ = 0;
  1400. /* fill in our direct SSID IE... */
  1401. if (is_direct) {
  1402. /* ...next IE... */
  1403. left -= 2 + priv->essid_len;
  1404. if (left < 0)
  1405. return 0;
  1406. /* ... fill it in... */
  1407. *pos++ = WLAN_EID_SSID;
  1408. *pos++ = priv->essid_len;
  1409. memcpy(pos, priv->essid, priv->essid_len);
  1410. pos += priv->essid_len;
  1411. len += 2 + priv->essid_len;
  1412. }
  1413. /* fill in supported rate */
  1414. /* ...next IE... */
  1415. left -= 2;
  1416. if (left < 0)
  1417. return 0;
  1418. /* ... fill it in... */
  1419. *pos++ = WLAN_EID_SUPP_RATES;
  1420. *pos = 0;
  1421. priv->active_rate = priv->rates_mask;
  1422. active_rates = priv->active_rate;
  1423. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  1424. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  1425. ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
  1426. priv->active_rate_basic, &left);
  1427. active_rates &= ~ret_rates;
  1428. ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
  1429. priv->active_rate_basic, &left);
  1430. active_rates &= ~ret_rates;
  1431. len += 2 + *pos;
  1432. pos += (*pos) + 1;
  1433. if (active_rates == 0)
  1434. goto fill_end;
  1435. /* fill in supported extended rate */
  1436. /* ...next IE... */
  1437. left -= 2;
  1438. if (left < 0)
  1439. return 0;
  1440. /* ... fill it in... */
  1441. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1442. *pos = 0;
  1443. iwl3945_supported_rate_to_ie(pos, active_rates,
  1444. priv->active_rate_basic, &left);
  1445. if (*pos > 0)
  1446. len += 2 + *pos;
  1447. fill_end:
  1448. return (u16)len;
  1449. }
  1450. /*
  1451. * QoS support
  1452. */
  1453. static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv,
  1454. struct iwl3945_qosparam_cmd *qos)
  1455. {
  1456. return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  1457. sizeof(struct iwl3945_qosparam_cmd), qos);
  1458. }
  1459. static void iwl3945_reset_qos(struct iwl3945_priv *priv)
  1460. {
  1461. u16 cw_min = 15;
  1462. u16 cw_max = 1023;
  1463. u8 aifs = 2;
  1464. u8 is_legacy = 0;
  1465. unsigned long flags;
  1466. int i;
  1467. spin_lock_irqsave(&priv->lock, flags);
  1468. priv->qos_data.qos_active = 0;
  1469. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  1470. if (priv->qos_data.qos_enable)
  1471. priv->qos_data.qos_active = 1;
  1472. if (!(priv->active_rate & 0xfff0)) {
  1473. cw_min = 31;
  1474. is_legacy = 1;
  1475. }
  1476. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1477. if (priv->qos_data.qos_enable)
  1478. priv->qos_data.qos_active = 1;
  1479. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  1480. cw_min = 31;
  1481. is_legacy = 1;
  1482. }
  1483. if (priv->qos_data.qos_active)
  1484. aifs = 3;
  1485. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  1486. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  1487. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  1488. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  1489. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  1490. if (priv->qos_data.qos_active) {
  1491. i = 1;
  1492. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  1493. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  1494. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  1495. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1496. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1497. i = 2;
  1498. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1499. cpu_to_le16((cw_min + 1) / 2 - 1);
  1500. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1501. cpu_to_le16(cw_max);
  1502. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1503. if (is_legacy)
  1504. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1505. cpu_to_le16(6016);
  1506. else
  1507. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1508. cpu_to_le16(3008);
  1509. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1510. i = 3;
  1511. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1512. cpu_to_le16((cw_min + 1) / 4 - 1);
  1513. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1514. cpu_to_le16((cw_max + 1) / 2 - 1);
  1515. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1516. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1517. if (is_legacy)
  1518. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1519. cpu_to_le16(3264);
  1520. else
  1521. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1522. cpu_to_le16(1504);
  1523. } else {
  1524. for (i = 1; i < 4; i++) {
  1525. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1526. cpu_to_le16(cw_min);
  1527. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1528. cpu_to_le16(cw_max);
  1529. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  1530. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1531. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1532. }
  1533. }
  1534. IWL_DEBUG_QOS("set QoS to default \n");
  1535. spin_unlock_irqrestore(&priv->lock, flags);
  1536. }
  1537. static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force)
  1538. {
  1539. unsigned long flags;
  1540. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1541. return;
  1542. if (!priv->qos_data.qos_enable)
  1543. return;
  1544. spin_lock_irqsave(&priv->lock, flags);
  1545. priv->qos_data.def_qos_parm.qos_flags = 0;
  1546. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  1547. !priv->qos_data.qos_cap.q_AP.txop_request)
  1548. priv->qos_data.def_qos_parm.qos_flags |=
  1549. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  1550. if (priv->qos_data.qos_active)
  1551. priv->qos_data.def_qos_parm.qos_flags |=
  1552. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  1553. spin_unlock_irqrestore(&priv->lock, flags);
  1554. if (force || iwl3945_is_associated(priv)) {
  1555. IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
  1556. priv->qos_data.qos_active);
  1557. iwl3945_send_qos_params_command(priv,
  1558. &(priv->qos_data.def_qos_parm));
  1559. }
  1560. }
  1561. /*
  1562. * Power management (not Tx power!) functions
  1563. */
  1564. #define MSEC_TO_USEC 1024
  1565. #define NOSLP __constant_cpu_to_le32(0)
  1566. #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
  1567. #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
  1568. #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
  1569. __constant_cpu_to_le32(X1), \
  1570. __constant_cpu_to_le32(X2), \
  1571. __constant_cpu_to_le32(X3), \
  1572. __constant_cpu_to_le32(X4)}
  1573. /* default power management (not Tx power) table values */
  1574. /* for tim 0-10 */
  1575. static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = {
  1576. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1577. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
  1578. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
  1579. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
  1580. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
  1581. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
  1582. };
  1583. /* for tim > 10 */
  1584. static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = {
  1585. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1586. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
  1587. SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
  1588. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
  1589. SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
  1590. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
  1591. SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
  1592. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
  1593. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
  1594. SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
  1595. };
  1596. int iwl3945_power_init_handle(struct iwl3945_priv *priv)
  1597. {
  1598. int rc = 0, i;
  1599. struct iwl3945_power_mgr *pow_data;
  1600. int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC;
  1601. u16 pci_pm;
  1602. IWL_DEBUG_POWER("Initialize power \n");
  1603. pow_data = &(priv->power_data);
  1604. memset(pow_data, 0, sizeof(*pow_data));
  1605. pow_data->active_index = IWL_POWER_RANGE_0;
  1606. pow_data->dtim_val = 0xffff;
  1607. memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
  1608. memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
  1609. rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
  1610. if (rc != 0)
  1611. return 0;
  1612. else {
  1613. struct iwl3945_powertable_cmd *cmd;
  1614. IWL_DEBUG_POWER("adjust power command flags\n");
  1615. for (i = 0; i < IWL_POWER_AC; i++) {
  1616. cmd = &pow_data->pwr_range_0[i].cmd;
  1617. if (pci_pm & 0x1)
  1618. cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
  1619. else
  1620. cmd->flags |= IWL_POWER_PCI_PM_MSK;
  1621. }
  1622. }
  1623. return rc;
  1624. }
  1625. static int iwl3945_update_power_cmd(struct iwl3945_priv *priv,
  1626. struct iwl3945_powertable_cmd *cmd, u32 mode)
  1627. {
  1628. int rc = 0, i;
  1629. u8 skip;
  1630. u32 max_sleep = 0;
  1631. struct iwl3945_power_vec_entry *range;
  1632. u8 period = 0;
  1633. struct iwl3945_power_mgr *pow_data;
  1634. if (mode > IWL_POWER_INDEX_5) {
  1635. IWL_DEBUG_POWER("Error invalid power mode \n");
  1636. return -1;
  1637. }
  1638. pow_data = &(priv->power_data);
  1639. if (pow_data->active_index == IWL_POWER_RANGE_0)
  1640. range = &pow_data->pwr_range_0[0];
  1641. else
  1642. range = &pow_data->pwr_range_1[1];
  1643. memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
  1644. #ifdef IWL_MAC80211_DISABLE
  1645. if (priv->assoc_network != NULL) {
  1646. unsigned long flags;
  1647. period = priv->assoc_network->tim.tim_period;
  1648. }
  1649. #endif /*IWL_MAC80211_DISABLE */
  1650. skip = range[mode].no_dtim;
  1651. if (period == 0) {
  1652. period = 1;
  1653. skip = 0;
  1654. }
  1655. if (skip == 0) {
  1656. max_sleep = period;
  1657. cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1658. } else {
  1659. __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
  1660. max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
  1661. cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1662. }
  1663. for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
  1664. if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
  1665. cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
  1666. }
  1667. IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
  1668. IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
  1669. IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
  1670. IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
  1671. le32_to_cpu(cmd->sleep_interval[0]),
  1672. le32_to_cpu(cmd->sleep_interval[1]),
  1673. le32_to_cpu(cmd->sleep_interval[2]),
  1674. le32_to_cpu(cmd->sleep_interval[3]),
  1675. le32_to_cpu(cmd->sleep_interval[4]));
  1676. return rc;
  1677. }
  1678. static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
  1679. {
  1680. u32 uninitialized_var(final_mode);
  1681. int rc;
  1682. struct iwl3945_powertable_cmd cmd;
  1683. /* If on battery, set to 3,
  1684. * if plugged into AC power, set to CAM ("continuously aware mode"),
  1685. * else user level */
  1686. switch (mode) {
  1687. case IWL_POWER_BATTERY:
  1688. final_mode = IWL_POWER_INDEX_3;
  1689. break;
  1690. case IWL_POWER_AC:
  1691. final_mode = IWL_POWER_MODE_CAM;
  1692. break;
  1693. default:
  1694. final_mode = mode;
  1695. break;
  1696. }
  1697. iwl3945_update_power_cmd(priv, &cmd, final_mode);
  1698. rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
  1699. if (final_mode == IWL_POWER_MODE_CAM)
  1700. clear_bit(STATUS_POWER_PMI, &priv->status);
  1701. else
  1702. set_bit(STATUS_POWER_PMI, &priv->status);
  1703. return rc;
  1704. }
  1705. int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  1706. {
  1707. /* Filter incoming packets to determine if they are targeted toward
  1708. * this network, discarding packets coming from ourselves */
  1709. switch (priv->iw_mode) {
  1710. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  1711. /* packets from our adapter are dropped (echo) */
  1712. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  1713. return 0;
  1714. /* {broad,multi}cast packets to our IBSS go through */
  1715. if (is_multicast_ether_addr(header->addr1))
  1716. return !compare_ether_addr(header->addr3, priv->bssid);
  1717. /* packets to our adapter go through */
  1718. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1719. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  1720. /* packets from our adapter are dropped (echo) */
  1721. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  1722. return 0;
  1723. /* {broad,multi}cast packets to our BSS go through */
  1724. if (is_multicast_ether_addr(header->addr1))
  1725. return !compare_ether_addr(header->addr2, priv->bssid);
  1726. /* packets to our adapter go through */
  1727. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1728. default:
  1729. return 1;
  1730. }
  1731. return 1;
  1732. }
  1733. /**
  1734. * iwl3945_scan_cancel - Cancel any currently executing HW scan
  1735. *
  1736. * NOTE: priv->mutex is not required before calling this function
  1737. */
  1738. static int iwl3945_scan_cancel(struct iwl3945_priv *priv)
  1739. {
  1740. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1741. clear_bit(STATUS_SCANNING, &priv->status);
  1742. return 0;
  1743. }
  1744. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1745. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1746. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  1747. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  1748. queue_work(priv->workqueue, &priv->abort_scan);
  1749. } else
  1750. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  1751. return test_bit(STATUS_SCANNING, &priv->status);
  1752. }
  1753. return 0;
  1754. }
  1755. /**
  1756. * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
  1757. * @ms: amount of time to wait (in milliseconds) for scan to abort
  1758. *
  1759. * NOTE: priv->mutex must be held before calling this function
  1760. */
  1761. static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms)
  1762. {
  1763. unsigned long now = jiffies;
  1764. int ret;
  1765. ret = iwl3945_scan_cancel(priv);
  1766. if (ret && ms) {
  1767. mutex_unlock(&priv->mutex);
  1768. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  1769. test_bit(STATUS_SCANNING, &priv->status))
  1770. msleep(1);
  1771. mutex_lock(&priv->mutex);
  1772. return test_bit(STATUS_SCANNING, &priv->status);
  1773. }
  1774. return ret;
  1775. }
  1776. static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
  1777. {
  1778. /* Reset ieee stats */
  1779. /* We don't reset the net_device_stats (ieee->stats) on
  1780. * re-association */
  1781. priv->last_seq_num = -1;
  1782. priv->last_frag_num = -1;
  1783. priv->last_packet_time = 0;
  1784. iwl3945_scan_cancel(priv);
  1785. }
  1786. #define MAX_UCODE_BEACON_INTERVAL 1024
  1787. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  1788. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  1789. {
  1790. u16 new_val = 0;
  1791. u16 beacon_factor = 0;
  1792. beacon_factor =
  1793. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  1794. / MAX_UCODE_BEACON_INTERVAL;
  1795. new_val = beacon_val / beacon_factor;
  1796. return cpu_to_le16(new_val);
  1797. }
  1798. static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
  1799. {
  1800. u64 interval_tm_unit;
  1801. u64 tsf, result;
  1802. unsigned long flags;
  1803. struct ieee80211_conf *conf = NULL;
  1804. u16 beacon_int = 0;
  1805. conf = ieee80211_get_hw_conf(priv->hw);
  1806. spin_lock_irqsave(&priv->lock, flags);
  1807. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
  1808. priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
  1809. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  1810. tsf = priv->timestamp1;
  1811. tsf = ((tsf << 32) | priv->timestamp0);
  1812. beacon_int = priv->beacon_int;
  1813. spin_unlock_irqrestore(&priv->lock, flags);
  1814. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  1815. if (beacon_int == 0) {
  1816. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  1817. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  1818. } else {
  1819. priv->rxon_timing.beacon_interval =
  1820. cpu_to_le16(beacon_int);
  1821. priv->rxon_timing.beacon_interval =
  1822. iwl3945_adjust_beacon_interval(
  1823. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1824. }
  1825. priv->rxon_timing.atim_window = 0;
  1826. } else {
  1827. priv->rxon_timing.beacon_interval =
  1828. iwl3945_adjust_beacon_interval(conf->beacon_int);
  1829. /* TODO: we need to get atim_window from upper stack
  1830. * for now we set to 0 */
  1831. priv->rxon_timing.atim_window = 0;
  1832. }
  1833. interval_tm_unit =
  1834. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  1835. result = do_div(tsf, interval_tm_unit);
  1836. priv->rxon_timing.beacon_init_val =
  1837. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  1838. IWL_DEBUG_ASSOC
  1839. ("beacon interval %d beacon timer %d beacon tim %d\n",
  1840. le16_to_cpu(priv->rxon_timing.beacon_interval),
  1841. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  1842. le16_to_cpu(priv->rxon_timing.atim_window));
  1843. }
  1844. static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
  1845. {
  1846. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1847. IWL_ERROR("APs don't scan.\n");
  1848. return 0;
  1849. }
  1850. if (!iwl3945_is_ready_rf(priv)) {
  1851. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  1852. return -EIO;
  1853. }
  1854. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1855. IWL_DEBUG_SCAN("Scan already in progress.\n");
  1856. return -EAGAIN;
  1857. }
  1858. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1859. IWL_DEBUG_SCAN("Scan request while abort pending. "
  1860. "Queuing.\n");
  1861. return -EAGAIN;
  1862. }
  1863. IWL_DEBUG_INFO("Starting scan...\n");
  1864. if (priv->cfg->sku & IWL_SKU_G)
  1865. priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
  1866. if (priv->cfg->sku & IWL_SKU_A)
  1867. priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
  1868. set_bit(STATUS_SCANNING, &priv->status);
  1869. priv->scan_start = jiffies;
  1870. priv->scan_pass_start = priv->scan_start;
  1871. queue_work(priv->workqueue, &priv->request_scan);
  1872. return 0;
  1873. }
  1874. static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
  1875. {
  1876. struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon;
  1877. if (hw_decrypt)
  1878. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  1879. else
  1880. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  1881. return 0;
  1882. }
  1883. static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv,
  1884. enum ieee80211_band band)
  1885. {
  1886. if (band == IEEE80211_BAND_5GHZ) {
  1887. priv->staging_rxon.flags &=
  1888. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  1889. | RXON_FLG_CCK_MSK);
  1890. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1891. } else {
  1892. /* Copied from iwl3945_bg_post_associate() */
  1893. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1894. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1895. else
  1896. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1897. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  1898. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1899. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  1900. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  1901. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  1902. }
  1903. }
  1904. /*
  1905. * initialize rxon structure with default values from eeprom
  1906. */
  1907. static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
  1908. {
  1909. const struct iwl3945_channel_info *ch_info;
  1910. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  1911. switch (priv->iw_mode) {
  1912. case IEEE80211_IF_TYPE_AP:
  1913. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  1914. break;
  1915. case IEEE80211_IF_TYPE_STA:
  1916. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  1917. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  1918. break;
  1919. case IEEE80211_IF_TYPE_IBSS:
  1920. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  1921. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  1922. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  1923. RXON_FILTER_ACCEPT_GRP_MSK;
  1924. break;
  1925. case IEEE80211_IF_TYPE_MNTR:
  1926. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  1927. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  1928. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  1929. break;
  1930. default:
  1931. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  1932. break;
  1933. }
  1934. #if 0
  1935. /* TODO: Figure out when short_preamble would be set and cache from
  1936. * that */
  1937. if (!hw_to_local(priv->hw)->short_preamble)
  1938. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1939. else
  1940. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1941. #endif
  1942. ch_info = iwl3945_get_channel_info(priv, priv->band,
  1943. le16_to_cpu(priv->staging_rxon.channel));
  1944. if (!ch_info)
  1945. ch_info = &priv->channel_info[0];
  1946. /*
  1947. * in some case A channels are all non IBSS
  1948. * in this case force B/G channel
  1949. */
  1950. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  1951. !(is_channel_ibss(ch_info)))
  1952. ch_info = &priv->channel_info[0];
  1953. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  1954. if (is_channel_a_band(ch_info))
  1955. priv->band = IEEE80211_BAND_5GHZ;
  1956. else
  1957. priv->band = IEEE80211_BAND_2GHZ;
  1958. iwl3945_set_flags_for_phymode(priv, priv->band);
  1959. priv->staging_rxon.ofdm_basic_rates =
  1960. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1961. priv->staging_rxon.cck_basic_rates =
  1962. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1963. }
  1964. static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
  1965. {
  1966. if (mode == IEEE80211_IF_TYPE_IBSS) {
  1967. const struct iwl3945_channel_info *ch_info;
  1968. ch_info = iwl3945_get_channel_info(priv,
  1969. priv->band,
  1970. le16_to_cpu(priv->staging_rxon.channel));
  1971. if (!ch_info || !is_channel_ibss(ch_info)) {
  1972. IWL_ERROR("channel %d not IBSS channel\n",
  1973. le16_to_cpu(priv->staging_rxon.channel));
  1974. return -EINVAL;
  1975. }
  1976. }
  1977. priv->iw_mode = mode;
  1978. iwl3945_connection_init_rx_config(priv);
  1979. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1980. iwl3945_clear_stations_table(priv);
  1981. /* dont commit rxon if rf-kill is on*/
  1982. if (!iwl3945_is_ready_rf(priv))
  1983. return -EAGAIN;
  1984. cancel_delayed_work(&priv->scan_check);
  1985. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  1986. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  1987. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  1988. return -EAGAIN;
  1989. }
  1990. iwl3945_commit_rxon(priv);
  1991. return 0;
  1992. }
  1993. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
  1994. struct ieee80211_tx_control *ctl,
  1995. struct iwl3945_cmd *cmd,
  1996. struct sk_buff *skb_frag,
  1997. int last_frag)
  1998. {
  1999. struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
  2000. switch (keyinfo->alg) {
  2001. case ALG_CCMP:
  2002. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
  2003. memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
  2004. IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
  2005. break;
  2006. case ALG_TKIP:
  2007. #if 0
  2008. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
  2009. if (last_frag)
  2010. memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
  2011. 8);
  2012. else
  2013. memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
  2014. #endif
  2015. break;
  2016. case ALG_WEP:
  2017. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
  2018. (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  2019. if (keyinfo->keylen == 13)
  2020. cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
  2021. memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
  2022. IWL_DEBUG_TX("Configuring packet for WEP encryption "
  2023. "with key %d\n", ctl->key_idx);
  2024. break;
  2025. default:
  2026. printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
  2027. break;
  2028. }
  2029. }
  2030. /*
  2031. * handle build REPLY_TX command notification.
  2032. */
  2033. static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
  2034. struct iwl3945_cmd *cmd,
  2035. struct ieee80211_tx_control *ctrl,
  2036. struct ieee80211_hdr *hdr,
  2037. int is_unicast, u8 std_id)
  2038. {
  2039. __le16 *qc;
  2040. u16 fc = le16_to_cpu(hdr->frame_control);
  2041. __le32 tx_flags = cmd->cmd.tx.tx_flags;
  2042. cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2043. if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
  2044. tx_flags |= TX_CMD_FLG_ACK_MSK;
  2045. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
  2046. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2047. if (ieee80211_is_probe_response(fc) &&
  2048. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  2049. tx_flags |= TX_CMD_FLG_TSF_MSK;
  2050. } else {
  2051. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  2052. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2053. }
  2054. cmd->cmd.tx.sta_id = std_id;
  2055. if (ieee80211_get_morefrag(hdr))
  2056. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  2057. qc = ieee80211_get_qos_ctrl(hdr);
  2058. if (qc) {
  2059. cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
  2060. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  2061. } else
  2062. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2063. if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
  2064. tx_flags |= TX_CMD_FLG_RTS_MSK;
  2065. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  2066. } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  2067. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2068. tx_flags |= TX_CMD_FLG_CTS_MSK;
  2069. }
  2070. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  2071. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  2072. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  2073. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
  2074. if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
  2075. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
  2076. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
  2077. else
  2078. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
  2079. } else {
  2080. cmd->cmd.tx.timeout.pm_frame_timeout = 0;
  2081. #ifdef CONFIG_IWL3945_LEDS
  2082. priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
  2083. #endif
  2084. }
  2085. cmd->cmd.tx.driver_txop = 0;
  2086. cmd->cmd.tx.tx_flags = tx_flags;
  2087. cmd->cmd.tx.next_frame_len = 0;
  2088. }
  2089. /**
  2090. * iwl3945_get_sta_id - Find station's index within station table
  2091. */
  2092. static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr)
  2093. {
  2094. int sta_id;
  2095. u16 fc = le16_to_cpu(hdr->frame_control);
  2096. /* If this frame is broadcast or management, use broadcast station id */
  2097. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  2098. is_multicast_ether_addr(hdr->addr1))
  2099. return priv->hw_setting.bcast_sta_id;
  2100. switch (priv->iw_mode) {
  2101. /* If we are a client station in a BSS network, use the special
  2102. * AP station entry (that's the only station we communicate with) */
  2103. case IEEE80211_IF_TYPE_STA:
  2104. return IWL_AP_ID;
  2105. /* If we are an AP, then find the station, or use BCAST */
  2106. case IEEE80211_IF_TYPE_AP:
  2107. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2108. if (sta_id != IWL_INVALID_STATION)
  2109. return sta_id;
  2110. return priv->hw_setting.bcast_sta_id;
  2111. /* If this frame is going out to an IBSS network, find the station,
  2112. * or create a new station table entry */
  2113. case IEEE80211_IF_TYPE_IBSS: {
  2114. DECLARE_MAC_BUF(mac);
  2115. /* Create new station table entry */
  2116. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2117. if (sta_id != IWL_INVALID_STATION)
  2118. return sta_id;
  2119. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  2120. if (sta_id != IWL_INVALID_STATION)
  2121. return sta_id;
  2122. IWL_DEBUG_DROP("Station %s not in station map. "
  2123. "Defaulting to broadcast...\n",
  2124. print_mac(mac, hdr->addr1));
  2125. iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  2126. return priv->hw_setting.bcast_sta_id;
  2127. }
  2128. default:
  2129. IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
  2130. return priv->hw_setting.bcast_sta_id;
  2131. }
  2132. }
  2133. /*
  2134. * start REPLY_TX command process
  2135. */
  2136. static int iwl3945_tx_skb(struct iwl3945_priv *priv,
  2137. struct sk_buff *skb, struct ieee80211_tx_control *ctl)
  2138. {
  2139. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2140. struct iwl3945_tfd_frame *tfd;
  2141. u32 *control_flags;
  2142. int txq_id = ctl->queue;
  2143. struct iwl3945_tx_queue *txq = NULL;
  2144. struct iwl3945_queue *q = NULL;
  2145. dma_addr_t phys_addr;
  2146. dma_addr_t txcmd_phys;
  2147. struct iwl3945_cmd *out_cmd = NULL;
  2148. u16 len, idx, len_org;
  2149. u8 id, hdr_len, unicast;
  2150. u8 sta_id;
  2151. u16 seq_number = 0;
  2152. u16 fc;
  2153. __le16 *qc;
  2154. u8 wait_write_ptr = 0;
  2155. unsigned long flags;
  2156. int rc;
  2157. spin_lock_irqsave(&priv->lock, flags);
  2158. if (iwl3945_is_rfkill(priv)) {
  2159. IWL_DEBUG_DROP("Dropping - RF KILL\n");
  2160. goto drop_unlock;
  2161. }
  2162. if (!priv->vif) {
  2163. IWL_DEBUG_DROP("Dropping - !priv->vif\n");
  2164. goto drop_unlock;
  2165. }
  2166. if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
  2167. IWL_ERROR("ERROR: No TX rate available.\n");
  2168. goto drop_unlock;
  2169. }
  2170. unicast = !is_multicast_ether_addr(hdr->addr1);
  2171. id = 0;
  2172. fc = le16_to_cpu(hdr->frame_control);
  2173. #ifdef CONFIG_IWL3945_DEBUG
  2174. if (ieee80211_is_auth(fc))
  2175. IWL_DEBUG_TX("Sending AUTH frame\n");
  2176. else if (ieee80211_is_assoc_request(fc))
  2177. IWL_DEBUG_TX("Sending ASSOC frame\n");
  2178. else if (ieee80211_is_reassoc_request(fc))
  2179. IWL_DEBUG_TX("Sending REASSOC frame\n");
  2180. #endif
  2181. /* drop all data frame if we are not associated */
  2182. if ((!iwl3945_is_associated(priv) ||
  2183. ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id)) &&
  2184. ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
  2185. IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
  2186. goto drop_unlock;
  2187. }
  2188. spin_unlock_irqrestore(&priv->lock, flags);
  2189. hdr_len = ieee80211_get_hdrlen(fc);
  2190. /* Find (or create) index into station table for destination station */
  2191. sta_id = iwl3945_get_sta_id(priv, hdr);
  2192. if (sta_id == IWL_INVALID_STATION) {
  2193. DECLARE_MAC_BUF(mac);
  2194. IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
  2195. print_mac(mac, hdr->addr1));
  2196. goto drop;
  2197. }
  2198. IWL_DEBUG_RATE("station Id %d\n", sta_id);
  2199. qc = ieee80211_get_qos_ctrl(hdr);
  2200. if (qc) {
  2201. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2202. seq_number = priv->stations[sta_id].tid[tid].seq_number &
  2203. IEEE80211_SCTL_SEQ;
  2204. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  2205. (hdr->seq_ctrl &
  2206. __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
  2207. seq_number += 0x10;
  2208. }
  2209. /* Descriptor for chosen Tx queue */
  2210. txq = &priv->txq[txq_id];
  2211. q = &txq->q;
  2212. spin_lock_irqsave(&priv->lock, flags);
  2213. /* Set up first empty TFD within this queue's circular TFD buffer */
  2214. tfd = &txq->bd[q->write_ptr];
  2215. memset(tfd, 0, sizeof(*tfd));
  2216. control_flags = (u32 *) tfd;
  2217. idx = get_cmd_index(q, q->write_ptr, 0);
  2218. /* Set up driver data for this TFD */
  2219. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
  2220. txq->txb[q->write_ptr].skb[0] = skb;
  2221. memcpy(&(txq->txb[q->write_ptr].status.control),
  2222. ctl, sizeof(struct ieee80211_tx_control));
  2223. /* Init first empty entry in queue's array of Tx/cmd buffers */
  2224. out_cmd = &txq->cmd[idx];
  2225. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  2226. memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
  2227. /*
  2228. * Set up the Tx-command (not MAC!) header.
  2229. * Store the chosen Tx queue and TFD index within the sequence field;
  2230. * after Tx, uCode's Tx response will return this value so driver can
  2231. * locate the frame within the tx queue and do post-tx processing.
  2232. */
  2233. out_cmd->hdr.cmd = REPLY_TX;
  2234. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  2235. INDEX_TO_SEQ(q->write_ptr)));
  2236. /* Copy MAC header from skb into command buffer */
  2237. memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
  2238. /*
  2239. * Use the first empty entry in this queue's command buffer array
  2240. * to contain the Tx command and MAC header concatenated together
  2241. * (payload data will be in another buffer).
  2242. * Size of this varies, due to varying MAC header length.
  2243. * If end is not dword aligned, we'll have 2 extra bytes at the end
  2244. * of the MAC header (device reads on dword boundaries).
  2245. * We'll tell device about this padding later.
  2246. */
  2247. len = priv->hw_setting.tx_cmd_len +
  2248. sizeof(struct iwl3945_cmd_header) + hdr_len;
  2249. len_org = len;
  2250. len = (len + 3) & ~3;
  2251. if (len_org != len)
  2252. len_org = 1;
  2253. else
  2254. len_org = 0;
  2255. /* Physical address of this Tx command's header (not MAC header!),
  2256. * within command buffer array. */
  2257. txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx +
  2258. offsetof(struct iwl3945_cmd, hdr);
  2259. /* Add buffer containing Tx command and MAC(!) header to TFD's
  2260. * first entry */
  2261. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
  2262. if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
  2263. iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
  2264. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  2265. * if any (802.11 null frames have no payload). */
  2266. len = skb->len - hdr_len;
  2267. if (len) {
  2268. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  2269. len, PCI_DMA_TODEVICE);
  2270. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
  2271. }
  2272. if (!len)
  2273. /* If there is no payload, then we use only one Tx buffer */
  2274. *control_flags = TFD_CTL_COUNT_SET(1);
  2275. else
  2276. /* Else use 2 buffers.
  2277. * Tell 3945 about any padding after MAC header */
  2278. *control_flags = TFD_CTL_COUNT_SET(2) |
  2279. TFD_CTL_PAD_SET(U32_PAD(len));
  2280. /* Total # bytes to be transmitted */
  2281. len = (u16)skb->len;
  2282. out_cmd->cmd.tx.len = cpu_to_le16(len);
  2283. /* TODO need this for burst mode later on */
  2284. iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
  2285. /* set is_hcca to 0; it probably will never be implemented */
  2286. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
  2287. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  2288. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  2289. if (!ieee80211_get_morefrag(hdr)) {
  2290. txq->need_update = 1;
  2291. if (qc) {
  2292. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2293. priv->stations[sta_id].tid[tid].seq_number = seq_number;
  2294. }
  2295. } else {
  2296. wait_write_ptr = 1;
  2297. txq->need_update = 0;
  2298. }
  2299. iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
  2300. sizeof(out_cmd->cmd.tx));
  2301. iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
  2302. ieee80211_get_hdrlen(fc));
  2303. /* Tell device the write index *just past* this latest filled TFD */
  2304. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  2305. rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
  2306. spin_unlock_irqrestore(&priv->lock, flags);
  2307. if (rc)
  2308. return rc;
  2309. if ((iwl3945_queue_space(q) < q->high_mark)
  2310. && priv->mac80211_registered) {
  2311. if (wait_write_ptr) {
  2312. spin_lock_irqsave(&priv->lock, flags);
  2313. txq->need_update = 1;
  2314. iwl3945_tx_queue_update_write_ptr(priv, txq);
  2315. spin_unlock_irqrestore(&priv->lock, flags);
  2316. }
  2317. ieee80211_stop_queue(priv->hw, ctl->queue);
  2318. }
  2319. return 0;
  2320. drop_unlock:
  2321. spin_unlock_irqrestore(&priv->lock, flags);
  2322. drop:
  2323. return -1;
  2324. }
  2325. static void iwl3945_set_rate(struct iwl3945_priv *priv)
  2326. {
  2327. const struct ieee80211_supported_band *sband = NULL;
  2328. struct ieee80211_rate *rate;
  2329. int i;
  2330. sband = iwl3945_get_band(priv, priv->band);
  2331. if (!sband) {
  2332. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  2333. return;
  2334. }
  2335. priv->active_rate = 0;
  2336. priv->active_rate_basic = 0;
  2337. IWL_DEBUG_RATE("Setting rates for %s GHz\n",
  2338. sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
  2339. for (i = 0; i < sband->n_bitrates; i++) {
  2340. rate = &sband->bitrates[i];
  2341. if ((rate->hw_value < IWL_RATE_COUNT) &&
  2342. !(rate->flags & IEEE80211_CHAN_DISABLED)) {
  2343. IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
  2344. rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
  2345. priv->active_rate |= (1 << rate->hw_value);
  2346. }
  2347. }
  2348. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  2349. priv->active_rate, priv->active_rate_basic);
  2350. /*
  2351. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  2352. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  2353. * OFDM
  2354. */
  2355. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  2356. priv->staging_rxon.cck_basic_rates =
  2357. ((priv->active_rate_basic &
  2358. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  2359. else
  2360. priv->staging_rxon.cck_basic_rates =
  2361. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  2362. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  2363. priv->staging_rxon.ofdm_basic_rates =
  2364. ((priv->active_rate_basic &
  2365. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  2366. IWL_FIRST_OFDM_RATE) & 0xFF;
  2367. else
  2368. priv->staging_rxon.ofdm_basic_rates =
  2369. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  2370. }
  2371. static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
  2372. {
  2373. unsigned long flags;
  2374. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  2375. return;
  2376. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  2377. disable_radio ? "OFF" : "ON");
  2378. if (disable_radio) {
  2379. iwl3945_scan_cancel(priv);
  2380. /* FIXME: This is a workaround for AP */
  2381. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  2382. spin_lock_irqsave(&priv->lock, flags);
  2383. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2384. CSR_UCODE_SW_BIT_RFKILL);
  2385. spin_unlock_irqrestore(&priv->lock, flags);
  2386. iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  2387. set_bit(STATUS_RF_KILL_SW, &priv->status);
  2388. }
  2389. return;
  2390. }
  2391. spin_lock_irqsave(&priv->lock, flags);
  2392. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2393. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  2394. spin_unlock_irqrestore(&priv->lock, flags);
  2395. /* wake up ucode */
  2396. msleep(10);
  2397. spin_lock_irqsave(&priv->lock, flags);
  2398. iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  2399. if (!iwl3945_grab_nic_access(priv))
  2400. iwl3945_release_nic_access(priv);
  2401. spin_unlock_irqrestore(&priv->lock, flags);
  2402. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  2403. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2404. "disabled by HW switch\n");
  2405. return;
  2406. }
  2407. queue_work(priv->workqueue, &priv->restart);
  2408. return;
  2409. }
  2410. void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
  2411. u32 decrypt_res, struct ieee80211_rx_status *stats)
  2412. {
  2413. u16 fc =
  2414. le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
  2415. if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
  2416. return;
  2417. if (!(fc & IEEE80211_FCTL_PROTECTED))
  2418. return;
  2419. IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
  2420. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  2421. case RX_RES_STATUS_SEC_TYPE_TKIP:
  2422. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2423. RX_RES_STATUS_BAD_ICV_MIC)
  2424. stats->flag |= RX_FLAG_MMIC_ERROR;
  2425. case RX_RES_STATUS_SEC_TYPE_WEP:
  2426. case RX_RES_STATUS_SEC_TYPE_CCMP:
  2427. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2428. RX_RES_STATUS_DECRYPT_OK) {
  2429. IWL_DEBUG_RX("hw decrypt successfully!!!\n");
  2430. stats->flag |= RX_FLAG_DECRYPTED;
  2431. }
  2432. break;
  2433. default:
  2434. break;
  2435. }
  2436. }
  2437. #define IWL_PACKET_RETRY_TIME HZ
  2438. int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  2439. {
  2440. u16 sc = le16_to_cpu(header->seq_ctrl);
  2441. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  2442. u16 frag = sc & IEEE80211_SCTL_FRAG;
  2443. u16 *last_seq, *last_frag;
  2444. unsigned long *last_time;
  2445. switch (priv->iw_mode) {
  2446. case IEEE80211_IF_TYPE_IBSS:{
  2447. struct list_head *p;
  2448. struct iwl3945_ibss_seq *entry = NULL;
  2449. u8 *mac = header->addr2;
  2450. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  2451. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  2452. entry = list_entry(p, struct iwl3945_ibss_seq, list);
  2453. if (!compare_ether_addr(entry->mac, mac))
  2454. break;
  2455. }
  2456. if (p == &priv->ibss_mac_hash[index]) {
  2457. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  2458. if (!entry) {
  2459. IWL_ERROR("Cannot malloc new mac entry\n");
  2460. return 0;
  2461. }
  2462. memcpy(entry->mac, mac, ETH_ALEN);
  2463. entry->seq_num = seq;
  2464. entry->frag_num = frag;
  2465. entry->packet_time = jiffies;
  2466. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  2467. return 0;
  2468. }
  2469. last_seq = &entry->seq_num;
  2470. last_frag = &entry->frag_num;
  2471. last_time = &entry->packet_time;
  2472. break;
  2473. }
  2474. case IEEE80211_IF_TYPE_STA:
  2475. last_seq = &priv->last_seq_num;
  2476. last_frag = &priv->last_frag_num;
  2477. last_time = &priv->last_packet_time;
  2478. break;
  2479. default:
  2480. return 0;
  2481. }
  2482. if ((*last_seq == seq) &&
  2483. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  2484. if (*last_frag == frag)
  2485. goto drop;
  2486. if (*last_frag + 1 != frag)
  2487. /* out-of-order fragment */
  2488. goto drop;
  2489. } else
  2490. *last_seq = seq;
  2491. *last_frag = frag;
  2492. *last_time = jiffies;
  2493. return 0;
  2494. drop:
  2495. return 1;
  2496. }
  2497. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  2498. #include "iwl-spectrum.h"
  2499. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  2500. #define BEACON_TIME_MASK_HIGH 0xFF000000
  2501. #define TIME_UNIT 1024
  2502. /*
  2503. * extended beacon time format
  2504. * time in usec will be changed into a 32-bit value in 8:24 format
  2505. * the high 1 byte is the beacon counts
  2506. * the lower 3 bytes is the time in usec within one beacon interval
  2507. */
  2508. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  2509. {
  2510. u32 quot;
  2511. u32 rem;
  2512. u32 interval = beacon_interval * 1024;
  2513. if (!interval || !usec)
  2514. return 0;
  2515. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  2516. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  2517. return (quot << 24) + rem;
  2518. }
  2519. /* base is usually what we get from ucode with each received frame,
  2520. * the same as HW timer counter counting down
  2521. */
  2522. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  2523. {
  2524. u32 base_low = base & BEACON_TIME_MASK_LOW;
  2525. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  2526. u32 interval = beacon_interval * TIME_UNIT;
  2527. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  2528. (addon & BEACON_TIME_MASK_HIGH);
  2529. if (base_low > addon_low)
  2530. res += base_low - addon_low;
  2531. else if (base_low < addon_low) {
  2532. res += interval + base_low - addon_low;
  2533. res += (1 << 24);
  2534. } else
  2535. res += (1 << 24);
  2536. return cpu_to_le32(res);
  2537. }
  2538. static int iwl3945_get_measurement(struct iwl3945_priv *priv,
  2539. struct ieee80211_measurement_params *params,
  2540. u8 type)
  2541. {
  2542. struct iwl3945_spectrum_cmd spectrum;
  2543. struct iwl3945_rx_packet *res;
  2544. struct iwl3945_host_cmd cmd = {
  2545. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  2546. .data = (void *)&spectrum,
  2547. .meta.flags = CMD_WANT_SKB,
  2548. };
  2549. u32 add_time = le64_to_cpu(params->start_time);
  2550. int rc;
  2551. int spectrum_resp_status;
  2552. int duration = le16_to_cpu(params->duration);
  2553. if (iwl3945_is_associated(priv))
  2554. add_time =
  2555. iwl3945_usecs_to_beacons(
  2556. le64_to_cpu(params->start_time) - priv->last_tsf,
  2557. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2558. memset(&spectrum, 0, sizeof(spectrum));
  2559. spectrum.channel_count = cpu_to_le16(1);
  2560. spectrum.flags =
  2561. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  2562. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  2563. cmd.len = sizeof(spectrum);
  2564. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  2565. if (iwl3945_is_associated(priv))
  2566. spectrum.start_time =
  2567. iwl3945_add_beacon_time(priv->last_beacon_time,
  2568. add_time,
  2569. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2570. else
  2571. spectrum.start_time = 0;
  2572. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  2573. spectrum.channels[0].channel = params->channel;
  2574. spectrum.channels[0].type = type;
  2575. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  2576. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  2577. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  2578. rc = iwl3945_send_cmd_sync(priv, &cmd);
  2579. if (rc)
  2580. return rc;
  2581. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  2582. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  2583. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  2584. rc = -EIO;
  2585. }
  2586. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  2587. switch (spectrum_resp_status) {
  2588. case 0: /* Command will be handled */
  2589. if (res->u.spectrum.id != 0xff) {
  2590. IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
  2591. res->u.spectrum.id);
  2592. priv->measurement_status &= ~MEASUREMENT_READY;
  2593. }
  2594. priv->measurement_status |= MEASUREMENT_ACTIVE;
  2595. rc = 0;
  2596. break;
  2597. case 1: /* Command will not be handled */
  2598. rc = -EAGAIN;
  2599. break;
  2600. }
  2601. dev_kfree_skb_any(cmd.meta.u.skb);
  2602. return rc;
  2603. }
  2604. #endif
  2605. static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv,
  2606. struct iwl3945_rx_mem_buffer *rxb)
  2607. {
  2608. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2609. struct iwl3945_alive_resp *palive;
  2610. struct delayed_work *pwork;
  2611. palive = &pkt->u.alive_frame;
  2612. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  2613. "0x%01X 0x%01X\n",
  2614. palive->is_valid, palive->ver_type,
  2615. palive->ver_subtype);
  2616. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  2617. IWL_DEBUG_INFO("Initialization Alive received.\n");
  2618. memcpy(&priv->card_alive_init,
  2619. &pkt->u.alive_frame,
  2620. sizeof(struct iwl3945_init_alive_resp));
  2621. pwork = &priv->init_alive_start;
  2622. } else {
  2623. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2624. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  2625. sizeof(struct iwl3945_alive_resp));
  2626. pwork = &priv->alive_start;
  2627. iwl3945_disable_events(priv);
  2628. }
  2629. /* We delay the ALIVE response by 5ms to
  2630. * give the HW RF Kill time to activate... */
  2631. if (palive->is_valid == UCODE_VALID_OK)
  2632. queue_delayed_work(priv->workqueue, pwork,
  2633. msecs_to_jiffies(5));
  2634. else
  2635. IWL_WARNING("uCode did not respond OK.\n");
  2636. }
  2637. static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv,
  2638. struct iwl3945_rx_mem_buffer *rxb)
  2639. {
  2640. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2641. IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  2642. return;
  2643. }
  2644. static void iwl3945_rx_reply_error(struct iwl3945_priv *priv,
  2645. struct iwl3945_rx_mem_buffer *rxb)
  2646. {
  2647. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2648. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  2649. "seq 0x%04X ser 0x%08X\n",
  2650. le32_to_cpu(pkt->u.err_resp.error_type),
  2651. get_cmd_string(pkt->u.err_resp.cmd_id),
  2652. pkt->u.err_resp.cmd_id,
  2653. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  2654. le32_to_cpu(pkt->u.err_resp.error_info));
  2655. }
  2656. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  2657. static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
  2658. {
  2659. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2660. struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon;
  2661. struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif);
  2662. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  2663. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  2664. rxon->channel = csa->channel;
  2665. priv->staging_rxon.channel = csa->channel;
  2666. }
  2667. static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv,
  2668. struct iwl3945_rx_mem_buffer *rxb)
  2669. {
  2670. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  2671. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2672. struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif);
  2673. if (!report->state) {
  2674. IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
  2675. "Spectrum Measure Notification: Start\n");
  2676. return;
  2677. }
  2678. memcpy(&priv->measure_report, report, sizeof(*report));
  2679. priv->measurement_status |= MEASUREMENT_READY;
  2680. #endif
  2681. }
  2682. static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv,
  2683. struct iwl3945_rx_mem_buffer *rxb)
  2684. {
  2685. #ifdef CONFIG_IWL3945_DEBUG
  2686. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2687. struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif);
  2688. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  2689. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  2690. #endif
  2691. }
  2692. static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv,
  2693. struct iwl3945_rx_mem_buffer *rxb)
  2694. {
  2695. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2696. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  2697. "notification for %s:\n",
  2698. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  2699. iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  2700. }
  2701. static void iwl3945_bg_beacon_update(struct work_struct *work)
  2702. {
  2703. struct iwl3945_priv *priv =
  2704. container_of(work, struct iwl3945_priv, beacon_update);
  2705. struct sk_buff *beacon;
  2706. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  2707. beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
  2708. if (!beacon) {
  2709. IWL_ERROR("update beacon failed\n");
  2710. return;
  2711. }
  2712. mutex_lock(&priv->mutex);
  2713. /* new beacon skb is allocated every time; dispose previous.*/
  2714. if (priv->ibss_beacon)
  2715. dev_kfree_skb(priv->ibss_beacon);
  2716. priv->ibss_beacon = beacon;
  2717. mutex_unlock(&priv->mutex);
  2718. iwl3945_send_beacon_cmd(priv);
  2719. }
  2720. static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
  2721. struct iwl3945_rx_mem_buffer *rxb)
  2722. {
  2723. #ifdef CONFIG_IWL3945_DEBUG
  2724. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2725. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  2726. u8 rate = beacon->beacon_notify_hdr.rate;
  2727. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  2728. "tsf %d %d rate %d\n",
  2729. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  2730. beacon->beacon_notify_hdr.failure_frame,
  2731. le32_to_cpu(beacon->ibss_mgr_status),
  2732. le32_to_cpu(beacon->high_tsf),
  2733. le32_to_cpu(beacon->low_tsf), rate);
  2734. #endif
  2735. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  2736. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  2737. queue_work(priv->workqueue, &priv->beacon_update);
  2738. }
  2739. /* Service response to REPLY_SCAN_CMD (0x80) */
  2740. static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv,
  2741. struct iwl3945_rx_mem_buffer *rxb)
  2742. {
  2743. #ifdef CONFIG_IWL3945_DEBUG
  2744. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2745. struct iwl3945_scanreq_notification *notif =
  2746. (struct iwl3945_scanreq_notification *)pkt->u.raw;
  2747. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  2748. #endif
  2749. }
  2750. /* Service SCAN_START_NOTIFICATION (0x82) */
  2751. static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv,
  2752. struct iwl3945_rx_mem_buffer *rxb)
  2753. {
  2754. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2755. struct iwl3945_scanstart_notification *notif =
  2756. (struct iwl3945_scanstart_notification *)pkt->u.raw;
  2757. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  2758. IWL_DEBUG_SCAN("Scan start: "
  2759. "%d [802.11%s] "
  2760. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  2761. notif->channel,
  2762. notif->band ? "bg" : "a",
  2763. notif->tsf_high,
  2764. notif->tsf_low, notif->status, notif->beacon_timer);
  2765. }
  2766. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  2767. static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv,
  2768. struct iwl3945_rx_mem_buffer *rxb)
  2769. {
  2770. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2771. struct iwl3945_scanresults_notification *notif =
  2772. (struct iwl3945_scanresults_notification *)pkt->u.raw;
  2773. IWL_DEBUG_SCAN("Scan ch.res: "
  2774. "%d [802.11%s] "
  2775. "(TSF: 0x%08X:%08X) - %d "
  2776. "elapsed=%lu usec (%dms since last)\n",
  2777. notif->channel,
  2778. notif->band ? "bg" : "a",
  2779. le32_to_cpu(notif->tsf_high),
  2780. le32_to_cpu(notif->tsf_low),
  2781. le32_to_cpu(notif->statistics[0]),
  2782. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  2783. jiffies_to_msecs(elapsed_jiffies
  2784. (priv->last_scan_jiffies, jiffies)));
  2785. priv->last_scan_jiffies = jiffies;
  2786. priv->next_scan_jiffies = 0;
  2787. }
  2788. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  2789. static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
  2790. struct iwl3945_rx_mem_buffer *rxb)
  2791. {
  2792. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2793. struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  2794. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  2795. scan_notif->scanned_channels,
  2796. scan_notif->tsf_low,
  2797. scan_notif->tsf_high, scan_notif->status);
  2798. /* The HW is no longer scanning */
  2799. clear_bit(STATUS_SCAN_HW, &priv->status);
  2800. /* The scan completion notification came in, so kill that timer... */
  2801. cancel_delayed_work(&priv->scan_check);
  2802. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  2803. (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
  2804. "2.4" : "5.2",
  2805. jiffies_to_msecs(elapsed_jiffies
  2806. (priv->scan_pass_start, jiffies)));
  2807. /* Remove this scanned band from the list of pending
  2808. * bands to scan, band G precedes A in order of scanning
  2809. * as seen in iwl3945_bg_request_scan */
  2810. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
  2811. priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
  2812. else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
  2813. priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
  2814. /* If a request to abort was given, or the scan did not succeed
  2815. * then we reset the scan state machine and terminate,
  2816. * re-queuing another scan if one has been requested */
  2817. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2818. IWL_DEBUG_INFO("Aborted scan completed.\n");
  2819. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  2820. } else {
  2821. /* If there are more bands on this scan pass reschedule */
  2822. if (priv->scan_bands > 0)
  2823. goto reschedule;
  2824. }
  2825. priv->last_scan_jiffies = jiffies;
  2826. priv->next_scan_jiffies = 0;
  2827. IWL_DEBUG_INFO("Setting scan to off\n");
  2828. clear_bit(STATUS_SCANNING, &priv->status);
  2829. IWL_DEBUG_INFO("Scan took %dms\n",
  2830. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  2831. queue_work(priv->workqueue, &priv->scan_completed);
  2832. return;
  2833. reschedule:
  2834. priv->scan_pass_start = jiffies;
  2835. queue_work(priv->workqueue, &priv->request_scan);
  2836. }
  2837. /* Handle notification from uCode that card's power state is changing
  2838. * due to software, hardware, or critical temperature RFKILL */
  2839. static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv,
  2840. struct iwl3945_rx_mem_buffer *rxb)
  2841. {
  2842. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2843. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  2844. unsigned long status = priv->status;
  2845. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  2846. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  2847. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  2848. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2849. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2850. if (flags & HW_CARD_DISABLED)
  2851. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2852. else
  2853. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2854. if (flags & SW_CARD_DISABLED)
  2855. set_bit(STATUS_RF_KILL_SW, &priv->status);
  2856. else
  2857. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  2858. iwl3945_scan_cancel(priv);
  2859. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  2860. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  2861. (test_bit(STATUS_RF_KILL_SW, &status) !=
  2862. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  2863. queue_work(priv->workqueue, &priv->rf_kill);
  2864. else
  2865. wake_up_interruptible(&priv->wait_command_queue);
  2866. }
  2867. /**
  2868. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  2869. *
  2870. * Setup the RX handlers for each of the reply types sent from the uCode
  2871. * to the host.
  2872. *
  2873. * This function chains into the hardware specific files for them to setup
  2874. * any hardware specific handlers as well.
  2875. */
  2876. static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv)
  2877. {
  2878. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  2879. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  2880. priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
  2881. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
  2882. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  2883. iwl3945_rx_spectrum_measure_notif;
  2884. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
  2885. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  2886. iwl3945_rx_pm_debug_statistics_notif;
  2887. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  2888. /*
  2889. * The same handler is used for both the REPLY to a discrete
  2890. * statistics request from the host as well as for the periodic
  2891. * statistics notifications (after received beacons) from the uCode.
  2892. */
  2893. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  2894. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  2895. priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
  2896. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
  2897. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  2898. iwl3945_rx_scan_results_notif;
  2899. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  2900. iwl3945_rx_scan_complete_notif;
  2901. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  2902. /* Set up hardware specific Rx handlers */
  2903. iwl3945_hw_rx_handler_setup(priv);
  2904. }
  2905. /**
  2906. * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
  2907. * When FW advances 'R' index, all entries between old and new 'R' index
  2908. * need to be reclaimed.
  2909. */
  2910. static void iwl3945_cmd_queue_reclaim(struct iwl3945_priv *priv,
  2911. int txq_id, int index)
  2912. {
  2913. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  2914. struct iwl3945_queue *q = &txq->q;
  2915. int nfreed = 0;
  2916. if ((index >= q->n_bd) || (iwl3945_x2_queue_used(q, index) == 0)) {
  2917. IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
  2918. "is out of range [0-%d] %d %d.\n", txq_id,
  2919. index, q->n_bd, q->write_ptr, q->read_ptr);
  2920. return;
  2921. }
  2922. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  2923. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2924. if (nfreed > 1) {
  2925. IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
  2926. q->write_ptr, q->read_ptr);
  2927. queue_work(priv->workqueue, &priv->restart);
  2928. break;
  2929. }
  2930. nfreed++;
  2931. }
  2932. }
  2933. /**
  2934. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  2935. * @rxb: Rx buffer to reclaim
  2936. *
  2937. * If an Rx buffer has an async callback associated with it the callback
  2938. * will be executed. The attached skb (if present) will only be freed
  2939. * if the callback returns 1
  2940. */
  2941. static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv,
  2942. struct iwl3945_rx_mem_buffer *rxb)
  2943. {
  2944. struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  2945. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  2946. int txq_id = SEQ_TO_QUEUE(sequence);
  2947. int index = SEQ_TO_INDEX(sequence);
  2948. int huge = sequence & SEQ_HUGE_FRAME;
  2949. int cmd_index;
  2950. struct iwl3945_cmd *cmd;
  2951. BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
  2952. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  2953. cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  2954. /* Input error checking is done when commands are added to queue. */
  2955. if (cmd->meta.flags & CMD_WANT_SKB) {
  2956. cmd->meta.source->u.skb = rxb->skb;
  2957. rxb->skb = NULL;
  2958. } else if (cmd->meta.u.callback &&
  2959. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  2960. rxb->skb = NULL;
  2961. iwl3945_cmd_queue_reclaim(priv, txq_id, index);
  2962. if (!(cmd->meta.flags & CMD_ASYNC)) {
  2963. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  2964. wake_up_interruptible(&priv->wait_command_queue);
  2965. }
  2966. }
  2967. /************************** RX-FUNCTIONS ****************************/
  2968. /*
  2969. * Rx theory of operation
  2970. *
  2971. * The host allocates 32 DMA target addresses and passes the host address
  2972. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  2973. * 0 to 31
  2974. *
  2975. * Rx Queue Indexes
  2976. * The host/firmware share two index registers for managing the Rx buffers.
  2977. *
  2978. * The READ index maps to the first position that the firmware may be writing
  2979. * to -- the driver can read up to (but not including) this position and get
  2980. * good data.
  2981. * The READ index is managed by the firmware once the card is enabled.
  2982. *
  2983. * The WRITE index maps to the last position the driver has read from -- the
  2984. * position preceding WRITE is the last slot the firmware can place a packet.
  2985. *
  2986. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  2987. * WRITE = READ.
  2988. *
  2989. * During initialization, the host sets up the READ queue position to the first
  2990. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  2991. *
  2992. * When the firmware places a packet in a buffer, it will advance the READ index
  2993. * and fire the RX interrupt. The driver can then query the READ index and
  2994. * process as many packets as possible, moving the WRITE index forward as it
  2995. * resets the Rx queue buffers with new memory.
  2996. *
  2997. * The management in the driver is as follows:
  2998. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  2999. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  3000. * to replenish the iwl->rxq->rx_free.
  3001. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  3002. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  3003. * 'processed' and 'read' driver indexes as well)
  3004. * + A received packet is processed and handed to the kernel network stack,
  3005. * detached from the iwl->rxq. The driver 'processed' index is updated.
  3006. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  3007. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  3008. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  3009. * were enough free buffers and RX_STALLED is set it is cleared.
  3010. *
  3011. *
  3012. * Driver sequence:
  3013. *
  3014. * iwl3945_rx_queue_alloc() Allocates rx_free
  3015. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  3016. * iwl3945_rx_queue_restock
  3017. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  3018. * queue, updates firmware pointers, and updates
  3019. * the WRITE index. If insufficient rx_free buffers
  3020. * are available, schedules iwl3945_rx_replenish
  3021. *
  3022. * -- enable interrupts --
  3023. * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
  3024. * READ INDEX, detaching the SKB from the pool.
  3025. * Moves the packet buffer from queue to rx_used.
  3026. * Calls iwl3945_rx_queue_restock to refill any empty
  3027. * slots.
  3028. * ...
  3029. *
  3030. */
  3031. /**
  3032. * iwl3945_rx_queue_space - Return number of free slots available in queue.
  3033. */
  3034. static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q)
  3035. {
  3036. int s = q->read - q->write;
  3037. if (s <= 0)
  3038. s += RX_QUEUE_SIZE;
  3039. /* keep some buffer to not confuse full and empty queue */
  3040. s -= 2;
  3041. if (s < 0)
  3042. s = 0;
  3043. return s;
  3044. }
  3045. /**
  3046. * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  3047. */
  3048. int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q)
  3049. {
  3050. u32 reg = 0;
  3051. int rc = 0;
  3052. unsigned long flags;
  3053. spin_lock_irqsave(&q->lock, flags);
  3054. if (q->need_update == 0)
  3055. goto exit_unlock;
  3056. /* If power-saving is in use, make sure device is awake */
  3057. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3058. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3059. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3060. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3061. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3062. goto exit_unlock;
  3063. }
  3064. rc = iwl3945_grab_nic_access(priv);
  3065. if (rc)
  3066. goto exit_unlock;
  3067. /* Device expects a multiple of 8 */
  3068. iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
  3069. q->write & ~0x7);
  3070. iwl3945_release_nic_access(priv);
  3071. /* Else device is assumed to be awake */
  3072. } else
  3073. /* Device expects a multiple of 8 */
  3074. iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
  3075. q->need_update = 0;
  3076. exit_unlock:
  3077. spin_unlock_irqrestore(&q->lock, flags);
  3078. return rc;
  3079. }
  3080. /**
  3081. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  3082. */
  3083. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv,
  3084. dma_addr_t dma_addr)
  3085. {
  3086. return cpu_to_le32((u32)dma_addr);
  3087. }
  3088. /**
  3089. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  3090. *
  3091. * If there are slots in the RX queue that need to be restocked,
  3092. * and we have free pre-allocated buffers, fill the ranks as much
  3093. * as we can, pulling from rx_free.
  3094. *
  3095. * This moves the 'write' index forward to catch up with 'processed', and
  3096. * also updates the memory address in the firmware to reference the new
  3097. * target buffer.
  3098. */
  3099. static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv)
  3100. {
  3101. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3102. struct list_head *element;
  3103. struct iwl3945_rx_mem_buffer *rxb;
  3104. unsigned long flags;
  3105. int write, rc;
  3106. spin_lock_irqsave(&rxq->lock, flags);
  3107. write = rxq->write & ~0x7;
  3108. while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  3109. /* Get next free Rx buffer, remove from free list */
  3110. element = rxq->rx_free.next;
  3111. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3112. list_del(element);
  3113. /* Point to Rx buffer via next RBD in circular buffer */
  3114. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr);
  3115. rxq->queue[rxq->write] = rxb;
  3116. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  3117. rxq->free_count--;
  3118. }
  3119. spin_unlock_irqrestore(&rxq->lock, flags);
  3120. /* If the pre-allocated buffer pool is dropping low, schedule to
  3121. * refill it */
  3122. if (rxq->free_count <= RX_LOW_WATERMARK)
  3123. queue_work(priv->workqueue, &priv->rx_replenish);
  3124. /* If we've added more space for the firmware to place data, tell it.
  3125. * Increment device's write pointer in multiples of 8. */
  3126. if ((write != (rxq->write & ~0x7))
  3127. || (abs(rxq->write - rxq->read) > 7)) {
  3128. spin_lock_irqsave(&rxq->lock, flags);
  3129. rxq->need_update = 1;
  3130. spin_unlock_irqrestore(&rxq->lock, flags);
  3131. rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
  3132. if (rc)
  3133. return rc;
  3134. }
  3135. return 0;
  3136. }
  3137. /**
  3138. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  3139. *
  3140. * When moving to rx_free an SKB is allocated for the slot.
  3141. *
  3142. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  3143. * This is called as a scheduled work item (except for during initialization)
  3144. */
  3145. static void iwl3945_rx_allocate(struct iwl3945_priv *priv)
  3146. {
  3147. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3148. struct list_head *element;
  3149. struct iwl3945_rx_mem_buffer *rxb;
  3150. unsigned long flags;
  3151. spin_lock_irqsave(&rxq->lock, flags);
  3152. while (!list_empty(&rxq->rx_used)) {
  3153. element = rxq->rx_used.next;
  3154. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3155. /* Alloc a new receive buffer */
  3156. rxb->skb =
  3157. alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
  3158. if (!rxb->skb) {
  3159. if (net_ratelimit())
  3160. printk(KERN_CRIT DRV_NAME
  3161. ": Can not allocate SKB buffers\n");
  3162. /* We don't reschedule replenish work here -- we will
  3163. * call the restock method and if it still needs
  3164. * more buffers it will schedule replenish */
  3165. break;
  3166. }
  3167. /* If radiotap head is required, reserve some headroom here.
  3168. * The physical head count is a variable rx_stats->phy_count.
  3169. * We reserve 4 bytes here. Plus these extra bytes, the
  3170. * headroom of the physical head should be enough for the
  3171. * radiotap head that iwl3945 supported. See iwl3945_rt.
  3172. */
  3173. skb_reserve(rxb->skb, 4);
  3174. priv->alloc_rxb_skb++;
  3175. list_del(element);
  3176. /* Get physical address of RB/SKB */
  3177. rxb->dma_addr =
  3178. pci_map_single(priv->pci_dev, rxb->skb->data,
  3179. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3180. list_add_tail(&rxb->list, &rxq->rx_free);
  3181. rxq->free_count++;
  3182. }
  3183. spin_unlock_irqrestore(&rxq->lock, flags);
  3184. }
  3185. /*
  3186. * this should be called while priv->lock is locked
  3187. */
  3188. static void __iwl3945_rx_replenish(void *data)
  3189. {
  3190. struct iwl3945_priv *priv = data;
  3191. iwl3945_rx_allocate(priv);
  3192. iwl3945_rx_queue_restock(priv);
  3193. }
  3194. void iwl3945_rx_replenish(void *data)
  3195. {
  3196. struct iwl3945_priv *priv = data;
  3197. unsigned long flags;
  3198. iwl3945_rx_allocate(priv);
  3199. spin_lock_irqsave(&priv->lock, flags);
  3200. iwl3945_rx_queue_restock(priv);
  3201. spin_unlock_irqrestore(&priv->lock, flags);
  3202. }
  3203. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  3204. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  3205. * This free routine walks the list of POOL entries and if SKB is set to
  3206. * non NULL it is unmapped and freed
  3207. */
  3208. static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3209. {
  3210. int i;
  3211. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  3212. if (rxq->pool[i].skb != NULL) {
  3213. pci_unmap_single(priv->pci_dev,
  3214. rxq->pool[i].dma_addr,
  3215. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3216. dev_kfree_skb(rxq->pool[i].skb);
  3217. }
  3218. }
  3219. pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  3220. rxq->dma_addr);
  3221. rxq->bd = NULL;
  3222. }
  3223. int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv)
  3224. {
  3225. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3226. struct pci_dev *dev = priv->pci_dev;
  3227. int i;
  3228. spin_lock_init(&rxq->lock);
  3229. INIT_LIST_HEAD(&rxq->rx_free);
  3230. INIT_LIST_HEAD(&rxq->rx_used);
  3231. /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
  3232. rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
  3233. if (!rxq->bd)
  3234. return -ENOMEM;
  3235. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3236. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  3237. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3238. /* Set us so that we have processed and used all buffers, but have
  3239. * not restocked the Rx queue with fresh buffers */
  3240. rxq->read = rxq->write = 0;
  3241. rxq->free_count = 0;
  3242. rxq->need_update = 0;
  3243. return 0;
  3244. }
  3245. void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3246. {
  3247. unsigned long flags;
  3248. int i;
  3249. spin_lock_irqsave(&rxq->lock, flags);
  3250. INIT_LIST_HEAD(&rxq->rx_free);
  3251. INIT_LIST_HEAD(&rxq->rx_used);
  3252. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3253. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  3254. /* In the reset function, these buffers may have been allocated
  3255. * to an SKB, so we need to unmap and free potential storage */
  3256. if (rxq->pool[i].skb != NULL) {
  3257. pci_unmap_single(priv->pci_dev,
  3258. rxq->pool[i].dma_addr,
  3259. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3260. priv->alloc_rxb_skb--;
  3261. dev_kfree_skb(rxq->pool[i].skb);
  3262. rxq->pool[i].skb = NULL;
  3263. }
  3264. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3265. }
  3266. /* Set us so that we have processed and used all buffers, but have
  3267. * not restocked the Rx queue with fresh buffers */
  3268. rxq->read = rxq->write = 0;
  3269. rxq->free_count = 0;
  3270. spin_unlock_irqrestore(&rxq->lock, flags);
  3271. }
  3272. /* Convert linear signal-to-noise ratio into dB */
  3273. static u8 ratio2dB[100] = {
  3274. /* 0 1 2 3 4 5 6 7 8 9 */
  3275. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  3276. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  3277. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  3278. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  3279. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  3280. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  3281. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  3282. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  3283. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  3284. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  3285. };
  3286. /* Calculates a relative dB value from a ratio of linear
  3287. * (i.e. not dB) signal levels.
  3288. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  3289. int iwl3945_calc_db_from_ratio(int sig_ratio)
  3290. {
  3291. /* 1000:1 or higher just report as 60 dB */
  3292. if (sig_ratio >= 1000)
  3293. return 60;
  3294. /* 100:1 or higher, divide by 10 and use table,
  3295. * add 20 dB to make up for divide by 10 */
  3296. if (sig_ratio >= 100)
  3297. return (20 + (int)ratio2dB[sig_ratio/10]);
  3298. /* We shouldn't see this */
  3299. if (sig_ratio < 1)
  3300. return 0;
  3301. /* Use table for ratios 1:1 - 99:1 */
  3302. return (int)ratio2dB[sig_ratio];
  3303. }
  3304. #define PERFECT_RSSI (-20) /* dBm */
  3305. #define WORST_RSSI (-95) /* dBm */
  3306. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  3307. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  3308. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  3309. * about formulas used below. */
  3310. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  3311. {
  3312. int sig_qual;
  3313. int degradation = PERFECT_RSSI - rssi_dbm;
  3314. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  3315. * as indicator; formula is (signal dbm - noise dbm).
  3316. * SNR at or above 40 is a great signal (100%).
  3317. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  3318. * Weakest usable signal is usually 10 - 15 dB SNR. */
  3319. if (noise_dbm) {
  3320. if (rssi_dbm - noise_dbm >= 40)
  3321. return 100;
  3322. else if (rssi_dbm < noise_dbm)
  3323. return 0;
  3324. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  3325. /* Else use just the signal level.
  3326. * This formula is a least squares fit of data points collected and
  3327. * compared with a reference system that had a percentage (%) display
  3328. * for signal quality. */
  3329. } else
  3330. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  3331. (15 * RSSI_RANGE + 62 * degradation)) /
  3332. (RSSI_RANGE * RSSI_RANGE);
  3333. if (sig_qual > 100)
  3334. sig_qual = 100;
  3335. else if (sig_qual < 1)
  3336. sig_qual = 0;
  3337. return sig_qual;
  3338. }
  3339. /**
  3340. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  3341. *
  3342. * Uses the priv->rx_handlers callback function array to invoke
  3343. * the appropriate handlers, including command responses,
  3344. * frame-received notifications, and other notifications.
  3345. */
  3346. static void iwl3945_rx_handle(struct iwl3945_priv *priv)
  3347. {
  3348. struct iwl3945_rx_mem_buffer *rxb;
  3349. struct iwl3945_rx_packet *pkt;
  3350. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3351. u32 r, i;
  3352. int reclaim;
  3353. unsigned long flags;
  3354. u8 fill_rx = 0;
  3355. u32 count = 8;
  3356. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  3357. * buffer that the driver may process (last buffer filled by ucode). */
  3358. r = iwl3945_hw_get_rx_read(priv);
  3359. i = rxq->read;
  3360. if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  3361. fill_rx = 1;
  3362. /* Rx interrupt, but nothing sent from uCode */
  3363. if (i == r)
  3364. IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  3365. while (i != r) {
  3366. rxb = rxq->queue[i];
  3367. /* If an RXB doesn't have a Rx queue slot associated with it,
  3368. * then a bug has been introduced in the queue refilling
  3369. * routines -- catch it here */
  3370. BUG_ON(rxb == NULL);
  3371. rxq->queue[i] = NULL;
  3372. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  3373. IWL_RX_BUF_SIZE,
  3374. PCI_DMA_FROMDEVICE);
  3375. pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  3376. /* Reclaim a command buffer only if this packet is a response
  3377. * to a (driver-originated) command.
  3378. * If the packet (e.g. Rx frame) originated from uCode,
  3379. * there is no command buffer to reclaim.
  3380. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3381. * but apparently a few don't get set; catch them here. */
  3382. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3383. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  3384. (pkt->hdr.cmd != REPLY_TX);
  3385. /* Based on type of command response or notification,
  3386. * handle those that need handling via function in
  3387. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  3388. if (priv->rx_handlers[pkt->hdr.cmd]) {
  3389. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3390. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  3391. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3392. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  3393. } else {
  3394. /* No handling needed */
  3395. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3396. "r %d i %d No handler needed for %s, 0x%02x\n",
  3397. r, i, get_cmd_string(pkt->hdr.cmd),
  3398. pkt->hdr.cmd);
  3399. }
  3400. if (reclaim) {
  3401. /* Invoke any callbacks, transfer the skb to caller, and
  3402. * fire off the (possibly) blocking iwl3945_send_cmd()
  3403. * as we reclaim the driver command queue */
  3404. if (rxb && rxb->skb)
  3405. iwl3945_tx_cmd_complete(priv, rxb);
  3406. else
  3407. IWL_WARNING("Claim null rxb?\n");
  3408. }
  3409. /* For now we just don't re-use anything. We can tweak this
  3410. * later to try and re-use notification packets and SKBs that
  3411. * fail to Rx correctly */
  3412. if (rxb->skb != NULL) {
  3413. priv->alloc_rxb_skb--;
  3414. dev_kfree_skb_any(rxb->skb);
  3415. rxb->skb = NULL;
  3416. }
  3417. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  3418. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3419. spin_lock_irqsave(&rxq->lock, flags);
  3420. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  3421. spin_unlock_irqrestore(&rxq->lock, flags);
  3422. i = (i + 1) & RX_QUEUE_MASK;
  3423. /* If there are a lot of unused frames,
  3424. * restock the Rx queue so ucode won't assert. */
  3425. if (fill_rx) {
  3426. count++;
  3427. if (count >= 8) {
  3428. priv->rxq.read = i;
  3429. __iwl3945_rx_replenish(priv);
  3430. count = 0;
  3431. }
  3432. }
  3433. }
  3434. /* Backtrack one entry */
  3435. priv->rxq.read = i;
  3436. iwl3945_rx_queue_restock(priv);
  3437. }
  3438. /**
  3439. * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
  3440. */
  3441. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  3442. struct iwl3945_tx_queue *txq)
  3443. {
  3444. u32 reg = 0;
  3445. int rc = 0;
  3446. int txq_id = txq->q.id;
  3447. if (txq->need_update == 0)
  3448. return rc;
  3449. /* if we're trying to save power */
  3450. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3451. /* wake up nic if it's powered down ...
  3452. * uCode will wake up, and interrupt us again, so next
  3453. * time we'll skip this part. */
  3454. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3455. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3456. IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
  3457. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3458. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3459. return rc;
  3460. }
  3461. /* restore this queue's parameters in nic hardware. */
  3462. rc = iwl3945_grab_nic_access(priv);
  3463. if (rc)
  3464. return rc;
  3465. iwl3945_write_direct32(priv, HBUS_TARG_WRPTR,
  3466. txq->q.write_ptr | (txq_id << 8));
  3467. iwl3945_release_nic_access(priv);
  3468. /* else not in power-save mode, uCode will never sleep when we're
  3469. * trying to tx (during RFKILL, we're not trying to tx). */
  3470. } else
  3471. iwl3945_write32(priv, HBUS_TARG_WRPTR,
  3472. txq->q.write_ptr | (txq_id << 8));
  3473. txq->need_update = 0;
  3474. return rc;
  3475. }
  3476. #ifdef CONFIG_IWL3945_DEBUG
  3477. static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon)
  3478. {
  3479. DECLARE_MAC_BUF(mac);
  3480. IWL_DEBUG_RADIO("RX CONFIG:\n");
  3481. iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  3482. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  3483. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  3484. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  3485. le32_to_cpu(rxon->filter_flags));
  3486. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  3487. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  3488. rxon->ofdm_basic_rates);
  3489. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  3490. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  3491. print_mac(mac, rxon->node_addr));
  3492. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  3493. print_mac(mac, rxon->bssid_addr));
  3494. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  3495. }
  3496. #endif
  3497. static void iwl3945_enable_interrupts(struct iwl3945_priv *priv)
  3498. {
  3499. IWL_DEBUG_ISR("Enabling interrupts\n");
  3500. set_bit(STATUS_INT_ENABLED, &priv->status);
  3501. iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  3502. }
  3503. /* call this function to flush any scheduled tasklet */
  3504. static inline void iwl_synchronize_irq(struct iwl3945_priv *priv)
  3505. {
  3506. /* wait to make sure we flush pedding tasklet*/
  3507. synchronize_irq(priv->pci_dev->irq);
  3508. tasklet_kill(&priv->irq_tasklet);
  3509. }
  3510. static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv)
  3511. {
  3512. clear_bit(STATUS_INT_ENABLED, &priv->status);
  3513. /* disable interrupts from uCode/NIC to host */
  3514. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  3515. /* acknowledge/clear/reset any interrupts still pending
  3516. * from uCode or flow handler (Rx/Tx DMA) */
  3517. iwl3945_write32(priv, CSR_INT, 0xffffffff);
  3518. iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  3519. IWL_DEBUG_ISR("Disabled interrupts\n");
  3520. }
  3521. static const char *desc_lookup(int i)
  3522. {
  3523. switch (i) {
  3524. case 1:
  3525. return "FAIL";
  3526. case 2:
  3527. return "BAD_PARAM";
  3528. case 3:
  3529. return "BAD_CHECKSUM";
  3530. case 4:
  3531. return "NMI_INTERRUPT";
  3532. case 5:
  3533. return "SYSASSERT";
  3534. case 6:
  3535. return "FATAL_ERROR";
  3536. }
  3537. return "UNKNOWN";
  3538. }
  3539. #define ERROR_START_OFFSET (1 * sizeof(u32))
  3540. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  3541. static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv)
  3542. {
  3543. u32 i;
  3544. u32 desc, time, count, base, data1;
  3545. u32 blink1, blink2, ilink1, ilink2;
  3546. int rc;
  3547. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  3548. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3549. IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
  3550. return;
  3551. }
  3552. rc = iwl3945_grab_nic_access(priv);
  3553. if (rc) {
  3554. IWL_WARNING("Can not read from adapter at this time.\n");
  3555. return;
  3556. }
  3557. count = iwl3945_read_targ_mem(priv, base);
  3558. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  3559. IWL_ERROR("Start IWL Error Log Dump:\n");
  3560. IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
  3561. }
  3562. IWL_ERROR("Desc Time asrtPC blink2 "
  3563. "ilink1 nmiPC Line\n");
  3564. for (i = ERROR_START_OFFSET;
  3565. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  3566. i += ERROR_ELEM_SIZE) {
  3567. desc = iwl3945_read_targ_mem(priv, base + i);
  3568. time =
  3569. iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  3570. blink1 =
  3571. iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  3572. blink2 =
  3573. iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  3574. ilink1 =
  3575. iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  3576. ilink2 =
  3577. iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  3578. data1 =
  3579. iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  3580. IWL_ERROR
  3581. ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  3582. desc_lookup(desc), desc, time, blink1, blink2,
  3583. ilink1, ilink2, data1);
  3584. }
  3585. iwl3945_release_nic_access(priv);
  3586. }
  3587. #define EVENT_START_OFFSET (6 * sizeof(u32))
  3588. /**
  3589. * iwl3945_print_event_log - Dump error event log to syslog
  3590. *
  3591. * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
  3592. */
  3593. static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx,
  3594. u32 num_events, u32 mode)
  3595. {
  3596. u32 i;
  3597. u32 base; /* SRAM byte address of event log header */
  3598. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  3599. u32 ptr; /* SRAM byte address of log data */
  3600. u32 ev, time, data; /* event log data */
  3601. if (num_events == 0)
  3602. return;
  3603. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3604. if (mode == 0)
  3605. event_size = 2 * sizeof(u32);
  3606. else
  3607. event_size = 3 * sizeof(u32);
  3608. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  3609. /* "time" is actually "data" for mode 0 (no timestamp).
  3610. * place event id # at far right for easier visual parsing. */
  3611. for (i = 0; i < num_events; i++) {
  3612. ev = iwl3945_read_targ_mem(priv, ptr);
  3613. ptr += sizeof(u32);
  3614. time = iwl3945_read_targ_mem(priv, ptr);
  3615. ptr += sizeof(u32);
  3616. if (mode == 0)
  3617. IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
  3618. else {
  3619. data = iwl3945_read_targ_mem(priv, ptr);
  3620. ptr += sizeof(u32);
  3621. IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
  3622. }
  3623. }
  3624. }
  3625. static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv)
  3626. {
  3627. int rc;
  3628. u32 base; /* SRAM byte address of event log header */
  3629. u32 capacity; /* event log capacity in # entries */
  3630. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  3631. u32 num_wraps; /* # times uCode wrapped to top of log */
  3632. u32 next_entry; /* index of next entry to be written by uCode */
  3633. u32 size; /* # entries that we'll print */
  3634. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3635. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3636. IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
  3637. return;
  3638. }
  3639. rc = iwl3945_grab_nic_access(priv);
  3640. if (rc) {
  3641. IWL_WARNING("Can not read from adapter at this time.\n");
  3642. return;
  3643. }
  3644. /* event log header */
  3645. capacity = iwl3945_read_targ_mem(priv, base);
  3646. mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32)));
  3647. num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32)));
  3648. next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32)));
  3649. size = num_wraps ? capacity : next_entry;
  3650. /* bail out if nothing in log */
  3651. if (size == 0) {
  3652. IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
  3653. iwl3945_release_nic_access(priv);
  3654. return;
  3655. }
  3656. IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
  3657. size, num_wraps);
  3658. /* if uCode has wrapped back to top of log, start at the oldest entry,
  3659. * i.e the next one that uCode would fill. */
  3660. if (num_wraps)
  3661. iwl3945_print_event_log(priv, next_entry,
  3662. capacity - next_entry, mode);
  3663. /* (then/else) start at top of log */
  3664. iwl3945_print_event_log(priv, 0, next_entry, mode);
  3665. iwl3945_release_nic_access(priv);
  3666. }
  3667. /**
  3668. * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
  3669. */
  3670. static void iwl3945_irq_handle_error(struct iwl3945_priv *priv)
  3671. {
  3672. /* Set the FW error flag -- cleared on iwl3945_down */
  3673. set_bit(STATUS_FW_ERROR, &priv->status);
  3674. /* Cancel currently queued command. */
  3675. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  3676. #ifdef CONFIG_IWL3945_DEBUG
  3677. if (iwl3945_debug_level & IWL_DL_FW_ERRORS) {
  3678. iwl3945_dump_nic_error_log(priv);
  3679. iwl3945_dump_nic_event_log(priv);
  3680. iwl3945_print_rx_config_cmd(&priv->staging_rxon);
  3681. }
  3682. #endif
  3683. wake_up_interruptible(&priv->wait_command_queue);
  3684. /* Keep the restart process from trying to send host
  3685. * commands by clearing the INIT status bit */
  3686. clear_bit(STATUS_READY, &priv->status);
  3687. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3688. IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
  3689. "Restarting adapter due to uCode error.\n");
  3690. if (iwl3945_is_associated(priv)) {
  3691. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  3692. sizeof(priv->recovery_rxon));
  3693. priv->error_recovering = 1;
  3694. }
  3695. queue_work(priv->workqueue, &priv->restart);
  3696. }
  3697. }
  3698. static void iwl3945_error_recovery(struct iwl3945_priv *priv)
  3699. {
  3700. unsigned long flags;
  3701. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  3702. sizeof(priv->staging_rxon));
  3703. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3704. iwl3945_commit_rxon(priv);
  3705. iwl3945_add_station(priv, priv->bssid, 1, 0);
  3706. spin_lock_irqsave(&priv->lock, flags);
  3707. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  3708. priv->error_recovering = 0;
  3709. spin_unlock_irqrestore(&priv->lock, flags);
  3710. }
  3711. static void iwl3945_irq_tasklet(struct iwl3945_priv *priv)
  3712. {
  3713. u32 inta, handled = 0;
  3714. u32 inta_fh;
  3715. unsigned long flags;
  3716. #ifdef CONFIG_IWL3945_DEBUG
  3717. u32 inta_mask;
  3718. #endif
  3719. spin_lock_irqsave(&priv->lock, flags);
  3720. /* Ack/clear/reset pending uCode interrupts.
  3721. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  3722. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  3723. inta = iwl3945_read32(priv, CSR_INT);
  3724. iwl3945_write32(priv, CSR_INT, inta);
  3725. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  3726. * Any new interrupts that happen after this, either while we're
  3727. * in this tasklet, or later, will show up in next ISR/tasklet. */
  3728. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3729. iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  3730. #ifdef CONFIG_IWL3945_DEBUG
  3731. if (iwl3945_debug_level & IWL_DL_ISR) {
  3732. /* just for debug */
  3733. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  3734. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  3735. inta, inta_mask, inta_fh);
  3736. }
  3737. #endif
  3738. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  3739. * atomic, make sure that inta covers all the interrupts that
  3740. * we've discovered, even if FH interrupt came in just after
  3741. * reading CSR_INT. */
  3742. if (inta_fh & CSR39_FH_INT_RX_MASK)
  3743. inta |= CSR_INT_BIT_FH_RX;
  3744. if (inta_fh & CSR39_FH_INT_TX_MASK)
  3745. inta |= CSR_INT_BIT_FH_TX;
  3746. /* Now service all interrupt bits discovered above. */
  3747. if (inta & CSR_INT_BIT_HW_ERR) {
  3748. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  3749. /* Tell the device to stop sending interrupts */
  3750. iwl3945_disable_interrupts(priv);
  3751. iwl3945_irq_handle_error(priv);
  3752. handled |= CSR_INT_BIT_HW_ERR;
  3753. spin_unlock_irqrestore(&priv->lock, flags);
  3754. return;
  3755. }
  3756. #ifdef CONFIG_IWL3945_DEBUG
  3757. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  3758. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  3759. if (inta & CSR_INT_BIT_SCD)
  3760. IWL_DEBUG_ISR("Scheduler finished to transmit "
  3761. "the frame/frames.\n");
  3762. /* Alive notification via Rx interrupt will do the real work */
  3763. if (inta & CSR_INT_BIT_ALIVE)
  3764. IWL_DEBUG_ISR("Alive interrupt\n");
  3765. }
  3766. #endif
  3767. /* Safely ignore these bits for debug checks below */
  3768. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  3769. /* HW RF KILL switch toggled (4965 only) */
  3770. if (inta & CSR_INT_BIT_RF_KILL) {
  3771. int hw_rf_kill = 0;
  3772. if (!(iwl3945_read32(priv, CSR_GP_CNTRL) &
  3773. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  3774. hw_rf_kill = 1;
  3775. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
  3776. "RF_KILL bit toggled to %s.\n",
  3777. hw_rf_kill ? "disable radio":"enable radio");
  3778. /* Queue restart only if RF_KILL switch was set to "kill"
  3779. * when we loaded driver, and is now set to "enable".
  3780. * After we're Alive, RF_KILL gets handled by
  3781. * iwl3945_rx_card_state_notif() */
  3782. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  3783. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3784. queue_work(priv->workqueue, &priv->restart);
  3785. }
  3786. handled |= CSR_INT_BIT_RF_KILL;
  3787. }
  3788. /* Chip got too hot and stopped itself (4965 only) */
  3789. if (inta & CSR_INT_BIT_CT_KILL) {
  3790. IWL_ERROR("Microcode CT kill error detected.\n");
  3791. handled |= CSR_INT_BIT_CT_KILL;
  3792. }
  3793. /* Error detected by uCode */
  3794. if (inta & CSR_INT_BIT_SW_ERR) {
  3795. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  3796. inta);
  3797. iwl3945_irq_handle_error(priv);
  3798. handled |= CSR_INT_BIT_SW_ERR;
  3799. }
  3800. /* uCode wakes up after power-down sleep */
  3801. if (inta & CSR_INT_BIT_WAKEUP) {
  3802. IWL_DEBUG_ISR("Wakeup interrupt\n");
  3803. iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
  3804. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]);
  3805. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]);
  3806. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]);
  3807. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]);
  3808. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]);
  3809. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]);
  3810. handled |= CSR_INT_BIT_WAKEUP;
  3811. }
  3812. /* All uCode command responses, including Tx command responses,
  3813. * Rx "responses" (frame-received notification), and other
  3814. * notifications from uCode come through here*/
  3815. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  3816. iwl3945_rx_handle(priv);
  3817. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  3818. }
  3819. if (inta & CSR_INT_BIT_FH_TX) {
  3820. IWL_DEBUG_ISR("Tx interrupt\n");
  3821. iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  3822. if (!iwl3945_grab_nic_access(priv)) {
  3823. iwl3945_write_direct32(priv,
  3824. FH_TCSR_CREDIT
  3825. (ALM_FH_SRVC_CHNL), 0x0);
  3826. iwl3945_release_nic_access(priv);
  3827. }
  3828. handled |= CSR_INT_BIT_FH_TX;
  3829. }
  3830. if (inta & ~handled)
  3831. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  3832. if (inta & ~CSR_INI_SET_MASK) {
  3833. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  3834. inta & ~CSR_INI_SET_MASK);
  3835. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  3836. }
  3837. /* Re-enable all interrupts */
  3838. /* only Re-enable if disabled by irq */
  3839. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  3840. iwl3945_enable_interrupts(priv);
  3841. #ifdef CONFIG_IWL3945_DEBUG
  3842. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  3843. inta = iwl3945_read32(priv, CSR_INT);
  3844. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  3845. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3846. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  3847. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  3848. }
  3849. #endif
  3850. spin_unlock_irqrestore(&priv->lock, flags);
  3851. }
  3852. static irqreturn_t iwl3945_isr(int irq, void *data)
  3853. {
  3854. struct iwl3945_priv *priv = data;
  3855. u32 inta, inta_mask;
  3856. u32 inta_fh;
  3857. if (!priv)
  3858. return IRQ_NONE;
  3859. spin_lock(&priv->lock);
  3860. /* Disable (but don't clear!) interrupts here to avoid
  3861. * back-to-back ISRs and sporadic interrupts from our NIC.
  3862. * If we have something to service, the tasklet will re-enable ints.
  3863. * If we *don't* have something, we'll re-enable before leaving here. */
  3864. inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */
  3865. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  3866. /* Discover which interrupts are active/pending */
  3867. inta = iwl3945_read32(priv, CSR_INT);
  3868. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3869. /* Ignore interrupt if there's nothing in NIC to service.
  3870. * This may be due to IRQ shared with another device,
  3871. * or due to sporadic interrupts thrown from our NIC. */
  3872. if (!inta && !inta_fh) {
  3873. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  3874. goto none;
  3875. }
  3876. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  3877. /* Hardware disappeared */
  3878. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  3879. goto unplugged;
  3880. }
  3881. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  3882. inta, inta_mask, inta_fh);
  3883. inta &= ~CSR_INT_BIT_SCD;
  3884. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  3885. if (likely(inta || inta_fh))
  3886. tasklet_schedule(&priv->irq_tasklet);
  3887. unplugged:
  3888. spin_unlock(&priv->lock);
  3889. return IRQ_HANDLED;
  3890. none:
  3891. /* re-enable interrupts here since we don't have anything to service. */
  3892. /* only Re-enable if disabled by irq */
  3893. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  3894. iwl3945_enable_interrupts(priv);
  3895. spin_unlock(&priv->lock);
  3896. return IRQ_NONE;
  3897. }
  3898. /************************** EEPROM BANDS ****************************
  3899. *
  3900. * The iwl3945_eeprom_band definitions below provide the mapping from the
  3901. * EEPROM contents to the specific channel number supported for each
  3902. * band.
  3903. *
  3904. * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
  3905. * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  3906. * The specific geography and calibration information for that channel
  3907. * is contained in the eeprom map itself.
  3908. *
  3909. * During init, we copy the eeprom information and channel map
  3910. * information into priv->channel_info_24/52 and priv->channel_map_24/52
  3911. *
  3912. * channel_map_24/52 provides the index in the channel_info array for a
  3913. * given channel. We have to have two separate maps as there is channel
  3914. * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
  3915. * band_2
  3916. *
  3917. * A value of 0xff stored in the channel_map indicates that the channel
  3918. * is not supported by the hardware at all.
  3919. *
  3920. * A value of 0xfe in the channel_map indicates that the channel is not
  3921. * valid for Tx with the current hardware. This means that
  3922. * while the system can tune and receive on a given channel, it may not
  3923. * be able to associate or transmit any frames on that
  3924. * channel. There is no corresponding channel information for that
  3925. * entry.
  3926. *
  3927. *********************************************************************/
  3928. /* 2.4 GHz */
  3929. static const u8 iwl3945_eeprom_band_1[14] = {
  3930. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  3931. };
  3932. /* 5.2 GHz bands */
  3933. static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
  3934. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  3935. };
  3936. static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
  3937. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  3938. };
  3939. static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
  3940. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  3941. };
  3942. static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
  3943. 145, 149, 153, 157, 161, 165
  3944. };
  3945. static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band,
  3946. int *eeprom_ch_count,
  3947. const struct iwl3945_eeprom_channel
  3948. **eeprom_ch_info,
  3949. const u8 **eeprom_ch_index)
  3950. {
  3951. switch (band) {
  3952. case 1: /* 2.4GHz band */
  3953. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
  3954. *eeprom_ch_info = priv->eeprom.band_1_channels;
  3955. *eeprom_ch_index = iwl3945_eeprom_band_1;
  3956. break;
  3957. case 2: /* 4.9GHz band */
  3958. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
  3959. *eeprom_ch_info = priv->eeprom.band_2_channels;
  3960. *eeprom_ch_index = iwl3945_eeprom_band_2;
  3961. break;
  3962. case 3: /* 5.2GHz band */
  3963. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
  3964. *eeprom_ch_info = priv->eeprom.band_3_channels;
  3965. *eeprom_ch_index = iwl3945_eeprom_band_3;
  3966. break;
  3967. case 4: /* 5.5GHz band */
  3968. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
  3969. *eeprom_ch_info = priv->eeprom.band_4_channels;
  3970. *eeprom_ch_index = iwl3945_eeprom_band_4;
  3971. break;
  3972. case 5: /* 5.7GHz band */
  3973. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
  3974. *eeprom_ch_info = priv->eeprom.band_5_channels;
  3975. *eeprom_ch_index = iwl3945_eeprom_band_5;
  3976. break;
  3977. default:
  3978. BUG();
  3979. return;
  3980. }
  3981. }
  3982. /**
  3983. * iwl3945_get_channel_info - Find driver's private channel info
  3984. *
  3985. * Based on band and channel number.
  3986. */
  3987. const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
  3988. enum ieee80211_band band, u16 channel)
  3989. {
  3990. int i;
  3991. switch (band) {
  3992. case IEEE80211_BAND_5GHZ:
  3993. for (i = 14; i < priv->channel_count; i++) {
  3994. if (priv->channel_info[i].channel == channel)
  3995. return &priv->channel_info[i];
  3996. }
  3997. break;
  3998. case IEEE80211_BAND_2GHZ:
  3999. if (channel >= 1 && channel <= 14)
  4000. return &priv->channel_info[channel - 1];
  4001. break;
  4002. case IEEE80211_NUM_BANDS:
  4003. WARN_ON(1);
  4004. }
  4005. return NULL;
  4006. }
  4007. #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  4008. ? # x " " : "")
  4009. /**
  4010. * iwl3945_init_channel_map - Set up driver's info for all possible channels
  4011. */
  4012. static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
  4013. {
  4014. int eeprom_ch_count = 0;
  4015. const u8 *eeprom_ch_index = NULL;
  4016. const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL;
  4017. int band, ch;
  4018. struct iwl3945_channel_info *ch_info;
  4019. if (priv->channel_count) {
  4020. IWL_DEBUG_INFO("Channel map already initialized.\n");
  4021. return 0;
  4022. }
  4023. if (priv->eeprom.version < 0x2f) {
  4024. IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
  4025. priv->eeprom.version);
  4026. return -EINVAL;
  4027. }
  4028. IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
  4029. priv->channel_count =
  4030. ARRAY_SIZE(iwl3945_eeprom_band_1) +
  4031. ARRAY_SIZE(iwl3945_eeprom_band_2) +
  4032. ARRAY_SIZE(iwl3945_eeprom_band_3) +
  4033. ARRAY_SIZE(iwl3945_eeprom_band_4) +
  4034. ARRAY_SIZE(iwl3945_eeprom_band_5);
  4035. IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
  4036. priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) *
  4037. priv->channel_count, GFP_KERNEL);
  4038. if (!priv->channel_info) {
  4039. IWL_ERROR("Could not allocate channel_info\n");
  4040. priv->channel_count = 0;
  4041. return -ENOMEM;
  4042. }
  4043. ch_info = priv->channel_info;
  4044. /* Loop through the 5 EEPROM bands adding them in order to the
  4045. * channel map we maintain (that contains additional information than
  4046. * what just in the EEPROM) */
  4047. for (band = 1; band <= 5; band++) {
  4048. iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
  4049. &eeprom_ch_info, &eeprom_ch_index);
  4050. /* Loop through each band adding each of the channels */
  4051. for (ch = 0; ch < eeprom_ch_count; ch++) {
  4052. ch_info->channel = eeprom_ch_index[ch];
  4053. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  4054. IEEE80211_BAND_5GHZ;
  4055. /* permanently store EEPROM's channel regulatory flags
  4056. * and max power in channel info database. */
  4057. ch_info->eeprom = eeprom_ch_info[ch];
  4058. /* Copy the run-time flags so they are there even on
  4059. * invalid channels */
  4060. ch_info->flags = eeprom_ch_info[ch].flags;
  4061. if (!(is_channel_valid(ch_info))) {
  4062. IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
  4063. "No traffic\n",
  4064. ch_info->channel,
  4065. ch_info->flags,
  4066. is_channel_a_band(ch_info) ?
  4067. "5.2" : "2.4");
  4068. ch_info++;
  4069. continue;
  4070. }
  4071. /* Initialize regulatory-based run-time data */
  4072. ch_info->max_power_avg = ch_info->curr_txpow =
  4073. eeprom_ch_info[ch].max_power_avg;
  4074. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  4075. ch_info->min_power = 0;
  4076. IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x"
  4077. " %ddBm): Ad-Hoc %ssupported\n",
  4078. ch_info->channel,
  4079. is_channel_a_band(ch_info) ?
  4080. "5.2" : "2.4",
  4081. CHECK_AND_PRINT(VALID),
  4082. CHECK_AND_PRINT(IBSS),
  4083. CHECK_AND_PRINT(ACTIVE),
  4084. CHECK_AND_PRINT(RADAR),
  4085. CHECK_AND_PRINT(WIDE),
  4086. CHECK_AND_PRINT(NARROW),
  4087. CHECK_AND_PRINT(DFS),
  4088. eeprom_ch_info[ch].flags,
  4089. eeprom_ch_info[ch].max_power_avg,
  4090. ((eeprom_ch_info[ch].
  4091. flags & EEPROM_CHANNEL_IBSS)
  4092. && !(eeprom_ch_info[ch].
  4093. flags & EEPROM_CHANNEL_RADAR))
  4094. ? "" : "not ");
  4095. /* Set the user_txpower_limit to the highest power
  4096. * supported by any channel */
  4097. if (eeprom_ch_info[ch].max_power_avg >
  4098. priv->user_txpower_limit)
  4099. priv->user_txpower_limit =
  4100. eeprom_ch_info[ch].max_power_avg;
  4101. ch_info++;
  4102. }
  4103. }
  4104. /* Set up txpower settings in driver for all channels */
  4105. if (iwl3945_txpower_set_from_eeprom(priv))
  4106. return -EIO;
  4107. return 0;
  4108. }
  4109. /*
  4110. * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
  4111. */
  4112. static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
  4113. {
  4114. kfree(priv->channel_info);
  4115. priv->channel_count = 0;
  4116. }
  4117. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  4118. * sending probe req. This should be set long enough to hear probe responses
  4119. * from more than one AP. */
  4120. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  4121. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  4122. /* For faster active scanning, scan will move to the next channel if fewer than
  4123. * PLCP_QUIET_THRESH packets are heard on this channel within
  4124. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  4125. * time if it's a quiet channel (nothing responded to our probe, and there's
  4126. * no other traffic).
  4127. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  4128. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  4129. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  4130. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  4131. * Must be set longer than active dwell time.
  4132. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  4133. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  4134. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  4135. #define IWL_PASSIVE_DWELL_BASE (100)
  4136. #define IWL_CHANNEL_TUNE_TIME 5
  4137. static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv,
  4138. enum ieee80211_band band)
  4139. {
  4140. if (band == IEEE80211_BAND_5GHZ)
  4141. return IWL_ACTIVE_DWELL_TIME_52;
  4142. else
  4143. return IWL_ACTIVE_DWELL_TIME_24;
  4144. }
  4145. static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv,
  4146. enum ieee80211_band band)
  4147. {
  4148. u16 active = iwl3945_get_active_dwell_time(priv, band);
  4149. u16 passive = (band == IEEE80211_BAND_2GHZ) ?
  4150. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  4151. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  4152. if (iwl3945_is_associated(priv)) {
  4153. /* If we're associated, we clamp the maximum passive
  4154. * dwell time to be 98% of the beacon interval (minus
  4155. * 2 * channel tune time) */
  4156. passive = priv->beacon_int;
  4157. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  4158. passive = IWL_PASSIVE_DWELL_BASE;
  4159. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  4160. }
  4161. if (passive <= active)
  4162. passive = active + 1;
  4163. return passive;
  4164. }
  4165. static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
  4166. enum ieee80211_band band,
  4167. u8 is_active, u8 direct_mask,
  4168. struct iwl3945_scan_channel *scan_ch)
  4169. {
  4170. const struct ieee80211_channel *channels = NULL;
  4171. const struct ieee80211_supported_band *sband;
  4172. const struct iwl3945_channel_info *ch_info;
  4173. u16 passive_dwell = 0;
  4174. u16 active_dwell = 0;
  4175. int added, i;
  4176. sband = iwl3945_get_band(priv, band);
  4177. if (!sband)
  4178. return 0;
  4179. channels = sband->channels;
  4180. active_dwell = iwl3945_get_active_dwell_time(priv, band);
  4181. passive_dwell = iwl3945_get_passive_dwell_time(priv, band);
  4182. for (i = 0, added = 0; i < sband->n_channels; i++) {
  4183. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  4184. continue;
  4185. scan_ch->channel = channels[i].hw_value;
  4186. ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
  4187. if (!is_channel_valid(ch_info)) {
  4188. IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
  4189. scan_ch->channel);
  4190. continue;
  4191. }
  4192. if (!is_active || is_channel_passive(ch_info) ||
  4193. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
  4194. scan_ch->type = 0; /* passive */
  4195. else
  4196. scan_ch->type = 1; /* active */
  4197. if (scan_ch->type & 1)
  4198. scan_ch->type |= (direct_mask << 1);
  4199. if (is_channel_narrow(ch_info))
  4200. scan_ch->type |= (1 << 7);
  4201. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  4202. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  4203. /* Set txpower levels to defaults */
  4204. scan_ch->tpc.dsp_atten = 110;
  4205. /* scan_pwr_info->tpc.dsp_atten; */
  4206. /*scan_pwr_info->tpc.tx_gain; */
  4207. if (band == IEEE80211_BAND_5GHZ)
  4208. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  4209. else {
  4210. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  4211. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  4212. * power level:
  4213. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  4214. */
  4215. }
  4216. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  4217. scan_ch->channel,
  4218. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  4219. (scan_ch->type & 1) ?
  4220. active_dwell : passive_dwell);
  4221. scan_ch++;
  4222. added++;
  4223. }
  4224. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  4225. return added;
  4226. }
  4227. static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
  4228. struct ieee80211_rate *rates)
  4229. {
  4230. int i;
  4231. for (i = 0; i < IWL_RATE_COUNT; i++) {
  4232. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  4233. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  4234. rates[i].hw_value_short = i;
  4235. rates[i].flags = 0;
  4236. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  4237. /*
  4238. * If CCK != 1M then set short preamble rate flag.
  4239. */
  4240. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  4241. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  4242. }
  4243. }
  4244. }
  4245. /**
  4246. * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
  4247. */
  4248. static int iwl3945_init_geos(struct iwl3945_priv *priv)
  4249. {
  4250. struct iwl3945_channel_info *ch;
  4251. struct ieee80211_supported_band *sband;
  4252. struct ieee80211_channel *channels;
  4253. struct ieee80211_channel *geo_ch;
  4254. struct ieee80211_rate *rates;
  4255. int i = 0;
  4256. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  4257. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  4258. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  4259. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4260. return 0;
  4261. }
  4262. channels = kzalloc(sizeof(struct ieee80211_channel) *
  4263. priv->channel_count, GFP_KERNEL);
  4264. if (!channels)
  4265. return -ENOMEM;
  4266. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  4267. GFP_KERNEL);
  4268. if (!rates) {
  4269. kfree(channels);
  4270. return -ENOMEM;
  4271. }
  4272. /* 5.2GHz channels start after the 2.4GHz channels */
  4273. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  4274. sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
  4275. /* just OFDM */
  4276. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  4277. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  4278. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  4279. sband->channels = channels;
  4280. /* OFDM & CCK */
  4281. sband->bitrates = rates;
  4282. sband->n_bitrates = IWL_RATE_COUNT;
  4283. priv->ieee_channels = channels;
  4284. priv->ieee_rates = rates;
  4285. iwl3945_init_hw_rates(priv, rates);
  4286. for (i = 0; i < priv->channel_count; i++) {
  4287. ch = &priv->channel_info[i];
  4288. /* FIXME: might be removed if scan is OK*/
  4289. if (!is_channel_valid(ch))
  4290. continue;
  4291. if (is_channel_a_band(ch))
  4292. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  4293. else
  4294. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  4295. geo_ch = &sband->channels[sband->n_channels++];
  4296. geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
  4297. geo_ch->max_power = ch->max_power_avg;
  4298. geo_ch->max_antenna_gain = 0xff;
  4299. geo_ch->hw_value = ch->channel;
  4300. if (is_channel_valid(ch)) {
  4301. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  4302. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  4303. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  4304. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  4305. if (ch->flags & EEPROM_CHANNEL_RADAR)
  4306. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  4307. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  4308. priv->max_channel_txpower_limit =
  4309. ch->max_power_avg;
  4310. } else {
  4311. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  4312. }
  4313. /* Save flags for reg domain usage */
  4314. geo_ch->orig_flags = geo_ch->flags;
  4315. IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
  4316. ch->channel, geo_ch->center_freq,
  4317. is_channel_a_band(ch) ? "5.2" : "2.4",
  4318. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  4319. "restricted" : "valid",
  4320. geo_ch->flags);
  4321. }
  4322. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  4323. priv->cfg->sku & IWL_SKU_A) {
  4324. printk(KERN_INFO DRV_NAME
  4325. ": Incorrectly detected BG card as ABG. Please send "
  4326. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  4327. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  4328. priv->cfg->sku &= ~IWL_SKU_A;
  4329. }
  4330. printk(KERN_INFO DRV_NAME
  4331. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  4332. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  4333. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  4334. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  4335. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4336. &priv->bands[IEEE80211_BAND_2GHZ];
  4337. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  4338. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4339. &priv->bands[IEEE80211_BAND_5GHZ];
  4340. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4341. return 0;
  4342. }
  4343. /*
  4344. * iwl3945_free_geos - undo allocations in iwl3945_init_geos
  4345. */
  4346. static void iwl3945_free_geos(struct iwl3945_priv *priv)
  4347. {
  4348. kfree(priv->ieee_channels);
  4349. kfree(priv->ieee_rates);
  4350. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4351. }
  4352. /******************************************************************************
  4353. *
  4354. * uCode download functions
  4355. *
  4356. ******************************************************************************/
  4357. static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
  4358. {
  4359. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  4360. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  4361. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  4362. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  4363. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  4364. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  4365. }
  4366. /**
  4367. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  4368. * looking at all data.
  4369. */
  4370. static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len)
  4371. {
  4372. u32 val;
  4373. u32 save_len = len;
  4374. int rc = 0;
  4375. u32 errcnt;
  4376. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4377. rc = iwl3945_grab_nic_access(priv);
  4378. if (rc)
  4379. return rc;
  4380. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  4381. errcnt = 0;
  4382. for (; len > 0; len -= sizeof(u32), image++) {
  4383. /* read data comes through single port, auto-incr addr */
  4384. /* NOTE: Use the debugless read so we don't flood kernel log
  4385. * if IWL_DL_IO is set */
  4386. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4387. if (val != le32_to_cpu(*image)) {
  4388. IWL_ERROR("uCode INST section is invalid at "
  4389. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4390. save_len - len, val, le32_to_cpu(*image));
  4391. rc = -EIO;
  4392. errcnt++;
  4393. if (errcnt >= 20)
  4394. break;
  4395. }
  4396. }
  4397. iwl3945_release_nic_access(priv);
  4398. if (!errcnt)
  4399. IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
  4400. return rc;
  4401. }
  4402. /**
  4403. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  4404. * using sample data 100 bytes apart. If these sample points are good,
  4405. * it's a pretty good bet that everything between them is good, too.
  4406. */
  4407. static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len)
  4408. {
  4409. u32 val;
  4410. int rc = 0;
  4411. u32 errcnt = 0;
  4412. u32 i;
  4413. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4414. rc = iwl3945_grab_nic_access(priv);
  4415. if (rc)
  4416. return rc;
  4417. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  4418. /* read data comes through single port, auto-incr addr */
  4419. /* NOTE: Use the debugless read so we don't flood kernel log
  4420. * if IWL_DL_IO is set */
  4421. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  4422. i + RTC_INST_LOWER_BOUND);
  4423. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4424. if (val != le32_to_cpu(*image)) {
  4425. #if 0 /* Enable this if you want to see details */
  4426. IWL_ERROR("uCode INST section is invalid at "
  4427. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4428. i, val, *image);
  4429. #endif
  4430. rc = -EIO;
  4431. errcnt++;
  4432. if (errcnt >= 3)
  4433. break;
  4434. }
  4435. }
  4436. iwl3945_release_nic_access(priv);
  4437. return rc;
  4438. }
  4439. /**
  4440. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  4441. * and verify its contents
  4442. */
  4443. static int iwl3945_verify_ucode(struct iwl3945_priv *priv)
  4444. {
  4445. __le32 *image;
  4446. u32 len;
  4447. int rc = 0;
  4448. /* Try bootstrap */
  4449. image = (__le32 *)priv->ucode_boot.v_addr;
  4450. len = priv->ucode_boot.len;
  4451. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4452. if (rc == 0) {
  4453. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  4454. return 0;
  4455. }
  4456. /* Try initialize */
  4457. image = (__le32 *)priv->ucode_init.v_addr;
  4458. len = priv->ucode_init.len;
  4459. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4460. if (rc == 0) {
  4461. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  4462. return 0;
  4463. }
  4464. /* Try runtime/protocol */
  4465. image = (__le32 *)priv->ucode_code.v_addr;
  4466. len = priv->ucode_code.len;
  4467. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4468. if (rc == 0) {
  4469. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  4470. return 0;
  4471. }
  4472. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  4473. /* Since nothing seems to match, show first several data entries in
  4474. * instruction SRAM, so maybe visual inspection will give a clue.
  4475. * Selection of bootstrap image (vs. other images) is arbitrary. */
  4476. image = (__le32 *)priv->ucode_boot.v_addr;
  4477. len = priv->ucode_boot.len;
  4478. rc = iwl3945_verify_inst_full(priv, image, len);
  4479. return rc;
  4480. }
  4481. /* check contents of special bootstrap uCode SRAM */
  4482. static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
  4483. {
  4484. __le32 *image = priv->ucode_boot.v_addr;
  4485. u32 len = priv->ucode_boot.len;
  4486. u32 reg;
  4487. u32 val;
  4488. IWL_DEBUG_INFO("Begin verify bsm\n");
  4489. /* verify BSM SRAM contents */
  4490. val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
  4491. for (reg = BSM_SRAM_LOWER_BOUND;
  4492. reg < BSM_SRAM_LOWER_BOUND + len;
  4493. reg += sizeof(u32), image ++) {
  4494. val = iwl3945_read_prph(priv, reg);
  4495. if (val != le32_to_cpu(*image)) {
  4496. IWL_ERROR("BSM uCode verification failed at "
  4497. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  4498. BSM_SRAM_LOWER_BOUND,
  4499. reg - BSM_SRAM_LOWER_BOUND, len,
  4500. val, le32_to_cpu(*image));
  4501. return -EIO;
  4502. }
  4503. }
  4504. IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
  4505. return 0;
  4506. }
  4507. /**
  4508. * iwl3945_load_bsm - Load bootstrap instructions
  4509. *
  4510. * BSM operation:
  4511. *
  4512. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  4513. * in special SRAM that does not power down during RFKILL. When powering back
  4514. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  4515. * the bootstrap program into the on-board processor, and starts it.
  4516. *
  4517. * The bootstrap program loads (via DMA) instructions and data for a new
  4518. * program from host DRAM locations indicated by the host driver in the
  4519. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  4520. * automatically.
  4521. *
  4522. * When initializing the NIC, the host driver points the BSM to the
  4523. * "initialize" uCode image. This uCode sets up some internal data, then
  4524. * notifies host via "initialize alive" that it is complete.
  4525. *
  4526. * The host then replaces the BSM_DRAM_* pointer values to point to the
  4527. * normal runtime uCode instructions and a backup uCode data cache buffer
  4528. * (filled initially with starting data values for the on-board processor),
  4529. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  4530. * which begins normal operation.
  4531. *
  4532. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  4533. * the backup data cache in DRAM before SRAM is powered down.
  4534. *
  4535. * When powering back up, the BSM loads the bootstrap program. This reloads
  4536. * the runtime uCode instructions and the backup data cache into SRAM,
  4537. * and re-launches the runtime uCode from where it left off.
  4538. */
  4539. static int iwl3945_load_bsm(struct iwl3945_priv *priv)
  4540. {
  4541. __le32 *image = priv->ucode_boot.v_addr;
  4542. u32 len = priv->ucode_boot.len;
  4543. dma_addr_t pinst;
  4544. dma_addr_t pdata;
  4545. u32 inst_len;
  4546. u32 data_len;
  4547. int rc;
  4548. int i;
  4549. u32 done;
  4550. u32 reg_offset;
  4551. IWL_DEBUG_INFO("Begin load bsm\n");
  4552. /* make sure bootstrap program is no larger than BSM's SRAM size */
  4553. if (len > IWL_MAX_BSM_SIZE)
  4554. return -EINVAL;
  4555. /* Tell bootstrap uCode where to find the "Initialize" uCode
  4556. * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
  4557. * NOTE: iwl3945_initialize_alive_start() will replace these values,
  4558. * after the "initialize" uCode has run, to point to
  4559. * runtime/protocol instructions and backup data cache. */
  4560. pinst = priv->ucode_init.p_addr;
  4561. pdata = priv->ucode_init_data.p_addr;
  4562. inst_len = priv->ucode_init.len;
  4563. data_len = priv->ucode_init_data.len;
  4564. rc = iwl3945_grab_nic_access(priv);
  4565. if (rc)
  4566. return rc;
  4567. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  4568. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  4569. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  4570. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  4571. /* Fill BSM memory with bootstrap instructions */
  4572. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  4573. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  4574. reg_offset += sizeof(u32), image++)
  4575. _iwl3945_write_prph(priv, reg_offset,
  4576. le32_to_cpu(*image));
  4577. rc = iwl3945_verify_bsm(priv);
  4578. if (rc) {
  4579. iwl3945_release_nic_access(priv);
  4580. return rc;
  4581. }
  4582. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  4583. iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
  4584. iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG,
  4585. RTC_INST_LOWER_BOUND);
  4586. iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  4587. /* Load bootstrap code into instruction SRAM now,
  4588. * to prepare to load "initialize" uCode */
  4589. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4590. BSM_WR_CTRL_REG_BIT_START);
  4591. /* Wait for load of bootstrap uCode to finish */
  4592. for (i = 0; i < 100; i++) {
  4593. done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG);
  4594. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  4595. break;
  4596. udelay(10);
  4597. }
  4598. if (i < 100)
  4599. IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
  4600. else {
  4601. IWL_ERROR("BSM write did not complete!\n");
  4602. return -EIO;
  4603. }
  4604. /* Enable future boot loads whenever power management unit triggers it
  4605. * (e.g. when powering back up after power-save shutdown) */
  4606. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4607. BSM_WR_CTRL_REG_BIT_START_EN);
  4608. iwl3945_release_nic_access(priv);
  4609. return 0;
  4610. }
  4611. static void iwl3945_nic_start(struct iwl3945_priv *priv)
  4612. {
  4613. /* Remove all resets to allow NIC to operate */
  4614. iwl3945_write32(priv, CSR_RESET, 0);
  4615. }
  4616. /**
  4617. * iwl3945_read_ucode - Read uCode images from disk file.
  4618. *
  4619. * Copy into buffers for card to fetch via bus-mastering
  4620. */
  4621. static int iwl3945_read_ucode(struct iwl3945_priv *priv)
  4622. {
  4623. struct iwl3945_ucode *ucode;
  4624. int ret = 0;
  4625. const struct firmware *ucode_raw;
  4626. /* firmware file name contains uCode/driver compatibility version */
  4627. const char *name = priv->cfg->fw_name;
  4628. u8 *src;
  4629. size_t len;
  4630. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  4631. /* Ask kernel firmware_class module to get the boot firmware off disk.
  4632. * request_firmware() is synchronous, file is in memory on return. */
  4633. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  4634. if (ret < 0) {
  4635. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  4636. name, ret);
  4637. goto error;
  4638. }
  4639. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  4640. name, ucode_raw->size);
  4641. /* Make sure that we got at least our header! */
  4642. if (ucode_raw->size < sizeof(*ucode)) {
  4643. IWL_ERROR("File size way too small!\n");
  4644. ret = -EINVAL;
  4645. goto err_release;
  4646. }
  4647. /* Data from ucode file: header followed by uCode images */
  4648. ucode = (void *)ucode_raw->data;
  4649. ver = le32_to_cpu(ucode->ver);
  4650. inst_size = le32_to_cpu(ucode->inst_size);
  4651. data_size = le32_to_cpu(ucode->data_size);
  4652. init_size = le32_to_cpu(ucode->init_size);
  4653. init_data_size = le32_to_cpu(ucode->init_data_size);
  4654. boot_size = le32_to_cpu(ucode->boot_size);
  4655. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  4656. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
  4657. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
  4658. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
  4659. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
  4660. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
  4661. /* Verify size of file vs. image size info in file's header */
  4662. if (ucode_raw->size < sizeof(*ucode) +
  4663. inst_size + data_size + init_size +
  4664. init_data_size + boot_size) {
  4665. IWL_DEBUG_INFO("uCode file size %d too small\n",
  4666. (int)ucode_raw->size);
  4667. ret = -EINVAL;
  4668. goto err_release;
  4669. }
  4670. /* Verify that uCode images will fit in card's SRAM */
  4671. if (inst_size > IWL_MAX_INST_SIZE) {
  4672. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  4673. inst_size);
  4674. ret = -EINVAL;
  4675. goto err_release;
  4676. }
  4677. if (data_size > IWL_MAX_DATA_SIZE) {
  4678. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  4679. data_size);
  4680. ret = -EINVAL;
  4681. goto err_release;
  4682. }
  4683. if (init_size > IWL_MAX_INST_SIZE) {
  4684. IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
  4685. init_size);
  4686. ret = -EINVAL;
  4687. goto err_release;
  4688. }
  4689. if (init_data_size > IWL_MAX_DATA_SIZE) {
  4690. IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
  4691. init_data_size);
  4692. ret = -EINVAL;
  4693. goto err_release;
  4694. }
  4695. if (boot_size > IWL_MAX_BSM_SIZE) {
  4696. IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
  4697. boot_size);
  4698. ret = -EINVAL;
  4699. goto err_release;
  4700. }
  4701. /* Allocate ucode buffers for card's bus-master loading ... */
  4702. /* Runtime instructions and 2 copies of data:
  4703. * 1) unmodified from disk
  4704. * 2) backup cache for save/restore during power-downs */
  4705. priv->ucode_code.len = inst_size;
  4706. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  4707. priv->ucode_data.len = data_size;
  4708. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  4709. priv->ucode_data_backup.len = data_size;
  4710. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  4711. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  4712. !priv->ucode_data_backup.v_addr)
  4713. goto err_pci_alloc;
  4714. /* Initialization instructions and data */
  4715. if (init_size && init_data_size) {
  4716. priv->ucode_init.len = init_size;
  4717. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  4718. priv->ucode_init_data.len = init_data_size;
  4719. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  4720. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  4721. goto err_pci_alloc;
  4722. }
  4723. /* Bootstrap (instructions only, no data) */
  4724. if (boot_size) {
  4725. priv->ucode_boot.len = boot_size;
  4726. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  4727. if (!priv->ucode_boot.v_addr)
  4728. goto err_pci_alloc;
  4729. }
  4730. /* Copy images into buffers for card's bus-master reads ... */
  4731. /* Runtime instructions (first block of data in file) */
  4732. src = &ucode->data[0];
  4733. len = priv->ucode_code.len;
  4734. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  4735. memcpy(priv->ucode_code.v_addr, src, len);
  4736. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  4737. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  4738. /* Runtime data (2nd block)
  4739. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  4740. src = &ucode->data[inst_size];
  4741. len = priv->ucode_data.len;
  4742. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  4743. memcpy(priv->ucode_data.v_addr, src, len);
  4744. memcpy(priv->ucode_data_backup.v_addr, src, len);
  4745. /* Initialization instructions (3rd block) */
  4746. if (init_size) {
  4747. src = &ucode->data[inst_size + data_size];
  4748. len = priv->ucode_init.len;
  4749. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  4750. len);
  4751. memcpy(priv->ucode_init.v_addr, src, len);
  4752. }
  4753. /* Initialization data (4th block) */
  4754. if (init_data_size) {
  4755. src = &ucode->data[inst_size + data_size + init_size];
  4756. len = priv->ucode_init_data.len;
  4757. IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
  4758. (int)len);
  4759. memcpy(priv->ucode_init_data.v_addr, src, len);
  4760. }
  4761. /* Bootstrap instructions (5th block) */
  4762. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  4763. len = priv->ucode_boot.len;
  4764. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
  4765. (int)len);
  4766. memcpy(priv->ucode_boot.v_addr, src, len);
  4767. /* We have our copies now, allow OS release its copies */
  4768. release_firmware(ucode_raw);
  4769. return 0;
  4770. err_pci_alloc:
  4771. IWL_ERROR("failed to allocate pci memory\n");
  4772. ret = -ENOMEM;
  4773. iwl3945_dealloc_ucode_pci(priv);
  4774. err_release:
  4775. release_firmware(ucode_raw);
  4776. error:
  4777. return ret;
  4778. }
  4779. /**
  4780. * iwl3945_set_ucode_ptrs - Set uCode address location
  4781. *
  4782. * Tell initialization uCode where to find runtime uCode.
  4783. *
  4784. * BSM registers initially contain pointers to initialization uCode.
  4785. * We need to replace them to load runtime uCode inst and data,
  4786. * and to save runtime data when powering down.
  4787. */
  4788. static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv)
  4789. {
  4790. dma_addr_t pinst;
  4791. dma_addr_t pdata;
  4792. int rc = 0;
  4793. unsigned long flags;
  4794. /* bits 31:0 for 3945 */
  4795. pinst = priv->ucode_code.p_addr;
  4796. pdata = priv->ucode_data_backup.p_addr;
  4797. spin_lock_irqsave(&priv->lock, flags);
  4798. rc = iwl3945_grab_nic_access(priv);
  4799. if (rc) {
  4800. spin_unlock_irqrestore(&priv->lock, flags);
  4801. return rc;
  4802. }
  4803. /* Tell bootstrap uCode where to find image to load */
  4804. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  4805. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  4806. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  4807. priv->ucode_data.len);
  4808. /* Inst bytecount must be last to set up, bit 31 signals uCode
  4809. * that all new ptr/size info is in place */
  4810. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  4811. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  4812. iwl3945_release_nic_access(priv);
  4813. spin_unlock_irqrestore(&priv->lock, flags);
  4814. IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
  4815. return rc;
  4816. }
  4817. /**
  4818. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  4819. *
  4820. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  4821. *
  4822. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  4823. */
  4824. static void iwl3945_init_alive_start(struct iwl3945_priv *priv)
  4825. {
  4826. /* Check alive response for "valid" sign from uCode */
  4827. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  4828. /* We had an error bringing up the hardware, so take it
  4829. * all the way back down so we can try again */
  4830. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  4831. goto restart;
  4832. }
  4833. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  4834. * This is a paranoid check, because we would not have gotten the
  4835. * "initialize" alive if code weren't properly loaded. */
  4836. if (iwl3945_verify_ucode(priv)) {
  4837. /* Runtime instruction load was bad;
  4838. * take it all the way back down so we can try again */
  4839. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  4840. goto restart;
  4841. }
  4842. /* Send pointers to protocol/runtime uCode image ... init code will
  4843. * load and launch runtime uCode, which will send us another "Alive"
  4844. * notification. */
  4845. IWL_DEBUG_INFO("Initialization Alive received.\n");
  4846. if (iwl3945_set_ucode_ptrs(priv)) {
  4847. /* Runtime instruction load won't happen;
  4848. * take it all the way back down so we can try again */
  4849. IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
  4850. goto restart;
  4851. }
  4852. return;
  4853. restart:
  4854. queue_work(priv->workqueue, &priv->restart);
  4855. }
  4856. /**
  4857. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  4858. * from protocol/runtime uCode (initialization uCode's
  4859. * Alive gets handled by iwl3945_init_alive_start()).
  4860. */
  4861. static void iwl3945_alive_start(struct iwl3945_priv *priv)
  4862. {
  4863. int rc = 0;
  4864. int thermal_spin = 0;
  4865. u32 rfkill;
  4866. IWL_DEBUG_INFO("Runtime Alive received.\n");
  4867. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  4868. /* We had an error bringing up the hardware, so take it
  4869. * all the way back down so we can try again */
  4870. IWL_DEBUG_INFO("Alive failed.\n");
  4871. goto restart;
  4872. }
  4873. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  4874. * This is a paranoid check, because we would not have gotten the
  4875. * "runtime" alive if code weren't properly loaded. */
  4876. if (iwl3945_verify_ucode(priv)) {
  4877. /* Runtime instruction load was bad;
  4878. * take it all the way back down so we can try again */
  4879. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  4880. goto restart;
  4881. }
  4882. iwl3945_clear_stations_table(priv);
  4883. rc = iwl3945_grab_nic_access(priv);
  4884. if (rc) {
  4885. IWL_WARNING("Can not read rfkill status from adapter\n");
  4886. return;
  4887. }
  4888. rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG);
  4889. IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
  4890. iwl3945_release_nic_access(priv);
  4891. if (rfkill & 0x1) {
  4892. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  4893. /* if rfkill is not on, then wait for thermal
  4894. * sensor in adapter to kick in */
  4895. while (iwl3945_hw_get_temperature(priv) == 0) {
  4896. thermal_spin++;
  4897. udelay(10);
  4898. }
  4899. if (thermal_spin)
  4900. IWL_DEBUG_INFO("Thermal calibration took %dus\n",
  4901. thermal_spin * 10);
  4902. } else
  4903. set_bit(STATUS_RF_KILL_HW, &priv->status);
  4904. /* After the ALIVE response, we can send commands to 3945 uCode */
  4905. set_bit(STATUS_ALIVE, &priv->status);
  4906. /* Clear out the uCode error bit if it is set */
  4907. clear_bit(STATUS_FW_ERROR, &priv->status);
  4908. if (iwl3945_is_rfkill(priv))
  4909. return;
  4910. ieee80211_start_queues(priv->hw);
  4911. priv->active_rate = priv->rates_mask;
  4912. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  4913. iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
  4914. if (iwl3945_is_associated(priv)) {
  4915. struct iwl3945_rxon_cmd *active_rxon =
  4916. (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
  4917. memcpy(&priv->staging_rxon, &priv->active_rxon,
  4918. sizeof(priv->staging_rxon));
  4919. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4920. } else {
  4921. /* Initialize our rx_config data */
  4922. iwl3945_connection_init_rx_config(priv);
  4923. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  4924. }
  4925. /* Configure Bluetooth device coexistence support */
  4926. iwl3945_send_bt_config(priv);
  4927. /* Configure the adapter for unassociated operation */
  4928. iwl3945_commit_rxon(priv);
  4929. /* At this point, the NIC is initialized and operational */
  4930. priv->notif_missed_beacons = 0;
  4931. iwl3945_reg_txpower_periodic(priv);
  4932. iwl3945_led_register(priv);
  4933. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  4934. set_bit(STATUS_READY, &priv->status);
  4935. wake_up_interruptible(&priv->wait_command_queue);
  4936. if (priv->error_recovering)
  4937. iwl3945_error_recovery(priv);
  4938. ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
  4939. return;
  4940. restart:
  4941. queue_work(priv->workqueue, &priv->restart);
  4942. }
  4943. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv);
  4944. static void __iwl3945_down(struct iwl3945_priv *priv)
  4945. {
  4946. unsigned long flags;
  4947. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  4948. struct ieee80211_conf *conf = NULL;
  4949. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  4950. conf = ieee80211_get_hw_conf(priv->hw);
  4951. if (!exit_pending)
  4952. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4953. iwl3945_led_unregister(priv);
  4954. iwl3945_clear_stations_table(priv);
  4955. /* Unblock any waiting calls */
  4956. wake_up_interruptible_all(&priv->wait_command_queue);
  4957. /* Wipe out the EXIT_PENDING status bit if we are not actually
  4958. * exiting the module */
  4959. if (!exit_pending)
  4960. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  4961. /* stop and reset the on-board processor */
  4962. iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  4963. /* tell the device to stop sending interrupts */
  4964. spin_lock_irqsave(&priv->lock, flags);
  4965. iwl3945_disable_interrupts(priv);
  4966. spin_unlock_irqrestore(&priv->lock, flags);
  4967. iwl_synchronize_irq(priv);
  4968. if (priv->mac80211_registered)
  4969. ieee80211_stop_queues(priv->hw);
  4970. /* If we have not previously called iwl3945_init() then
  4971. * clear all bits but the RF Kill and SUSPEND bits and return */
  4972. if (!iwl3945_is_init(priv)) {
  4973. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  4974. STATUS_RF_KILL_HW |
  4975. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  4976. STATUS_RF_KILL_SW |
  4977. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  4978. STATUS_GEO_CONFIGURED |
  4979. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  4980. STATUS_IN_SUSPEND;
  4981. goto exit;
  4982. }
  4983. /* ...otherwise clear out all the status bits but the RF Kill and
  4984. * SUSPEND bits and continue taking the NIC down. */
  4985. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  4986. STATUS_RF_KILL_HW |
  4987. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  4988. STATUS_RF_KILL_SW |
  4989. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  4990. STATUS_GEO_CONFIGURED |
  4991. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  4992. STATUS_IN_SUSPEND |
  4993. test_bit(STATUS_FW_ERROR, &priv->status) <<
  4994. STATUS_FW_ERROR;
  4995. spin_lock_irqsave(&priv->lock, flags);
  4996. iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  4997. spin_unlock_irqrestore(&priv->lock, flags);
  4998. iwl3945_hw_txq_ctx_stop(priv);
  4999. iwl3945_hw_rxq_stop(priv);
  5000. spin_lock_irqsave(&priv->lock, flags);
  5001. if (!iwl3945_grab_nic_access(priv)) {
  5002. iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
  5003. APMG_CLK_VAL_DMA_CLK_RQT);
  5004. iwl3945_release_nic_access(priv);
  5005. }
  5006. spin_unlock_irqrestore(&priv->lock, flags);
  5007. udelay(5);
  5008. iwl3945_hw_nic_stop_master(priv);
  5009. iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  5010. iwl3945_hw_nic_reset(priv);
  5011. exit:
  5012. memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp));
  5013. if (priv->ibss_beacon)
  5014. dev_kfree_skb(priv->ibss_beacon);
  5015. priv->ibss_beacon = NULL;
  5016. /* clear out any free frames */
  5017. iwl3945_clear_free_frames(priv);
  5018. }
  5019. static void iwl3945_down(struct iwl3945_priv *priv)
  5020. {
  5021. mutex_lock(&priv->mutex);
  5022. __iwl3945_down(priv);
  5023. mutex_unlock(&priv->mutex);
  5024. iwl3945_cancel_deferred_work(priv);
  5025. }
  5026. #define MAX_HW_RESTARTS 5
  5027. static int __iwl3945_up(struct iwl3945_priv *priv)
  5028. {
  5029. int rc, i;
  5030. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5031. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  5032. return -EIO;
  5033. }
  5034. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  5035. IWL_WARNING("Radio disabled by SW RF kill (module "
  5036. "parameter)\n");
  5037. return -ENODEV;
  5038. }
  5039. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  5040. IWL_ERROR("ucode not available for device bringup\n");
  5041. return -EIO;
  5042. }
  5043. /* If platform's RF_KILL switch is NOT set to KILL */
  5044. if (iwl3945_read32(priv, CSR_GP_CNTRL) &
  5045. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  5046. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  5047. else {
  5048. set_bit(STATUS_RF_KILL_HW, &priv->status);
  5049. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  5050. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  5051. return -ENODEV;
  5052. }
  5053. }
  5054. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5055. rc = iwl3945_hw_nic_init(priv);
  5056. if (rc) {
  5057. IWL_ERROR("Unable to int nic\n");
  5058. return rc;
  5059. }
  5060. /* make sure rfkill handshake bits are cleared */
  5061. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5062. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  5063. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  5064. /* clear (again), then enable host interrupts */
  5065. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5066. iwl3945_enable_interrupts(priv);
  5067. /* really make sure rfkill handshake bits are cleared */
  5068. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5069. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5070. /* Copy original ucode data image from disk into backup cache.
  5071. * This will be used to initialize the on-board processor's
  5072. * data SRAM for a clean start when the runtime program first loads. */
  5073. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  5074. priv->ucode_data.len);
  5075. /* We return success when we resume from suspend and rf_kill is on. */
  5076. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  5077. return 0;
  5078. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  5079. iwl3945_clear_stations_table(priv);
  5080. /* load bootstrap state machine,
  5081. * load bootstrap program into processor's memory,
  5082. * prepare to load the "initialize" uCode */
  5083. rc = iwl3945_load_bsm(priv);
  5084. if (rc) {
  5085. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
  5086. continue;
  5087. }
  5088. /* start card; "initialize" will load runtime ucode */
  5089. iwl3945_nic_start(priv);
  5090. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  5091. return 0;
  5092. }
  5093. set_bit(STATUS_EXIT_PENDING, &priv->status);
  5094. __iwl3945_down(priv);
  5095. /* tried to restart and config the device for as long as our
  5096. * patience could withstand */
  5097. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  5098. return -EIO;
  5099. }
  5100. /*****************************************************************************
  5101. *
  5102. * Workqueue callbacks
  5103. *
  5104. *****************************************************************************/
  5105. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  5106. {
  5107. struct iwl3945_priv *priv =
  5108. container_of(data, struct iwl3945_priv, init_alive_start.work);
  5109. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5110. return;
  5111. mutex_lock(&priv->mutex);
  5112. iwl3945_init_alive_start(priv);
  5113. mutex_unlock(&priv->mutex);
  5114. }
  5115. static void iwl3945_bg_alive_start(struct work_struct *data)
  5116. {
  5117. struct iwl3945_priv *priv =
  5118. container_of(data, struct iwl3945_priv, alive_start.work);
  5119. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5120. return;
  5121. mutex_lock(&priv->mutex);
  5122. iwl3945_alive_start(priv);
  5123. mutex_unlock(&priv->mutex);
  5124. }
  5125. static void iwl3945_bg_rf_kill(struct work_struct *work)
  5126. {
  5127. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill);
  5128. wake_up_interruptible(&priv->wait_command_queue);
  5129. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5130. return;
  5131. mutex_lock(&priv->mutex);
  5132. if (!iwl3945_is_rfkill(priv)) {
  5133. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
  5134. "HW and/or SW RF Kill no longer active, restarting "
  5135. "device\n");
  5136. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5137. queue_work(priv->workqueue, &priv->restart);
  5138. } else {
  5139. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  5140. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  5141. "disabled by SW switch\n");
  5142. else
  5143. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  5144. "Kill switch must be turned off for "
  5145. "wireless networking to work.\n");
  5146. }
  5147. mutex_unlock(&priv->mutex);
  5148. }
  5149. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  5150. static void iwl3945_bg_scan_check(struct work_struct *data)
  5151. {
  5152. struct iwl3945_priv *priv =
  5153. container_of(data, struct iwl3945_priv, scan_check.work);
  5154. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5155. return;
  5156. mutex_lock(&priv->mutex);
  5157. if (test_bit(STATUS_SCANNING, &priv->status) ||
  5158. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5159. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
  5160. "Scan completion watchdog resetting adapter (%dms)\n",
  5161. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  5162. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5163. iwl3945_send_scan_abort(priv);
  5164. }
  5165. mutex_unlock(&priv->mutex);
  5166. }
  5167. static void iwl3945_bg_request_scan(struct work_struct *data)
  5168. {
  5169. struct iwl3945_priv *priv =
  5170. container_of(data, struct iwl3945_priv, request_scan);
  5171. struct iwl3945_host_cmd cmd = {
  5172. .id = REPLY_SCAN_CMD,
  5173. .len = sizeof(struct iwl3945_scan_cmd),
  5174. .meta.flags = CMD_SIZE_HUGE,
  5175. };
  5176. int rc = 0;
  5177. struct iwl3945_scan_cmd *scan;
  5178. struct ieee80211_conf *conf = NULL;
  5179. u8 direct_mask;
  5180. enum ieee80211_band band;
  5181. conf = ieee80211_get_hw_conf(priv->hw);
  5182. mutex_lock(&priv->mutex);
  5183. if (!iwl3945_is_ready(priv)) {
  5184. IWL_WARNING("request scan called when driver not ready.\n");
  5185. goto done;
  5186. }
  5187. /* Make sure the scan wasn't cancelled before this queued work
  5188. * was given the chance to run... */
  5189. if (!test_bit(STATUS_SCANNING, &priv->status))
  5190. goto done;
  5191. /* This should never be called or scheduled if there is currently
  5192. * a scan active in the hardware. */
  5193. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  5194. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  5195. "Ignoring second request.\n");
  5196. rc = -EIO;
  5197. goto done;
  5198. }
  5199. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5200. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  5201. goto done;
  5202. }
  5203. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5204. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  5205. goto done;
  5206. }
  5207. if (iwl3945_is_rfkill(priv)) {
  5208. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  5209. goto done;
  5210. }
  5211. if (!test_bit(STATUS_READY, &priv->status)) {
  5212. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  5213. goto done;
  5214. }
  5215. if (!priv->scan_bands) {
  5216. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  5217. goto done;
  5218. }
  5219. if (!priv->scan) {
  5220. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  5221. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  5222. if (!priv->scan) {
  5223. rc = -ENOMEM;
  5224. goto done;
  5225. }
  5226. }
  5227. scan = priv->scan;
  5228. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  5229. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  5230. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  5231. if (iwl3945_is_associated(priv)) {
  5232. u16 interval = 0;
  5233. u32 extra;
  5234. u32 suspend_time = 100;
  5235. u32 scan_suspend_time = 100;
  5236. unsigned long flags;
  5237. IWL_DEBUG_INFO("Scanning while associated...\n");
  5238. spin_lock_irqsave(&priv->lock, flags);
  5239. interval = priv->beacon_int;
  5240. spin_unlock_irqrestore(&priv->lock, flags);
  5241. scan->suspend_time = 0;
  5242. scan->max_out_time = cpu_to_le32(200 * 1024);
  5243. if (!interval)
  5244. interval = suspend_time;
  5245. /*
  5246. * suspend time format:
  5247. * 0-19: beacon interval in usec (time before exec.)
  5248. * 20-23: 0
  5249. * 24-31: number of beacons (suspend between channels)
  5250. */
  5251. extra = (suspend_time / interval) << 24;
  5252. scan_suspend_time = 0xFF0FFFFF &
  5253. (extra | ((suspend_time % interval) * 1024));
  5254. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  5255. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  5256. scan_suspend_time, interval);
  5257. }
  5258. /* We should add the ability for user to lock to PASSIVE ONLY */
  5259. if (priv->one_direct_scan) {
  5260. IWL_DEBUG_SCAN
  5261. ("Kicking off one direct scan for '%s'\n",
  5262. iwl3945_escape_essid(priv->direct_ssid,
  5263. priv->direct_ssid_len));
  5264. scan->direct_scan[0].id = WLAN_EID_SSID;
  5265. scan->direct_scan[0].len = priv->direct_ssid_len;
  5266. memcpy(scan->direct_scan[0].ssid,
  5267. priv->direct_ssid, priv->direct_ssid_len);
  5268. direct_mask = 1;
  5269. } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
  5270. IWL_DEBUG_SCAN
  5271. ("Kicking off one direct scan for '%s' when not associated\n",
  5272. iwl3945_escape_essid(priv->essid, priv->essid_len));
  5273. scan->direct_scan[0].id = WLAN_EID_SSID;
  5274. scan->direct_scan[0].len = priv->essid_len;
  5275. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  5276. direct_mask = 1;
  5277. } else {
  5278. IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
  5279. direct_mask = 0;
  5280. }
  5281. /* We don't build a direct scan probe request; the uCode will do
  5282. * that based on the direct_mask added to each channel entry */
  5283. scan->tx_cmd.len = cpu_to_le16(
  5284. iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
  5285. IWL_MAX_SCAN_SIZE - sizeof(*scan), 0));
  5286. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  5287. scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
  5288. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  5289. /* flags + rate selection */
  5290. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
  5291. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  5292. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  5293. scan->good_CRC_th = 0;
  5294. band = IEEE80211_BAND_2GHZ;
  5295. } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
  5296. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  5297. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  5298. band = IEEE80211_BAND_5GHZ;
  5299. } else {
  5300. IWL_WARNING("Invalid scan band count\n");
  5301. goto done;
  5302. }
  5303. /* select Rx antennas */
  5304. scan->flags |= iwl3945_get_antenna_flags(priv);
  5305. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  5306. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  5307. if (direct_mask)
  5308. scan->channel_count =
  5309. iwl3945_get_channels_for_scan(
  5310. priv, band, 1, /* active */
  5311. direct_mask,
  5312. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  5313. else
  5314. scan->channel_count =
  5315. iwl3945_get_channels_for_scan(
  5316. priv, band, 0, /* passive */
  5317. direct_mask,
  5318. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  5319. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  5320. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  5321. cmd.data = scan;
  5322. scan->len = cpu_to_le16(cmd.len);
  5323. set_bit(STATUS_SCAN_HW, &priv->status);
  5324. rc = iwl3945_send_cmd_sync(priv, &cmd);
  5325. if (rc)
  5326. goto done;
  5327. queue_delayed_work(priv->workqueue, &priv->scan_check,
  5328. IWL_SCAN_CHECK_WATCHDOG);
  5329. mutex_unlock(&priv->mutex);
  5330. return;
  5331. done:
  5332. /* inform mac80211 scan aborted */
  5333. queue_work(priv->workqueue, &priv->scan_completed);
  5334. mutex_unlock(&priv->mutex);
  5335. }
  5336. static void iwl3945_bg_up(struct work_struct *data)
  5337. {
  5338. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up);
  5339. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5340. return;
  5341. mutex_lock(&priv->mutex);
  5342. __iwl3945_up(priv);
  5343. mutex_unlock(&priv->mutex);
  5344. }
  5345. static void iwl3945_bg_restart(struct work_struct *data)
  5346. {
  5347. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart);
  5348. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5349. return;
  5350. iwl3945_down(priv);
  5351. queue_work(priv->workqueue, &priv->up);
  5352. }
  5353. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  5354. {
  5355. struct iwl3945_priv *priv =
  5356. container_of(data, struct iwl3945_priv, rx_replenish);
  5357. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5358. return;
  5359. mutex_lock(&priv->mutex);
  5360. iwl3945_rx_replenish(priv);
  5361. mutex_unlock(&priv->mutex);
  5362. }
  5363. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  5364. static void iwl3945_bg_post_associate(struct work_struct *data)
  5365. {
  5366. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
  5367. post_associate.work);
  5368. int rc = 0;
  5369. struct ieee80211_conf *conf = NULL;
  5370. DECLARE_MAC_BUF(mac);
  5371. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  5372. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  5373. return;
  5374. }
  5375. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  5376. priv->assoc_id,
  5377. print_mac(mac, priv->active_rxon.bssid_addr));
  5378. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5379. return;
  5380. mutex_lock(&priv->mutex);
  5381. if (!priv->vif || !priv->is_open) {
  5382. mutex_unlock(&priv->mutex);
  5383. return;
  5384. }
  5385. iwl3945_scan_cancel_timeout(priv, 200);
  5386. conf = ieee80211_get_hw_conf(priv->hw);
  5387. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5388. iwl3945_commit_rxon(priv);
  5389. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5390. iwl3945_setup_rxon_timing(priv);
  5391. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5392. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5393. if (rc)
  5394. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5395. "Attempting to continue.\n");
  5396. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5397. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5398. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  5399. priv->assoc_id, priv->beacon_int);
  5400. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5401. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  5402. else
  5403. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5404. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5405. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5406. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  5407. else
  5408. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5409. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5410. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5411. }
  5412. iwl3945_commit_rxon(priv);
  5413. switch (priv->iw_mode) {
  5414. case IEEE80211_IF_TYPE_STA:
  5415. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  5416. break;
  5417. case IEEE80211_IF_TYPE_IBSS:
  5418. /* clear out the station table */
  5419. iwl3945_clear_stations_table(priv);
  5420. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5421. iwl3945_add_station(priv, priv->bssid, 0, 0);
  5422. iwl3945_sync_sta(priv, IWL_STA_ID,
  5423. (priv->band == IEEE80211_BAND_5GHZ) ?
  5424. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  5425. CMD_ASYNC);
  5426. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  5427. iwl3945_send_beacon_cmd(priv);
  5428. break;
  5429. default:
  5430. IWL_ERROR("%s Should not be called in %d mode\n",
  5431. __FUNCTION__, priv->iw_mode);
  5432. break;
  5433. }
  5434. iwl3945_sequence_reset(priv);
  5435. iwl3945_activate_qos(priv, 0);
  5436. /* we have just associated, don't start scan too early */
  5437. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  5438. mutex_unlock(&priv->mutex);
  5439. }
  5440. static void iwl3945_bg_abort_scan(struct work_struct *work)
  5441. {
  5442. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan);
  5443. if (!iwl3945_is_ready(priv))
  5444. return;
  5445. mutex_lock(&priv->mutex);
  5446. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  5447. iwl3945_send_scan_abort(priv);
  5448. mutex_unlock(&priv->mutex);
  5449. }
  5450. static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  5451. static void iwl3945_bg_scan_completed(struct work_struct *work)
  5452. {
  5453. struct iwl3945_priv *priv =
  5454. container_of(work, struct iwl3945_priv, scan_completed);
  5455. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
  5456. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5457. return;
  5458. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  5459. iwl3945_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  5460. ieee80211_scan_completed(priv->hw);
  5461. /* Since setting the TXPOWER may have been deferred while
  5462. * performing the scan, fire one off */
  5463. mutex_lock(&priv->mutex);
  5464. iwl3945_hw_reg_send_txpower(priv);
  5465. mutex_unlock(&priv->mutex);
  5466. }
  5467. /*****************************************************************************
  5468. *
  5469. * mac80211 entry point functions
  5470. *
  5471. *****************************************************************************/
  5472. #define UCODE_READY_TIMEOUT (2 * HZ)
  5473. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  5474. {
  5475. struct iwl3945_priv *priv = hw->priv;
  5476. int ret;
  5477. IWL_DEBUG_MAC80211("enter\n");
  5478. if (pci_enable_device(priv->pci_dev)) {
  5479. IWL_ERROR("Fail to pci_enable_device\n");
  5480. return -ENODEV;
  5481. }
  5482. pci_restore_state(priv->pci_dev);
  5483. pci_enable_msi(priv->pci_dev);
  5484. ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
  5485. DRV_NAME, priv);
  5486. if (ret) {
  5487. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  5488. goto out_disable_msi;
  5489. }
  5490. /* we should be verifying the device is ready to be opened */
  5491. mutex_lock(&priv->mutex);
  5492. memset(&priv->staging_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
  5493. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  5494. * ucode filename and max sizes are card-specific. */
  5495. if (!priv->ucode_code.len) {
  5496. ret = iwl3945_read_ucode(priv);
  5497. if (ret) {
  5498. IWL_ERROR("Could not read microcode: %d\n", ret);
  5499. mutex_unlock(&priv->mutex);
  5500. goto out_release_irq;
  5501. }
  5502. }
  5503. ret = __iwl3945_up(priv);
  5504. mutex_unlock(&priv->mutex);
  5505. if (ret)
  5506. goto out_release_irq;
  5507. IWL_DEBUG_INFO("Start UP work.\n");
  5508. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  5509. return 0;
  5510. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  5511. * mac80211 will not be run successfully. */
  5512. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  5513. test_bit(STATUS_READY, &priv->status),
  5514. UCODE_READY_TIMEOUT);
  5515. if (!ret) {
  5516. if (!test_bit(STATUS_READY, &priv->status)) {
  5517. IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
  5518. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  5519. ret = -ETIMEDOUT;
  5520. goto out_release_irq;
  5521. }
  5522. }
  5523. priv->is_open = 1;
  5524. IWL_DEBUG_MAC80211("leave\n");
  5525. return 0;
  5526. out_release_irq:
  5527. free_irq(priv->pci_dev->irq, priv);
  5528. out_disable_msi:
  5529. pci_disable_msi(priv->pci_dev);
  5530. pci_disable_device(priv->pci_dev);
  5531. priv->is_open = 0;
  5532. IWL_DEBUG_MAC80211("leave - failed\n");
  5533. return ret;
  5534. }
  5535. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  5536. {
  5537. struct iwl3945_priv *priv = hw->priv;
  5538. IWL_DEBUG_MAC80211("enter\n");
  5539. if (!priv->is_open) {
  5540. IWL_DEBUG_MAC80211("leave - skip\n");
  5541. return;
  5542. }
  5543. priv->is_open = 0;
  5544. if (iwl3945_is_ready_rf(priv)) {
  5545. /* stop mac, cancel any scan request and clear
  5546. * RXON_FILTER_ASSOC_MSK BIT
  5547. */
  5548. mutex_lock(&priv->mutex);
  5549. iwl3945_scan_cancel_timeout(priv, 100);
  5550. cancel_delayed_work(&priv->post_associate);
  5551. mutex_unlock(&priv->mutex);
  5552. }
  5553. iwl3945_down(priv);
  5554. flush_workqueue(priv->workqueue);
  5555. free_irq(priv->pci_dev->irq, priv);
  5556. pci_disable_msi(priv->pci_dev);
  5557. pci_save_state(priv->pci_dev);
  5558. pci_disable_device(priv->pci_dev);
  5559. IWL_DEBUG_MAC80211("leave\n");
  5560. }
  5561. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  5562. struct ieee80211_tx_control *ctl)
  5563. {
  5564. struct iwl3945_priv *priv = hw->priv;
  5565. IWL_DEBUG_MAC80211("enter\n");
  5566. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  5567. IWL_DEBUG_MAC80211("leave - monitor\n");
  5568. dev_kfree_skb_any(skb);
  5569. return 0;
  5570. }
  5571. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  5572. ctl->tx_rate->bitrate);
  5573. if (iwl3945_tx_skb(priv, skb, ctl))
  5574. dev_kfree_skb_any(skb);
  5575. IWL_DEBUG_MAC80211("leave\n");
  5576. return 0;
  5577. }
  5578. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  5579. struct ieee80211_if_init_conf *conf)
  5580. {
  5581. struct iwl3945_priv *priv = hw->priv;
  5582. unsigned long flags;
  5583. DECLARE_MAC_BUF(mac);
  5584. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  5585. if (priv->vif) {
  5586. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  5587. return -EOPNOTSUPP;
  5588. }
  5589. spin_lock_irqsave(&priv->lock, flags);
  5590. priv->vif = conf->vif;
  5591. spin_unlock_irqrestore(&priv->lock, flags);
  5592. mutex_lock(&priv->mutex);
  5593. if (conf->mac_addr) {
  5594. IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr));
  5595. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  5596. }
  5597. if (iwl3945_is_ready(priv))
  5598. iwl3945_set_mode(priv, conf->type);
  5599. mutex_unlock(&priv->mutex);
  5600. IWL_DEBUG_MAC80211("leave\n");
  5601. return 0;
  5602. }
  5603. /**
  5604. * iwl3945_mac_config - mac80211 config callback
  5605. *
  5606. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  5607. * be set inappropriately and the driver currently sets the hardware up to
  5608. * use it whenever needed.
  5609. */
  5610. static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  5611. {
  5612. struct iwl3945_priv *priv = hw->priv;
  5613. const struct iwl3945_channel_info *ch_info;
  5614. unsigned long flags;
  5615. int ret = 0;
  5616. mutex_lock(&priv->mutex);
  5617. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  5618. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  5619. if (!iwl3945_is_ready(priv)) {
  5620. IWL_DEBUG_MAC80211("leave - not ready\n");
  5621. ret = -EIO;
  5622. goto out;
  5623. }
  5624. if (unlikely(!iwl3945_param_disable_hw_scan &&
  5625. test_bit(STATUS_SCANNING, &priv->status))) {
  5626. IWL_DEBUG_MAC80211("leave - scanning\n");
  5627. set_bit(STATUS_CONF_PENDING, &priv->status);
  5628. mutex_unlock(&priv->mutex);
  5629. return 0;
  5630. }
  5631. spin_lock_irqsave(&priv->lock, flags);
  5632. ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
  5633. conf->channel->hw_value);
  5634. if (!is_channel_valid(ch_info)) {
  5635. IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
  5636. conf->channel->hw_value, conf->channel->band);
  5637. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  5638. spin_unlock_irqrestore(&priv->lock, flags);
  5639. ret = -EINVAL;
  5640. goto out;
  5641. }
  5642. iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
  5643. iwl3945_set_flags_for_phymode(priv, conf->channel->band);
  5644. /* The list of supported rates and rate mask can be different
  5645. * for each phymode; since the phymode may have changed, reset
  5646. * the rate mask to what mac80211 lists */
  5647. iwl3945_set_rate(priv);
  5648. spin_unlock_irqrestore(&priv->lock, flags);
  5649. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  5650. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  5651. iwl3945_hw_channel_switch(priv, conf->channel);
  5652. goto out;
  5653. }
  5654. #endif
  5655. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  5656. if (!conf->radio_enabled) {
  5657. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  5658. goto out;
  5659. }
  5660. if (iwl3945_is_rfkill(priv)) {
  5661. IWL_DEBUG_MAC80211("leave - RF kill\n");
  5662. ret = -EIO;
  5663. goto out;
  5664. }
  5665. iwl3945_set_rate(priv);
  5666. if (memcmp(&priv->active_rxon,
  5667. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  5668. iwl3945_commit_rxon(priv);
  5669. else
  5670. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  5671. IWL_DEBUG_MAC80211("leave\n");
  5672. out:
  5673. clear_bit(STATUS_CONF_PENDING, &priv->status);
  5674. mutex_unlock(&priv->mutex);
  5675. return ret;
  5676. }
  5677. static void iwl3945_config_ap(struct iwl3945_priv *priv)
  5678. {
  5679. int rc = 0;
  5680. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5681. return;
  5682. /* The following should be done only at AP bring up */
  5683. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  5684. /* RXON - unassoc (to set timing command) */
  5685. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5686. iwl3945_commit_rxon(priv);
  5687. /* RXON Timing */
  5688. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5689. iwl3945_setup_rxon_timing(priv);
  5690. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5691. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5692. if (rc)
  5693. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5694. "Attempting to continue.\n");
  5695. /* FIXME: what should be the assoc_id for AP? */
  5696. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5697. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5698. priv->staging_rxon.flags |=
  5699. RXON_FLG_SHORT_PREAMBLE_MSK;
  5700. else
  5701. priv->staging_rxon.flags &=
  5702. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5703. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5704. if (priv->assoc_capability &
  5705. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5706. priv->staging_rxon.flags |=
  5707. RXON_FLG_SHORT_SLOT_MSK;
  5708. else
  5709. priv->staging_rxon.flags &=
  5710. ~RXON_FLG_SHORT_SLOT_MSK;
  5711. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5712. priv->staging_rxon.flags &=
  5713. ~RXON_FLG_SHORT_SLOT_MSK;
  5714. }
  5715. /* restore RXON assoc */
  5716. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5717. iwl3945_commit_rxon(priv);
  5718. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5719. }
  5720. iwl3945_send_beacon_cmd(priv);
  5721. /* FIXME - we need to add code here to detect a totally new
  5722. * configuration, reset the AP, unassoc, rxon timing, assoc,
  5723. * clear sta table, add BCAST sta... */
  5724. }
  5725. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
  5726. struct ieee80211_vif *vif,
  5727. struct ieee80211_if_conf *conf)
  5728. {
  5729. struct iwl3945_priv *priv = hw->priv;
  5730. DECLARE_MAC_BUF(mac);
  5731. unsigned long flags;
  5732. int rc;
  5733. if (conf == NULL)
  5734. return -EIO;
  5735. if (priv->vif != vif) {
  5736. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  5737. return 0;
  5738. }
  5739. /* XXX: this MUST use conf->mac_addr */
  5740. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  5741. (!conf->beacon || !conf->ssid_len)) {
  5742. IWL_DEBUG_MAC80211
  5743. ("Leaving in AP mode because HostAPD is not ready.\n");
  5744. return 0;
  5745. }
  5746. if (!iwl3945_is_alive(priv))
  5747. return -EAGAIN;
  5748. mutex_lock(&priv->mutex);
  5749. if (conf->bssid)
  5750. IWL_DEBUG_MAC80211("bssid: %s\n",
  5751. print_mac(mac, conf->bssid));
  5752. /*
  5753. * very dubious code was here; the probe filtering flag is never set:
  5754. *
  5755. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  5756. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  5757. */
  5758. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  5759. if (!conf->bssid) {
  5760. conf->bssid = priv->mac_addr;
  5761. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  5762. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  5763. print_mac(mac, conf->bssid));
  5764. }
  5765. if (priv->ibss_beacon)
  5766. dev_kfree_skb(priv->ibss_beacon);
  5767. priv->ibss_beacon = conf->beacon;
  5768. }
  5769. if (iwl3945_is_rfkill(priv))
  5770. goto done;
  5771. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  5772. !is_multicast_ether_addr(conf->bssid)) {
  5773. /* If there is currently a HW scan going on in the background
  5774. * then we need to cancel it else the RXON below will fail. */
  5775. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  5776. IWL_WARNING("Aborted scan still in progress "
  5777. "after 100ms\n");
  5778. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  5779. mutex_unlock(&priv->mutex);
  5780. return -EAGAIN;
  5781. }
  5782. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  5783. /* TODO: Audit driver for usage of these members and see
  5784. * if mac80211 deprecates them (priv->bssid looks like it
  5785. * shouldn't be there, but I haven't scanned the IBSS code
  5786. * to verify) - jpk */
  5787. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  5788. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  5789. iwl3945_config_ap(priv);
  5790. else {
  5791. rc = iwl3945_commit_rxon(priv);
  5792. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  5793. iwl3945_add_station(priv,
  5794. priv->active_rxon.bssid_addr, 1, 0);
  5795. }
  5796. } else {
  5797. iwl3945_scan_cancel_timeout(priv, 100);
  5798. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5799. iwl3945_commit_rxon(priv);
  5800. }
  5801. done:
  5802. spin_lock_irqsave(&priv->lock, flags);
  5803. if (!conf->ssid_len)
  5804. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  5805. else
  5806. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  5807. priv->essid_len = conf->ssid_len;
  5808. spin_unlock_irqrestore(&priv->lock, flags);
  5809. IWL_DEBUG_MAC80211("leave\n");
  5810. mutex_unlock(&priv->mutex);
  5811. return 0;
  5812. }
  5813. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  5814. unsigned int changed_flags,
  5815. unsigned int *total_flags,
  5816. int mc_count, struct dev_addr_list *mc_list)
  5817. {
  5818. /*
  5819. * XXX: dummy
  5820. * see also iwl3945_connection_init_rx_config
  5821. */
  5822. *total_flags = 0;
  5823. }
  5824. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  5825. struct ieee80211_if_init_conf *conf)
  5826. {
  5827. struct iwl3945_priv *priv = hw->priv;
  5828. IWL_DEBUG_MAC80211("enter\n");
  5829. mutex_lock(&priv->mutex);
  5830. if (iwl3945_is_ready_rf(priv)) {
  5831. iwl3945_scan_cancel_timeout(priv, 100);
  5832. cancel_delayed_work(&priv->post_associate);
  5833. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5834. iwl3945_commit_rxon(priv);
  5835. }
  5836. if (priv->vif == conf->vif) {
  5837. priv->vif = NULL;
  5838. memset(priv->bssid, 0, ETH_ALEN);
  5839. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  5840. priv->essid_len = 0;
  5841. }
  5842. mutex_unlock(&priv->mutex);
  5843. IWL_DEBUG_MAC80211("leave\n");
  5844. }
  5845. static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  5846. {
  5847. int rc = 0;
  5848. unsigned long flags;
  5849. struct iwl3945_priv *priv = hw->priv;
  5850. IWL_DEBUG_MAC80211("enter\n");
  5851. mutex_lock(&priv->mutex);
  5852. spin_lock_irqsave(&priv->lock, flags);
  5853. if (!iwl3945_is_ready_rf(priv)) {
  5854. rc = -EIO;
  5855. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  5856. goto out_unlock;
  5857. }
  5858. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  5859. rc = -EIO;
  5860. IWL_ERROR("ERROR: APs don't scan\n");
  5861. goto out_unlock;
  5862. }
  5863. /* we don't schedule scan within next_scan_jiffies period */
  5864. if (priv->next_scan_jiffies &&
  5865. time_after(priv->next_scan_jiffies, jiffies)) {
  5866. rc = -EAGAIN;
  5867. goto out_unlock;
  5868. }
  5869. /* if we just finished scan ask for delay */
  5870. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  5871. IWL_DELAY_NEXT_SCAN, jiffies)) {
  5872. rc = -EAGAIN;
  5873. goto out_unlock;
  5874. }
  5875. if (len) {
  5876. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  5877. iwl3945_escape_essid(ssid, len), (int)len);
  5878. priv->one_direct_scan = 1;
  5879. priv->direct_ssid_len = (u8)
  5880. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  5881. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  5882. } else
  5883. priv->one_direct_scan = 0;
  5884. rc = iwl3945_scan_initiate(priv);
  5885. IWL_DEBUG_MAC80211("leave\n");
  5886. out_unlock:
  5887. spin_unlock_irqrestore(&priv->lock, flags);
  5888. mutex_unlock(&priv->mutex);
  5889. return rc;
  5890. }
  5891. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  5892. const u8 *local_addr, const u8 *addr,
  5893. struct ieee80211_key_conf *key)
  5894. {
  5895. struct iwl3945_priv *priv = hw->priv;
  5896. int rc = 0;
  5897. u8 sta_id;
  5898. IWL_DEBUG_MAC80211("enter\n");
  5899. if (!iwl3945_param_hwcrypto) {
  5900. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  5901. return -EOPNOTSUPP;
  5902. }
  5903. if (is_zero_ether_addr(addr))
  5904. /* only support pairwise keys */
  5905. return -EOPNOTSUPP;
  5906. sta_id = iwl3945_hw_find_station(priv, addr);
  5907. if (sta_id == IWL_INVALID_STATION) {
  5908. DECLARE_MAC_BUF(mac);
  5909. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  5910. print_mac(mac, addr));
  5911. return -EINVAL;
  5912. }
  5913. mutex_lock(&priv->mutex);
  5914. iwl3945_scan_cancel_timeout(priv, 100);
  5915. switch (cmd) {
  5916. case SET_KEY:
  5917. rc = iwl3945_update_sta_key_info(priv, key, sta_id);
  5918. if (!rc) {
  5919. iwl3945_set_rxon_hwcrypto(priv, 1);
  5920. iwl3945_commit_rxon(priv);
  5921. key->hw_key_idx = sta_id;
  5922. IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
  5923. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  5924. }
  5925. break;
  5926. case DISABLE_KEY:
  5927. rc = iwl3945_clear_sta_key_info(priv, sta_id);
  5928. if (!rc) {
  5929. iwl3945_set_rxon_hwcrypto(priv, 0);
  5930. iwl3945_commit_rxon(priv);
  5931. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  5932. }
  5933. break;
  5934. default:
  5935. rc = -EINVAL;
  5936. }
  5937. IWL_DEBUG_MAC80211("leave\n");
  5938. mutex_unlock(&priv->mutex);
  5939. return rc;
  5940. }
  5941. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
  5942. const struct ieee80211_tx_queue_params *params)
  5943. {
  5944. struct iwl3945_priv *priv = hw->priv;
  5945. unsigned long flags;
  5946. int q;
  5947. IWL_DEBUG_MAC80211("enter\n");
  5948. if (!iwl3945_is_ready_rf(priv)) {
  5949. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  5950. return -EIO;
  5951. }
  5952. if (queue >= AC_NUM) {
  5953. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  5954. return 0;
  5955. }
  5956. if (!priv->qos_data.qos_enable) {
  5957. priv->qos_data.qos_active = 0;
  5958. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  5959. return 0;
  5960. }
  5961. q = AC_NUM - 1 - queue;
  5962. spin_lock_irqsave(&priv->lock, flags);
  5963. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  5964. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  5965. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  5966. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  5967. cpu_to_le16((params->txop * 32));
  5968. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  5969. priv->qos_data.qos_active = 1;
  5970. spin_unlock_irqrestore(&priv->lock, flags);
  5971. mutex_lock(&priv->mutex);
  5972. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  5973. iwl3945_activate_qos(priv, 1);
  5974. else if (priv->assoc_id && iwl3945_is_associated(priv))
  5975. iwl3945_activate_qos(priv, 0);
  5976. mutex_unlock(&priv->mutex);
  5977. IWL_DEBUG_MAC80211("leave\n");
  5978. return 0;
  5979. }
  5980. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  5981. struct ieee80211_tx_queue_stats *stats)
  5982. {
  5983. struct iwl3945_priv *priv = hw->priv;
  5984. int i, avail;
  5985. struct iwl3945_tx_queue *txq;
  5986. struct iwl3945_queue *q;
  5987. unsigned long flags;
  5988. IWL_DEBUG_MAC80211("enter\n");
  5989. if (!iwl3945_is_ready_rf(priv)) {
  5990. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  5991. return -EIO;
  5992. }
  5993. spin_lock_irqsave(&priv->lock, flags);
  5994. for (i = 0; i < AC_NUM; i++) {
  5995. txq = &priv->txq[i];
  5996. q = &txq->q;
  5997. avail = iwl3945_queue_space(q);
  5998. stats->data[i].len = q->n_window - avail;
  5999. stats->data[i].limit = q->n_window - q->high_mark;
  6000. stats->data[i].count = q->n_window;
  6001. }
  6002. spin_unlock_irqrestore(&priv->lock, flags);
  6003. IWL_DEBUG_MAC80211("leave\n");
  6004. return 0;
  6005. }
  6006. static int iwl3945_mac_get_stats(struct ieee80211_hw *hw,
  6007. struct ieee80211_low_level_stats *stats)
  6008. {
  6009. IWL_DEBUG_MAC80211("enter\n");
  6010. IWL_DEBUG_MAC80211("leave\n");
  6011. return 0;
  6012. }
  6013. static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw)
  6014. {
  6015. IWL_DEBUG_MAC80211("enter\n");
  6016. IWL_DEBUG_MAC80211("leave\n");
  6017. return 0;
  6018. }
  6019. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  6020. {
  6021. struct iwl3945_priv *priv = hw->priv;
  6022. unsigned long flags;
  6023. mutex_lock(&priv->mutex);
  6024. IWL_DEBUG_MAC80211("enter\n");
  6025. iwl3945_reset_qos(priv);
  6026. cancel_delayed_work(&priv->post_associate);
  6027. spin_lock_irqsave(&priv->lock, flags);
  6028. priv->assoc_id = 0;
  6029. priv->assoc_capability = 0;
  6030. priv->call_post_assoc_from_beacon = 0;
  6031. /* new association get rid of ibss beacon skb */
  6032. if (priv->ibss_beacon)
  6033. dev_kfree_skb(priv->ibss_beacon);
  6034. priv->ibss_beacon = NULL;
  6035. priv->beacon_int = priv->hw->conf.beacon_int;
  6036. priv->timestamp1 = 0;
  6037. priv->timestamp0 = 0;
  6038. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  6039. priv->beacon_int = 0;
  6040. spin_unlock_irqrestore(&priv->lock, flags);
  6041. if (!iwl3945_is_ready_rf(priv)) {
  6042. IWL_DEBUG_MAC80211("leave - not ready\n");
  6043. mutex_unlock(&priv->mutex);
  6044. return;
  6045. }
  6046. /* we are restarting association process
  6047. * clear RXON_FILTER_ASSOC_MSK bit
  6048. */
  6049. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  6050. iwl3945_scan_cancel_timeout(priv, 100);
  6051. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  6052. iwl3945_commit_rxon(priv);
  6053. }
  6054. /* Per mac80211.h: This is only used in IBSS mode... */
  6055. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6056. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  6057. mutex_unlock(&priv->mutex);
  6058. return;
  6059. }
  6060. iwl3945_set_rate(priv);
  6061. mutex_unlock(&priv->mutex);
  6062. IWL_DEBUG_MAC80211("leave\n");
  6063. }
  6064. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
  6065. struct ieee80211_tx_control *control)
  6066. {
  6067. struct iwl3945_priv *priv = hw->priv;
  6068. unsigned long flags;
  6069. mutex_lock(&priv->mutex);
  6070. IWL_DEBUG_MAC80211("enter\n");
  6071. if (!iwl3945_is_ready_rf(priv)) {
  6072. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  6073. mutex_unlock(&priv->mutex);
  6074. return -EIO;
  6075. }
  6076. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6077. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  6078. mutex_unlock(&priv->mutex);
  6079. return -EIO;
  6080. }
  6081. spin_lock_irqsave(&priv->lock, flags);
  6082. if (priv->ibss_beacon)
  6083. dev_kfree_skb(priv->ibss_beacon);
  6084. priv->ibss_beacon = skb;
  6085. priv->assoc_id = 0;
  6086. IWL_DEBUG_MAC80211("leave\n");
  6087. spin_unlock_irqrestore(&priv->lock, flags);
  6088. iwl3945_reset_qos(priv);
  6089. queue_work(priv->workqueue, &priv->post_associate.work);
  6090. mutex_unlock(&priv->mutex);
  6091. return 0;
  6092. }
  6093. /*****************************************************************************
  6094. *
  6095. * sysfs attributes
  6096. *
  6097. *****************************************************************************/
  6098. #ifdef CONFIG_IWL3945_DEBUG
  6099. /*
  6100. * The following adds a new attribute to the sysfs representation
  6101. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  6102. * used for controlling the debug level.
  6103. *
  6104. * See the level definitions in iwl for details.
  6105. */
  6106. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  6107. {
  6108. return sprintf(buf, "0x%08X\n", iwl3945_debug_level);
  6109. }
  6110. static ssize_t store_debug_level(struct device_driver *d,
  6111. const char *buf, size_t count)
  6112. {
  6113. char *p = (char *)buf;
  6114. u32 val;
  6115. val = simple_strtoul(p, &p, 0);
  6116. if (p == buf)
  6117. printk(KERN_INFO DRV_NAME
  6118. ": %s is not in hex or decimal form.\n", buf);
  6119. else
  6120. iwl3945_debug_level = val;
  6121. return strnlen(buf, count);
  6122. }
  6123. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
  6124. show_debug_level, store_debug_level);
  6125. #endif /* CONFIG_IWL3945_DEBUG */
  6126. static ssize_t show_rf_kill(struct device *d,
  6127. struct device_attribute *attr, char *buf)
  6128. {
  6129. /*
  6130. * 0 - RF kill not enabled
  6131. * 1 - SW based RF kill active (sysfs)
  6132. * 2 - HW based RF kill active
  6133. * 3 - Both HW and SW based RF kill active
  6134. */
  6135. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6136. int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
  6137. (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
  6138. return sprintf(buf, "%i\n", val);
  6139. }
  6140. static ssize_t store_rf_kill(struct device *d,
  6141. struct device_attribute *attr,
  6142. const char *buf, size_t count)
  6143. {
  6144. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6145. mutex_lock(&priv->mutex);
  6146. iwl3945_radio_kill_sw(priv, buf[0] == '1');
  6147. mutex_unlock(&priv->mutex);
  6148. return count;
  6149. }
  6150. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  6151. static ssize_t show_temperature(struct device *d,
  6152. struct device_attribute *attr, char *buf)
  6153. {
  6154. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6155. if (!iwl3945_is_alive(priv))
  6156. return -EAGAIN;
  6157. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  6158. }
  6159. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  6160. static ssize_t show_rs_window(struct device *d,
  6161. struct device_attribute *attr,
  6162. char *buf)
  6163. {
  6164. struct iwl3945_priv *priv = d->driver_data;
  6165. return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  6166. }
  6167. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  6168. static ssize_t show_tx_power(struct device *d,
  6169. struct device_attribute *attr, char *buf)
  6170. {
  6171. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6172. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  6173. }
  6174. static ssize_t store_tx_power(struct device *d,
  6175. struct device_attribute *attr,
  6176. const char *buf, size_t count)
  6177. {
  6178. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6179. char *p = (char *)buf;
  6180. u32 val;
  6181. val = simple_strtoul(p, &p, 10);
  6182. if (p == buf)
  6183. printk(KERN_INFO DRV_NAME
  6184. ": %s is not in decimal form.\n", buf);
  6185. else
  6186. iwl3945_hw_reg_set_txpower(priv, val);
  6187. return count;
  6188. }
  6189. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  6190. static ssize_t show_flags(struct device *d,
  6191. struct device_attribute *attr, char *buf)
  6192. {
  6193. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6194. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  6195. }
  6196. static ssize_t store_flags(struct device *d,
  6197. struct device_attribute *attr,
  6198. const char *buf, size_t count)
  6199. {
  6200. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6201. u32 flags = simple_strtoul(buf, NULL, 0);
  6202. mutex_lock(&priv->mutex);
  6203. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  6204. /* Cancel any currently running scans... */
  6205. if (iwl3945_scan_cancel_timeout(priv, 100))
  6206. IWL_WARNING("Could not cancel scan.\n");
  6207. else {
  6208. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  6209. flags);
  6210. priv->staging_rxon.flags = cpu_to_le32(flags);
  6211. iwl3945_commit_rxon(priv);
  6212. }
  6213. }
  6214. mutex_unlock(&priv->mutex);
  6215. return count;
  6216. }
  6217. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  6218. static ssize_t show_filter_flags(struct device *d,
  6219. struct device_attribute *attr, char *buf)
  6220. {
  6221. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6222. return sprintf(buf, "0x%04X\n",
  6223. le32_to_cpu(priv->active_rxon.filter_flags));
  6224. }
  6225. static ssize_t store_filter_flags(struct device *d,
  6226. struct device_attribute *attr,
  6227. const char *buf, size_t count)
  6228. {
  6229. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6230. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  6231. mutex_lock(&priv->mutex);
  6232. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  6233. /* Cancel any currently running scans... */
  6234. if (iwl3945_scan_cancel_timeout(priv, 100))
  6235. IWL_WARNING("Could not cancel scan.\n");
  6236. else {
  6237. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  6238. "0x%04X\n", filter_flags);
  6239. priv->staging_rxon.filter_flags =
  6240. cpu_to_le32(filter_flags);
  6241. iwl3945_commit_rxon(priv);
  6242. }
  6243. }
  6244. mutex_unlock(&priv->mutex);
  6245. return count;
  6246. }
  6247. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  6248. store_filter_flags);
  6249. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6250. static ssize_t show_measurement(struct device *d,
  6251. struct device_attribute *attr, char *buf)
  6252. {
  6253. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6254. struct iwl3945_spectrum_notification measure_report;
  6255. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  6256. u8 *data = (u8 *) & measure_report;
  6257. unsigned long flags;
  6258. spin_lock_irqsave(&priv->lock, flags);
  6259. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  6260. spin_unlock_irqrestore(&priv->lock, flags);
  6261. return 0;
  6262. }
  6263. memcpy(&measure_report, &priv->measure_report, size);
  6264. priv->measurement_status = 0;
  6265. spin_unlock_irqrestore(&priv->lock, flags);
  6266. while (size && (PAGE_SIZE - len)) {
  6267. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6268. PAGE_SIZE - len, 1);
  6269. len = strlen(buf);
  6270. if (PAGE_SIZE - len)
  6271. buf[len++] = '\n';
  6272. ofs += 16;
  6273. size -= min(size, 16U);
  6274. }
  6275. return len;
  6276. }
  6277. static ssize_t store_measurement(struct device *d,
  6278. struct device_attribute *attr,
  6279. const char *buf, size_t count)
  6280. {
  6281. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6282. struct ieee80211_measurement_params params = {
  6283. .channel = le16_to_cpu(priv->active_rxon.channel),
  6284. .start_time = cpu_to_le64(priv->last_tsf),
  6285. .duration = cpu_to_le16(1),
  6286. };
  6287. u8 type = IWL_MEASURE_BASIC;
  6288. u8 buffer[32];
  6289. u8 channel;
  6290. if (count) {
  6291. char *p = buffer;
  6292. strncpy(buffer, buf, min(sizeof(buffer), count));
  6293. channel = simple_strtoul(p, NULL, 0);
  6294. if (channel)
  6295. params.channel = channel;
  6296. p = buffer;
  6297. while (*p && *p != ' ')
  6298. p++;
  6299. if (*p)
  6300. type = simple_strtoul(p + 1, NULL, 0);
  6301. }
  6302. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  6303. "channel %d (for '%s')\n", type, params.channel, buf);
  6304. iwl3945_get_measurement(priv, &params, type);
  6305. return count;
  6306. }
  6307. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  6308. show_measurement, store_measurement);
  6309. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  6310. static ssize_t store_retry_rate(struct device *d,
  6311. struct device_attribute *attr,
  6312. const char *buf, size_t count)
  6313. {
  6314. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6315. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  6316. if (priv->retry_rate <= 0)
  6317. priv->retry_rate = 1;
  6318. return count;
  6319. }
  6320. static ssize_t show_retry_rate(struct device *d,
  6321. struct device_attribute *attr, char *buf)
  6322. {
  6323. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6324. return sprintf(buf, "%d", priv->retry_rate);
  6325. }
  6326. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  6327. store_retry_rate);
  6328. static ssize_t store_power_level(struct device *d,
  6329. struct device_attribute *attr,
  6330. const char *buf, size_t count)
  6331. {
  6332. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6333. int rc;
  6334. int mode;
  6335. mode = simple_strtoul(buf, NULL, 0);
  6336. mutex_lock(&priv->mutex);
  6337. if (!iwl3945_is_ready(priv)) {
  6338. rc = -EAGAIN;
  6339. goto out;
  6340. }
  6341. if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
  6342. mode = IWL_POWER_AC;
  6343. else
  6344. mode |= IWL_POWER_ENABLED;
  6345. if (mode != priv->power_mode) {
  6346. rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
  6347. if (rc) {
  6348. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  6349. goto out;
  6350. }
  6351. priv->power_mode = mode;
  6352. }
  6353. rc = count;
  6354. out:
  6355. mutex_unlock(&priv->mutex);
  6356. return rc;
  6357. }
  6358. #define MAX_WX_STRING 80
  6359. /* Values are in microsecond */
  6360. static const s32 timeout_duration[] = {
  6361. 350000,
  6362. 250000,
  6363. 75000,
  6364. 37000,
  6365. 25000,
  6366. };
  6367. static const s32 period_duration[] = {
  6368. 400000,
  6369. 700000,
  6370. 1000000,
  6371. 1000000,
  6372. 1000000
  6373. };
  6374. static ssize_t show_power_level(struct device *d,
  6375. struct device_attribute *attr, char *buf)
  6376. {
  6377. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6378. int level = IWL_POWER_LEVEL(priv->power_mode);
  6379. char *p = buf;
  6380. p += sprintf(p, "%d ", level);
  6381. switch (level) {
  6382. case IWL_POWER_MODE_CAM:
  6383. case IWL_POWER_AC:
  6384. p += sprintf(p, "(AC)");
  6385. break;
  6386. case IWL_POWER_BATTERY:
  6387. p += sprintf(p, "(BATTERY)");
  6388. break;
  6389. default:
  6390. p += sprintf(p,
  6391. "(Timeout %dms, Period %dms)",
  6392. timeout_duration[level - 1] / 1000,
  6393. period_duration[level - 1] / 1000);
  6394. }
  6395. if (!(priv->power_mode & IWL_POWER_ENABLED))
  6396. p += sprintf(p, " OFF\n");
  6397. else
  6398. p += sprintf(p, " \n");
  6399. return (p - buf + 1);
  6400. }
  6401. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  6402. store_power_level);
  6403. static ssize_t show_channels(struct device *d,
  6404. struct device_attribute *attr, char *buf)
  6405. {
  6406. /* all this shit doesn't belong into sysfs anyway */
  6407. return 0;
  6408. }
  6409. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  6410. static ssize_t show_statistics(struct device *d,
  6411. struct device_attribute *attr, char *buf)
  6412. {
  6413. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6414. u32 size = sizeof(struct iwl3945_notif_statistics);
  6415. u32 len = 0, ofs = 0;
  6416. u8 *data = (u8 *) & priv->statistics;
  6417. int rc = 0;
  6418. if (!iwl3945_is_alive(priv))
  6419. return -EAGAIN;
  6420. mutex_lock(&priv->mutex);
  6421. rc = iwl3945_send_statistics_request(priv);
  6422. mutex_unlock(&priv->mutex);
  6423. if (rc) {
  6424. len = sprintf(buf,
  6425. "Error sending statistics request: 0x%08X\n", rc);
  6426. return len;
  6427. }
  6428. while (size && (PAGE_SIZE - len)) {
  6429. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6430. PAGE_SIZE - len, 1);
  6431. len = strlen(buf);
  6432. if (PAGE_SIZE - len)
  6433. buf[len++] = '\n';
  6434. ofs += 16;
  6435. size -= min(size, 16U);
  6436. }
  6437. return len;
  6438. }
  6439. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  6440. static ssize_t show_antenna(struct device *d,
  6441. struct device_attribute *attr, char *buf)
  6442. {
  6443. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6444. if (!iwl3945_is_alive(priv))
  6445. return -EAGAIN;
  6446. return sprintf(buf, "%d\n", priv->antenna);
  6447. }
  6448. static ssize_t store_antenna(struct device *d,
  6449. struct device_attribute *attr,
  6450. const char *buf, size_t count)
  6451. {
  6452. int ant;
  6453. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6454. if (count == 0)
  6455. return 0;
  6456. if (sscanf(buf, "%1i", &ant) != 1) {
  6457. IWL_DEBUG_INFO("not in hex or decimal form.\n");
  6458. return count;
  6459. }
  6460. if ((ant >= 0) && (ant <= 2)) {
  6461. IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
  6462. priv->antenna = (enum iwl3945_antenna)ant;
  6463. } else
  6464. IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
  6465. return count;
  6466. }
  6467. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  6468. static ssize_t show_status(struct device *d,
  6469. struct device_attribute *attr, char *buf)
  6470. {
  6471. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6472. if (!iwl3945_is_alive(priv))
  6473. return -EAGAIN;
  6474. return sprintf(buf, "0x%08x\n", (int)priv->status);
  6475. }
  6476. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  6477. static ssize_t dump_error_log(struct device *d,
  6478. struct device_attribute *attr,
  6479. const char *buf, size_t count)
  6480. {
  6481. char *p = (char *)buf;
  6482. if (p[0] == '1')
  6483. iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data);
  6484. return strnlen(buf, count);
  6485. }
  6486. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  6487. static ssize_t dump_event_log(struct device *d,
  6488. struct device_attribute *attr,
  6489. const char *buf, size_t count)
  6490. {
  6491. char *p = (char *)buf;
  6492. if (p[0] == '1')
  6493. iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data);
  6494. return strnlen(buf, count);
  6495. }
  6496. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  6497. /*****************************************************************************
  6498. *
  6499. * driver setup and teardown
  6500. *
  6501. *****************************************************************************/
  6502. static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
  6503. {
  6504. priv->workqueue = create_workqueue(DRV_NAME);
  6505. init_waitqueue_head(&priv->wait_command_queue);
  6506. INIT_WORK(&priv->up, iwl3945_bg_up);
  6507. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  6508. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  6509. INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
  6510. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  6511. INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
  6512. INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
  6513. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  6514. INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate);
  6515. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  6516. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  6517. INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
  6518. iwl3945_hw_setup_deferred_work(priv);
  6519. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  6520. iwl3945_irq_tasklet, (unsigned long)priv);
  6521. }
  6522. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
  6523. {
  6524. iwl3945_hw_cancel_deferred_work(priv);
  6525. cancel_delayed_work_sync(&priv->init_alive_start);
  6526. cancel_delayed_work(&priv->scan_check);
  6527. cancel_delayed_work(&priv->alive_start);
  6528. cancel_delayed_work(&priv->post_associate);
  6529. cancel_work_sync(&priv->beacon_update);
  6530. }
  6531. static struct attribute *iwl3945_sysfs_entries[] = {
  6532. &dev_attr_antenna.attr,
  6533. &dev_attr_channels.attr,
  6534. &dev_attr_dump_errors.attr,
  6535. &dev_attr_dump_events.attr,
  6536. &dev_attr_flags.attr,
  6537. &dev_attr_filter_flags.attr,
  6538. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6539. &dev_attr_measurement.attr,
  6540. #endif
  6541. &dev_attr_power_level.attr,
  6542. &dev_attr_retry_rate.attr,
  6543. &dev_attr_rf_kill.attr,
  6544. &dev_attr_rs_window.attr,
  6545. &dev_attr_statistics.attr,
  6546. &dev_attr_status.attr,
  6547. &dev_attr_temperature.attr,
  6548. &dev_attr_tx_power.attr,
  6549. NULL
  6550. };
  6551. static struct attribute_group iwl3945_attribute_group = {
  6552. .name = NULL, /* put in device directory */
  6553. .attrs = iwl3945_sysfs_entries,
  6554. };
  6555. static struct ieee80211_ops iwl3945_hw_ops = {
  6556. .tx = iwl3945_mac_tx,
  6557. .start = iwl3945_mac_start,
  6558. .stop = iwl3945_mac_stop,
  6559. .add_interface = iwl3945_mac_add_interface,
  6560. .remove_interface = iwl3945_mac_remove_interface,
  6561. .config = iwl3945_mac_config,
  6562. .config_interface = iwl3945_mac_config_interface,
  6563. .configure_filter = iwl3945_configure_filter,
  6564. .set_key = iwl3945_mac_set_key,
  6565. .get_stats = iwl3945_mac_get_stats,
  6566. .get_tx_stats = iwl3945_mac_get_tx_stats,
  6567. .conf_tx = iwl3945_mac_conf_tx,
  6568. .get_tsf = iwl3945_mac_get_tsf,
  6569. .reset_tsf = iwl3945_mac_reset_tsf,
  6570. .beacon_update = iwl3945_mac_beacon_update,
  6571. .hw_scan = iwl3945_mac_hw_scan
  6572. };
  6573. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6574. {
  6575. int err = 0;
  6576. struct iwl3945_priv *priv;
  6577. struct ieee80211_hw *hw;
  6578. struct iwl_3945_cfg *cfg = (struct iwl_3945_cfg *)(ent->driver_data);
  6579. int i;
  6580. unsigned long flags;
  6581. DECLARE_MAC_BUF(mac);
  6582. /* Disabling hardware scan means that mac80211 will perform scans
  6583. * "the hard way", rather than using device's scan. */
  6584. if (iwl3945_param_disable_hw_scan) {
  6585. IWL_DEBUG_INFO("Disabling hw_scan\n");
  6586. iwl3945_hw_ops.hw_scan = NULL;
  6587. }
  6588. if ((iwl3945_param_queues_num > IWL39_MAX_NUM_QUEUES) ||
  6589. (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) {
  6590. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  6591. IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
  6592. err = -EINVAL;
  6593. goto out;
  6594. }
  6595. /* mac80211 allocates memory for this device instance, including
  6596. * space for this driver's private structure */
  6597. hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops);
  6598. if (hw == NULL) {
  6599. IWL_ERROR("Can not allocate network device\n");
  6600. err = -ENOMEM;
  6601. goto out;
  6602. }
  6603. SET_IEEE80211_DEV(hw, &pdev->dev);
  6604. hw->rate_control_algorithm = "iwl-3945-rs";
  6605. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  6606. priv = hw->priv;
  6607. priv->hw = hw;
  6608. priv->pci_dev = pdev;
  6609. priv->cfg = cfg;
  6610. /* Select antenna (may be helpful if only one antenna is connected) */
  6611. priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna;
  6612. #ifdef CONFIG_IWL3945_DEBUG
  6613. iwl3945_debug_level = iwl3945_param_debug;
  6614. atomic_set(&priv->restrict_refcnt, 0);
  6615. #endif
  6616. priv->retry_rate = 1;
  6617. priv->ibss_beacon = NULL;
  6618. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  6619. * the range of signal quality values that we'll provide.
  6620. * Negative values for level/noise indicate that we'll provide dBm.
  6621. * For WE, at least, non-0 values here *enable* display of values
  6622. * in app (iwconfig). */
  6623. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  6624. hw->max_noise = -20; /* noise level, negative indicates dBm */
  6625. hw->max_signal = 100; /* link quality indication (%) */
  6626. /* Tell mac80211 our Tx characteristics */
  6627. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  6628. /* 4 EDCA QOS priorities */
  6629. hw->queues = 4;
  6630. spin_lock_init(&priv->lock);
  6631. spin_lock_init(&priv->power_data.lock);
  6632. spin_lock_init(&priv->sta_lock);
  6633. spin_lock_init(&priv->hcmd_lock);
  6634. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  6635. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  6636. INIT_LIST_HEAD(&priv->free_frames);
  6637. mutex_init(&priv->mutex);
  6638. if (pci_enable_device(pdev)) {
  6639. err = -ENODEV;
  6640. goto out_ieee80211_free_hw;
  6641. }
  6642. pci_set_master(pdev);
  6643. /* Clear the driver's (not device's) station table */
  6644. iwl3945_clear_stations_table(priv);
  6645. priv->data_retry_limit = -1;
  6646. priv->ieee_channels = NULL;
  6647. priv->ieee_rates = NULL;
  6648. priv->band = IEEE80211_BAND_2GHZ;
  6649. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  6650. if (!err)
  6651. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  6652. if (err) {
  6653. printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
  6654. goto out_pci_disable_device;
  6655. }
  6656. pci_set_drvdata(pdev, priv);
  6657. err = pci_request_regions(pdev, DRV_NAME);
  6658. if (err)
  6659. goto out_pci_disable_device;
  6660. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  6661. * PCI Tx retries from interfering with C3 CPU state */
  6662. pci_write_config_byte(pdev, 0x41, 0x00);
  6663. priv->hw_base = pci_iomap(pdev, 0, 0);
  6664. if (!priv->hw_base) {
  6665. err = -ENODEV;
  6666. goto out_pci_release_regions;
  6667. }
  6668. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  6669. (unsigned long long) pci_resource_len(pdev, 0));
  6670. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  6671. /* Initialize module parameter values here */
  6672. /* Disable radio (SW RF KILL) via parameter when loading driver */
  6673. if (iwl3945_param_disable) {
  6674. set_bit(STATUS_RF_KILL_SW, &priv->status);
  6675. IWL_DEBUG_INFO("Radio disabled.\n");
  6676. }
  6677. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  6678. printk(KERN_INFO DRV_NAME
  6679. ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
  6680. /* Device-specific setup */
  6681. if (iwl3945_hw_set_hw_setting(priv)) {
  6682. IWL_ERROR("failed to set hw settings\n");
  6683. goto out_iounmap;
  6684. }
  6685. if (iwl3945_param_qos_enable)
  6686. priv->qos_data.qos_enable = 1;
  6687. iwl3945_reset_qos(priv);
  6688. priv->qos_data.qos_active = 0;
  6689. priv->qos_data.qos_cap.val = 0;
  6690. iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  6691. iwl3945_setup_deferred_work(priv);
  6692. iwl3945_setup_rx_handlers(priv);
  6693. priv->rates_mask = IWL_RATES_MASK;
  6694. /* If power management is turned on, default to AC mode */
  6695. priv->power_mode = IWL_POWER_AC;
  6696. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  6697. spin_lock_irqsave(&priv->lock, flags);
  6698. iwl3945_disable_interrupts(priv);
  6699. spin_unlock_irqrestore(&priv->lock, flags);
  6700. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6701. if (err) {
  6702. IWL_ERROR("failed to create sysfs device attributes\n");
  6703. goto out_release_irq;
  6704. }
  6705. /* nic init */
  6706. iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  6707. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  6708. iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  6709. err = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
  6710. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  6711. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  6712. if (err < 0) {
  6713. IWL_DEBUG_INFO("Failed to init the card\n");
  6714. goto out_remove_sysfs;
  6715. }
  6716. /* Read the EEPROM */
  6717. err = iwl3945_eeprom_init(priv);
  6718. if (err) {
  6719. IWL_ERROR("Unable to init EEPROM\n");
  6720. goto out_remove_sysfs;
  6721. }
  6722. /* MAC Address location in EEPROM same for 3945/4965 */
  6723. get_eeprom_mac(priv, priv->mac_addr);
  6724. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  6725. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  6726. err = iwl3945_init_channel_map(priv);
  6727. if (err) {
  6728. IWL_ERROR("initializing regulatory failed: %d\n", err);
  6729. goto out_remove_sysfs;
  6730. }
  6731. err = iwl3945_init_geos(priv);
  6732. if (err) {
  6733. IWL_ERROR("initializing geos failed: %d\n", err);
  6734. goto out_free_channel_map;
  6735. }
  6736. err = ieee80211_register_hw(priv->hw);
  6737. if (err) {
  6738. IWL_ERROR("Failed to register network device (error %d)\n", err);
  6739. goto out_free_geos;
  6740. }
  6741. priv->hw->conf.beacon_int = 100;
  6742. priv->mac80211_registered = 1;
  6743. pci_save_state(pdev);
  6744. pci_disable_device(pdev);
  6745. return 0;
  6746. out_free_geos:
  6747. iwl3945_free_geos(priv);
  6748. out_free_channel_map:
  6749. iwl3945_free_channel_map(priv);
  6750. out_remove_sysfs:
  6751. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6752. out_release_irq:
  6753. destroy_workqueue(priv->workqueue);
  6754. priv->workqueue = NULL;
  6755. iwl3945_unset_hw_setting(priv);
  6756. out_iounmap:
  6757. pci_iounmap(pdev, priv->hw_base);
  6758. out_pci_release_regions:
  6759. pci_release_regions(pdev);
  6760. out_pci_disable_device:
  6761. pci_disable_device(pdev);
  6762. pci_set_drvdata(pdev, NULL);
  6763. out_ieee80211_free_hw:
  6764. ieee80211_free_hw(priv->hw);
  6765. out:
  6766. return err;
  6767. }
  6768. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  6769. {
  6770. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6771. struct list_head *p, *q;
  6772. int i;
  6773. unsigned long flags;
  6774. if (!priv)
  6775. return;
  6776. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  6777. set_bit(STATUS_EXIT_PENDING, &priv->status);
  6778. iwl3945_down(priv);
  6779. /* make sure we flush any pending irq or
  6780. * tasklet for the driver
  6781. */
  6782. spin_lock_irqsave(&priv->lock, flags);
  6783. iwl3945_disable_interrupts(priv);
  6784. spin_unlock_irqrestore(&priv->lock, flags);
  6785. iwl_synchronize_irq(priv);
  6786. /* Free MAC hash list for ADHOC */
  6787. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  6788. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  6789. list_del(p);
  6790. kfree(list_entry(p, struct iwl3945_ibss_seq, list));
  6791. }
  6792. }
  6793. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6794. iwl3945_dealloc_ucode_pci(priv);
  6795. if (priv->rxq.bd)
  6796. iwl3945_rx_queue_free(priv, &priv->rxq);
  6797. iwl3945_hw_txq_ctx_free(priv);
  6798. iwl3945_unset_hw_setting(priv);
  6799. iwl3945_clear_stations_table(priv);
  6800. if (priv->mac80211_registered) {
  6801. ieee80211_unregister_hw(priv->hw);
  6802. }
  6803. /*netif_stop_queue(dev); */
  6804. flush_workqueue(priv->workqueue);
  6805. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  6806. * priv->workqueue... so we can't take down the workqueue
  6807. * until now... */
  6808. destroy_workqueue(priv->workqueue);
  6809. priv->workqueue = NULL;
  6810. pci_iounmap(pdev, priv->hw_base);
  6811. pci_release_regions(pdev);
  6812. pci_disable_device(pdev);
  6813. pci_set_drvdata(pdev, NULL);
  6814. iwl3945_free_channel_map(priv);
  6815. iwl3945_free_geos(priv);
  6816. if (priv->ibss_beacon)
  6817. dev_kfree_skb(priv->ibss_beacon);
  6818. ieee80211_free_hw(priv->hw);
  6819. }
  6820. #ifdef CONFIG_PM
  6821. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  6822. {
  6823. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6824. if (priv->is_open) {
  6825. set_bit(STATUS_IN_SUSPEND, &priv->status);
  6826. iwl3945_mac_stop(priv->hw);
  6827. priv->is_open = 1;
  6828. }
  6829. pci_set_power_state(pdev, PCI_D3hot);
  6830. return 0;
  6831. }
  6832. static int iwl3945_pci_resume(struct pci_dev *pdev)
  6833. {
  6834. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6835. pci_set_power_state(pdev, PCI_D0);
  6836. if (priv->is_open)
  6837. iwl3945_mac_start(priv->hw);
  6838. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  6839. return 0;
  6840. }
  6841. #endif /* CONFIG_PM */
  6842. /*****************************************************************************
  6843. *
  6844. * driver and module entry point
  6845. *
  6846. *****************************************************************************/
  6847. static struct pci_driver iwl3945_driver = {
  6848. .name = DRV_NAME,
  6849. .id_table = iwl3945_hw_card_ids,
  6850. .probe = iwl3945_pci_probe,
  6851. .remove = __devexit_p(iwl3945_pci_remove),
  6852. #ifdef CONFIG_PM
  6853. .suspend = iwl3945_pci_suspend,
  6854. .resume = iwl3945_pci_resume,
  6855. #endif
  6856. };
  6857. static int __init iwl3945_init(void)
  6858. {
  6859. int ret;
  6860. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  6861. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  6862. ret = iwl3945_rate_control_register();
  6863. if (ret) {
  6864. IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
  6865. return ret;
  6866. }
  6867. ret = pci_register_driver(&iwl3945_driver);
  6868. if (ret) {
  6869. IWL_ERROR("Unable to initialize PCI module\n");
  6870. goto error_register;
  6871. }
  6872. #ifdef CONFIG_IWL3945_DEBUG
  6873. ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  6874. if (ret) {
  6875. IWL_ERROR("Unable to create driver sysfs file\n");
  6876. goto error_debug;
  6877. }
  6878. #endif
  6879. return ret;
  6880. #ifdef CONFIG_IWL3945_DEBUG
  6881. error_debug:
  6882. pci_unregister_driver(&iwl3945_driver);
  6883. #endif
  6884. error_register:
  6885. iwl3945_rate_control_unregister();
  6886. return ret;
  6887. }
  6888. static void __exit iwl3945_exit(void)
  6889. {
  6890. #ifdef CONFIG_IWL3945_DEBUG
  6891. driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  6892. #endif
  6893. pci_unregister_driver(&iwl3945_driver);
  6894. iwl3945_rate_control_unregister();
  6895. }
  6896. module_param_named(antenna, iwl3945_param_antenna, int, 0444);
  6897. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  6898. module_param_named(disable, iwl3945_param_disable, int, 0444);
  6899. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  6900. module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444);
  6901. MODULE_PARM_DESC(hwcrypto,
  6902. "using hardware crypto engine (default 0 [software])\n");
  6903. module_param_named(debug, iwl3945_param_debug, int, 0444);
  6904. MODULE_PARM_DESC(debug, "debug output mask");
  6905. module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444);
  6906. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  6907. module_param_named(queues_num, iwl3945_param_queues_num, int, 0444);
  6908. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  6909. /* QoS */
  6910. module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444);
  6911. MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
  6912. module_exit(iwl3945_exit);
  6913. module_init(iwl3945_init);