iwl-agn.c 116 KB

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