iwl4965-base.c 126 KB

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