iwl3945-base.c 148 KB

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