iwl4965-base.c 215 KB

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