iwl4965-base.c 223 KB

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