iwl4965-base.c 122 KB

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