iwl-agn.c 113 KB

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