iwl-agn.c 115 KB

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