iwl-agn.c 124 KB

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