iwl3945-base.c 110 KB

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