iwl4965-base.c 227 KB

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