iwl4965-base.c 195 KB

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