iwl3945-base.c 234 KB

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