iwl4965-base.c 167 KB

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