iwl3945-base.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/wireless.h>
  42. #include <linux/firmware.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_arp.h>
  45. #include <net/ieee80211_radiotap.h>
  46. #include <net/mac80211.h>
  47. #include <asm/div64.h>
  48. #define DRV_NAME "iwl3945"
  49. #include "iwl-fh.h"
  50. #include "iwl-3945-fh.h"
  51. #include "iwl-commands.h"
  52. #include "iwl-sta.h"
  53. #include "iwl-3945.h"
  54. #include "iwl-core.h"
  55. #include "iwl-helpers.h"
  56. #include "iwl-dev.h"
  57. #include "iwl-spectrum.h"
  58. /*
  59. * module name, copyright, version, etc.
  60. */
  61. #define DRV_DESCRIPTION \
  62. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  63. #ifdef CONFIG_IWLWIFI_DEBUG
  64. #define VD "d"
  65. #else
  66. #define VD
  67. #endif
  68. /*
  69. * add "s" to indicate spectrum measurement included.
  70. * we add it here to be consistent with previous releases in which
  71. * this was configurable.
  72. */
  73. #define DRV_VERSION IWLWIFI_VERSION VD "s"
  74. #define DRV_COPYRIGHT "Copyright(c) 2003-2010 Intel Corporation"
  75. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  76. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  77. MODULE_VERSION(DRV_VERSION);
  78. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  79. MODULE_LICENSE("GPL");
  80. /* module parameters */
  81. struct iwl_mod_params iwl3945_mod_params = {
  82. .sw_crypto = 1,
  83. .restart_fw = 1,
  84. /* the rest are 0 by default */
  85. };
  86. /**
  87. * iwl3945_get_antenna_flags - Get antenna flags for RXON command
  88. * @priv: eeprom and antenna fields are used to determine antenna flags
  89. *
  90. * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
  91. * iwl3945_mod_params.antenna specifies the antenna diversity mode:
  92. *
  93. * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
  94. * IWL_ANTENNA_MAIN - Force MAIN antenna
  95. * IWL_ANTENNA_AUX - Force AUX antenna
  96. */
  97. __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
  98. {
  99. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  100. switch (iwl3945_mod_params.antenna) {
  101. case IWL_ANTENNA_DIVERSITY:
  102. return 0;
  103. case IWL_ANTENNA_MAIN:
  104. if (eeprom->antenna_switch_type)
  105. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  106. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  107. case IWL_ANTENNA_AUX:
  108. if (eeprom->antenna_switch_type)
  109. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  110. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  111. }
  112. /* bad antenna selector value */
  113. IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
  114. iwl3945_mod_params.antenna);
  115. return 0; /* "diversity" is default if error */
  116. }
  117. static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  118. struct ieee80211_key_conf *keyconf,
  119. u8 sta_id)
  120. {
  121. unsigned long flags;
  122. __le16 key_flags = 0;
  123. int ret;
  124. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  125. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  126. if (sta_id == priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id)
  127. key_flags |= STA_KEY_MULTICAST_MSK;
  128. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  129. keyconf->hw_key_idx = keyconf->keyidx;
  130. key_flags &= ~STA_KEY_FLG_INVALID;
  131. spin_lock_irqsave(&priv->sta_lock, flags);
  132. priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  133. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  134. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  135. keyconf->keylen);
  136. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  137. keyconf->keylen);
  138. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  139. == STA_KEY_FLG_NO_ENC)
  140. priv->stations[sta_id].sta.key.key_offset =
  141. iwl_get_free_ucode_key_index(priv);
  142. /* else, we are overriding an existing key => no need to allocated room
  143. * in uCode. */
  144. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  145. "no space for a new key");
  146. priv->stations[sta_id].sta.key.key_flags = key_flags;
  147. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  148. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  149. IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
  150. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  151. spin_unlock_irqrestore(&priv->sta_lock, flags);
  152. return ret;
  153. }
  154. static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  155. struct ieee80211_key_conf *keyconf,
  156. u8 sta_id)
  157. {
  158. return -EOPNOTSUPP;
  159. }
  160. static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
  161. struct ieee80211_key_conf *keyconf,
  162. u8 sta_id)
  163. {
  164. return -EOPNOTSUPP;
  165. }
  166. static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
  167. {
  168. unsigned long flags;
  169. struct iwl_addsta_cmd sta_cmd;
  170. spin_lock_irqsave(&priv->sta_lock, flags);
  171. memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
  172. memset(&priv->stations[sta_id].sta.key, 0,
  173. sizeof(struct iwl4965_keyinfo));
  174. priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  175. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  176. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  177. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
  178. spin_unlock_irqrestore(&priv->sta_lock, flags);
  179. IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
  180. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  181. }
  182. static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
  183. struct ieee80211_key_conf *keyconf, u8 sta_id)
  184. {
  185. int ret = 0;
  186. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  187. switch (keyconf->cipher) {
  188. case WLAN_CIPHER_SUITE_CCMP:
  189. ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  190. break;
  191. case WLAN_CIPHER_SUITE_TKIP:
  192. ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  193. break;
  194. case WLAN_CIPHER_SUITE_WEP40:
  195. case WLAN_CIPHER_SUITE_WEP104:
  196. ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  197. break;
  198. default:
  199. IWL_ERR(priv, "Unknown alg: %s alg=%x\n", __func__,
  200. keyconf->cipher);
  201. ret = -EINVAL;
  202. }
  203. IWL_DEBUG_WEP(priv, "Set dynamic key: alg=%x len=%d idx=%d sta=%d ret=%d\n",
  204. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  205. sta_id, ret);
  206. return ret;
  207. }
  208. static int iwl3945_remove_static_key(struct iwl_priv *priv)
  209. {
  210. int ret = -EOPNOTSUPP;
  211. return ret;
  212. }
  213. static int iwl3945_set_static_key(struct iwl_priv *priv,
  214. struct ieee80211_key_conf *key)
  215. {
  216. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  217. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  218. return -EOPNOTSUPP;
  219. IWL_ERR(priv, "Static key invalid: cipher %x\n", key->cipher);
  220. return -EINVAL;
  221. }
  222. static void iwl3945_clear_free_frames(struct iwl_priv *priv)
  223. {
  224. struct list_head *element;
  225. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  226. priv->frames_count);
  227. while (!list_empty(&priv->free_frames)) {
  228. element = priv->free_frames.next;
  229. list_del(element);
  230. kfree(list_entry(element, struct iwl3945_frame, list));
  231. priv->frames_count--;
  232. }
  233. if (priv->frames_count) {
  234. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  235. priv->frames_count);
  236. priv->frames_count = 0;
  237. }
  238. }
  239. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
  240. {
  241. struct iwl3945_frame *frame;
  242. struct list_head *element;
  243. if (list_empty(&priv->free_frames)) {
  244. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  245. if (!frame) {
  246. IWL_ERR(priv, "Could not allocate frame!\n");
  247. return NULL;
  248. }
  249. priv->frames_count++;
  250. return frame;
  251. }
  252. element = priv->free_frames.next;
  253. list_del(element);
  254. return list_entry(element, struct iwl3945_frame, list);
  255. }
  256. static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
  257. {
  258. memset(frame, 0, sizeof(*frame));
  259. list_add(&frame->list, &priv->free_frames);
  260. }
  261. unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
  262. struct ieee80211_hdr *hdr,
  263. int left)
  264. {
  265. if (!iwl_is_associated(priv, IWL_RXON_CTX_BSS) || !priv->ibss_beacon)
  266. return 0;
  267. if (priv->ibss_beacon->len > left)
  268. return 0;
  269. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  270. return priv->ibss_beacon->len;
  271. }
  272. static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
  273. {
  274. struct iwl3945_frame *frame;
  275. unsigned int frame_size;
  276. int rc;
  277. u8 rate;
  278. frame = iwl3945_get_free_frame(priv);
  279. if (!frame) {
  280. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  281. "command.\n");
  282. return -ENOMEM;
  283. }
  284. rate = iwl_rate_get_lowest_plcp(priv,
  285. &priv->contexts[IWL_RXON_CTX_BSS]);
  286. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  287. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  288. &frame->u.cmd[0]);
  289. iwl3945_free_frame(priv, frame);
  290. return rc;
  291. }
  292. static void iwl3945_unset_hw_params(struct iwl_priv *priv)
  293. {
  294. if (priv->_3945.shared_virt)
  295. dma_free_coherent(&priv->pci_dev->dev,
  296. sizeof(struct iwl3945_shared),
  297. priv->_3945.shared_virt,
  298. priv->_3945.shared_phys);
  299. }
  300. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  301. struct ieee80211_tx_info *info,
  302. struct iwl_device_cmd *cmd,
  303. struct sk_buff *skb_frag,
  304. int sta_id)
  305. {
  306. struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  307. struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
  308. tx_cmd->sec_ctl = 0;
  309. switch (keyinfo->cipher) {
  310. case WLAN_CIPHER_SUITE_CCMP:
  311. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  312. memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen);
  313. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  314. break;
  315. case WLAN_CIPHER_SUITE_TKIP:
  316. break;
  317. case WLAN_CIPHER_SUITE_WEP104:
  318. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  319. /* fall through */
  320. case WLAN_CIPHER_SUITE_WEP40:
  321. tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
  322. (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  323. memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen);
  324. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  325. "with key %d\n", info->control.hw_key->hw_key_idx);
  326. break;
  327. default:
  328. IWL_ERR(priv, "Unknown encode cipher %x\n", keyinfo->cipher);
  329. break;
  330. }
  331. }
  332. /*
  333. * handle build REPLY_TX command notification.
  334. */
  335. static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
  336. struct iwl_device_cmd *cmd,
  337. struct ieee80211_tx_info *info,
  338. struct ieee80211_hdr *hdr, u8 std_id)
  339. {
  340. struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  341. __le32 tx_flags = tx_cmd->tx_flags;
  342. __le16 fc = hdr->frame_control;
  343. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  344. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  345. tx_flags |= TX_CMD_FLG_ACK_MSK;
  346. if (ieee80211_is_mgmt(fc))
  347. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  348. if (ieee80211_is_probe_resp(fc) &&
  349. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  350. tx_flags |= TX_CMD_FLG_TSF_MSK;
  351. } else {
  352. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  353. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  354. }
  355. tx_cmd->sta_id = std_id;
  356. if (ieee80211_has_morefrags(fc))
  357. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  358. if (ieee80211_is_data_qos(fc)) {
  359. u8 *qc = ieee80211_get_qos_ctl(hdr);
  360. tx_cmd->tid_tspec = qc[0] & 0xf;
  361. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  362. } else {
  363. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  364. }
  365. priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
  366. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  367. if (ieee80211_is_mgmt(fc)) {
  368. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  369. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  370. else
  371. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  372. } else {
  373. tx_cmd->timeout.pm_frame_timeout = 0;
  374. }
  375. tx_cmd->driver_txop = 0;
  376. tx_cmd->tx_flags = tx_flags;
  377. tx_cmd->next_frame_len = 0;
  378. }
  379. /*
  380. * start REPLY_TX command process
  381. */
  382. static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  383. {
  384. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  385. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  386. struct iwl3945_tx_cmd *tx_cmd;
  387. struct iwl_tx_queue *txq = NULL;
  388. struct iwl_queue *q = NULL;
  389. struct iwl_device_cmd *out_cmd;
  390. struct iwl_cmd_meta *out_meta;
  391. dma_addr_t phys_addr;
  392. dma_addr_t txcmd_phys;
  393. int txq_id = skb_get_queue_mapping(skb);
  394. u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
  395. u8 id;
  396. u8 unicast;
  397. u8 sta_id;
  398. u8 tid = 0;
  399. __le16 fc;
  400. u8 wait_write_ptr = 0;
  401. unsigned long flags;
  402. spin_lock_irqsave(&priv->lock, flags);
  403. if (iwl_is_rfkill(priv)) {
  404. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  405. goto drop_unlock;
  406. }
  407. if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
  408. IWL_ERR(priv, "ERROR: No TX rate available.\n");
  409. goto drop_unlock;
  410. }
  411. unicast = !is_multicast_ether_addr(hdr->addr1);
  412. id = 0;
  413. fc = hdr->frame_control;
  414. #ifdef CONFIG_IWLWIFI_DEBUG
  415. if (ieee80211_is_auth(fc))
  416. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  417. else if (ieee80211_is_assoc_req(fc))
  418. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  419. else if (ieee80211_is_reassoc_req(fc))
  420. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  421. #endif
  422. spin_unlock_irqrestore(&priv->lock, flags);
  423. hdr_len = ieee80211_hdrlen(fc);
  424. /* Find index into station table for destination station */
  425. sta_id = iwl_sta_id_or_broadcast(
  426. priv, &priv->contexts[IWL_RXON_CTX_BSS],
  427. info->control.sta);
  428. if (sta_id == IWL_INVALID_STATION) {
  429. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  430. hdr->addr1);
  431. goto drop;
  432. }
  433. IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
  434. if (ieee80211_is_data_qos(fc)) {
  435. u8 *qc = ieee80211_get_qos_ctl(hdr);
  436. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  437. if (unlikely(tid >= MAX_TID_COUNT))
  438. goto drop;
  439. }
  440. /* Descriptor for chosen Tx queue */
  441. txq = &priv->txq[txq_id];
  442. q = &txq->q;
  443. if ((iwl_queue_space(q) < q->high_mark))
  444. goto drop;
  445. spin_lock_irqsave(&priv->lock, flags);
  446. idx = get_cmd_index(q, q->write_ptr, 0);
  447. /* Set up driver data for this TFD */
  448. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  449. txq->txb[q->write_ptr].skb = skb;
  450. txq->txb[q->write_ptr].ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  451. /* Init first empty entry in queue's array of Tx/cmd buffers */
  452. out_cmd = txq->cmd[idx];
  453. out_meta = &txq->meta[idx];
  454. tx_cmd = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
  455. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  456. memset(tx_cmd, 0, sizeof(*tx_cmd));
  457. /*
  458. * Set up the Tx-command (not MAC!) header.
  459. * Store the chosen Tx queue and TFD index within the sequence field;
  460. * after Tx, uCode's Tx response will return this value so driver can
  461. * locate the frame within the tx queue and do post-tx processing.
  462. */
  463. out_cmd->hdr.cmd = REPLY_TX;
  464. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  465. INDEX_TO_SEQ(q->write_ptr)));
  466. /* Copy MAC header from skb into command buffer */
  467. memcpy(tx_cmd->hdr, hdr, hdr_len);
  468. if (info->control.hw_key)
  469. iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
  470. /* TODO need this for burst mode later on */
  471. iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
  472. /* set is_hcca to 0; it probably will never be implemented */
  473. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
  474. /* Total # bytes to be transmitted */
  475. len = (u16)skb->len;
  476. tx_cmd->len = cpu_to_le16(len);
  477. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  478. iwl_update_stats(priv, true, fc, len);
  479. tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  480. tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  481. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  482. txq->need_update = 1;
  483. } else {
  484. wait_write_ptr = 1;
  485. txq->need_update = 0;
  486. }
  487. IWL_DEBUG_TX(priv, "sequence nr = 0X%x\n",
  488. le16_to_cpu(out_cmd->hdr.sequence));
  489. IWL_DEBUG_TX(priv, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  490. iwl_print_hex_dump(priv, IWL_DL_TX, tx_cmd, sizeof(*tx_cmd));
  491. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr,
  492. ieee80211_hdrlen(fc));
  493. /*
  494. * Use the first empty entry in this queue's command buffer array
  495. * to contain the Tx command and MAC header concatenated together
  496. * (payload data will be in another buffer).
  497. * Size of this varies, due to varying MAC header length.
  498. * If end is not dword aligned, we'll have 2 extra bytes at the end
  499. * of the MAC header (device reads on dword boundaries).
  500. * We'll tell device about this padding later.
  501. */
  502. len = sizeof(struct iwl3945_tx_cmd) +
  503. sizeof(struct iwl_cmd_header) + hdr_len;
  504. len_org = len;
  505. len = (len + 3) & ~3;
  506. if (len_org != len)
  507. len_org = 1;
  508. else
  509. len_org = 0;
  510. /* Physical address of this Tx command's header (not MAC header!),
  511. * within command buffer array. */
  512. txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
  513. len, PCI_DMA_TODEVICE);
  514. /* we do not map meta data ... so we can safely access address to
  515. * provide to unmap command*/
  516. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  517. dma_unmap_len_set(out_meta, len, len);
  518. /* Add buffer containing Tx command and MAC(!) header to TFD's
  519. * first entry */
  520. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  521. txcmd_phys, len, 1, 0);
  522. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  523. * if any (802.11 null frames have no payload). */
  524. len = skb->len - hdr_len;
  525. if (len) {
  526. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  527. len, PCI_DMA_TODEVICE);
  528. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  529. phys_addr, len,
  530. 0, U32_PAD(len));
  531. }
  532. /* Tell device the write index *just past* this latest filled TFD */
  533. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  534. iwl_txq_update_write_ptr(priv, txq);
  535. spin_unlock_irqrestore(&priv->lock, flags);
  536. if ((iwl_queue_space(q) < q->high_mark)
  537. && priv->mac80211_registered) {
  538. if (wait_write_ptr) {
  539. spin_lock_irqsave(&priv->lock, flags);
  540. txq->need_update = 1;
  541. iwl_txq_update_write_ptr(priv, txq);
  542. spin_unlock_irqrestore(&priv->lock, flags);
  543. }
  544. iwl_stop_queue(priv, skb_get_queue_mapping(skb));
  545. }
  546. return 0;
  547. drop_unlock:
  548. spin_unlock_irqrestore(&priv->lock, flags);
  549. drop:
  550. return -1;
  551. }
  552. static int iwl3945_get_measurement(struct iwl_priv *priv,
  553. struct ieee80211_measurement_params *params,
  554. u8 type)
  555. {
  556. struct iwl_spectrum_cmd spectrum;
  557. struct iwl_rx_packet *pkt;
  558. struct iwl_host_cmd cmd = {
  559. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  560. .data = (void *)&spectrum,
  561. .flags = CMD_WANT_SKB,
  562. };
  563. u32 add_time = le64_to_cpu(params->start_time);
  564. int rc;
  565. int spectrum_resp_status;
  566. int duration = le16_to_cpu(params->duration);
  567. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  568. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
  569. add_time = iwl_usecs_to_beacons(priv,
  570. le64_to_cpu(params->start_time) - priv->_3945.last_tsf,
  571. le16_to_cpu(ctx->timing.beacon_interval));
  572. memset(&spectrum, 0, sizeof(spectrum));
  573. spectrum.channel_count = cpu_to_le16(1);
  574. spectrum.flags =
  575. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  576. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  577. cmd.len = sizeof(spectrum);
  578. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  579. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
  580. spectrum.start_time =
  581. iwl_add_beacon_time(priv,
  582. priv->_3945.last_beacon_time, add_time,
  583. le16_to_cpu(ctx->timing.beacon_interval));
  584. else
  585. spectrum.start_time = 0;
  586. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  587. spectrum.channels[0].channel = params->channel;
  588. spectrum.channels[0].type = type;
  589. if (ctx->active.flags & RXON_FLG_BAND_24G_MSK)
  590. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  591. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  592. rc = iwl_send_cmd_sync(priv, &cmd);
  593. if (rc)
  594. return rc;
  595. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  596. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  597. IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
  598. rc = -EIO;
  599. }
  600. spectrum_resp_status = le16_to_cpu(pkt->u.spectrum.status);
  601. switch (spectrum_resp_status) {
  602. case 0: /* Command will be handled */
  603. if (pkt->u.spectrum.id != 0xff) {
  604. IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
  605. pkt->u.spectrum.id);
  606. priv->measurement_status &= ~MEASUREMENT_READY;
  607. }
  608. priv->measurement_status |= MEASUREMENT_ACTIVE;
  609. rc = 0;
  610. break;
  611. case 1: /* Command will not be handled */
  612. rc = -EAGAIN;
  613. break;
  614. }
  615. iwl_free_pages(priv, cmd.reply_page);
  616. return rc;
  617. }
  618. static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
  619. struct iwl_rx_mem_buffer *rxb)
  620. {
  621. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  622. struct iwl_alive_resp *palive;
  623. struct delayed_work *pwork;
  624. palive = &pkt->u.alive_frame;
  625. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  626. "0x%01X 0x%01X\n",
  627. palive->is_valid, palive->ver_type,
  628. palive->ver_subtype);
  629. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  630. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  631. memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
  632. sizeof(struct iwl_alive_resp));
  633. pwork = &priv->init_alive_start;
  634. } else {
  635. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  636. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  637. sizeof(struct iwl_alive_resp));
  638. pwork = &priv->alive_start;
  639. iwl3945_disable_events(priv);
  640. }
  641. /* We delay the ALIVE response by 5ms to
  642. * give the HW RF Kill time to activate... */
  643. if (palive->is_valid == UCODE_VALID_OK)
  644. queue_delayed_work(priv->workqueue, pwork,
  645. msecs_to_jiffies(5));
  646. else
  647. IWL_WARN(priv, "uCode did not respond OK.\n");
  648. }
  649. static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
  650. struct iwl_rx_mem_buffer *rxb)
  651. {
  652. #ifdef CONFIG_IWLWIFI_DEBUG
  653. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  654. #endif
  655. IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  656. }
  657. static void iwl3945_bg_beacon_update(struct work_struct *work)
  658. {
  659. struct iwl_priv *priv =
  660. container_of(work, struct iwl_priv, beacon_update);
  661. struct sk_buff *beacon;
  662. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  663. beacon = ieee80211_beacon_get(priv->hw,
  664. priv->contexts[IWL_RXON_CTX_BSS].vif);
  665. if (!beacon) {
  666. IWL_ERR(priv, "update beacon failed\n");
  667. return;
  668. }
  669. mutex_lock(&priv->mutex);
  670. /* new beacon skb is allocated every time; dispose previous.*/
  671. if (priv->ibss_beacon)
  672. dev_kfree_skb(priv->ibss_beacon);
  673. priv->ibss_beacon = beacon;
  674. mutex_unlock(&priv->mutex);
  675. iwl3945_send_beacon_cmd(priv);
  676. }
  677. static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
  678. struct iwl_rx_mem_buffer *rxb)
  679. {
  680. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  681. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  682. #ifdef CONFIG_IWLWIFI_DEBUG
  683. u8 rate = beacon->beacon_notify_hdr.rate;
  684. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  685. "tsf %d %d rate %d\n",
  686. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  687. beacon->beacon_notify_hdr.failure_frame,
  688. le32_to_cpu(beacon->ibss_mgr_status),
  689. le32_to_cpu(beacon->high_tsf),
  690. le32_to_cpu(beacon->low_tsf), rate);
  691. #endif
  692. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  693. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  694. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  695. queue_work(priv->workqueue, &priv->beacon_update);
  696. }
  697. /* Handle notification from uCode that card's power state is changing
  698. * due to software, hardware, or critical temperature RFKILL */
  699. static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
  700. struct iwl_rx_mem_buffer *rxb)
  701. {
  702. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  703. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  704. unsigned long status = priv->status;
  705. IWL_WARN(priv, "Card state received: HW:%s SW:%s\n",
  706. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  707. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  708. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  709. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  710. if (flags & HW_CARD_DISABLED)
  711. set_bit(STATUS_RF_KILL_HW, &priv->status);
  712. else
  713. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  714. iwl_scan_cancel(priv);
  715. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  716. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  717. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  718. test_bit(STATUS_RF_KILL_HW, &priv->status));
  719. else
  720. wake_up_interruptible(&priv->wait_command_queue);
  721. }
  722. /**
  723. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  724. *
  725. * Setup the RX handlers for each of the reply types sent from the uCode
  726. * to the host.
  727. *
  728. * This function chains into the hardware specific files for them to setup
  729. * any hardware specific handlers as well.
  730. */
  731. static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
  732. {
  733. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  734. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  735. priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
  736. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  737. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  738. iwl_rx_spectrum_measure_notif;
  739. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  740. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  741. iwl_rx_pm_debug_statistics_notif;
  742. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  743. /*
  744. * The same handler is used for both the REPLY to a discrete
  745. * statistics request from the host as well as for the periodic
  746. * statistics notifications (after received beacons) from the uCode.
  747. */
  748. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_reply_statistics;
  749. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  750. iwl_setup_rx_scan_handlers(priv);
  751. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  752. /* Set up hardware specific Rx handlers */
  753. iwl3945_hw_rx_handler_setup(priv);
  754. }
  755. /************************** RX-FUNCTIONS ****************************/
  756. /*
  757. * Rx theory of operation
  758. *
  759. * The host allocates 32 DMA target addresses and passes the host address
  760. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  761. * 0 to 31
  762. *
  763. * Rx Queue Indexes
  764. * The host/firmware share two index registers for managing the Rx buffers.
  765. *
  766. * The READ index maps to the first position that the firmware may be writing
  767. * to -- the driver can read up to (but not including) this position and get
  768. * good data.
  769. * The READ index is managed by the firmware once the card is enabled.
  770. *
  771. * The WRITE index maps to the last position the driver has read from -- the
  772. * position preceding WRITE is the last slot the firmware can place a packet.
  773. *
  774. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  775. * WRITE = READ.
  776. *
  777. * During initialization, the host sets up the READ queue position to the first
  778. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  779. *
  780. * When the firmware places a packet in a buffer, it will advance the READ index
  781. * and fire the RX interrupt. The driver can then query the READ index and
  782. * process as many packets as possible, moving the WRITE index forward as it
  783. * resets the Rx queue buffers with new memory.
  784. *
  785. * The management in the driver is as follows:
  786. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  787. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  788. * to replenish the iwl->rxq->rx_free.
  789. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  790. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  791. * 'processed' and 'read' driver indexes as well)
  792. * + A received packet is processed and handed to the kernel network stack,
  793. * detached from the iwl->rxq. The driver 'processed' index is updated.
  794. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  795. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  796. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  797. * were enough free buffers and RX_STALLED is set it is cleared.
  798. *
  799. *
  800. * Driver sequence:
  801. *
  802. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  803. * iwl3945_rx_queue_restock
  804. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  805. * queue, updates firmware pointers, and updates
  806. * the WRITE index. If insufficient rx_free buffers
  807. * are available, schedules iwl3945_rx_replenish
  808. *
  809. * -- enable interrupts --
  810. * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
  811. * READ INDEX, detaching the SKB from the pool.
  812. * Moves the packet buffer from queue to rx_used.
  813. * Calls iwl3945_rx_queue_restock to refill any empty
  814. * slots.
  815. * ...
  816. *
  817. */
  818. /**
  819. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  820. */
  821. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
  822. dma_addr_t dma_addr)
  823. {
  824. return cpu_to_le32((u32)dma_addr);
  825. }
  826. /**
  827. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  828. *
  829. * If there are slots in the RX queue that need to be restocked,
  830. * and we have free pre-allocated buffers, fill the ranks as much
  831. * as we can, pulling from rx_free.
  832. *
  833. * This moves the 'write' index forward to catch up with 'processed', and
  834. * also updates the memory address in the firmware to reference the new
  835. * target buffer.
  836. */
  837. static void iwl3945_rx_queue_restock(struct iwl_priv *priv)
  838. {
  839. struct iwl_rx_queue *rxq = &priv->rxq;
  840. struct list_head *element;
  841. struct iwl_rx_mem_buffer *rxb;
  842. unsigned long flags;
  843. int write;
  844. spin_lock_irqsave(&rxq->lock, flags);
  845. write = rxq->write & ~0x7;
  846. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  847. /* Get next free Rx buffer, remove from free list */
  848. element = rxq->rx_free.next;
  849. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  850. list_del(element);
  851. /* Point to Rx buffer via next RBD in circular buffer */
  852. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->page_dma);
  853. rxq->queue[rxq->write] = rxb;
  854. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  855. rxq->free_count--;
  856. }
  857. spin_unlock_irqrestore(&rxq->lock, flags);
  858. /* If the pre-allocated buffer pool is dropping low, schedule to
  859. * refill it */
  860. if (rxq->free_count <= RX_LOW_WATERMARK)
  861. queue_work(priv->workqueue, &priv->rx_replenish);
  862. /* If we've added more space for the firmware to place data, tell it.
  863. * Increment device's write pointer in multiples of 8. */
  864. if ((rxq->write_actual != (rxq->write & ~0x7))
  865. || (abs(rxq->write - rxq->read) > 7)) {
  866. spin_lock_irqsave(&rxq->lock, flags);
  867. rxq->need_update = 1;
  868. spin_unlock_irqrestore(&rxq->lock, flags);
  869. iwl_rx_queue_update_write_ptr(priv, rxq);
  870. }
  871. }
  872. /**
  873. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  874. *
  875. * When moving to rx_free an SKB is allocated for the slot.
  876. *
  877. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  878. * This is called as a scheduled work item (except for during initialization)
  879. */
  880. static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  881. {
  882. struct iwl_rx_queue *rxq = &priv->rxq;
  883. struct list_head *element;
  884. struct iwl_rx_mem_buffer *rxb;
  885. struct page *page;
  886. unsigned long flags;
  887. gfp_t gfp_mask = priority;
  888. while (1) {
  889. spin_lock_irqsave(&rxq->lock, flags);
  890. if (list_empty(&rxq->rx_used)) {
  891. spin_unlock_irqrestore(&rxq->lock, flags);
  892. return;
  893. }
  894. spin_unlock_irqrestore(&rxq->lock, flags);
  895. if (rxq->free_count > RX_LOW_WATERMARK)
  896. gfp_mask |= __GFP_NOWARN;
  897. if (priv->hw_params.rx_page_order > 0)
  898. gfp_mask |= __GFP_COMP;
  899. /* Alloc a new receive buffer */
  900. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  901. if (!page) {
  902. if (net_ratelimit())
  903. IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n");
  904. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  905. net_ratelimit())
  906. IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
  907. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  908. rxq->free_count);
  909. /* We don't reschedule replenish work here -- we will
  910. * call the restock method and if it still needs
  911. * more buffers it will schedule replenish */
  912. break;
  913. }
  914. spin_lock_irqsave(&rxq->lock, flags);
  915. if (list_empty(&rxq->rx_used)) {
  916. spin_unlock_irqrestore(&rxq->lock, flags);
  917. __free_pages(page, priv->hw_params.rx_page_order);
  918. return;
  919. }
  920. element = rxq->rx_used.next;
  921. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  922. list_del(element);
  923. spin_unlock_irqrestore(&rxq->lock, flags);
  924. rxb->page = page;
  925. /* Get physical address of RB/SKB */
  926. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  927. PAGE_SIZE << priv->hw_params.rx_page_order,
  928. PCI_DMA_FROMDEVICE);
  929. spin_lock_irqsave(&rxq->lock, flags);
  930. list_add_tail(&rxb->list, &rxq->rx_free);
  931. rxq->free_count++;
  932. priv->alloc_rxb_page++;
  933. spin_unlock_irqrestore(&rxq->lock, flags);
  934. }
  935. }
  936. void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  937. {
  938. unsigned long flags;
  939. int i;
  940. spin_lock_irqsave(&rxq->lock, flags);
  941. INIT_LIST_HEAD(&rxq->rx_free);
  942. INIT_LIST_HEAD(&rxq->rx_used);
  943. /* Fill the rx_used queue with _all_ of the Rx buffers */
  944. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  945. /* In the reset function, these buffers may have been allocated
  946. * to an SKB, so we need to unmap and free potential storage */
  947. if (rxq->pool[i].page != NULL) {
  948. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  949. PAGE_SIZE << priv->hw_params.rx_page_order,
  950. PCI_DMA_FROMDEVICE);
  951. __iwl_free_pages(priv, rxq->pool[i].page);
  952. rxq->pool[i].page = NULL;
  953. }
  954. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  955. }
  956. /* Set us so that we have processed and used all buffers, but have
  957. * not restocked the Rx queue with fresh buffers */
  958. rxq->read = rxq->write = 0;
  959. rxq->write_actual = 0;
  960. rxq->free_count = 0;
  961. spin_unlock_irqrestore(&rxq->lock, flags);
  962. }
  963. void iwl3945_rx_replenish(void *data)
  964. {
  965. struct iwl_priv *priv = data;
  966. unsigned long flags;
  967. iwl3945_rx_allocate(priv, GFP_KERNEL);
  968. spin_lock_irqsave(&priv->lock, flags);
  969. iwl3945_rx_queue_restock(priv);
  970. spin_unlock_irqrestore(&priv->lock, flags);
  971. }
  972. static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
  973. {
  974. iwl3945_rx_allocate(priv, GFP_ATOMIC);
  975. iwl3945_rx_queue_restock(priv);
  976. }
  977. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  978. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  979. * This free routine walks the list of POOL entries and if SKB is set to
  980. * non NULL it is unmapped and freed
  981. */
  982. static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  983. {
  984. int i;
  985. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  986. if (rxq->pool[i].page != NULL) {
  987. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  988. PAGE_SIZE << priv->hw_params.rx_page_order,
  989. PCI_DMA_FROMDEVICE);
  990. __iwl_free_pages(priv, rxq->pool[i].page);
  991. rxq->pool[i].page = NULL;
  992. }
  993. }
  994. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  995. rxq->bd_dma);
  996. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  997. rxq->rb_stts, rxq->rb_stts_dma);
  998. rxq->bd = NULL;
  999. rxq->rb_stts = NULL;
  1000. }
  1001. /* Convert linear signal-to-noise ratio into dB */
  1002. static u8 ratio2dB[100] = {
  1003. /* 0 1 2 3 4 5 6 7 8 9 */
  1004. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1005. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1006. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1007. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1008. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1009. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1010. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1011. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1012. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1013. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1014. };
  1015. /* Calculates a relative dB value from a ratio of linear
  1016. * (i.e. not dB) signal levels.
  1017. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1018. int iwl3945_calc_db_from_ratio(int sig_ratio)
  1019. {
  1020. /* 1000:1 or higher just report as 60 dB */
  1021. if (sig_ratio >= 1000)
  1022. return 60;
  1023. /* 100:1 or higher, divide by 10 and use table,
  1024. * add 20 dB to make up for divide by 10 */
  1025. if (sig_ratio >= 100)
  1026. return 20 + (int)ratio2dB[sig_ratio/10];
  1027. /* We shouldn't see this */
  1028. if (sig_ratio < 1)
  1029. return 0;
  1030. /* Use table for ratios 1:1 - 99:1 */
  1031. return (int)ratio2dB[sig_ratio];
  1032. }
  1033. /**
  1034. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  1035. *
  1036. * Uses the priv->rx_handlers callback function array to invoke
  1037. * the appropriate handlers, including command responses,
  1038. * frame-received notifications, and other notifications.
  1039. */
  1040. static void iwl3945_rx_handle(struct iwl_priv *priv)
  1041. {
  1042. struct iwl_rx_mem_buffer *rxb;
  1043. struct iwl_rx_packet *pkt;
  1044. struct iwl_rx_queue *rxq = &priv->rxq;
  1045. u32 r, i;
  1046. int reclaim;
  1047. unsigned long flags;
  1048. u8 fill_rx = 0;
  1049. u32 count = 8;
  1050. int total_empty = 0;
  1051. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1052. * buffer that the driver may process (last buffer filled by ucode). */
  1053. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  1054. i = rxq->read;
  1055. /* calculate total frames need to be restock after handling RX */
  1056. total_empty = r - rxq->write_actual;
  1057. if (total_empty < 0)
  1058. total_empty += RX_QUEUE_SIZE;
  1059. if (total_empty > (RX_QUEUE_SIZE / 2))
  1060. fill_rx = 1;
  1061. /* Rx interrupt, but nothing sent from uCode */
  1062. if (i == r)
  1063. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  1064. while (i != r) {
  1065. int len;
  1066. rxb = rxq->queue[i];
  1067. /* If an RXB doesn't have a Rx queue slot associated with it,
  1068. * then a bug has been introduced in the queue refilling
  1069. * routines -- catch it here */
  1070. BUG_ON(rxb == NULL);
  1071. rxq->queue[i] = NULL;
  1072. pci_unmap_page(priv->pci_dev, rxb->page_dma,
  1073. PAGE_SIZE << priv->hw_params.rx_page_order,
  1074. PCI_DMA_FROMDEVICE);
  1075. pkt = rxb_addr(rxb);
  1076. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1077. len += sizeof(u32); /* account for status word */
  1078. trace_iwlwifi_dev_rx(priv, pkt, len);
  1079. /* Reclaim a command buffer only if this packet is a response
  1080. * to a (driver-originated) command.
  1081. * If the packet (e.g. Rx frame) originated from uCode,
  1082. * there is no command buffer to reclaim.
  1083. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1084. * but apparently a few don't get set; catch them here. */
  1085. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1086. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1087. (pkt->hdr.cmd != REPLY_TX);
  1088. /* Based on type of command response or notification,
  1089. * handle those that need handling via function in
  1090. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  1091. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1092. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i,
  1093. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1094. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  1095. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1096. } else {
  1097. /* No handling needed */
  1098. IWL_DEBUG_RX(priv,
  1099. "r %d i %d No handler needed for %s, 0x%02x\n",
  1100. r, i, get_cmd_string(pkt->hdr.cmd),
  1101. pkt->hdr.cmd);
  1102. }
  1103. /*
  1104. * XXX: After here, we should always check rxb->page
  1105. * against NULL before touching it or its virtual
  1106. * memory (pkt). Because some rx_handler might have
  1107. * already taken or freed the pages.
  1108. */
  1109. if (reclaim) {
  1110. /* Invoke any callbacks, transfer the buffer to caller,
  1111. * and fire off the (possibly) blocking iwl_send_cmd()
  1112. * as we reclaim the driver command queue */
  1113. if (rxb->page)
  1114. iwl_tx_cmd_complete(priv, rxb);
  1115. else
  1116. IWL_WARN(priv, "Claim null rxb?\n");
  1117. }
  1118. /* Reuse the page if possible. For notification packets and
  1119. * SKBs that fail to Rx correctly, add them back into the
  1120. * rx_free list for reuse later. */
  1121. spin_lock_irqsave(&rxq->lock, flags);
  1122. if (rxb->page != NULL) {
  1123. rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
  1124. 0, PAGE_SIZE << priv->hw_params.rx_page_order,
  1125. PCI_DMA_FROMDEVICE);
  1126. list_add_tail(&rxb->list, &rxq->rx_free);
  1127. rxq->free_count++;
  1128. } else
  1129. list_add_tail(&rxb->list, &rxq->rx_used);
  1130. spin_unlock_irqrestore(&rxq->lock, flags);
  1131. i = (i + 1) & RX_QUEUE_MASK;
  1132. /* If there are a lot of unused frames,
  1133. * restock the Rx queue so ucode won't assert. */
  1134. if (fill_rx) {
  1135. count++;
  1136. if (count >= 8) {
  1137. rxq->read = i;
  1138. iwl3945_rx_replenish_now(priv);
  1139. count = 0;
  1140. }
  1141. }
  1142. }
  1143. /* Backtrack one entry */
  1144. rxq->read = i;
  1145. if (fill_rx)
  1146. iwl3945_rx_replenish_now(priv);
  1147. else
  1148. iwl3945_rx_queue_restock(priv);
  1149. }
  1150. /* call this function to flush any scheduled tasklet */
  1151. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1152. {
  1153. /* wait to make sure we flush pending tasklet*/
  1154. synchronize_irq(priv->pci_dev->irq);
  1155. tasklet_kill(&priv->irq_tasklet);
  1156. }
  1157. static const char *desc_lookup(int i)
  1158. {
  1159. switch (i) {
  1160. case 1:
  1161. return "FAIL";
  1162. case 2:
  1163. return "BAD_PARAM";
  1164. case 3:
  1165. return "BAD_CHECKSUM";
  1166. case 4:
  1167. return "NMI_INTERRUPT";
  1168. case 5:
  1169. return "SYSASSERT";
  1170. case 6:
  1171. return "FATAL_ERROR";
  1172. }
  1173. return "UNKNOWN";
  1174. }
  1175. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1176. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1177. void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
  1178. {
  1179. u32 i;
  1180. u32 desc, time, count, base, data1;
  1181. u32 blink1, blink2, ilink1, ilink2;
  1182. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1183. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1184. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1185. return;
  1186. }
  1187. count = iwl_read_targ_mem(priv, base);
  1188. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1189. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1190. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1191. priv->status, count);
  1192. }
  1193. IWL_ERR(priv, "Desc Time asrtPC blink2 "
  1194. "ilink1 nmiPC Line\n");
  1195. for (i = ERROR_START_OFFSET;
  1196. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  1197. i += ERROR_ELEM_SIZE) {
  1198. desc = iwl_read_targ_mem(priv, base + i);
  1199. time =
  1200. iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  1201. blink1 =
  1202. iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  1203. blink2 =
  1204. iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  1205. ilink1 =
  1206. iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  1207. ilink2 =
  1208. iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  1209. data1 =
  1210. iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  1211. IWL_ERR(priv,
  1212. "%-13s (0x%X) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  1213. desc_lookup(desc), desc, time, blink1, blink2,
  1214. ilink1, ilink2, data1);
  1215. trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0,
  1216. 0, blink1, blink2, ilink1, ilink2);
  1217. }
  1218. }
  1219. #define EVENT_START_OFFSET (6 * sizeof(u32))
  1220. /**
  1221. * iwl3945_print_event_log - Dump error event log to syslog
  1222. *
  1223. */
  1224. static int iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1225. u32 num_events, u32 mode,
  1226. int pos, char **buf, size_t bufsz)
  1227. {
  1228. u32 i;
  1229. u32 base; /* SRAM byte address of event log header */
  1230. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1231. u32 ptr; /* SRAM byte address of log data */
  1232. u32 ev, time, data; /* event log data */
  1233. unsigned long reg_flags;
  1234. if (num_events == 0)
  1235. return pos;
  1236. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1237. if (mode == 0)
  1238. event_size = 2 * sizeof(u32);
  1239. else
  1240. event_size = 3 * sizeof(u32);
  1241. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1242. /* Make sure device is powered up for SRAM reads */
  1243. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1244. iwl_grab_nic_access(priv);
  1245. /* Set starting address; reads will auto-increment */
  1246. _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1247. rmb();
  1248. /* "time" is actually "data" for mode 0 (no timestamp).
  1249. * place event id # at far right for easier visual parsing. */
  1250. for (i = 0; i < num_events; i++) {
  1251. ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1252. time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1253. if (mode == 0) {
  1254. /* data, ev */
  1255. if (bufsz) {
  1256. pos += scnprintf(*buf + pos, bufsz - pos,
  1257. "0x%08x:%04u\n",
  1258. time, ev);
  1259. } else {
  1260. IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
  1261. trace_iwlwifi_dev_ucode_event(priv, 0,
  1262. time, ev);
  1263. }
  1264. } else {
  1265. data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1266. if (bufsz) {
  1267. pos += scnprintf(*buf + pos, bufsz - pos,
  1268. "%010u:0x%08x:%04u\n",
  1269. time, data, ev);
  1270. } else {
  1271. IWL_ERR(priv, "%010u\t0x%08x\t%04u\n",
  1272. time, data, ev);
  1273. trace_iwlwifi_dev_ucode_event(priv, time,
  1274. data, ev);
  1275. }
  1276. }
  1277. }
  1278. /* Allow device to power down */
  1279. iwl_release_nic_access(priv);
  1280. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1281. return pos;
  1282. }
  1283. /**
  1284. * iwl3945_print_last_event_logs - Dump the newest # of event log to syslog
  1285. */
  1286. static int iwl3945_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1287. u32 num_wraps, u32 next_entry,
  1288. u32 size, u32 mode,
  1289. int pos, char **buf, size_t bufsz)
  1290. {
  1291. /*
  1292. * display the newest DEFAULT_LOG_ENTRIES entries
  1293. * i.e the entries just before the next ont that uCode would fill.
  1294. */
  1295. if (num_wraps) {
  1296. if (next_entry < size) {
  1297. pos = iwl3945_print_event_log(priv,
  1298. capacity - (size - next_entry),
  1299. size - next_entry, mode,
  1300. pos, buf, bufsz);
  1301. pos = iwl3945_print_event_log(priv, 0,
  1302. next_entry, mode,
  1303. pos, buf, bufsz);
  1304. } else
  1305. pos = iwl3945_print_event_log(priv, next_entry - size,
  1306. size, mode,
  1307. pos, buf, bufsz);
  1308. } else {
  1309. if (next_entry < size)
  1310. pos = iwl3945_print_event_log(priv, 0,
  1311. next_entry, mode,
  1312. pos, buf, bufsz);
  1313. else
  1314. pos = iwl3945_print_event_log(priv, next_entry - size,
  1315. size, mode,
  1316. pos, buf, bufsz);
  1317. }
  1318. return pos;
  1319. }
  1320. #define DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES (20)
  1321. int iwl3945_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1322. char **buf, bool display)
  1323. {
  1324. u32 base; /* SRAM byte address of event log header */
  1325. u32 capacity; /* event log capacity in # entries */
  1326. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1327. u32 num_wraps; /* # times uCode wrapped to top of log */
  1328. u32 next_entry; /* index of next entry to be written by uCode */
  1329. u32 size; /* # entries that we'll print */
  1330. int pos = 0;
  1331. size_t bufsz = 0;
  1332. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1333. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1334. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1335. return -EINVAL;
  1336. }
  1337. /* event log header */
  1338. capacity = iwl_read_targ_mem(priv, base);
  1339. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1340. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1341. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1342. if (capacity > priv->cfg->max_event_log_size) {
  1343. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  1344. capacity, priv->cfg->max_event_log_size);
  1345. capacity = priv->cfg->max_event_log_size;
  1346. }
  1347. if (next_entry > priv->cfg->max_event_log_size) {
  1348. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1349. next_entry, priv->cfg->max_event_log_size);
  1350. next_entry = priv->cfg->max_event_log_size;
  1351. }
  1352. size = num_wraps ? capacity : next_entry;
  1353. /* bail out if nothing in log */
  1354. if (size == 0) {
  1355. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1356. return pos;
  1357. }
  1358. #ifdef CONFIG_IWLWIFI_DEBUG
  1359. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1360. size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
  1361. ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
  1362. #else
  1363. size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
  1364. ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
  1365. #endif
  1366. IWL_ERR(priv, "Start IWL Event Log Dump: display last %d count\n",
  1367. size);
  1368. #ifdef CONFIG_IWLWIFI_DEBUG
  1369. if (display) {
  1370. if (full_log)
  1371. bufsz = capacity * 48;
  1372. else
  1373. bufsz = size * 48;
  1374. *buf = kmalloc(bufsz, GFP_KERNEL);
  1375. if (!*buf)
  1376. return -ENOMEM;
  1377. }
  1378. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1379. /* if uCode has wrapped back to top of log,
  1380. * start at the oldest entry,
  1381. * i.e the next one that uCode would fill.
  1382. */
  1383. if (num_wraps)
  1384. pos = iwl3945_print_event_log(priv, next_entry,
  1385. capacity - next_entry, mode,
  1386. pos, buf, bufsz);
  1387. /* (then/else) start at top of log */
  1388. pos = iwl3945_print_event_log(priv, 0, next_entry, mode,
  1389. pos, buf, bufsz);
  1390. } else
  1391. pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
  1392. next_entry, size, mode,
  1393. pos, buf, bufsz);
  1394. #else
  1395. pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
  1396. next_entry, size, mode,
  1397. pos, buf, bufsz);
  1398. #endif
  1399. return pos;
  1400. }
  1401. static void iwl3945_irq_tasklet(struct iwl_priv *priv)
  1402. {
  1403. u32 inta, handled = 0;
  1404. u32 inta_fh;
  1405. unsigned long flags;
  1406. #ifdef CONFIG_IWLWIFI_DEBUG
  1407. u32 inta_mask;
  1408. #endif
  1409. spin_lock_irqsave(&priv->lock, flags);
  1410. /* Ack/clear/reset pending uCode interrupts.
  1411. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1412. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1413. inta = iwl_read32(priv, CSR_INT);
  1414. iwl_write32(priv, CSR_INT, inta);
  1415. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1416. * Any new interrupts that happen after this, either while we're
  1417. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1418. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1419. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1420. #ifdef CONFIG_IWLWIFI_DEBUG
  1421. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  1422. /* just for debug */
  1423. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1424. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1425. inta, inta_mask, inta_fh);
  1426. }
  1427. #endif
  1428. spin_unlock_irqrestore(&priv->lock, flags);
  1429. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1430. * atomic, make sure that inta covers all the interrupts that
  1431. * we've discovered, even if FH interrupt came in just after
  1432. * reading CSR_INT. */
  1433. if (inta_fh & CSR39_FH_INT_RX_MASK)
  1434. inta |= CSR_INT_BIT_FH_RX;
  1435. if (inta_fh & CSR39_FH_INT_TX_MASK)
  1436. inta |= CSR_INT_BIT_FH_TX;
  1437. /* Now service all interrupt bits discovered above. */
  1438. if (inta & CSR_INT_BIT_HW_ERR) {
  1439. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  1440. /* Tell the device to stop sending interrupts */
  1441. iwl_disable_interrupts(priv);
  1442. priv->isr_stats.hw++;
  1443. iwl_irq_handle_error(priv);
  1444. handled |= CSR_INT_BIT_HW_ERR;
  1445. return;
  1446. }
  1447. #ifdef CONFIG_IWLWIFI_DEBUG
  1448. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1449. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1450. if (inta & CSR_INT_BIT_SCD) {
  1451. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  1452. "the frame/frames.\n");
  1453. priv->isr_stats.sch++;
  1454. }
  1455. /* Alive notification via Rx interrupt will do the real work */
  1456. if (inta & CSR_INT_BIT_ALIVE) {
  1457. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  1458. priv->isr_stats.alive++;
  1459. }
  1460. }
  1461. #endif
  1462. /* Safely ignore these bits for debug checks below */
  1463. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1464. /* Error detected by uCode */
  1465. if (inta & CSR_INT_BIT_SW_ERR) {
  1466. IWL_ERR(priv, "Microcode SW error detected. "
  1467. "Restarting 0x%X.\n", inta);
  1468. priv->isr_stats.sw++;
  1469. priv->isr_stats.sw_err = inta;
  1470. iwl_irq_handle_error(priv);
  1471. handled |= CSR_INT_BIT_SW_ERR;
  1472. }
  1473. /* uCode wakes up after power-down sleep */
  1474. if (inta & CSR_INT_BIT_WAKEUP) {
  1475. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1476. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1477. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1478. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1479. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1480. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1481. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1482. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1483. priv->isr_stats.wakeup++;
  1484. handled |= CSR_INT_BIT_WAKEUP;
  1485. }
  1486. /* All uCode command responses, including Tx command responses,
  1487. * Rx "responses" (frame-received notification), and other
  1488. * notifications from uCode come through here*/
  1489. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1490. iwl3945_rx_handle(priv);
  1491. priv->isr_stats.rx++;
  1492. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1493. }
  1494. if (inta & CSR_INT_BIT_FH_TX) {
  1495. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  1496. priv->isr_stats.tx++;
  1497. iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  1498. iwl_write_direct32(priv, FH39_TCSR_CREDIT
  1499. (FH39_SRVC_CHNL), 0x0);
  1500. handled |= CSR_INT_BIT_FH_TX;
  1501. }
  1502. if (inta & ~handled) {
  1503. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1504. priv->isr_stats.unhandled++;
  1505. }
  1506. if (inta & ~priv->inta_mask) {
  1507. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1508. inta & ~priv->inta_mask);
  1509. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  1510. }
  1511. /* Re-enable all interrupts */
  1512. /* only Re-enable if disabled by irq */
  1513. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1514. iwl_enable_interrupts(priv);
  1515. #ifdef CONFIG_IWLWIFI_DEBUG
  1516. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1517. inta = iwl_read32(priv, CSR_INT);
  1518. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1519. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1520. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  1521. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  1522. }
  1523. #endif
  1524. }
  1525. static int iwl3945_get_single_channel_for_scan(struct iwl_priv *priv,
  1526. struct ieee80211_vif *vif,
  1527. enum ieee80211_band band,
  1528. struct iwl3945_scan_channel *scan_ch)
  1529. {
  1530. const struct ieee80211_supported_band *sband;
  1531. u16 passive_dwell = 0;
  1532. u16 active_dwell = 0;
  1533. int added = 0;
  1534. u8 channel = 0;
  1535. sband = iwl_get_hw_mode(priv, band);
  1536. if (!sband) {
  1537. IWL_ERR(priv, "invalid band\n");
  1538. return added;
  1539. }
  1540. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  1541. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1542. if (passive_dwell <= active_dwell)
  1543. passive_dwell = active_dwell + 1;
  1544. channel = iwl_get_single_channel_number(priv, band);
  1545. if (channel) {
  1546. scan_ch->channel = channel;
  1547. scan_ch->type = 0; /* passive */
  1548. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1549. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1550. /* Set txpower levels to defaults */
  1551. scan_ch->tpc.dsp_atten = 110;
  1552. if (band == IEEE80211_BAND_5GHZ)
  1553. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1554. else
  1555. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  1556. added++;
  1557. } else
  1558. IWL_ERR(priv, "no valid channel found\n");
  1559. return added;
  1560. }
  1561. static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
  1562. enum ieee80211_band band,
  1563. u8 is_active, u8 n_probes,
  1564. struct iwl3945_scan_channel *scan_ch,
  1565. struct ieee80211_vif *vif)
  1566. {
  1567. struct ieee80211_channel *chan;
  1568. const struct ieee80211_supported_band *sband;
  1569. const struct iwl_channel_info *ch_info;
  1570. u16 passive_dwell = 0;
  1571. u16 active_dwell = 0;
  1572. int added, i;
  1573. sband = iwl_get_hw_mode(priv, band);
  1574. if (!sband)
  1575. return 0;
  1576. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  1577. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1578. if (passive_dwell <= active_dwell)
  1579. passive_dwell = active_dwell + 1;
  1580. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  1581. chan = priv->scan_request->channels[i];
  1582. if (chan->band != band)
  1583. continue;
  1584. scan_ch->channel = chan->hw_value;
  1585. ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
  1586. if (!is_channel_valid(ch_info)) {
  1587. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  1588. scan_ch->channel);
  1589. continue;
  1590. }
  1591. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1592. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1593. /* If passive , set up for auto-switch
  1594. * and use long active_dwell time.
  1595. */
  1596. if (!is_active || is_channel_passive(ch_info) ||
  1597. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
  1598. scan_ch->type = 0; /* passive */
  1599. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1600. scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
  1601. } else {
  1602. scan_ch->type = 1; /* active */
  1603. }
  1604. /* Set direct probe bits. These may be used both for active
  1605. * scan channels (probes gets sent right away),
  1606. * or for passive channels (probes get se sent only after
  1607. * hearing clear Rx packet).*/
  1608. if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
  1609. if (n_probes)
  1610. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  1611. } else {
  1612. /* uCode v1 does not allow setting direct probe bits on
  1613. * passive channel. */
  1614. if ((scan_ch->type & 1) && n_probes)
  1615. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  1616. }
  1617. /* Set txpower levels to defaults */
  1618. scan_ch->tpc.dsp_atten = 110;
  1619. /* scan_pwr_info->tpc.dsp_atten; */
  1620. /*scan_pwr_info->tpc.tx_gain; */
  1621. if (band == IEEE80211_BAND_5GHZ)
  1622. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1623. else {
  1624. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  1625. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  1626. * power level:
  1627. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  1628. */
  1629. }
  1630. IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
  1631. scan_ch->channel,
  1632. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  1633. (scan_ch->type & 1) ?
  1634. active_dwell : passive_dwell);
  1635. scan_ch++;
  1636. added++;
  1637. }
  1638. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  1639. return added;
  1640. }
  1641. static void iwl3945_init_hw_rates(struct iwl_priv *priv,
  1642. struct ieee80211_rate *rates)
  1643. {
  1644. int i;
  1645. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  1646. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  1647. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  1648. rates[i].hw_value_short = i;
  1649. rates[i].flags = 0;
  1650. if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  1651. /*
  1652. * If CCK != 1M then set short preamble rate flag.
  1653. */
  1654. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  1655. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  1656. }
  1657. }
  1658. }
  1659. /******************************************************************************
  1660. *
  1661. * uCode download functions
  1662. *
  1663. ******************************************************************************/
  1664. static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
  1665. {
  1666. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1667. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1668. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1669. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1670. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1671. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1672. }
  1673. /**
  1674. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  1675. * looking at all data.
  1676. */
  1677. static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
  1678. {
  1679. u32 val;
  1680. u32 save_len = len;
  1681. int rc = 0;
  1682. u32 errcnt;
  1683. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1684. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1685. IWL39_RTC_INST_LOWER_BOUND);
  1686. errcnt = 0;
  1687. for (; len > 0; len -= sizeof(u32), image++) {
  1688. /* read data comes through single port, auto-incr addr */
  1689. /* NOTE: Use the debugless read so we don't flood kernel log
  1690. * if IWL_DL_IO is set */
  1691. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1692. if (val != le32_to_cpu(*image)) {
  1693. IWL_ERR(priv, "uCode INST section is invalid at "
  1694. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1695. save_len - len, val, le32_to_cpu(*image));
  1696. rc = -EIO;
  1697. errcnt++;
  1698. if (errcnt >= 20)
  1699. break;
  1700. }
  1701. }
  1702. if (!errcnt)
  1703. IWL_DEBUG_INFO(priv,
  1704. "ucode image in INSTRUCTION memory is good\n");
  1705. return rc;
  1706. }
  1707. /**
  1708. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  1709. * using sample data 100 bytes apart. If these sample points are good,
  1710. * it's a pretty good bet that everything between them is good, too.
  1711. */
  1712. static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  1713. {
  1714. u32 val;
  1715. int rc = 0;
  1716. u32 errcnt = 0;
  1717. u32 i;
  1718. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1719. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  1720. /* read data comes through single port, auto-incr addr */
  1721. /* NOTE: Use the debugless read so we don't flood kernel log
  1722. * if IWL_DL_IO is set */
  1723. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1724. i + IWL39_RTC_INST_LOWER_BOUND);
  1725. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1726. if (val != le32_to_cpu(*image)) {
  1727. #if 0 /* Enable this if you want to see details */
  1728. IWL_ERR(priv, "uCode INST section is invalid at "
  1729. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1730. i, val, *image);
  1731. #endif
  1732. rc = -EIO;
  1733. errcnt++;
  1734. if (errcnt >= 3)
  1735. break;
  1736. }
  1737. }
  1738. return rc;
  1739. }
  1740. /**
  1741. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  1742. * and verify its contents
  1743. */
  1744. static int iwl3945_verify_ucode(struct iwl_priv *priv)
  1745. {
  1746. __le32 *image;
  1747. u32 len;
  1748. int rc = 0;
  1749. /* Try bootstrap */
  1750. image = (__le32 *)priv->ucode_boot.v_addr;
  1751. len = priv->ucode_boot.len;
  1752. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1753. if (rc == 0) {
  1754. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  1755. return 0;
  1756. }
  1757. /* Try initialize */
  1758. image = (__le32 *)priv->ucode_init.v_addr;
  1759. len = priv->ucode_init.len;
  1760. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1761. if (rc == 0) {
  1762. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  1763. return 0;
  1764. }
  1765. /* Try runtime/protocol */
  1766. image = (__le32 *)priv->ucode_code.v_addr;
  1767. len = priv->ucode_code.len;
  1768. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1769. if (rc == 0) {
  1770. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  1771. return 0;
  1772. }
  1773. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  1774. /* Since nothing seems to match, show first several data entries in
  1775. * instruction SRAM, so maybe visual inspection will give a clue.
  1776. * Selection of bootstrap image (vs. other images) is arbitrary. */
  1777. image = (__le32 *)priv->ucode_boot.v_addr;
  1778. len = priv->ucode_boot.len;
  1779. rc = iwl3945_verify_inst_full(priv, image, len);
  1780. return rc;
  1781. }
  1782. static void iwl3945_nic_start(struct iwl_priv *priv)
  1783. {
  1784. /* Remove all resets to allow NIC to operate */
  1785. iwl_write32(priv, CSR_RESET, 0);
  1786. }
  1787. #define IWL3945_UCODE_GET(item) \
  1788. static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode)\
  1789. { \
  1790. return le32_to_cpu(ucode->u.v1.item); \
  1791. }
  1792. static u32 iwl3945_ucode_get_header_size(u32 api_ver)
  1793. {
  1794. return 24;
  1795. }
  1796. static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode)
  1797. {
  1798. return (u8 *) ucode->u.v1.data;
  1799. }
  1800. IWL3945_UCODE_GET(inst_size);
  1801. IWL3945_UCODE_GET(data_size);
  1802. IWL3945_UCODE_GET(init_size);
  1803. IWL3945_UCODE_GET(init_data_size);
  1804. IWL3945_UCODE_GET(boot_size);
  1805. /**
  1806. * iwl3945_read_ucode - Read uCode images from disk file.
  1807. *
  1808. * Copy into buffers for card to fetch via bus-mastering
  1809. */
  1810. static int iwl3945_read_ucode(struct iwl_priv *priv)
  1811. {
  1812. const struct iwl_ucode_header *ucode;
  1813. int ret = -EINVAL, index;
  1814. const struct firmware *ucode_raw;
  1815. /* firmware file name contains uCode/driver compatibility version */
  1816. const char *name_pre = priv->cfg->fw_name_pre;
  1817. const unsigned int api_max = priv->cfg->ucode_api_max;
  1818. const unsigned int api_min = priv->cfg->ucode_api_min;
  1819. char buf[25];
  1820. u8 *src;
  1821. size_t len;
  1822. u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
  1823. /* Ask kernel firmware_class module to get the boot firmware off disk.
  1824. * request_firmware() is synchronous, file is in memory on return. */
  1825. for (index = api_max; index >= api_min; index--) {
  1826. sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
  1827. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  1828. if (ret < 0) {
  1829. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  1830. buf, ret);
  1831. if (ret == -ENOENT)
  1832. continue;
  1833. else
  1834. goto error;
  1835. } else {
  1836. if (index < api_max)
  1837. IWL_ERR(priv, "Loaded firmware %s, "
  1838. "which is deprecated. "
  1839. " Please use API v%u instead.\n",
  1840. buf, api_max);
  1841. IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
  1842. "(%zd bytes) from disk\n",
  1843. buf, ucode_raw->size);
  1844. break;
  1845. }
  1846. }
  1847. if (ret < 0)
  1848. goto error;
  1849. /* Make sure that we got at least our header! */
  1850. if (ucode_raw->size < iwl3945_ucode_get_header_size(1)) {
  1851. IWL_ERR(priv, "File size way too small!\n");
  1852. ret = -EINVAL;
  1853. goto err_release;
  1854. }
  1855. /* Data from ucode file: header followed by uCode images */
  1856. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1857. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1858. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1859. inst_size = iwl3945_ucode_get_inst_size(ucode);
  1860. data_size = iwl3945_ucode_get_data_size(ucode);
  1861. init_size = iwl3945_ucode_get_init_size(ucode);
  1862. init_data_size = iwl3945_ucode_get_init_data_size(ucode);
  1863. boot_size = iwl3945_ucode_get_boot_size(ucode);
  1864. src = iwl3945_ucode_get_data(ucode);
  1865. /* api_ver should match the api version forming part of the
  1866. * firmware filename ... but we don't check for that and only rely
  1867. * on the API version read from firmware header from here on forward */
  1868. if (api_ver < api_min || api_ver > api_max) {
  1869. IWL_ERR(priv, "Driver unable to support your firmware API. "
  1870. "Driver supports v%u, firmware is v%u.\n",
  1871. api_max, api_ver);
  1872. priv->ucode_ver = 0;
  1873. ret = -EINVAL;
  1874. goto err_release;
  1875. }
  1876. if (api_ver != api_max)
  1877. IWL_ERR(priv, "Firmware has old API version. Expected %u, "
  1878. "got %u. New firmware can be obtained "
  1879. "from http://www.intellinuxwireless.org.\n",
  1880. api_max, api_ver);
  1881. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  1882. IWL_UCODE_MAJOR(priv->ucode_ver),
  1883. IWL_UCODE_MINOR(priv->ucode_ver),
  1884. IWL_UCODE_API(priv->ucode_ver),
  1885. IWL_UCODE_SERIAL(priv->ucode_ver));
  1886. snprintf(priv->hw->wiphy->fw_version,
  1887. sizeof(priv->hw->wiphy->fw_version),
  1888. "%u.%u.%u.%u",
  1889. IWL_UCODE_MAJOR(priv->ucode_ver),
  1890. IWL_UCODE_MINOR(priv->ucode_ver),
  1891. IWL_UCODE_API(priv->ucode_ver),
  1892. IWL_UCODE_SERIAL(priv->ucode_ver));
  1893. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1894. priv->ucode_ver);
  1895. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
  1896. inst_size);
  1897. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
  1898. data_size);
  1899. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
  1900. init_size);
  1901. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
  1902. init_data_size);
  1903. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
  1904. boot_size);
  1905. /* Verify size of file vs. image size info in file's header */
  1906. if (ucode_raw->size != iwl3945_ucode_get_header_size(api_ver) +
  1907. inst_size + data_size + init_size +
  1908. init_data_size + boot_size) {
  1909. IWL_DEBUG_INFO(priv,
  1910. "uCode file size %zd does not match expected size\n",
  1911. ucode_raw->size);
  1912. ret = -EINVAL;
  1913. goto err_release;
  1914. }
  1915. /* Verify that uCode images will fit in card's SRAM */
  1916. if (inst_size > IWL39_MAX_INST_SIZE) {
  1917. IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
  1918. inst_size);
  1919. ret = -EINVAL;
  1920. goto err_release;
  1921. }
  1922. if (data_size > IWL39_MAX_DATA_SIZE) {
  1923. IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
  1924. data_size);
  1925. ret = -EINVAL;
  1926. goto err_release;
  1927. }
  1928. if (init_size > IWL39_MAX_INST_SIZE) {
  1929. IWL_DEBUG_INFO(priv,
  1930. "uCode init instr len %d too large to fit in\n",
  1931. init_size);
  1932. ret = -EINVAL;
  1933. goto err_release;
  1934. }
  1935. if (init_data_size > IWL39_MAX_DATA_SIZE) {
  1936. IWL_DEBUG_INFO(priv,
  1937. "uCode init data len %d too large to fit in\n",
  1938. init_data_size);
  1939. ret = -EINVAL;
  1940. goto err_release;
  1941. }
  1942. if (boot_size > IWL39_MAX_BSM_SIZE) {
  1943. IWL_DEBUG_INFO(priv,
  1944. "uCode boot instr len %d too large to fit in\n",
  1945. boot_size);
  1946. ret = -EINVAL;
  1947. goto err_release;
  1948. }
  1949. /* Allocate ucode buffers for card's bus-master loading ... */
  1950. /* Runtime instructions and 2 copies of data:
  1951. * 1) unmodified from disk
  1952. * 2) backup cache for save/restore during power-downs */
  1953. priv->ucode_code.len = inst_size;
  1954. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1955. priv->ucode_data.len = data_size;
  1956. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1957. priv->ucode_data_backup.len = data_size;
  1958. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1959. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  1960. !priv->ucode_data_backup.v_addr)
  1961. goto err_pci_alloc;
  1962. /* Initialization instructions and data */
  1963. if (init_size && init_data_size) {
  1964. priv->ucode_init.len = init_size;
  1965. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1966. priv->ucode_init_data.len = init_data_size;
  1967. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1968. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1969. goto err_pci_alloc;
  1970. }
  1971. /* Bootstrap (instructions only, no data) */
  1972. if (boot_size) {
  1973. priv->ucode_boot.len = boot_size;
  1974. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1975. if (!priv->ucode_boot.v_addr)
  1976. goto err_pci_alloc;
  1977. }
  1978. /* Copy images into buffers for card's bus-master reads ... */
  1979. /* Runtime instructions (first block of data in file) */
  1980. len = inst_size;
  1981. IWL_DEBUG_INFO(priv,
  1982. "Copying (but not loading) uCode instr len %zd\n", len);
  1983. memcpy(priv->ucode_code.v_addr, src, len);
  1984. src += len;
  1985. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1986. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1987. /* Runtime data (2nd block)
  1988. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  1989. len = data_size;
  1990. IWL_DEBUG_INFO(priv,
  1991. "Copying (but not loading) uCode data len %zd\n", len);
  1992. memcpy(priv->ucode_data.v_addr, src, len);
  1993. memcpy(priv->ucode_data_backup.v_addr, src, len);
  1994. src += len;
  1995. /* Initialization instructions (3rd block) */
  1996. if (init_size) {
  1997. len = init_size;
  1998. IWL_DEBUG_INFO(priv,
  1999. "Copying (but not loading) init instr len %zd\n", len);
  2000. memcpy(priv->ucode_init.v_addr, src, len);
  2001. src += len;
  2002. }
  2003. /* Initialization data (4th block) */
  2004. if (init_data_size) {
  2005. len = init_data_size;
  2006. IWL_DEBUG_INFO(priv,
  2007. "Copying (but not loading) init data len %zd\n", len);
  2008. memcpy(priv->ucode_init_data.v_addr, src, len);
  2009. src += len;
  2010. }
  2011. /* Bootstrap instructions (5th block) */
  2012. len = boot_size;
  2013. IWL_DEBUG_INFO(priv,
  2014. "Copying (but not loading) boot instr len %zd\n", len);
  2015. memcpy(priv->ucode_boot.v_addr, src, len);
  2016. /* We have our copies now, allow OS release its copies */
  2017. release_firmware(ucode_raw);
  2018. return 0;
  2019. err_pci_alloc:
  2020. IWL_ERR(priv, "failed to allocate pci memory\n");
  2021. ret = -ENOMEM;
  2022. iwl3945_dealloc_ucode_pci(priv);
  2023. err_release:
  2024. release_firmware(ucode_raw);
  2025. error:
  2026. return ret;
  2027. }
  2028. /**
  2029. * iwl3945_set_ucode_ptrs - Set uCode address location
  2030. *
  2031. * Tell initialization uCode where to find runtime uCode.
  2032. *
  2033. * BSM registers initially contain pointers to initialization uCode.
  2034. * We need to replace them to load runtime uCode inst and data,
  2035. * and to save runtime data when powering down.
  2036. */
  2037. static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
  2038. {
  2039. dma_addr_t pinst;
  2040. dma_addr_t pdata;
  2041. /* bits 31:0 for 3945 */
  2042. pinst = priv->ucode_code.p_addr;
  2043. pdata = priv->ucode_data_backup.p_addr;
  2044. /* Tell bootstrap uCode where to find image to load */
  2045. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  2046. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  2047. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  2048. priv->ucode_data.len);
  2049. /* Inst byte count must be last to set up, bit 31 signals uCode
  2050. * that all new ptr/size info is in place */
  2051. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  2052. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  2053. IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
  2054. return 0;
  2055. }
  2056. /**
  2057. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  2058. *
  2059. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  2060. *
  2061. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  2062. */
  2063. static void iwl3945_init_alive_start(struct iwl_priv *priv)
  2064. {
  2065. /* Check alive response for "valid" sign from uCode */
  2066. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  2067. /* We had an error bringing up the hardware, so take it
  2068. * all the way back down so we can try again */
  2069. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  2070. goto restart;
  2071. }
  2072. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  2073. * This is a paranoid check, because we would not have gotten the
  2074. * "initialize" alive if code weren't properly loaded. */
  2075. if (iwl3945_verify_ucode(priv)) {
  2076. /* Runtime instruction load was bad;
  2077. * take it all the way back down so we can try again */
  2078. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  2079. goto restart;
  2080. }
  2081. /* Send pointers to protocol/runtime uCode image ... init code will
  2082. * load and launch runtime uCode, which will send us another "Alive"
  2083. * notification. */
  2084. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  2085. if (iwl3945_set_ucode_ptrs(priv)) {
  2086. /* Runtime instruction load won't happen;
  2087. * take it all the way back down so we can try again */
  2088. IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
  2089. goto restart;
  2090. }
  2091. return;
  2092. restart:
  2093. queue_work(priv->workqueue, &priv->restart);
  2094. }
  2095. /**
  2096. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  2097. * from protocol/runtime uCode (initialization uCode's
  2098. * Alive gets handled by iwl3945_init_alive_start()).
  2099. */
  2100. static void iwl3945_alive_start(struct iwl_priv *priv)
  2101. {
  2102. int thermal_spin = 0;
  2103. u32 rfkill;
  2104. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2105. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  2106. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2107. /* We had an error bringing up the hardware, so take it
  2108. * all the way back down so we can try again */
  2109. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  2110. goto restart;
  2111. }
  2112. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2113. * This is a paranoid check, because we would not have gotten the
  2114. * "runtime" alive if code weren't properly loaded. */
  2115. if (iwl3945_verify_ucode(priv)) {
  2116. /* Runtime instruction load was bad;
  2117. * take it all the way back down so we can try again */
  2118. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  2119. goto restart;
  2120. }
  2121. rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
  2122. IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
  2123. if (rfkill & 0x1) {
  2124. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2125. /* if RFKILL is not on, then wait for thermal
  2126. * sensor in adapter to kick in */
  2127. while (iwl3945_hw_get_temperature(priv) == 0) {
  2128. thermal_spin++;
  2129. udelay(10);
  2130. }
  2131. if (thermal_spin)
  2132. IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
  2133. thermal_spin * 10);
  2134. } else
  2135. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2136. /* After the ALIVE response, we can send commands to 3945 uCode */
  2137. set_bit(STATUS_ALIVE, &priv->status);
  2138. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  2139. /* Enable timer to monitor the driver queues */
  2140. mod_timer(&priv->monitor_recover,
  2141. jiffies +
  2142. msecs_to_jiffies(priv->cfg->monitor_recover_period));
  2143. }
  2144. if (iwl_is_rfkill(priv))
  2145. return;
  2146. ieee80211_wake_queues(priv->hw);
  2147. priv->active_rate = IWL_RATES_MASK;
  2148. iwl_power_update_mode(priv, true);
  2149. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
  2150. struct iwl3945_rxon_cmd *active_rxon =
  2151. (struct iwl3945_rxon_cmd *)(&ctx->active);
  2152. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2153. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2154. } else {
  2155. /* Initialize our rx_config data */
  2156. iwl_connection_init_rx_config(priv, NULL);
  2157. }
  2158. /* Configure Bluetooth device coexistence support */
  2159. priv->cfg->ops->hcmd->send_bt_config(priv);
  2160. /* Configure the adapter for unassociated operation */
  2161. iwlcore_commit_rxon(priv, ctx);
  2162. iwl3945_reg_txpower_periodic(priv);
  2163. iwl_leds_init(priv);
  2164. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  2165. set_bit(STATUS_READY, &priv->status);
  2166. wake_up_interruptible(&priv->wait_command_queue);
  2167. return;
  2168. restart:
  2169. queue_work(priv->workqueue, &priv->restart);
  2170. }
  2171. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
  2172. static void __iwl3945_down(struct iwl_priv *priv)
  2173. {
  2174. unsigned long flags;
  2175. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2176. struct ieee80211_conf *conf = NULL;
  2177. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  2178. conf = ieee80211_get_hw_conf(priv->hw);
  2179. if (!exit_pending)
  2180. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2181. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  2182. * to prevent rearm timer */
  2183. if (priv->cfg->ops->lib->recover_from_tx_stall)
  2184. del_timer_sync(&priv->monitor_recover);
  2185. /* Station information will now be cleared in device */
  2186. iwl_clear_ucode_stations(priv, NULL);
  2187. iwl_dealloc_bcast_stations(priv);
  2188. iwl_clear_driver_stations(priv);
  2189. /* Unblock any waiting calls */
  2190. wake_up_interruptible_all(&priv->wait_command_queue);
  2191. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2192. * exiting the module */
  2193. if (!exit_pending)
  2194. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2195. /* stop and reset the on-board processor */
  2196. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2197. /* tell the device to stop sending interrupts */
  2198. spin_lock_irqsave(&priv->lock, flags);
  2199. iwl_disable_interrupts(priv);
  2200. spin_unlock_irqrestore(&priv->lock, flags);
  2201. iwl_synchronize_irq(priv);
  2202. if (priv->mac80211_registered)
  2203. ieee80211_stop_queues(priv->hw);
  2204. /* If we have not previously called iwl3945_init() then
  2205. * clear all bits but the RF Kill bits and return */
  2206. if (!iwl_is_init(priv)) {
  2207. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2208. STATUS_RF_KILL_HW |
  2209. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2210. STATUS_GEO_CONFIGURED |
  2211. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2212. STATUS_EXIT_PENDING;
  2213. goto exit;
  2214. }
  2215. /* ...otherwise clear out all the status bits but the RF Kill
  2216. * bit and continue taking the NIC down. */
  2217. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2218. STATUS_RF_KILL_HW |
  2219. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2220. STATUS_GEO_CONFIGURED |
  2221. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2222. STATUS_FW_ERROR |
  2223. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2224. STATUS_EXIT_PENDING;
  2225. iwl3945_hw_txq_ctx_stop(priv);
  2226. iwl3945_hw_rxq_stop(priv);
  2227. /* Power-down device's busmaster DMA clocks */
  2228. iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  2229. udelay(5);
  2230. /* Stop the device, and put it in low power state */
  2231. priv->cfg->ops->lib->apm_ops.stop(priv);
  2232. exit:
  2233. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2234. if (priv->ibss_beacon)
  2235. dev_kfree_skb(priv->ibss_beacon);
  2236. priv->ibss_beacon = NULL;
  2237. /* clear out any free frames */
  2238. iwl3945_clear_free_frames(priv);
  2239. }
  2240. static void iwl3945_down(struct iwl_priv *priv)
  2241. {
  2242. mutex_lock(&priv->mutex);
  2243. __iwl3945_down(priv);
  2244. mutex_unlock(&priv->mutex);
  2245. iwl3945_cancel_deferred_work(priv);
  2246. }
  2247. #define MAX_HW_RESTARTS 5
  2248. static int __iwl3945_up(struct iwl_priv *priv)
  2249. {
  2250. int rc, i;
  2251. rc = iwl_alloc_bcast_station(priv, &priv->contexts[IWL_RXON_CTX_BSS],
  2252. false);
  2253. if (rc)
  2254. return rc;
  2255. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2256. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2257. return -EIO;
  2258. }
  2259. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2260. IWL_ERR(priv, "ucode not available for device bring up\n");
  2261. return -EIO;
  2262. }
  2263. /* If platform's RF_KILL switch is NOT set to KILL */
  2264. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2265. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2266. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2267. else {
  2268. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2269. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2270. return -ENODEV;
  2271. }
  2272. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2273. rc = iwl3945_hw_nic_init(priv);
  2274. if (rc) {
  2275. IWL_ERR(priv, "Unable to int nic\n");
  2276. return rc;
  2277. }
  2278. /* make sure rfkill handshake bits are cleared */
  2279. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2280. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2281. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2282. /* clear (again), then enable host interrupts */
  2283. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2284. iwl_enable_interrupts(priv);
  2285. /* really make sure rfkill handshake bits are cleared */
  2286. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2287. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2288. /* Copy original ucode data image from disk into backup cache.
  2289. * This will be used to initialize the on-board processor's
  2290. * data SRAM for a clean start when the runtime program first loads. */
  2291. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2292. priv->ucode_data.len);
  2293. /* We return success when we resume from suspend and rf_kill is on. */
  2294. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2295. return 0;
  2296. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2297. /* load bootstrap state machine,
  2298. * load bootstrap program into processor's memory,
  2299. * prepare to load the "initialize" uCode */
  2300. rc = priv->cfg->ops->lib->load_ucode(priv);
  2301. if (rc) {
  2302. IWL_ERR(priv,
  2303. "Unable to set up bootstrap uCode: %d\n", rc);
  2304. continue;
  2305. }
  2306. /* start card; "initialize" will load runtime ucode */
  2307. iwl3945_nic_start(priv);
  2308. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2309. return 0;
  2310. }
  2311. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2312. __iwl3945_down(priv);
  2313. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2314. /* tried to restart and config the device for as long as our
  2315. * patience could withstand */
  2316. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2317. return -EIO;
  2318. }
  2319. /*****************************************************************************
  2320. *
  2321. * Workqueue callbacks
  2322. *
  2323. *****************************************************************************/
  2324. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  2325. {
  2326. struct iwl_priv *priv =
  2327. container_of(data, struct iwl_priv, init_alive_start.work);
  2328. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2329. return;
  2330. mutex_lock(&priv->mutex);
  2331. iwl3945_init_alive_start(priv);
  2332. mutex_unlock(&priv->mutex);
  2333. }
  2334. static void iwl3945_bg_alive_start(struct work_struct *data)
  2335. {
  2336. struct iwl_priv *priv =
  2337. container_of(data, struct iwl_priv, alive_start.work);
  2338. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2339. return;
  2340. mutex_lock(&priv->mutex);
  2341. iwl3945_alive_start(priv);
  2342. mutex_unlock(&priv->mutex);
  2343. }
  2344. /*
  2345. * 3945 cannot interrupt driver when hardware rf kill switch toggles;
  2346. * driver must poll CSR_GP_CNTRL_REG register for change. This register
  2347. * *is* readable even when device has been SW_RESET into low power mode
  2348. * (e.g. during RF KILL).
  2349. */
  2350. static void iwl3945_rfkill_poll(struct work_struct *data)
  2351. {
  2352. struct iwl_priv *priv =
  2353. container_of(data, struct iwl_priv, _3945.rfkill_poll.work);
  2354. bool old_rfkill = test_bit(STATUS_RF_KILL_HW, &priv->status);
  2355. bool new_rfkill = !(iwl_read32(priv, CSR_GP_CNTRL)
  2356. & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
  2357. if (new_rfkill != old_rfkill) {
  2358. if (new_rfkill)
  2359. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2360. else
  2361. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2362. wiphy_rfkill_set_hw_state(priv->hw->wiphy, new_rfkill);
  2363. IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
  2364. new_rfkill ? "disable radio" : "enable radio");
  2365. }
  2366. /* Keep this running, even if radio now enabled. This will be
  2367. * cancelled in mac_start() if system decides to start again */
  2368. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  2369. round_jiffies_relative(2 * HZ));
  2370. }
  2371. void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2372. {
  2373. struct iwl_host_cmd cmd = {
  2374. .id = REPLY_SCAN_CMD,
  2375. .len = sizeof(struct iwl3945_scan_cmd),
  2376. .flags = CMD_SIZE_HUGE,
  2377. };
  2378. struct iwl3945_scan_cmd *scan;
  2379. struct ieee80211_conf *conf = NULL;
  2380. u8 n_probes = 0;
  2381. enum ieee80211_band band;
  2382. bool is_active = false;
  2383. conf = ieee80211_get_hw_conf(priv->hw);
  2384. cancel_delayed_work(&priv->scan_check);
  2385. if (!iwl_is_ready(priv)) {
  2386. IWL_WARN(priv, "request scan called when driver not ready.\n");
  2387. goto done;
  2388. }
  2389. /* Make sure the scan wasn't canceled before this queued work
  2390. * was given the chance to run... */
  2391. if (!test_bit(STATUS_SCANNING, &priv->status))
  2392. goto done;
  2393. /* This should never be called or scheduled if there is currently
  2394. * a scan active in the hardware. */
  2395. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2396. IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
  2397. "Ignoring second request.\n");
  2398. goto done;
  2399. }
  2400. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2401. IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
  2402. goto done;
  2403. }
  2404. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2405. IWL_DEBUG_HC(priv,
  2406. "Scan request while abort pending. Queuing.\n");
  2407. goto done;
  2408. }
  2409. if (iwl_is_rfkill(priv)) {
  2410. IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
  2411. goto done;
  2412. }
  2413. if (!test_bit(STATUS_READY, &priv->status)) {
  2414. IWL_DEBUG_HC(priv,
  2415. "Scan request while uninitialized. Queuing.\n");
  2416. goto done;
  2417. }
  2418. if (!priv->scan_cmd) {
  2419. priv->scan_cmd = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  2420. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2421. if (!priv->scan_cmd) {
  2422. IWL_DEBUG_SCAN(priv, "Fail to allocate scan memory\n");
  2423. goto done;
  2424. }
  2425. }
  2426. scan = priv->scan_cmd;
  2427. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2428. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2429. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2430. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
  2431. u16 interval = 0;
  2432. u32 extra;
  2433. u32 suspend_time = 100;
  2434. u32 scan_suspend_time = 100;
  2435. unsigned long flags;
  2436. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  2437. spin_lock_irqsave(&priv->lock, flags);
  2438. if (priv->is_internal_short_scan)
  2439. interval = 0;
  2440. else
  2441. interval = vif->bss_conf.beacon_int;
  2442. spin_unlock_irqrestore(&priv->lock, flags);
  2443. scan->suspend_time = 0;
  2444. scan->max_out_time = cpu_to_le32(200 * 1024);
  2445. if (!interval)
  2446. interval = suspend_time;
  2447. /*
  2448. * suspend time format:
  2449. * 0-19: beacon interval in usec (time before exec.)
  2450. * 20-23: 0
  2451. * 24-31: number of beacons (suspend between channels)
  2452. */
  2453. extra = (suspend_time / interval) << 24;
  2454. scan_suspend_time = 0xFF0FFFFF &
  2455. (extra | ((suspend_time % interval) * 1024));
  2456. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2457. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  2458. scan_suspend_time, interval);
  2459. }
  2460. if (priv->is_internal_short_scan) {
  2461. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  2462. } else if (priv->scan_request->n_ssids) {
  2463. int i, p = 0;
  2464. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  2465. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  2466. /* always does wildcard anyway */
  2467. if (!priv->scan_request->ssids[i].ssid_len)
  2468. continue;
  2469. scan->direct_scan[p].id = WLAN_EID_SSID;
  2470. scan->direct_scan[p].len =
  2471. priv->scan_request->ssids[i].ssid_len;
  2472. memcpy(scan->direct_scan[p].ssid,
  2473. priv->scan_request->ssids[i].ssid,
  2474. priv->scan_request->ssids[i].ssid_len);
  2475. n_probes++;
  2476. p++;
  2477. }
  2478. is_active = true;
  2479. } else
  2480. IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
  2481. /* We don't build a direct scan probe request; the uCode will do
  2482. * that based on the direct_mask added to each channel entry */
  2483. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2484. scan->tx_cmd.sta_id = priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
  2485. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2486. /* flags + rate selection */
  2487. switch (priv->scan_band) {
  2488. case IEEE80211_BAND_2GHZ:
  2489. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  2490. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  2491. scan->good_CRC_th = 0;
  2492. band = IEEE80211_BAND_2GHZ;
  2493. break;
  2494. case IEEE80211_BAND_5GHZ:
  2495. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  2496. /*
  2497. * If active scaning is requested but a certain channel
  2498. * is marked passive, we can do active scanning if we
  2499. * detect transmissions.
  2500. */
  2501. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  2502. IWL_GOOD_CRC_TH_DISABLED;
  2503. band = IEEE80211_BAND_5GHZ;
  2504. break;
  2505. default:
  2506. IWL_WARN(priv, "Invalid scan band\n");
  2507. goto done;
  2508. }
  2509. if (!priv->is_internal_short_scan) {
  2510. scan->tx_cmd.len = cpu_to_le16(
  2511. iwl_fill_probe_req(priv,
  2512. (struct ieee80211_mgmt *)scan->data,
  2513. vif->addr,
  2514. priv->scan_request->ie,
  2515. priv->scan_request->ie_len,
  2516. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  2517. } else {
  2518. /* use bcast addr, will not be transmitted but must be valid */
  2519. scan->tx_cmd.len = cpu_to_le16(
  2520. iwl_fill_probe_req(priv,
  2521. (struct ieee80211_mgmt *)scan->data,
  2522. iwl_bcast_addr, NULL, 0,
  2523. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  2524. }
  2525. /* select Rx antennas */
  2526. scan->flags |= iwl3945_get_antenna_flags(priv);
  2527. if (priv->is_internal_short_scan) {
  2528. scan->channel_count =
  2529. iwl3945_get_single_channel_for_scan(priv, vif, band,
  2530. (void *)&scan->data[le16_to_cpu(
  2531. scan->tx_cmd.len)]);
  2532. } else {
  2533. scan->channel_count =
  2534. iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
  2535. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)], vif);
  2536. }
  2537. if (scan->channel_count == 0) {
  2538. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  2539. goto done;
  2540. }
  2541. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  2542. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  2543. cmd.data = scan;
  2544. scan->len = cpu_to_le16(cmd.len);
  2545. set_bit(STATUS_SCAN_HW, &priv->status);
  2546. if (iwl_send_cmd_sync(priv, &cmd))
  2547. goto done;
  2548. queue_delayed_work(priv->workqueue, &priv->scan_check,
  2549. IWL_SCAN_CHECK_WATCHDOG);
  2550. return;
  2551. done:
  2552. /* can not perform scan make sure we clear scanning
  2553. * bits from status so next scan request can be performed.
  2554. * if we dont clear scanning status bit here all next scan
  2555. * will fail
  2556. */
  2557. clear_bit(STATUS_SCAN_HW, &priv->status);
  2558. clear_bit(STATUS_SCANNING, &priv->status);
  2559. /* inform mac80211 scan aborted */
  2560. queue_work(priv->workqueue, &priv->scan_completed);
  2561. }
  2562. static void iwl3945_bg_restart(struct work_struct *data)
  2563. {
  2564. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2565. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2566. return;
  2567. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2568. struct iwl_rxon_context *ctx;
  2569. mutex_lock(&priv->mutex);
  2570. for_each_context(priv, ctx)
  2571. ctx->vif = NULL;
  2572. priv->is_open = 0;
  2573. mutex_unlock(&priv->mutex);
  2574. iwl3945_down(priv);
  2575. ieee80211_restart_hw(priv->hw);
  2576. } else {
  2577. iwl3945_down(priv);
  2578. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2579. return;
  2580. mutex_lock(&priv->mutex);
  2581. __iwl3945_up(priv);
  2582. mutex_unlock(&priv->mutex);
  2583. }
  2584. }
  2585. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  2586. {
  2587. struct iwl_priv *priv =
  2588. container_of(data, struct iwl_priv, rx_replenish);
  2589. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2590. return;
  2591. mutex_lock(&priv->mutex);
  2592. iwl3945_rx_replenish(priv);
  2593. mutex_unlock(&priv->mutex);
  2594. }
  2595. void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2596. {
  2597. int rc = 0;
  2598. struct ieee80211_conf *conf = NULL;
  2599. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2600. if (!vif || !priv->is_open)
  2601. return;
  2602. if (vif->type == NL80211_IFTYPE_AP) {
  2603. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  2604. return;
  2605. }
  2606. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  2607. vif->bss_conf.aid, ctx->active.bssid_addr);
  2608. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2609. return;
  2610. iwl_scan_cancel_timeout(priv, 200);
  2611. conf = ieee80211_get_hw_conf(priv->hw);
  2612. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2613. iwlcore_commit_rxon(priv, ctx);
  2614. rc = iwl_send_rxon_timing(priv, ctx);
  2615. if (rc)
  2616. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2617. "Attempting to continue.\n");
  2618. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2619. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  2620. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  2621. vif->bss_conf.aid, vif->bss_conf.beacon_int);
  2622. if (vif->bss_conf.use_short_preamble)
  2623. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2624. else
  2625. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2626. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  2627. if (vif->bss_conf.use_short_slot)
  2628. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2629. else
  2630. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2631. }
  2632. iwlcore_commit_rxon(priv, ctx);
  2633. switch (vif->type) {
  2634. case NL80211_IFTYPE_STATION:
  2635. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  2636. break;
  2637. case NL80211_IFTYPE_ADHOC:
  2638. iwl3945_send_beacon_cmd(priv);
  2639. break;
  2640. default:
  2641. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  2642. __func__, vif->type);
  2643. break;
  2644. }
  2645. }
  2646. /*****************************************************************************
  2647. *
  2648. * mac80211 entry point functions
  2649. *
  2650. *****************************************************************************/
  2651. #define UCODE_READY_TIMEOUT (2 * HZ)
  2652. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  2653. {
  2654. struct iwl_priv *priv = hw->priv;
  2655. int ret;
  2656. IWL_DEBUG_MAC80211(priv, "enter\n");
  2657. /* we should be verifying the device is ready to be opened */
  2658. mutex_lock(&priv->mutex);
  2659. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  2660. * ucode filename and max sizes are card-specific. */
  2661. if (!priv->ucode_code.len) {
  2662. ret = iwl3945_read_ucode(priv);
  2663. if (ret) {
  2664. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  2665. mutex_unlock(&priv->mutex);
  2666. goto out_release_irq;
  2667. }
  2668. }
  2669. ret = __iwl3945_up(priv);
  2670. mutex_unlock(&priv->mutex);
  2671. if (ret)
  2672. goto out_release_irq;
  2673. IWL_DEBUG_INFO(priv, "Start UP work.\n");
  2674. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  2675. * mac80211 will not be run successfully. */
  2676. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2677. test_bit(STATUS_READY, &priv->status),
  2678. UCODE_READY_TIMEOUT);
  2679. if (!ret) {
  2680. if (!test_bit(STATUS_READY, &priv->status)) {
  2681. IWL_ERR(priv,
  2682. "Wait for START_ALIVE timeout after %dms.\n",
  2683. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2684. ret = -ETIMEDOUT;
  2685. goto out_release_irq;
  2686. }
  2687. }
  2688. /* ucode is running and will send rfkill notifications,
  2689. * no need to poll the killswitch state anymore */
  2690. cancel_delayed_work(&priv->_3945.rfkill_poll);
  2691. iwl_led_start(priv);
  2692. priv->is_open = 1;
  2693. IWL_DEBUG_MAC80211(priv, "leave\n");
  2694. return 0;
  2695. out_release_irq:
  2696. priv->is_open = 0;
  2697. IWL_DEBUG_MAC80211(priv, "leave - failed\n");
  2698. return ret;
  2699. }
  2700. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  2701. {
  2702. struct iwl_priv *priv = hw->priv;
  2703. IWL_DEBUG_MAC80211(priv, "enter\n");
  2704. if (!priv->is_open) {
  2705. IWL_DEBUG_MAC80211(priv, "leave - skip\n");
  2706. return;
  2707. }
  2708. priv->is_open = 0;
  2709. if (iwl_is_ready_rf(priv)) {
  2710. /* stop mac, cancel any scan request and clear
  2711. * RXON_FILTER_ASSOC_MSK BIT
  2712. */
  2713. mutex_lock(&priv->mutex);
  2714. iwl_scan_cancel_timeout(priv, 100);
  2715. mutex_unlock(&priv->mutex);
  2716. }
  2717. iwl3945_down(priv);
  2718. flush_workqueue(priv->workqueue);
  2719. /* start polling the killswitch state again */
  2720. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  2721. round_jiffies_relative(2 * HZ));
  2722. IWL_DEBUG_MAC80211(priv, "leave\n");
  2723. }
  2724. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2725. {
  2726. struct iwl_priv *priv = hw->priv;
  2727. IWL_DEBUG_MAC80211(priv, "enter\n");
  2728. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2729. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2730. if (iwl3945_tx_skb(priv, skb))
  2731. dev_kfree_skb_any(skb);
  2732. IWL_DEBUG_MAC80211(priv, "leave\n");
  2733. return NETDEV_TX_OK;
  2734. }
  2735. void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2736. {
  2737. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2738. int rc = 0;
  2739. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2740. return;
  2741. /* The following should be done only at AP bring up */
  2742. if (!(iwl_is_associated(priv, IWL_RXON_CTX_BSS))) {
  2743. /* RXON - unassoc (to set timing command) */
  2744. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2745. iwlcore_commit_rxon(priv, ctx);
  2746. /* RXON Timing */
  2747. rc = iwl_send_rxon_timing(priv, ctx);
  2748. if (rc)
  2749. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2750. "Attempting to continue.\n");
  2751. ctx->staging.assoc_id = 0;
  2752. if (vif->bss_conf.use_short_preamble)
  2753. ctx->staging.flags |=
  2754. RXON_FLG_SHORT_PREAMBLE_MSK;
  2755. else
  2756. ctx->staging.flags &=
  2757. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2758. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  2759. if (vif->bss_conf.use_short_slot)
  2760. ctx->staging.flags |=
  2761. RXON_FLG_SHORT_SLOT_MSK;
  2762. else
  2763. ctx->staging.flags &=
  2764. ~RXON_FLG_SHORT_SLOT_MSK;
  2765. }
  2766. /* restore RXON assoc */
  2767. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2768. iwlcore_commit_rxon(priv, ctx);
  2769. }
  2770. iwl3945_send_beacon_cmd(priv);
  2771. /* FIXME - we need to add code here to detect a totally new
  2772. * configuration, reset the AP, unassoc, rxon timing, assoc,
  2773. * clear sta table, add BCAST sta... */
  2774. }
  2775. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2776. struct ieee80211_vif *vif,
  2777. struct ieee80211_sta *sta,
  2778. struct ieee80211_key_conf *key)
  2779. {
  2780. struct iwl_priv *priv = hw->priv;
  2781. int ret = 0;
  2782. u8 sta_id = IWL_INVALID_STATION;
  2783. u8 static_key;
  2784. IWL_DEBUG_MAC80211(priv, "enter\n");
  2785. if (iwl3945_mod_params.sw_crypto) {
  2786. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2787. return -EOPNOTSUPP;
  2788. }
  2789. static_key = !iwl_is_associated(priv, IWL_RXON_CTX_BSS);
  2790. if (!static_key) {
  2791. sta_id = iwl_sta_id_or_broadcast(
  2792. priv, &priv->contexts[IWL_RXON_CTX_BSS], sta);
  2793. if (sta_id == IWL_INVALID_STATION)
  2794. return -EINVAL;
  2795. }
  2796. mutex_lock(&priv->mutex);
  2797. iwl_scan_cancel_timeout(priv, 100);
  2798. switch (cmd) {
  2799. case SET_KEY:
  2800. if (static_key)
  2801. ret = iwl3945_set_static_key(priv, key);
  2802. else
  2803. ret = iwl3945_set_dynamic_key(priv, key, sta_id);
  2804. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2805. break;
  2806. case DISABLE_KEY:
  2807. if (static_key)
  2808. ret = iwl3945_remove_static_key(priv);
  2809. else
  2810. ret = iwl3945_clear_sta_key_info(priv, sta_id);
  2811. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2812. break;
  2813. default:
  2814. ret = -EINVAL;
  2815. }
  2816. mutex_unlock(&priv->mutex);
  2817. IWL_DEBUG_MAC80211(priv, "leave\n");
  2818. return ret;
  2819. }
  2820. static int iwl3945_mac_sta_add(struct ieee80211_hw *hw,
  2821. struct ieee80211_vif *vif,
  2822. struct ieee80211_sta *sta)
  2823. {
  2824. struct iwl_priv *priv = hw->priv;
  2825. struct iwl3945_sta_priv *sta_priv = (void *)sta->drv_priv;
  2826. int ret;
  2827. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2828. u8 sta_id;
  2829. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2830. sta->addr);
  2831. mutex_lock(&priv->mutex);
  2832. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2833. sta->addr);
  2834. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2835. ret = iwl_add_station_common(priv, &priv->contexts[IWL_RXON_CTX_BSS],
  2836. sta->addr, is_ap, sta, &sta_id);
  2837. if (ret) {
  2838. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2839. sta->addr, ret);
  2840. /* Should we return success if return code is EEXIST ? */
  2841. mutex_unlock(&priv->mutex);
  2842. return ret;
  2843. }
  2844. sta_priv->common.sta_id = sta_id;
  2845. /* Initialize rate scaling */
  2846. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2847. sta->addr);
  2848. iwl3945_rs_rate_init(priv, sta, sta_id);
  2849. mutex_unlock(&priv->mutex);
  2850. return 0;
  2851. }
  2852. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  2853. unsigned int changed_flags,
  2854. unsigned int *total_flags,
  2855. u64 multicast)
  2856. {
  2857. struct iwl_priv *priv = hw->priv;
  2858. __le32 filter_or = 0, filter_nand = 0;
  2859. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2860. #define CHK(test, flag) do { \
  2861. if (*total_flags & (test)) \
  2862. filter_or |= (flag); \
  2863. else \
  2864. filter_nand |= (flag); \
  2865. } while (0)
  2866. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2867. changed_flags, *total_flags);
  2868. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2869. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
  2870. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2871. #undef CHK
  2872. mutex_lock(&priv->mutex);
  2873. ctx->staging.filter_flags &= ~filter_nand;
  2874. ctx->staging.filter_flags |= filter_or;
  2875. /*
  2876. * Committing directly here breaks for some reason,
  2877. * but we'll eventually commit the filter flags
  2878. * change anyway.
  2879. */
  2880. mutex_unlock(&priv->mutex);
  2881. /*
  2882. * Receiving all multicast frames is always enabled by the
  2883. * default flags setup in iwl_connection_init_rx_config()
  2884. * since we currently do not support programming multicast
  2885. * filters into the device.
  2886. */
  2887. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2888. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2889. }
  2890. /*****************************************************************************
  2891. *
  2892. * sysfs attributes
  2893. *
  2894. *****************************************************************************/
  2895. #ifdef CONFIG_IWLWIFI_DEBUG
  2896. /*
  2897. * The following adds a new attribute to the sysfs representation
  2898. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  2899. * used for controlling the debug level.
  2900. *
  2901. * See the level definitions in iwl for details.
  2902. *
  2903. * The debug_level being managed using sysfs below is a per device debug
  2904. * level that is used instead of the global debug level if it (the per
  2905. * device debug level) is set.
  2906. */
  2907. static ssize_t show_debug_level(struct device *d,
  2908. struct device_attribute *attr, char *buf)
  2909. {
  2910. struct iwl_priv *priv = dev_get_drvdata(d);
  2911. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  2912. }
  2913. static ssize_t store_debug_level(struct device *d,
  2914. struct device_attribute *attr,
  2915. const char *buf, size_t count)
  2916. {
  2917. struct iwl_priv *priv = dev_get_drvdata(d);
  2918. unsigned long val;
  2919. int ret;
  2920. ret = strict_strtoul(buf, 0, &val);
  2921. if (ret)
  2922. IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
  2923. else {
  2924. priv->debug_level = val;
  2925. if (iwl_alloc_traffic_mem(priv))
  2926. IWL_ERR(priv,
  2927. "Not enough memory to generate traffic log\n");
  2928. }
  2929. return strnlen(buf, count);
  2930. }
  2931. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  2932. show_debug_level, store_debug_level);
  2933. #endif /* CONFIG_IWLWIFI_DEBUG */
  2934. static ssize_t show_temperature(struct device *d,
  2935. struct device_attribute *attr, char *buf)
  2936. {
  2937. struct iwl_priv *priv = dev_get_drvdata(d);
  2938. if (!iwl_is_alive(priv))
  2939. return -EAGAIN;
  2940. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  2941. }
  2942. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  2943. static ssize_t show_tx_power(struct device *d,
  2944. struct device_attribute *attr, char *buf)
  2945. {
  2946. struct iwl_priv *priv = dev_get_drvdata(d);
  2947. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  2948. }
  2949. static ssize_t store_tx_power(struct device *d,
  2950. struct device_attribute *attr,
  2951. const char *buf, size_t count)
  2952. {
  2953. struct iwl_priv *priv = dev_get_drvdata(d);
  2954. char *p = (char *)buf;
  2955. u32 val;
  2956. val = simple_strtoul(p, &p, 10);
  2957. if (p == buf)
  2958. IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
  2959. else
  2960. iwl3945_hw_reg_set_txpower(priv, val);
  2961. return count;
  2962. }
  2963. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  2964. static ssize_t show_flags(struct device *d,
  2965. struct device_attribute *attr, char *buf)
  2966. {
  2967. struct iwl_priv *priv = dev_get_drvdata(d);
  2968. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2969. return sprintf(buf, "0x%04X\n", ctx->active.flags);
  2970. }
  2971. static ssize_t store_flags(struct device *d,
  2972. struct device_attribute *attr,
  2973. const char *buf, size_t count)
  2974. {
  2975. struct iwl_priv *priv = dev_get_drvdata(d);
  2976. u32 flags = simple_strtoul(buf, NULL, 0);
  2977. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2978. mutex_lock(&priv->mutex);
  2979. if (le32_to_cpu(ctx->staging.flags) != flags) {
  2980. /* Cancel any currently running scans... */
  2981. if (iwl_scan_cancel_timeout(priv, 100))
  2982. IWL_WARN(priv, "Could not cancel scan.\n");
  2983. else {
  2984. IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
  2985. flags);
  2986. ctx->staging.flags = cpu_to_le32(flags);
  2987. iwlcore_commit_rxon(priv, ctx);
  2988. }
  2989. }
  2990. mutex_unlock(&priv->mutex);
  2991. return count;
  2992. }
  2993. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  2994. static ssize_t show_filter_flags(struct device *d,
  2995. struct device_attribute *attr, char *buf)
  2996. {
  2997. struct iwl_priv *priv = dev_get_drvdata(d);
  2998. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2999. return sprintf(buf, "0x%04X\n",
  3000. le32_to_cpu(ctx->active.filter_flags));
  3001. }
  3002. static ssize_t store_filter_flags(struct device *d,
  3003. struct device_attribute *attr,
  3004. const char *buf, size_t count)
  3005. {
  3006. struct iwl_priv *priv = dev_get_drvdata(d);
  3007. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  3008. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3009. mutex_lock(&priv->mutex);
  3010. if (le32_to_cpu(ctx->staging.filter_flags) != filter_flags) {
  3011. /* Cancel any currently running scans... */
  3012. if (iwl_scan_cancel_timeout(priv, 100))
  3013. IWL_WARN(priv, "Could not cancel scan.\n");
  3014. else {
  3015. IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
  3016. "0x%04X\n", filter_flags);
  3017. ctx->staging.filter_flags =
  3018. cpu_to_le32(filter_flags);
  3019. iwlcore_commit_rxon(priv, ctx);
  3020. }
  3021. }
  3022. mutex_unlock(&priv->mutex);
  3023. return count;
  3024. }
  3025. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3026. store_filter_flags);
  3027. static ssize_t show_measurement(struct device *d,
  3028. struct device_attribute *attr, char *buf)
  3029. {
  3030. struct iwl_priv *priv = dev_get_drvdata(d);
  3031. struct iwl_spectrum_notification measure_report;
  3032. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3033. u8 *data = (u8 *)&measure_report;
  3034. unsigned long flags;
  3035. spin_lock_irqsave(&priv->lock, flags);
  3036. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3037. spin_unlock_irqrestore(&priv->lock, flags);
  3038. return 0;
  3039. }
  3040. memcpy(&measure_report, &priv->measure_report, size);
  3041. priv->measurement_status = 0;
  3042. spin_unlock_irqrestore(&priv->lock, flags);
  3043. while (size && (PAGE_SIZE - len)) {
  3044. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3045. PAGE_SIZE - len, 1);
  3046. len = strlen(buf);
  3047. if (PAGE_SIZE - len)
  3048. buf[len++] = '\n';
  3049. ofs += 16;
  3050. size -= min(size, 16U);
  3051. }
  3052. return len;
  3053. }
  3054. static ssize_t store_measurement(struct device *d,
  3055. struct device_attribute *attr,
  3056. const char *buf, size_t count)
  3057. {
  3058. struct iwl_priv *priv = dev_get_drvdata(d);
  3059. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  3060. struct ieee80211_measurement_params params = {
  3061. .channel = le16_to_cpu(ctx->active.channel),
  3062. .start_time = cpu_to_le64(priv->_3945.last_tsf),
  3063. .duration = cpu_to_le16(1),
  3064. };
  3065. u8 type = IWL_MEASURE_BASIC;
  3066. u8 buffer[32];
  3067. u8 channel;
  3068. if (count) {
  3069. char *p = buffer;
  3070. strncpy(buffer, buf, min(sizeof(buffer), count));
  3071. channel = simple_strtoul(p, NULL, 0);
  3072. if (channel)
  3073. params.channel = channel;
  3074. p = buffer;
  3075. while (*p && *p != ' ')
  3076. p++;
  3077. if (*p)
  3078. type = simple_strtoul(p + 1, NULL, 0);
  3079. }
  3080. IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
  3081. "channel %d (for '%s')\n", type, params.channel, buf);
  3082. iwl3945_get_measurement(priv, &params, type);
  3083. return count;
  3084. }
  3085. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3086. show_measurement, store_measurement);
  3087. static ssize_t store_retry_rate(struct device *d,
  3088. struct device_attribute *attr,
  3089. const char *buf, size_t count)
  3090. {
  3091. struct iwl_priv *priv = dev_get_drvdata(d);
  3092. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3093. if (priv->retry_rate <= 0)
  3094. priv->retry_rate = 1;
  3095. return count;
  3096. }
  3097. static ssize_t show_retry_rate(struct device *d,
  3098. struct device_attribute *attr, char *buf)
  3099. {
  3100. struct iwl_priv *priv = dev_get_drvdata(d);
  3101. return sprintf(buf, "%d", priv->retry_rate);
  3102. }
  3103. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3104. store_retry_rate);
  3105. static ssize_t show_channels(struct device *d,
  3106. struct device_attribute *attr, char *buf)
  3107. {
  3108. /* all this shit doesn't belong into sysfs anyway */
  3109. return 0;
  3110. }
  3111. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  3112. static ssize_t show_antenna(struct device *d,
  3113. struct device_attribute *attr, char *buf)
  3114. {
  3115. struct iwl_priv *priv = dev_get_drvdata(d);
  3116. if (!iwl_is_alive(priv))
  3117. return -EAGAIN;
  3118. return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
  3119. }
  3120. static ssize_t store_antenna(struct device *d,
  3121. struct device_attribute *attr,
  3122. const char *buf, size_t count)
  3123. {
  3124. struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
  3125. int ant;
  3126. if (count == 0)
  3127. return 0;
  3128. if (sscanf(buf, "%1i", &ant) != 1) {
  3129. IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
  3130. return count;
  3131. }
  3132. if ((ant >= 0) && (ant <= 2)) {
  3133. IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
  3134. iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
  3135. } else
  3136. IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
  3137. return count;
  3138. }
  3139. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  3140. static ssize_t show_status(struct device *d,
  3141. struct device_attribute *attr, char *buf)
  3142. {
  3143. struct iwl_priv *priv = dev_get_drvdata(d);
  3144. if (!iwl_is_alive(priv))
  3145. return -EAGAIN;
  3146. return sprintf(buf, "0x%08x\n", (int)priv->status);
  3147. }
  3148. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  3149. static ssize_t dump_error_log(struct device *d,
  3150. struct device_attribute *attr,
  3151. const char *buf, size_t count)
  3152. {
  3153. struct iwl_priv *priv = dev_get_drvdata(d);
  3154. char *p = (char *)buf;
  3155. if (p[0] == '1')
  3156. iwl3945_dump_nic_error_log(priv);
  3157. return strnlen(buf, count);
  3158. }
  3159. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  3160. /*****************************************************************************
  3161. *
  3162. * driver setup and tear down
  3163. *
  3164. *****************************************************************************/
  3165. static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
  3166. {
  3167. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  3168. init_waitqueue_head(&priv->wait_command_queue);
  3169. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  3170. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  3171. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  3172. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  3173. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  3174. INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll);
  3175. iwl_setup_scan_deferred_work(priv);
  3176. iwl3945_hw_setup_deferred_work(priv);
  3177. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  3178. init_timer(&priv->monitor_recover);
  3179. priv->monitor_recover.data = (unsigned long)priv;
  3180. priv->monitor_recover.function =
  3181. priv->cfg->ops->lib->recover_from_tx_stall;
  3182. }
  3183. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  3184. iwl3945_irq_tasklet, (unsigned long)priv);
  3185. }
  3186. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
  3187. {
  3188. iwl3945_hw_cancel_deferred_work(priv);
  3189. cancel_delayed_work_sync(&priv->init_alive_start);
  3190. cancel_delayed_work(&priv->scan_check);
  3191. cancel_delayed_work(&priv->alive_start);
  3192. cancel_work_sync(&priv->start_internal_scan);
  3193. cancel_work_sync(&priv->beacon_update);
  3194. }
  3195. static struct attribute *iwl3945_sysfs_entries[] = {
  3196. &dev_attr_antenna.attr,
  3197. &dev_attr_channels.attr,
  3198. &dev_attr_dump_errors.attr,
  3199. &dev_attr_flags.attr,
  3200. &dev_attr_filter_flags.attr,
  3201. &dev_attr_measurement.attr,
  3202. &dev_attr_retry_rate.attr,
  3203. &dev_attr_status.attr,
  3204. &dev_attr_temperature.attr,
  3205. &dev_attr_tx_power.attr,
  3206. #ifdef CONFIG_IWLWIFI_DEBUG
  3207. &dev_attr_debug_level.attr,
  3208. #endif
  3209. NULL
  3210. };
  3211. static struct attribute_group iwl3945_attribute_group = {
  3212. .name = NULL, /* put in device directory */
  3213. .attrs = iwl3945_sysfs_entries,
  3214. };
  3215. static struct ieee80211_ops iwl3945_hw_ops = {
  3216. .tx = iwl3945_mac_tx,
  3217. .start = iwl3945_mac_start,
  3218. .stop = iwl3945_mac_stop,
  3219. .add_interface = iwl_mac_add_interface,
  3220. .remove_interface = iwl_mac_remove_interface,
  3221. .config = iwl_mac_config,
  3222. .configure_filter = iwl3945_configure_filter,
  3223. .set_key = iwl3945_mac_set_key,
  3224. .conf_tx = iwl_mac_conf_tx,
  3225. .reset_tsf = iwl_mac_reset_tsf,
  3226. .bss_info_changed = iwl_bss_info_changed,
  3227. .hw_scan = iwl_mac_hw_scan,
  3228. .sta_add = iwl3945_mac_sta_add,
  3229. .sta_remove = iwl_mac_sta_remove,
  3230. .tx_last_beacon = iwl_mac_tx_last_beacon,
  3231. };
  3232. static int iwl3945_init_drv(struct iwl_priv *priv)
  3233. {
  3234. int ret;
  3235. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  3236. priv->retry_rate = 1;
  3237. priv->ibss_beacon = NULL;
  3238. spin_lock_init(&priv->sta_lock);
  3239. spin_lock_init(&priv->hcmd_lock);
  3240. INIT_LIST_HEAD(&priv->free_frames);
  3241. mutex_init(&priv->mutex);
  3242. mutex_init(&priv->sync_cmd_mutex);
  3243. priv->ieee_channels = NULL;
  3244. priv->ieee_rates = NULL;
  3245. priv->band = IEEE80211_BAND_2GHZ;
  3246. priv->iw_mode = NL80211_IFTYPE_STATION;
  3247. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  3248. priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
  3249. if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
  3250. IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
  3251. eeprom->version);
  3252. ret = -EINVAL;
  3253. goto err;
  3254. }
  3255. ret = iwl_init_channel_map(priv);
  3256. if (ret) {
  3257. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  3258. goto err;
  3259. }
  3260. /* Set up txpower settings in driver for all channels */
  3261. if (iwl3945_txpower_set_from_eeprom(priv)) {
  3262. ret = -EIO;
  3263. goto err_free_channel_map;
  3264. }
  3265. ret = iwlcore_init_geos(priv);
  3266. if (ret) {
  3267. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  3268. goto err_free_channel_map;
  3269. }
  3270. iwl3945_init_hw_rates(priv, priv->ieee_rates);
  3271. return 0;
  3272. err_free_channel_map:
  3273. iwl_free_channel_map(priv);
  3274. err:
  3275. return ret;
  3276. }
  3277. #define IWL3945_MAX_PROBE_REQUEST 200
  3278. static int iwl3945_setup_mac(struct iwl_priv *priv)
  3279. {
  3280. int ret;
  3281. struct ieee80211_hw *hw = priv->hw;
  3282. hw->rate_control_algorithm = "iwl-3945-rs";
  3283. hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
  3284. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  3285. /* Tell mac80211 our characteristics */
  3286. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  3287. IEEE80211_HW_SPECTRUM_MGMT;
  3288. if (!priv->cfg->broken_powersave)
  3289. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  3290. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  3291. hw->wiphy->interface_modes =
  3292. BIT(NL80211_IFTYPE_STATION) |
  3293. BIT(NL80211_IFTYPE_ADHOC);
  3294. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  3295. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  3296. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
  3297. /* we create the 802.11 header and a zero-length SSID element */
  3298. hw->wiphy->max_scan_ie_len = IWL3945_MAX_PROBE_REQUEST - 24 - 2;
  3299. /* Default value; 4 EDCA QOS priorities */
  3300. hw->queues = 4;
  3301. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  3302. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  3303. &priv->bands[IEEE80211_BAND_2GHZ];
  3304. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  3305. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  3306. &priv->bands[IEEE80211_BAND_5GHZ];
  3307. ret = ieee80211_register_hw(priv->hw);
  3308. if (ret) {
  3309. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  3310. return ret;
  3311. }
  3312. priv->mac80211_registered = 1;
  3313. return 0;
  3314. }
  3315. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3316. {
  3317. int err = 0, i;
  3318. struct iwl_priv *priv;
  3319. struct ieee80211_hw *hw;
  3320. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  3321. struct iwl3945_eeprom *eeprom;
  3322. unsigned long flags;
  3323. /***********************
  3324. * 1. Allocating HW data
  3325. * ********************/
  3326. /* mac80211 allocates memory for this device instance, including
  3327. * space for this driver's private structure */
  3328. hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
  3329. if (hw == NULL) {
  3330. pr_err("Can not allocate network device\n");
  3331. err = -ENOMEM;
  3332. goto out;
  3333. }
  3334. priv = hw->priv;
  3335. SET_IEEE80211_DEV(hw, &pdev->dev);
  3336. priv->cmd_queue = IWL39_CMD_QUEUE_NUM;
  3337. /* 3945 has only one valid context */
  3338. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  3339. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  3340. priv->contexts[i].ctxid = i;
  3341. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  3342. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  3343. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  3344. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  3345. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  3346. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  3347. /*
  3348. * Disabling hardware scan means that mac80211 will perform scans
  3349. * "the hard way", rather than using device's scan.
  3350. */
  3351. if (iwl3945_mod_params.disable_hw_scan) {
  3352. IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
  3353. iwl3945_hw_ops.hw_scan = NULL;
  3354. }
  3355. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3356. priv->cfg = cfg;
  3357. priv->pci_dev = pdev;
  3358. priv->inta_mask = CSR_INI_SET_MASK;
  3359. if (iwl_alloc_traffic_mem(priv))
  3360. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3361. /***************************
  3362. * 2. Initializing PCI bus
  3363. * *************************/
  3364. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  3365. PCIE_LINK_STATE_CLKPM);
  3366. if (pci_enable_device(pdev)) {
  3367. err = -ENODEV;
  3368. goto out_ieee80211_free_hw;
  3369. }
  3370. pci_set_master(pdev);
  3371. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3372. if (!err)
  3373. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3374. if (err) {
  3375. IWL_WARN(priv, "No suitable DMA available.\n");
  3376. goto out_pci_disable_device;
  3377. }
  3378. pci_set_drvdata(pdev, priv);
  3379. err = pci_request_regions(pdev, DRV_NAME);
  3380. if (err)
  3381. goto out_pci_disable_device;
  3382. /***********************
  3383. * 3. Read REV Register
  3384. * ********************/
  3385. priv->hw_base = pci_iomap(pdev, 0, 0);
  3386. if (!priv->hw_base) {
  3387. err = -ENODEV;
  3388. goto out_pci_release_regions;
  3389. }
  3390. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  3391. (unsigned long long) pci_resource_len(pdev, 0));
  3392. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  3393. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3394. * PCI Tx retries from interfering with C3 CPU state */
  3395. pci_write_config_byte(pdev, 0x41, 0x00);
  3396. /* these spin locks will be used in apm_ops.init and EEPROM access
  3397. * we should init now
  3398. */
  3399. spin_lock_init(&priv->reg_lock);
  3400. spin_lock_init(&priv->lock);
  3401. /*
  3402. * stop and reset the on-board processor just in case it is in a
  3403. * strange state ... like being left stranded by a primary kernel
  3404. * and this is now the kdump kernel trying to start up
  3405. */
  3406. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3407. /***********************
  3408. * 4. Read EEPROM
  3409. * ********************/
  3410. /* Read the EEPROM */
  3411. err = iwl_eeprom_init(priv);
  3412. if (err) {
  3413. IWL_ERR(priv, "Unable to init EEPROM\n");
  3414. goto out_iounmap;
  3415. }
  3416. /* MAC Address location in EEPROM same for 3945/4965 */
  3417. eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  3418. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", eeprom->mac_address);
  3419. SET_IEEE80211_PERM_ADDR(priv->hw, eeprom->mac_address);
  3420. /***********************
  3421. * 5. Setup HW Constants
  3422. * ********************/
  3423. /* Device-specific setup */
  3424. if (iwl3945_hw_set_hw_params(priv)) {
  3425. IWL_ERR(priv, "failed to set hw settings\n");
  3426. goto out_eeprom_free;
  3427. }
  3428. /***********************
  3429. * 6. Setup priv
  3430. * ********************/
  3431. err = iwl3945_init_drv(priv);
  3432. if (err) {
  3433. IWL_ERR(priv, "initializing driver failed\n");
  3434. goto out_unset_hw_params;
  3435. }
  3436. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
  3437. priv->cfg->name);
  3438. /***********************
  3439. * 7. Setup Services
  3440. * ********************/
  3441. spin_lock_irqsave(&priv->lock, flags);
  3442. iwl_disable_interrupts(priv);
  3443. spin_unlock_irqrestore(&priv->lock, flags);
  3444. pci_enable_msi(priv->pci_dev);
  3445. err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
  3446. IRQF_SHARED, DRV_NAME, priv);
  3447. if (err) {
  3448. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  3449. goto out_disable_msi;
  3450. }
  3451. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3452. if (err) {
  3453. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  3454. goto out_release_irq;
  3455. }
  3456. iwl_set_rxon_channel(priv,
  3457. &priv->bands[IEEE80211_BAND_2GHZ].channels[5],
  3458. &priv->contexts[IWL_RXON_CTX_BSS]);
  3459. iwl3945_setup_deferred_work(priv);
  3460. iwl3945_setup_rx_handlers(priv);
  3461. iwl_power_initialize(priv);
  3462. /*********************************
  3463. * 8. Setup and Register mac80211
  3464. * *******************************/
  3465. iwl_enable_interrupts(priv);
  3466. err = iwl3945_setup_mac(priv);
  3467. if (err)
  3468. goto out_remove_sysfs;
  3469. err = iwl_dbgfs_register(priv, DRV_NAME);
  3470. if (err)
  3471. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  3472. /* Start monitoring the killswitch */
  3473. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  3474. 2 * HZ);
  3475. return 0;
  3476. out_remove_sysfs:
  3477. destroy_workqueue(priv->workqueue);
  3478. priv->workqueue = NULL;
  3479. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3480. out_release_irq:
  3481. free_irq(priv->pci_dev->irq, priv);
  3482. out_disable_msi:
  3483. pci_disable_msi(priv->pci_dev);
  3484. iwlcore_free_geos(priv);
  3485. iwl_free_channel_map(priv);
  3486. out_unset_hw_params:
  3487. iwl3945_unset_hw_params(priv);
  3488. out_eeprom_free:
  3489. iwl_eeprom_free(priv);
  3490. out_iounmap:
  3491. pci_iounmap(pdev, priv->hw_base);
  3492. out_pci_release_regions:
  3493. pci_release_regions(pdev);
  3494. out_pci_disable_device:
  3495. pci_set_drvdata(pdev, NULL);
  3496. pci_disable_device(pdev);
  3497. out_ieee80211_free_hw:
  3498. iwl_free_traffic_mem(priv);
  3499. ieee80211_free_hw(priv->hw);
  3500. out:
  3501. return err;
  3502. }
  3503. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  3504. {
  3505. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3506. unsigned long flags;
  3507. if (!priv)
  3508. return;
  3509. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3510. iwl_dbgfs_unregister(priv);
  3511. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3512. if (priv->mac80211_registered) {
  3513. ieee80211_unregister_hw(priv->hw);
  3514. priv->mac80211_registered = 0;
  3515. } else {
  3516. iwl3945_down(priv);
  3517. }
  3518. /*
  3519. * Make sure device is reset to low power before unloading driver.
  3520. * This may be redundant with iwl_down(), but there are paths to
  3521. * run iwl_down() without calling apm_ops.stop(), and there are
  3522. * paths to avoid running iwl_down() at all before leaving driver.
  3523. * This (inexpensive) call *makes sure* device is reset.
  3524. */
  3525. priv->cfg->ops->lib->apm_ops.stop(priv);
  3526. /* make sure we flush any pending irq or
  3527. * tasklet for the driver
  3528. */
  3529. spin_lock_irqsave(&priv->lock, flags);
  3530. iwl_disable_interrupts(priv);
  3531. spin_unlock_irqrestore(&priv->lock, flags);
  3532. iwl_synchronize_irq(priv);
  3533. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3534. cancel_delayed_work_sync(&priv->_3945.rfkill_poll);
  3535. iwl3945_dealloc_ucode_pci(priv);
  3536. if (priv->rxq.bd)
  3537. iwl3945_rx_queue_free(priv, &priv->rxq);
  3538. iwl3945_hw_txq_ctx_free(priv);
  3539. iwl3945_unset_hw_params(priv);
  3540. /*netif_stop_queue(dev); */
  3541. flush_workqueue(priv->workqueue);
  3542. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  3543. * priv->workqueue... so we can't take down the workqueue
  3544. * until now... */
  3545. destroy_workqueue(priv->workqueue);
  3546. priv->workqueue = NULL;
  3547. iwl_free_traffic_mem(priv);
  3548. free_irq(pdev->irq, priv);
  3549. pci_disable_msi(pdev);
  3550. pci_iounmap(pdev, priv->hw_base);
  3551. pci_release_regions(pdev);
  3552. pci_disable_device(pdev);
  3553. pci_set_drvdata(pdev, NULL);
  3554. iwl_free_channel_map(priv);
  3555. iwlcore_free_geos(priv);
  3556. kfree(priv->scan_cmd);
  3557. if (priv->ibss_beacon)
  3558. dev_kfree_skb(priv->ibss_beacon);
  3559. ieee80211_free_hw(priv->hw);
  3560. }
  3561. /*****************************************************************************
  3562. *
  3563. * driver and module entry point
  3564. *
  3565. *****************************************************************************/
  3566. static struct pci_driver iwl3945_driver = {
  3567. .name = DRV_NAME,
  3568. .id_table = iwl3945_hw_card_ids,
  3569. .probe = iwl3945_pci_probe,
  3570. .remove = __devexit_p(iwl3945_pci_remove),
  3571. #ifdef CONFIG_PM
  3572. .suspend = iwl_pci_suspend,
  3573. .resume = iwl_pci_resume,
  3574. #endif
  3575. };
  3576. static int __init iwl3945_init(void)
  3577. {
  3578. int ret;
  3579. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3580. pr_info(DRV_COPYRIGHT "\n");
  3581. ret = iwl3945_rate_control_register();
  3582. if (ret) {
  3583. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3584. return ret;
  3585. }
  3586. ret = pci_register_driver(&iwl3945_driver);
  3587. if (ret) {
  3588. pr_err("Unable to initialize PCI module\n");
  3589. goto error_register;
  3590. }
  3591. return ret;
  3592. error_register:
  3593. iwl3945_rate_control_unregister();
  3594. return ret;
  3595. }
  3596. static void __exit iwl3945_exit(void)
  3597. {
  3598. pci_unregister_driver(&iwl3945_driver);
  3599. iwl3945_rate_control_unregister();
  3600. }
  3601. MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
  3602. module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO);
  3603. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  3604. module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO);
  3605. MODULE_PARM_DESC(swcrypto,
  3606. "using software crypto (default 1 [software])\n");
  3607. #ifdef CONFIG_IWLWIFI_DEBUG
  3608. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3609. MODULE_PARM_DESC(debug, "debug output mask");
  3610. #endif
  3611. module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan,
  3612. int, S_IRUGO);
  3613. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  3614. module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO);
  3615. MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
  3616. module_exit(iwl3945_exit);
  3617. module_init(iwl3945_init);