iwl-agn.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409
  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/wireless.h>
  42. #include <linux/firmware.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_arp.h>
  45. #include <net/mac80211.h>
  46. #include <asm/div64.h>
  47. #define DRV_NAME "iwlagn"
  48. #include "iwl-eeprom.h"
  49. #include "iwl-dev.h"
  50. #include "iwl-core.h"
  51. #include "iwl-io.h"
  52. #include "iwl-helpers.h"
  53. #include "iwl-sta.h"
  54. #include "iwl-agn-calib.h"
  55. #include "iwl-agn.h"
  56. /******************************************************************************
  57. *
  58. * module boiler plate
  59. *
  60. ******************************************************************************/
  61. /*
  62. * module name, copyright, version, etc.
  63. */
  64. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  65. #ifdef CONFIG_IWLWIFI_DEBUG
  66. #define VD "d"
  67. #else
  68. #define VD
  69. #endif
  70. #define DRV_VERSION IWLWIFI_VERSION VD
  71. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  72. MODULE_VERSION(DRV_VERSION);
  73. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  74. MODULE_LICENSE("GPL");
  75. static int iwlagn_ant_coupling;
  76. static bool iwlagn_bt_ch_announce = 1;
  77. void iwl_update_chain_flags(struct iwl_priv *priv)
  78. {
  79. struct iwl_rxon_context *ctx;
  80. if (priv->cfg->ops->hcmd->set_rxon_chain) {
  81. for_each_context(priv, ctx) {
  82. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  83. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  84. iwlcore_commit_rxon(priv, ctx);
  85. }
  86. }
  87. }
  88. static void iwl_clear_free_frames(struct iwl_priv *priv)
  89. {
  90. struct list_head *element;
  91. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  92. priv->frames_count);
  93. while (!list_empty(&priv->free_frames)) {
  94. element = priv->free_frames.next;
  95. list_del(element);
  96. kfree(list_entry(element, struct iwl_frame, list));
  97. priv->frames_count--;
  98. }
  99. if (priv->frames_count) {
  100. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  101. priv->frames_count);
  102. priv->frames_count = 0;
  103. }
  104. }
  105. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  106. {
  107. struct iwl_frame *frame;
  108. struct list_head *element;
  109. if (list_empty(&priv->free_frames)) {
  110. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  111. if (!frame) {
  112. IWL_ERR(priv, "Could not allocate frame!\n");
  113. return NULL;
  114. }
  115. priv->frames_count++;
  116. return frame;
  117. }
  118. element = priv->free_frames.next;
  119. list_del(element);
  120. return list_entry(element, struct iwl_frame, list);
  121. }
  122. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  123. {
  124. memset(frame, 0, sizeof(*frame));
  125. list_add(&frame->list, &priv->free_frames);
  126. }
  127. static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
  128. struct ieee80211_hdr *hdr,
  129. int left)
  130. {
  131. lockdep_assert_held(&priv->mutex);
  132. if (!priv->beacon_skb)
  133. return 0;
  134. if (priv->beacon_skb->len > left)
  135. return 0;
  136. memcpy(hdr, priv->beacon_skb->data, priv->beacon_skb->len);
  137. return priv->beacon_skb->len;
  138. }
  139. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  140. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  141. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  142. u8 *beacon, u32 frame_size)
  143. {
  144. u16 tim_idx;
  145. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  146. /*
  147. * The index is relative to frame start but we start looking at the
  148. * variable-length part of the beacon.
  149. */
  150. tim_idx = mgmt->u.beacon.variable - beacon;
  151. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  152. while ((tim_idx < (frame_size - 2)) &&
  153. (beacon[tim_idx] != WLAN_EID_TIM))
  154. tim_idx += beacon[tim_idx+1] + 2;
  155. /* If TIM field was found, set variables */
  156. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  157. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  158. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  159. } else
  160. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  161. }
  162. static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
  163. struct iwl_frame *frame)
  164. {
  165. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  166. u32 frame_size;
  167. u32 rate_flags;
  168. u32 rate;
  169. /*
  170. * We have to set up the TX command, the TX Beacon command, and the
  171. * beacon contents.
  172. */
  173. lockdep_assert_held(&priv->mutex);
  174. if (!priv->beacon_ctx) {
  175. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  176. return 0;
  177. }
  178. /* Initialize memory */
  179. tx_beacon_cmd = &frame->u.beacon;
  180. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  181. /* Set up TX beacon contents */
  182. frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
  183. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  184. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  185. return 0;
  186. if (!frame_size)
  187. return 0;
  188. /* Set up TX command fields */
  189. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  190. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  191. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  192. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  193. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  194. /* Set up TX beacon command fields */
  195. iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
  196. frame_size);
  197. /* Set up packet rate and flags */
  198. rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx);
  199. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  200. priv->hw_params.valid_tx_ant);
  201. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  202. if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
  203. rate_flags |= RATE_MCS_CCK_MSK;
  204. tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
  205. rate_flags);
  206. return sizeof(*tx_beacon_cmd) + frame_size;
  207. }
  208. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  209. {
  210. struct iwl_frame *frame;
  211. unsigned int frame_size;
  212. int rc;
  213. struct iwl_host_cmd cmd = {
  214. .id = REPLY_TX_BEACON,
  215. .flags = CMD_SIZE_HUGE,
  216. };
  217. frame = iwl_get_free_frame(priv);
  218. if (!frame) {
  219. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  220. "command.\n");
  221. return -ENOMEM;
  222. }
  223. frame_size = iwl_hw_get_beacon_cmd(priv, frame);
  224. if (!frame_size) {
  225. IWL_ERR(priv, "Error configuring the beacon command\n");
  226. iwl_free_frame(priv, frame);
  227. return -EINVAL;
  228. }
  229. cmd.len = frame_size;
  230. cmd.data = &frame->u.cmd[0];
  231. rc = iwl_send_cmd_sync(priv, &cmd);
  232. iwl_free_frame(priv, frame);
  233. return rc;
  234. }
  235. static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
  236. {
  237. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  238. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  239. if (sizeof(dma_addr_t) > sizeof(u32))
  240. addr |=
  241. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  242. return addr;
  243. }
  244. static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  245. {
  246. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  247. return le16_to_cpu(tb->hi_n_len) >> 4;
  248. }
  249. static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
  250. dma_addr_t addr, u16 len)
  251. {
  252. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  253. u16 hi_n_len = len << 4;
  254. put_unaligned_le32(addr, &tb->lo);
  255. if (sizeof(dma_addr_t) > sizeof(u32))
  256. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  257. tb->hi_n_len = cpu_to_le16(hi_n_len);
  258. tfd->num_tbs = idx + 1;
  259. }
  260. static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
  261. {
  262. return tfd->num_tbs & 0x1f;
  263. }
  264. /**
  265. * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  266. * @priv - driver private data
  267. * @txq - tx queue
  268. *
  269. * Does NOT advance any TFD circular buffer read/write indexes
  270. * Does NOT free the TFD itself (which is within circular buffer)
  271. */
  272. void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  273. {
  274. struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
  275. struct iwl_tfd *tfd;
  276. struct pci_dev *dev = priv->pci_dev;
  277. int index = txq->q.read_ptr;
  278. int i;
  279. int num_tbs;
  280. tfd = &tfd_tmp[index];
  281. /* Sanity check on number of chunks */
  282. num_tbs = iwl_tfd_get_num_tbs(tfd);
  283. if (num_tbs >= IWL_NUM_OF_TBS) {
  284. IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
  285. /* @todo issue fatal error, it is quite serious situation */
  286. return;
  287. }
  288. /* Unmap tx_cmd */
  289. if (num_tbs)
  290. pci_unmap_single(dev,
  291. dma_unmap_addr(&txq->meta[index], mapping),
  292. dma_unmap_len(&txq->meta[index], len),
  293. PCI_DMA_BIDIRECTIONAL);
  294. /* Unmap chunks, if any. */
  295. for (i = 1; i < num_tbs; i++)
  296. pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
  297. iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
  298. /* free SKB */
  299. if (txq->txb) {
  300. struct sk_buff *skb;
  301. skb = txq->txb[txq->q.read_ptr].skb;
  302. /* can be called from irqs-disabled context */
  303. if (skb) {
  304. dev_kfree_skb_any(skb);
  305. txq->txb[txq->q.read_ptr].skb = NULL;
  306. }
  307. }
  308. }
  309. int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
  310. struct iwl_tx_queue *txq,
  311. dma_addr_t addr, u16 len,
  312. u8 reset, u8 pad)
  313. {
  314. struct iwl_queue *q;
  315. struct iwl_tfd *tfd, *tfd_tmp;
  316. u32 num_tbs;
  317. q = &txq->q;
  318. tfd_tmp = (struct iwl_tfd *)txq->tfds;
  319. tfd = &tfd_tmp[q->write_ptr];
  320. if (reset)
  321. memset(tfd, 0, sizeof(*tfd));
  322. num_tbs = iwl_tfd_get_num_tbs(tfd);
  323. /* Each TFD can point to a maximum 20 Tx buffers */
  324. if (num_tbs >= IWL_NUM_OF_TBS) {
  325. IWL_ERR(priv, "Error can not send more than %d chunks\n",
  326. IWL_NUM_OF_TBS);
  327. return -EINVAL;
  328. }
  329. if (WARN_ON(addr & ~DMA_BIT_MASK(36)))
  330. return -EINVAL;
  331. if (unlikely(addr & ~IWL_TX_DMA_MASK))
  332. IWL_ERR(priv, "Unaligned address = %llx\n",
  333. (unsigned long long)addr);
  334. iwl_tfd_set_tb(tfd, num_tbs, addr, len);
  335. return 0;
  336. }
  337. /*
  338. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  339. * given Tx queue, and enable the DMA channel used for that queue.
  340. *
  341. * supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  342. * channels supported in hardware.
  343. */
  344. int iwl_hw_tx_queue_init(struct iwl_priv *priv,
  345. struct iwl_tx_queue *txq)
  346. {
  347. int txq_id = txq->q.id;
  348. /* Circular buffer (TFD queue in DRAM) physical base address */
  349. iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  350. txq->q.dma_addr >> 8);
  351. return 0;
  352. }
  353. static void iwl_bg_beacon_update(struct work_struct *work)
  354. {
  355. struct iwl_priv *priv =
  356. container_of(work, struct iwl_priv, beacon_update);
  357. struct sk_buff *beacon;
  358. mutex_lock(&priv->mutex);
  359. if (!priv->beacon_ctx) {
  360. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  361. goto out;
  362. }
  363. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  364. /*
  365. * The ucode will send beacon notifications even in
  366. * IBSS mode, but we don't want to process them. But
  367. * we need to defer the type check to here due to
  368. * requiring locking around the beacon_ctx access.
  369. */
  370. goto out;
  371. }
  372. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  373. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  374. if (!beacon) {
  375. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  376. goto out;
  377. }
  378. /* new beacon skb is allocated every time; dispose previous.*/
  379. dev_kfree_skb(priv->beacon_skb);
  380. priv->beacon_skb = beacon;
  381. iwlagn_send_beacon_cmd(priv);
  382. out:
  383. mutex_unlock(&priv->mutex);
  384. }
  385. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  386. {
  387. struct iwl_priv *priv =
  388. container_of(work, struct iwl_priv, bt_runtime_config);
  389. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  390. return;
  391. /* dont send host command if rf-kill is on */
  392. if (!iwl_is_ready_rf(priv))
  393. return;
  394. priv->cfg->ops->hcmd->send_bt_config(priv);
  395. }
  396. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  397. {
  398. struct iwl_priv *priv =
  399. container_of(work, struct iwl_priv, bt_full_concurrency);
  400. struct iwl_rxon_context *ctx;
  401. mutex_lock(&priv->mutex);
  402. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  403. goto out;
  404. /* dont send host command if rf-kill is on */
  405. if (!iwl_is_ready_rf(priv))
  406. goto out;
  407. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  408. priv->bt_full_concurrent ?
  409. "full concurrency" : "3-wire");
  410. /*
  411. * LQ & RXON updated cmds must be sent before BT Config cmd
  412. * to avoid 3-wire collisions
  413. */
  414. for_each_context(priv, ctx) {
  415. if (priv->cfg->ops->hcmd->set_rxon_chain)
  416. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  417. iwlcore_commit_rxon(priv, ctx);
  418. }
  419. priv->cfg->ops->hcmd->send_bt_config(priv);
  420. out:
  421. mutex_unlock(&priv->mutex);
  422. }
  423. /**
  424. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  425. *
  426. * This callback is provided in order to send a statistics request.
  427. *
  428. * This timer function is continually reset to execute within
  429. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  430. * was received. We need to ensure we receive the statistics in order
  431. * to update the temperature used for calibrating the TXPOWER.
  432. */
  433. static void iwl_bg_statistics_periodic(unsigned long data)
  434. {
  435. struct iwl_priv *priv = (struct iwl_priv *)data;
  436. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  437. return;
  438. /* dont send host command if rf-kill is on */
  439. if (!iwl_is_ready_rf(priv))
  440. return;
  441. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  442. }
  443. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  444. u32 start_idx, u32 num_events,
  445. u32 mode)
  446. {
  447. u32 i;
  448. u32 ptr; /* SRAM byte address of log data */
  449. u32 ev, time, data; /* event log data */
  450. unsigned long reg_flags;
  451. if (mode == 0)
  452. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  453. else
  454. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  455. /* Make sure device is powered up for SRAM reads */
  456. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  457. if (iwl_grab_nic_access(priv)) {
  458. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  459. return;
  460. }
  461. /* Set starting address; reads will auto-increment */
  462. iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
  463. rmb();
  464. /*
  465. * "time" is actually "data" for mode 0 (no timestamp).
  466. * place event id # at far right for easier visual parsing.
  467. */
  468. for (i = 0; i < num_events; i++) {
  469. ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  470. time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  471. if (mode == 0) {
  472. trace_iwlwifi_dev_ucode_cont_event(priv,
  473. 0, time, ev);
  474. } else {
  475. data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  476. trace_iwlwifi_dev_ucode_cont_event(priv,
  477. time, data, ev);
  478. }
  479. }
  480. /* Allow device to power down */
  481. iwl_release_nic_access(priv);
  482. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  483. }
  484. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  485. {
  486. u32 capacity; /* event log capacity in # entries */
  487. u32 base; /* SRAM byte address of event log header */
  488. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  489. u32 num_wraps; /* # times uCode wrapped to top of log */
  490. u32 next_entry; /* index of next entry to be written by uCode */
  491. base = priv->device_pointers.error_event_table;
  492. if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  493. capacity = iwl_read_targ_mem(priv, base);
  494. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  495. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  496. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  497. } else
  498. return;
  499. if (num_wraps == priv->event_log.num_wraps) {
  500. iwl_print_cont_event_trace(priv,
  501. base, priv->event_log.next_entry,
  502. next_entry - priv->event_log.next_entry,
  503. mode);
  504. priv->event_log.non_wraps_count++;
  505. } else {
  506. if ((num_wraps - priv->event_log.num_wraps) > 1)
  507. priv->event_log.wraps_more_count++;
  508. else
  509. priv->event_log.wraps_once_count++;
  510. trace_iwlwifi_dev_ucode_wrap_event(priv,
  511. num_wraps - priv->event_log.num_wraps,
  512. next_entry, priv->event_log.next_entry);
  513. if (next_entry < priv->event_log.next_entry) {
  514. iwl_print_cont_event_trace(priv, base,
  515. priv->event_log.next_entry,
  516. capacity - priv->event_log.next_entry,
  517. mode);
  518. iwl_print_cont_event_trace(priv, base, 0,
  519. next_entry, mode);
  520. } else {
  521. iwl_print_cont_event_trace(priv, base,
  522. next_entry, capacity - next_entry,
  523. mode);
  524. iwl_print_cont_event_trace(priv, base, 0,
  525. next_entry, mode);
  526. }
  527. }
  528. priv->event_log.num_wraps = num_wraps;
  529. priv->event_log.next_entry = next_entry;
  530. }
  531. /**
  532. * iwl_bg_ucode_trace - Timer callback to log ucode event
  533. *
  534. * The timer is continually set to execute every
  535. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  536. * this function is to perform continuous uCode event logging operation
  537. * if enabled
  538. */
  539. static void iwl_bg_ucode_trace(unsigned long data)
  540. {
  541. struct iwl_priv *priv = (struct iwl_priv *)data;
  542. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  543. return;
  544. if (priv->event_log.ucode_trace) {
  545. iwl_continuous_event_trace(priv);
  546. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  547. mod_timer(&priv->ucode_trace,
  548. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  549. }
  550. }
  551. static void iwl_bg_tx_flush(struct work_struct *work)
  552. {
  553. struct iwl_priv *priv =
  554. container_of(work, struct iwl_priv, tx_flush);
  555. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  556. return;
  557. /* do nothing if rf-kill is on */
  558. if (!iwl_is_ready_rf(priv))
  559. return;
  560. if (priv->cfg->ops->lib->txfifo_flush) {
  561. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  562. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  563. }
  564. }
  565. /**
  566. * iwl_rx_handle - Main entry function for receiving responses from uCode
  567. *
  568. * Uses the priv->rx_handlers callback function array to invoke
  569. * the appropriate handlers, including command responses,
  570. * frame-received notifications, and other notifications.
  571. */
  572. static void iwl_rx_handle(struct iwl_priv *priv)
  573. {
  574. struct iwl_rx_mem_buffer *rxb;
  575. struct iwl_rx_packet *pkt;
  576. struct iwl_rx_queue *rxq = &priv->rxq;
  577. u32 r, i;
  578. int reclaim;
  579. unsigned long flags;
  580. u8 fill_rx = 0;
  581. u32 count = 8;
  582. int total_empty;
  583. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  584. * buffer that the driver may process (last buffer filled by ucode). */
  585. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  586. i = rxq->read;
  587. /* Rx interrupt, but nothing sent from uCode */
  588. if (i == r)
  589. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  590. /* calculate total frames need to be restock after handling RX */
  591. total_empty = r - rxq->write_actual;
  592. if (total_empty < 0)
  593. total_empty += RX_QUEUE_SIZE;
  594. if (total_empty > (RX_QUEUE_SIZE / 2))
  595. fill_rx = 1;
  596. while (i != r) {
  597. int len;
  598. rxb = rxq->queue[i];
  599. /* If an RXB doesn't have a Rx queue slot associated with it,
  600. * then a bug has been introduced in the queue refilling
  601. * routines -- catch it here */
  602. if (WARN_ON(rxb == NULL)) {
  603. i = (i + 1) & RX_QUEUE_MASK;
  604. continue;
  605. }
  606. rxq->queue[i] = NULL;
  607. pci_unmap_page(priv->pci_dev, rxb->page_dma,
  608. PAGE_SIZE << priv->hw_params.rx_page_order,
  609. PCI_DMA_FROMDEVICE);
  610. pkt = rxb_addr(rxb);
  611. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  612. len += sizeof(u32); /* account for status word */
  613. trace_iwlwifi_dev_rx(priv, pkt, len);
  614. /* Reclaim a command buffer only if this packet is a response
  615. * to a (driver-originated) command.
  616. * If the packet (e.g. Rx frame) originated from uCode,
  617. * there is no command buffer to reclaim.
  618. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  619. * but apparently a few don't get set; catch them here. */
  620. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  621. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  622. (pkt->hdr.cmd != REPLY_RX) &&
  623. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  624. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  625. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  626. (pkt->hdr.cmd != REPLY_TX);
  627. /*
  628. * Do the notification wait before RX handlers so
  629. * even if the RX handler consumes the RXB we have
  630. * access to it in the notification wait entry.
  631. */
  632. if (!list_empty(&priv->_agn.notif_waits)) {
  633. struct iwl_notification_wait *w;
  634. spin_lock(&priv->_agn.notif_wait_lock);
  635. list_for_each_entry(w, &priv->_agn.notif_waits, list) {
  636. if (w->cmd == pkt->hdr.cmd) {
  637. w->triggered = true;
  638. if (w->fn)
  639. w->fn(priv, pkt);
  640. }
  641. }
  642. spin_unlock(&priv->_agn.notif_wait_lock);
  643. wake_up_all(&priv->_agn.notif_waitq);
  644. }
  645. /* Based on type of command response or notification,
  646. * handle those that need handling via function in
  647. * rx_handlers table. See iwl_setup_rx_handlers() */
  648. if (priv->rx_handlers[pkt->hdr.cmd]) {
  649. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
  650. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  651. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  652. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  653. } else {
  654. /* No handling needed */
  655. IWL_DEBUG_RX(priv,
  656. "r %d i %d No handler needed for %s, 0x%02x\n",
  657. r, i, get_cmd_string(pkt->hdr.cmd),
  658. pkt->hdr.cmd);
  659. }
  660. /*
  661. * XXX: After here, we should always check rxb->page
  662. * against NULL before touching it or its virtual
  663. * memory (pkt). Because some rx_handler might have
  664. * already taken or freed the pages.
  665. */
  666. if (reclaim) {
  667. /* Invoke any callbacks, transfer the buffer to caller,
  668. * and fire off the (possibly) blocking iwl_send_cmd()
  669. * as we reclaim the driver command queue */
  670. if (rxb->page)
  671. iwl_tx_cmd_complete(priv, rxb);
  672. else
  673. IWL_WARN(priv, "Claim null rxb?\n");
  674. }
  675. /* Reuse the page if possible. For notification packets and
  676. * SKBs that fail to Rx correctly, add them back into the
  677. * rx_free list for reuse later. */
  678. spin_lock_irqsave(&rxq->lock, flags);
  679. if (rxb->page != NULL) {
  680. rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
  681. 0, PAGE_SIZE << priv->hw_params.rx_page_order,
  682. PCI_DMA_FROMDEVICE);
  683. list_add_tail(&rxb->list, &rxq->rx_free);
  684. rxq->free_count++;
  685. } else
  686. list_add_tail(&rxb->list, &rxq->rx_used);
  687. spin_unlock_irqrestore(&rxq->lock, flags);
  688. i = (i + 1) & RX_QUEUE_MASK;
  689. /* If there are a lot of unused frames,
  690. * restock the Rx queue so ucode wont assert. */
  691. if (fill_rx) {
  692. count++;
  693. if (count >= 8) {
  694. rxq->read = i;
  695. iwlagn_rx_replenish_now(priv);
  696. count = 0;
  697. }
  698. }
  699. }
  700. /* Backtrack one entry */
  701. rxq->read = i;
  702. if (fill_rx)
  703. iwlagn_rx_replenish_now(priv);
  704. else
  705. iwlagn_rx_queue_restock(priv);
  706. }
  707. /* call this function to flush any scheduled tasklet */
  708. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  709. {
  710. /* wait to make sure we flush pending tasklet*/
  711. synchronize_irq(priv->pci_dev->irq);
  712. tasklet_kill(&priv->irq_tasklet);
  713. }
  714. /* tasklet for iwlagn interrupt */
  715. static void iwl_irq_tasklet(struct iwl_priv *priv)
  716. {
  717. u32 inta = 0;
  718. u32 handled = 0;
  719. unsigned long flags;
  720. u32 i;
  721. #ifdef CONFIG_IWLWIFI_DEBUG
  722. u32 inta_mask;
  723. #endif
  724. spin_lock_irqsave(&priv->lock, flags);
  725. /* Ack/clear/reset pending uCode interrupts.
  726. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  727. */
  728. /* There is a hardware bug in the interrupt mask function that some
  729. * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
  730. * they are disabled in the CSR_INT_MASK register. Furthermore the
  731. * ICT interrupt handling mechanism has another bug that might cause
  732. * these unmasked interrupts fail to be detected. We workaround the
  733. * hardware bugs here by ACKing all the possible interrupts so that
  734. * interrupt coalescing can still be achieved.
  735. */
  736. iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
  737. inta = priv->_agn.inta;
  738. #ifdef CONFIG_IWLWIFI_DEBUG
  739. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  740. /* just for debug */
  741. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  742. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
  743. inta, inta_mask);
  744. }
  745. #endif
  746. spin_unlock_irqrestore(&priv->lock, flags);
  747. /* saved interrupt in inta variable now we can reset priv->_agn.inta */
  748. priv->_agn.inta = 0;
  749. /* Now service all interrupt bits discovered above. */
  750. if (inta & CSR_INT_BIT_HW_ERR) {
  751. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  752. /* Tell the device to stop sending interrupts */
  753. iwl_disable_interrupts(priv);
  754. priv->isr_stats.hw++;
  755. iwl_irq_handle_error(priv);
  756. handled |= CSR_INT_BIT_HW_ERR;
  757. return;
  758. }
  759. #ifdef CONFIG_IWLWIFI_DEBUG
  760. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  761. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  762. if (inta & CSR_INT_BIT_SCD) {
  763. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  764. "the frame/frames.\n");
  765. priv->isr_stats.sch++;
  766. }
  767. /* Alive notification via Rx interrupt will do the real work */
  768. if (inta & CSR_INT_BIT_ALIVE) {
  769. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  770. priv->isr_stats.alive++;
  771. }
  772. }
  773. #endif
  774. /* Safely ignore these bits for debug checks below */
  775. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  776. /* HW RF KILL switch toggled */
  777. if (inta & CSR_INT_BIT_RF_KILL) {
  778. int hw_rf_kill = 0;
  779. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  780. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  781. hw_rf_kill = 1;
  782. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  783. hw_rf_kill ? "disable radio" : "enable radio");
  784. priv->isr_stats.rfkill++;
  785. /* driver only loads ucode once setting the interface up.
  786. * the driver allows loading the ucode even if the radio
  787. * is killed. Hence update the killswitch state here. The
  788. * rfkill handler will care about restarting if needed.
  789. */
  790. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  791. if (hw_rf_kill)
  792. set_bit(STATUS_RF_KILL_HW, &priv->status);
  793. else
  794. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  795. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  796. }
  797. handled |= CSR_INT_BIT_RF_KILL;
  798. }
  799. /* Chip got too hot and stopped itself */
  800. if (inta & CSR_INT_BIT_CT_KILL) {
  801. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  802. priv->isr_stats.ctkill++;
  803. handled |= CSR_INT_BIT_CT_KILL;
  804. }
  805. /* Error detected by uCode */
  806. if (inta & CSR_INT_BIT_SW_ERR) {
  807. IWL_ERR(priv, "Microcode SW error detected. "
  808. " Restarting 0x%X.\n", inta);
  809. priv->isr_stats.sw++;
  810. iwl_irq_handle_error(priv);
  811. handled |= CSR_INT_BIT_SW_ERR;
  812. }
  813. /* uCode wakes up after power-down sleep */
  814. if (inta & CSR_INT_BIT_WAKEUP) {
  815. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  816. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  817. for (i = 0; i < priv->hw_params.max_txq_num; i++)
  818. iwl_txq_update_write_ptr(priv, &priv->txq[i]);
  819. priv->isr_stats.wakeup++;
  820. handled |= CSR_INT_BIT_WAKEUP;
  821. }
  822. /* All uCode command responses, including Tx command responses,
  823. * Rx "responses" (frame-received notification), and other
  824. * notifications from uCode come through here*/
  825. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
  826. CSR_INT_BIT_RX_PERIODIC)) {
  827. IWL_DEBUG_ISR(priv, "Rx interrupt\n");
  828. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  829. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  830. iwl_write32(priv, CSR_FH_INT_STATUS,
  831. CSR_FH_INT_RX_MASK);
  832. }
  833. if (inta & CSR_INT_BIT_RX_PERIODIC) {
  834. handled |= CSR_INT_BIT_RX_PERIODIC;
  835. iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
  836. }
  837. /* Sending RX interrupt require many steps to be done in the
  838. * the device:
  839. * 1- write interrupt to current index in ICT table.
  840. * 2- dma RX frame.
  841. * 3- update RX shared data to indicate last write index.
  842. * 4- send interrupt.
  843. * This could lead to RX race, driver could receive RX interrupt
  844. * but the shared data changes does not reflect this;
  845. * periodic interrupt will detect any dangling Rx activity.
  846. */
  847. /* Disable periodic interrupt; we use it as just a one-shot. */
  848. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  849. CSR_INT_PERIODIC_DIS);
  850. iwl_rx_handle(priv);
  851. /*
  852. * Enable periodic interrupt in 8 msec only if we received
  853. * real RX interrupt (instead of just periodic int), to catch
  854. * any dangling Rx interrupt. If it was just the periodic
  855. * interrupt, there was no dangling Rx activity, and no need
  856. * to extend the periodic interrupt; one-shot is enough.
  857. */
  858. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
  859. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  860. CSR_INT_PERIODIC_ENA);
  861. priv->isr_stats.rx++;
  862. }
  863. /* This "Tx" DMA channel is used only for loading uCode */
  864. if (inta & CSR_INT_BIT_FH_TX) {
  865. iwl_write32(priv, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
  866. IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
  867. priv->isr_stats.tx++;
  868. handled |= CSR_INT_BIT_FH_TX;
  869. /* Wake up uCode load routine, now that load is complete */
  870. priv->ucode_write_complete = 1;
  871. wake_up_interruptible(&priv->wait_command_queue);
  872. }
  873. if (inta & ~handled) {
  874. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  875. priv->isr_stats.unhandled++;
  876. }
  877. if (inta & ~(priv->inta_mask)) {
  878. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  879. inta & ~priv->inta_mask);
  880. }
  881. /* Re-enable all interrupts */
  882. /* only Re-enable if disabled by irq */
  883. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  884. iwl_enable_interrupts(priv);
  885. /* Re-enable RF_KILL if it occurred */
  886. else if (handled & CSR_INT_BIT_RF_KILL)
  887. iwl_enable_rfkill_int(priv);
  888. }
  889. /*****************************************************************************
  890. *
  891. * sysfs attributes
  892. *
  893. *****************************************************************************/
  894. #ifdef CONFIG_IWLWIFI_DEBUG
  895. /*
  896. * The following adds a new attribute to the sysfs representation
  897. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  898. * used for controlling the debug level.
  899. *
  900. * See the level definitions in iwl for details.
  901. *
  902. * The debug_level being managed using sysfs below is a per device debug
  903. * level that is used instead of the global debug level if it (the per
  904. * device debug level) is set.
  905. */
  906. static ssize_t show_debug_level(struct device *d,
  907. struct device_attribute *attr, char *buf)
  908. {
  909. struct iwl_priv *priv = dev_get_drvdata(d);
  910. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  911. }
  912. static ssize_t store_debug_level(struct device *d,
  913. struct device_attribute *attr,
  914. const char *buf, size_t count)
  915. {
  916. struct iwl_priv *priv = dev_get_drvdata(d);
  917. unsigned long val;
  918. int ret;
  919. ret = strict_strtoul(buf, 0, &val);
  920. if (ret)
  921. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  922. else {
  923. priv->debug_level = val;
  924. if (iwl_alloc_traffic_mem(priv))
  925. IWL_ERR(priv,
  926. "Not enough memory to generate traffic log\n");
  927. }
  928. return strnlen(buf, count);
  929. }
  930. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  931. show_debug_level, store_debug_level);
  932. #endif /* CONFIG_IWLWIFI_DEBUG */
  933. static ssize_t show_temperature(struct device *d,
  934. struct device_attribute *attr, char *buf)
  935. {
  936. struct iwl_priv *priv = dev_get_drvdata(d);
  937. if (!iwl_is_alive(priv))
  938. return -EAGAIN;
  939. return sprintf(buf, "%d\n", priv->temperature);
  940. }
  941. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  942. static ssize_t show_tx_power(struct device *d,
  943. struct device_attribute *attr, char *buf)
  944. {
  945. struct iwl_priv *priv = dev_get_drvdata(d);
  946. if (!iwl_is_ready_rf(priv))
  947. return sprintf(buf, "off\n");
  948. else
  949. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  950. }
  951. static ssize_t store_tx_power(struct device *d,
  952. struct device_attribute *attr,
  953. const char *buf, size_t count)
  954. {
  955. struct iwl_priv *priv = dev_get_drvdata(d);
  956. unsigned long val;
  957. int ret;
  958. ret = strict_strtoul(buf, 10, &val);
  959. if (ret)
  960. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  961. else {
  962. ret = iwl_set_tx_power(priv, val, false);
  963. if (ret)
  964. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  965. ret);
  966. else
  967. ret = count;
  968. }
  969. return ret;
  970. }
  971. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  972. static struct attribute *iwl_sysfs_entries[] = {
  973. &dev_attr_temperature.attr,
  974. &dev_attr_tx_power.attr,
  975. #ifdef CONFIG_IWLWIFI_DEBUG
  976. &dev_attr_debug_level.attr,
  977. #endif
  978. NULL
  979. };
  980. static struct attribute_group iwl_attribute_group = {
  981. .name = NULL, /* put in device directory */
  982. .attrs = iwl_sysfs_entries,
  983. };
  984. /******************************************************************************
  985. *
  986. * uCode download functions
  987. *
  988. ******************************************************************************/
  989. static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
  990. {
  991. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  992. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  993. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  994. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  995. }
  996. static void iwl_nic_start(struct iwl_priv *priv)
  997. {
  998. /* Remove all resets to allow NIC to operate */
  999. iwl_write32(priv, CSR_RESET, 0);
  1000. }
  1001. struct iwlagn_ucode_capabilities {
  1002. u32 max_probe_length;
  1003. u32 standard_phy_calibration_size;
  1004. u32 flags;
  1005. };
  1006. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  1007. static int iwl_mac_setup_register(struct iwl_priv *priv,
  1008. struct iwlagn_ucode_capabilities *capa);
  1009. #define UCODE_EXPERIMENTAL_INDEX 100
  1010. #define UCODE_EXPERIMENTAL_TAG "exp"
  1011. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  1012. {
  1013. const char *name_pre = priv->cfg->fw_name_pre;
  1014. char tag[8];
  1015. if (first) {
  1016. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  1017. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  1018. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  1019. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  1020. #endif
  1021. priv->fw_index = priv->cfg->ucode_api_max;
  1022. sprintf(tag, "%d", priv->fw_index);
  1023. } else {
  1024. priv->fw_index--;
  1025. sprintf(tag, "%d", priv->fw_index);
  1026. }
  1027. if (priv->fw_index < priv->cfg->ucode_api_min) {
  1028. IWL_ERR(priv, "no suitable firmware found!\n");
  1029. return -ENOENT;
  1030. }
  1031. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  1032. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  1033. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1034. ? "EXPERIMENTAL " : "",
  1035. priv->firmware_name);
  1036. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  1037. &priv->pci_dev->dev, GFP_KERNEL, priv,
  1038. iwl_ucode_callback);
  1039. }
  1040. struct iwlagn_firmware_pieces {
  1041. const void *inst, *data, *init, *init_data;
  1042. size_t inst_size, data_size, init_size, init_data_size;
  1043. u32 build;
  1044. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1045. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1046. };
  1047. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  1048. const struct firmware *ucode_raw,
  1049. struct iwlagn_firmware_pieces *pieces)
  1050. {
  1051. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  1052. u32 api_ver, hdr_size;
  1053. const u8 *src;
  1054. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1055. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1056. switch (api_ver) {
  1057. default:
  1058. hdr_size = 28;
  1059. if (ucode_raw->size < hdr_size) {
  1060. IWL_ERR(priv, "File size too small!\n");
  1061. return -EINVAL;
  1062. }
  1063. pieces->build = le32_to_cpu(ucode->u.v2.build);
  1064. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  1065. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  1066. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  1067. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  1068. src = ucode->u.v2.data;
  1069. break;
  1070. case 0:
  1071. case 1:
  1072. case 2:
  1073. hdr_size = 24;
  1074. if (ucode_raw->size < hdr_size) {
  1075. IWL_ERR(priv, "File size too small!\n");
  1076. return -EINVAL;
  1077. }
  1078. pieces->build = 0;
  1079. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  1080. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  1081. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  1082. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  1083. src = ucode->u.v1.data;
  1084. break;
  1085. }
  1086. /* Verify size of file vs. image size info in file's header */
  1087. if (ucode_raw->size != hdr_size + pieces->inst_size +
  1088. pieces->data_size + pieces->init_size +
  1089. pieces->init_data_size) {
  1090. IWL_ERR(priv,
  1091. "uCode file size %d does not match expected size\n",
  1092. (int)ucode_raw->size);
  1093. return -EINVAL;
  1094. }
  1095. pieces->inst = src;
  1096. src += pieces->inst_size;
  1097. pieces->data = src;
  1098. src += pieces->data_size;
  1099. pieces->init = src;
  1100. src += pieces->init_size;
  1101. pieces->init_data = src;
  1102. src += pieces->init_data_size;
  1103. return 0;
  1104. }
  1105. static int iwlagn_wanted_ucode_alternative = 1;
  1106. static int iwlagn_load_firmware(struct iwl_priv *priv,
  1107. const struct firmware *ucode_raw,
  1108. struct iwlagn_firmware_pieces *pieces,
  1109. struct iwlagn_ucode_capabilities *capa)
  1110. {
  1111. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  1112. struct iwl_ucode_tlv *tlv;
  1113. size_t len = ucode_raw->size;
  1114. const u8 *data;
  1115. int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
  1116. u64 alternatives;
  1117. u32 tlv_len;
  1118. enum iwl_ucode_tlv_type tlv_type;
  1119. const u8 *tlv_data;
  1120. if (len < sizeof(*ucode)) {
  1121. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  1122. return -EINVAL;
  1123. }
  1124. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  1125. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  1126. le32_to_cpu(ucode->magic));
  1127. return -EINVAL;
  1128. }
  1129. /*
  1130. * Check which alternatives are present, and "downgrade"
  1131. * when the chosen alternative is not present, warning
  1132. * the user when that happens. Some files may not have
  1133. * any alternatives, so don't warn in that case.
  1134. */
  1135. alternatives = le64_to_cpu(ucode->alternatives);
  1136. tmp = wanted_alternative;
  1137. if (wanted_alternative > 63)
  1138. wanted_alternative = 63;
  1139. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  1140. wanted_alternative--;
  1141. if (wanted_alternative && wanted_alternative != tmp)
  1142. IWL_WARN(priv,
  1143. "uCode alternative %d not available, choosing %d\n",
  1144. tmp, wanted_alternative);
  1145. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1146. pieces->build = le32_to_cpu(ucode->build);
  1147. data = ucode->data;
  1148. len -= sizeof(*ucode);
  1149. while (len >= sizeof(*tlv)) {
  1150. u16 tlv_alt;
  1151. len -= sizeof(*tlv);
  1152. tlv = (void *)data;
  1153. tlv_len = le32_to_cpu(tlv->length);
  1154. tlv_type = le16_to_cpu(tlv->type);
  1155. tlv_alt = le16_to_cpu(tlv->alternative);
  1156. tlv_data = tlv->data;
  1157. if (len < tlv_len) {
  1158. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  1159. len, tlv_len);
  1160. return -EINVAL;
  1161. }
  1162. len -= ALIGN(tlv_len, 4);
  1163. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  1164. /*
  1165. * Alternative 0 is always valid.
  1166. *
  1167. * Skip alternative TLVs that are not selected.
  1168. */
  1169. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  1170. continue;
  1171. switch (tlv_type) {
  1172. case IWL_UCODE_TLV_INST:
  1173. pieces->inst = tlv_data;
  1174. pieces->inst_size = tlv_len;
  1175. break;
  1176. case IWL_UCODE_TLV_DATA:
  1177. pieces->data = tlv_data;
  1178. pieces->data_size = tlv_len;
  1179. break;
  1180. case IWL_UCODE_TLV_INIT:
  1181. pieces->init = tlv_data;
  1182. pieces->init_size = tlv_len;
  1183. break;
  1184. case IWL_UCODE_TLV_INIT_DATA:
  1185. pieces->init_data = tlv_data;
  1186. pieces->init_data_size = tlv_len;
  1187. break;
  1188. case IWL_UCODE_TLV_BOOT:
  1189. IWL_ERR(priv, "Found unexpected BOOT ucode\n");
  1190. break;
  1191. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  1192. if (tlv_len != sizeof(u32))
  1193. goto invalid_tlv_len;
  1194. capa->max_probe_length =
  1195. le32_to_cpup((__le32 *)tlv_data);
  1196. break;
  1197. case IWL_UCODE_TLV_PAN:
  1198. if (tlv_len)
  1199. goto invalid_tlv_len;
  1200. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  1201. break;
  1202. case IWL_UCODE_TLV_FLAGS:
  1203. /* must be at least one u32 */
  1204. if (tlv_len < sizeof(u32))
  1205. goto invalid_tlv_len;
  1206. /* and a proper number of u32s */
  1207. if (tlv_len % sizeof(u32))
  1208. goto invalid_tlv_len;
  1209. /*
  1210. * This driver only reads the first u32 as
  1211. * right now no more features are defined,
  1212. * if that changes then either the driver
  1213. * will not work with the new firmware, or
  1214. * it'll not take advantage of new features.
  1215. */
  1216. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  1217. break;
  1218. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  1219. if (tlv_len != sizeof(u32))
  1220. goto invalid_tlv_len;
  1221. pieces->init_evtlog_ptr =
  1222. le32_to_cpup((__le32 *)tlv_data);
  1223. break;
  1224. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  1225. if (tlv_len != sizeof(u32))
  1226. goto invalid_tlv_len;
  1227. pieces->init_evtlog_size =
  1228. le32_to_cpup((__le32 *)tlv_data);
  1229. break;
  1230. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  1231. if (tlv_len != sizeof(u32))
  1232. goto invalid_tlv_len;
  1233. pieces->init_errlog_ptr =
  1234. le32_to_cpup((__le32 *)tlv_data);
  1235. break;
  1236. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  1237. if (tlv_len != sizeof(u32))
  1238. goto invalid_tlv_len;
  1239. pieces->inst_evtlog_ptr =
  1240. le32_to_cpup((__le32 *)tlv_data);
  1241. break;
  1242. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  1243. if (tlv_len != sizeof(u32))
  1244. goto invalid_tlv_len;
  1245. pieces->inst_evtlog_size =
  1246. le32_to_cpup((__le32 *)tlv_data);
  1247. break;
  1248. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  1249. if (tlv_len != sizeof(u32))
  1250. goto invalid_tlv_len;
  1251. pieces->inst_errlog_ptr =
  1252. le32_to_cpup((__le32 *)tlv_data);
  1253. break;
  1254. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  1255. if (tlv_len)
  1256. goto invalid_tlv_len;
  1257. priv->enhance_sensitivity_table = true;
  1258. break;
  1259. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  1260. if (tlv_len != sizeof(u32))
  1261. goto invalid_tlv_len;
  1262. capa->standard_phy_calibration_size =
  1263. le32_to_cpup((__le32 *)tlv_data);
  1264. break;
  1265. default:
  1266. IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
  1267. break;
  1268. }
  1269. }
  1270. if (len) {
  1271. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  1272. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  1273. return -EINVAL;
  1274. }
  1275. return 0;
  1276. invalid_tlv_len:
  1277. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  1278. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  1279. return -EINVAL;
  1280. }
  1281. /**
  1282. * iwl_ucode_callback - callback when firmware was loaded
  1283. *
  1284. * If loaded successfully, copies the firmware into buffers
  1285. * for the card to fetch (via DMA).
  1286. */
  1287. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  1288. {
  1289. struct iwl_priv *priv = context;
  1290. struct iwl_ucode_header *ucode;
  1291. int err;
  1292. struct iwlagn_firmware_pieces pieces;
  1293. const unsigned int api_max = priv->cfg->ucode_api_max;
  1294. const unsigned int api_min = priv->cfg->ucode_api_min;
  1295. u32 api_ver;
  1296. char buildstr[25];
  1297. u32 build;
  1298. struct iwlagn_ucode_capabilities ucode_capa = {
  1299. .max_probe_length = 200,
  1300. .standard_phy_calibration_size =
  1301. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  1302. };
  1303. memset(&pieces, 0, sizeof(pieces));
  1304. if (!ucode_raw) {
  1305. if (priv->fw_index <= priv->cfg->ucode_api_max)
  1306. IWL_ERR(priv,
  1307. "request for firmware file '%s' failed.\n",
  1308. priv->firmware_name);
  1309. goto try_again;
  1310. }
  1311. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  1312. priv->firmware_name, ucode_raw->size);
  1313. /* Make sure that we got at least the API version number */
  1314. if (ucode_raw->size < 4) {
  1315. IWL_ERR(priv, "File size way too small!\n");
  1316. goto try_again;
  1317. }
  1318. /* Data from ucode file: header followed by uCode images */
  1319. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1320. if (ucode->ver)
  1321. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  1322. else
  1323. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  1324. &ucode_capa);
  1325. if (err)
  1326. goto try_again;
  1327. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1328. build = pieces.build;
  1329. /*
  1330. * api_ver should match the api version forming part of the
  1331. * firmware filename ... but we don't check for that and only rely
  1332. * on the API version read from firmware header from here on forward
  1333. */
  1334. /* no api version check required for experimental uCode */
  1335. if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  1336. if (api_ver < api_min || api_ver > api_max) {
  1337. IWL_ERR(priv,
  1338. "Driver unable to support your firmware API. "
  1339. "Driver supports v%u, firmware is v%u.\n",
  1340. api_max, api_ver);
  1341. goto try_again;
  1342. }
  1343. if (api_ver != api_max)
  1344. IWL_ERR(priv,
  1345. "Firmware has old API version. Expected v%u, "
  1346. "got v%u. New firmware can be obtained "
  1347. "from http://www.intellinuxwireless.org.\n",
  1348. api_max, api_ver);
  1349. }
  1350. if (build)
  1351. sprintf(buildstr, " build %u%s", build,
  1352. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1353. ? " (EXP)" : "");
  1354. else
  1355. buildstr[0] = '\0';
  1356. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  1357. IWL_UCODE_MAJOR(priv->ucode_ver),
  1358. IWL_UCODE_MINOR(priv->ucode_ver),
  1359. IWL_UCODE_API(priv->ucode_ver),
  1360. IWL_UCODE_SERIAL(priv->ucode_ver),
  1361. buildstr);
  1362. snprintf(priv->hw->wiphy->fw_version,
  1363. sizeof(priv->hw->wiphy->fw_version),
  1364. "%u.%u.%u.%u%s",
  1365. IWL_UCODE_MAJOR(priv->ucode_ver),
  1366. IWL_UCODE_MINOR(priv->ucode_ver),
  1367. IWL_UCODE_API(priv->ucode_ver),
  1368. IWL_UCODE_SERIAL(priv->ucode_ver),
  1369. buildstr);
  1370. /*
  1371. * For any of the failures below (before allocating pci memory)
  1372. * we will try to load a version with a smaller API -- maybe the
  1373. * user just got a corrupted version of the latest API.
  1374. */
  1375. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1376. priv->ucode_ver);
  1377. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  1378. pieces.inst_size);
  1379. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  1380. pieces.data_size);
  1381. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  1382. pieces.init_size);
  1383. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  1384. pieces.init_data_size);
  1385. /* Verify that uCode images will fit in card's SRAM */
  1386. if (pieces.inst_size > priv->hw_params.max_inst_size) {
  1387. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  1388. pieces.inst_size);
  1389. goto try_again;
  1390. }
  1391. if (pieces.data_size > priv->hw_params.max_data_size) {
  1392. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  1393. pieces.data_size);
  1394. goto try_again;
  1395. }
  1396. if (pieces.init_size > priv->hw_params.max_inst_size) {
  1397. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  1398. pieces.init_size);
  1399. goto try_again;
  1400. }
  1401. if (pieces.init_data_size > priv->hw_params.max_data_size) {
  1402. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  1403. pieces.init_data_size);
  1404. goto try_again;
  1405. }
  1406. /* Allocate ucode buffers for card's bus-master loading ... */
  1407. /* Runtime instructions and 2 copies of data:
  1408. * 1) unmodified from disk
  1409. * 2) backup cache for save/restore during power-downs */
  1410. priv->ucode_code.len = pieces.inst_size;
  1411. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1412. priv->ucode_data.len = pieces.data_size;
  1413. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1414. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr)
  1415. goto err_pci_alloc;
  1416. /* Initialization instructions and data */
  1417. if (pieces.init_size && pieces.init_data_size) {
  1418. priv->ucode_init.len = pieces.init_size;
  1419. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1420. priv->ucode_init_data.len = pieces.init_data_size;
  1421. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1422. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1423. goto err_pci_alloc;
  1424. }
  1425. /* Now that we can no longer fail, copy information */
  1426. /*
  1427. * The (size - 16) / 12 formula is based on the information recorded
  1428. * for each event, which is of mode 1 (including timestamp) for all
  1429. * new microcodes that include this information.
  1430. */
  1431. priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
  1432. if (pieces.init_evtlog_size)
  1433. priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  1434. else
  1435. priv->_agn.init_evtlog_size =
  1436. priv->cfg->base_params->max_event_log_size;
  1437. priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
  1438. priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  1439. if (pieces.inst_evtlog_size)
  1440. priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  1441. else
  1442. priv->_agn.inst_evtlog_size =
  1443. priv->cfg->base_params->max_event_log_size;
  1444. priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
  1445. if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1446. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  1447. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1448. } else
  1449. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1450. if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
  1451. priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1452. else
  1453. priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1454. /* Copy images into buffers for card's bus-master reads ... */
  1455. /* Runtime instructions (first block of data in file) */
  1456. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
  1457. pieces.inst_size);
  1458. memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  1459. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1460. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1461. /*
  1462. * Runtime data
  1463. * NOTE: Copy into backup buffer will be done in iwl_up()
  1464. */
  1465. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
  1466. pieces.data_size);
  1467. memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
  1468. /* Initialization instructions */
  1469. if (pieces.init_size) {
  1470. IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
  1471. pieces.init_size);
  1472. memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
  1473. }
  1474. /* Initialization data */
  1475. if (pieces.init_data_size) {
  1476. IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
  1477. pieces.init_data_size);
  1478. memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
  1479. pieces.init_data_size);
  1480. }
  1481. /*
  1482. * figure out the offset of chain noise reset and gain commands
  1483. * base on the size of standard phy calibration commands table size
  1484. */
  1485. if (ucode_capa.standard_phy_calibration_size >
  1486. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  1487. ucode_capa.standard_phy_calibration_size =
  1488. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1489. priv->_agn.phy_calib_chain_noise_reset_cmd =
  1490. ucode_capa.standard_phy_calibration_size;
  1491. priv->_agn.phy_calib_chain_noise_gain_cmd =
  1492. ucode_capa.standard_phy_calibration_size + 1;
  1493. /**************************************************
  1494. * This is still part of probe() in a sense...
  1495. *
  1496. * 9. Setup and register with mac80211 and debugfs
  1497. **************************************************/
  1498. err = iwl_mac_setup_register(priv, &ucode_capa);
  1499. if (err)
  1500. goto out_unbind;
  1501. err = iwl_dbgfs_register(priv, DRV_NAME);
  1502. if (err)
  1503. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  1504. err = sysfs_create_group(&priv->pci_dev->dev.kobj,
  1505. &iwl_attribute_group);
  1506. if (err) {
  1507. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  1508. goto out_unbind;
  1509. }
  1510. /* We have our copies now, allow OS release its copies */
  1511. release_firmware(ucode_raw);
  1512. complete(&priv->_agn.firmware_loading_complete);
  1513. return;
  1514. try_again:
  1515. /* try next, if any */
  1516. if (iwl_request_firmware(priv, false))
  1517. goto out_unbind;
  1518. release_firmware(ucode_raw);
  1519. return;
  1520. err_pci_alloc:
  1521. IWL_ERR(priv, "failed to allocate pci memory\n");
  1522. iwl_dealloc_ucode_pci(priv);
  1523. out_unbind:
  1524. complete(&priv->_agn.firmware_loading_complete);
  1525. device_release_driver(&priv->pci_dev->dev);
  1526. release_firmware(ucode_raw);
  1527. }
  1528. static const char *desc_lookup_text[] = {
  1529. "OK",
  1530. "FAIL",
  1531. "BAD_PARAM",
  1532. "BAD_CHECKSUM",
  1533. "NMI_INTERRUPT_WDG",
  1534. "SYSASSERT",
  1535. "FATAL_ERROR",
  1536. "BAD_COMMAND",
  1537. "HW_ERROR_TUNE_LOCK",
  1538. "HW_ERROR_TEMPERATURE",
  1539. "ILLEGAL_CHAN_FREQ",
  1540. "VCC_NOT_STABLE",
  1541. "FH_ERROR",
  1542. "NMI_INTERRUPT_HOST",
  1543. "NMI_INTERRUPT_ACTION_PT",
  1544. "NMI_INTERRUPT_UNKNOWN",
  1545. "UCODE_VERSION_MISMATCH",
  1546. "HW_ERROR_ABS_LOCK",
  1547. "HW_ERROR_CAL_LOCK_FAIL",
  1548. "NMI_INTERRUPT_INST_ACTION_PT",
  1549. "NMI_INTERRUPT_DATA_ACTION_PT",
  1550. "NMI_TRM_HW_ER",
  1551. "NMI_INTERRUPT_TRM",
  1552. "NMI_INTERRUPT_BREAK_POINT"
  1553. "DEBUG_0",
  1554. "DEBUG_1",
  1555. "DEBUG_2",
  1556. "DEBUG_3",
  1557. };
  1558. static struct { char *name; u8 num; } advanced_lookup[] = {
  1559. { "NMI_INTERRUPT_WDG", 0x34 },
  1560. { "SYSASSERT", 0x35 },
  1561. { "UCODE_VERSION_MISMATCH", 0x37 },
  1562. { "BAD_COMMAND", 0x38 },
  1563. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1564. { "FATAL_ERROR", 0x3D },
  1565. { "NMI_TRM_HW_ERR", 0x46 },
  1566. { "NMI_INTERRUPT_TRM", 0x4C },
  1567. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1568. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1569. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1570. { "NMI_INTERRUPT_HOST", 0x66 },
  1571. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1572. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1573. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1574. { "ADVANCED_SYSASSERT", 0 },
  1575. };
  1576. static const char *desc_lookup(u32 num)
  1577. {
  1578. int i;
  1579. int max = ARRAY_SIZE(desc_lookup_text);
  1580. if (num < max)
  1581. return desc_lookup_text[num];
  1582. max = ARRAY_SIZE(advanced_lookup) - 1;
  1583. for (i = 0; i < max; i++) {
  1584. if (advanced_lookup[i].num == num)
  1585. break;;
  1586. }
  1587. return advanced_lookup[i].name;
  1588. }
  1589. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1590. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1591. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1592. {
  1593. u32 data2, line;
  1594. u32 desc, time, count, base, data1;
  1595. u32 blink1, blink2, ilink1, ilink2;
  1596. u32 pc, hcmd;
  1597. struct iwl_error_event_table table;
  1598. base = priv->device_pointers.error_event_table;
  1599. if (priv->ucode_type == UCODE_INIT) {
  1600. if (!base)
  1601. base = priv->_agn.init_errlog_ptr;
  1602. } else {
  1603. if (!base)
  1604. base = priv->_agn.inst_errlog_ptr;
  1605. }
  1606. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1607. IWL_ERR(priv,
  1608. "Not valid error log pointer 0x%08X for %s uCode\n",
  1609. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  1610. return;
  1611. }
  1612. iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
  1613. count = table.valid;
  1614. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1615. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1616. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1617. priv->status, count);
  1618. }
  1619. desc = table.error_id;
  1620. priv->isr_stats.err_code = desc;
  1621. pc = table.pc;
  1622. blink1 = table.blink1;
  1623. blink2 = table.blink2;
  1624. ilink1 = table.ilink1;
  1625. ilink2 = table.ilink2;
  1626. data1 = table.data1;
  1627. data2 = table.data2;
  1628. line = table.line;
  1629. time = table.tsf_low;
  1630. hcmd = table.hcmd;
  1631. trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
  1632. blink1, blink2, ilink1, ilink2);
  1633. IWL_ERR(priv, "Desc Time "
  1634. "data1 data2 line\n");
  1635. IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  1636. desc_lookup(desc), desc, time, data1, data2, line);
  1637. IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
  1638. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  1639. pc, blink1, blink2, ilink1, ilink2, hcmd);
  1640. }
  1641. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1642. /**
  1643. * iwl_print_event_log - Dump error event log to syslog
  1644. *
  1645. */
  1646. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1647. u32 num_events, u32 mode,
  1648. int pos, char **buf, size_t bufsz)
  1649. {
  1650. u32 i;
  1651. u32 base; /* SRAM byte address of event log header */
  1652. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1653. u32 ptr; /* SRAM byte address of log data */
  1654. u32 ev, time, data; /* event log data */
  1655. unsigned long reg_flags;
  1656. if (num_events == 0)
  1657. return pos;
  1658. base = priv->device_pointers.log_event_table;
  1659. if (priv->ucode_type == UCODE_INIT) {
  1660. if (!base)
  1661. base = priv->_agn.init_evtlog_ptr;
  1662. } else {
  1663. if (!base)
  1664. base = priv->_agn.inst_evtlog_ptr;
  1665. }
  1666. if (mode == 0)
  1667. event_size = 2 * sizeof(u32);
  1668. else
  1669. event_size = 3 * sizeof(u32);
  1670. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1671. /* Make sure device is powered up for SRAM reads */
  1672. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1673. iwl_grab_nic_access(priv);
  1674. /* Set starting address; reads will auto-increment */
  1675. iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1676. rmb();
  1677. /* "time" is actually "data" for mode 0 (no timestamp).
  1678. * place event id # at far right for easier visual parsing. */
  1679. for (i = 0; i < num_events; i++) {
  1680. ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1681. time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1682. if (mode == 0) {
  1683. /* data, ev */
  1684. if (bufsz) {
  1685. pos += scnprintf(*buf + pos, bufsz - pos,
  1686. "EVT_LOG:0x%08x:%04u\n",
  1687. time, ev);
  1688. } else {
  1689. trace_iwlwifi_dev_ucode_event(priv, 0,
  1690. time, ev);
  1691. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1692. time, ev);
  1693. }
  1694. } else {
  1695. data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1696. if (bufsz) {
  1697. pos += scnprintf(*buf + pos, bufsz - pos,
  1698. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1699. time, data, ev);
  1700. } else {
  1701. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1702. time, data, ev);
  1703. trace_iwlwifi_dev_ucode_event(priv, time,
  1704. data, ev);
  1705. }
  1706. }
  1707. }
  1708. /* Allow device to power down */
  1709. iwl_release_nic_access(priv);
  1710. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1711. return pos;
  1712. }
  1713. /**
  1714. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1715. */
  1716. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1717. u32 num_wraps, u32 next_entry,
  1718. u32 size, u32 mode,
  1719. int pos, char **buf, size_t bufsz)
  1720. {
  1721. /*
  1722. * display the newest DEFAULT_LOG_ENTRIES entries
  1723. * i.e the entries just before the next ont that uCode would fill.
  1724. */
  1725. if (num_wraps) {
  1726. if (next_entry < size) {
  1727. pos = iwl_print_event_log(priv,
  1728. capacity - (size - next_entry),
  1729. size - next_entry, mode,
  1730. pos, buf, bufsz);
  1731. pos = iwl_print_event_log(priv, 0,
  1732. next_entry, mode,
  1733. pos, buf, bufsz);
  1734. } else
  1735. pos = iwl_print_event_log(priv, next_entry - size,
  1736. size, mode, pos, buf, bufsz);
  1737. } else {
  1738. if (next_entry < size) {
  1739. pos = iwl_print_event_log(priv, 0, next_entry,
  1740. mode, pos, buf, bufsz);
  1741. } else {
  1742. pos = iwl_print_event_log(priv, next_entry - size,
  1743. size, mode, pos, buf, bufsz);
  1744. }
  1745. }
  1746. return pos;
  1747. }
  1748. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1749. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1750. char **buf, bool display)
  1751. {
  1752. u32 base; /* SRAM byte address of event log header */
  1753. u32 capacity; /* event log capacity in # entries */
  1754. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1755. u32 num_wraps; /* # times uCode wrapped to top of log */
  1756. u32 next_entry; /* index of next entry to be written by uCode */
  1757. u32 size; /* # entries that we'll print */
  1758. u32 logsize;
  1759. int pos = 0;
  1760. size_t bufsz = 0;
  1761. base = priv->device_pointers.log_event_table;
  1762. if (priv->ucode_type == UCODE_INIT) {
  1763. logsize = priv->_agn.init_evtlog_size;
  1764. if (!base)
  1765. base = priv->_agn.init_evtlog_ptr;
  1766. } else {
  1767. logsize = priv->_agn.inst_evtlog_size;
  1768. if (!base)
  1769. base = priv->_agn.inst_evtlog_ptr;
  1770. }
  1771. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1772. IWL_ERR(priv,
  1773. "Invalid event log pointer 0x%08X for %s uCode\n",
  1774. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  1775. return -EINVAL;
  1776. }
  1777. /* event log header */
  1778. capacity = iwl_read_targ_mem(priv, base);
  1779. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1780. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1781. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1782. if (capacity > logsize) {
  1783. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  1784. capacity, logsize);
  1785. capacity = logsize;
  1786. }
  1787. if (next_entry > logsize) {
  1788. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1789. next_entry, logsize);
  1790. next_entry = logsize;
  1791. }
  1792. size = num_wraps ? capacity : next_entry;
  1793. /* bail out if nothing in log */
  1794. if (size == 0) {
  1795. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1796. return pos;
  1797. }
  1798. /* enable/disable bt channel inhibition */
  1799. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  1800. #ifdef CONFIG_IWLWIFI_DEBUG
  1801. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1802. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1803. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1804. #else
  1805. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1806. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1807. #endif
  1808. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1809. size);
  1810. #ifdef CONFIG_IWLWIFI_DEBUG
  1811. if (display) {
  1812. if (full_log)
  1813. bufsz = capacity * 48;
  1814. else
  1815. bufsz = size * 48;
  1816. *buf = kmalloc(bufsz, GFP_KERNEL);
  1817. if (!*buf)
  1818. return -ENOMEM;
  1819. }
  1820. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1821. /*
  1822. * if uCode has wrapped back to top of log,
  1823. * start at the oldest entry,
  1824. * i.e the next one that uCode would fill.
  1825. */
  1826. if (num_wraps)
  1827. pos = iwl_print_event_log(priv, next_entry,
  1828. capacity - next_entry, mode,
  1829. pos, buf, bufsz);
  1830. /* (then/else) start at top of log */
  1831. pos = iwl_print_event_log(priv, 0,
  1832. next_entry, mode, pos, buf, bufsz);
  1833. } else
  1834. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1835. next_entry, size, mode,
  1836. pos, buf, bufsz);
  1837. #else
  1838. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1839. next_entry, size, mode,
  1840. pos, buf, bufsz);
  1841. #endif
  1842. return pos;
  1843. }
  1844. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1845. {
  1846. struct iwl_ct_kill_config cmd;
  1847. struct iwl_ct_kill_throttling_config adv_cmd;
  1848. unsigned long flags;
  1849. int ret = 0;
  1850. spin_lock_irqsave(&priv->lock, flags);
  1851. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1852. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1853. spin_unlock_irqrestore(&priv->lock, flags);
  1854. priv->thermal_throttle.ct_kill_toggle = false;
  1855. if (priv->cfg->base_params->support_ct_kill_exit) {
  1856. adv_cmd.critical_temperature_enter =
  1857. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1858. adv_cmd.critical_temperature_exit =
  1859. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  1860. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1861. sizeof(adv_cmd), &adv_cmd);
  1862. if (ret)
  1863. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1864. else
  1865. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1866. "succeeded, "
  1867. "critical temperature enter is %d,"
  1868. "exit is %d\n",
  1869. priv->hw_params.ct_kill_threshold,
  1870. priv->hw_params.ct_kill_exit_threshold);
  1871. } else {
  1872. cmd.critical_temperature_R =
  1873. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1874. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1875. sizeof(cmd), &cmd);
  1876. if (ret)
  1877. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1878. else
  1879. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1880. "succeeded, "
  1881. "critical temperature is %d\n",
  1882. priv->hw_params.ct_kill_threshold);
  1883. }
  1884. }
  1885. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  1886. {
  1887. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  1888. struct iwl_host_cmd cmd = {
  1889. .id = CALIBRATION_CFG_CMD,
  1890. .len = sizeof(struct iwl_calib_cfg_cmd),
  1891. .data = &calib_cfg_cmd,
  1892. };
  1893. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  1894. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  1895. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  1896. return iwl_send_cmd(priv, &cmd);
  1897. }
  1898. /**
  1899. * iwl_alive_start - called after REPLY_ALIVE notification received
  1900. * from protocol/runtime uCode (initialization uCode's
  1901. * Alive gets handled by iwl_init_alive_start()).
  1902. */
  1903. static void iwl_alive_start(struct iwl_priv *priv)
  1904. {
  1905. int ret = 0;
  1906. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1907. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1908. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  1909. * This is a paranoid check, because we would not have gotten the
  1910. * "runtime" alive if code weren't properly loaded. */
  1911. if (iwl_verify_ucode(priv, &priv->ucode_code)) {
  1912. /* Runtime instruction load was bad;
  1913. * take it all the way back down so we can try again */
  1914. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  1915. goto restart;
  1916. }
  1917. ret = iwlagn_alive_notify(priv);
  1918. if (ret) {
  1919. IWL_WARN(priv,
  1920. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  1921. goto restart;
  1922. }
  1923. /* After the ALIVE response, we can send host commands to the uCode */
  1924. set_bit(STATUS_ALIVE, &priv->status);
  1925. /* Enable watchdog to monitor the driver tx queues */
  1926. iwl_setup_watchdog(priv);
  1927. if (iwl_is_rfkill(priv))
  1928. return;
  1929. /* download priority table before any calibration request */
  1930. if (priv->cfg->bt_params &&
  1931. priv->cfg->bt_params->advanced_bt_coexist) {
  1932. /* Configure Bluetooth device coexistence support */
  1933. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1934. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1935. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1936. priv->cfg->ops->hcmd->send_bt_config(priv);
  1937. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  1938. iwlagn_send_prio_tbl(priv);
  1939. /* FIXME: w/a to force change uCode BT state machine */
  1940. iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  1941. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1942. iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  1943. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1944. }
  1945. if (priv->hw_params.calib_rt_cfg)
  1946. iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
  1947. ieee80211_wake_queues(priv->hw);
  1948. priv->active_rate = IWL_RATES_MASK;
  1949. /* Configure Tx antenna selection based on H/W config */
  1950. if (priv->cfg->ops->hcmd->set_tx_ant)
  1951. priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
  1952. if (iwl_is_associated_ctx(ctx)) {
  1953. struct iwl_rxon_cmd *active_rxon =
  1954. (struct iwl_rxon_cmd *)&ctx->active;
  1955. /* apply any changes in staging */
  1956. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1957. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1958. } else {
  1959. struct iwl_rxon_context *tmp;
  1960. /* Initialize our rx_config data */
  1961. for_each_context(priv, tmp)
  1962. iwl_connection_init_rx_config(priv, tmp);
  1963. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1964. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1965. }
  1966. if (!priv->cfg->bt_params || (priv->cfg->bt_params &&
  1967. !priv->cfg->bt_params->advanced_bt_coexist)) {
  1968. /*
  1969. * default is 2-wire BT coexexistence support
  1970. */
  1971. priv->cfg->ops->hcmd->send_bt_config(priv);
  1972. }
  1973. iwl_reset_run_time_calib(priv);
  1974. set_bit(STATUS_READY, &priv->status);
  1975. /* Configure the adapter for unassociated operation */
  1976. iwlcore_commit_rxon(priv, ctx);
  1977. /* At this point, the NIC is initialized and operational */
  1978. iwl_rf_kill_ct_config(priv);
  1979. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1980. wake_up_interruptible(&priv->wait_command_queue);
  1981. iwl_power_update_mode(priv, true);
  1982. IWL_DEBUG_INFO(priv, "Updated power mode\n");
  1983. return;
  1984. restart:
  1985. queue_work(priv->workqueue, &priv->restart);
  1986. }
  1987. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1988. static void __iwl_down(struct iwl_priv *priv)
  1989. {
  1990. unsigned long flags;
  1991. int exit_pending;
  1992. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1993. iwl_scan_cancel_timeout(priv, 200);
  1994. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  1995. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1996. * to prevent rearm timer */
  1997. del_timer_sync(&priv->watchdog);
  1998. iwl_clear_ucode_stations(priv, NULL);
  1999. iwl_dealloc_bcast_stations(priv);
  2000. iwl_clear_driver_stations(priv);
  2001. /* reset BT coex data */
  2002. priv->bt_status = 0;
  2003. if (priv->cfg->bt_params)
  2004. priv->bt_traffic_load =
  2005. priv->cfg->bt_params->bt_init_traffic_load;
  2006. else
  2007. priv->bt_traffic_load = 0;
  2008. priv->bt_full_concurrent = false;
  2009. priv->bt_ci_compliance = 0;
  2010. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2011. * exiting the module */
  2012. if (!exit_pending)
  2013. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2014. /* stop and reset the on-board processor */
  2015. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2016. /* tell the device to stop sending interrupts */
  2017. spin_lock_irqsave(&priv->lock, flags);
  2018. iwl_disable_interrupts(priv);
  2019. spin_unlock_irqrestore(&priv->lock, flags);
  2020. iwl_synchronize_irq(priv);
  2021. if (priv->mac80211_registered)
  2022. ieee80211_stop_queues(priv->hw);
  2023. /* If we have not previously called iwl_init() then
  2024. * clear all bits but the RF Kill bit and return */
  2025. if (!iwl_is_init(priv)) {
  2026. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2027. STATUS_RF_KILL_HW |
  2028. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2029. STATUS_GEO_CONFIGURED |
  2030. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2031. STATUS_EXIT_PENDING;
  2032. goto exit;
  2033. }
  2034. /* ...otherwise clear out all the status bits but the RF Kill
  2035. * bit and continue taking the NIC down. */
  2036. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2037. STATUS_RF_KILL_HW |
  2038. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2039. STATUS_GEO_CONFIGURED |
  2040. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2041. STATUS_FW_ERROR |
  2042. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2043. STATUS_EXIT_PENDING;
  2044. /* device going down, Stop using ICT table */
  2045. iwl_disable_ict(priv);
  2046. iwlagn_txq_ctx_stop(priv);
  2047. iwlagn_rxq_stop(priv);
  2048. /* Power-down device's busmaster DMA clocks */
  2049. iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  2050. udelay(5);
  2051. /* Make sure (redundant) we've released our request to stay awake */
  2052. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2053. /* Stop the device, and put it in low power state */
  2054. iwl_apm_stop(priv);
  2055. exit:
  2056. dev_kfree_skb(priv->beacon_skb);
  2057. priv->beacon_skb = NULL;
  2058. /* clear out any free frames */
  2059. iwl_clear_free_frames(priv);
  2060. }
  2061. static void iwl_down(struct iwl_priv *priv)
  2062. {
  2063. mutex_lock(&priv->mutex);
  2064. __iwl_down(priv);
  2065. mutex_unlock(&priv->mutex);
  2066. iwl_cancel_deferred_work(priv);
  2067. }
  2068. #define HW_READY_TIMEOUT (50)
  2069. static int iwl_set_hw_ready(struct iwl_priv *priv)
  2070. {
  2071. int ret = 0;
  2072. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2073. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  2074. /* See if we got it */
  2075. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2076. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2077. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2078. HW_READY_TIMEOUT);
  2079. if (ret != -ETIMEDOUT)
  2080. priv->hw_ready = true;
  2081. else
  2082. priv->hw_ready = false;
  2083. IWL_DEBUG_INFO(priv, "hardware %s\n",
  2084. (priv->hw_ready == 1) ? "ready" : "not ready");
  2085. return ret;
  2086. }
  2087. static int iwl_prepare_card_hw(struct iwl_priv *priv)
  2088. {
  2089. int ret = 0;
  2090. IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
  2091. ret = iwl_set_hw_ready(priv);
  2092. if (priv->hw_ready)
  2093. return ret;
  2094. /* If HW is not ready, prepare the conditions to check again */
  2095. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2096. CSR_HW_IF_CONFIG_REG_PREPARE);
  2097. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2098. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  2099. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  2100. /* HW should be ready by now, check again. */
  2101. if (ret != -ETIMEDOUT)
  2102. iwl_set_hw_ready(priv);
  2103. return ret;
  2104. }
  2105. #define MAX_HW_RESTARTS 5
  2106. static int __iwl_up(struct iwl_priv *priv)
  2107. {
  2108. struct iwl_rxon_context *ctx;
  2109. int i;
  2110. int ret;
  2111. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2112. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2113. return -EIO;
  2114. }
  2115. for_each_context(priv, ctx) {
  2116. ret = iwlagn_alloc_bcast_station(priv, ctx);
  2117. if (ret) {
  2118. iwl_dealloc_bcast_stations(priv);
  2119. return ret;
  2120. }
  2121. }
  2122. iwl_prepare_card_hw(priv);
  2123. if (!priv->hw_ready) {
  2124. IWL_WARN(priv, "Exit HW not ready\n");
  2125. return -EIO;
  2126. }
  2127. /* If platform's RF_KILL switch is NOT set to KILL */
  2128. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2129. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2130. else
  2131. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2132. if (iwl_is_rfkill(priv)) {
  2133. wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
  2134. iwl_enable_interrupts(priv);
  2135. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2136. return 0;
  2137. }
  2138. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2139. ret = iwlagn_hw_nic_init(priv);
  2140. if (ret) {
  2141. IWL_ERR(priv, "Unable to init nic\n");
  2142. return ret;
  2143. }
  2144. /* make sure rfkill handshake bits are cleared */
  2145. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2146. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2147. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2148. /* clear (again), then enable host interrupts */
  2149. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2150. iwl_enable_interrupts(priv);
  2151. /* really make sure rfkill handshake bits are cleared */
  2152. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2153. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2154. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2155. /* load bootstrap state machine,
  2156. * load bootstrap program into processor's memory,
  2157. * prepare to load the "initialize" uCode */
  2158. ret = iwlagn_load_ucode(priv);
  2159. if (ret) {
  2160. IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
  2161. ret);
  2162. continue;
  2163. }
  2164. /* start card; "initialize" will load runtime ucode */
  2165. iwl_nic_start(priv);
  2166. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2167. return 0;
  2168. }
  2169. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2170. __iwl_down(priv);
  2171. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2172. /* tried to restart and config the device for as long as our
  2173. * patience could withstand */
  2174. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2175. return -EIO;
  2176. }
  2177. /*****************************************************************************
  2178. *
  2179. * Workqueue callbacks
  2180. *
  2181. *****************************************************************************/
  2182. static void iwl_bg_init_alive_start(struct work_struct *data)
  2183. {
  2184. struct iwl_priv *priv =
  2185. container_of(data, struct iwl_priv, init_alive_start.work);
  2186. mutex_lock(&priv->mutex);
  2187. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2188. mutex_unlock(&priv->mutex);
  2189. return;
  2190. }
  2191. iwlagn_init_alive_start(priv);
  2192. mutex_unlock(&priv->mutex);
  2193. }
  2194. static void iwl_bg_alive_start(struct work_struct *data)
  2195. {
  2196. struct iwl_priv *priv =
  2197. container_of(data, struct iwl_priv, alive_start.work);
  2198. mutex_lock(&priv->mutex);
  2199. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2200. goto unlock;
  2201. /* enable dram interrupt */
  2202. iwl_reset_ict(priv);
  2203. iwl_alive_start(priv);
  2204. unlock:
  2205. mutex_unlock(&priv->mutex);
  2206. }
  2207. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  2208. {
  2209. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2210. run_time_calib_work);
  2211. mutex_lock(&priv->mutex);
  2212. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2213. test_bit(STATUS_SCANNING, &priv->status)) {
  2214. mutex_unlock(&priv->mutex);
  2215. return;
  2216. }
  2217. if (priv->start_calib) {
  2218. iwl_chain_noise_calibration(priv);
  2219. iwl_sensitivity_calibration(priv);
  2220. }
  2221. mutex_unlock(&priv->mutex);
  2222. }
  2223. static void iwl_bg_restart(struct work_struct *data)
  2224. {
  2225. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2226. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2227. return;
  2228. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2229. struct iwl_rxon_context *ctx;
  2230. bool bt_full_concurrent;
  2231. u8 bt_ci_compliance;
  2232. u8 bt_load;
  2233. u8 bt_status;
  2234. mutex_lock(&priv->mutex);
  2235. for_each_context(priv, ctx)
  2236. ctx->vif = NULL;
  2237. priv->is_open = 0;
  2238. /*
  2239. * __iwl_down() will clear the BT status variables,
  2240. * which is correct, but when we restart we really
  2241. * want to keep them so restore them afterwards.
  2242. *
  2243. * The restart process will later pick them up and
  2244. * re-configure the hw when we reconfigure the BT
  2245. * command.
  2246. */
  2247. bt_full_concurrent = priv->bt_full_concurrent;
  2248. bt_ci_compliance = priv->bt_ci_compliance;
  2249. bt_load = priv->bt_traffic_load;
  2250. bt_status = priv->bt_status;
  2251. __iwl_down(priv);
  2252. priv->bt_full_concurrent = bt_full_concurrent;
  2253. priv->bt_ci_compliance = bt_ci_compliance;
  2254. priv->bt_traffic_load = bt_load;
  2255. priv->bt_status = bt_status;
  2256. mutex_unlock(&priv->mutex);
  2257. iwl_cancel_deferred_work(priv);
  2258. ieee80211_restart_hw(priv->hw);
  2259. } else {
  2260. iwl_down(priv);
  2261. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2262. return;
  2263. mutex_lock(&priv->mutex);
  2264. __iwl_up(priv);
  2265. mutex_unlock(&priv->mutex);
  2266. }
  2267. }
  2268. static void iwl_bg_rx_replenish(struct work_struct *data)
  2269. {
  2270. struct iwl_priv *priv =
  2271. container_of(data, struct iwl_priv, rx_replenish);
  2272. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2273. return;
  2274. mutex_lock(&priv->mutex);
  2275. iwlagn_rx_replenish(priv);
  2276. mutex_unlock(&priv->mutex);
  2277. }
  2278. static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  2279. struct ieee80211_channel *chan,
  2280. enum nl80211_channel_type channel_type,
  2281. unsigned int wait)
  2282. {
  2283. struct iwl_priv *priv = hw->priv;
  2284. int ret;
  2285. /* Not supported if we don't have PAN */
  2286. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
  2287. ret = -EOPNOTSUPP;
  2288. goto free;
  2289. }
  2290. /* Not supported on pre-P2P firmware */
  2291. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  2292. BIT(NL80211_IFTYPE_P2P_CLIENT))) {
  2293. ret = -EOPNOTSUPP;
  2294. goto free;
  2295. }
  2296. mutex_lock(&priv->mutex);
  2297. if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
  2298. /*
  2299. * If the PAN context is free, use the normal
  2300. * way of doing remain-on-channel offload + TX.
  2301. */
  2302. ret = 1;
  2303. goto out;
  2304. }
  2305. /* TODO: queue up if scanning? */
  2306. if (test_bit(STATUS_SCANNING, &priv->status) ||
  2307. priv->_agn.offchan_tx_skb) {
  2308. ret = -EBUSY;
  2309. goto out;
  2310. }
  2311. /*
  2312. * max_scan_ie_len doesn't include the blank SSID or the header,
  2313. * so need to add that again here.
  2314. */
  2315. if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
  2316. ret = -ENOBUFS;
  2317. goto out;
  2318. }
  2319. priv->_agn.offchan_tx_skb = skb;
  2320. priv->_agn.offchan_tx_timeout = wait;
  2321. priv->_agn.offchan_tx_chan = chan;
  2322. ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
  2323. IWL_SCAN_OFFCH_TX, chan->band);
  2324. if (ret)
  2325. priv->_agn.offchan_tx_skb = NULL;
  2326. out:
  2327. mutex_unlock(&priv->mutex);
  2328. free:
  2329. if (ret < 0)
  2330. kfree_skb(skb);
  2331. return ret;
  2332. }
  2333. static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
  2334. {
  2335. struct iwl_priv *priv = hw->priv;
  2336. int ret;
  2337. mutex_lock(&priv->mutex);
  2338. if (!priv->_agn.offchan_tx_skb) {
  2339. ret = -EINVAL;
  2340. goto unlock;
  2341. }
  2342. priv->_agn.offchan_tx_skb = NULL;
  2343. ret = iwl_scan_cancel_timeout(priv, 200);
  2344. if (ret)
  2345. ret = -EIO;
  2346. unlock:
  2347. mutex_unlock(&priv->mutex);
  2348. return ret;
  2349. }
  2350. /*****************************************************************************
  2351. *
  2352. * mac80211 entry point functions
  2353. *
  2354. *****************************************************************************/
  2355. #define UCODE_READY_TIMEOUT (4 * HZ)
  2356. /*
  2357. * Not a mac80211 entry point function, but it fits in with all the
  2358. * other mac80211 functions grouped here.
  2359. */
  2360. static int iwl_mac_setup_register(struct iwl_priv *priv,
  2361. struct iwlagn_ucode_capabilities *capa)
  2362. {
  2363. int ret;
  2364. struct ieee80211_hw *hw = priv->hw;
  2365. struct iwl_rxon_context *ctx;
  2366. hw->rate_control_algorithm = "iwl-agn-rs";
  2367. /* Tell mac80211 our characteristics */
  2368. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  2369. IEEE80211_HW_AMPDU_AGGREGATION |
  2370. IEEE80211_HW_NEED_DTIM_PERIOD |
  2371. IEEE80211_HW_SPECTRUM_MGMT |
  2372. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  2373. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2374. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  2375. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  2376. if (priv->cfg->sku & IWL_SKU_N)
  2377. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  2378. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  2379. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  2380. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  2381. hw->sta_data_size = sizeof(struct iwl_station_priv);
  2382. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  2383. for_each_context(priv, ctx) {
  2384. hw->wiphy->interface_modes |= ctx->interface_modes;
  2385. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  2386. }
  2387. hw->wiphy->max_remain_on_channel_duration = 1000;
  2388. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  2389. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  2390. WIPHY_FLAG_IBSS_RSN;
  2391. /*
  2392. * For now, disable PS by default because it affects
  2393. * RX performance significantly.
  2394. */
  2395. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  2396. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  2397. /* we create the 802.11 header and a zero-length SSID element */
  2398. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  2399. /* Default value; 4 EDCA QOS priorities */
  2400. hw->queues = 4;
  2401. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  2402. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  2403. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  2404. &priv->bands[IEEE80211_BAND_2GHZ];
  2405. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  2406. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  2407. &priv->bands[IEEE80211_BAND_5GHZ];
  2408. iwl_leds_init(priv);
  2409. ret = ieee80211_register_hw(priv->hw);
  2410. if (ret) {
  2411. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  2412. return ret;
  2413. }
  2414. priv->mac80211_registered = 1;
  2415. return 0;
  2416. }
  2417. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  2418. {
  2419. struct iwl_priv *priv = hw->priv;
  2420. int ret;
  2421. IWL_DEBUG_MAC80211(priv, "enter\n");
  2422. /* we should be verifying the device is ready to be opened */
  2423. mutex_lock(&priv->mutex);
  2424. ret = __iwl_up(priv);
  2425. mutex_unlock(&priv->mutex);
  2426. if (ret)
  2427. return ret;
  2428. if (iwl_is_rfkill(priv))
  2429. goto out;
  2430. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  2431. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  2432. * mac80211 will not be run successfully. */
  2433. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2434. test_bit(STATUS_READY, &priv->status),
  2435. UCODE_READY_TIMEOUT);
  2436. if (!ret) {
  2437. if (!test_bit(STATUS_READY, &priv->status)) {
  2438. IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
  2439. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2440. return -ETIMEDOUT;
  2441. }
  2442. }
  2443. iwlagn_led_enable(priv);
  2444. out:
  2445. priv->is_open = 1;
  2446. IWL_DEBUG_MAC80211(priv, "leave\n");
  2447. return 0;
  2448. }
  2449. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  2450. {
  2451. struct iwl_priv *priv = hw->priv;
  2452. IWL_DEBUG_MAC80211(priv, "enter\n");
  2453. if (!priv->is_open)
  2454. return;
  2455. priv->is_open = 0;
  2456. iwl_down(priv);
  2457. flush_workqueue(priv->workqueue);
  2458. /* User space software may expect getting rfkill changes
  2459. * even if interface is down */
  2460. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2461. iwl_enable_rfkill_int(priv);
  2462. IWL_DEBUG_MAC80211(priv, "leave\n");
  2463. }
  2464. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2465. {
  2466. struct iwl_priv *priv = hw->priv;
  2467. IWL_DEBUG_MACDUMP(priv, "enter\n");
  2468. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2469. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2470. if (iwlagn_tx_skb(priv, skb))
  2471. dev_kfree_skb_any(skb);
  2472. IWL_DEBUG_MACDUMP(priv, "leave\n");
  2473. }
  2474. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  2475. struct ieee80211_vif *vif,
  2476. struct ieee80211_key_conf *keyconf,
  2477. struct ieee80211_sta *sta,
  2478. u32 iv32, u16 *phase1key)
  2479. {
  2480. struct iwl_priv *priv = hw->priv;
  2481. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2482. IWL_DEBUG_MAC80211(priv, "enter\n");
  2483. iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
  2484. iv32, phase1key);
  2485. IWL_DEBUG_MAC80211(priv, "leave\n");
  2486. }
  2487. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2488. struct ieee80211_vif *vif,
  2489. struct ieee80211_sta *sta,
  2490. struct ieee80211_key_conf *key)
  2491. {
  2492. struct iwl_priv *priv = hw->priv;
  2493. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2494. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2495. int ret;
  2496. u8 sta_id;
  2497. bool is_default_wep_key = false;
  2498. IWL_DEBUG_MAC80211(priv, "enter\n");
  2499. if (priv->cfg->mod_params->sw_crypto) {
  2500. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2501. return -EOPNOTSUPP;
  2502. }
  2503. /*
  2504. * To support IBSS RSN, don't program group keys in IBSS, the
  2505. * hardware will then not attempt to decrypt the frames.
  2506. */
  2507. if (vif->type == NL80211_IFTYPE_ADHOC &&
  2508. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  2509. return -EOPNOTSUPP;
  2510. sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
  2511. if (sta_id == IWL_INVALID_STATION)
  2512. return -EINVAL;
  2513. mutex_lock(&priv->mutex);
  2514. iwl_scan_cancel_timeout(priv, 100);
  2515. /*
  2516. * If we are getting WEP group key and we didn't receive any key mapping
  2517. * so far, we are in legacy wep mode (group key only), otherwise we are
  2518. * in 1X mode.
  2519. * In legacy wep mode, we use another host command to the uCode.
  2520. */
  2521. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2522. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  2523. !sta) {
  2524. if (cmd == SET_KEY)
  2525. is_default_wep_key = !ctx->key_mapping_keys;
  2526. else
  2527. is_default_wep_key =
  2528. (key->hw_key_idx == HW_KEY_DEFAULT);
  2529. }
  2530. switch (cmd) {
  2531. case SET_KEY:
  2532. if (is_default_wep_key)
  2533. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  2534. else
  2535. ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
  2536. key, sta_id);
  2537. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2538. break;
  2539. case DISABLE_KEY:
  2540. if (is_default_wep_key)
  2541. ret = iwl_remove_default_wep_key(priv, ctx, key);
  2542. else
  2543. ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
  2544. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2545. break;
  2546. default:
  2547. ret = -EINVAL;
  2548. }
  2549. mutex_unlock(&priv->mutex);
  2550. IWL_DEBUG_MAC80211(priv, "leave\n");
  2551. return ret;
  2552. }
  2553. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  2554. struct ieee80211_vif *vif,
  2555. enum ieee80211_ampdu_mlme_action action,
  2556. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  2557. u8 buf_size)
  2558. {
  2559. struct iwl_priv *priv = hw->priv;
  2560. int ret = -EINVAL;
  2561. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  2562. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2563. sta->addr, tid);
  2564. if (!(priv->cfg->sku & IWL_SKU_N))
  2565. return -EACCES;
  2566. mutex_lock(&priv->mutex);
  2567. switch (action) {
  2568. case IEEE80211_AMPDU_RX_START:
  2569. IWL_DEBUG_HT(priv, "start Rx\n");
  2570. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  2571. break;
  2572. case IEEE80211_AMPDU_RX_STOP:
  2573. IWL_DEBUG_HT(priv, "stop Rx\n");
  2574. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  2575. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2576. ret = 0;
  2577. break;
  2578. case IEEE80211_AMPDU_TX_START:
  2579. IWL_DEBUG_HT(priv, "start Tx\n");
  2580. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  2581. if (ret == 0) {
  2582. priv->_agn.agg_tids_count++;
  2583. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  2584. priv->_agn.agg_tids_count);
  2585. }
  2586. break;
  2587. case IEEE80211_AMPDU_TX_STOP:
  2588. IWL_DEBUG_HT(priv, "stop Tx\n");
  2589. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  2590. if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
  2591. priv->_agn.agg_tids_count--;
  2592. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  2593. priv->_agn.agg_tids_count);
  2594. }
  2595. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2596. ret = 0;
  2597. if (priv->cfg->ht_params &&
  2598. priv->cfg->ht_params->use_rts_for_aggregation) {
  2599. struct iwl_station_priv *sta_priv =
  2600. (void *) sta->drv_priv;
  2601. /*
  2602. * switch off RTS/CTS if it was previously enabled
  2603. */
  2604. sta_priv->lq_sta.lq.general_params.flags &=
  2605. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2606. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2607. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2608. }
  2609. break;
  2610. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2611. buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
  2612. iwlagn_txq_agg_queue_setup(priv, sta, tid, buf_size);
  2613. /*
  2614. * If the limit is 0, then it wasn't initialised yet,
  2615. * use the default. We can do that since we take the
  2616. * minimum below, and we don't want to go above our
  2617. * default due to hardware restrictions.
  2618. */
  2619. if (sta_priv->max_agg_bufsize == 0)
  2620. sta_priv->max_agg_bufsize =
  2621. LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2622. /*
  2623. * Even though in theory the peer could have different
  2624. * aggregation reorder buffer sizes for different sessions,
  2625. * our ucode doesn't allow for that and has a global limit
  2626. * for each station. Therefore, use the minimum of all the
  2627. * aggregation sessions and our default value.
  2628. */
  2629. sta_priv->max_agg_bufsize =
  2630. min(sta_priv->max_agg_bufsize, buf_size);
  2631. if (priv->cfg->ht_params &&
  2632. priv->cfg->ht_params->use_rts_for_aggregation) {
  2633. /*
  2634. * switch to RTS/CTS if it is the prefer protection
  2635. * method for HT traffic
  2636. */
  2637. sta_priv->lq_sta.lq.general_params.flags |=
  2638. LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2639. }
  2640. sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
  2641. sta_priv->max_agg_bufsize;
  2642. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2643. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2644. ret = 0;
  2645. break;
  2646. }
  2647. mutex_unlock(&priv->mutex);
  2648. return ret;
  2649. }
  2650. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  2651. struct ieee80211_vif *vif,
  2652. struct ieee80211_sta *sta)
  2653. {
  2654. struct iwl_priv *priv = hw->priv;
  2655. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  2656. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2657. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2658. int ret;
  2659. u8 sta_id;
  2660. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2661. sta->addr);
  2662. mutex_lock(&priv->mutex);
  2663. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2664. sta->addr);
  2665. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2666. atomic_set(&sta_priv->pending_frames, 0);
  2667. if (vif->type == NL80211_IFTYPE_AP)
  2668. sta_priv->client = true;
  2669. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  2670. is_ap, sta, &sta_id);
  2671. if (ret) {
  2672. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2673. sta->addr, ret);
  2674. /* Should we return success if return code is EEXIST ? */
  2675. mutex_unlock(&priv->mutex);
  2676. return ret;
  2677. }
  2678. sta_priv->common.sta_id = sta_id;
  2679. /* Initialize rate scaling */
  2680. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2681. sta->addr);
  2682. iwl_rs_rate_init(priv, sta, sta_id);
  2683. mutex_unlock(&priv->mutex);
  2684. return 0;
  2685. }
  2686. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  2687. struct ieee80211_channel_switch *ch_switch)
  2688. {
  2689. struct iwl_priv *priv = hw->priv;
  2690. const struct iwl_channel_info *ch_info;
  2691. struct ieee80211_conf *conf = &hw->conf;
  2692. struct ieee80211_channel *channel = ch_switch->channel;
  2693. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  2694. /*
  2695. * MULTI-FIXME
  2696. * When we add support for multiple interfaces, we need to
  2697. * revisit this. The channel switch command in the device
  2698. * only affects the BSS context, but what does that really
  2699. * mean? And what if we get a CSA on the second interface?
  2700. * This needs a lot of work.
  2701. */
  2702. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2703. u16 ch;
  2704. unsigned long flags = 0;
  2705. IWL_DEBUG_MAC80211(priv, "enter\n");
  2706. mutex_lock(&priv->mutex);
  2707. if (iwl_is_rfkill(priv))
  2708. goto out;
  2709. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2710. test_bit(STATUS_SCANNING, &priv->status))
  2711. goto out;
  2712. if (!iwl_is_associated_ctx(ctx))
  2713. goto out;
  2714. /* channel switch in progress */
  2715. if (priv->switch_rxon.switch_in_progress == true)
  2716. goto out;
  2717. if (priv->cfg->ops->lib->set_channel_switch) {
  2718. ch = channel->hw_value;
  2719. if (le16_to_cpu(ctx->active.channel) != ch) {
  2720. ch_info = iwl_get_channel_info(priv,
  2721. channel->band,
  2722. ch);
  2723. if (!is_channel_valid(ch_info)) {
  2724. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  2725. goto out;
  2726. }
  2727. spin_lock_irqsave(&priv->lock, flags);
  2728. priv->current_ht_config.smps = conf->smps_mode;
  2729. /* Configure HT40 channels */
  2730. ctx->ht.enabled = conf_is_ht(conf);
  2731. if (ctx->ht.enabled) {
  2732. if (conf_is_ht40_minus(conf)) {
  2733. ctx->ht.extension_chan_offset =
  2734. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2735. ctx->ht.is_40mhz = true;
  2736. } else if (conf_is_ht40_plus(conf)) {
  2737. ctx->ht.extension_chan_offset =
  2738. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2739. ctx->ht.is_40mhz = true;
  2740. } else {
  2741. ctx->ht.extension_chan_offset =
  2742. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2743. ctx->ht.is_40mhz = false;
  2744. }
  2745. } else
  2746. ctx->ht.is_40mhz = false;
  2747. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2748. ctx->staging.flags = 0;
  2749. iwl_set_rxon_channel(priv, channel, ctx);
  2750. iwl_set_rxon_ht(priv, ht_conf);
  2751. iwl_set_flags_for_band(priv, ctx, channel->band,
  2752. ctx->vif);
  2753. spin_unlock_irqrestore(&priv->lock, flags);
  2754. iwl_set_rate(priv);
  2755. /*
  2756. * at this point, staging_rxon has the
  2757. * configuration for channel switch
  2758. */
  2759. if (priv->cfg->ops->lib->set_channel_switch(priv,
  2760. ch_switch))
  2761. priv->switch_rxon.switch_in_progress = false;
  2762. }
  2763. }
  2764. out:
  2765. mutex_unlock(&priv->mutex);
  2766. if (!priv->switch_rxon.switch_in_progress)
  2767. ieee80211_chswitch_done(ctx->vif, false);
  2768. IWL_DEBUG_MAC80211(priv, "leave\n");
  2769. }
  2770. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  2771. unsigned int changed_flags,
  2772. unsigned int *total_flags,
  2773. u64 multicast)
  2774. {
  2775. struct iwl_priv *priv = hw->priv;
  2776. __le32 filter_or = 0, filter_nand = 0;
  2777. struct iwl_rxon_context *ctx;
  2778. #define CHK(test, flag) do { \
  2779. if (*total_flags & (test)) \
  2780. filter_or |= (flag); \
  2781. else \
  2782. filter_nand |= (flag); \
  2783. } while (0)
  2784. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2785. changed_flags, *total_flags);
  2786. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2787. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2788. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2789. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2790. #undef CHK
  2791. mutex_lock(&priv->mutex);
  2792. for_each_context(priv, ctx) {
  2793. ctx->staging.filter_flags &= ~filter_nand;
  2794. ctx->staging.filter_flags |= filter_or;
  2795. /*
  2796. * Not committing directly because hardware can perform a scan,
  2797. * but we'll eventually commit the filter flags change anyway.
  2798. */
  2799. }
  2800. mutex_unlock(&priv->mutex);
  2801. /*
  2802. * Receiving all multicast frames is always enabled by the
  2803. * default flags setup in iwl_connection_init_rx_config()
  2804. * since we currently do not support programming multicast
  2805. * filters into the device.
  2806. */
  2807. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2808. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2809. }
  2810. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  2811. {
  2812. struct iwl_priv *priv = hw->priv;
  2813. mutex_lock(&priv->mutex);
  2814. IWL_DEBUG_MAC80211(priv, "enter\n");
  2815. /* do not support "flush" */
  2816. if (!priv->cfg->ops->lib->txfifo_flush)
  2817. goto done;
  2818. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2819. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  2820. goto done;
  2821. }
  2822. if (iwl_is_rfkill(priv)) {
  2823. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  2824. goto done;
  2825. }
  2826. /*
  2827. * mac80211 will not push any more frames for transmit
  2828. * until the flush is completed
  2829. */
  2830. if (drop) {
  2831. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  2832. if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
  2833. IWL_ERR(priv, "flush request fail\n");
  2834. goto done;
  2835. }
  2836. }
  2837. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  2838. iwlagn_wait_tx_queue_empty(priv);
  2839. done:
  2840. mutex_unlock(&priv->mutex);
  2841. IWL_DEBUG_MAC80211(priv, "leave\n");
  2842. }
  2843. static void iwlagn_disable_roc(struct iwl_priv *priv)
  2844. {
  2845. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  2846. struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
  2847. lockdep_assert_held(&priv->mutex);
  2848. if (!ctx->is_active)
  2849. return;
  2850. ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
  2851. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2852. iwl_set_rxon_channel(priv, chan, ctx);
  2853. iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
  2854. priv->_agn.hw_roc_channel = NULL;
  2855. iwlcore_commit_rxon(priv, ctx);
  2856. ctx->is_active = false;
  2857. }
  2858. static void iwlagn_bg_roc_done(struct work_struct *work)
  2859. {
  2860. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2861. _agn.hw_roc_work.work);
  2862. mutex_lock(&priv->mutex);
  2863. ieee80211_remain_on_channel_expired(priv->hw);
  2864. iwlagn_disable_roc(priv);
  2865. mutex_unlock(&priv->mutex);
  2866. }
  2867. static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
  2868. struct ieee80211_channel *channel,
  2869. enum nl80211_channel_type channel_type,
  2870. int duration)
  2871. {
  2872. struct iwl_priv *priv = hw->priv;
  2873. int err = 0;
  2874. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2875. return -EOPNOTSUPP;
  2876. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  2877. BIT(NL80211_IFTYPE_P2P_CLIENT)))
  2878. return -EOPNOTSUPP;
  2879. mutex_lock(&priv->mutex);
  2880. if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
  2881. test_bit(STATUS_SCAN_HW, &priv->status)) {
  2882. err = -EBUSY;
  2883. goto out;
  2884. }
  2885. priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
  2886. priv->_agn.hw_roc_channel = channel;
  2887. priv->_agn.hw_roc_chantype = channel_type;
  2888. priv->_agn.hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
  2889. iwlcore_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
  2890. queue_delayed_work(priv->workqueue, &priv->_agn.hw_roc_work,
  2891. msecs_to_jiffies(duration + 20));
  2892. msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
  2893. ieee80211_ready_on_channel(priv->hw);
  2894. out:
  2895. mutex_unlock(&priv->mutex);
  2896. return err;
  2897. }
  2898. static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2899. {
  2900. struct iwl_priv *priv = hw->priv;
  2901. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2902. return -EOPNOTSUPP;
  2903. cancel_delayed_work_sync(&priv->_agn.hw_roc_work);
  2904. mutex_lock(&priv->mutex);
  2905. iwlagn_disable_roc(priv);
  2906. mutex_unlock(&priv->mutex);
  2907. return 0;
  2908. }
  2909. /*****************************************************************************
  2910. *
  2911. * driver setup and teardown
  2912. *
  2913. *****************************************************************************/
  2914. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  2915. {
  2916. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  2917. init_waitqueue_head(&priv->wait_command_queue);
  2918. INIT_WORK(&priv->restart, iwl_bg_restart);
  2919. INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
  2920. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  2921. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  2922. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  2923. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  2924. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  2925. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  2926. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  2927. INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
  2928. iwl_setup_scan_deferred_work(priv);
  2929. if (priv->cfg->ops->lib->setup_deferred_work)
  2930. priv->cfg->ops->lib->setup_deferred_work(priv);
  2931. init_timer(&priv->statistics_periodic);
  2932. priv->statistics_periodic.data = (unsigned long)priv;
  2933. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  2934. init_timer(&priv->ucode_trace);
  2935. priv->ucode_trace.data = (unsigned long)priv;
  2936. priv->ucode_trace.function = iwl_bg_ucode_trace;
  2937. init_timer(&priv->watchdog);
  2938. priv->watchdog.data = (unsigned long)priv;
  2939. priv->watchdog.function = iwl_bg_watchdog;
  2940. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  2941. iwl_irq_tasklet, (unsigned long)priv);
  2942. }
  2943. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  2944. {
  2945. if (priv->cfg->ops->lib->cancel_deferred_work)
  2946. priv->cfg->ops->lib->cancel_deferred_work(priv);
  2947. cancel_delayed_work_sync(&priv->init_alive_start);
  2948. cancel_delayed_work(&priv->alive_start);
  2949. cancel_work_sync(&priv->run_time_calib_work);
  2950. cancel_work_sync(&priv->beacon_update);
  2951. iwl_cancel_scan_deferred_work(priv);
  2952. cancel_work_sync(&priv->bt_full_concurrency);
  2953. cancel_work_sync(&priv->bt_runtime_config);
  2954. del_timer_sync(&priv->statistics_periodic);
  2955. del_timer_sync(&priv->ucode_trace);
  2956. }
  2957. static void iwl_init_hw_rates(struct iwl_priv *priv,
  2958. struct ieee80211_rate *rates)
  2959. {
  2960. int i;
  2961. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  2962. rates[i].bitrate = iwl_rates[i].ieee * 5;
  2963. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2964. rates[i].hw_value_short = i;
  2965. rates[i].flags = 0;
  2966. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  2967. /*
  2968. * If CCK != 1M then set short preamble rate flag.
  2969. */
  2970. rates[i].flags |=
  2971. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  2972. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2973. }
  2974. }
  2975. }
  2976. static int iwl_init_drv(struct iwl_priv *priv)
  2977. {
  2978. int ret;
  2979. spin_lock_init(&priv->sta_lock);
  2980. spin_lock_init(&priv->hcmd_lock);
  2981. INIT_LIST_HEAD(&priv->free_frames);
  2982. mutex_init(&priv->mutex);
  2983. priv->ieee_channels = NULL;
  2984. priv->ieee_rates = NULL;
  2985. priv->band = IEEE80211_BAND_2GHZ;
  2986. priv->iw_mode = NL80211_IFTYPE_STATION;
  2987. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2988. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  2989. priv->_agn.agg_tids_count = 0;
  2990. /* initialize force reset */
  2991. priv->force_reset[IWL_RF_RESET].reset_duration =
  2992. IWL_DELAY_NEXT_FORCE_RF_RESET;
  2993. priv->force_reset[IWL_FW_RESET].reset_duration =
  2994. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  2995. priv->rx_statistics_jiffies = jiffies;
  2996. /* Choose which receivers/antennas to use */
  2997. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2998. priv->cfg->ops->hcmd->set_rxon_chain(priv,
  2999. &priv->contexts[IWL_RXON_CTX_BSS]);
  3000. iwl_init_scan_params(priv);
  3001. /* init bt coex */
  3002. if (priv->cfg->bt_params &&
  3003. priv->cfg->bt_params->advanced_bt_coexist) {
  3004. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  3005. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  3006. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  3007. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  3008. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  3009. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  3010. }
  3011. /* Set the tx_power_user_lmt to the lowest power level
  3012. * this value will get overwritten by channel max power avg
  3013. * from eeprom */
  3014. priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
  3015. priv->tx_power_next = IWLAGN_TX_POWER_TARGET_POWER_MIN;
  3016. ret = iwl_init_channel_map(priv);
  3017. if (ret) {
  3018. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  3019. goto err;
  3020. }
  3021. ret = iwlcore_init_geos(priv);
  3022. if (ret) {
  3023. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  3024. goto err_free_channel_map;
  3025. }
  3026. iwl_init_hw_rates(priv, priv->ieee_rates);
  3027. return 0;
  3028. err_free_channel_map:
  3029. iwl_free_channel_map(priv);
  3030. err:
  3031. return ret;
  3032. }
  3033. static void iwl_uninit_drv(struct iwl_priv *priv)
  3034. {
  3035. iwl_calib_free_results(priv);
  3036. iwlcore_free_geos(priv);
  3037. iwl_free_channel_map(priv);
  3038. kfree(priv->scan_cmd);
  3039. }
  3040. struct ieee80211_ops iwlagn_hw_ops = {
  3041. .tx = iwlagn_mac_tx,
  3042. .start = iwlagn_mac_start,
  3043. .stop = iwlagn_mac_stop,
  3044. .add_interface = iwl_mac_add_interface,
  3045. .remove_interface = iwl_mac_remove_interface,
  3046. .change_interface = iwl_mac_change_interface,
  3047. .config = iwlagn_mac_config,
  3048. .configure_filter = iwlagn_configure_filter,
  3049. .set_key = iwlagn_mac_set_key,
  3050. .update_tkip_key = iwlagn_mac_update_tkip_key,
  3051. .conf_tx = iwl_mac_conf_tx,
  3052. .bss_info_changed = iwlagn_bss_info_changed,
  3053. .ampdu_action = iwlagn_mac_ampdu_action,
  3054. .hw_scan = iwl_mac_hw_scan,
  3055. .sta_notify = iwlagn_mac_sta_notify,
  3056. .sta_add = iwlagn_mac_sta_add,
  3057. .sta_remove = iwl_mac_sta_remove,
  3058. .channel_switch = iwlagn_mac_channel_switch,
  3059. .flush = iwlagn_mac_flush,
  3060. .tx_last_beacon = iwl_mac_tx_last_beacon,
  3061. .remain_on_channel = iwl_mac_remain_on_channel,
  3062. .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
  3063. .offchannel_tx = iwl_mac_offchannel_tx,
  3064. .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
  3065. };
  3066. static u32 iwl_hw_detect(struct iwl_priv *priv)
  3067. {
  3068. u8 rev_id;
  3069. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
  3070. IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
  3071. return iwl_read32(priv, CSR_HW_REV);
  3072. }
  3073. static int iwl_set_hw_params(struct iwl_priv *priv)
  3074. {
  3075. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  3076. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  3077. if (priv->cfg->mod_params->amsdu_size_8K)
  3078. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
  3079. else
  3080. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
  3081. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  3082. if (priv->cfg->mod_params->disable_11n)
  3083. priv->cfg->sku &= ~IWL_SKU_N;
  3084. /* Device-specific setup */
  3085. return priv->cfg->ops->lib->set_hw_params(priv);
  3086. }
  3087. static const u8 iwlagn_bss_ac_to_fifo[] = {
  3088. IWL_TX_FIFO_VO,
  3089. IWL_TX_FIFO_VI,
  3090. IWL_TX_FIFO_BE,
  3091. IWL_TX_FIFO_BK,
  3092. };
  3093. static const u8 iwlagn_bss_ac_to_queue[] = {
  3094. 0, 1, 2, 3,
  3095. };
  3096. static const u8 iwlagn_pan_ac_to_fifo[] = {
  3097. IWL_TX_FIFO_VO_IPAN,
  3098. IWL_TX_FIFO_VI_IPAN,
  3099. IWL_TX_FIFO_BE_IPAN,
  3100. IWL_TX_FIFO_BK_IPAN,
  3101. };
  3102. static const u8 iwlagn_pan_ac_to_queue[] = {
  3103. 7, 6, 5, 4,
  3104. };
  3105. /* This function both allocates and initializes hw and priv. */
  3106. static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
  3107. {
  3108. struct iwl_priv *priv;
  3109. /* mac80211 allocates memory for this device instance, including
  3110. * space for this driver's private structure */
  3111. struct ieee80211_hw *hw;
  3112. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
  3113. if (hw == NULL) {
  3114. pr_err("%s: Can not allocate network device\n",
  3115. cfg->name);
  3116. goto out;
  3117. }
  3118. priv = hw->priv;
  3119. priv->hw = hw;
  3120. out:
  3121. return hw;
  3122. }
  3123. static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3124. {
  3125. int err = 0, i;
  3126. struct iwl_priv *priv;
  3127. struct ieee80211_hw *hw;
  3128. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  3129. unsigned long flags;
  3130. u16 pci_cmd, num_mac;
  3131. u32 hw_rev;
  3132. /************************
  3133. * 1. Allocating HW data
  3134. ************************/
  3135. hw = iwl_alloc_all(cfg);
  3136. if (!hw) {
  3137. err = -ENOMEM;
  3138. goto out;
  3139. }
  3140. priv = hw->priv;
  3141. /* At this point both hw and priv are allocated. */
  3142. /*
  3143. * The default context is always valid,
  3144. * more may be discovered when firmware
  3145. * is loaded.
  3146. */
  3147. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  3148. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  3149. priv->contexts[i].ctxid = i;
  3150. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  3151. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  3152. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  3153. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  3154. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  3155. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  3156. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  3157. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  3158. priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
  3159. priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
  3160. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  3161. BIT(NL80211_IFTYPE_ADHOC);
  3162. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  3163. BIT(NL80211_IFTYPE_STATION);
  3164. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  3165. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  3166. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  3167. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  3168. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  3169. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
  3170. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
  3171. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  3172. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  3173. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  3174. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  3175. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  3176. priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
  3177. priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
  3178. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  3179. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  3180. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  3181. #ifdef CONFIG_IWL_P2P
  3182. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  3183. BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
  3184. #endif
  3185. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  3186. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  3187. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  3188. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  3189. SET_IEEE80211_DEV(hw, &pdev->dev);
  3190. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3191. priv->cfg = cfg;
  3192. priv->pci_dev = pdev;
  3193. priv->inta_mask = CSR_INI_SET_MASK;
  3194. /* is antenna coupling more than 35dB ? */
  3195. priv->bt_ant_couple_ok =
  3196. (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  3197. true : false;
  3198. /* enable/disable bt channel inhibition */
  3199. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  3200. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  3201. (priv->bt_ch_announce) ? "On" : "Off");
  3202. if (iwl_alloc_traffic_mem(priv))
  3203. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3204. /**************************
  3205. * 2. Initializing PCI bus
  3206. **************************/
  3207. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  3208. PCIE_LINK_STATE_CLKPM);
  3209. if (pci_enable_device(pdev)) {
  3210. err = -ENODEV;
  3211. goto out_ieee80211_free_hw;
  3212. }
  3213. pci_set_master(pdev);
  3214. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  3215. if (!err)
  3216. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  3217. if (err) {
  3218. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3219. if (!err)
  3220. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3221. /* both attempts failed: */
  3222. if (err) {
  3223. IWL_WARN(priv, "No suitable DMA available.\n");
  3224. goto out_pci_disable_device;
  3225. }
  3226. }
  3227. err = pci_request_regions(pdev, DRV_NAME);
  3228. if (err)
  3229. goto out_pci_disable_device;
  3230. pci_set_drvdata(pdev, priv);
  3231. /***********************
  3232. * 3. Read REV register
  3233. ***********************/
  3234. priv->hw_base = pci_iomap(pdev, 0, 0);
  3235. if (!priv->hw_base) {
  3236. err = -ENODEV;
  3237. goto out_pci_release_regions;
  3238. }
  3239. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  3240. (unsigned long long) pci_resource_len(pdev, 0));
  3241. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  3242. /* these spin locks will be used in apm_ops.init and EEPROM access
  3243. * we should init now
  3244. */
  3245. spin_lock_init(&priv->reg_lock);
  3246. spin_lock_init(&priv->lock);
  3247. /*
  3248. * stop and reset the on-board processor just in case it is in a
  3249. * strange state ... like being left stranded by a primary kernel
  3250. * and this is now the kdump kernel trying to start up
  3251. */
  3252. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3253. hw_rev = iwl_hw_detect(priv);
  3254. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  3255. priv->cfg->name, hw_rev);
  3256. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3257. * PCI Tx retries from interfering with C3 CPU state */
  3258. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  3259. iwl_prepare_card_hw(priv);
  3260. if (!priv->hw_ready) {
  3261. IWL_WARN(priv, "Failed, HW not ready\n");
  3262. goto out_iounmap;
  3263. }
  3264. /*****************
  3265. * 4. Read EEPROM
  3266. *****************/
  3267. /* Read the EEPROM */
  3268. err = iwl_eeprom_init(priv, hw_rev);
  3269. if (err) {
  3270. IWL_ERR(priv, "Unable to init EEPROM\n");
  3271. goto out_iounmap;
  3272. }
  3273. err = iwl_eeprom_check_version(priv);
  3274. if (err)
  3275. goto out_free_eeprom;
  3276. err = iwl_eeprom_check_sku(priv);
  3277. if (err)
  3278. goto out_free_eeprom;
  3279. /* extract MAC Address */
  3280. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  3281. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  3282. priv->hw->wiphy->addresses = priv->addresses;
  3283. priv->hw->wiphy->n_addresses = 1;
  3284. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  3285. if (num_mac > 1) {
  3286. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  3287. ETH_ALEN);
  3288. priv->addresses[1].addr[5]++;
  3289. priv->hw->wiphy->n_addresses++;
  3290. }
  3291. /************************
  3292. * 5. Setup HW constants
  3293. ************************/
  3294. if (iwl_set_hw_params(priv)) {
  3295. IWL_ERR(priv, "failed to set hw parameters\n");
  3296. goto out_free_eeprom;
  3297. }
  3298. /*******************
  3299. * 6. Setup priv
  3300. *******************/
  3301. err = iwl_init_drv(priv);
  3302. if (err)
  3303. goto out_free_eeprom;
  3304. /* At this point both hw and priv are initialized. */
  3305. /********************
  3306. * 7. Setup services
  3307. ********************/
  3308. spin_lock_irqsave(&priv->lock, flags);
  3309. iwl_disable_interrupts(priv);
  3310. spin_unlock_irqrestore(&priv->lock, flags);
  3311. pci_enable_msi(priv->pci_dev);
  3312. iwl_alloc_isr_ict(priv);
  3313. err = request_irq(priv->pci_dev->irq, iwl_isr_ict,
  3314. IRQF_SHARED, DRV_NAME, priv);
  3315. if (err) {
  3316. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  3317. goto out_disable_msi;
  3318. }
  3319. iwl_setup_deferred_work(priv);
  3320. iwl_setup_rx_handlers(priv);
  3321. /*********************************************
  3322. * 8. Enable interrupts and read RFKILL state
  3323. *********************************************/
  3324. /* enable rfkill interrupt: hw bug w/a */
  3325. pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
  3326. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  3327. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  3328. pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
  3329. }
  3330. iwl_enable_rfkill_int(priv);
  3331. /* If platform's RF_KILL switch is NOT set to KILL */
  3332. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3333. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3334. else
  3335. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3336. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  3337. test_bit(STATUS_RF_KILL_HW, &priv->status));
  3338. iwl_power_initialize(priv);
  3339. iwl_tt_initialize(priv);
  3340. init_completion(&priv->_agn.firmware_loading_complete);
  3341. err = iwl_request_firmware(priv, true);
  3342. if (err)
  3343. goto out_destroy_workqueue;
  3344. return 0;
  3345. out_destroy_workqueue:
  3346. destroy_workqueue(priv->workqueue);
  3347. priv->workqueue = NULL;
  3348. free_irq(priv->pci_dev->irq, priv);
  3349. iwl_free_isr_ict(priv);
  3350. out_disable_msi:
  3351. pci_disable_msi(priv->pci_dev);
  3352. iwl_uninit_drv(priv);
  3353. out_free_eeprom:
  3354. iwl_eeprom_free(priv);
  3355. out_iounmap:
  3356. pci_iounmap(pdev, priv->hw_base);
  3357. out_pci_release_regions:
  3358. pci_set_drvdata(pdev, NULL);
  3359. pci_release_regions(pdev);
  3360. out_pci_disable_device:
  3361. pci_disable_device(pdev);
  3362. out_ieee80211_free_hw:
  3363. iwl_free_traffic_mem(priv);
  3364. ieee80211_free_hw(priv->hw);
  3365. out:
  3366. return err;
  3367. }
  3368. static void __devexit iwl_pci_remove(struct pci_dev *pdev)
  3369. {
  3370. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3371. unsigned long flags;
  3372. if (!priv)
  3373. return;
  3374. wait_for_completion(&priv->_agn.firmware_loading_complete);
  3375. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3376. iwl_dbgfs_unregister(priv);
  3377. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  3378. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  3379. * to be called and iwl_down since we are removing the device
  3380. * we need to set STATUS_EXIT_PENDING bit.
  3381. */
  3382. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3383. iwl_leds_exit(priv);
  3384. if (priv->mac80211_registered) {
  3385. ieee80211_unregister_hw(priv->hw);
  3386. priv->mac80211_registered = 0;
  3387. } else {
  3388. iwl_down(priv);
  3389. }
  3390. /*
  3391. * Make sure device is reset to low power before unloading driver.
  3392. * This may be redundant with iwl_down(), but there are paths to
  3393. * run iwl_down() without calling apm_ops.stop(), and there are
  3394. * paths to avoid running iwl_down() at all before leaving driver.
  3395. * This (inexpensive) call *makes sure* device is reset.
  3396. */
  3397. iwl_apm_stop(priv);
  3398. iwl_tt_exit(priv);
  3399. /* make sure we flush any pending irq or
  3400. * tasklet for the driver
  3401. */
  3402. spin_lock_irqsave(&priv->lock, flags);
  3403. iwl_disable_interrupts(priv);
  3404. spin_unlock_irqrestore(&priv->lock, flags);
  3405. iwl_synchronize_irq(priv);
  3406. iwl_dealloc_ucode_pci(priv);
  3407. if (priv->rxq.bd)
  3408. iwlagn_rx_queue_free(priv, &priv->rxq);
  3409. iwlagn_hw_txq_ctx_free(priv);
  3410. iwl_eeprom_free(priv);
  3411. /*netif_stop_queue(dev); */
  3412. flush_workqueue(priv->workqueue);
  3413. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  3414. * priv->workqueue... so we can't take down the workqueue
  3415. * until now... */
  3416. destroy_workqueue(priv->workqueue);
  3417. priv->workqueue = NULL;
  3418. iwl_free_traffic_mem(priv);
  3419. free_irq(priv->pci_dev->irq, priv);
  3420. pci_disable_msi(priv->pci_dev);
  3421. pci_iounmap(pdev, priv->hw_base);
  3422. pci_release_regions(pdev);
  3423. pci_disable_device(pdev);
  3424. pci_set_drvdata(pdev, NULL);
  3425. iwl_uninit_drv(priv);
  3426. iwl_free_isr_ict(priv);
  3427. dev_kfree_skb(priv->beacon_skb);
  3428. ieee80211_free_hw(priv->hw);
  3429. }
  3430. /*****************************************************************************
  3431. *
  3432. * driver and module entry point
  3433. *
  3434. *****************************************************************************/
  3435. /* Hardware specific file defines the PCI IDs table for that hardware module */
  3436. static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
  3437. {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
  3438. {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
  3439. {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
  3440. {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
  3441. {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
  3442. {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3443. {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
  3444. {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
  3445. {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
  3446. {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
  3447. {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
  3448. {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
  3449. {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
  3450. {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3451. {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
  3452. {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
  3453. {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
  3454. {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
  3455. {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
  3456. {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
  3457. {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
  3458. {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3459. {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
  3460. {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
  3461. /* 5300 Series WiFi */
  3462. {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
  3463. {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
  3464. {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
  3465. {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
  3466. {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
  3467. {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
  3468. {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
  3469. {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
  3470. {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
  3471. {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
  3472. {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
  3473. {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
  3474. /* 5350 Series WiFi/WiMax */
  3475. {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
  3476. {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
  3477. {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
  3478. /* 5150 Series Wifi/WiMax */
  3479. {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
  3480. {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
  3481. {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
  3482. {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
  3483. {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
  3484. {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
  3485. {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
  3486. {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
  3487. {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
  3488. {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
  3489. /* 6x00 Series */
  3490. {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
  3491. {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
  3492. {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
  3493. {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
  3494. {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
  3495. {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
  3496. {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
  3497. {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
  3498. {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
  3499. {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
  3500. /* 6x05 Series */
  3501. {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)},
  3502. {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)},
  3503. {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)},
  3504. {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)},
  3505. {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)},
  3506. {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)},
  3507. {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)},
  3508. /* 6x30 Series */
  3509. {IWL_PCI_DEVICE(0x008A, 0x5305, iwl1030_bgn_cfg)},
  3510. {IWL_PCI_DEVICE(0x008A, 0x5307, iwl1030_bg_cfg)},
  3511. {IWL_PCI_DEVICE(0x008A, 0x5325, iwl1030_bgn_cfg)},
  3512. {IWL_PCI_DEVICE(0x008A, 0x5327, iwl1030_bg_cfg)},
  3513. {IWL_PCI_DEVICE(0x008B, 0x5315, iwl1030_bgn_cfg)},
  3514. {IWL_PCI_DEVICE(0x008B, 0x5317, iwl1030_bg_cfg)},
  3515. {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6030_2agn_cfg)},
  3516. {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6030_2bgn_cfg)},
  3517. {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6030_2abg_cfg)},
  3518. {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6030_2agn_cfg)},
  3519. {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6030_2bgn_cfg)},
  3520. {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6030_2abg_cfg)},
  3521. {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6030_2bg_cfg)},
  3522. {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6030_2agn_cfg)},
  3523. {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6030_2bgn_cfg)},
  3524. {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6030_2abg_cfg)},
  3525. /* 6x50 WiFi/WiMax Series */
  3526. {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
  3527. {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
  3528. {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
  3529. {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
  3530. {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
  3531. {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
  3532. /* 6150 WiFi/WiMax Series */
  3533. {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6150_bgn_cfg)},
  3534. {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6150_bgn_cfg)},
  3535. {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6150_bgn_cfg)},
  3536. {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6150_bgn_cfg)},
  3537. {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6150_bgn_cfg)},
  3538. {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6150_bgn_cfg)},
  3539. /* 1000 Series WiFi */
  3540. {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
  3541. {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
  3542. {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
  3543. {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
  3544. {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
  3545. {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
  3546. {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
  3547. {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
  3548. {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
  3549. {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
  3550. {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
  3551. {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
  3552. /* 100 Series WiFi */
  3553. {IWL_PCI_DEVICE(0x08AE, 0x1005, iwl100_bgn_cfg)},
  3554. {IWL_PCI_DEVICE(0x08AE, 0x1007, iwl100_bg_cfg)},
  3555. {IWL_PCI_DEVICE(0x08AF, 0x1015, iwl100_bgn_cfg)},
  3556. {IWL_PCI_DEVICE(0x08AF, 0x1017, iwl100_bg_cfg)},
  3557. {IWL_PCI_DEVICE(0x08AE, 0x1025, iwl100_bgn_cfg)},
  3558. {IWL_PCI_DEVICE(0x08AE, 0x1027, iwl100_bg_cfg)},
  3559. /* 130 Series WiFi */
  3560. {IWL_PCI_DEVICE(0x0896, 0x5005, iwl130_bgn_cfg)},
  3561. {IWL_PCI_DEVICE(0x0896, 0x5007, iwl130_bg_cfg)},
  3562. {IWL_PCI_DEVICE(0x0897, 0x5015, iwl130_bgn_cfg)},
  3563. {IWL_PCI_DEVICE(0x0897, 0x5017, iwl130_bg_cfg)},
  3564. {IWL_PCI_DEVICE(0x0896, 0x5025, iwl130_bgn_cfg)},
  3565. {IWL_PCI_DEVICE(0x0896, 0x5027, iwl130_bg_cfg)},
  3566. /* 2x00 Series */
  3567. {IWL_PCI_DEVICE(0x0890, 0x4022, iwl2000_2bgn_cfg)},
  3568. {IWL_PCI_DEVICE(0x0891, 0x4222, iwl2000_2bgn_cfg)},
  3569. {IWL_PCI_DEVICE(0x0890, 0x4422, iwl2000_2bgn_cfg)},
  3570. {IWL_PCI_DEVICE(0x0890, 0x4026, iwl2000_2bg_cfg)},
  3571. {IWL_PCI_DEVICE(0x0891, 0x4226, iwl2000_2bg_cfg)},
  3572. {IWL_PCI_DEVICE(0x0890, 0x4426, iwl2000_2bg_cfg)},
  3573. /* 2x30 Series */
  3574. {IWL_PCI_DEVICE(0x0887, 0x4062, iwl2030_2bgn_cfg)},
  3575. {IWL_PCI_DEVICE(0x0888, 0x4262, iwl2030_2bgn_cfg)},
  3576. {IWL_PCI_DEVICE(0x0887, 0x4462, iwl2030_2bgn_cfg)},
  3577. {IWL_PCI_DEVICE(0x0887, 0x4066, iwl2030_2bg_cfg)},
  3578. {IWL_PCI_DEVICE(0x0888, 0x4266, iwl2030_2bg_cfg)},
  3579. {IWL_PCI_DEVICE(0x0887, 0x4466, iwl2030_2bg_cfg)},
  3580. /* 6x35 Series */
  3581. {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)},
  3582. {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)},
  3583. {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)},
  3584. {IWL_PCI_DEVICE(0x088E, 0x4064, iwl6035_2abg_cfg)},
  3585. {IWL_PCI_DEVICE(0x088F, 0x4264, iwl6035_2abg_cfg)},
  3586. {IWL_PCI_DEVICE(0x088E, 0x4464, iwl6035_2abg_cfg)},
  3587. {IWL_PCI_DEVICE(0x088E, 0x4066, iwl6035_2bg_cfg)},
  3588. {IWL_PCI_DEVICE(0x088F, 0x4266, iwl6035_2bg_cfg)},
  3589. {IWL_PCI_DEVICE(0x088E, 0x4466, iwl6035_2bg_cfg)},
  3590. /* 200 Series */
  3591. {IWL_PCI_DEVICE(0x0894, 0x0022, iwl200_bgn_cfg)},
  3592. {IWL_PCI_DEVICE(0x0895, 0x0222, iwl200_bgn_cfg)},
  3593. {IWL_PCI_DEVICE(0x0894, 0x0422, iwl200_bgn_cfg)},
  3594. {IWL_PCI_DEVICE(0x0894, 0x0026, iwl200_bg_cfg)},
  3595. {IWL_PCI_DEVICE(0x0895, 0x0226, iwl200_bg_cfg)},
  3596. {IWL_PCI_DEVICE(0x0894, 0x0426, iwl200_bg_cfg)},
  3597. /* 230 Series */
  3598. {IWL_PCI_DEVICE(0x0892, 0x0062, iwl230_bgn_cfg)},
  3599. {IWL_PCI_DEVICE(0x0893, 0x0262, iwl230_bgn_cfg)},
  3600. {IWL_PCI_DEVICE(0x0892, 0x0462, iwl230_bgn_cfg)},
  3601. {IWL_PCI_DEVICE(0x0892, 0x0066, iwl230_bg_cfg)},
  3602. {IWL_PCI_DEVICE(0x0893, 0x0266, iwl230_bg_cfg)},
  3603. {IWL_PCI_DEVICE(0x0892, 0x0466, iwl230_bg_cfg)},
  3604. {0}
  3605. };
  3606. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  3607. static struct pci_driver iwl_driver = {
  3608. .name = DRV_NAME,
  3609. .id_table = iwl_hw_card_ids,
  3610. .probe = iwl_pci_probe,
  3611. .remove = __devexit_p(iwl_pci_remove),
  3612. .driver.pm = IWL_PM_OPS,
  3613. };
  3614. static int __init iwl_init(void)
  3615. {
  3616. int ret;
  3617. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3618. pr_info(DRV_COPYRIGHT "\n");
  3619. ret = iwlagn_rate_control_register();
  3620. if (ret) {
  3621. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3622. return ret;
  3623. }
  3624. ret = pci_register_driver(&iwl_driver);
  3625. if (ret) {
  3626. pr_err("Unable to initialize PCI module\n");
  3627. goto error_register;
  3628. }
  3629. return ret;
  3630. error_register:
  3631. iwlagn_rate_control_unregister();
  3632. return ret;
  3633. }
  3634. static void __exit iwl_exit(void)
  3635. {
  3636. pci_unregister_driver(&iwl_driver);
  3637. iwlagn_rate_control_unregister();
  3638. }
  3639. module_exit(iwl_exit);
  3640. module_init(iwl_init);
  3641. #ifdef CONFIG_IWLWIFI_DEBUG
  3642. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3643. MODULE_PARM_DESC(debug, "debug output mask");
  3644. #endif
  3645. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  3646. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  3647. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  3648. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  3649. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  3650. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  3651. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  3652. int, S_IRUGO);
  3653. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  3654. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  3655. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  3656. module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
  3657. S_IRUGO);
  3658. MODULE_PARM_DESC(ucode_alternative,
  3659. "specify ucode alternative to use from ucode file");
  3660. module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
  3661. MODULE_PARM_DESC(antenna_coupling,
  3662. "specify antenna coupling in dB (defualt: 0 dB)");
  3663. module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
  3664. MODULE_PARM_DESC(bt_ch_inhibition,
  3665. "Disable BT channel inhibition (default: enable)");
  3666. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  3667. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  3668. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  3669. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");