iwl3945-base.c 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 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. * Intel Linux Wireless <ilw@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/init.h>
  32. #include <linux/pci.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/delay.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/wireless.h>
  38. #include <linux/firmware.h>
  39. #include <linux/etherdevice.h>
  40. #include <linux/if_arp.h>
  41. #include <net/ieee80211_radiotap.h>
  42. #include <net/lib80211.h>
  43. #include <net/mac80211.h>
  44. #include <asm/div64.h>
  45. #define DRV_NAME "iwl3945"
  46. #include "iwl-fh.h"
  47. #include "iwl-3945-fh.h"
  48. #include "iwl-commands.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-3945.h"
  51. #include "iwl-helpers.h"
  52. #include "iwl-core.h"
  53. #include "iwl-dev.h"
  54. /*
  55. * module name, copyright, version, etc.
  56. */
  57. #define DRV_DESCRIPTION \
  58. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  59. #ifdef CONFIG_IWLWIFI_DEBUG
  60. #define VD "d"
  61. #else
  62. #define VD
  63. #endif
  64. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  65. #define VS "s"
  66. #else
  67. #define VS
  68. #endif
  69. #define IWL39_VERSION "1.2.26k" VD VS
  70. #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
  71. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  72. #define DRV_VERSION IWL39_VERSION
  73. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  74. MODULE_VERSION(DRV_VERSION);
  75. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  76. MODULE_LICENSE("GPL");
  77. /* module parameters */
  78. struct iwl_mod_params iwl3945_mod_params = {
  79. .num_of_queues = IWL39_MAX_NUM_QUEUES,
  80. .sw_crypto = 1,
  81. .restart_fw = 1,
  82. /* the rest are 0 by default */
  83. };
  84. /*************** STATION TABLE MANAGEMENT ****
  85. * mac80211 should be examined to determine if sta_info is duplicating
  86. * the functionality provided here
  87. */
  88. /**************************************************************/
  89. #if 0 /* temporary disable till we add real remove station */
  90. /**
  91. * iwl3945_remove_station - Remove driver's knowledge of station.
  92. *
  93. * NOTE: This does not remove station from device's station table.
  94. */
  95. static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  96. {
  97. int index = IWL_INVALID_STATION;
  98. int i;
  99. unsigned long flags;
  100. spin_lock_irqsave(&priv->sta_lock, flags);
  101. if (is_ap)
  102. index = IWL_AP_ID;
  103. else if (is_broadcast_ether_addr(addr))
  104. index = priv->hw_params.bcast_sta_id;
  105. else
  106. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  107. if (priv->stations_39[i].used &&
  108. !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  109. addr)) {
  110. index = i;
  111. break;
  112. }
  113. if (unlikely(index == IWL_INVALID_STATION))
  114. goto out;
  115. if (priv->stations_39[index].used) {
  116. priv->stations_39[index].used = 0;
  117. priv->num_stations--;
  118. }
  119. BUG_ON(priv->num_stations < 0);
  120. out:
  121. spin_unlock_irqrestore(&priv->sta_lock, flags);
  122. return 0;
  123. }
  124. #endif
  125. /**
  126. * iwl3945_clear_stations_table - Clear the driver's station table
  127. *
  128. * NOTE: This does not clear or otherwise alter the device's station table.
  129. */
  130. static void iwl3945_clear_stations_table(struct iwl_priv *priv)
  131. {
  132. unsigned long flags;
  133. spin_lock_irqsave(&priv->sta_lock, flags);
  134. priv->num_stations = 0;
  135. memset(priv->stations_39, 0, sizeof(priv->stations_39));
  136. spin_unlock_irqrestore(&priv->sta_lock, flags);
  137. }
  138. /**
  139. * iwl3945_add_station - Add station to station tables in driver and device
  140. */
  141. u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
  142. {
  143. int i;
  144. int index = IWL_INVALID_STATION;
  145. struct iwl3945_station_entry *station;
  146. unsigned long flags_spin;
  147. u8 rate;
  148. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  149. if (is_ap)
  150. index = IWL_AP_ID;
  151. else if (is_broadcast_ether_addr(addr))
  152. index = priv->hw_params.bcast_sta_id;
  153. else
  154. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  155. if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  156. addr)) {
  157. index = i;
  158. break;
  159. }
  160. if (!priv->stations_39[i].used &&
  161. index == IWL_INVALID_STATION)
  162. index = i;
  163. }
  164. /* These two conditions has the same outcome but keep them separate
  165. since they have different meaning */
  166. if (unlikely(index == IWL_INVALID_STATION)) {
  167. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  168. return index;
  169. }
  170. if (priv->stations_39[index].used &&
  171. !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
  172. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  173. return index;
  174. }
  175. IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
  176. station = &priv->stations_39[index];
  177. station->used = 1;
  178. priv->num_stations++;
  179. /* Set up the REPLY_ADD_STA command to send to device */
  180. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  181. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  182. station->sta.mode = 0;
  183. station->sta.sta.sta_id = index;
  184. station->sta.station_flags = 0;
  185. if (priv->band == IEEE80211_BAND_5GHZ)
  186. rate = IWL_RATE_6M_PLCP;
  187. else
  188. rate = IWL_RATE_1M_PLCP;
  189. /* Turn on both antennas for the station... */
  190. station->sta.rate_n_flags =
  191. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  192. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  193. /* Add station to device's station table */
  194. iwl_send_add_sta(priv,
  195. (struct iwl_addsta_cmd *)&station->sta, flags);
  196. return index;
  197. }
  198. static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
  199. {
  200. int rc = 0;
  201. struct iwl_rx_packet *res = NULL;
  202. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  203. struct iwl_host_cmd cmd = {
  204. .id = REPLY_RXON_ASSOC,
  205. .len = sizeof(rxon_assoc),
  206. .meta.flags = CMD_WANT_SKB,
  207. .data = &rxon_assoc,
  208. };
  209. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  210. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  211. if ((rxon1->flags == rxon2->flags) &&
  212. (rxon1->filter_flags == rxon2->filter_flags) &&
  213. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  214. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  215. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  216. return 0;
  217. }
  218. rxon_assoc.flags = priv->staging_rxon.flags;
  219. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  220. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  221. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  222. rxon_assoc.reserved = 0;
  223. rc = iwl_send_cmd_sync(priv, &cmd);
  224. if (rc)
  225. return rc;
  226. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  227. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  228. IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
  229. rc = -EIO;
  230. }
  231. priv->alloc_rxb_skb--;
  232. dev_kfree_skb_any(cmd.meta.u.skb);
  233. return rc;
  234. }
  235. /**
  236. * iwl3945_get_antenna_flags - Get antenna flags for RXON command
  237. * @priv: eeprom and antenna fields are used to determine antenna flags
  238. *
  239. * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
  240. * iwl3945_mod_params.antenna specifies the antenna diversity mode:
  241. *
  242. * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
  243. * IWL_ANTENNA_MAIN - Force MAIN antenna
  244. * IWL_ANTENNA_AUX - Force AUX antenna
  245. */
  246. __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
  247. {
  248. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  249. switch (iwl3945_mod_params.antenna) {
  250. case IWL_ANTENNA_DIVERSITY:
  251. return 0;
  252. case IWL_ANTENNA_MAIN:
  253. if (eeprom->antenna_switch_type)
  254. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  255. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  256. case IWL_ANTENNA_AUX:
  257. if (eeprom->antenna_switch_type)
  258. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  259. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  260. }
  261. /* bad antenna selector value */
  262. IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
  263. iwl3945_mod_params.antenna);
  264. return 0; /* "diversity" is default if error */
  265. }
  266. /**
  267. * iwl3945_commit_rxon - commit staging_rxon to hardware
  268. *
  269. * The RXON command in staging_rxon is committed to the hardware and
  270. * the active_rxon structure is updated with the new data. This
  271. * function correctly transitions out of the RXON_ASSOC_MSK state if
  272. * a HW tune is required based on the RXON structure changes.
  273. */
  274. static int iwl3945_commit_rxon(struct iwl_priv *priv)
  275. {
  276. /* cast away the const for active_rxon in this function */
  277. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  278. struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
  279. int rc = 0;
  280. if (!iwl_is_alive(priv))
  281. return -1;
  282. /* always get timestamp with Rx frame */
  283. staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
  284. /* select antenna */
  285. staging_rxon->flags &=
  286. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  287. staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
  288. rc = iwl_check_rxon_cmd(priv);
  289. if (rc) {
  290. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  291. return -EINVAL;
  292. }
  293. /* If we don't need to send a full RXON, we can use
  294. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  295. * and other flags for the current radio configuration. */
  296. if (!iwl_full_rxon_required(priv)) {
  297. rc = iwl3945_send_rxon_assoc(priv);
  298. if (rc) {
  299. IWL_ERR(priv, "Error setting RXON_ASSOC "
  300. "configuration (%d).\n", rc);
  301. return rc;
  302. }
  303. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  304. return 0;
  305. }
  306. /* If we are currently associated and the new config requires
  307. * an RXON_ASSOC and the new config wants the associated mask enabled,
  308. * we must clear the associated from the active configuration
  309. * before we apply the new config */
  310. if (iwl_is_associated(priv) &&
  311. (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
  312. IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
  313. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  314. /*
  315. * reserved4 and 5 could have been filled by the iwlcore code.
  316. * Let's clear them before pushing to the 3945.
  317. */
  318. active_rxon->reserved4 = 0;
  319. active_rxon->reserved5 = 0;
  320. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  321. sizeof(struct iwl3945_rxon_cmd),
  322. &priv->active_rxon);
  323. /* If the mask clearing failed then we set
  324. * active_rxon back to what it was previously */
  325. if (rc) {
  326. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  327. IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
  328. "configuration (%d).\n", rc);
  329. return rc;
  330. }
  331. }
  332. IWL_DEBUG_INFO(priv, "Sending RXON\n"
  333. "* with%s RXON_FILTER_ASSOC_MSK\n"
  334. "* channel = %d\n"
  335. "* bssid = %pM\n",
  336. ((priv->staging_rxon.filter_flags &
  337. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  338. le16_to_cpu(staging_rxon->channel),
  339. staging_rxon->bssid_addr);
  340. /*
  341. * reserved4 and 5 could have been filled by the iwlcore code.
  342. * Let's clear them before pushing to the 3945.
  343. */
  344. staging_rxon->reserved4 = 0;
  345. staging_rxon->reserved5 = 0;
  346. /* Apply the new configuration */
  347. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  348. sizeof(struct iwl3945_rxon_cmd),
  349. staging_rxon);
  350. if (rc) {
  351. IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
  352. return rc;
  353. }
  354. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  355. iwl3945_clear_stations_table(priv);
  356. /* If we issue a new RXON command which required a tune then we must
  357. * send a new TXPOWER command or we won't be able to Tx any frames */
  358. rc = priv->cfg->ops->lib->send_tx_power(priv);
  359. if (rc) {
  360. IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
  361. return rc;
  362. }
  363. /* Add the broadcast address so we can send broadcast frames */
  364. if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
  365. IWL_INVALID_STATION) {
  366. IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
  367. return -EIO;
  368. }
  369. /* If we have set the ASSOC_MSK and we are in BSS mode then
  370. * add the IWL_AP_ID to the station rate table */
  371. if (iwl_is_associated(priv) &&
  372. (priv->iw_mode == NL80211_IFTYPE_STATION))
  373. if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
  374. 1, 0)
  375. == IWL_INVALID_STATION) {
  376. IWL_ERR(priv, "Error adding AP address for transmit\n");
  377. return -EIO;
  378. }
  379. /* Init the hardware's rate fallback order based on the band */
  380. rc = iwl3945_init_hw_rate_table(priv);
  381. if (rc) {
  382. IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
  383. return -EIO;
  384. }
  385. return 0;
  386. }
  387. static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
  388. struct ieee80211_key_conf *keyconf,
  389. u8 sta_id)
  390. {
  391. unsigned long flags;
  392. __le16 key_flags = 0;
  393. switch (keyconf->alg) {
  394. case ALG_CCMP:
  395. key_flags |= STA_KEY_FLG_CCMP;
  396. key_flags |= cpu_to_le16(
  397. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  398. key_flags &= ~STA_KEY_FLG_INVALID;
  399. break;
  400. case ALG_TKIP:
  401. case ALG_WEP:
  402. default:
  403. return -EINVAL;
  404. }
  405. spin_lock_irqsave(&priv->sta_lock, flags);
  406. priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
  407. priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
  408. memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
  409. keyconf->keylen);
  410. memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
  411. keyconf->keylen);
  412. priv->stations_39[sta_id].sta.key.key_flags = key_flags;
  413. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  414. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  415. spin_unlock_irqrestore(&priv->sta_lock, flags);
  416. IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
  417. iwl_send_add_sta(priv,
  418. (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
  419. return 0;
  420. }
  421. static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
  422. {
  423. unsigned long flags;
  424. spin_lock_irqsave(&priv->sta_lock, flags);
  425. memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  426. memset(&priv->stations_39[sta_id].sta.key, 0,
  427. sizeof(struct iwl4965_keyinfo));
  428. priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  429. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  430. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  431. spin_unlock_irqrestore(&priv->sta_lock, flags);
  432. IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
  433. iwl_send_add_sta(priv,
  434. (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
  435. return 0;
  436. }
  437. static void iwl3945_clear_free_frames(struct iwl_priv *priv)
  438. {
  439. struct list_head *element;
  440. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  441. priv->frames_count);
  442. while (!list_empty(&priv->free_frames)) {
  443. element = priv->free_frames.next;
  444. list_del(element);
  445. kfree(list_entry(element, struct iwl3945_frame, list));
  446. priv->frames_count--;
  447. }
  448. if (priv->frames_count) {
  449. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  450. priv->frames_count);
  451. priv->frames_count = 0;
  452. }
  453. }
  454. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
  455. {
  456. struct iwl3945_frame *frame;
  457. struct list_head *element;
  458. if (list_empty(&priv->free_frames)) {
  459. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  460. if (!frame) {
  461. IWL_ERR(priv, "Could not allocate frame!\n");
  462. return NULL;
  463. }
  464. priv->frames_count++;
  465. return frame;
  466. }
  467. element = priv->free_frames.next;
  468. list_del(element);
  469. return list_entry(element, struct iwl3945_frame, list);
  470. }
  471. static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
  472. {
  473. memset(frame, 0, sizeof(*frame));
  474. list_add(&frame->list, &priv->free_frames);
  475. }
  476. unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
  477. struct ieee80211_hdr *hdr,
  478. int left)
  479. {
  480. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  481. ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
  482. (priv->iw_mode != NL80211_IFTYPE_AP)))
  483. return 0;
  484. if (priv->ibss_beacon->len > left)
  485. return 0;
  486. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  487. return priv->ibss_beacon->len;
  488. }
  489. static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
  490. {
  491. struct iwl3945_frame *frame;
  492. unsigned int frame_size;
  493. int rc;
  494. u8 rate;
  495. frame = iwl3945_get_free_frame(priv);
  496. if (!frame) {
  497. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  498. "command.\n");
  499. return -ENOMEM;
  500. }
  501. rate = iwl_rate_get_lowest_plcp(priv);
  502. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  503. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  504. &frame->u.cmd[0]);
  505. iwl3945_free_frame(priv, frame);
  506. return rc;
  507. }
  508. static void iwl3945_unset_hw_params(struct iwl_priv *priv)
  509. {
  510. if (priv->shared_virt)
  511. pci_free_consistent(priv->pci_dev,
  512. sizeof(struct iwl3945_shared),
  513. priv->shared_virt,
  514. priv->shared_phys);
  515. }
  516. /*
  517. * QoS support
  518. */
  519. static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
  520. struct iwl_qosparam_cmd *qos)
  521. {
  522. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  523. sizeof(struct iwl_qosparam_cmd), qos);
  524. }
  525. static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
  526. {
  527. unsigned long flags;
  528. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  529. return;
  530. spin_lock_irqsave(&priv->lock, flags);
  531. priv->qos_data.def_qos_parm.qos_flags = 0;
  532. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  533. !priv->qos_data.qos_cap.q_AP.txop_request)
  534. priv->qos_data.def_qos_parm.qos_flags |=
  535. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  536. if (priv->qos_data.qos_active)
  537. priv->qos_data.def_qos_parm.qos_flags |=
  538. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  539. spin_unlock_irqrestore(&priv->lock, flags);
  540. if (force || iwl_is_associated(priv)) {
  541. IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
  542. priv->qos_data.qos_active);
  543. iwl3945_send_qos_params_command(priv,
  544. &(priv->qos_data.def_qos_parm));
  545. }
  546. }
  547. #define MAX_UCODE_BEACON_INTERVAL 1024
  548. #define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
  549. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  550. {
  551. u16 new_val = 0;
  552. u16 beacon_factor = 0;
  553. beacon_factor =
  554. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  555. / MAX_UCODE_BEACON_INTERVAL;
  556. new_val = beacon_val / beacon_factor;
  557. return cpu_to_le16(new_val);
  558. }
  559. static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
  560. {
  561. u64 interval_tm_unit;
  562. u64 tsf, result;
  563. unsigned long flags;
  564. struct ieee80211_conf *conf = NULL;
  565. u16 beacon_int = 0;
  566. conf = ieee80211_get_hw_conf(priv->hw);
  567. spin_lock_irqsave(&priv->lock, flags);
  568. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  569. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  570. tsf = priv->timestamp;
  571. beacon_int = priv->beacon_int;
  572. spin_unlock_irqrestore(&priv->lock, flags);
  573. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  574. if (beacon_int == 0) {
  575. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  576. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  577. } else {
  578. priv->rxon_timing.beacon_interval =
  579. cpu_to_le16(beacon_int);
  580. priv->rxon_timing.beacon_interval =
  581. iwl3945_adjust_beacon_interval(
  582. le16_to_cpu(priv->rxon_timing.beacon_interval));
  583. }
  584. priv->rxon_timing.atim_window = 0;
  585. } else {
  586. priv->rxon_timing.beacon_interval =
  587. iwl3945_adjust_beacon_interval(conf->beacon_int);
  588. /* TODO: we need to get atim_window from upper stack
  589. * for now we set to 0 */
  590. priv->rxon_timing.atim_window = 0;
  591. }
  592. interval_tm_unit =
  593. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  594. result = do_div(tsf, interval_tm_unit);
  595. priv->rxon_timing.beacon_init_val =
  596. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  597. IWL_DEBUG_ASSOC(priv,
  598. "beacon interval %d beacon timer %d beacon tim %d\n",
  599. le16_to_cpu(priv->rxon_timing.beacon_interval),
  600. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  601. le16_to_cpu(priv->rxon_timing.atim_window));
  602. }
  603. static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
  604. {
  605. if (mode == NL80211_IFTYPE_ADHOC) {
  606. const struct iwl_channel_info *ch_info;
  607. ch_info = iwl_get_channel_info(priv,
  608. priv->band,
  609. le16_to_cpu(priv->staging_rxon.channel));
  610. if (!ch_info || !is_channel_ibss(ch_info)) {
  611. IWL_ERR(priv, "channel %d not IBSS channel\n",
  612. le16_to_cpu(priv->staging_rxon.channel));
  613. return -EINVAL;
  614. }
  615. }
  616. iwl_connection_init_rx_config(priv, mode);
  617. iwl3945_clear_stations_table(priv);
  618. /* don't commit rxon if rf-kill is on*/
  619. if (!iwl_is_ready_rf(priv))
  620. return -EAGAIN;
  621. cancel_delayed_work(&priv->scan_check);
  622. if (iwl_scan_cancel_timeout(priv, 100)) {
  623. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  624. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  625. return -EAGAIN;
  626. }
  627. iwl3945_commit_rxon(priv);
  628. return 0;
  629. }
  630. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  631. struct ieee80211_tx_info *info,
  632. struct iwl_cmd *cmd,
  633. struct sk_buff *skb_frag,
  634. int last_frag)
  635. {
  636. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  637. struct iwl3945_hw_key *keyinfo =
  638. &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
  639. switch (keyinfo->alg) {
  640. case ALG_CCMP:
  641. tx->sec_ctl = TX_CMD_SEC_CCM;
  642. memcpy(tx->key, keyinfo->key, keyinfo->keylen);
  643. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  644. break;
  645. case ALG_TKIP:
  646. #if 0
  647. tx->sec_ctl = TX_CMD_SEC_TKIP;
  648. if (last_frag)
  649. memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
  650. 8);
  651. else
  652. memset(tx->tkip_mic.byte, 0, 8);
  653. #endif
  654. break;
  655. case ALG_WEP:
  656. tx->sec_ctl = TX_CMD_SEC_WEP |
  657. (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  658. if (keyinfo->keylen == 13)
  659. tx->sec_ctl |= TX_CMD_SEC_KEY128;
  660. memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
  661. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  662. "with key %d\n", info->control.hw_key->hw_key_idx);
  663. break;
  664. default:
  665. IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
  666. break;
  667. }
  668. }
  669. /*
  670. * handle build REPLY_TX command notification.
  671. */
  672. static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
  673. struct iwl_cmd *cmd,
  674. struct ieee80211_tx_info *info,
  675. struct ieee80211_hdr *hdr, u8 std_id)
  676. {
  677. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  678. __le32 tx_flags = tx->tx_flags;
  679. __le16 fc = hdr->frame_control;
  680. u8 rc_flags = info->control.rates[0].flags;
  681. tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  682. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  683. tx_flags |= TX_CMD_FLG_ACK_MSK;
  684. if (ieee80211_is_mgmt(fc))
  685. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  686. if (ieee80211_is_probe_resp(fc) &&
  687. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  688. tx_flags |= TX_CMD_FLG_TSF_MSK;
  689. } else {
  690. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  691. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  692. }
  693. tx->sta_id = std_id;
  694. if (ieee80211_has_morefrags(fc))
  695. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  696. if (ieee80211_is_data_qos(fc)) {
  697. u8 *qc = ieee80211_get_qos_ctl(hdr);
  698. tx->tid_tspec = qc[0] & 0xf;
  699. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  700. } else {
  701. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  702. }
  703. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  704. tx_flags |= TX_CMD_FLG_RTS_MSK;
  705. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  706. } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  707. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  708. tx_flags |= TX_CMD_FLG_CTS_MSK;
  709. }
  710. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  711. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  712. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  713. if (ieee80211_is_mgmt(fc)) {
  714. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  715. tx->timeout.pm_frame_timeout = cpu_to_le16(3);
  716. else
  717. tx->timeout.pm_frame_timeout = cpu_to_le16(2);
  718. } else {
  719. tx->timeout.pm_frame_timeout = 0;
  720. #ifdef CONFIG_IWL3945_LEDS
  721. priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
  722. #endif
  723. }
  724. tx->driver_txop = 0;
  725. tx->tx_flags = tx_flags;
  726. tx->next_frame_len = 0;
  727. }
  728. /**
  729. * iwl3945_get_sta_id - Find station's index within station table
  730. */
  731. static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  732. {
  733. int sta_id;
  734. u16 fc = le16_to_cpu(hdr->frame_control);
  735. /* If this frame is broadcast or management, use broadcast station id */
  736. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  737. is_multicast_ether_addr(hdr->addr1))
  738. return priv->hw_params.bcast_sta_id;
  739. switch (priv->iw_mode) {
  740. /* If we are a client station in a BSS network, use the special
  741. * AP station entry (that's the only station we communicate with) */
  742. case NL80211_IFTYPE_STATION:
  743. return IWL_AP_ID;
  744. /* If we are an AP, then find the station, or use BCAST */
  745. case NL80211_IFTYPE_AP:
  746. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  747. if (sta_id != IWL_INVALID_STATION)
  748. return sta_id;
  749. return priv->hw_params.bcast_sta_id;
  750. /* If this frame is going out to an IBSS network, find the station,
  751. * or create a new station table entry */
  752. case NL80211_IFTYPE_ADHOC: {
  753. /* Create new station table entry */
  754. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  755. if (sta_id != IWL_INVALID_STATION)
  756. return sta_id;
  757. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  758. if (sta_id != IWL_INVALID_STATION)
  759. return sta_id;
  760. IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
  761. "Defaulting to broadcast...\n",
  762. hdr->addr1);
  763. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  764. return priv->hw_params.bcast_sta_id;
  765. }
  766. /* If we are in monitor mode, use BCAST. This is required for
  767. * packet injection. */
  768. case NL80211_IFTYPE_MONITOR:
  769. return priv->hw_params.bcast_sta_id;
  770. default:
  771. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  772. priv->iw_mode);
  773. return priv->hw_params.bcast_sta_id;
  774. }
  775. }
  776. /*
  777. * start REPLY_TX command process
  778. */
  779. static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  780. {
  781. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  782. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  783. struct iwl3945_tx_cmd *tx;
  784. struct iwl_tx_queue *txq = NULL;
  785. struct iwl_queue *q = NULL;
  786. struct iwl_cmd *out_cmd = NULL;
  787. dma_addr_t phys_addr;
  788. dma_addr_t txcmd_phys;
  789. int txq_id = skb_get_queue_mapping(skb);
  790. u16 len, idx, len_org, hdr_len;
  791. u8 id;
  792. u8 unicast;
  793. u8 sta_id;
  794. u8 tid = 0;
  795. u16 seq_number = 0;
  796. __le16 fc;
  797. u8 wait_write_ptr = 0;
  798. u8 *qc = NULL;
  799. unsigned long flags;
  800. int rc;
  801. spin_lock_irqsave(&priv->lock, flags);
  802. if (iwl_is_rfkill(priv)) {
  803. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  804. goto drop_unlock;
  805. }
  806. if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
  807. IWL_ERR(priv, "ERROR: No TX rate available.\n");
  808. goto drop_unlock;
  809. }
  810. unicast = !is_multicast_ether_addr(hdr->addr1);
  811. id = 0;
  812. fc = hdr->frame_control;
  813. #ifdef CONFIG_IWLWIFI_DEBUG
  814. if (ieee80211_is_auth(fc))
  815. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  816. else if (ieee80211_is_assoc_req(fc))
  817. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  818. else if (ieee80211_is_reassoc_req(fc))
  819. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  820. #endif
  821. /* drop all data frame if we are not associated */
  822. if (ieee80211_is_data(fc) &&
  823. (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
  824. (!iwl_is_associated(priv) ||
  825. ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
  826. IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
  827. goto drop_unlock;
  828. }
  829. spin_unlock_irqrestore(&priv->lock, flags);
  830. hdr_len = ieee80211_hdrlen(fc);
  831. /* Find (or create) index into station table for destination station */
  832. sta_id = iwl3945_get_sta_id(priv, hdr);
  833. if (sta_id == IWL_INVALID_STATION) {
  834. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  835. hdr->addr1);
  836. goto drop;
  837. }
  838. IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
  839. if (ieee80211_is_data_qos(fc)) {
  840. qc = ieee80211_get_qos_ctl(hdr);
  841. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  842. seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
  843. IEEE80211_SCTL_SEQ;
  844. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  845. (hdr->seq_ctrl &
  846. cpu_to_le16(IEEE80211_SCTL_FRAG));
  847. seq_number += 0x10;
  848. }
  849. /* Descriptor for chosen Tx queue */
  850. txq = &priv->txq[txq_id];
  851. q = &txq->q;
  852. spin_lock_irqsave(&priv->lock, flags);
  853. idx = get_cmd_index(q, q->write_ptr, 0);
  854. /* Set up driver data for this TFD */
  855. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  856. txq->txb[q->write_ptr].skb[0] = skb;
  857. /* Init first empty entry in queue's array of Tx/cmd buffers */
  858. out_cmd = txq->cmd[idx];
  859. tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
  860. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  861. memset(tx, 0, sizeof(*tx));
  862. /*
  863. * Set up the Tx-command (not MAC!) header.
  864. * Store the chosen Tx queue and TFD index within the sequence field;
  865. * after Tx, uCode's Tx response will return this value so driver can
  866. * locate the frame within the tx queue and do post-tx processing.
  867. */
  868. out_cmd->hdr.cmd = REPLY_TX;
  869. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  870. INDEX_TO_SEQ(q->write_ptr)));
  871. /* Copy MAC header from skb into command buffer */
  872. memcpy(tx->hdr, hdr, hdr_len);
  873. /*
  874. * Use the first empty entry in this queue's command buffer array
  875. * to contain the Tx command and MAC header concatenated together
  876. * (payload data will be in another buffer).
  877. * Size of this varies, due to varying MAC header length.
  878. * If end is not dword aligned, we'll have 2 extra bytes at the end
  879. * of the MAC header (device reads on dword boundaries).
  880. * We'll tell device about this padding later.
  881. */
  882. len = sizeof(struct iwl3945_tx_cmd) +
  883. sizeof(struct iwl_cmd_header) + hdr_len;
  884. len_org = len;
  885. len = (len + 3) & ~3;
  886. if (len_org != len)
  887. len_org = 1;
  888. else
  889. len_org = 0;
  890. /* Physical address of this Tx command's header (not MAC header!),
  891. * within command buffer array. */
  892. txcmd_phys = pci_map_single(priv->pci_dev,
  893. out_cmd, sizeof(struct iwl_cmd),
  894. PCI_DMA_TODEVICE);
  895. pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
  896. pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
  897. /* Add buffer containing Tx command and MAC(!) header to TFD's
  898. * first entry */
  899. txcmd_phys += offsetof(struct iwl_cmd, hdr);
  900. /* Add buffer containing Tx command and MAC(!) header to TFD's
  901. * first entry */
  902. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  903. txcmd_phys, len, 1, 0);
  904. if (info->control.hw_key)
  905. iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
  906. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  907. * if any (802.11 null frames have no payload). */
  908. len = skb->len - hdr_len;
  909. if (len) {
  910. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  911. len, PCI_DMA_TODEVICE);
  912. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  913. phys_addr, len,
  914. 0, U32_PAD(len));
  915. }
  916. /* Total # bytes to be transmitted */
  917. len = (u16)skb->len;
  918. tx->len = cpu_to_le16(len);
  919. /* TODO need this for burst mode later on */
  920. iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
  921. /* set is_hcca to 0; it probably will never be implemented */
  922. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
  923. tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  924. tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  925. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  926. txq->need_update = 1;
  927. if (qc)
  928. priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
  929. } else {
  930. wait_write_ptr = 1;
  931. txq->need_update = 0;
  932. }
  933. iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
  934. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
  935. ieee80211_hdrlen(fc));
  936. /* Tell device the write index *just past* this latest filled TFD */
  937. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  938. rc = iwl_txq_update_write_ptr(priv, txq);
  939. spin_unlock_irqrestore(&priv->lock, flags);
  940. if (rc)
  941. return rc;
  942. if ((iwl_queue_space(q) < q->high_mark)
  943. && priv->mac80211_registered) {
  944. if (wait_write_ptr) {
  945. spin_lock_irqsave(&priv->lock, flags);
  946. txq->need_update = 1;
  947. iwl_txq_update_write_ptr(priv, txq);
  948. spin_unlock_irqrestore(&priv->lock, flags);
  949. }
  950. ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
  951. }
  952. return 0;
  953. drop_unlock:
  954. spin_unlock_irqrestore(&priv->lock, flags);
  955. drop:
  956. return -1;
  957. }
  958. static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  959. {
  960. unsigned long flags;
  961. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  962. return;
  963. IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
  964. disable_radio ? "OFF" : "ON");
  965. if (disable_radio) {
  966. iwl_scan_cancel(priv);
  967. /* FIXME: This is a workaround for AP */
  968. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  969. spin_lock_irqsave(&priv->lock, flags);
  970. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  971. CSR_UCODE_SW_BIT_RFKILL);
  972. spin_unlock_irqrestore(&priv->lock, flags);
  973. iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  974. set_bit(STATUS_RF_KILL_SW, &priv->status);
  975. }
  976. return;
  977. }
  978. spin_lock_irqsave(&priv->lock, flags);
  979. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  980. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  981. spin_unlock_irqrestore(&priv->lock, flags);
  982. /* wake up ucode */
  983. msleep(10);
  984. spin_lock_irqsave(&priv->lock, flags);
  985. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  986. if (!iwl_grab_nic_access(priv))
  987. iwl_release_nic_access(priv);
  988. spin_unlock_irqrestore(&priv->lock, flags);
  989. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  990. IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
  991. "disabled by HW switch\n");
  992. return;
  993. }
  994. if (priv->is_open)
  995. queue_work(priv->workqueue, &priv->restart);
  996. return;
  997. }
  998. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  999. #include "iwl-spectrum.h"
  1000. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1001. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1002. #define TIME_UNIT 1024
  1003. /*
  1004. * extended beacon time format
  1005. * time in usec will be changed into a 32-bit value in 8:24 format
  1006. * the high 1 byte is the beacon counts
  1007. * the lower 3 bytes is the time in usec within one beacon interval
  1008. */
  1009. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1010. {
  1011. u32 quot;
  1012. u32 rem;
  1013. u32 interval = beacon_interval * 1024;
  1014. if (!interval || !usec)
  1015. return 0;
  1016. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1017. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1018. return (quot << 24) + rem;
  1019. }
  1020. /* base is usually what we get from ucode with each received frame,
  1021. * the same as HW timer counter counting down
  1022. */
  1023. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1024. {
  1025. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1026. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1027. u32 interval = beacon_interval * TIME_UNIT;
  1028. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1029. (addon & BEACON_TIME_MASK_HIGH);
  1030. if (base_low > addon_low)
  1031. res += base_low - addon_low;
  1032. else if (base_low < addon_low) {
  1033. res += interval + base_low - addon_low;
  1034. res += (1 << 24);
  1035. } else
  1036. res += (1 << 24);
  1037. return cpu_to_le32(res);
  1038. }
  1039. static int iwl3945_get_measurement(struct iwl_priv *priv,
  1040. struct ieee80211_measurement_params *params,
  1041. u8 type)
  1042. {
  1043. struct iwl_spectrum_cmd spectrum;
  1044. struct iwl_rx_packet *res;
  1045. struct iwl_host_cmd cmd = {
  1046. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1047. .data = (void *)&spectrum,
  1048. .meta.flags = CMD_WANT_SKB,
  1049. };
  1050. u32 add_time = le64_to_cpu(params->start_time);
  1051. int rc;
  1052. int spectrum_resp_status;
  1053. int duration = le16_to_cpu(params->duration);
  1054. if (iwl_is_associated(priv))
  1055. add_time =
  1056. iwl3945_usecs_to_beacons(
  1057. le64_to_cpu(params->start_time) - priv->last_tsf,
  1058. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1059. memset(&spectrum, 0, sizeof(spectrum));
  1060. spectrum.channel_count = cpu_to_le16(1);
  1061. spectrum.flags =
  1062. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1063. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1064. cmd.len = sizeof(spectrum);
  1065. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1066. if (iwl_is_associated(priv))
  1067. spectrum.start_time =
  1068. iwl3945_add_beacon_time(priv->last_beacon_time,
  1069. add_time,
  1070. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1071. else
  1072. spectrum.start_time = 0;
  1073. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1074. spectrum.channels[0].channel = params->channel;
  1075. spectrum.channels[0].type = type;
  1076. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1077. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1078. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1079. rc = iwl_send_cmd_sync(priv, &cmd);
  1080. if (rc)
  1081. return rc;
  1082. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1083. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1084. IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
  1085. rc = -EIO;
  1086. }
  1087. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1088. switch (spectrum_resp_status) {
  1089. case 0: /* Command will be handled */
  1090. if (res->u.spectrum.id != 0xff) {
  1091. IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
  1092. res->u.spectrum.id);
  1093. priv->measurement_status &= ~MEASUREMENT_READY;
  1094. }
  1095. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1096. rc = 0;
  1097. break;
  1098. case 1: /* Command will not be handled */
  1099. rc = -EAGAIN;
  1100. break;
  1101. }
  1102. dev_kfree_skb_any(cmd.meta.u.skb);
  1103. return rc;
  1104. }
  1105. #endif
  1106. static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
  1107. struct iwl_rx_mem_buffer *rxb)
  1108. {
  1109. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1110. struct iwl_alive_resp *palive;
  1111. struct delayed_work *pwork;
  1112. palive = &pkt->u.alive_frame;
  1113. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  1114. "0x%01X 0x%01X\n",
  1115. palive->is_valid, palive->ver_type,
  1116. palive->ver_subtype);
  1117. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1118. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  1119. memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
  1120. sizeof(struct iwl_alive_resp));
  1121. pwork = &priv->init_alive_start;
  1122. } else {
  1123. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1124. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1125. sizeof(struct iwl_alive_resp));
  1126. pwork = &priv->alive_start;
  1127. iwl3945_disable_events(priv);
  1128. }
  1129. /* We delay the ALIVE response by 5ms to
  1130. * give the HW RF Kill time to activate... */
  1131. if (palive->is_valid == UCODE_VALID_OK)
  1132. queue_delayed_work(priv->workqueue, pwork,
  1133. msecs_to_jiffies(5));
  1134. else
  1135. IWL_WARN(priv, "uCode did not respond OK.\n");
  1136. }
  1137. static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
  1138. struct iwl_rx_mem_buffer *rxb)
  1139. {
  1140. #ifdef CONFIG_IWLWIFI_DEBUG
  1141. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1142. #endif
  1143. IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  1144. return;
  1145. }
  1146. static void iwl3945_rx_reply_error(struct iwl_priv *priv,
  1147. struct iwl_rx_mem_buffer *rxb)
  1148. {
  1149. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1150. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1151. "seq 0x%04X ser 0x%08X\n",
  1152. le32_to_cpu(pkt->u.err_resp.error_type),
  1153. get_cmd_string(pkt->u.err_resp.cmd_id),
  1154. pkt->u.err_resp.cmd_id,
  1155. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1156. le32_to_cpu(pkt->u.err_resp.error_info));
  1157. }
  1158. static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1159. struct iwl_rx_mem_buffer *rxb)
  1160. {
  1161. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  1162. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1163. struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1164. if (!report->state) {
  1165. IWL_DEBUG(priv, IWL_DL_11H | IWL_DL_INFO,
  1166. "Spectrum Measure Notification: Start\n");
  1167. return;
  1168. }
  1169. memcpy(&priv->measure_report, report, sizeof(*report));
  1170. priv->measurement_status |= MEASUREMENT_READY;
  1171. #endif
  1172. }
  1173. static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
  1174. struct iwl_rx_mem_buffer *rxb)
  1175. {
  1176. #ifdef CONFIG_IWLWIFI_DEBUG
  1177. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1178. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1179. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1180. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1181. #endif
  1182. }
  1183. static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1184. struct iwl_rx_mem_buffer *rxb)
  1185. {
  1186. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1187. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1188. "notification for %s:\n",
  1189. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1190. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
  1191. le32_to_cpu(pkt->len));
  1192. }
  1193. static void iwl3945_bg_beacon_update(struct work_struct *work)
  1194. {
  1195. struct iwl_priv *priv =
  1196. container_of(work, struct iwl_priv, beacon_update);
  1197. struct sk_buff *beacon;
  1198. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1199. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1200. if (!beacon) {
  1201. IWL_ERR(priv, "update beacon failed\n");
  1202. return;
  1203. }
  1204. mutex_lock(&priv->mutex);
  1205. /* new beacon skb is allocated every time; dispose previous.*/
  1206. if (priv->ibss_beacon)
  1207. dev_kfree_skb(priv->ibss_beacon);
  1208. priv->ibss_beacon = beacon;
  1209. mutex_unlock(&priv->mutex);
  1210. iwl3945_send_beacon_cmd(priv);
  1211. }
  1212. static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
  1213. struct iwl_rx_mem_buffer *rxb)
  1214. {
  1215. #ifdef CONFIG_IWLWIFI_DEBUG
  1216. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1217. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  1218. u8 rate = beacon->beacon_notify_hdr.rate;
  1219. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  1220. "tsf %d %d rate %d\n",
  1221. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1222. beacon->beacon_notify_hdr.failure_frame,
  1223. le32_to_cpu(beacon->ibss_mgr_status),
  1224. le32_to_cpu(beacon->high_tsf),
  1225. le32_to_cpu(beacon->low_tsf), rate);
  1226. #endif
  1227. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  1228. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1229. queue_work(priv->workqueue, &priv->beacon_update);
  1230. }
  1231. /* Handle notification from uCode that card's power state is changing
  1232. * due to software, hardware, or critical temperature RFKILL */
  1233. static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
  1234. struct iwl_rx_mem_buffer *rxb)
  1235. {
  1236. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1237. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1238. unsigned long status = priv->status;
  1239. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
  1240. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1241. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1242. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1243. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1244. if (flags & HW_CARD_DISABLED)
  1245. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1246. else
  1247. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1248. if (flags & SW_CARD_DISABLED)
  1249. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1250. else
  1251. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1252. iwl_scan_cancel(priv);
  1253. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1254. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1255. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1256. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1257. queue_work(priv->workqueue, &priv->rf_kill);
  1258. else
  1259. wake_up_interruptible(&priv->wait_command_queue);
  1260. }
  1261. /**
  1262. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  1263. *
  1264. * Setup the RX handlers for each of the reply types sent from the uCode
  1265. * to the host.
  1266. *
  1267. * This function chains into the hardware specific files for them to setup
  1268. * any hardware specific handlers as well.
  1269. */
  1270. static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
  1271. {
  1272. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  1273. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  1274. priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
  1275. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  1276. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1277. iwl3945_rx_spectrum_measure_notif;
  1278. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
  1279. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1280. iwl3945_rx_pm_debug_statistics_notif;
  1281. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  1282. /*
  1283. * The same handler is used for both the REPLY to a discrete
  1284. * statistics request from the host as well as for the periodic
  1285. * statistics notifications (after received beacons) from the uCode.
  1286. */
  1287. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  1288. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  1289. iwl_setup_rx_scan_handlers(priv);
  1290. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  1291. /* Set up hardware specific Rx handlers */
  1292. iwl3945_hw_rx_handler_setup(priv);
  1293. }
  1294. /**
  1295. * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
  1296. * When FW advances 'R' index, all entries between old and new 'R' index
  1297. * need to be reclaimed.
  1298. */
  1299. static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
  1300. int txq_id, int index)
  1301. {
  1302. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1303. struct iwl_queue *q = &txq->q;
  1304. int nfreed = 0;
  1305. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  1306. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  1307. "is out of range [0-%d] %d %d.\n", txq_id,
  1308. index, q->n_bd, q->write_ptr, q->read_ptr);
  1309. return;
  1310. }
  1311. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  1312. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  1313. if (nfreed > 1) {
  1314. IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
  1315. q->write_ptr, q->read_ptr);
  1316. queue_work(priv->workqueue, &priv->restart);
  1317. break;
  1318. }
  1319. nfreed++;
  1320. }
  1321. }
  1322. /**
  1323. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1324. * @rxb: Rx buffer to reclaim
  1325. *
  1326. * If an Rx buffer has an async callback associated with it the callback
  1327. * will be executed. The attached skb (if present) will only be freed
  1328. * if the callback returns 1
  1329. */
  1330. static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
  1331. struct iwl_rx_mem_buffer *rxb)
  1332. {
  1333. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1334. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1335. int txq_id = SEQ_TO_QUEUE(sequence);
  1336. int index = SEQ_TO_INDEX(sequence);
  1337. int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  1338. int cmd_index;
  1339. struct iwl_cmd *cmd;
  1340. if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
  1341. "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
  1342. txq_id, sequence,
  1343. priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
  1344. priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
  1345. iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
  1346. return;
  1347. }
  1348. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1349. cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1350. /* Input error checking is done when commands are added to queue. */
  1351. if (cmd->meta.flags & CMD_WANT_SKB) {
  1352. cmd->meta.source->u.skb = rxb->skb;
  1353. rxb->skb = NULL;
  1354. } else if (cmd->meta.u.callback &&
  1355. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  1356. rxb->skb = NULL;
  1357. iwl3945_cmd_queue_reclaim(priv, txq_id, index);
  1358. if (!(cmd->meta.flags & CMD_ASYNC)) {
  1359. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1360. wake_up_interruptible(&priv->wait_command_queue);
  1361. }
  1362. }
  1363. /************************** RX-FUNCTIONS ****************************/
  1364. /*
  1365. * Rx theory of operation
  1366. *
  1367. * The host allocates 32 DMA target addresses and passes the host address
  1368. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  1369. * 0 to 31
  1370. *
  1371. * Rx Queue Indexes
  1372. * The host/firmware share two index registers for managing the Rx buffers.
  1373. *
  1374. * The READ index maps to the first position that the firmware may be writing
  1375. * to -- the driver can read up to (but not including) this position and get
  1376. * good data.
  1377. * The READ index is managed by the firmware once the card is enabled.
  1378. *
  1379. * The WRITE index maps to the last position the driver has read from -- the
  1380. * position preceding WRITE is the last slot the firmware can place a packet.
  1381. *
  1382. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  1383. * WRITE = READ.
  1384. *
  1385. * During initialization, the host sets up the READ queue position to the first
  1386. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  1387. *
  1388. * When the firmware places a packet in a buffer, it will advance the READ index
  1389. * and fire the RX interrupt. The driver can then query the READ index and
  1390. * process as many packets as possible, moving the WRITE index forward as it
  1391. * resets the Rx queue buffers with new memory.
  1392. *
  1393. * The management in the driver is as follows:
  1394. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  1395. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  1396. * to replenish the iwl->rxq->rx_free.
  1397. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  1398. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  1399. * 'processed' and 'read' driver indexes as well)
  1400. * + A received packet is processed and handed to the kernel network stack,
  1401. * detached from the iwl->rxq. The driver 'processed' index is updated.
  1402. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  1403. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  1404. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  1405. * were enough free buffers and RX_STALLED is set it is cleared.
  1406. *
  1407. *
  1408. * Driver sequence:
  1409. *
  1410. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  1411. * iwl3945_rx_queue_restock
  1412. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  1413. * queue, updates firmware pointers, and updates
  1414. * the WRITE index. If insufficient rx_free buffers
  1415. * are available, schedules iwl3945_rx_replenish
  1416. *
  1417. * -- enable interrupts --
  1418. * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
  1419. * READ INDEX, detaching the SKB from the pool.
  1420. * Moves the packet buffer from queue to rx_used.
  1421. * Calls iwl3945_rx_queue_restock to refill any empty
  1422. * slots.
  1423. * ...
  1424. *
  1425. */
  1426. /**
  1427. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  1428. */
  1429. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
  1430. dma_addr_t dma_addr)
  1431. {
  1432. return cpu_to_le32((u32)dma_addr);
  1433. }
  1434. /**
  1435. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  1436. *
  1437. * If there are slots in the RX queue that need to be restocked,
  1438. * and we have free pre-allocated buffers, fill the ranks as much
  1439. * as we can, pulling from rx_free.
  1440. *
  1441. * This moves the 'write' index forward to catch up with 'processed', and
  1442. * also updates the memory address in the firmware to reference the new
  1443. * target buffer.
  1444. */
  1445. static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
  1446. {
  1447. struct iwl_rx_queue *rxq = &priv->rxq;
  1448. struct list_head *element;
  1449. struct iwl_rx_mem_buffer *rxb;
  1450. unsigned long flags;
  1451. int write, rc;
  1452. spin_lock_irqsave(&rxq->lock, flags);
  1453. write = rxq->write & ~0x7;
  1454. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  1455. /* Get next free Rx buffer, remove from free list */
  1456. element = rxq->rx_free.next;
  1457. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  1458. list_del(element);
  1459. /* Point to Rx buffer via next RBD in circular buffer */
  1460. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
  1461. rxq->queue[rxq->write] = rxb;
  1462. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  1463. rxq->free_count--;
  1464. }
  1465. spin_unlock_irqrestore(&rxq->lock, flags);
  1466. /* If the pre-allocated buffer pool is dropping low, schedule to
  1467. * refill it */
  1468. if (rxq->free_count <= RX_LOW_WATERMARK)
  1469. queue_work(priv->workqueue, &priv->rx_replenish);
  1470. /* If we've added more space for the firmware to place data, tell it.
  1471. * Increment device's write pointer in multiples of 8. */
  1472. if ((write != (rxq->write & ~0x7))
  1473. || (abs(rxq->write - rxq->read) > 7)) {
  1474. spin_lock_irqsave(&rxq->lock, flags);
  1475. rxq->need_update = 1;
  1476. spin_unlock_irqrestore(&rxq->lock, flags);
  1477. rc = iwl_rx_queue_update_write_ptr(priv, rxq);
  1478. if (rc)
  1479. return rc;
  1480. }
  1481. return 0;
  1482. }
  1483. /**
  1484. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  1485. *
  1486. * When moving to rx_free an SKB is allocated for the slot.
  1487. *
  1488. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  1489. * This is called as a scheduled work item (except for during initialization)
  1490. */
  1491. static void iwl3945_rx_allocate(struct iwl_priv *priv)
  1492. {
  1493. struct iwl_rx_queue *rxq = &priv->rxq;
  1494. struct list_head *element;
  1495. struct iwl_rx_mem_buffer *rxb;
  1496. unsigned long flags;
  1497. spin_lock_irqsave(&rxq->lock, flags);
  1498. while (!list_empty(&rxq->rx_used)) {
  1499. element = rxq->rx_used.next;
  1500. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  1501. /* Alloc a new receive buffer */
  1502. rxb->skb =
  1503. alloc_skb(priv->hw_params.rx_buf_size,
  1504. __GFP_NOWARN | GFP_ATOMIC);
  1505. if (!rxb->skb) {
  1506. if (net_ratelimit())
  1507. IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
  1508. /* We don't reschedule replenish work here -- we will
  1509. * call the restock method and if it still needs
  1510. * more buffers it will schedule replenish */
  1511. break;
  1512. }
  1513. /* If radiotap head is required, reserve some headroom here.
  1514. * The physical head count is a variable rx_stats->phy_count.
  1515. * We reserve 4 bytes here. Plus these extra bytes, the
  1516. * headroom of the physical head should be enough for the
  1517. * radiotap head that iwl3945 supported. See iwl3945_rt.
  1518. */
  1519. skb_reserve(rxb->skb, 4);
  1520. priv->alloc_rxb_skb++;
  1521. list_del(element);
  1522. /* Get physical address of RB/SKB */
  1523. rxb->real_dma_addr = pci_map_single(priv->pci_dev,
  1524. rxb->skb->data,
  1525. priv->hw_params.rx_buf_size,
  1526. PCI_DMA_FROMDEVICE);
  1527. list_add_tail(&rxb->list, &rxq->rx_free);
  1528. rxq->free_count++;
  1529. }
  1530. spin_unlock_irqrestore(&rxq->lock, flags);
  1531. }
  1532. /*
  1533. * this should be called while priv->lock is locked
  1534. */
  1535. static void __iwl3945_rx_replenish(void *data)
  1536. {
  1537. struct iwl_priv *priv = data;
  1538. iwl3945_rx_allocate(priv);
  1539. iwl3945_rx_queue_restock(priv);
  1540. }
  1541. void iwl3945_rx_replenish(void *data)
  1542. {
  1543. struct iwl_priv *priv = data;
  1544. unsigned long flags;
  1545. iwl3945_rx_allocate(priv);
  1546. spin_lock_irqsave(&priv->lock, flags);
  1547. iwl3945_rx_queue_restock(priv);
  1548. spin_unlock_irqrestore(&priv->lock, flags);
  1549. }
  1550. /* Convert linear signal-to-noise ratio into dB */
  1551. static u8 ratio2dB[100] = {
  1552. /* 0 1 2 3 4 5 6 7 8 9 */
  1553. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1554. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1555. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1556. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1557. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1558. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1559. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1560. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1561. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1562. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1563. };
  1564. /* Calculates a relative dB value from a ratio of linear
  1565. * (i.e. not dB) signal levels.
  1566. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1567. int iwl3945_calc_db_from_ratio(int sig_ratio)
  1568. {
  1569. /* 1000:1 or higher just report as 60 dB */
  1570. if (sig_ratio >= 1000)
  1571. return 60;
  1572. /* 100:1 or higher, divide by 10 and use table,
  1573. * add 20 dB to make up for divide by 10 */
  1574. if (sig_ratio >= 100)
  1575. return 20 + (int)ratio2dB[sig_ratio/10];
  1576. /* We shouldn't see this */
  1577. if (sig_ratio < 1)
  1578. return 0;
  1579. /* Use table for ratios 1:1 - 99:1 */
  1580. return (int)ratio2dB[sig_ratio];
  1581. }
  1582. #define PERFECT_RSSI (-20) /* dBm */
  1583. #define WORST_RSSI (-95) /* dBm */
  1584. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  1585. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  1586. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  1587. * about formulas used below. */
  1588. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  1589. {
  1590. int sig_qual;
  1591. int degradation = PERFECT_RSSI - rssi_dbm;
  1592. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  1593. * as indicator; formula is (signal dbm - noise dbm).
  1594. * SNR at or above 40 is a great signal (100%).
  1595. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  1596. * Weakest usable signal is usually 10 - 15 dB SNR. */
  1597. if (noise_dbm) {
  1598. if (rssi_dbm - noise_dbm >= 40)
  1599. return 100;
  1600. else if (rssi_dbm < noise_dbm)
  1601. return 0;
  1602. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  1603. /* Else use just the signal level.
  1604. * This formula is a least squares fit of data points collected and
  1605. * compared with a reference system that had a percentage (%) display
  1606. * for signal quality. */
  1607. } else
  1608. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  1609. (15 * RSSI_RANGE + 62 * degradation)) /
  1610. (RSSI_RANGE * RSSI_RANGE);
  1611. if (sig_qual > 100)
  1612. sig_qual = 100;
  1613. else if (sig_qual < 1)
  1614. sig_qual = 0;
  1615. return sig_qual;
  1616. }
  1617. /**
  1618. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  1619. *
  1620. * Uses the priv->rx_handlers callback function array to invoke
  1621. * the appropriate handlers, including command responses,
  1622. * frame-received notifications, and other notifications.
  1623. */
  1624. static void iwl3945_rx_handle(struct iwl_priv *priv)
  1625. {
  1626. struct iwl_rx_mem_buffer *rxb;
  1627. struct iwl_rx_packet *pkt;
  1628. struct iwl_rx_queue *rxq = &priv->rxq;
  1629. u32 r, i;
  1630. int reclaim;
  1631. unsigned long flags;
  1632. u8 fill_rx = 0;
  1633. u32 count = 8;
  1634. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1635. * buffer that the driver may process (last buffer filled by ucode). */
  1636. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  1637. i = rxq->read;
  1638. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  1639. fill_rx = 1;
  1640. /* Rx interrupt, but nothing sent from uCode */
  1641. if (i == r)
  1642. IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  1643. while (i != r) {
  1644. rxb = rxq->queue[i];
  1645. /* If an RXB doesn't have a Rx queue slot associated with it,
  1646. * then a bug has been introduced in the queue refilling
  1647. * routines -- catch it here */
  1648. BUG_ON(rxb == NULL);
  1649. rxq->queue[i] = NULL;
  1650. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
  1651. priv->hw_params.rx_buf_size,
  1652. PCI_DMA_FROMDEVICE);
  1653. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1654. /* Reclaim a command buffer only if this packet is a response
  1655. * to a (driver-originated) command.
  1656. * If the packet (e.g. Rx frame) originated from uCode,
  1657. * there is no command buffer to reclaim.
  1658. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1659. * but apparently a few don't get set; catch them here. */
  1660. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1661. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1662. (pkt->hdr.cmd != REPLY_TX);
  1663. /* Based on type of command response or notification,
  1664. * handle those that need handling via function in
  1665. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  1666. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1667. IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  1668. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  1669. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1670. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1671. } else {
  1672. /* No handling needed */
  1673. IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  1674. "r %d i %d No handler needed for %s, 0x%02x\n",
  1675. r, i, get_cmd_string(pkt->hdr.cmd),
  1676. pkt->hdr.cmd);
  1677. }
  1678. if (reclaim) {
  1679. /* Invoke any callbacks, transfer the skb to caller, and
  1680. * fire off the (possibly) blocking iwl_send_cmd()
  1681. * as we reclaim the driver command queue */
  1682. if (rxb && rxb->skb)
  1683. iwl3945_tx_cmd_complete(priv, rxb);
  1684. else
  1685. IWL_WARN(priv, "Claim null rxb?\n");
  1686. }
  1687. /* For now we just don't re-use anything. We can tweak this
  1688. * later to try and re-use notification packets and SKBs that
  1689. * fail to Rx correctly */
  1690. if (rxb->skb != NULL) {
  1691. priv->alloc_rxb_skb--;
  1692. dev_kfree_skb_any(rxb->skb);
  1693. rxb->skb = NULL;
  1694. }
  1695. pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
  1696. priv->hw_params.rx_buf_size,
  1697. PCI_DMA_FROMDEVICE);
  1698. spin_lock_irqsave(&rxq->lock, flags);
  1699. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  1700. spin_unlock_irqrestore(&rxq->lock, flags);
  1701. i = (i + 1) & RX_QUEUE_MASK;
  1702. /* If there are a lot of unused frames,
  1703. * restock the Rx queue so ucode won't assert. */
  1704. if (fill_rx) {
  1705. count++;
  1706. if (count >= 8) {
  1707. priv->rxq.read = i;
  1708. __iwl3945_rx_replenish(priv);
  1709. count = 0;
  1710. }
  1711. }
  1712. }
  1713. /* Backtrack one entry */
  1714. priv->rxq.read = i;
  1715. iwl3945_rx_queue_restock(priv);
  1716. }
  1717. static void iwl3945_enable_interrupts(struct iwl_priv *priv)
  1718. {
  1719. IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
  1720. set_bit(STATUS_INT_ENABLED, &priv->status);
  1721. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  1722. }
  1723. /* call this function to flush any scheduled tasklet */
  1724. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1725. {
  1726. /* wait to make sure we flush pending tasklet*/
  1727. synchronize_irq(priv->pci_dev->irq);
  1728. tasklet_kill(&priv->irq_tasklet);
  1729. }
  1730. static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
  1731. {
  1732. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1733. /* disable interrupts from uCode/NIC to host */
  1734. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1735. /* acknowledge/clear/reset any interrupts still pending
  1736. * from uCode or flow handler (Rx/Tx DMA) */
  1737. iwl_write32(priv, CSR_INT, 0xffffffff);
  1738. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1739. IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
  1740. }
  1741. static const char *desc_lookup(int i)
  1742. {
  1743. switch (i) {
  1744. case 1:
  1745. return "FAIL";
  1746. case 2:
  1747. return "BAD_PARAM";
  1748. case 3:
  1749. return "BAD_CHECKSUM";
  1750. case 4:
  1751. return "NMI_INTERRUPT";
  1752. case 5:
  1753. return "SYSASSERT";
  1754. case 6:
  1755. return "FATAL_ERROR";
  1756. }
  1757. return "UNKNOWN";
  1758. }
  1759. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1760. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1761. static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
  1762. {
  1763. u32 i;
  1764. u32 desc, time, count, base, data1;
  1765. u32 blink1, blink2, ilink1, ilink2;
  1766. int rc;
  1767. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1768. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1769. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1770. return;
  1771. }
  1772. rc = iwl_grab_nic_access(priv);
  1773. if (rc) {
  1774. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  1775. return;
  1776. }
  1777. count = iwl_read_targ_mem(priv, base);
  1778. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1779. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1780. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1781. priv->status, count);
  1782. }
  1783. IWL_ERR(priv, "Desc Time asrtPC blink2 "
  1784. "ilink1 nmiPC Line\n");
  1785. for (i = ERROR_START_OFFSET;
  1786. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  1787. i += ERROR_ELEM_SIZE) {
  1788. desc = iwl_read_targ_mem(priv, base + i);
  1789. time =
  1790. iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  1791. blink1 =
  1792. iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  1793. blink2 =
  1794. iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  1795. ilink1 =
  1796. iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  1797. ilink2 =
  1798. iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  1799. data1 =
  1800. iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  1801. IWL_ERR(priv,
  1802. "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  1803. desc_lookup(desc), desc, time, blink1, blink2,
  1804. ilink1, ilink2, data1);
  1805. }
  1806. iwl_release_nic_access(priv);
  1807. }
  1808. #define EVENT_START_OFFSET (6 * sizeof(u32))
  1809. /**
  1810. * iwl3945_print_event_log - Dump error event log to syslog
  1811. *
  1812. * NOTE: Must be called with iwl_grab_nic_access() already obtained!
  1813. */
  1814. static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1815. u32 num_events, u32 mode)
  1816. {
  1817. u32 i;
  1818. u32 base; /* SRAM byte address of event log header */
  1819. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1820. u32 ptr; /* SRAM byte address of log data */
  1821. u32 ev, time, data; /* event log data */
  1822. if (num_events == 0)
  1823. return;
  1824. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1825. if (mode == 0)
  1826. event_size = 2 * sizeof(u32);
  1827. else
  1828. event_size = 3 * sizeof(u32);
  1829. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1830. /* "time" is actually "data" for mode 0 (no timestamp).
  1831. * place event id # at far right for easier visual parsing. */
  1832. for (i = 0; i < num_events; i++) {
  1833. ev = iwl_read_targ_mem(priv, ptr);
  1834. ptr += sizeof(u32);
  1835. time = iwl_read_targ_mem(priv, ptr);
  1836. ptr += sizeof(u32);
  1837. if (mode == 0) {
  1838. /* data, ev */
  1839. IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
  1840. } else {
  1841. data = iwl_read_targ_mem(priv, ptr);
  1842. ptr += sizeof(u32);
  1843. IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
  1844. }
  1845. }
  1846. }
  1847. static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
  1848. {
  1849. int rc;
  1850. u32 base; /* SRAM byte address of event log header */
  1851. u32 capacity; /* event log capacity in # entries */
  1852. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1853. u32 num_wraps; /* # times uCode wrapped to top of log */
  1854. u32 next_entry; /* index of next entry to be written by uCode */
  1855. u32 size; /* # entries that we'll print */
  1856. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1857. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1858. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1859. return;
  1860. }
  1861. rc = iwl_grab_nic_access(priv);
  1862. if (rc) {
  1863. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  1864. return;
  1865. }
  1866. /* event log header */
  1867. capacity = iwl_read_targ_mem(priv, base);
  1868. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1869. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1870. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1871. size = num_wraps ? capacity : next_entry;
  1872. /* bail out if nothing in log */
  1873. if (size == 0) {
  1874. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1875. iwl_release_nic_access(priv);
  1876. return;
  1877. }
  1878. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  1879. size, num_wraps);
  1880. /* if uCode has wrapped back to top of log, start at the oldest entry,
  1881. * i.e the next one that uCode would fill. */
  1882. if (num_wraps)
  1883. iwl3945_print_event_log(priv, next_entry,
  1884. capacity - next_entry, mode);
  1885. /* (then/else) start at top of log */
  1886. iwl3945_print_event_log(priv, 0, next_entry, mode);
  1887. iwl_release_nic_access(priv);
  1888. }
  1889. static void iwl3945_error_recovery(struct iwl_priv *priv)
  1890. {
  1891. unsigned long flags;
  1892. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  1893. sizeof(priv->staging_rxon));
  1894. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1895. iwl3945_commit_rxon(priv);
  1896. iwl3945_add_station(priv, priv->bssid, 1, 0);
  1897. spin_lock_irqsave(&priv->lock, flags);
  1898. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  1899. priv->error_recovering = 0;
  1900. spin_unlock_irqrestore(&priv->lock, flags);
  1901. }
  1902. static void iwl3945_irq_tasklet(struct iwl_priv *priv)
  1903. {
  1904. u32 inta, handled = 0;
  1905. u32 inta_fh;
  1906. unsigned long flags;
  1907. #ifdef CONFIG_IWLWIFI_DEBUG
  1908. u32 inta_mask;
  1909. #endif
  1910. spin_lock_irqsave(&priv->lock, flags);
  1911. /* Ack/clear/reset pending uCode interrupts.
  1912. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1913. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1914. inta = iwl_read32(priv, CSR_INT);
  1915. iwl_write32(priv, CSR_INT, inta);
  1916. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1917. * Any new interrupts that happen after this, either while we're
  1918. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1919. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1920. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1921. #ifdef CONFIG_IWLWIFI_DEBUG
  1922. if (priv->debug_level & IWL_DL_ISR) {
  1923. /* just for debug */
  1924. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1925. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1926. inta, inta_mask, inta_fh);
  1927. }
  1928. #endif
  1929. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1930. * atomic, make sure that inta covers all the interrupts that
  1931. * we've discovered, even if FH interrupt came in just after
  1932. * reading CSR_INT. */
  1933. if (inta_fh & CSR39_FH_INT_RX_MASK)
  1934. inta |= CSR_INT_BIT_FH_RX;
  1935. if (inta_fh & CSR39_FH_INT_TX_MASK)
  1936. inta |= CSR_INT_BIT_FH_TX;
  1937. /* Now service all interrupt bits discovered above. */
  1938. if (inta & CSR_INT_BIT_HW_ERR) {
  1939. IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
  1940. /* Tell the device to stop sending interrupts */
  1941. iwl3945_disable_interrupts(priv);
  1942. iwl_irq_handle_error(priv);
  1943. handled |= CSR_INT_BIT_HW_ERR;
  1944. spin_unlock_irqrestore(&priv->lock, flags);
  1945. return;
  1946. }
  1947. #ifdef CONFIG_IWLWIFI_DEBUG
  1948. if (priv->debug_level & (IWL_DL_ISR)) {
  1949. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1950. if (inta & CSR_INT_BIT_SCD)
  1951. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  1952. "the frame/frames.\n");
  1953. /* Alive notification via Rx interrupt will do the real work */
  1954. if (inta & CSR_INT_BIT_ALIVE)
  1955. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  1956. }
  1957. #endif
  1958. /* Safely ignore these bits for debug checks below */
  1959. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1960. /* Error detected by uCode */
  1961. if (inta & CSR_INT_BIT_SW_ERR) {
  1962. IWL_ERR(priv, "Microcode SW error detected. "
  1963. "Restarting 0x%X.\n", inta);
  1964. iwl_irq_handle_error(priv);
  1965. handled |= CSR_INT_BIT_SW_ERR;
  1966. }
  1967. /* uCode wakes up after power-down sleep */
  1968. if (inta & CSR_INT_BIT_WAKEUP) {
  1969. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1970. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1971. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1972. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1973. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1974. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1975. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1976. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1977. handled |= CSR_INT_BIT_WAKEUP;
  1978. }
  1979. /* All uCode command responses, including Tx command responses,
  1980. * Rx "responses" (frame-received notification), and other
  1981. * notifications from uCode come through here*/
  1982. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1983. iwl3945_rx_handle(priv);
  1984. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1985. }
  1986. if (inta & CSR_INT_BIT_FH_TX) {
  1987. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  1988. iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  1989. if (!iwl_grab_nic_access(priv)) {
  1990. iwl_write_direct32(priv, FH39_TCSR_CREDIT
  1991. (FH39_SRVC_CHNL), 0x0);
  1992. iwl_release_nic_access(priv);
  1993. }
  1994. handled |= CSR_INT_BIT_FH_TX;
  1995. }
  1996. if (inta & ~handled)
  1997. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1998. if (inta & ~CSR_INI_SET_MASK) {
  1999. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  2000. inta & ~CSR_INI_SET_MASK);
  2001. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  2002. }
  2003. /* Re-enable all interrupts */
  2004. /* only Re-enable if disabled by irq */
  2005. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2006. iwl3945_enable_interrupts(priv);
  2007. #ifdef CONFIG_IWLWIFI_DEBUG
  2008. if (priv->debug_level & (IWL_DL_ISR)) {
  2009. inta = iwl_read32(priv, CSR_INT);
  2010. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2011. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2012. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  2013. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  2014. }
  2015. #endif
  2016. spin_unlock_irqrestore(&priv->lock, flags);
  2017. }
  2018. static irqreturn_t iwl3945_isr(int irq, void *data)
  2019. {
  2020. struct iwl_priv *priv = data;
  2021. u32 inta, inta_mask;
  2022. u32 inta_fh;
  2023. if (!priv)
  2024. return IRQ_NONE;
  2025. spin_lock(&priv->lock);
  2026. /* Disable (but don't clear!) interrupts here to avoid
  2027. * back-to-back ISRs and sporadic interrupts from our NIC.
  2028. * If we have something to service, the tasklet will re-enable ints.
  2029. * If we *don't* have something, we'll re-enable before leaving here. */
  2030. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2031. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2032. /* Discover which interrupts are active/pending */
  2033. inta = iwl_read32(priv, CSR_INT);
  2034. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2035. /* Ignore interrupt if there's nothing in NIC to service.
  2036. * This may be due to IRQ shared with another device,
  2037. * or due to sporadic interrupts thrown from our NIC. */
  2038. if (!inta && !inta_fh) {
  2039. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  2040. goto none;
  2041. }
  2042. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2043. /* Hardware disappeared */
  2044. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  2045. goto unplugged;
  2046. }
  2047. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2048. inta, inta_mask, inta_fh);
  2049. inta &= ~CSR_INT_BIT_SCD;
  2050. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  2051. if (likely(inta || inta_fh))
  2052. tasklet_schedule(&priv->irq_tasklet);
  2053. unplugged:
  2054. spin_unlock(&priv->lock);
  2055. return IRQ_HANDLED;
  2056. none:
  2057. /* re-enable interrupts here since we don't have anything to service. */
  2058. /* only Re-enable if disabled by irq */
  2059. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2060. iwl3945_enable_interrupts(priv);
  2061. spin_unlock(&priv->lock);
  2062. return IRQ_NONE;
  2063. }
  2064. static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
  2065. enum ieee80211_band band,
  2066. u8 is_active, u8 n_probes,
  2067. struct iwl3945_scan_channel *scan_ch)
  2068. {
  2069. const struct ieee80211_channel *channels = NULL;
  2070. const struct ieee80211_supported_band *sband;
  2071. const struct iwl_channel_info *ch_info;
  2072. u16 passive_dwell = 0;
  2073. u16 active_dwell = 0;
  2074. int added, i;
  2075. sband = iwl_get_hw_mode(priv, band);
  2076. if (!sband)
  2077. return 0;
  2078. channels = sband->channels;
  2079. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  2080. passive_dwell = iwl_get_passive_dwell_time(priv, band);
  2081. if (passive_dwell <= active_dwell)
  2082. passive_dwell = active_dwell + 1;
  2083. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2084. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2085. continue;
  2086. scan_ch->channel = channels[i].hw_value;
  2087. ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
  2088. if (!is_channel_valid(ch_info)) {
  2089. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  2090. scan_ch->channel);
  2091. continue;
  2092. }
  2093. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2094. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2095. /* If passive , set up for auto-switch
  2096. * and use long active_dwell time.
  2097. */
  2098. if (!is_active || is_channel_passive(ch_info) ||
  2099. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
  2100. scan_ch->type = 0; /* passive */
  2101. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  2102. scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
  2103. } else {
  2104. scan_ch->type = 1; /* active */
  2105. }
  2106. /* Set direct probe bits. These may be used both for active
  2107. * scan channels (probes gets sent right away),
  2108. * or for passive channels (probes get se sent only after
  2109. * hearing clear Rx packet).*/
  2110. if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
  2111. if (n_probes)
  2112. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  2113. } else {
  2114. /* uCode v1 does not allow setting direct probe bits on
  2115. * passive channel. */
  2116. if ((scan_ch->type & 1) && n_probes)
  2117. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  2118. }
  2119. /* Set txpower levels to defaults */
  2120. scan_ch->tpc.dsp_atten = 110;
  2121. /* scan_pwr_info->tpc.dsp_atten; */
  2122. /*scan_pwr_info->tpc.tx_gain; */
  2123. if (band == IEEE80211_BAND_5GHZ)
  2124. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2125. else {
  2126. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2127. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2128. * power level:
  2129. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2130. */
  2131. }
  2132. IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
  2133. scan_ch->channel,
  2134. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2135. (scan_ch->type & 1) ?
  2136. active_dwell : passive_dwell);
  2137. scan_ch++;
  2138. added++;
  2139. }
  2140. IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
  2141. return added;
  2142. }
  2143. static void iwl3945_init_hw_rates(struct iwl_priv *priv,
  2144. struct ieee80211_rate *rates)
  2145. {
  2146. int i;
  2147. for (i = 0; i < IWL_RATE_COUNT; i++) {
  2148. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  2149. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2150. rates[i].hw_value_short = i;
  2151. rates[i].flags = 0;
  2152. if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  2153. /*
  2154. * If CCK != 1M then set short preamble rate flag.
  2155. */
  2156. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  2157. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2158. }
  2159. }
  2160. }
  2161. /******************************************************************************
  2162. *
  2163. * uCode download functions
  2164. *
  2165. ******************************************************************************/
  2166. static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
  2167. {
  2168. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2169. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2170. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2171. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2172. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2173. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2174. }
  2175. /**
  2176. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  2177. * looking at all data.
  2178. */
  2179. static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
  2180. {
  2181. u32 val;
  2182. u32 save_len = len;
  2183. int rc = 0;
  2184. u32 errcnt;
  2185. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  2186. rc = iwl_grab_nic_access(priv);
  2187. if (rc)
  2188. return rc;
  2189. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2190. IWL39_RTC_INST_LOWER_BOUND);
  2191. errcnt = 0;
  2192. for (; len > 0; len -= sizeof(u32), image++) {
  2193. /* read data comes through single port, auto-incr addr */
  2194. /* NOTE: Use the debugless read so we don't flood kernel log
  2195. * if IWL_DL_IO is set */
  2196. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2197. if (val != le32_to_cpu(*image)) {
  2198. IWL_ERR(priv, "uCode INST section is invalid at "
  2199. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2200. save_len - len, val, le32_to_cpu(*image));
  2201. rc = -EIO;
  2202. errcnt++;
  2203. if (errcnt >= 20)
  2204. break;
  2205. }
  2206. }
  2207. iwl_release_nic_access(priv);
  2208. if (!errcnt)
  2209. IWL_DEBUG_INFO(priv,
  2210. "ucode image in INSTRUCTION memory is good\n");
  2211. return rc;
  2212. }
  2213. /**
  2214. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  2215. * using sample data 100 bytes apart. If these sample points are good,
  2216. * it's a pretty good bet that everything between them is good, too.
  2217. */
  2218. static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  2219. {
  2220. u32 val;
  2221. int rc = 0;
  2222. u32 errcnt = 0;
  2223. u32 i;
  2224. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  2225. rc = iwl_grab_nic_access(priv);
  2226. if (rc)
  2227. return rc;
  2228. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  2229. /* read data comes through single port, auto-incr addr */
  2230. /* NOTE: Use the debugless read so we don't flood kernel log
  2231. * if IWL_DL_IO is set */
  2232. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2233. i + IWL39_RTC_INST_LOWER_BOUND);
  2234. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2235. if (val != le32_to_cpu(*image)) {
  2236. #if 0 /* Enable this if you want to see details */
  2237. IWL_ERR(priv, "uCode INST section is invalid at "
  2238. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2239. i, val, *image);
  2240. #endif
  2241. rc = -EIO;
  2242. errcnt++;
  2243. if (errcnt >= 3)
  2244. break;
  2245. }
  2246. }
  2247. iwl_release_nic_access(priv);
  2248. return rc;
  2249. }
  2250. /**
  2251. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  2252. * and verify its contents
  2253. */
  2254. static int iwl3945_verify_ucode(struct iwl_priv *priv)
  2255. {
  2256. __le32 *image;
  2257. u32 len;
  2258. int rc = 0;
  2259. /* Try bootstrap */
  2260. image = (__le32 *)priv->ucode_boot.v_addr;
  2261. len = priv->ucode_boot.len;
  2262. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2263. if (rc == 0) {
  2264. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  2265. return 0;
  2266. }
  2267. /* Try initialize */
  2268. image = (__le32 *)priv->ucode_init.v_addr;
  2269. len = priv->ucode_init.len;
  2270. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2271. if (rc == 0) {
  2272. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  2273. return 0;
  2274. }
  2275. /* Try runtime/protocol */
  2276. image = (__le32 *)priv->ucode_code.v_addr;
  2277. len = priv->ucode_code.len;
  2278. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2279. if (rc == 0) {
  2280. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  2281. return 0;
  2282. }
  2283. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  2284. /* Since nothing seems to match, show first several data entries in
  2285. * instruction SRAM, so maybe visual inspection will give a clue.
  2286. * Selection of bootstrap image (vs. other images) is arbitrary. */
  2287. image = (__le32 *)priv->ucode_boot.v_addr;
  2288. len = priv->ucode_boot.len;
  2289. rc = iwl3945_verify_inst_full(priv, image, len);
  2290. return rc;
  2291. }
  2292. static void iwl3945_nic_start(struct iwl_priv *priv)
  2293. {
  2294. /* Remove all resets to allow NIC to operate */
  2295. iwl_write32(priv, CSR_RESET, 0);
  2296. }
  2297. /**
  2298. * iwl3945_read_ucode - Read uCode images from disk file.
  2299. *
  2300. * Copy into buffers for card to fetch via bus-mastering
  2301. */
  2302. static int iwl3945_read_ucode(struct iwl_priv *priv)
  2303. {
  2304. struct iwl_ucode *ucode;
  2305. int ret = -EINVAL, index;
  2306. const struct firmware *ucode_raw;
  2307. /* firmware file name contains uCode/driver compatibility version */
  2308. const char *name_pre = priv->cfg->fw_name_pre;
  2309. const unsigned int api_max = priv->cfg->ucode_api_max;
  2310. const unsigned int api_min = priv->cfg->ucode_api_min;
  2311. char buf[25];
  2312. u8 *src;
  2313. size_t len;
  2314. u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2315. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2316. * request_firmware() is synchronous, file is in memory on return. */
  2317. for (index = api_max; index >= api_min; index--) {
  2318. sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
  2319. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  2320. if (ret < 0) {
  2321. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  2322. buf, ret);
  2323. if (ret == -ENOENT)
  2324. continue;
  2325. else
  2326. goto error;
  2327. } else {
  2328. if (index < api_max)
  2329. IWL_ERR(priv, "Loaded firmware %s, "
  2330. "which is deprecated. "
  2331. " Please use API v%u instead.\n",
  2332. buf, api_max);
  2333. IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
  2334. "(%zd bytes) from disk\n",
  2335. buf, ucode_raw->size);
  2336. break;
  2337. }
  2338. }
  2339. if (ret < 0)
  2340. goto error;
  2341. /* Make sure that we got at least our header! */
  2342. if (ucode_raw->size < sizeof(*ucode)) {
  2343. IWL_ERR(priv, "File size way too small!\n");
  2344. ret = -EINVAL;
  2345. goto err_release;
  2346. }
  2347. /* Data from ucode file: header followed by uCode images */
  2348. ucode = (void *)ucode_raw->data;
  2349. priv->ucode_ver = le32_to_cpu(ucode->ver);
  2350. api_ver = IWL_UCODE_API(priv->ucode_ver);
  2351. inst_size = le32_to_cpu(ucode->inst_size);
  2352. data_size = le32_to_cpu(ucode->data_size);
  2353. init_size = le32_to_cpu(ucode->init_size);
  2354. init_data_size = le32_to_cpu(ucode->init_data_size);
  2355. boot_size = le32_to_cpu(ucode->boot_size);
  2356. /* api_ver should match the api version forming part of the
  2357. * firmware filename ... but we don't check for that and only rely
  2358. * on the API version read from firware header from here on forward */
  2359. if (api_ver < api_min || api_ver > api_max) {
  2360. IWL_ERR(priv, "Driver unable to support your firmware API. "
  2361. "Driver supports v%u, firmware is v%u.\n",
  2362. api_max, api_ver);
  2363. priv->ucode_ver = 0;
  2364. ret = -EINVAL;
  2365. goto err_release;
  2366. }
  2367. if (api_ver != api_max)
  2368. IWL_ERR(priv, "Firmware has old API version. Expected %u, "
  2369. "got %u. New firmware can be obtained "
  2370. "from http://www.intellinuxwireless.org.\n",
  2371. api_max, api_ver);
  2372. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  2373. IWL_UCODE_MAJOR(priv->ucode_ver),
  2374. IWL_UCODE_MINOR(priv->ucode_ver),
  2375. IWL_UCODE_API(priv->ucode_ver),
  2376. IWL_UCODE_SERIAL(priv->ucode_ver));
  2377. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  2378. priv->ucode_ver);
  2379. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
  2380. inst_size);
  2381. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
  2382. data_size);
  2383. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
  2384. init_size);
  2385. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
  2386. init_data_size);
  2387. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
  2388. boot_size);
  2389. /* Verify size of file vs. image size info in file's header */
  2390. if (ucode_raw->size < sizeof(*ucode) +
  2391. inst_size + data_size + init_size +
  2392. init_data_size + boot_size) {
  2393. IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
  2394. ucode_raw->size);
  2395. ret = -EINVAL;
  2396. goto err_release;
  2397. }
  2398. /* Verify that uCode images will fit in card's SRAM */
  2399. if (inst_size > IWL39_MAX_INST_SIZE) {
  2400. IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
  2401. inst_size);
  2402. ret = -EINVAL;
  2403. goto err_release;
  2404. }
  2405. if (data_size > IWL39_MAX_DATA_SIZE) {
  2406. IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
  2407. data_size);
  2408. ret = -EINVAL;
  2409. goto err_release;
  2410. }
  2411. if (init_size > IWL39_MAX_INST_SIZE) {
  2412. IWL_DEBUG_INFO(priv,
  2413. "uCode init instr len %d too large to fit in\n",
  2414. init_size);
  2415. ret = -EINVAL;
  2416. goto err_release;
  2417. }
  2418. if (init_data_size > IWL39_MAX_DATA_SIZE) {
  2419. IWL_DEBUG_INFO(priv,
  2420. "uCode init data len %d too large to fit in\n",
  2421. init_data_size);
  2422. ret = -EINVAL;
  2423. goto err_release;
  2424. }
  2425. if (boot_size > IWL39_MAX_BSM_SIZE) {
  2426. IWL_DEBUG_INFO(priv,
  2427. "uCode boot instr len %d too large to fit in\n",
  2428. boot_size);
  2429. ret = -EINVAL;
  2430. goto err_release;
  2431. }
  2432. /* Allocate ucode buffers for card's bus-master loading ... */
  2433. /* Runtime instructions and 2 copies of data:
  2434. * 1) unmodified from disk
  2435. * 2) backup cache for save/restore during power-downs */
  2436. priv->ucode_code.len = inst_size;
  2437. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  2438. priv->ucode_data.len = data_size;
  2439. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  2440. priv->ucode_data_backup.len = data_size;
  2441. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2442. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  2443. !priv->ucode_data_backup.v_addr)
  2444. goto err_pci_alloc;
  2445. /* Initialization instructions and data */
  2446. if (init_size && init_data_size) {
  2447. priv->ucode_init.len = init_size;
  2448. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  2449. priv->ucode_init_data.len = init_data_size;
  2450. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2451. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  2452. goto err_pci_alloc;
  2453. }
  2454. /* Bootstrap (instructions only, no data) */
  2455. if (boot_size) {
  2456. priv->ucode_boot.len = boot_size;
  2457. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2458. if (!priv->ucode_boot.v_addr)
  2459. goto err_pci_alloc;
  2460. }
  2461. /* Copy images into buffers for card's bus-master reads ... */
  2462. /* Runtime instructions (first block of data in file) */
  2463. src = &ucode->data[0];
  2464. len = priv->ucode_code.len;
  2465. IWL_DEBUG_INFO(priv,
  2466. "Copying (but not loading) uCode instr len %zd\n", len);
  2467. memcpy(priv->ucode_code.v_addr, src, len);
  2468. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  2469. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  2470. /* Runtime data (2nd block)
  2471. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  2472. src = &ucode->data[inst_size];
  2473. len = priv->ucode_data.len;
  2474. IWL_DEBUG_INFO(priv,
  2475. "Copying (but not loading) uCode data len %zd\n", len);
  2476. memcpy(priv->ucode_data.v_addr, src, len);
  2477. memcpy(priv->ucode_data_backup.v_addr, src, len);
  2478. /* Initialization instructions (3rd block) */
  2479. if (init_size) {
  2480. src = &ucode->data[inst_size + data_size];
  2481. len = priv->ucode_init.len;
  2482. IWL_DEBUG_INFO(priv,
  2483. "Copying (but not loading) init instr len %zd\n", len);
  2484. memcpy(priv->ucode_init.v_addr, src, len);
  2485. }
  2486. /* Initialization data (4th block) */
  2487. if (init_data_size) {
  2488. src = &ucode->data[inst_size + data_size + init_size];
  2489. len = priv->ucode_init_data.len;
  2490. IWL_DEBUG_INFO(priv,
  2491. "Copying (but not loading) init data len %zd\n", len);
  2492. memcpy(priv->ucode_init_data.v_addr, src, len);
  2493. }
  2494. /* Bootstrap instructions (5th block) */
  2495. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  2496. len = priv->ucode_boot.len;
  2497. IWL_DEBUG_INFO(priv,
  2498. "Copying (but not loading) boot instr len %zd\n", len);
  2499. memcpy(priv->ucode_boot.v_addr, src, len);
  2500. /* We have our copies now, allow OS release its copies */
  2501. release_firmware(ucode_raw);
  2502. return 0;
  2503. err_pci_alloc:
  2504. IWL_ERR(priv, "failed to allocate pci memory\n");
  2505. ret = -ENOMEM;
  2506. iwl3945_dealloc_ucode_pci(priv);
  2507. err_release:
  2508. release_firmware(ucode_raw);
  2509. error:
  2510. return ret;
  2511. }
  2512. /**
  2513. * iwl3945_set_ucode_ptrs - Set uCode address location
  2514. *
  2515. * Tell initialization uCode where to find runtime uCode.
  2516. *
  2517. * BSM registers initially contain pointers to initialization uCode.
  2518. * We need to replace them to load runtime uCode inst and data,
  2519. * and to save runtime data when powering down.
  2520. */
  2521. static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
  2522. {
  2523. dma_addr_t pinst;
  2524. dma_addr_t pdata;
  2525. int rc = 0;
  2526. unsigned long flags;
  2527. /* bits 31:0 for 3945 */
  2528. pinst = priv->ucode_code.p_addr;
  2529. pdata = priv->ucode_data_backup.p_addr;
  2530. spin_lock_irqsave(&priv->lock, flags);
  2531. rc = iwl_grab_nic_access(priv);
  2532. if (rc) {
  2533. spin_unlock_irqrestore(&priv->lock, flags);
  2534. return rc;
  2535. }
  2536. /* Tell bootstrap uCode where to find image to load */
  2537. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  2538. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  2539. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  2540. priv->ucode_data.len);
  2541. /* Inst byte count must be last to set up, bit 31 signals uCode
  2542. * that all new ptr/size info is in place */
  2543. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  2544. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  2545. iwl_release_nic_access(priv);
  2546. spin_unlock_irqrestore(&priv->lock, flags);
  2547. IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
  2548. return rc;
  2549. }
  2550. /**
  2551. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  2552. *
  2553. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  2554. *
  2555. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  2556. */
  2557. static void iwl3945_init_alive_start(struct iwl_priv *priv)
  2558. {
  2559. /* Check alive response for "valid" sign from uCode */
  2560. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  2561. /* We had an error bringing up the hardware, so take it
  2562. * all the way back down so we can try again */
  2563. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  2564. goto restart;
  2565. }
  2566. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  2567. * This is a paranoid check, because we would not have gotten the
  2568. * "initialize" alive if code weren't properly loaded. */
  2569. if (iwl3945_verify_ucode(priv)) {
  2570. /* Runtime instruction load was bad;
  2571. * take it all the way back down so we can try again */
  2572. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  2573. goto restart;
  2574. }
  2575. /* Send pointers to protocol/runtime uCode image ... init code will
  2576. * load and launch runtime uCode, which will send us another "Alive"
  2577. * notification. */
  2578. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  2579. if (iwl3945_set_ucode_ptrs(priv)) {
  2580. /* Runtime instruction load won't happen;
  2581. * take it all the way back down so we can try again */
  2582. IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
  2583. goto restart;
  2584. }
  2585. return;
  2586. restart:
  2587. queue_work(priv->workqueue, &priv->restart);
  2588. }
  2589. /* temporary */
  2590. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
  2591. struct sk_buff *skb);
  2592. /**
  2593. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  2594. * from protocol/runtime uCode (initialization uCode's
  2595. * Alive gets handled by iwl3945_init_alive_start()).
  2596. */
  2597. static void iwl3945_alive_start(struct iwl_priv *priv)
  2598. {
  2599. int rc = 0;
  2600. int thermal_spin = 0;
  2601. u32 rfkill;
  2602. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  2603. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2604. /* We had an error bringing up the hardware, so take it
  2605. * all the way back down so we can try again */
  2606. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  2607. goto restart;
  2608. }
  2609. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2610. * This is a paranoid check, because we would not have gotten the
  2611. * "runtime" alive if code weren't properly loaded. */
  2612. if (iwl3945_verify_ucode(priv)) {
  2613. /* Runtime instruction load was bad;
  2614. * take it all the way back down so we can try again */
  2615. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  2616. goto restart;
  2617. }
  2618. iwl3945_clear_stations_table(priv);
  2619. rc = iwl_grab_nic_access(priv);
  2620. if (rc) {
  2621. IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
  2622. return;
  2623. }
  2624. rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
  2625. IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
  2626. iwl_release_nic_access(priv);
  2627. if (rfkill & 0x1) {
  2628. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2629. /* if RFKILL is not on, then wait for thermal
  2630. * sensor in adapter to kick in */
  2631. while (iwl3945_hw_get_temperature(priv) == 0) {
  2632. thermal_spin++;
  2633. udelay(10);
  2634. }
  2635. if (thermal_spin)
  2636. IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
  2637. thermal_spin * 10);
  2638. } else
  2639. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2640. /* After the ALIVE response, we can send commands to 3945 uCode */
  2641. set_bit(STATUS_ALIVE, &priv->status);
  2642. /* Clear out the uCode error bit if it is set */
  2643. clear_bit(STATUS_FW_ERROR, &priv->status);
  2644. if (iwl_is_rfkill(priv))
  2645. return;
  2646. ieee80211_wake_queues(priv->hw);
  2647. priv->active_rate = priv->rates_mask;
  2648. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  2649. iwl_power_update_mode(priv, false);
  2650. if (iwl_is_associated(priv)) {
  2651. struct iwl3945_rxon_cmd *active_rxon =
  2652. (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
  2653. memcpy(&priv->staging_rxon, &priv->active_rxon,
  2654. sizeof(priv->staging_rxon));
  2655. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2656. } else {
  2657. /* Initialize our rx_config data */
  2658. iwl_connection_init_rx_config(priv, priv->iw_mode);
  2659. }
  2660. /* Configure Bluetooth device coexistence support */
  2661. iwl_send_bt_config(priv);
  2662. /* Configure the adapter for unassociated operation */
  2663. iwl3945_commit_rxon(priv);
  2664. iwl3945_reg_txpower_periodic(priv);
  2665. iwl3945_led_register(priv);
  2666. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  2667. set_bit(STATUS_READY, &priv->status);
  2668. wake_up_interruptible(&priv->wait_command_queue);
  2669. if (priv->error_recovering)
  2670. iwl3945_error_recovery(priv);
  2671. /* reassociate for ADHOC mode */
  2672. if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
  2673. struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
  2674. priv->vif);
  2675. if (beacon)
  2676. iwl3945_mac_beacon_update(priv->hw, beacon);
  2677. }
  2678. return;
  2679. restart:
  2680. queue_work(priv->workqueue, &priv->restart);
  2681. }
  2682. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
  2683. static void __iwl3945_down(struct iwl_priv *priv)
  2684. {
  2685. unsigned long flags;
  2686. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2687. struct ieee80211_conf *conf = NULL;
  2688. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  2689. conf = ieee80211_get_hw_conf(priv->hw);
  2690. if (!exit_pending)
  2691. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2692. iwl3945_led_unregister(priv);
  2693. iwl3945_clear_stations_table(priv);
  2694. /* Unblock any waiting calls */
  2695. wake_up_interruptible_all(&priv->wait_command_queue);
  2696. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2697. * exiting the module */
  2698. if (!exit_pending)
  2699. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2700. /* stop and reset the on-board processor */
  2701. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2702. /* tell the device to stop sending interrupts */
  2703. spin_lock_irqsave(&priv->lock, flags);
  2704. iwl3945_disable_interrupts(priv);
  2705. spin_unlock_irqrestore(&priv->lock, flags);
  2706. iwl_synchronize_irq(priv);
  2707. if (priv->mac80211_registered)
  2708. ieee80211_stop_queues(priv->hw);
  2709. /* If we have not previously called iwl3945_init() then
  2710. * clear all bits but the RF Kill and SUSPEND bits and return */
  2711. if (!iwl_is_init(priv)) {
  2712. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2713. STATUS_RF_KILL_HW |
  2714. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2715. STATUS_RF_KILL_SW |
  2716. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2717. STATUS_GEO_CONFIGURED |
  2718. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2719. STATUS_IN_SUSPEND |
  2720. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2721. STATUS_EXIT_PENDING;
  2722. goto exit;
  2723. }
  2724. /* ...otherwise clear out all the status bits but the RF Kill and
  2725. * SUSPEND bits and continue taking the NIC down. */
  2726. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2727. STATUS_RF_KILL_HW |
  2728. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2729. STATUS_RF_KILL_SW |
  2730. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2731. STATUS_GEO_CONFIGURED |
  2732. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2733. STATUS_IN_SUSPEND |
  2734. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2735. STATUS_FW_ERROR |
  2736. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2737. STATUS_EXIT_PENDING;
  2738. priv->cfg->ops->lib->apm_ops.reset(priv);
  2739. spin_lock_irqsave(&priv->lock, flags);
  2740. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2741. spin_unlock_irqrestore(&priv->lock, flags);
  2742. iwl3945_hw_txq_ctx_stop(priv);
  2743. iwl3945_hw_rxq_stop(priv);
  2744. spin_lock_irqsave(&priv->lock, flags);
  2745. if (!iwl_grab_nic_access(priv)) {
  2746. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  2747. APMG_CLK_VAL_DMA_CLK_RQT);
  2748. iwl_release_nic_access(priv);
  2749. }
  2750. spin_unlock_irqrestore(&priv->lock, flags);
  2751. udelay(5);
  2752. if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
  2753. priv->cfg->ops->lib->apm_ops.stop(priv);
  2754. else
  2755. priv->cfg->ops->lib->apm_ops.reset(priv);
  2756. exit:
  2757. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2758. if (priv->ibss_beacon)
  2759. dev_kfree_skb(priv->ibss_beacon);
  2760. priv->ibss_beacon = NULL;
  2761. /* clear out any free frames */
  2762. iwl3945_clear_free_frames(priv);
  2763. }
  2764. static void iwl3945_down(struct iwl_priv *priv)
  2765. {
  2766. mutex_lock(&priv->mutex);
  2767. __iwl3945_down(priv);
  2768. mutex_unlock(&priv->mutex);
  2769. iwl3945_cancel_deferred_work(priv);
  2770. }
  2771. #define MAX_HW_RESTARTS 5
  2772. static int __iwl3945_up(struct iwl_priv *priv)
  2773. {
  2774. int rc, i;
  2775. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2776. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2777. return -EIO;
  2778. }
  2779. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  2780. IWL_WARN(priv, "Radio disabled by SW RF kill (module "
  2781. "parameter)\n");
  2782. return -ENODEV;
  2783. }
  2784. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2785. IWL_ERR(priv, "ucode not available for device bring up\n");
  2786. return -EIO;
  2787. }
  2788. /* If platform's RF_KILL switch is NOT set to KILL */
  2789. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2790. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2791. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2792. else {
  2793. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2794. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2795. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2796. return -ENODEV;
  2797. }
  2798. }
  2799. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2800. rc = iwl3945_hw_nic_init(priv);
  2801. if (rc) {
  2802. IWL_ERR(priv, "Unable to int nic\n");
  2803. return rc;
  2804. }
  2805. /* make sure rfkill handshake bits are cleared */
  2806. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2807. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2808. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2809. /* clear (again), then enable host interrupts */
  2810. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2811. iwl3945_enable_interrupts(priv);
  2812. /* really make sure rfkill handshake bits are cleared */
  2813. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2814. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2815. /* Copy original ucode data image from disk into backup cache.
  2816. * This will be used to initialize the on-board processor's
  2817. * data SRAM for a clean start when the runtime program first loads. */
  2818. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2819. priv->ucode_data.len);
  2820. /* We return success when we resume from suspend and rf_kill is on. */
  2821. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2822. return 0;
  2823. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2824. iwl3945_clear_stations_table(priv);
  2825. /* load bootstrap state machine,
  2826. * load bootstrap program into processor's memory,
  2827. * prepare to load the "initialize" uCode */
  2828. priv->cfg->ops->lib->load_ucode(priv);
  2829. if (rc) {
  2830. IWL_ERR(priv,
  2831. "Unable to set up bootstrap uCode: %d\n", rc);
  2832. continue;
  2833. }
  2834. /* start card; "initialize" will load runtime ucode */
  2835. iwl3945_nic_start(priv);
  2836. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2837. return 0;
  2838. }
  2839. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2840. __iwl3945_down(priv);
  2841. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2842. /* tried to restart and config the device for as long as our
  2843. * patience could withstand */
  2844. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2845. return -EIO;
  2846. }
  2847. /*****************************************************************************
  2848. *
  2849. * Workqueue callbacks
  2850. *
  2851. *****************************************************************************/
  2852. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  2853. {
  2854. struct iwl_priv *priv =
  2855. container_of(data, struct iwl_priv, init_alive_start.work);
  2856. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2857. return;
  2858. mutex_lock(&priv->mutex);
  2859. iwl3945_init_alive_start(priv);
  2860. mutex_unlock(&priv->mutex);
  2861. }
  2862. static void iwl3945_bg_alive_start(struct work_struct *data)
  2863. {
  2864. struct iwl_priv *priv =
  2865. container_of(data, struct iwl_priv, alive_start.work);
  2866. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2867. return;
  2868. mutex_lock(&priv->mutex);
  2869. iwl3945_alive_start(priv);
  2870. mutex_unlock(&priv->mutex);
  2871. }
  2872. static void iwl3945_rfkill_poll(struct work_struct *data)
  2873. {
  2874. struct iwl_priv *priv =
  2875. container_of(data, struct iwl_priv, rfkill_poll.work);
  2876. unsigned long status = priv->status;
  2877. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2878. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2879. else
  2880. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2881. if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
  2882. queue_work(priv->workqueue, &priv->rf_kill);
  2883. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  2884. round_jiffies_relative(2 * HZ));
  2885. }
  2886. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  2887. static void iwl3945_bg_request_scan(struct work_struct *data)
  2888. {
  2889. struct iwl_priv *priv =
  2890. container_of(data, struct iwl_priv, request_scan);
  2891. struct iwl_host_cmd cmd = {
  2892. .id = REPLY_SCAN_CMD,
  2893. .len = sizeof(struct iwl3945_scan_cmd),
  2894. .meta.flags = CMD_SIZE_HUGE,
  2895. };
  2896. int rc = 0;
  2897. struct iwl3945_scan_cmd *scan;
  2898. struct ieee80211_conf *conf = NULL;
  2899. u8 n_probes = 2;
  2900. enum ieee80211_band band;
  2901. DECLARE_SSID_BUF(ssid);
  2902. conf = ieee80211_get_hw_conf(priv->hw);
  2903. mutex_lock(&priv->mutex);
  2904. if (!iwl_is_ready(priv)) {
  2905. IWL_WARN(priv, "request scan called when driver not ready.\n");
  2906. goto done;
  2907. }
  2908. /* Make sure the scan wasn't canceled before this queued work
  2909. * was given the chance to run... */
  2910. if (!test_bit(STATUS_SCANNING, &priv->status))
  2911. goto done;
  2912. /* This should never be called or scheduled if there is currently
  2913. * a scan active in the hardware. */
  2914. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2915. IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
  2916. "Ignoring second request.\n");
  2917. rc = -EIO;
  2918. goto done;
  2919. }
  2920. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2921. IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
  2922. goto done;
  2923. }
  2924. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2925. IWL_DEBUG_HC(priv,
  2926. "Scan request while abort pending. Queuing.\n");
  2927. goto done;
  2928. }
  2929. if (iwl_is_rfkill(priv)) {
  2930. IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
  2931. goto done;
  2932. }
  2933. if (!test_bit(STATUS_READY, &priv->status)) {
  2934. IWL_DEBUG_HC(priv,
  2935. "Scan request while uninitialized. Queuing.\n");
  2936. goto done;
  2937. }
  2938. if (!priv->scan_bands) {
  2939. IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
  2940. goto done;
  2941. }
  2942. if (!priv->scan) {
  2943. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  2944. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2945. if (!priv->scan) {
  2946. rc = -ENOMEM;
  2947. goto done;
  2948. }
  2949. }
  2950. scan = priv->scan;
  2951. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2952. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2953. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2954. if (iwl_is_associated(priv)) {
  2955. u16 interval = 0;
  2956. u32 extra;
  2957. u32 suspend_time = 100;
  2958. u32 scan_suspend_time = 100;
  2959. unsigned long flags;
  2960. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  2961. spin_lock_irqsave(&priv->lock, flags);
  2962. interval = priv->beacon_int;
  2963. spin_unlock_irqrestore(&priv->lock, flags);
  2964. scan->suspend_time = 0;
  2965. scan->max_out_time = cpu_to_le32(200 * 1024);
  2966. if (!interval)
  2967. interval = suspend_time;
  2968. /*
  2969. * suspend time format:
  2970. * 0-19: beacon interval in usec (time before exec.)
  2971. * 20-23: 0
  2972. * 24-31: number of beacons (suspend between channels)
  2973. */
  2974. extra = (suspend_time / interval) << 24;
  2975. scan_suspend_time = 0xFF0FFFFF &
  2976. (extra | ((suspend_time % interval) * 1024));
  2977. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2978. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  2979. scan_suspend_time, interval);
  2980. }
  2981. /* We should add the ability for user to lock to PASSIVE ONLY */
  2982. if (priv->one_direct_scan) {
  2983. IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
  2984. print_ssid(ssid, priv->direct_ssid,
  2985. priv->direct_ssid_len));
  2986. scan->direct_scan[0].id = WLAN_EID_SSID;
  2987. scan->direct_scan[0].len = priv->direct_ssid_len;
  2988. memcpy(scan->direct_scan[0].ssid,
  2989. priv->direct_ssid, priv->direct_ssid_len);
  2990. n_probes++;
  2991. } else
  2992. IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
  2993. /* We don't build a direct scan probe request; the uCode will do
  2994. * that based on the direct_mask added to each channel entry */
  2995. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2996. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  2997. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2998. /* flags + rate selection */
  2999. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
  3000. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  3001. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  3002. scan->good_CRC_th = 0;
  3003. band = IEEE80211_BAND_2GHZ;
  3004. } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
  3005. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  3006. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  3007. band = IEEE80211_BAND_5GHZ;
  3008. } else {
  3009. IWL_WARN(priv, "Invalid scan band count\n");
  3010. goto done;
  3011. }
  3012. scan->tx_cmd.len = cpu_to_le16(
  3013. iwl_fill_probe_req(priv, band,
  3014. (struct ieee80211_mgmt *)scan->data,
  3015. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  3016. /* select Rx antennas */
  3017. scan->flags |= iwl3945_get_antenna_flags(priv);
  3018. if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
  3019. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  3020. scan->channel_count =
  3021. iwl3945_get_channels_for_scan(priv, band, 1, /* active */
  3022. n_probes,
  3023. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  3024. if (scan->channel_count == 0) {
  3025. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  3026. goto done;
  3027. }
  3028. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  3029. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  3030. cmd.data = scan;
  3031. scan->len = cpu_to_le16(cmd.len);
  3032. set_bit(STATUS_SCAN_HW, &priv->status);
  3033. rc = iwl_send_cmd_sync(priv, &cmd);
  3034. if (rc)
  3035. goto done;
  3036. queue_delayed_work(priv->workqueue, &priv->scan_check,
  3037. IWL_SCAN_CHECK_WATCHDOG);
  3038. mutex_unlock(&priv->mutex);
  3039. return;
  3040. done:
  3041. /* can not perform scan make sure we clear scanning
  3042. * bits from status so next scan request can be performed.
  3043. * if we dont clear scanning status bit here all next scan
  3044. * will fail
  3045. */
  3046. clear_bit(STATUS_SCAN_HW, &priv->status);
  3047. clear_bit(STATUS_SCANNING, &priv->status);
  3048. /* inform mac80211 scan aborted */
  3049. queue_work(priv->workqueue, &priv->scan_completed);
  3050. mutex_unlock(&priv->mutex);
  3051. }
  3052. static void iwl3945_bg_up(struct work_struct *data)
  3053. {
  3054. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  3055. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3056. return;
  3057. mutex_lock(&priv->mutex);
  3058. __iwl3945_up(priv);
  3059. mutex_unlock(&priv->mutex);
  3060. iwl_rfkill_set_hw_state(priv);
  3061. }
  3062. static void iwl3945_bg_restart(struct work_struct *data)
  3063. {
  3064. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  3065. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3066. return;
  3067. iwl3945_down(priv);
  3068. queue_work(priv->workqueue, &priv->up);
  3069. }
  3070. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  3071. {
  3072. struct iwl_priv *priv =
  3073. container_of(data, struct iwl_priv, rx_replenish);
  3074. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3075. return;
  3076. mutex_lock(&priv->mutex);
  3077. iwl3945_rx_replenish(priv);
  3078. mutex_unlock(&priv->mutex);
  3079. }
  3080. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  3081. static void iwl3945_post_associate(struct iwl_priv *priv)
  3082. {
  3083. int rc = 0;
  3084. struct ieee80211_conf *conf = NULL;
  3085. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  3086. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  3087. return;
  3088. }
  3089. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  3090. priv->assoc_id, priv->active_rxon.bssid_addr);
  3091. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3092. return;
  3093. if (!priv->vif || !priv->is_open)
  3094. return;
  3095. iwl_scan_cancel_timeout(priv, 200);
  3096. conf = ieee80211_get_hw_conf(priv->hw);
  3097. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3098. iwl3945_commit_rxon(priv);
  3099. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  3100. iwl3945_setup_rxon_timing(priv);
  3101. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3102. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3103. if (rc)
  3104. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  3105. "Attempting to continue.\n");
  3106. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3107. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3108. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  3109. priv->assoc_id, priv->beacon_int);
  3110. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3111. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3112. else
  3113. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3114. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3115. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3116. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  3117. else
  3118. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3119. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  3120. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3121. }
  3122. iwl3945_commit_rxon(priv);
  3123. switch (priv->iw_mode) {
  3124. case NL80211_IFTYPE_STATION:
  3125. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  3126. break;
  3127. case NL80211_IFTYPE_ADHOC:
  3128. priv->assoc_id = 1;
  3129. iwl3945_add_station(priv, priv->bssid, 0, 0);
  3130. iwl3945_sync_sta(priv, IWL_STA_ID,
  3131. (priv->band == IEEE80211_BAND_5GHZ) ?
  3132. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  3133. CMD_ASYNC);
  3134. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  3135. iwl3945_send_beacon_cmd(priv);
  3136. break;
  3137. default:
  3138. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  3139. __func__, priv->iw_mode);
  3140. break;
  3141. }
  3142. iwl3945_activate_qos(priv, 0);
  3143. /* we have just associated, don't start scan too early */
  3144. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  3145. }
  3146. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
  3147. /*****************************************************************************
  3148. *
  3149. * mac80211 entry point functions
  3150. *
  3151. *****************************************************************************/
  3152. #define UCODE_READY_TIMEOUT (2 * HZ)
  3153. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  3154. {
  3155. struct iwl_priv *priv = hw->priv;
  3156. int ret;
  3157. IWL_DEBUG_MAC80211(priv, "enter\n");
  3158. /* we should be verifying the device is ready to be opened */
  3159. mutex_lock(&priv->mutex);
  3160. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  3161. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3162. * ucode filename and max sizes are card-specific. */
  3163. if (!priv->ucode_code.len) {
  3164. ret = iwl3945_read_ucode(priv);
  3165. if (ret) {
  3166. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  3167. mutex_unlock(&priv->mutex);
  3168. goto out_release_irq;
  3169. }
  3170. }
  3171. ret = __iwl3945_up(priv);
  3172. mutex_unlock(&priv->mutex);
  3173. iwl_rfkill_set_hw_state(priv);
  3174. if (ret)
  3175. goto out_release_irq;
  3176. IWL_DEBUG_INFO(priv, "Start UP work.\n");
  3177. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3178. return 0;
  3179. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  3180. * mac80211 will not be run successfully. */
  3181. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3182. test_bit(STATUS_READY, &priv->status),
  3183. UCODE_READY_TIMEOUT);
  3184. if (!ret) {
  3185. if (!test_bit(STATUS_READY, &priv->status)) {
  3186. IWL_ERR(priv,
  3187. "Wait for START_ALIVE timeout after %dms.\n",
  3188. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3189. ret = -ETIMEDOUT;
  3190. goto out_release_irq;
  3191. }
  3192. }
  3193. /* ucode is running and will send rfkill notifications,
  3194. * no need to poll the killswitch state anymore */
  3195. cancel_delayed_work(&priv->rfkill_poll);
  3196. priv->is_open = 1;
  3197. IWL_DEBUG_MAC80211(priv, "leave\n");
  3198. return 0;
  3199. out_release_irq:
  3200. priv->is_open = 0;
  3201. IWL_DEBUG_MAC80211(priv, "leave - failed\n");
  3202. return ret;
  3203. }
  3204. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  3205. {
  3206. struct iwl_priv *priv = hw->priv;
  3207. IWL_DEBUG_MAC80211(priv, "enter\n");
  3208. if (!priv->is_open) {
  3209. IWL_DEBUG_MAC80211(priv, "leave - skip\n");
  3210. return;
  3211. }
  3212. priv->is_open = 0;
  3213. if (iwl_is_ready_rf(priv)) {
  3214. /* stop mac, cancel any scan request and clear
  3215. * RXON_FILTER_ASSOC_MSK BIT
  3216. */
  3217. mutex_lock(&priv->mutex);
  3218. iwl_scan_cancel_timeout(priv, 100);
  3219. mutex_unlock(&priv->mutex);
  3220. }
  3221. iwl3945_down(priv);
  3222. flush_workqueue(priv->workqueue);
  3223. /* start polling the killswitch state again */
  3224. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  3225. round_jiffies_relative(2 * HZ));
  3226. IWL_DEBUG_MAC80211(priv, "leave\n");
  3227. }
  3228. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3229. {
  3230. struct iwl_priv *priv = hw->priv;
  3231. IWL_DEBUG_MAC80211(priv, "enter\n");
  3232. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3233. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3234. if (iwl3945_tx_skb(priv, skb))
  3235. dev_kfree_skb_any(skb);
  3236. IWL_DEBUG_MAC80211(priv, "leave\n");
  3237. return NETDEV_TX_OK;
  3238. }
  3239. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  3240. struct ieee80211_if_init_conf *conf)
  3241. {
  3242. struct iwl_priv *priv = hw->priv;
  3243. unsigned long flags;
  3244. IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
  3245. if (priv->vif) {
  3246. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  3247. return -EOPNOTSUPP;
  3248. }
  3249. spin_lock_irqsave(&priv->lock, flags);
  3250. priv->vif = conf->vif;
  3251. priv->iw_mode = conf->type;
  3252. spin_unlock_irqrestore(&priv->lock, flags);
  3253. mutex_lock(&priv->mutex);
  3254. if (conf->mac_addr) {
  3255. IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
  3256. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3257. }
  3258. if (iwl_is_ready(priv))
  3259. iwl3945_set_mode(priv, conf->type);
  3260. mutex_unlock(&priv->mutex);
  3261. IWL_DEBUG_MAC80211(priv, "leave\n");
  3262. return 0;
  3263. }
  3264. /**
  3265. * iwl3945_mac_config - mac80211 config callback
  3266. *
  3267. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3268. * be set inappropriately and the driver currently sets the hardware up to
  3269. * use it whenever needed.
  3270. */
  3271. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
  3272. {
  3273. struct iwl_priv *priv = hw->priv;
  3274. const struct iwl_channel_info *ch_info;
  3275. struct ieee80211_conf *conf = &hw->conf;
  3276. unsigned long flags;
  3277. int ret = 0;
  3278. mutex_lock(&priv->mutex);
  3279. IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
  3280. conf->channel->hw_value);
  3281. if (!iwl_is_ready(priv)) {
  3282. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  3283. ret = -EIO;
  3284. goto out;
  3285. }
  3286. if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
  3287. test_bit(STATUS_SCANNING, &priv->status))) {
  3288. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  3289. set_bit(STATUS_CONF_PENDING, &priv->status);
  3290. mutex_unlock(&priv->mutex);
  3291. return 0;
  3292. }
  3293. spin_lock_irqsave(&priv->lock, flags);
  3294. ch_info = iwl_get_channel_info(priv, conf->channel->band,
  3295. conf->channel->hw_value);
  3296. if (!is_channel_valid(ch_info)) {
  3297. IWL_DEBUG_SCAN(priv,
  3298. "Channel %d [%d] is INVALID for this band.\n",
  3299. conf->channel->hw_value, conf->channel->band);
  3300. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  3301. spin_unlock_irqrestore(&priv->lock, flags);
  3302. ret = -EINVAL;
  3303. goto out;
  3304. }
  3305. iwl_set_rxon_channel(priv, conf->channel);
  3306. iwl_set_flags_for_band(priv, conf->channel->band);
  3307. /* The list of supported rates and rate mask can be different
  3308. * for each phymode; since the phymode may have changed, reset
  3309. * the rate mask to what mac80211 lists */
  3310. iwl_set_rate(priv);
  3311. spin_unlock_irqrestore(&priv->lock, flags);
  3312. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3313. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3314. iwl3945_hw_channel_switch(priv, conf->channel);
  3315. goto out;
  3316. }
  3317. #endif
  3318. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  3319. if (!conf->radio_enabled) {
  3320. IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
  3321. goto out;
  3322. }
  3323. if (iwl_is_rfkill(priv)) {
  3324. IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
  3325. ret = -EIO;
  3326. goto out;
  3327. }
  3328. iwl_set_rate(priv);
  3329. if (memcmp(&priv->active_rxon,
  3330. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  3331. iwl3945_commit_rxon(priv);
  3332. else
  3333. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
  3334. IWL_DEBUG_MAC80211(priv, "leave\n");
  3335. out:
  3336. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3337. mutex_unlock(&priv->mutex);
  3338. return ret;
  3339. }
  3340. static void iwl3945_config_ap(struct iwl_priv *priv)
  3341. {
  3342. int rc = 0;
  3343. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3344. return;
  3345. /* The following should be done only at AP bring up */
  3346. if (!(iwl_is_associated(priv))) {
  3347. /* RXON - unassoc (to set timing command) */
  3348. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3349. iwl3945_commit_rxon(priv);
  3350. /* RXON Timing */
  3351. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  3352. iwl3945_setup_rxon_timing(priv);
  3353. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3354. sizeof(priv->rxon_timing),
  3355. &priv->rxon_timing);
  3356. if (rc)
  3357. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  3358. "Attempting to continue.\n");
  3359. /* FIXME: what should be the assoc_id for AP? */
  3360. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3361. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3362. priv->staging_rxon.flags |=
  3363. RXON_FLG_SHORT_PREAMBLE_MSK;
  3364. else
  3365. priv->staging_rxon.flags &=
  3366. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3367. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3368. if (priv->assoc_capability &
  3369. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3370. priv->staging_rxon.flags |=
  3371. RXON_FLG_SHORT_SLOT_MSK;
  3372. else
  3373. priv->staging_rxon.flags &=
  3374. ~RXON_FLG_SHORT_SLOT_MSK;
  3375. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  3376. priv->staging_rxon.flags &=
  3377. ~RXON_FLG_SHORT_SLOT_MSK;
  3378. }
  3379. /* restore RXON assoc */
  3380. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3381. iwl3945_commit_rxon(priv);
  3382. iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
  3383. }
  3384. iwl3945_send_beacon_cmd(priv);
  3385. /* FIXME - we need to add code here to detect a totally new
  3386. * configuration, reset the AP, unassoc, rxon timing, assoc,
  3387. * clear sta table, add BCAST sta... */
  3388. }
  3389. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
  3390. struct ieee80211_vif *vif,
  3391. struct ieee80211_if_conf *conf)
  3392. {
  3393. struct iwl_priv *priv = hw->priv;
  3394. int rc;
  3395. if (conf == NULL)
  3396. return -EIO;
  3397. if (priv->vif != vif) {
  3398. IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
  3399. return 0;
  3400. }
  3401. /* handle this temporarily here */
  3402. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  3403. conf->changed & IEEE80211_IFCC_BEACON) {
  3404. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  3405. if (!beacon)
  3406. return -ENOMEM;
  3407. mutex_lock(&priv->mutex);
  3408. rc = iwl3945_mac_beacon_update(hw, beacon);
  3409. mutex_unlock(&priv->mutex);
  3410. if (rc)
  3411. return rc;
  3412. }
  3413. if (!iwl_is_alive(priv))
  3414. return -EAGAIN;
  3415. mutex_lock(&priv->mutex);
  3416. if (conf->bssid)
  3417. IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
  3418. /*
  3419. * very dubious code was here; the probe filtering flag is never set:
  3420. *
  3421. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  3422. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  3423. */
  3424. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  3425. if (!conf->bssid) {
  3426. conf->bssid = priv->mac_addr;
  3427. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  3428. IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
  3429. conf->bssid);
  3430. }
  3431. if (priv->ibss_beacon)
  3432. dev_kfree_skb(priv->ibss_beacon);
  3433. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  3434. }
  3435. if (iwl_is_rfkill(priv))
  3436. goto done;
  3437. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  3438. !is_multicast_ether_addr(conf->bssid)) {
  3439. /* If there is currently a HW scan going on in the background
  3440. * then we need to cancel it else the RXON below will fail. */
  3441. if (iwl_scan_cancel_timeout(priv, 100)) {
  3442. IWL_WARN(priv, "Aborted scan still in progress "
  3443. "after 100ms\n");
  3444. IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
  3445. mutex_unlock(&priv->mutex);
  3446. return -EAGAIN;
  3447. }
  3448. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  3449. /* TODO: Audit driver for usage of these members and see
  3450. * if mac80211 deprecates them (priv->bssid looks like it
  3451. * shouldn't be there, but I haven't scanned the IBSS code
  3452. * to verify) - jpk */
  3453. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  3454. if (priv->iw_mode == NL80211_IFTYPE_AP)
  3455. iwl3945_config_ap(priv);
  3456. else {
  3457. rc = iwl3945_commit_rxon(priv);
  3458. if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
  3459. iwl3945_add_station(priv,
  3460. priv->active_rxon.bssid_addr, 1, 0);
  3461. }
  3462. } else {
  3463. iwl_scan_cancel_timeout(priv, 100);
  3464. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3465. iwl3945_commit_rxon(priv);
  3466. }
  3467. done:
  3468. IWL_DEBUG_MAC80211(priv, "leave\n");
  3469. mutex_unlock(&priv->mutex);
  3470. return 0;
  3471. }
  3472. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  3473. struct ieee80211_if_init_conf *conf)
  3474. {
  3475. struct iwl_priv *priv = hw->priv;
  3476. IWL_DEBUG_MAC80211(priv, "enter\n");
  3477. mutex_lock(&priv->mutex);
  3478. if (iwl_is_ready_rf(priv)) {
  3479. iwl_scan_cancel_timeout(priv, 100);
  3480. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3481. iwl3945_commit_rxon(priv);
  3482. }
  3483. if (priv->vif == conf->vif) {
  3484. priv->vif = NULL;
  3485. memset(priv->bssid, 0, ETH_ALEN);
  3486. }
  3487. mutex_unlock(&priv->mutex);
  3488. IWL_DEBUG_MAC80211(priv, "leave\n");
  3489. }
  3490. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  3491. static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
  3492. struct ieee80211_vif *vif,
  3493. struct ieee80211_bss_conf *bss_conf,
  3494. u32 changes)
  3495. {
  3496. struct iwl_priv *priv = hw->priv;
  3497. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  3498. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  3499. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  3500. bss_conf->use_short_preamble);
  3501. if (bss_conf->use_short_preamble)
  3502. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3503. else
  3504. priv->staging_rxon.flags &=
  3505. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3506. }
  3507. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  3508. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
  3509. bss_conf->use_cts_prot);
  3510. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  3511. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  3512. else
  3513. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  3514. }
  3515. if (changes & BSS_CHANGED_ASSOC) {
  3516. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  3517. /* This should never happen as this function should
  3518. * never be called from interrupt context. */
  3519. if (WARN_ON_ONCE(in_interrupt()))
  3520. return;
  3521. if (bss_conf->assoc) {
  3522. priv->assoc_id = bss_conf->aid;
  3523. priv->beacon_int = bss_conf->beacon_int;
  3524. priv->timestamp = bss_conf->timestamp;
  3525. priv->assoc_capability = bss_conf->assoc_capability;
  3526. priv->power_data.dtim_period = bss_conf->dtim_period;
  3527. priv->next_scan_jiffies = jiffies +
  3528. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  3529. mutex_lock(&priv->mutex);
  3530. iwl3945_post_associate(priv);
  3531. mutex_unlock(&priv->mutex);
  3532. } else {
  3533. priv->assoc_id = 0;
  3534. IWL_DEBUG_MAC80211(priv,
  3535. "DISASSOC %d\n", bss_conf->assoc);
  3536. }
  3537. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  3538. IWL_DEBUG_MAC80211(priv,
  3539. "Associated Changes %d\n", changes);
  3540. iwl3945_send_rxon_assoc(priv);
  3541. }
  3542. }
  3543. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3544. struct ieee80211_vif *vif,
  3545. struct ieee80211_sta *sta,
  3546. struct ieee80211_key_conf *key)
  3547. {
  3548. struct iwl_priv *priv = hw->priv;
  3549. const u8 *addr;
  3550. int ret;
  3551. u8 sta_id;
  3552. IWL_DEBUG_MAC80211(priv, "enter\n");
  3553. if (iwl3945_mod_params.sw_crypto) {
  3554. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  3555. return -EOPNOTSUPP;
  3556. }
  3557. addr = sta ? sta->addr : iwl_bcast_addr;
  3558. sta_id = iwl3945_hw_find_station(priv, addr);
  3559. if (sta_id == IWL_INVALID_STATION) {
  3560. IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
  3561. addr);
  3562. return -EINVAL;
  3563. }
  3564. mutex_lock(&priv->mutex);
  3565. iwl_scan_cancel_timeout(priv, 100);
  3566. switch (cmd) {
  3567. case SET_KEY:
  3568. ret = iwl3945_update_sta_key_info(priv, key, sta_id);
  3569. if (!ret) {
  3570. iwl_set_rxon_hwcrypto(priv, 1);
  3571. iwl3945_commit_rxon(priv);
  3572. key->hw_key_idx = sta_id;
  3573. IWL_DEBUG_MAC80211(priv,
  3574. "set_key success, using hwcrypto\n");
  3575. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  3576. }
  3577. break;
  3578. case DISABLE_KEY:
  3579. ret = iwl3945_clear_sta_key_info(priv, sta_id);
  3580. if (!ret) {
  3581. iwl_set_rxon_hwcrypto(priv, 0);
  3582. iwl3945_commit_rxon(priv);
  3583. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  3584. }
  3585. break;
  3586. default:
  3587. ret = -EINVAL;
  3588. }
  3589. IWL_DEBUG_MAC80211(priv, "leave\n");
  3590. mutex_unlock(&priv->mutex);
  3591. return ret;
  3592. }
  3593. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3594. const struct ieee80211_tx_queue_params *params)
  3595. {
  3596. struct iwl_priv *priv = hw->priv;
  3597. unsigned long flags;
  3598. int q;
  3599. IWL_DEBUG_MAC80211(priv, "enter\n");
  3600. if (!iwl_is_ready_rf(priv)) {
  3601. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3602. return -EIO;
  3603. }
  3604. if (queue >= AC_NUM) {
  3605. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  3606. return 0;
  3607. }
  3608. q = AC_NUM - 1 - queue;
  3609. spin_lock_irqsave(&priv->lock, flags);
  3610. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  3611. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  3612. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  3613. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  3614. cpu_to_le16((params->txop * 32));
  3615. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  3616. priv->qos_data.qos_active = 1;
  3617. spin_unlock_irqrestore(&priv->lock, flags);
  3618. mutex_lock(&priv->mutex);
  3619. if (priv->iw_mode == NL80211_IFTYPE_AP)
  3620. iwl3945_activate_qos(priv, 1);
  3621. else if (priv->assoc_id && iwl_is_associated(priv))
  3622. iwl3945_activate_qos(priv, 0);
  3623. mutex_unlock(&priv->mutex);
  3624. IWL_DEBUG_MAC80211(priv, "leave\n");
  3625. return 0;
  3626. }
  3627. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  3628. struct ieee80211_tx_queue_stats *stats)
  3629. {
  3630. struct iwl_priv *priv = hw->priv;
  3631. int i, avail;
  3632. struct iwl_tx_queue *txq;
  3633. struct iwl_queue *q;
  3634. unsigned long flags;
  3635. IWL_DEBUG_MAC80211(priv, "enter\n");
  3636. if (!iwl_is_ready_rf(priv)) {
  3637. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3638. return -EIO;
  3639. }
  3640. spin_lock_irqsave(&priv->lock, flags);
  3641. for (i = 0; i < AC_NUM; i++) {
  3642. txq = &priv->txq[i];
  3643. q = &txq->q;
  3644. avail = iwl_queue_space(q);
  3645. stats[i].len = q->n_window - avail;
  3646. stats[i].limit = q->n_window - q->high_mark;
  3647. stats[i].count = q->n_window;
  3648. }
  3649. spin_unlock_irqrestore(&priv->lock, flags);
  3650. IWL_DEBUG_MAC80211(priv, "leave\n");
  3651. return 0;
  3652. }
  3653. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  3654. {
  3655. struct iwl_priv *priv = hw->priv;
  3656. unsigned long flags;
  3657. mutex_lock(&priv->mutex);
  3658. IWL_DEBUG_MAC80211(priv, "enter\n");
  3659. iwl_reset_qos(priv);
  3660. spin_lock_irqsave(&priv->lock, flags);
  3661. priv->assoc_id = 0;
  3662. priv->assoc_capability = 0;
  3663. /* new association get rid of ibss beacon skb */
  3664. if (priv->ibss_beacon)
  3665. dev_kfree_skb(priv->ibss_beacon);
  3666. priv->ibss_beacon = NULL;
  3667. priv->beacon_int = priv->hw->conf.beacon_int;
  3668. priv->timestamp = 0;
  3669. if ((priv->iw_mode == NL80211_IFTYPE_STATION))
  3670. priv->beacon_int = 0;
  3671. spin_unlock_irqrestore(&priv->lock, flags);
  3672. if (!iwl_is_ready_rf(priv)) {
  3673. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  3674. mutex_unlock(&priv->mutex);
  3675. return;
  3676. }
  3677. /* we are restarting association process
  3678. * clear RXON_FILTER_ASSOC_MSK bit
  3679. */
  3680. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  3681. iwl_scan_cancel_timeout(priv, 100);
  3682. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3683. iwl3945_commit_rxon(priv);
  3684. }
  3685. /* Per mac80211.h: This is only used in IBSS mode... */
  3686. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  3687. IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
  3688. mutex_unlock(&priv->mutex);
  3689. return;
  3690. }
  3691. iwl_set_rate(priv);
  3692. mutex_unlock(&priv->mutex);
  3693. IWL_DEBUG_MAC80211(priv, "leave\n");
  3694. }
  3695. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  3696. {
  3697. struct iwl_priv *priv = hw->priv;
  3698. unsigned long flags;
  3699. IWL_DEBUG_MAC80211(priv, "enter\n");
  3700. if (!iwl_is_ready_rf(priv)) {
  3701. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3702. return -EIO;
  3703. }
  3704. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  3705. IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
  3706. return -EIO;
  3707. }
  3708. spin_lock_irqsave(&priv->lock, flags);
  3709. if (priv->ibss_beacon)
  3710. dev_kfree_skb(priv->ibss_beacon);
  3711. priv->ibss_beacon = skb;
  3712. priv->assoc_id = 0;
  3713. IWL_DEBUG_MAC80211(priv, "leave\n");
  3714. spin_unlock_irqrestore(&priv->lock, flags);
  3715. iwl_reset_qos(priv);
  3716. iwl3945_post_associate(priv);
  3717. return 0;
  3718. }
  3719. /*****************************************************************************
  3720. *
  3721. * sysfs attributes
  3722. *
  3723. *****************************************************************************/
  3724. #ifdef CONFIG_IWLWIFI_DEBUG
  3725. /*
  3726. * The following adds a new attribute to the sysfs representation
  3727. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  3728. * used for controlling the debug level.
  3729. *
  3730. * See the level definitions in iwl for details.
  3731. */
  3732. static ssize_t show_debug_level(struct device *d,
  3733. struct device_attribute *attr, char *buf)
  3734. {
  3735. struct iwl_priv *priv = d->driver_data;
  3736. return sprintf(buf, "0x%08X\n", priv->debug_level);
  3737. }
  3738. static ssize_t store_debug_level(struct device *d,
  3739. struct device_attribute *attr,
  3740. const char *buf, size_t count)
  3741. {
  3742. struct iwl_priv *priv = d->driver_data;
  3743. unsigned long val;
  3744. int ret;
  3745. ret = strict_strtoul(buf, 0, &val);
  3746. if (ret)
  3747. IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
  3748. else
  3749. priv->debug_level = val;
  3750. return strnlen(buf, count);
  3751. }
  3752. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3753. show_debug_level, store_debug_level);
  3754. #endif /* CONFIG_IWLWIFI_DEBUG */
  3755. static ssize_t show_temperature(struct device *d,
  3756. struct device_attribute *attr, char *buf)
  3757. {
  3758. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3759. if (!iwl_is_alive(priv))
  3760. return -EAGAIN;
  3761. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  3762. }
  3763. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  3764. static ssize_t show_tx_power(struct device *d,
  3765. struct device_attribute *attr, char *buf)
  3766. {
  3767. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3768. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  3769. }
  3770. static ssize_t store_tx_power(struct device *d,
  3771. struct device_attribute *attr,
  3772. const char *buf, size_t count)
  3773. {
  3774. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3775. char *p = (char *)buf;
  3776. u32 val;
  3777. val = simple_strtoul(p, &p, 10);
  3778. if (p == buf)
  3779. IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
  3780. else
  3781. iwl3945_hw_reg_set_txpower(priv, val);
  3782. return count;
  3783. }
  3784. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  3785. static ssize_t show_flags(struct device *d,
  3786. struct device_attribute *attr, char *buf)
  3787. {
  3788. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3789. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  3790. }
  3791. static ssize_t store_flags(struct device *d,
  3792. struct device_attribute *attr,
  3793. const char *buf, size_t count)
  3794. {
  3795. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3796. u32 flags = simple_strtoul(buf, NULL, 0);
  3797. mutex_lock(&priv->mutex);
  3798. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  3799. /* Cancel any currently running scans... */
  3800. if (iwl_scan_cancel_timeout(priv, 100))
  3801. IWL_WARN(priv, "Could not cancel scan.\n");
  3802. else {
  3803. IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
  3804. flags);
  3805. priv->staging_rxon.flags = cpu_to_le32(flags);
  3806. iwl3945_commit_rxon(priv);
  3807. }
  3808. }
  3809. mutex_unlock(&priv->mutex);
  3810. return count;
  3811. }
  3812. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  3813. static ssize_t show_filter_flags(struct device *d,
  3814. struct device_attribute *attr, char *buf)
  3815. {
  3816. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3817. return sprintf(buf, "0x%04X\n",
  3818. le32_to_cpu(priv->active_rxon.filter_flags));
  3819. }
  3820. static ssize_t store_filter_flags(struct device *d,
  3821. struct device_attribute *attr,
  3822. const char *buf, size_t count)
  3823. {
  3824. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3825. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3826. mutex_lock(&priv->mutex);
  3827. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  3828. /* Cancel any currently running scans... */
  3829. if (iwl_scan_cancel_timeout(priv, 100))
  3830. IWL_WARN(priv, "Could not cancel scan.\n");
  3831. else {
  3832. IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
  3833. "0x%04X\n", filter_flags);
  3834. priv->staging_rxon.filter_flags =
  3835. cpu_to_le32(filter_flags);
  3836. iwl3945_commit_rxon(priv);
  3837. }
  3838. }
  3839. mutex_unlock(&priv->mutex);
  3840. return count;
  3841. }
  3842. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3843. store_filter_flags);
  3844. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  3845. static ssize_t show_measurement(struct device *d,
  3846. struct device_attribute *attr, char *buf)
  3847. {
  3848. struct iwl_priv *priv = dev_get_drvdata(d);
  3849. struct iwl_spectrum_notification measure_report;
  3850. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3851. u8 *data = (u8 *)&measure_report;
  3852. unsigned long flags;
  3853. spin_lock_irqsave(&priv->lock, flags);
  3854. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3855. spin_unlock_irqrestore(&priv->lock, flags);
  3856. return 0;
  3857. }
  3858. memcpy(&measure_report, &priv->measure_report, size);
  3859. priv->measurement_status = 0;
  3860. spin_unlock_irqrestore(&priv->lock, flags);
  3861. while (size && (PAGE_SIZE - len)) {
  3862. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3863. PAGE_SIZE - len, 1);
  3864. len = strlen(buf);
  3865. if (PAGE_SIZE - len)
  3866. buf[len++] = '\n';
  3867. ofs += 16;
  3868. size -= min(size, 16U);
  3869. }
  3870. return len;
  3871. }
  3872. static ssize_t store_measurement(struct device *d,
  3873. struct device_attribute *attr,
  3874. const char *buf, size_t count)
  3875. {
  3876. struct iwl_priv *priv = dev_get_drvdata(d);
  3877. struct ieee80211_measurement_params params = {
  3878. .channel = le16_to_cpu(priv->active_rxon.channel),
  3879. .start_time = cpu_to_le64(priv->last_tsf),
  3880. .duration = cpu_to_le16(1),
  3881. };
  3882. u8 type = IWL_MEASURE_BASIC;
  3883. u8 buffer[32];
  3884. u8 channel;
  3885. if (count) {
  3886. char *p = buffer;
  3887. strncpy(buffer, buf, min(sizeof(buffer), count));
  3888. channel = simple_strtoul(p, NULL, 0);
  3889. if (channel)
  3890. params.channel = channel;
  3891. p = buffer;
  3892. while (*p && *p != ' ')
  3893. p++;
  3894. if (*p)
  3895. type = simple_strtoul(p + 1, NULL, 0);
  3896. }
  3897. IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
  3898. "channel %d (for '%s')\n", type, params.channel, buf);
  3899. iwl3945_get_measurement(priv, &params, type);
  3900. return count;
  3901. }
  3902. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3903. show_measurement, store_measurement);
  3904. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  3905. static ssize_t store_retry_rate(struct device *d,
  3906. struct device_attribute *attr,
  3907. const char *buf, size_t count)
  3908. {
  3909. struct iwl_priv *priv = dev_get_drvdata(d);
  3910. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3911. if (priv->retry_rate <= 0)
  3912. priv->retry_rate = 1;
  3913. return count;
  3914. }
  3915. static ssize_t show_retry_rate(struct device *d,
  3916. struct device_attribute *attr, char *buf)
  3917. {
  3918. struct iwl_priv *priv = dev_get_drvdata(d);
  3919. return sprintf(buf, "%d", priv->retry_rate);
  3920. }
  3921. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3922. store_retry_rate);
  3923. static ssize_t store_power_level(struct device *d,
  3924. struct device_attribute *attr,
  3925. const char *buf, size_t count)
  3926. {
  3927. struct iwl_priv *priv = dev_get_drvdata(d);
  3928. int ret;
  3929. unsigned long mode;
  3930. mutex_lock(&priv->mutex);
  3931. if (!iwl_is_ready(priv)) {
  3932. ret = -EAGAIN;
  3933. goto out;
  3934. }
  3935. ret = strict_strtoul(buf, 10, &mode);
  3936. if (ret)
  3937. goto out;
  3938. ret = iwl_power_set_user_mode(priv, mode);
  3939. if (ret) {
  3940. IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
  3941. goto out;
  3942. }
  3943. ret = count;
  3944. out:
  3945. mutex_unlock(&priv->mutex);
  3946. return ret;
  3947. }
  3948. static ssize_t show_power_level(struct device *d,
  3949. struct device_attribute *attr, char *buf)
  3950. {
  3951. struct iwl_priv *priv = dev_get_drvdata(d);
  3952. int mode = priv->power_data.user_power_setting;
  3953. int system = priv->power_data.system_power_setting;
  3954. int level = priv->power_data.power_mode;
  3955. char *p = buf;
  3956. switch (system) {
  3957. case IWL_POWER_SYS_AUTO:
  3958. p += sprintf(p, "SYSTEM:auto");
  3959. break;
  3960. case IWL_POWER_SYS_AC:
  3961. p += sprintf(p, "SYSTEM:ac");
  3962. break;
  3963. case IWL_POWER_SYS_BATTERY:
  3964. p += sprintf(p, "SYSTEM:battery");
  3965. break;
  3966. }
  3967. p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
  3968. "fixed" : "auto");
  3969. p += sprintf(p, "\tINDEX:%d", level);
  3970. p += sprintf(p, "\n");
  3971. return p - buf + 1;
  3972. }
  3973. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
  3974. show_power_level, store_power_level);
  3975. #define MAX_WX_STRING 80
  3976. /* Values are in microsecond */
  3977. static const s32 timeout_duration[] = {
  3978. 350000,
  3979. 250000,
  3980. 75000,
  3981. 37000,
  3982. 25000,
  3983. };
  3984. static const s32 period_duration[] = {
  3985. 400000,
  3986. 700000,
  3987. 1000000,
  3988. 1000000,
  3989. 1000000
  3990. };
  3991. static ssize_t show_channels(struct device *d,
  3992. struct device_attribute *attr, char *buf)
  3993. {
  3994. /* all this shit doesn't belong into sysfs anyway */
  3995. return 0;
  3996. }
  3997. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  3998. static ssize_t show_statistics(struct device *d,
  3999. struct device_attribute *attr, char *buf)
  4000. {
  4001. struct iwl_priv *priv = dev_get_drvdata(d);
  4002. u32 size = sizeof(struct iwl3945_notif_statistics);
  4003. u32 len = 0, ofs = 0;
  4004. u8 *data = (u8 *)&priv->statistics_39;
  4005. int rc = 0;
  4006. if (!iwl_is_alive(priv))
  4007. return -EAGAIN;
  4008. mutex_lock(&priv->mutex);
  4009. rc = iwl_send_statistics_request(priv, 0);
  4010. mutex_unlock(&priv->mutex);
  4011. if (rc) {
  4012. len = sprintf(buf,
  4013. "Error sending statistics request: 0x%08X\n", rc);
  4014. return len;
  4015. }
  4016. while (size && (PAGE_SIZE - len)) {
  4017. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4018. PAGE_SIZE - len, 1);
  4019. len = strlen(buf);
  4020. if (PAGE_SIZE - len)
  4021. buf[len++] = '\n';
  4022. ofs += 16;
  4023. size -= min(size, 16U);
  4024. }
  4025. return len;
  4026. }
  4027. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  4028. static ssize_t show_antenna(struct device *d,
  4029. struct device_attribute *attr, char *buf)
  4030. {
  4031. struct iwl_priv *priv = dev_get_drvdata(d);
  4032. if (!iwl_is_alive(priv))
  4033. return -EAGAIN;
  4034. return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
  4035. }
  4036. static ssize_t store_antenna(struct device *d,
  4037. struct device_attribute *attr,
  4038. const char *buf, size_t count)
  4039. {
  4040. struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
  4041. int ant;
  4042. if (count == 0)
  4043. return 0;
  4044. if (sscanf(buf, "%1i", &ant) != 1) {
  4045. IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
  4046. return count;
  4047. }
  4048. if ((ant >= 0) && (ant <= 2)) {
  4049. IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
  4050. iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
  4051. } else
  4052. IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
  4053. return count;
  4054. }
  4055. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  4056. static ssize_t show_status(struct device *d,
  4057. struct device_attribute *attr, char *buf)
  4058. {
  4059. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4060. if (!iwl_is_alive(priv))
  4061. return -EAGAIN;
  4062. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4063. }
  4064. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4065. static ssize_t dump_error_log(struct device *d,
  4066. struct device_attribute *attr,
  4067. const char *buf, size_t count)
  4068. {
  4069. char *p = (char *)buf;
  4070. if (p[0] == '1')
  4071. iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
  4072. return strnlen(buf, count);
  4073. }
  4074. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  4075. static ssize_t dump_event_log(struct device *d,
  4076. struct device_attribute *attr,
  4077. const char *buf, size_t count)
  4078. {
  4079. char *p = (char *)buf;
  4080. if (p[0] == '1')
  4081. iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
  4082. return strnlen(buf, count);
  4083. }
  4084. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  4085. /*****************************************************************************
  4086. *
  4087. * driver setup and tear down
  4088. *
  4089. *****************************************************************************/
  4090. static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
  4091. {
  4092. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  4093. init_waitqueue_head(&priv->wait_command_queue);
  4094. INIT_WORK(&priv->up, iwl3945_bg_up);
  4095. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  4096. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  4097. INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
  4098. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  4099. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  4100. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  4101. INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
  4102. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  4103. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  4104. INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
  4105. INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
  4106. iwl3945_hw_setup_deferred_work(priv);
  4107. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4108. iwl3945_irq_tasklet, (unsigned long)priv);
  4109. }
  4110. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
  4111. {
  4112. iwl3945_hw_cancel_deferred_work(priv);
  4113. cancel_delayed_work_sync(&priv->init_alive_start);
  4114. cancel_delayed_work(&priv->scan_check);
  4115. cancel_delayed_work(&priv->alive_start);
  4116. cancel_work_sync(&priv->beacon_update);
  4117. }
  4118. static struct attribute *iwl3945_sysfs_entries[] = {
  4119. &dev_attr_antenna.attr,
  4120. &dev_attr_channels.attr,
  4121. &dev_attr_dump_errors.attr,
  4122. &dev_attr_dump_events.attr,
  4123. &dev_attr_flags.attr,
  4124. &dev_attr_filter_flags.attr,
  4125. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  4126. &dev_attr_measurement.attr,
  4127. #endif
  4128. &dev_attr_power_level.attr,
  4129. &dev_attr_retry_rate.attr,
  4130. &dev_attr_statistics.attr,
  4131. &dev_attr_status.attr,
  4132. &dev_attr_temperature.attr,
  4133. &dev_attr_tx_power.attr,
  4134. #ifdef CONFIG_IWLWIFI_DEBUG
  4135. &dev_attr_debug_level.attr,
  4136. #endif
  4137. NULL
  4138. };
  4139. static struct attribute_group iwl3945_attribute_group = {
  4140. .name = NULL, /* put in device directory */
  4141. .attrs = iwl3945_sysfs_entries,
  4142. };
  4143. static struct ieee80211_ops iwl3945_hw_ops = {
  4144. .tx = iwl3945_mac_tx,
  4145. .start = iwl3945_mac_start,
  4146. .stop = iwl3945_mac_stop,
  4147. .add_interface = iwl3945_mac_add_interface,
  4148. .remove_interface = iwl3945_mac_remove_interface,
  4149. .config = iwl3945_mac_config,
  4150. .config_interface = iwl3945_mac_config_interface,
  4151. .configure_filter = iwl_configure_filter,
  4152. .set_key = iwl3945_mac_set_key,
  4153. .get_tx_stats = iwl3945_mac_get_tx_stats,
  4154. .conf_tx = iwl3945_mac_conf_tx,
  4155. .reset_tsf = iwl3945_mac_reset_tsf,
  4156. .bss_info_changed = iwl3945_bss_info_changed,
  4157. .hw_scan = iwl_mac_hw_scan
  4158. };
  4159. static int iwl3945_init_drv(struct iwl_priv *priv)
  4160. {
  4161. int ret;
  4162. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  4163. priv->retry_rate = 1;
  4164. priv->ibss_beacon = NULL;
  4165. spin_lock_init(&priv->lock);
  4166. spin_lock_init(&priv->power_data.lock);
  4167. spin_lock_init(&priv->sta_lock);
  4168. spin_lock_init(&priv->hcmd_lock);
  4169. INIT_LIST_HEAD(&priv->free_frames);
  4170. mutex_init(&priv->mutex);
  4171. /* Clear the driver's (not device's) station table */
  4172. iwl3945_clear_stations_table(priv);
  4173. priv->data_retry_limit = -1;
  4174. priv->ieee_channels = NULL;
  4175. priv->ieee_rates = NULL;
  4176. priv->band = IEEE80211_BAND_2GHZ;
  4177. priv->iw_mode = NL80211_IFTYPE_STATION;
  4178. iwl_reset_qos(priv);
  4179. priv->qos_data.qos_active = 0;
  4180. priv->qos_data.qos_cap.val = 0;
  4181. priv->rates_mask = IWL_RATES_MASK;
  4182. /* If power management is turned on, default to CAM mode */
  4183. priv->power_mode = IWL_POWER_MODE_CAM;
  4184. priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
  4185. if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
  4186. IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
  4187. eeprom->version);
  4188. ret = -EINVAL;
  4189. goto err;
  4190. }
  4191. ret = iwl_init_channel_map(priv);
  4192. if (ret) {
  4193. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  4194. goto err;
  4195. }
  4196. /* Set up txpower settings in driver for all channels */
  4197. if (iwl3945_txpower_set_from_eeprom(priv)) {
  4198. ret = -EIO;
  4199. goto err_free_channel_map;
  4200. }
  4201. ret = iwlcore_init_geos(priv);
  4202. if (ret) {
  4203. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  4204. goto err_free_channel_map;
  4205. }
  4206. iwl3945_init_hw_rates(priv, priv->ieee_rates);
  4207. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  4208. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4209. &priv->bands[IEEE80211_BAND_2GHZ];
  4210. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  4211. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4212. &priv->bands[IEEE80211_BAND_5GHZ];
  4213. return 0;
  4214. err_free_channel_map:
  4215. iwl_free_channel_map(priv);
  4216. err:
  4217. return ret;
  4218. }
  4219. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4220. {
  4221. int err = 0;
  4222. struct iwl_priv *priv;
  4223. struct ieee80211_hw *hw;
  4224. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4225. struct iwl3945_eeprom *eeprom;
  4226. unsigned long flags;
  4227. /***********************
  4228. * 1. Allocating HW data
  4229. * ********************/
  4230. /* mac80211 allocates memory for this device instance, including
  4231. * space for this driver's private structure */
  4232. hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
  4233. if (hw == NULL) {
  4234. printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
  4235. err = -ENOMEM;
  4236. goto out;
  4237. }
  4238. priv = hw->priv;
  4239. SET_IEEE80211_DEV(hw, &pdev->dev);
  4240. if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
  4241. (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
  4242. IWL_ERR(priv,
  4243. "invalid queues_num, should be between %d and %d\n",
  4244. IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
  4245. err = -EINVAL;
  4246. goto out;
  4247. }
  4248. /*
  4249. * Disabling hardware scan means that mac80211 will perform scans
  4250. * "the hard way", rather than using device's scan.
  4251. */
  4252. if (iwl3945_mod_params.disable_hw_scan) {
  4253. IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
  4254. iwl3945_hw_ops.hw_scan = NULL;
  4255. }
  4256. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  4257. priv->cfg = cfg;
  4258. priv->pci_dev = pdev;
  4259. #ifdef CONFIG_IWLWIFI_DEBUG
  4260. priv->debug_level = iwl3945_mod_params.debug;
  4261. atomic_set(&priv->restrict_refcnt, 0);
  4262. #endif
  4263. hw->rate_control_algorithm = "iwl-3945-rs";
  4264. hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
  4265. /* Tell mac80211 our characteristics */
  4266. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4267. IEEE80211_HW_NOISE_DBM;
  4268. hw->wiphy->interface_modes =
  4269. BIT(NL80211_IFTYPE_STATION) |
  4270. BIT(NL80211_IFTYPE_ADHOC);
  4271. hw->wiphy->custom_regulatory = true;
  4272. hw->wiphy->max_scan_ssids = 1;
  4273. /* 4 EDCA QOS priorities */
  4274. hw->queues = 4;
  4275. /***************************
  4276. * 2. Initializing PCI bus
  4277. * *************************/
  4278. if (pci_enable_device(pdev)) {
  4279. err = -ENODEV;
  4280. goto out_ieee80211_free_hw;
  4281. }
  4282. pci_set_master(pdev);
  4283. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4284. if (!err)
  4285. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  4286. if (err) {
  4287. IWL_WARN(priv, "No suitable DMA available.\n");
  4288. goto out_pci_disable_device;
  4289. }
  4290. pci_set_drvdata(pdev, priv);
  4291. err = pci_request_regions(pdev, DRV_NAME);
  4292. if (err)
  4293. goto out_pci_disable_device;
  4294. /***********************
  4295. * 3. Read REV Register
  4296. * ********************/
  4297. priv->hw_base = pci_iomap(pdev, 0, 0);
  4298. if (!priv->hw_base) {
  4299. err = -ENODEV;
  4300. goto out_pci_release_regions;
  4301. }
  4302. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  4303. (unsigned long long) pci_resource_len(pdev, 0));
  4304. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  4305. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  4306. * PCI Tx retries from interfering with C3 CPU state */
  4307. pci_write_config_byte(pdev, 0x41, 0x00);
  4308. /* amp init */
  4309. err = priv->cfg->ops->lib->apm_ops.init(priv);
  4310. if (err < 0) {
  4311. IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
  4312. goto out_iounmap;
  4313. }
  4314. /***********************
  4315. * 4. Read EEPROM
  4316. * ********************/
  4317. /* Read the EEPROM */
  4318. err = iwl_eeprom_init(priv);
  4319. if (err) {
  4320. IWL_ERR(priv, "Unable to init EEPROM\n");
  4321. goto out_remove_sysfs;
  4322. }
  4323. /* MAC Address location in EEPROM same for 3945/4965 */
  4324. eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  4325. memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
  4326. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
  4327. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  4328. /***********************
  4329. * 5. Setup HW Constants
  4330. * ********************/
  4331. /* Device-specific setup */
  4332. if (iwl3945_hw_set_hw_params(priv)) {
  4333. IWL_ERR(priv, "failed to set hw settings\n");
  4334. goto out_iounmap;
  4335. }
  4336. /***********************
  4337. * 6. Setup priv
  4338. * ********************/
  4339. err = iwl3945_init_drv(priv);
  4340. if (err) {
  4341. IWL_ERR(priv, "initializing driver failed\n");
  4342. goto out_free_geos;
  4343. }
  4344. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
  4345. priv->cfg->name);
  4346. /***********************************
  4347. * 7. Initialize Module Parameters
  4348. * **********************************/
  4349. /* Initialize module parameter values here */
  4350. /* Disable radio (SW RF KILL) via parameter when loading driver */
  4351. if (iwl3945_mod_params.disable) {
  4352. set_bit(STATUS_RF_KILL_SW, &priv->status);
  4353. IWL_DEBUG_INFO(priv, "Radio disabled.\n");
  4354. }
  4355. /***********************
  4356. * 8. Setup Services
  4357. * ********************/
  4358. spin_lock_irqsave(&priv->lock, flags);
  4359. iwl3945_disable_interrupts(priv);
  4360. spin_unlock_irqrestore(&priv->lock, flags);
  4361. pci_enable_msi(priv->pci_dev);
  4362. err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
  4363. DRV_NAME, priv);
  4364. if (err) {
  4365. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  4366. goto out_disable_msi;
  4367. }
  4368. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4369. if (err) {
  4370. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  4371. goto out_release_irq;
  4372. }
  4373. iwl_set_rxon_channel(priv,
  4374. &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
  4375. iwl3945_setup_deferred_work(priv);
  4376. iwl3945_setup_rx_handlers(priv);
  4377. /*********************************
  4378. * 9. Setup and Register mac80211
  4379. * *******************************/
  4380. err = ieee80211_register_hw(priv->hw);
  4381. if (err) {
  4382. IWL_ERR(priv, "Failed to register network device: %d\n", err);
  4383. goto out_remove_sysfs;
  4384. }
  4385. priv->hw->conf.beacon_int = 100;
  4386. priv->mac80211_registered = 1;
  4387. err = iwl_rfkill_init(priv);
  4388. if (err)
  4389. IWL_ERR(priv, "Unable to initialize RFKILL system. "
  4390. "Ignoring error: %d\n", err);
  4391. /* Start monitoring the killswitch */
  4392. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  4393. 2 * HZ);
  4394. return 0;
  4395. out_remove_sysfs:
  4396. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4397. out_free_geos:
  4398. iwlcore_free_geos(priv);
  4399. out_release_irq:
  4400. free_irq(priv->pci_dev->irq, priv);
  4401. destroy_workqueue(priv->workqueue);
  4402. priv->workqueue = NULL;
  4403. iwl3945_unset_hw_params(priv);
  4404. out_disable_msi:
  4405. pci_disable_msi(priv->pci_dev);
  4406. out_iounmap:
  4407. pci_iounmap(pdev, priv->hw_base);
  4408. out_pci_release_regions:
  4409. pci_release_regions(pdev);
  4410. out_pci_disable_device:
  4411. pci_disable_device(pdev);
  4412. pci_set_drvdata(pdev, NULL);
  4413. out_ieee80211_free_hw:
  4414. ieee80211_free_hw(priv->hw);
  4415. out:
  4416. return err;
  4417. }
  4418. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  4419. {
  4420. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4421. unsigned long flags;
  4422. if (!priv)
  4423. return;
  4424. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  4425. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4426. if (priv->mac80211_registered) {
  4427. ieee80211_unregister_hw(priv->hw);
  4428. priv->mac80211_registered = 0;
  4429. } else {
  4430. iwl3945_down(priv);
  4431. }
  4432. /* make sure we flush any pending irq or
  4433. * tasklet for the driver
  4434. */
  4435. spin_lock_irqsave(&priv->lock, flags);
  4436. iwl3945_disable_interrupts(priv);
  4437. spin_unlock_irqrestore(&priv->lock, flags);
  4438. iwl_synchronize_irq(priv);
  4439. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4440. iwl_rfkill_unregister(priv);
  4441. cancel_delayed_work(&priv->rfkill_poll);
  4442. iwl3945_dealloc_ucode_pci(priv);
  4443. if (priv->rxq.bd)
  4444. iwl_rx_queue_free(priv, &priv->rxq);
  4445. iwl3945_hw_txq_ctx_free(priv);
  4446. iwl3945_unset_hw_params(priv);
  4447. iwl3945_clear_stations_table(priv);
  4448. /*netif_stop_queue(dev); */
  4449. flush_workqueue(priv->workqueue);
  4450. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  4451. * priv->workqueue... so we can't take down the workqueue
  4452. * until now... */
  4453. destroy_workqueue(priv->workqueue);
  4454. priv->workqueue = NULL;
  4455. free_irq(pdev->irq, priv);
  4456. pci_disable_msi(pdev);
  4457. pci_iounmap(pdev, priv->hw_base);
  4458. pci_release_regions(pdev);
  4459. pci_disable_device(pdev);
  4460. pci_set_drvdata(pdev, NULL);
  4461. iwl_free_channel_map(priv);
  4462. iwlcore_free_geos(priv);
  4463. kfree(priv->scan);
  4464. if (priv->ibss_beacon)
  4465. dev_kfree_skb(priv->ibss_beacon);
  4466. ieee80211_free_hw(priv->hw);
  4467. }
  4468. #ifdef CONFIG_PM
  4469. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4470. {
  4471. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4472. if (priv->is_open) {
  4473. set_bit(STATUS_IN_SUSPEND, &priv->status);
  4474. iwl3945_mac_stop(priv->hw);
  4475. priv->is_open = 1;
  4476. }
  4477. pci_save_state(pdev);
  4478. pci_disable_device(pdev);
  4479. pci_set_power_state(pdev, PCI_D3hot);
  4480. return 0;
  4481. }
  4482. static int iwl3945_pci_resume(struct pci_dev *pdev)
  4483. {
  4484. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4485. int ret;
  4486. pci_set_power_state(pdev, PCI_D0);
  4487. ret = pci_enable_device(pdev);
  4488. if (ret)
  4489. return ret;
  4490. pci_restore_state(pdev);
  4491. if (priv->is_open)
  4492. iwl3945_mac_start(priv->hw);
  4493. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  4494. return 0;
  4495. }
  4496. #endif /* CONFIG_PM */
  4497. /*****************************************************************************
  4498. *
  4499. * driver and module entry point
  4500. *
  4501. *****************************************************************************/
  4502. static struct pci_driver iwl3945_driver = {
  4503. .name = DRV_NAME,
  4504. .id_table = iwl3945_hw_card_ids,
  4505. .probe = iwl3945_pci_probe,
  4506. .remove = __devexit_p(iwl3945_pci_remove),
  4507. #ifdef CONFIG_PM
  4508. .suspend = iwl3945_pci_suspend,
  4509. .resume = iwl3945_pci_resume,
  4510. #endif
  4511. };
  4512. static int __init iwl3945_init(void)
  4513. {
  4514. int ret;
  4515. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  4516. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  4517. ret = iwl3945_rate_control_register();
  4518. if (ret) {
  4519. printk(KERN_ERR DRV_NAME
  4520. "Unable to register rate control algorithm: %d\n", ret);
  4521. return ret;
  4522. }
  4523. ret = pci_register_driver(&iwl3945_driver);
  4524. if (ret) {
  4525. printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
  4526. goto error_register;
  4527. }
  4528. return ret;
  4529. error_register:
  4530. iwl3945_rate_control_unregister();
  4531. return ret;
  4532. }
  4533. static void __exit iwl3945_exit(void)
  4534. {
  4535. pci_unregister_driver(&iwl3945_driver);
  4536. iwl3945_rate_control_unregister();
  4537. }
  4538. MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
  4539. module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
  4540. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  4541. module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
  4542. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  4543. module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
  4544. MODULE_PARM_DESC(swcrypto,
  4545. "using software crypto (default 1 [software])\n");
  4546. module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
  4547. MODULE_PARM_DESC(debug, "debug output mask");
  4548. module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
  4549. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  4550. module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
  4551. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  4552. module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
  4553. MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
  4554. module_exit(iwl3945_exit);
  4555. module_init(iwl3945_init);