iwl4965-base.c 122 KB

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