iwl4965-base.c 152 KB

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