iwl3945-base.c 246 KB

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