iwl-agn.c 123 KB

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