iwl-agn.c 112 KB

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