iwl3945-base.c 146 KB

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