iwl4965-base.c 151 KB

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