iwl4965-base.c 159 KB

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