iwl-agn.c 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220
  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, w->fn_data);
  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. /* tasklet for iwlagn interrupt */
  708. static void iwl_irq_tasklet(struct iwl_priv *priv)
  709. {
  710. u32 inta = 0;
  711. u32 handled = 0;
  712. unsigned long flags;
  713. u32 i;
  714. #ifdef CONFIG_IWLWIFI_DEBUG
  715. u32 inta_mask;
  716. #endif
  717. spin_lock_irqsave(&priv->lock, flags);
  718. /* Ack/clear/reset pending uCode interrupts.
  719. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  720. */
  721. /* There is a hardware bug in the interrupt mask function that some
  722. * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
  723. * they are disabled in the CSR_INT_MASK register. Furthermore the
  724. * ICT interrupt handling mechanism has another bug that might cause
  725. * these unmasked interrupts fail to be detected. We workaround the
  726. * hardware bugs here by ACKing all the possible interrupts so that
  727. * interrupt coalescing can still be achieved.
  728. */
  729. iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
  730. inta = priv->_agn.inta;
  731. #ifdef CONFIG_IWLWIFI_DEBUG
  732. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  733. /* just for debug */
  734. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  735. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
  736. inta, inta_mask);
  737. }
  738. #endif
  739. spin_unlock_irqrestore(&priv->lock, flags);
  740. /* saved interrupt in inta variable now we can reset priv->_agn.inta */
  741. priv->_agn.inta = 0;
  742. /* Now service all interrupt bits discovered above. */
  743. if (inta & CSR_INT_BIT_HW_ERR) {
  744. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  745. /* Tell the device to stop sending interrupts */
  746. iwl_disable_interrupts(priv);
  747. priv->isr_stats.hw++;
  748. iwl_irq_handle_error(priv);
  749. handled |= CSR_INT_BIT_HW_ERR;
  750. return;
  751. }
  752. #ifdef CONFIG_IWLWIFI_DEBUG
  753. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  754. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  755. if (inta & CSR_INT_BIT_SCD) {
  756. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  757. "the frame/frames.\n");
  758. priv->isr_stats.sch++;
  759. }
  760. /* Alive notification via Rx interrupt will do the real work */
  761. if (inta & CSR_INT_BIT_ALIVE) {
  762. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  763. priv->isr_stats.alive++;
  764. }
  765. }
  766. #endif
  767. /* Safely ignore these bits for debug checks below */
  768. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  769. /* HW RF KILL switch toggled */
  770. if (inta & CSR_INT_BIT_RF_KILL) {
  771. int hw_rf_kill = 0;
  772. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  773. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  774. hw_rf_kill = 1;
  775. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  776. hw_rf_kill ? "disable radio" : "enable radio");
  777. priv->isr_stats.rfkill++;
  778. /* driver only loads ucode once setting the interface up.
  779. * the driver allows loading the ucode even if the radio
  780. * is killed. Hence update the killswitch state here. The
  781. * rfkill handler will care about restarting if needed.
  782. */
  783. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  784. if (hw_rf_kill)
  785. set_bit(STATUS_RF_KILL_HW, &priv->status);
  786. else
  787. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  788. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  789. }
  790. handled |= CSR_INT_BIT_RF_KILL;
  791. }
  792. /* Chip got too hot and stopped itself */
  793. if (inta & CSR_INT_BIT_CT_KILL) {
  794. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  795. priv->isr_stats.ctkill++;
  796. handled |= CSR_INT_BIT_CT_KILL;
  797. }
  798. /* Error detected by uCode */
  799. if (inta & CSR_INT_BIT_SW_ERR) {
  800. IWL_ERR(priv, "Microcode SW error detected. "
  801. " Restarting 0x%X.\n", inta);
  802. priv->isr_stats.sw++;
  803. iwl_irq_handle_error(priv);
  804. handled |= CSR_INT_BIT_SW_ERR;
  805. }
  806. /* uCode wakes up after power-down sleep */
  807. if (inta & CSR_INT_BIT_WAKEUP) {
  808. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  809. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  810. for (i = 0; i < priv->hw_params.max_txq_num; i++)
  811. iwl_txq_update_write_ptr(priv, &priv->txq[i]);
  812. priv->isr_stats.wakeup++;
  813. handled |= CSR_INT_BIT_WAKEUP;
  814. }
  815. /* All uCode command responses, including Tx command responses,
  816. * Rx "responses" (frame-received notification), and other
  817. * notifications from uCode come through here*/
  818. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
  819. CSR_INT_BIT_RX_PERIODIC)) {
  820. IWL_DEBUG_ISR(priv, "Rx interrupt\n");
  821. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  822. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  823. iwl_write32(priv, CSR_FH_INT_STATUS,
  824. CSR_FH_INT_RX_MASK);
  825. }
  826. if (inta & CSR_INT_BIT_RX_PERIODIC) {
  827. handled |= CSR_INT_BIT_RX_PERIODIC;
  828. iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
  829. }
  830. /* Sending RX interrupt require many steps to be done in the
  831. * the device:
  832. * 1- write interrupt to current index in ICT table.
  833. * 2- dma RX frame.
  834. * 3- update RX shared data to indicate last write index.
  835. * 4- send interrupt.
  836. * This could lead to RX race, driver could receive RX interrupt
  837. * but the shared data changes does not reflect this;
  838. * periodic interrupt will detect any dangling Rx activity.
  839. */
  840. /* Disable periodic interrupt; we use it as just a one-shot. */
  841. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  842. CSR_INT_PERIODIC_DIS);
  843. iwl_rx_handle(priv);
  844. /*
  845. * Enable periodic interrupt in 8 msec only if we received
  846. * real RX interrupt (instead of just periodic int), to catch
  847. * any dangling Rx interrupt. If it was just the periodic
  848. * interrupt, there was no dangling Rx activity, and no need
  849. * to extend the periodic interrupt; one-shot is enough.
  850. */
  851. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
  852. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  853. CSR_INT_PERIODIC_ENA);
  854. priv->isr_stats.rx++;
  855. }
  856. /* This "Tx" DMA channel is used only for loading uCode */
  857. if (inta & CSR_INT_BIT_FH_TX) {
  858. iwl_write32(priv, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
  859. IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
  860. priv->isr_stats.tx++;
  861. handled |= CSR_INT_BIT_FH_TX;
  862. /* Wake up uCode load routine, now that load is complete */
  863. priv->ucode_write_complete = 1;
  864. wake_up_interruptible(&priv->wait_command_queue);
  865. }
  866. if (inta & ~handled) {
  867. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  868. priv->isr_stats.unhandled++;
  869. }
  870. if (inta & ~(priv->inta_mask)) {
  871. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  872. inta & ~priv->inta_mask);
  873. }
  874. /* Re-enable all interrupts */
  875. /* only Re-enable if disabled by irq */
  876. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  877. iwl_enable_interrupts(priv);
  878. /* Re-enable RF_KILL if it occurred */
  879. else if (handled & CSR_INT_BIT_RF_KILL)
  880. iwl_enable_rfkill_int(priv);
  881. }
  882. /*****************************************************************************
  883. *
  884. * sysfs attributes
  885. *
  886. *****************************************************************************/
  887. #ifdef CONFIG_IWLWIFI_DEBUG
  888. /*
  889. * The following adds a new attribute to the sysfs representation
  890. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  891. * used for controlling the debug level.
  892. *
  893. * See the level definitions in iwl for details.
  894. *
  895. * The debug_level being managed using sysfs below is a per device debug
  896. * level that is used instead of the global debug level if it (the per
  897. * device debug level) is set.
  898. */
  899. static ssize_t show_debug_level(struct device *d,
  900. struct device_attribute *attr, char *buf)
  901. {
  902. struct iwl_priv *priv = dev_get_drvdata(d);
  903. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  904. }
  905. static ssize_t store_debug_level(struct device *d,
  906. struct device_attribute *attr,
  907. const char *buf, size_t count)
  908. {
  909. struct iwl_priv *priv = dev_get_drvdata(d);
  910. unsigned long val;
  911. int ret;
  912. ret = strict_strtoul(buf, 0, &val);
  913. if (ret)
  914. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  915. else {
  916. priv->debug_level = val;
  917. if (iwl_alloc_traffic_mem(priv))
  918. IWL_ERR(priv,
  919. "Not enough memory to generate traffic log\n");
  920. }
  921. return strnlen(buf, count);
  922. }
  923. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  924. show_debug_level, store_debug_level);
  925. #endif /* CONFIG_IWLWIFI_DEBUG */
  926. static ssize_t show_temperature(struct device *d,
  927. struct device_attribute *attr, char *buf)
  928. {
  929. struct iwl_priv *priv = dev_get_drvdata(d);
  930. if (!iwl_is_alive(priv))
  931. return -EAGAIN;
  932. return sprintf(buf, "%d\n", priv->temperature);
  933. }
  934. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  935. static ssize_t show_tx_power(struct device *d,
  936. struct device_attribute *attr, char *buf)
  937. {
  938. struct iwl_priv *priv = dev_get_drvdata(d);
  939. if (!iwl_is_ready_rf(priv))
  940. return sprintf(buf, "off\n");
  941. else
  942. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  943. }
  944. static ssize_t store_tx_power(struct device *d,
  945. struct device_attribute *attr,
  946. const char *buf, size_t count)
  947. {
  948. struct iwl_priv *priv = dev_get_drvdata(d);
  949. unsigned long val;
  950. int ret;
  951. ret = strict_strtoul(buf, 10, &val);
  952. if (ret)
  953. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  954. else {
  955. ret = iwl_set_tx_power(priv, val, false);
  956. if (ret)
  957. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  958. ret);
  959. else
  960. ret = count;
  961. }
  962. return ret;
  963. }
  964. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  965. static struct attribute *iwl_sysfs_entries[] = {
  966. &dev_attr_temperature.attr,
  967. &dev_attr_tx_power.attr,
  968. #ifdef CONFIG_IWLWIFI_DEBUG
  969. &dev_attr_debug_level.attr,
  970. #endif
  971. NULL
  972. };
  973. static struct attribute_group iwl_attribute_group = {
  974. .name = NULL, /* put in device directory */
  975. .attrs = iwl_sysfs_entries,
  976. };
  977. /******************************************************************************
  978. *
  979. * uCode download functions
  980. *
  981. ******************************************************************************/
  982. static void iwl_free_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
  983. {
  984. if (desc->v_addr)
  985. dma_free_coherent(&pci_dev->dev, desc->len,
  986. desc->v_addr, desc->p_addr);
  987. desc->v_addr = NULL;
  988. desc->len = 0;
  989. }
  990. static void iwl_free_fw_img(struct pci_dev *pci_dev, struct fw_img *img)
  991. {
  992. iwl_free_fw_desc(pci_dev, &img->code);
  993. iwl_free_fw_desc(pci_dev, &img->data);
  994. }
  995. static int iwl_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc,
  996. const void *data, size_t len)
  997. {
  998. if (!len) {
  999. desc->v_addr = NULL;
  1000. return -EINVAL;
  1001. }
  1002. desc->v_addr = dma_alloc_coherent(&pci_dev->dev, len,
  1003. &desc->p_addr, GFP_KERNEL);
  1004. if (!desc->v_addr)
  1005. return -ENOMEM;
  1006. desc->len = len;
  1007. memcpy(desc->v_addr, data, len);
  1008. return 0;
  1009. }
  1010. static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
  1011. {
  1012. iwl_free_fw_img(priv->pci_dev, &priv->ucode_rt);
  1013. iwl_free_fw_img(priv->pci_dev, &priv->ucode_init);
  1014. }
  1015. struct iwlagn_ucode_capabilities {
  1016. u32 max_probe_length;
  1017. u32 standard_phy_calibration_size;
  1018. u32 flags;
  1019. };
  1020. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  1021. static int iwl_mac_setup_register(struct iwl_priv *priv,
  1022. struct iwlagn_ucode_capabilities *capa);
  1023. #define UCODE_EXPERIMENTAL_INDEX 100
  1024. #define UCODE_EXPERIMENTAL_TAG "exp"
  1025. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  1026. {
  1027. const char *name_pre = priv->cfg->fw_name_pre;
  1028. char tag[8];
  1029. if (first) {
  1030. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  1031. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  1032. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  1033. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  1034. #endif
  1035. priv->fw_index = priv->cfg->ucode_api_max;
  1036. sprintf(tag, "%d", priv->fw_index);
  1037. } else {
  1038. priv->fw_index--;
  1039. sprintf(tag, "%d", priv->fw_index);
  1040. }
  1041. if (priv->fw_index < priv->cfg->ucode_api_min) {
  1042. IWL_ERR(priv, "no suitable firmware found!\n");
  1043. return -ENOENT;
  1044. }
  1045. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  1046. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  1047. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1048. ? "EXPERIMENTAL " : "",
  1049. priv->firmware_name);
  1050. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  1051. &priv->pci_dev->dev, GFP_KERNEL, priv,
  1052. iwl_ucode_callback);
  1053. }
  1054. struct iwlagn_firmware_pieces {
  1055. const void *inst, *data, *init, *init_data;
  1056. size_t inst_size, data_size, init_size, init_data_size;
  1057. u32 build;
  1058. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1059. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1060. };
  1061. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  1062. const struct firmware *ucode_raw,
  1063. struct iwlagn_firmware_pieces *pieces)
  1064. {
  1065. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  1066. u32 api_ver, hdr_size;
  1067. const u8 *src;
  1068. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1069. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1070. switch (api_ver) {
  1071. default:
  1072. hdr_size = 28;
  1073. if (ucode_raw->size < hdr_size) {
  1074. IWL_ERR(priv, "File size too small!\n");
  1075. return -EINVAL;
  1076. }
  1077. pieces->build = le32_to_cpu(ucode->u.v2.build);
  1078. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  1079. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  1080. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  1081. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  1082. src = ucode->u.v2.data;
  1083. break;
  1084. case 0:
  1085. case 1:
  1086. case 2:
  1087. hdr_size = 24;
  1088. if (ucode_raw->size < hdr_size) {
  1089. IWL_ERR(priv, "File size too small!\n");
  1090. return -EINVAL;
  1091. }
  1092. pieces->build = 0;
  1093. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  1094. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  1095. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  1096. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  1097. src = ucode->u.v1.data;
  1098. break;
  1099. }
  1100. /* Verify size of file vs. image size info in file's header */
  1101. if (ucode_raw->size != hdr_size + pieces->inst_size +
  1102. pieces->data_size + pieces->init_size +
  1103. pieces->init_data_size) {
  1104. IWL_ERR(priv,
  1105. "uCode file size %d does not match expected size\n",
  1106. (int)ucode_raw->size);
  1107. return -EINVAL;
  1108. }
  1109. pieces->inst = src;
  1110. src += pieces->inst_size;
  1111. pieces->data = src;
  1112. src += pieces->data_size;
  1113. pieces->init = src;
  1114. src += pieces->init_size;
  1115. pieces->init_data = src;
  1116. src += pieces->init_data_size;
  1117. return 0;
  1118. }
  1119. static int iwlagn_wanted_ucode_alternative = 1;
  1120. static int iwlagn_load_firmware(struct iwl_priv *priv,
  1121. const struct firmware *ucode_raw,
  1122. struct iwlagn_firmware_pieces *pieces,
  1123. struct iwlagn_ucode_capabilities *capa)
  1124. {
  1125. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  1126. struct iwl_ucode_tlv *tlv;
  1127. size_t len = ucode_raw->size;
  1128. const u8 *data;
  1129. int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
  1130. u64 alternatives;
  1131. u32 tlv_len;
  1132. enum iwl_ucode_tlv_type tlv_type;
  1133. const u8 *tlv_data;
  1134. if (len < sizeof(*ucode)) {
  1135. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  1136. return -EINVAL;
  1137. }
  1138. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  1139. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  1140. le32_to_cpu(ucode->magic));
  1141. return -EINVAL;
  1142. }
  1143. /*
  1144. * Check which alternatives are present, and "downgrade"
  1145. * when the chosen alternative is not present, warning
  1146. * the user when that happens. Some files may not have
  1147. * any alternatives, so don't warn in that case.
  1148. */
  1149. alternatives = le64_to_cpu(ucode->alternatives);
  1150. tmp = wanted_alternative;
  1151. if (wanted_alternative > 63)
  1152. wanted_alternative = 63;
  1153. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  1154. wanted_alternative--;
  1155. if (wanted_alternative && wanted_alternative != tmp)
  1156. IWL_WARN(priv,
  1157. "uCode alternative %d not available, choosing %d\n",
  1158. tmp, wanted_alternative);
  1159. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1160. pieces->build = le32_to_cpu(ucode->build);
  1161. data = ucode->data;
  1162. len -= sizeof(*ucode);
  1163. while (len >= sizeof(*tlv)) {
  1164. u16 tlv_alt;
  1165. len -= sizeof(*tlv);
  1166. tlv = (void *)data;
  1167. tlv_len = le32_to_cpu(tlv->length);
  1168. tlv_type = le16_to_cpu(tlv->type);
  1169. tlv_alt = le16_to_cpu(tlv->alternative);
  1170. tlv_data = tlv->data;
  1171. if (len < tlv_len) {
  1172. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  1173. len, tlv_len);
  1174. return -EINVAL;
  1175. }
  1176. len -= ALIGN(tlv_len, 4);
  1177. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  1178. /*
  1179. * Alternative 0 is always valid.
  1180. *
  1181. * Skip alternative TLVs that are not selected.
  1182. */
  1183. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  1184. continue;
  1185. switch (tlv_type) {
  1186. case IWL_UCODE_TLV_INST:
  1187. pieces->inst = tlv_data;
  1188. pieces->inst_size = tlv_len;
  1189. break;
  1190. case IWL_UCODE_TLV_DATA:
  1191. pieces->data = tlv_data;
  1192. pieces->data_size = tlv_len;
  1193. break;
  1194. case IWL_UCODE_TLV_INIT:
  1195. pieces->init = tlv_data;
  1196. pieces->init_size = tlv_len;
  1197. break;
  1198. case IWL_UCODE_TLV_INIT_DATA:
  1199. pieces->init_data = tlv_data;
  1200. pieces->init_data_size = tlv_len;
  1201. break;
  1202. case IWL_UCODE_TLV_BOOT:
  1203. IWL_ERR(priv, "Found unexpected BOOT ucode\n");
  1204. break;
  1205. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  1206. if (tlv_len != sizeof(u32))
  1207. goto invalid_tlv_len;
  1208. capa->max_probe_length =
  1209. le32_to_cpup((__le32 *)tlv_data);
  1210. break;
  1211. case IWL_UCODE_TLV_PAN:
  1212. if (tlv_len)
  1213. goto invalid_tlv_len;
  1214. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  1215. break;
  1216. case IWL_UCODE_TLV_FLAGS:
  1217. /* must be at least one u32 */
  1218. if (tlv_len < sizeof(u32))
  1219. goto invalid_tlv_len;
  1220. /* and a proper number of u32s */
  1221. if (tlv_len % sizeof(u32))
  1222. goto invalid_tlv_len;
  1223. /*
  1224. * This driver only reads the first u32 as
  1225. * right now no more features are defined,
  1226. * if that changes then either the driver
  1227. * will not work with the new firmware, or
  1228. * it'll not take advantage of new features.
  1229. */
  1230. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  1231. break;
  1232. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  1233. if (tlv_len != sizeof(u32))
  1234. goto invalid_tlv_len;
  1235. pieces->init_evtlog_ptr =
  1236. le32_to_cpup((__le32 *)tlv_data);
  1237. break;
  1238. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  1239. if (tlv_len != sizeof(u32))
  1240. goto invalid_tlv_len;
  1241. pieces->init_evtlog_size =
  1242. le32_to_cpup((__le32 *)tlv_data);
  1243. break;
  1244. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  1245. if (tlv_len != sizeof(u32))
  1246. goto invalid_tlv_len;
  1247. pieces->init_errlog_ptr =
  1248. le32_to_cpup((__le32 *)tlv_data);
  1249. break;
  1250. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  1251. if (tlv_len != sizeof(u32))
  1252. goto invalid_tlv_len;
  1253. pieces->inst_evtlog_ptr =
  1254. le32_to_cpup((__le32 *)tlv_data);
  1255. break;
  1256. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  1257. if (tlv_len != sizeof(u32))
  1258. goto invalid_tlv_len;
  1259. pieces->inst_evtlog_size =
  1260. le32_to_cpup((__le32 *)tlv_data);
  1261. break;
  1262. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  1263. if (tlv_len != sizeof(u32))
  1264. goto invalid_tlv_len;
  1265. pieces->inst_errlog_ptr =
  1266. le32_to_cpup((__le32 *)tlv_data);
  1267. break;
  1268. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  1269. if (tlv_len)
  1270. goto invalid_tlv_len;
  1271. priv->enhance_sensitivity_table = true;
  1272. break;
  1273. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  1274. if (tlv_len != sizeof(u32))
  1275. goto invalid_tlv_len;
  1276. capa->standard_phy_calibration_size =
  1277. le32_to_cpup((__le32 *)tlv_data);
  1278. break;
  1279. default:
  1280. IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
  1281. break;
  1282. }
  1283. }
  1284. if (len) {
  1285. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  1286. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  1287. return -EINVAL;
  1288. }
  1289. return 0;
  1290. invalid_tlv_len:
  1291. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  1292. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  1293. return -EINVAL;
  1294. }
  1295. /**
  1296. * iwl_ucode_callback - callback when firmware was loaded
  1297. *
  1298. * If loaded successfully, copies the firmware into buffers
  1299. * for the card to fetch (via DMA).
  1300. */
  1301. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  1302. {
  1303. struct iwl_priv *priv = context;
  1304. struct iwl_ucode_header *ucode;
  1305. int err;
  1306. struct iwlagn_firmware_pieces pieces;
  1307. const unsigned int api_max = priv->cfg->ucode_api_max;
  1308. const unsigned int api_min = priv->cfg->ucode_api_min;
  1309. u32 api_ver;
  1310. char buildstr[25];
  1311. u32 build;
  1312. struct iwlagn_ucode_capabilities ucode_capa = {
  1313. .max_probe_length = 200,
  1314. .standard_phy_calibration_size =
  1315. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  1316. };
  1317. memset(&pieces, 0, sizeof(pieces));
  1318. if (!ucode_raw) {
  1319. if (priv->fw_index <= priv->cfg->ucode_api_max)
  1320. IWL_ERR(priv,
  1321. "request for firmware file '%s' failed.\n",
  1322. priv->firmware_name);
  1323. goto try_again;
  1324. }
  1325. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  1326. priv->firmware_name, ucode_raw->size);
  1327. /* Make sure that we got at least the API version number */
  1328. if (ucode_raw->size < 4) {
  1329. IWL_ERR(priv, "File size way too small!\n");
  1330. goto try_again;
  1331. }
  1332. /* Data from ucode file: header followed by uCode images */
  1333. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1334. if (ucode->ver)
  1335. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  1336. else
  1337. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  1338. &ucode_capa);
  1339. if (err)
  1340. goto try_again;
  1341. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1342. build = pieces.build;
  1343. /*
  1344. * api_ver should match the api version forming part of the
  1345. * firmware filename ... but we don't check for that and only rely
  1346. * on the API version read from firmware header from here on forward
  1347. */
  1348. /* no api version check required for experimental uCode */
  1349. if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  1350. if (api_ver < api_min || api_ver > api_max) {
  1351. IWL_ERR(priv,
  1352. "Driver unable to support your firmware API. "
  1353. "Driver supports v%u, firmware is v%u.\n",
  1354. api_max, api_ver);
  1355. goto try_again;
  1356. }
  1357. if (api_ver != api_max)
  1358. IWL_ERR(priv,
  1359. "Firmware has old API version. Expected v%u, "
  1360. "got v%u. New firmware can be obtained "
  1361. "from http://www.intellinuxwireless.org.\n",
  1362. api_max, api_ver);
  1363. }
  1364. if (build)
  1365. sprintf(buildstr, " build %u%s", build,
  1366. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1367. ? " (EXP)" : "");
  1368. else
  1369. buildstr[0] = '\0';
  1370. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  1371. IWL_UCODE_MAJOR(priv->ucode_ver),
  1372. IWL_UCODE_MINOR(priv->ucode_ver),
  1373. IWL_UCODE_API(priv->ucode_ver),
  1374. IWL_UCODE_SERIAL(priv->ucode_ver),
  1375. buildstr);
  1376. snprintf(priv->hw->wiphy->fw_version,
  1377. sizeof(priv->hw->wiphy->fw_version),
  1378. "%u.%u.%u.%u%s",
  1379. IWL_UCODE_MAJOR(priv->ucode_ver),
  1380. IWL_UCODE_MINOR(priv->ucode_ver),
  1381. IWL_UCODE_API(priv->ucode_ver),
  1382. IWL_UCODE_SERIAL(priv->ucode_ver),
  1383. buildstr);
  1384. /*
  1385. * For any of the failures below (before allocating pci memory)
  1386. * we will try to load a version with a smaller API -- maybe the
  1387. * user just got a corrupted version of the latest API.
  1388. */
  1389. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1390. priv->ucode_ver);
  1391. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  1392. pieces.inst_size);
  1393. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  1394. pieces.data_size);
  1395. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  1396. pieces.init_size);
  1397. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  1398. pieces.init_data_size);
  1399. /* Verify that uCode images will fit in card's SRAM */
  1400. if (pieces.inst_size > priv->hw_params.max_inst_size) {
  1401. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  1402. pieces.inst_size);
  1403. goto try_again;
  1404. }
  1405. if (pieces.data_size > priv->hw_params.max_data_size) {
  1406. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  1407. pieces.data_size);
  1408. goto try_again;
  1409. }
  1410. if (pieces.init_size > priv->hw_params.max_inst_size) {
  1411. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  1412. pieces.init_size);
  1413. goto try_again;
  1414. }
  1415. if (pieces.init_data_size > priv->hw_params.max_data_size) {
  1416. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  1417. pieces.init_data_size);
  1418. goto try_again;
  1419. }
  1420. /* Allocate ucode buffers for card's bus-master loading ... */
  1421. /* Runtime instructions and 2 copies of data:
  1422. * 1) unmodified from disk
  1423. * 2) backup cache for save/restore during power-downs */
  1424. if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.code,
  1425. pieces.inst, pieces.inst_size))
  1426. goto err_pci_alloc;
  1427. if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.data,
  1428. pieces.data, pieces.data_size))
  1429. goto err_pci_alloc;
  1430. /* Initialization instructions and data */
  1431. if (pieces.init_size && pieces.init_data_size) {
  1432. if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.code,
  1433. pieces.init, pieces.init_size))
  1434. goto err_pci_alloc;
  1435. if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.data,
  1436. pieces.init_data, pieces.init_data_size))
  1437. goto err_pci_alloc;
  1438. }
  1439. /* Now that we can no longer fail, copy information */
  1440. /*
  1441. * The (size - 16) / 12 formula is based on the information recorded
  1442. * for each event, which is of mode 1 (including timestamp) for all
  1443. * new microcodes that include this information.
  1444. */
  1445. priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
  1446. if (pieces.init_evtlog_size)
  1447. priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  1448. else
  1449. priv->_agn.init_evtlog_size =
  1450. priv->cfg->base_params->max_event_log_size;
  1451. priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
  1452. priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  1453. if (pieces.inst_evtlog_size)
  1454. priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  1455. else
  1456. priv->_agn.inst_evtlog_size =
  1457. priv->cfg->base_params->max_event_log_size;
  1458. priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
  1459. if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1460. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  1461. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1462. } else
  1463. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1464. if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
  1465. priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1466. else
  1467. priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1468. /*
  1469. * figure out the offset of chain noise reset and gain commands
  1470. * base on the size of standard phy calibration commands table size
  1471. */
  1472. if (ucode_capa.standard_phy_calibration_size >
  1473. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  1474. ucode_capa.standard_phy_calibration_size =
  1475. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1476. priv->_agn.phy_calib_chain_noise_reset_cmd =
  1477. ucode_capa.standard_phy_calibration_size;
  1478. priv->_agn.phy_calib_chain_noise_gain_cmd =
  1479. ucode_capa.standard_phy_calibration_size + 1;
  1480. /**************************************************
  1481. * This is still part of probe() in a sense...
  1482. *
  1483. * 9. Setup and register with mac80211 and debugfs
  1484. **************************************************/
  1485. err = iwl_mac_setup_register(priv, &ucode_capa);
  1486. if (err)
  1487. goto out_unbind;
  1488. err = iwl_dbgfs_register(priv, DRV_NAME);
  1489. if (err)
  1490. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  1491. err = sysfs_create_group(&priv->pci_dev->dev.kobj,
  1492. &iwl_attribute_group);
  1493. if (err) {
  1494. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  1495. goto out_unbind;
  1496. }
  1497. /* We have our copies now, allow OS release its copies */
  1498. release_firmware(ucode_raw);
  1499. complete(&priv->_agn.firmware_loading_complete);
  1500. return;
  1501. try_again:
  1502. /* try next, if any */
  1503. if (iwl_request_firmware(priv, false))
  1504. goto out_unbind;
  1505. release_firmware(ucode_raw);
  1506. return;
  1507. err_pci_alloc:
  1508. IWL_ERR(priv, "failed to allocate pci memory\n");
  1509. iwl_dealloc_ucode_pci(priv);
  1510. out_unbind:
  1511. complete(&priv->_agn.firmware_loading_complete);
  1512. device_release_driver(&priv->pci_dev->dev);
  1513. release_firmware(ucode_raw);
  1514. }
  1515. static const char *desc_lookup_text[] = {
  1516. "OK",
  1517. "FAIL",
  1518. "BAD_PARAM",
  1519. "BAD_CHECKSUM",
  1520. "NMI_INTERRUPT_WDG",
  1521. "SYSASSERT",
  1522. "FATAL_ERROR",
  1523. "BAD_COMMAND",
  1524. "HW_ERROR_TUNE_LOCK",
  1525. "HW_ERROR_TEMPERATURE",
  1526. "ILLEGAL_CHAN_FREQ",
  1527. "VCC_NOT_STABLE",
  1528. "FH_ERROR",
  1529. "NMI_INTERRUPT_HOST",
  1530. "NMI_INTERRUPT_ACTION_PT",
  1531. "NMI_INTERRUPT_UNKNOWN",
  1532. "UCODE_VERSION_MISMATCH",
  1533. "HW_ERROR_ABS_LOCK",
  1534. "HW_ERROR_CAL_LOCK_FAIL",
  1535. "NMI_INTERRUPT_INST_ACTION_PT",
  1536. "NMI_INTERRUPT_DATA_ACTION_PT",
  1537. "NMI_TRM_HW_ER",
  1538. "NMI_INTERRUPT_TRM",
  1539. "NMI_INTERRUPT_BREAK_POINT"
  1540. "DEBUG_0",
  1541. "DEBUG_1",
  1542. "DEBUG_2",
  1543. "DEBUG_3",
  1544. };
  1545. static struct { char *name; u8 num; } advanced_lookup[] = {
  1546. { "NMI_INTERRUPT_WDG", 0x34 },
  1547. { "SYSASSERT", 0x35 },
  1548. { "UCODE_VERSION_MISMATCH", 0x37 },
  1549. { "BAD_COMMAND", 0x38 },
  1550. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1551. { "FATAL_ERROR", 0x3D },
  1552. { "NMI_TRM_HW_ERR", 0x46 },
  1553. { "NMI_INTERRUPT_TRM", 0x4C },
  1554. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1555. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1556. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1557. { "NMI_INTERRUPT_HOST", 0x66 },
  1558. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1559. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1560. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1561. { "ADVANCED_SYSASSERT", 0 },
  1562. };
  1563. static const char *desc_lookup(u32 num)
  1564. {
  1565. int i;
  1566. int max = ARRAY_SIZE(desc_lookup_text);
  1567. if (num < max)
  1568. return desc_lookup_text[num];
  1569. max = ARRAY_SIZE(advanced_lookup) - 1;
  1570. for (i = 0; i < max; i++) {
  1571. if (advanced_lookup[i].num == num)
  1572. break;;
  1573. }
  1574. return advanced_lookup[i].name;
  1575. }
  1576. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1577. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1578. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1579. {
  1580. u32 data2, line;
  1581. u32 desc, time, count, base, data1;
  1582. u32 blink1, blink2, ilink1, ilink2;
  1583. u32 pc, hcmd;
  1584. struct iwl_error_event_table table;
  1585. base = priv->device_pointers.error_event_table;
  1586. if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
  1587. if (!base)
  1588. base = priv->_agn.init_errlog_ptr;
  1589. } else {
  1590. if (!base)
  1591. base = priv->_agn.inst_errlog_ptr;
  1592. }
  1593. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1594. IWL_ERR(priv,
  1595. "Not valid error log pointer 0x%08X for %s uCode\n",
  1596. base,
  1597. (priv->ucode_type == UCODE_SUBTYPE_INIT)
  1598. ? "Init" : "RT");
  1599. return;
  1600. }
  1601. iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
  1602. count = table.valid;
  1603. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1604. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1605. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1606. priv->status, count);
  1607. }
  1608. desc = table.error_id;
  1609. priv->isr_stats.err_code = desc;
  1610. pc = table.pc;
  1611. blink1 = table.blink1;
  1612. blink2 = table.blink2;
  1613. ilink1 = table.ilink1;
  1614. ilink2 = table.ilink2;
  1615. data1 = table.data1;
  1616. data2 = table.data2;
  1617. line = table.line;
  1618. time = table.tsf_low;
  1619. hcmd = table.hcmd;
  1620. trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
  1621. blink1, blink2, ilink1, ilink2);
  1622. IWL_ERR(priv, "Desc Time "
  1623. "data1 data2 line\n");
  1624. IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  1625. desc_lookup(desc), desc, time, data1, data2, line);
  1626. IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
  1627. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  1628. pc, blink1, blink2, ilink1, ilink2, hcmd);
  1629. }
  1630. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1631. /**
  1632. * iwl_print_event_log - Dump error event log to syslog
  1633. *
  1634. */
  1635. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1636. u32 num_events, u32 mode,
  1637. int pos, char **buf, size_t bufsz)
  1638. {
  1639. u32 i;
  1640. u32 base; /* SRAM byte address of event log header */
  1641. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1642. u32 ptr; /* SRAM byte address of log data */
  1643. u32 ev, time, data; /* event log data */
  1644. unsigned long reg_flags;
  1645. if (num_events == 0)
  1646. return pos;
  1647. base = priv->device_pointers.log_event_table;
  1648. if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
  1649. if (!base)
  1650. base = priv->_agn.init_evtlog_ptr;
  1651. } else {
  1652. if (!base)
  1653. base = priv->_agn.inst_evtlog_ptr;
  1654. }
  1655. if (mode == 0)
  1656. event_size = 2 * sizeof(u32);
  1657. else
  1658. event_size = 3 * sizeof(u32);
  1659. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1660. /* Make sure device is powered up for SRAM reads */
  1661. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1662. iwl_grab_nic_access(priv);
  1663. /* Set starting address; reads will auto-increment */
  1664. iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1665. rmb();
  1666. /* "time" is actually "data" for mode 0 (no timestamp).
  1667. * place event id # at far right for easier visual parsing. */
  1668. for (i = 0; i < num_events; i++) {
  1669. ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1670. time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1671. if (mode == 0) {
  1672. /* data, ev */
  1673. if (bufsz) {
  1674. pos += scnprintf(*buf + pos, bufsz - pos,
  1675. "EVT_LOG:0x%08x:%04u\n",
  1676. time, ev);
  1677. } else {
  1678. trace_iwlwifi_dev_ucode_event(priv, 0,
  1679. time, ev);
  1680. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1681. time, ev);
  1682. }
  1683. } else {
  1684. data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1685. if (bufsz) {
  1686. pos += scnprintf(*buf + pos, bufsz - pos,
  1687. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1688. time, data, ev);
  1689. } else {
  1690. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1691. time, data, ev);
  1692. trace_iwlwifi_dev_ucode_event(priv, time,
  1693. data, ev);
  1694. }
  1695. }
  1696. }
  1697. /* Allow device to power down */
  1698. iwl_release_nic_access(priv);
  1699. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1700. return pos;
  1701. }
  1702. /**
  1703. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1704. */
  1705. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1706. u32 num_wraps, u32 next_entry,
  1707. u32 size, u32 mode,
  1708. int pos, char **buf, size_t bufsz)
  1709. {
  1710. /*
  1711. * display the newest DEFAULT_LOG_ENTRIES entries
  1712. * i.e the entries just before the next ont that uCode would fill.
  1713. */
  1714. if (num_wraps) {
  1715. if (next_entry < size) {
  1716. pos = iwl_print_event_log(priv,
  1717. capacity - (size - next_entry),
  1718. size - next_entry, mode,
  1719. pos, buf, bufsz);
  1720. pos = iwl_print_event_log(priv, 0,
  1721. next_entry, mode,
  1722. pos, buf, bufsz);
  1723. } else
  1724. pos = iwl_print_event_log(priv, next_entry - size,
  1725. size, mode, pos, buf, bufsz);
  1726. } else {
  1727. if (next_entry < size) {
  1728. pos = iwl_print_event_log(priv, 0, next_entry,
  1729. mode, pos, buf, bufsz);
  1730. } else {
  1731. pos = iwl_print_event_log(priv, next_entry - size,
  1732. size, mode, pos, buf, bufsz);
  1733. }
  1734. }
  1735. return pos;
  1736. }
  1737. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1738. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1739. char **buf, bool display)
  1740. {
  1741. u32 base; /* SRAM byte address of event log header */
  1742. u32 capacity; /* event log capacity in # entries */
  1743. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1744. u32 num_wraps; /* # times uCode wrapped to top of log */
  1745. u32 next_entry; /* index of next entry to be written by uCode */
  1746. u32 size; /* # entries that we'll print */
  1747. u32 logsize;
  1748. int pos = 0;
  1749. size_t bufsz = 0;
  1750. base = priv->device_pointers.log_event_table;
  1751. if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
  1752. logsize = priv->_agn.init_evtlog_size;
  1753. if (!base)
  1754. base = priv->_agn.init_evtlog_ptr;
  1755. } else {
  1756. logsize = priv->_agn.inst_evtlog_size;
  1757. if (!base)
  1758. base = priv->_agn.inst_evtlog_ptr;
  1759. }
  1760. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1761. IWL_ERR(priv,
  1762. "Invalid event log pointer 0x%08X for %s uCode\n",
  1763. base,
  1764. (priv->ucode_type == UCODE_SUBTYPE_INIT)
  1765. ? "Init" : "RT");
  1766. return -EINVAL;
  1767. }
  1768. /* event log header */
  1769. capacity = iwl_read_targ_mem(priv, base);
  1770. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1771. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1772. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1773. if (capacity > logsize) {
  1774. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  1775. capacity, logsize);
  1776. capacity = logsize;
  1777. }
  1778. if (next_entry > logsize) {
  1779. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1780. next_entry, logsize);
  1781. next_entry = logsize;
  1782. }
  1783. size = num_wraps ? capacity : next_entry;
  1784. /* bail out if nothing in log */
  1785. if (size == 0) {
  1786. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1787. return pos;
  1788. }
  1789. /* enable/disable bt channel inhibition */
  1790. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  1791. #ifdef CONFIG_IWLWIFI_DEBUG
  1792. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1793. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1794. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1795. #else
  1796. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1797. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1798. #endif
  1799. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1800. size);
  1801. #ifdef CONFIG_IWLWIFI_DEBUG
  1802. if (display) {
  1803. if (full_log)
  1804. bufsz = capacity * 48;
  1805. else
  1806. bufsz = size * 48;
  1807. *buf = kmalloc(bufsz, GFP_KERNEL);
  1808. if (!*buf)
  1809. return -ENOMEM;
  1810. }
  1811. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1812. /*
  1813. * if uCode has wrapped back to top of log,
  1814. * start at the oldest entry,
  1815. * i.e the next one that uCode would fill.
  1816. */
  1817. if (num_wraps)
  1818. pos = iwl_print_event_log(priv, next_entry,
  1819. capacity - next_entry, mode,
  1820. pos, buf, bufsz);
  1821. /* (then/else) start at top of log */
  1822. pos = iwl_print_event_log(priv, 0,
  1823. next_entry, mode, pos, buf, bufsz);
  1824. } else
  1825. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1826. next_entry, size, mode,
  1827. pos, buf, bufsz);
  1828. #else
  1829. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1830. next_entry, size, mode,
  1831. pos, buf, bufsz);
  1832. #endif
  1833. return pos;
  1834. }
  1835. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1836. {
  1837. struct iwl_ct_kill_config cmd;
  1838. struct iwl_ct_kill_throttling_config adv_cmd;
  1839. unsigned long flags;
  1840. int ret = 0;
  1841. spin_lock_irqsave(&priv->lock, flags);
  1842. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1843. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1844. spin_unlock_irqrestore(&priv->lock, flags);
  1845. priv->thermal_throttle.ct_kill_toggle = false;
  1846. if (priv->cfg->base_params->support_ct_kill_exit) {
  1847. adv_cmd.critical_temperature_enter =
  1848. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1849. adv_cmd.critical_temperature_exit =
  1850. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  1851. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1852. sizeof(adv_cmd), &adv_cmd);
  1853. if (ret)
  1854. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1855. else
  1856. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1857. "succeeded, "
  1858. "critical temperature enter is %d,"
  1859. "exit is %d\n",
  1860. priv->hw_params.ct_kill_threshold,
  1861. priv->hw_params.ct_kill_exit_threshold);
  1862. } else {
  1863. cmd.critical_temperature_R =
  1864. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1865. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1866. sizeof(cmd), &cmd);
  1867. if (ret)
  1868. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1869. else
  1870. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1871. "succeeded, "
  1872. "critical temperature is %d\n",
  1873. priv->hw_params.ct_kill_threshold);
  1874. }
  1875. }
  1876. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  1877. {
  1878. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  1879. struct iwl_host_cmd cmd = {
  1880. .id = CALIBRATION_CFG_CMD,
  1881. .len = sizeof(struct iwl_calib_cfg_cmd),
  1882. .data = &calib_cfg_cmd,
  1883. };
  1884. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  1885. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  1886. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  1887. return iwl_send_cmd(priv, &cmd);
  1888. }
  1889. /**
  1890. * iwl_alive_start - called after REPLY_ALIVE notification received
  1891. * from protocol/runtime uCode (initialization uCode's
  1892. * Alive gets handled by iwl_init_alive_start()).
  1893. */
  1894. static int iwl_alive_start(struct iwl_priv *priv)
  1895. {
  1896. int ret = 0;
  1897. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1898. iwl_reset_ict(priv);
  1899. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1900. /* After the ALIVE response, we can send host commands to the uCode */
  1901. set_bit(STATUS_ALIVE, &priv->status);
  1902. /* Enable watchdog to monitor the driver tx queues */
  1903. iwl_setup_watchdog(priv);
  1904. if (iwl_is_rfkill(priv))
  1905. return -ERFKILL;
  1906. /* download priority table before any calibration request */
  1907. if (priv->cfg->bt_params &&
  1908. priv->cfg->bt_params->advanced_bt_coexist) {
  1909. /* Configure Bluetooth device coexistence support */
  1910. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1911. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1912. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1913. priv->cfg->ops->hcmd->send_bt_config(priv);
  1914. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  1915. iwlagn_send_prio_tbl(priv);
  1916. /* FIXME: w/a to force change uCode BT state machine */
  1917. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  1918. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1919. if (ret)
  1920. return ret;
  1921. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  1922. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1923. if (ret)
  1924. return ret;
  1925. }
  1926. if (priv->hw_params.calib_rt_cfg)
  1927. iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
  1928. ieee80211_wake_queues(priv->hw);
  1929. priv->active_rate = IWL_RATES_MASK;
  1930. /* Configure Tx antenna selection based on H/W config */
  1931. if (priv->cfg->ops->hcmd->set_tx_ant)
  1932. priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
  1933. if (iwl_is_associated_ctx(ctx)) {
  1934. struct iwl_rxon_cmd *active_rxon =
  1935. (struct iwl_rxon_cmd *)&ctx->active;
  1936. /* apply any changes in staging */
  1937. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1938. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1939. } else {
  1940. struct iwl_rxon_context *tmp;
  1941. /* Initialize our rx_config data */
  1942. for_each_context(priv, tmp)
  1943. iwl_connection_init_rx_config(priv, tmp);
  1944. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1945. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1946. }
  1947. if (!priv->cfg->bt_params || (priv->cfg->bt_params &&
  1948. !priv->cfg->bt_params->advanced_bt_coexist)) {
  1949. /*
  1950. * default is 2-wire BT coexexistence support
  1951. */
  1952. priv->cfg->ops->hcmd->send_bt_config(priv);
  1953. }
  1954. iwl_reset_run_time_calib(priv);
  1955. set_bit(STATUS_READY, &priv->status);
  1956. /* Configure the adapter for unassociated operation */
  1957. ret = iwlcore_commit_rxon(priv, ctx);
  1958. if (ret)
  1959. return ret;
  1960. /* At this point, the NIC is initialized and operational */
  1961. iwl_rf_kill_ct_config(priv);
  1962. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1963. return iwl_power_update_mode(priv, true);
  1964. }
  1965. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1966. static void __iwl_down(struct iwl_priv *priv)
  1967. {
  1968. int exit_pending;
  1969. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1970. iwl_scan_cancel_timeout(priv, 200);
  1971. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  1972. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1973. * to prevent rearm timer */
  1974. del_timer_sync(&priv->watchdog);
  1975. iwl_clear_ucode_stations(priv, NULL);
  1976. iwl_dealloc_bcast_stations(priv);
  1977. iwl_clear_driver_stations(priv);
  1978. /* reset BT coex data */
  1979. priv->bt_status = 0;
  1980. if (priv->cfg->bt_params)
  1981. priv->bt_traffic_load =
  1982. priv->cfg->bt_params->bt_init_traffic_load;
  1983. else
  1984. priv->bt_traffic_load = 0;
  1985. priv->bt_full_concurrent = false;
  1986. priv->bt_ci_compliance = 0;
  1987. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1988. * exiting the module */
  1989. if (!exit_pending)
  1990. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1991. if (priv->mac80211_registered)
  1992. ieee80211_stop_queues(priv->hw);
  1993. /* Clear out all status bits but a few that are stable across reset */
  1994. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1995. STATUS_RF_KILL_HW |
  1996. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1997. STATUS_GEO_CONFIGURED |
  1998. test_bit(STATUS_FW_ERROR, &priv->status) <<
  1999. STATUS_FW_ERROR |
  2000. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2001. STATUS_EXIT_PENDING;
  2002. iwlagn_stop_device(priv);
  2003. dev_kfree_skb(priv->beacon_skb);
  2004. priv->beacon_skb = NULL;
  2005. /* clear out any free frames */
  2006. iwl_clear_free_frames(priv);
  2007. }
  2008. static void iwl_down(struct iwl_priv *priv)
  2009. {
  2010. mutex_lock(&priv->mutex);
  2011. __iwl_down(priv);
  2012. mutex_unlock(&priv->mutex);
  2013. iwl_cancel_deferred_work(priv);
  2014. }
  2015. #define HW_READY_TIMEOUT (50)
  2016. /* Note: returns poll_bit return value, which is >= 0 if success */
  2017. static int iwl_set_hw_ready(struct iwl_priv *priv)
  2018. {
  2019. int ret;
  2020. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2021. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  2022. /* See if we got it */
  2023. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2024. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2025. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2026. HW_READY_TIMEOUT);
  2027. IWL_DEBUG_INFO(priv, "hardware%s ready\n", ret < 0 ? " not" : "");
  2028. return ret;
  2029. }
  2030. /* Note: returns standard 0/-ERROR code */
  2031. int iwl_prepare_card_hw(struct iwl_priv *priv)
  2032. {
  2033. int ret;
  2034. IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
  2035. ret = iwl_set_hw_ready(priv);
  2036. if (ret >= 0)
  2037. return 0;
  2038. /* If HW is not ready, prepare the conditions to check again */
  2039. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2040. CSR_HW_IF_CONFIG_REG_PREPARE);
  2041. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2042. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  2043. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  2044. if (ret < 0)
  2045. return ret;
  2046. /* HW should be ready by now, check again. */
  2047. ret = iwl_set_hw_ready(priv);
  2048. if (ret >= 0)
  2049. return 0;
  2050. return ret;
  2051. }
  2052. #define MAX_HW_RESTARTS 5
  2053. static int __iwl_up(struct iwl_priv *priv)
  2054. {
  2055. struct iwl_rxon_context *ctx;
  2056. int ret;
  2057. lockdep_assert_held(&priv->mutex);
  2058. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2059. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2060. return -EIO;
  2061. }
  2062. for_each_context(priv, ctx) {
  2063. ret = iwlagn_alloc_bcast_station(priv, ctx);
  2064. if (ret) {
  2065. iwl_dealloc_bcast_stations(priv);
  2066. return ret;
  2067. }
  2068. }
  2069. ret = iwlagn_run_init_ucode(priv);
  2070. if (ret) {
  2071. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  2072. goto error;
  2073. }
  2074. ret = iwlagn_load_ucode_wait_alive(priv,
  2075. &priv->ucode_rt,
  2076. UCODE_SUBTYPE_REGULAR,
  2077. UCODE_SUBTYPE_REGULAR_NEW);
  2078. if (ret) {
  2079. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  2080. goto error;
  2081. }
  2082. ret = iwl_alive_start(priv);
  2083. if (ret)
  2084. goto error;
  2085. return 0;
  2086. error:
  2087. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2088. __iwl_down(priv);
  2089. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2090. IWL_ERR(priv, "Unable to initialize device.\n");
  2091. return ret;
  2092. }
  2093. /*****************************************************************************
  2094. *
  2095. * Workqueue callbacks
  2096. *
  2097. *****************************************************************************/
  2098. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  2099. {
  2100. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2101. run_time_calib_work);
  2102. mutex_lock(&priv->mutex);
  2103. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2104. test_bit(STATUS_SCANNING, &priv->status)) {
  2105. mutex_unlock(&priv->mutex);
  2106. return;
  2107. }
  2108. if (priv->start_calib) {
  2109. iwl_chain_noise_calibration(priv);
  2110. iwl_sensitivity_calibration(priv);
  2111. }
  2112. mutex_unlock(&priv->mutex);
  2113. }
  2114. static void iwl_bg_restart(struct work_struct *data)
  2115. {
  2116. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2117. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2118. return;
  2119. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2120. struct iwl_rxon_context *ctx;
  2121. bool bt_full_concurrent;
  2122. u8 bt_ci_compliance;
  2123. u8 bt_load;
  2124. u8 bt_status;
  2125. mutex_lock(&priv->mutex);
  2126. for_each_context(priv, ctx)
  2127. ctx->vif = NULL;
  2128. priv->is_open = 0;
  2129. /*
  2130. * __iwl_down() will clear the BT status variables,
  2131. * which is correct, but when we restart we really
  2132. * want to keep them so restore them afterwards.
  2133. *
  2134. * The restart process will later pick them up and
  2135. * re-configure the hw when we reconfigure the BT
  2136. * command.
  2137. */
  2138. bt_full_concurrent = priv->bt_full_concurrent;
  2139. bt_ci_compliance = priv->bt_ci_compliance;
  2140. bt_load = priv->bt_traffic_load;
  2141. bt_status = priv->bt_status;
  2142. __iwl_down(priv);
  2143. priv->bt_full_concurrent = bt_full_concurrent;
  2144. priv->bt_ci_compliance = bt_ci_compliance;
  2145. priv->bt_traffic_load = bt_load;
  2146. priv->bt_status = bt_status;
  2147. mutex_unlock(&priv->mutex);
  2148. iwl_cancel_deferred_work(priv);
  2149. ieee80211_restart_hw(priv->hw);
  2150. } else {
  2151. WARN_ON(1);
  2152. }
  2153. }
  2154. static void iwl_bg_rx_replenish(struct work_struct *data)
  2155. {
  2156. struct iwl_priv *priv =
  2157. container_of(data, struct iwl_priv, rx_replenish);
  2158. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2159. return;
  2160. mutex_lock(&priv->mutex);
  2161. iwlagn_rx_replenish(priv);
  2162. mutex_unlock(&priv->mutex);
  2163. }
  2164. static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  2165. struct ieee80211_channel *chan,
  2166. enum nl80211_channel_type channel_type,
  2167. unsigned int wait)
  2168. {
  2169. struct iwl_priv *priv = hw->priv;
  2170. int ret;
  2171. /* Not supported if we don't have PAN */
  2172. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
  2173. ret = -EOPNOTSUPP;
  2174. goto free;
  2175. }
  2176. /* Not supported on pre-P2P firmware */
  2177. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  2178. BIT(NL80211_IFTYPE_P2P_CLIENT))) {
  2179. ret = -EOPNOTSUPP;
  2180. goto free;
  2181. }
  2182. mutex_lock(&priv->mutex);
  2183. if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
  2184. /*
  2185. * If the PAN context is free, use the normal
  2186. * way of doing remain-on-channel offload + TX.
  2187. */
  2188. ret = 1;
  2189. goto out;
  2190. }
  2191. /* TODO: queue up if scanning? */
  2192. if (test_bit(STATUS_SCANNING, &priv->status) ||
  2193. priv->_agn.offchan_tx_skb) {
  2194. ret = -EBUSY;
  2195. goto out;
  2196. }
  2197. /*
  2198. * max_scan_ie_len doesn't include the blank SSID or the header,
  2199. * so need to add that again here.
  2200. */
  2201. if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
  2202. ret = -ENOBUFS;
  2203. goto out;
  2204. }
  2205. priv->_agn.offchan_tx_skb = skb;
  2206. priv->_agn.offchan_tx_timeout = wait;
  2207. priv->_agn.offchan_tx_chan = chan;
  2208. ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
  2209. IWL_SCAN_OFFCH_TX, chan->band);
  2210. if (ret)
  2211. priv->_agn.offchan_tx_skb = NULL;
  2212. out:
  2213. mutex_unlock(&priv->mutex);
  2214. free:
  2215. if (ret < 0)
  2216. kfree_skb(skb);
  2217. return ret;
  2218. }
  2219. static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
  2220. {
  2221. struct iwl_priv *priv = hw->priv;
  2222. int ret;
  2223. mutex_lock(&priv->mutex);
  2224. if (!priv->_agn.offchan_tx_skb) {
  2225. ret = -EINVAL;
  2226. goto unlock;
  2227. }
  2228. priv->_agn.offchan_tx_skb = NULL;
  2229. ret = iwl_scan_cancel_timeout(priv, 200);
  2230. if (ret)
  2231. ret = -EIO;
  2232. unlock:
  2233. mutex_unlock(&priv->mutex);
  2234. return ret;
  2235. }
  2236. /*****************************************************************************
  2237. *
  2238. * mac80211 entry point functions
  2239. *
  2240. *****************************************************************************/
  2241. /*
  2242. * Not a mac80211 entry point function, but it fits in with all the
  2243. * other mac80211 functions grouped here.
  2244. */
  2245. static int iwl_mac_setup_register(struct iwl_priv *priv,
  2246. struct iwlagn_ucode_capabilities *capa)
  2247. {
  2248. int ret;
  2249. struct ieee80211_hw *hw = priv->hw;
  2250. struct iwl_rxon_context *ctx;
  2251. hw->rate_control_algorithm = "iwl-agn-rs";
  2252. /* Tell mac80211 our characteristics */
  2253. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  2254. IEEE80211_HW_AMPDU_AGGREGATION |
  2255. IEEE80211_HW_NEED_DTIM_PERIOD |
  2256. IEEE80211_HW_SPECTRUM_MGMT |
  2257. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  2258. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2259. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  2260. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  2261. if (priv->cfg->sku & IWL_SKU_N)
  2262. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  2263. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  2264. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  2265. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  2266. hw->sta_data_size = sizeof(struct iwl_station_priv);
  2267. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  2268. for_each_context(priv, ctx) {
  2269. hw->wiphy->interface_modes |= ctx->interface_modes;
  2270. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  2271. }
  2272. hw->wiphy->max_remain_on_channel_duration = 1000;
  2273. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  2274. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  2275. WIPHY_FLAG_IBSS_RSN;
  2276. /*
  2277. * For now, disable PS by default because it affects
  2278. * RX performance significantly.
  2279. */
  2280. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  2281. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  2282. /* we create the 802.11 header and a zero-length SSID element */
  2283. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  2284. /* Default value; 4 EDCA QOS priorities */
  2285. hw->queues = 4;
  2286. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  2287. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  2288. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  2289. &priv->bands[IEEE80211_BAND_2GHZ];
  2290. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  2291. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  2292. &priv->bands[IEEE80211_BAND_5GHZ];
  2293. iwl_leds_init(priv);
  2294. ret = ieee80211_register_hw(priv->hw);
  2295. if (ret) {
  2296. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  2297. return ret;
  2298. }
  2299. priv->mac80211_registered = 1;
  2300. return 0;
  2301. }
  2302. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  2303. {
  2304. struct iwl_priv *priv = hw->priv;
  2305. int ret;
  2306. IWL_DEBUG_MAC80211(priv, "enter\n");
  2307. /* we should be verifying the device is ready to be opened */
  2308. mutex_lock(&priv->mutex);
  2309. ret = __iwl_up(priv);
  2310. mutex_unlock(&priv->mutex);
  2311. if (ret)
  2312. return ret;
  2313. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  2314. /* Now we should be done, and the READY bit should be set. */
  2315. if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
  2316. ret = -EIO;
  2317. iwlagn_led_enable(priv);
  2318. priv->is_open = 1;
  2319. IWL_DEBUG_MAC80211(priv, "leave\n");
  2320. return 0;
  2321. }
  2322. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  2323. {
  2324. struct iwl_priv *priv = hw->priv;
  2325. IWL_DEBUG_MAC80211(priv, "enter\n");
  2326. if (!priv->is_open)
  2327. return;
  2328. priv->is_open = 0;
  2329. iwl_down(priv);
  2330. flush_workqueue(priv->workqueue);
  2331. /* User space software may expect getting rfkill changes
  2332. * even if interface is down */
  2333. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2334. iwl_enable_rfkill_int(priv);
  2335. IWL_DEBUG_MAC80211(priv, "leave\n");
  2336. }
  2337. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2338. {
  2339. struct iwl_priv *priv = hw->priv;
  2340. IWL_DEBUG_MACDUMP(priv, "enter\n");
  2341. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2342. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2343. if (iwlagn_tx_skb(priv, skb))
  2344. dev_kfree_skb_any(skb);
  2345. IWL_DEBUG_MACDUMP(priv, "leave\n");
  2346. }
  2347. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  2348. struct ieee80211_vif *vif,
  2349. struct ieee80211_key_conf *keyconf,
  2350. struct ieee80211_sta *sta,
  2351. u32 iv32, u16 *phase1key)
  2352. {
  2353. struct iwl_priv *priv = hw->priv;
  2354. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2355. IWL_DEBUG_MAC80211(priv, "enter\n");
  2356. iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
  2357. iv32, phase1key);
  2358. IWL_DEBUG_MAC80211(priv, "leave\n");
  2359. }
  2360. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2361. struct ieee80211_vif *vif,
  2362. struct ieee80211_sta *sta,
  2363. struct ieee80211_key_conf *key)
  2364. {
  2365. struct iwl_priv *priv = hw->priv;
  2366. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2367. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2368. int ret;
  2369. u8 sta_id;
  2370. bool is_default_wep_key = false;
  2371. IWL_DEBUG_MAC80211(priv, "enter\n");
  2372. if (priv->cfg->mod_params->sw_crypto) {
  2373. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2374. return -EOPNOTSUPP;
  2375. }
  2376. /*
  2377. * To support IBSS RSN, don't program group keys in IBSS, the
  2378. * hardware will then not attempt to decrypt the frames.
  2379. */
  2380. if (vif->type == NL80211_IFTYPE_ADHOC &&
  2381. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  2382. return -EOPNOTSUPP;
  2383. sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
  2384. if (sta_id == IWL_INVALID_STATION)
  2385. return -EINVAL;
  2386. mutex_lock(&priv->mutex);
  2387. iwl_scan_cancel_timeout(priv, 100);
  2388. /*
  2389. * If we are getting WEP group key and we didn't receive any key mapping
  2390. * so far, we are in legacy wep mode (group key only), otherwise we are
  2391. * in 1X mode.
  2392. * In legacy wep mode, we use another host command to the uCode.
  2393. */
  2394. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2395. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  2396. !sta) {
  2397. if (cmd == SET_KEY)
  2398. is_default_wep_key = !ctx->key_mapping_keys;
  2399. else
  2400. is_default_wep_key =
  2401. (key->hw_key_idx == HW_KEY_DEFAULT);
  2402. }
  2403. switch (cmd) {
  2404. case SET_KEY:
  2405. if (is_default_wep_key)
  2406. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  2407. else
  2408. ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
  2409. key, sta_id);
  2410. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2411. break;
  2412. case DISABLE_KEY:
  2413. if (is_default_wep_key)
  2414. ret = iwl_remove_default_wep_key(priv, ctx, key);
  2415. else
  2416. ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
  2417. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2418. break;
  2419. default:
  2420. ret = -EINVAL;
  2421. }
  2422. mutex_unlock(&priv->mutex);
  2423. IWL_DEBUG_MAC80211(priv, "leave\n");
  2424. return ret;
  2425. }
  2426. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  2427. struct ieee80211_vif *vif,
  2428. enum ieee80211_ampdu_mlme_action action,
  2429. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  2430. u8 buf_size)
  2431. {
  2432. struct iwl_priv *priv = hw->priv;
  2433. int ret = -EINVAL;
  2434. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  2435. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2436. sta->addr, tid);
  2437. if (!(priv->cfg->sku & IWL_SKU_N))
  2438. return -EACCES;
  2439. mutex_lock(&priv->mutex);
  2440. switch (action) {
  2441. case IEEE80211_AMPDU_RX_START:
  2442. IWL_DEBUG_HT(priv, "start Rx\n");
  2443. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  2444. break;
  2445. case IEEE80211_AMPDU_RX_STOP:
  2446. IWL_DEBUG_HT(priv, "stop Rx\n");
  2447. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  2448. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2449. ret = 0;
  2450. break;
  2451. case IEEE80211_AMPDU_TX_START:
  2452. IWL_DEBUG_HT(priv, "start Tx\n");
  2453. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  2454. if (ret == 0) {
  2455. priv->_agn.agg_tids_count++;
  2456. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  2457. priv->_agn.agg_tids_count);
  2458. }
  2459. break;
  2460. case IEEE80211_AMPDU_TX_STOP:
  2461. IWL_DEBUG_HT(priv, "stop Tx\n");
  2462. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  2463. if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
  2464. priv->_agn.agg_tids_count--;
  2465. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  2466. priv->_agn.agg_tids_count);
  2467. }
  2468. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2469. ret = 0;
  2470. if (priv->cfg->ht_params &&
  2471. priv->cfg->ht_params->use_rts_for_aggregation) {
  2472. struct iwl_station_priv *sta_priv =
  2473. (void *) sta->drv_priv;
  2474. /*
  2475. * switch off RTS/CTS if it was previously enabled
  2476. */
  2477. sta_priv->lq_sta.lq.general_params.flags &=
  2478. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2479. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2480. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2481. }
  2482. break;
  2483. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2484. buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
  2485. iwlagn_txq_agg_queue_setup(priv, sta, tid, buf_size);
  2486. /*
  2487. * If the limit is 0, then it wasn't initialised yet,
  2488. * use the default. We can do that since we take the
  2489. * minimum below, and we don't want to go above our
  2490. * default due to hardware restrictions.
  2491. */
  2492. if (sta_priv->max_agg_bufsize == 0)
  2493. sta_priv->max_agg_bufsize =
  2494. LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2495. /*
  2496. * Even though in theory the peer could have different
  2497. * aggregation reorder buffer sizes for different sessions,
  2498. * our ucode doesn't allow for that and has a global limit
  2499. * for each station. Therefore, use the minimum of all the
  2500. * aggregation sessions and our default value.
  2501. */
  2502. sta_priv->max_agg_bufsize =
  2503. min(sta_priv->max_agg_bufsize, buf_size);
  2504. if (priv->cfg->ht_params &&
  2505. priv->cfg->ht_params->use_rts_for_aggregation) {
  2506. /*
  2507. * switch to RTS/CTS if it is the prefer protection
  2508. * method for HT traffic
  2509. */
  2510. sta_priv->lq_sta.lq.general_params.flags |=
  2511. LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2512. }
  2513. sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
  2514. sta_priv->max_agg_bufsize;
  2515. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2516. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2517. ret = 0;
  2518. break;
  2519. }
  2520. mutex_unlock(&priv->mutex);
  2521. return ret;
  2522. }
  2523. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  2524. struct ieee80211_vif *vif,
  2525. struct ieee80211_sta *sta)
  2526. {
  2527. struct iwl_priv *priv = hw->priv;
  2528. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  2529. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2530. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2531. int ret;
  2532. u8 sta_id;
  2533. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2534. sta->addr);
  2535. mutex_lock(&priv->mutex);
  2536. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2537. sta->addr);
  2538. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2539. atomic_set(&sta_priv->pending_frames, 0);
  2540. if (vif->type == NL80211_IFTYPE_AP)
  2541. sta_priv->client = true;
  2542. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  2543. is_ap, sta, &sta_id);
  2544. if (ret) {
  2545. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2546. sta->addr, ret);
  2547. /* Should we return success if return code is EEXIST ? */
  2548. mutex_unlock(&priv->mutex);
  2549. return ret;
  2550. }
  2551. sta_priv->common.sta_id = sta_id;
  2552. /* Initialize rate scaling */
  2553. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2554. sta->addr);
  2555. iwl_rs_rate_init(priv, sta, sta_id);
  2556. mutex_unlock(&priv->mutex);
  2557. return 0;
  2558. }
  2559. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  2560. struct ieee80211_channel_switch *ch_switch)
  2561. {
  2562. struct iwl_priv *priv = hw->priv;
  2563. const struct iwl_channel_info *ch_info;
  2564. struct ieee80211_conf *conf = &hw->conf;
  2565. struct ieee80211_channel *channel = ch_switch->channel;
  2566. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  2567. /*
  2568. * MULTI-FIXME
  2569. * When we add support for multiple interfaces, we need to
  2570. * revisit this. The channel switch command in the device
  2571. * only affects the BSS context, but what does that really
  2572. * mean? And what if we get a CSA on the second interface?
  2573. * This needs a lot of work.
  2574. */
  2575. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2576. u16 ch;
  2577. unsigned long flags = 0;
  2578. IWL_DEBUG_MAC80211(priv, "enter\n");
  2579. mutex_lock(&priv->mutex);
  2580. if (iwl_is_rfkill(priv))
  2581. goto out;
  2582. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2583. test_bit(STATUS_SCANNING, &priv->status))
  2584. goto out;
  2585. if (!iwl_is_associated_ctx(ctx))
  2586. goto out;
  2587. /* channel switch in progress */
  2588. if (priv->switch_rxon.switch_in_progress == true)
  2589. goto out;
  2590. if (priv->cfg->ops->lib->set_channel_switch) {
  2591. ch = channel->hw_value;
  2592. if (le16_to_cpu(ctx->active.channel) != ch) {
  2593. ch_info = iwl_get_channel_info(priv,
  2594. channel->band,
  2595. ch);
  2596. if (!is_channel_valid(ch_info)) {
  2597. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  2598. goto out;
  2599. }
  2600. spin_lock_irqsave(&priv->lock, flags);
  2601. priv->current_ht_config.smps = conf->smps_mode;
  2602. /* Configure HT40 channels */
  2603. ctx->ht.enabled = conf_is_ht(conf);
  2604. if (ctx->ht.enabled) {
  2605. if (conf_is_ht40_minus(conf)) {
  2606. ctx->ht.extension_chan_offset =
  2607. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2608. ctx->ht.is_40mhz = true;
  2609. } else if (conf_is_ht40_plus(conf)) {
  2610. ctx->ht.extension_chan_offset =
  2611. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2612. ctx->ht.is_40mhz = true;
  2613. } else {
  2614. ctx->ht.extension_chan_offset =
  2615. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2616. ctx->ht.is_40mhz = false;
  2617. }
  2618. } else
  2619. ctx->ht.is_40mhz = false;
  2620. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2621. ctx->staging.flags = 0;
  2622. iwl_set_rxon_channel(priv, channel, ctx);
  2623. iwl_set_rxon_ht(priv, ht_conf);
  2624. iwl_set_flags_for_band(priv, ctx, channel->band,
  2625. ctx->vif);
  2626. spin_unlock_irqrestore(&priv->lock, flags);
  2627. iwl_set_rate(priv);
  2628. /*
  2629. * at this point, staging_rxon has the
  2630. * configuration for channel switch
  2631. */
  2632. if (priv->cfg->ops->lib->set_channel_switch(priv,
  2633. ch_switch))
  2634. priv->switch_rxon.switch_in_progress = false;
  2635. }
  2636. }
  2637. out:
  2638. mutex_unlock(&priv->mutex);
  2639. if (!priv->switch_rxon.switch_in_progress)
  2640. ieee80211_chswitch_done(ctx->vif, false);
  2641. IWL_DEBUG_MAC80211(priv, "leave\n");
  2642. }
  2643. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  2644. unsigned int changed_flags,
  2645. unsigned int *total_flags,
  2646. u64 multicast)
  2647. {
  2648. struct iwl_priv *priv = hw->priv;
  2649. __le32 filter_or = 0, filter_nand = 0;
  2650. struct iwl_rxon_context *ctx;
  2651. #define CHK(test, flag) do { \
  2652. if (*total_flags & (test)) \
  2653. filter_or |= (flag); \
  2654. else \
  2655. filter_nand |= (flag); \
  2656. } while (0)
  2657. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2658. changed_flags, *total_flags);
  2659. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2660. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2661. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2662. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2663. #undef CHK
  2664. mutex_lock(&priv->mutex);
  2665. for_each_context(priv, ctx) {
  2666. ctx->staging.filter_flags &= ~filter_nand;
  2667. ctx->staging.filter_flags |= filter_or;
  2668. /*
  2669. * Not committing directly because hardware can perform a scan,
  2670. * but we'll eventually commit the filter flags change anyway.
  2671. */
  2672. }
  2673. mutex_unlock(&priv->mutex);
  2674. /*
  2675. * Receiving all multicast frames is always enabled by the
  2676. * default flags setup in iwl_connection_init_rx_config()
  2677. * since we currently do not support programming multicast
  2678. * filters into the device.
  2679. */
  2680. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2681. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2682. }
  2683. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  2684. {
  2685. struct iwl_priv *priv = hw->priv;
  2686. mutex_lock(&priv->mutex);
  2687. IWL_DEBUG_MAC80211(priv, "enter\n");
  2688. /* do not support "flush" */
  2689. if (!priv->cfg->ops->lib->txfifo_flush)
  2690. goto done;
  2691. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2692. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  2693. goto done;
  2694. }
  2695. if (iwl_is_rfkill(priv)) {
  2696. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  2697. goto done;
  2698. }
  2699. /*
  2700. * mac80211 will not push any more frames for transmit
  2701. * until the flush is completed
  2702. */
  2703. if (drop) {
  2704. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  2705. if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
  2706. IWL_ERR(priv, "flush request fail\n");
  2707. goto done;
  2708. }
  2709. }
  2710. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  2711. iwlagn_wait_tx_queue_empty(priv);
  2712. done:
  2713. mutex_unlock(&priv->mutex);
  2714. IWL_DEBUG_MAC80211(priv, "leave\n");
  2715. }
  2716. static void iwlagn_disable_roc(struct iwl_priv *priv)
  2717. {
  2718. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  2719. struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
  2720. lockdep_assert_held(&priv->mutex);
  2721. if (!ctx->is_active)
  2722. return;
  2723. ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
  2724. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2725. iwl_set_rxon_channel(priv, chan, ctx);
  2726. iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
  2727. priv->_agn.hw_roc_channel = NULL;
  2728. iwlcore_commit_rxon(priv, ctx);
  2729. ctx->is_active = false;
  2730. }
  2731. static void iwlagn_bg_roc_done(struct work_struct *work)
  2732. {
  2733. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2734. _agn.hw_roc_work.work);
  2735. mutex_lock(&priv->mutex);
  2736. ieee80211_remain_on_channel_expired(priv->hw);
  2737. iwlagn_disable_roc(priv);
  2738. mutex_unlock(&priv->mutex);
  2739. }
  2740. static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
  2741. struct ieee80211_channel *channel,
  2742. enum nl80211_channel_type channel_type,
  2743. int duration)
  2744. {
  2745. struct iwl_priv *priv = hw->priv;
  2746. int err = 0;
  2747. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2748. return -EOPNOTSUPP;
  2749. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  2750. BIT(NL80211_IFTYPE_P2P_CLIENT)))
  2751. return -EOPNOTSUPP;
  2752. mutex_lock(&priv->mutex);
  2753. if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
  2754. test_bit(STATUS_SCAN_HW, &priv->status)) {
  2755. err = -EBUSY;
  2756. goto out;
  2757. }
  2758. priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
  2759. priv->_agn.hw_roc_channel = channel;
  2760. priv->_agn.hw_roc_chantype = channel_type;
  2761. priv->_agn.hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
  2762. iwlcore_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
  2763. queue_delayed_work(priv->workqueue, &priv->_agn.hw_roc_work,
  2764. msecs_to_jiffies(duration + 20));
  2765. msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
  2766. ieee80211_ready_on_channel(priv->hw);
  2767. out:
  2768. mutex_unlock(&priv->mutex);
  2769. return err;
  2770. }
  2771. static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2772. {
  2773. struct iwl_priv *priv = hw->priv;
  2774. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2775. return -EOPNOTSUPP;
  2776. cancel_delayed_work_sync(&priv->_agn.hw_roc_work);
  2777. mutex_lock(&priv->mutex);
  2778. iwlagn_disable_roc(priv);
  2779. mutex_unlock(&priv->mutex);
  2780. return 0;
  2781. }
  2782. /*****************************************************************************
  2783. *
  2784. * driver setup and teardown
  2785. *
  2786. *****************************************************************************/
  2787. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  2788. {
  2789. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  2790. init_waitqueue_head(&priv->wait_command_queue);
  2791. INIT_WORK(&priv->restart, iwl_bg_restart);
  2792. INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
  2793. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  2794. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  2795. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  2796. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  2797. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  2798. INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
  2799. iwl_setup_scan_deferred_work(priv);
  2800. if (priv->cfg->ops->lib->setup_deferred_work)
  2801. priv->cfg->ops->lib->setup_deferred_work(priv);
  2802. init_timer(&priv->statistics_periodic);
  2803. priv->statistics_periodic.data = (unsigned long)priv;
  2804. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  2805. init_timer(&priv->ucode_trace);
  2806. priv->ucode_trace.data = (unsigned long)priv;
  2807. priv->ucode_trace.function = iwl_bg_ucode_trace;
  2808. init_timer(&priv->watchdog);
  2809. priv->watchdog.data = (unsigned long)priv;
  2810. priv->watchdog.function = iwl_bg_watchdog;
  2811. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  2812. iwl_irq_tasklet, (unsigned long)priv);
  2813. }
  2814. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  2815. {
  2816. if (priv->cfg->ops->lib->cancel_deferred_work)
  2817. priv->cfg->ops->lib->cancel_deferred_work(priv);
  2818. cancel_work_sync(&priv->run_time_calib_work);
  2819. cancel_work_sync(&priv->beacon_update);
  2820. iwl_cancel_scan_deferred_work(priv);
  2821. cancel_work_sync(&priv->bt_full_concurrency);
  2822. cancel_work_sync(&priv->bt_runtime_config);
  2823. del_timer_sync(&priv->statistics_periodic);
  2824. del_timer_sync(&priv->ucode_trace);
  2825. }
  2826. static void iwl_init_hw_rates(struct iwl_priv *priv,
  2827. struct ieee80211_rate *rates)
  2828. {
  2829. int i;
  2830. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  2831. rates[i].bitrate = iwl_rates[i].ieee * 5;
  2832. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2833. rates[i].hw_value_short = i;
  2834. rates[i].flags = 0;
  2835. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  2836. /*
  2837. * If CCK != 1M then set short preamble rate flag.
  2838. */
  2839. rates[i].flags |=
  2840. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  2841. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2842. }
  2843. }
  2844. }
  2845. static int iwl_init_drv(struct iwl_priv *priv)
  2846. {
  2847. int ret;
  2848. spin_lock_init(&priv->sta_lock);
  2849. spin_lock_init(&priv->hcmd_lock);
  2850. INIT_LIST_HEAD(&priv->free_frames);
  2851. mutex_init(&priv->mutex);
  2852. priv->ieee_channels = NULL;
  2853. priv->ieee_rates = NULL;
  2854. priv->band = IEEE80211_BAND_2GHZ;
  2855. priv->iw_mode = NL80211_IFTYPE_STATION;
  2856. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2857. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  2858. priv->_agn.agg_tids_count = 0;
  2859. /* initialize force reset */
  2860. priv->force_reset[IWL_RF_RESET].reset_duration =
  2861. IWL_DELAY_NEXT_FORCE_RF_RESET;
  2862. priv->force_reset[IWL_FW_RESET].reset_duration =
  2863. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  2864. priv->rx_statistics_jiffies = jiffies;
  2865. /* Choose which receivers/antennas to use */
  2866. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2867. priv->cfg->ops->hcmd->set_rxon_chain(priv,
  2868. &priv->contexts[IWL_RXON_CTX_BSS]);
  2869. iwl_init_scan_params(priv);
  2870. /* init bt coex */
  2871. if (priv->cfg->bt_params &&
  2872. priv->cfg->bt_params->advanced_bt_coexist) {
  2873. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  2874. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  2875. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  2876. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  2877. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  2878. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  2879. }
  2880. ret = iwl_init_channel_map(priv);
  2881. if (ret) {
  2882. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  2883. goto err;
  2884. }
  2885. ret = iwlcore_init_geos(priv);
  2886. if (ret) {
  2887. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  2888. goto err_free_channel_map;
  2889. }
  2890. iwl_init_hw_rates(priv, priv->ieee_rates);
  2891. return 0;
  2892. err_free_channel_map:
  2893. iwl_free_channel_map(priv);
  2894. err:
  2895. return ret;
  2896. }
  2897. static void iwl_uninit_drv(struct iwl_priv *priv)
  2898. {
  2899. iwl_calib_free_results(priv);
  2900. iwlcore_free_geos(priv);
  2901. iwl_free_channel_map(priv);
  2902. kfree(priv->scan_cmd);
  2903. }
  2904. struct ieee80211_ops iwlagn_hw_ops = {
  2905. .tx = iwlagn_mac_tx,
  2906. .start = iwlagn_mac_start,
  2907. .stop = iwlagn_mac_stop,
  2908. .add_interface = iwl_mac_add_interface,
  2909. .remove_interface = iwl_mac_remove_interface,
  2910. .change_interface = iwl_mac_change_interface,
  2911. .config = iwlagn_mac_config,
  2912. .configure_filter = iwlagn_configure_filter,
  2913. .set_key = iwlagn_mac_set_key,
  2914. .update_tkip_key = iwlagn_mac_update_tkip_key,
  2915. .conf_tx = iwl_mac_conf_tx,
  2916. .bss_info_changed = iwlagn_bss_info_changed,
  2917. .ampdu_action = iwlagn_mac_ampdu_action,
  2918. .hw_scan = iwl_mac_hw_scan,
  2919. .sta_notify = iwlagn_mac_sta_notify,
  2920. .sta_add = iwlagn_mac_sta_add,
  2921. .sta_remove = iwl_mac_sta_remove,
  2922. .channel_switch = iwlagn_mac_channel_switch,
  2923. .flush = iwlagn_mac_flush,
  2924. .tx_last_beacon = iwl_mac_tx_last_beacon,
  2925. .remain_on_channel = iwl_mac_remain_on_channel,
  2926. .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
  2927. .offchannel_tx = iwl_mac_offchannel_tx,
  2928. .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
  2929. };
  2930. static u32 iwl_hw_detect(struct iwl_priv *priv)
  2931. {
  2932. u8 rev_id;
  2933. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
  2934. IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
  2935. return iwl_read32(priv, CSR_HW_REV);
  2936. }
  2937. static int iwl_set_hw_params(struct iwl_priv *priv)
  2938. {
  2939. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  2940. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2941. if (priv->cfg->mod_params->amsdu_size_8K)
  2942. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
  2943. else
  2944. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
  2945. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  2946. if (priv->cfg->mod_params->disable_11n)
  2947. priv->cfg->sku &= ~IWL_SKU_N;
  2948. /* Device-specific setup */
  2949. return priv->cfg->ops->lib->set_hw_params(priv);
  2950. }
  2951. static const u8 iwlagn_bss_ac_to_fifo[] = {
  2952. IWL_TX_FIFO_VO,
  2953. IWL_TX_FIFO_VI,
  2954. IWL_TX_FIFO_BE,
  2955. IWL_TX_FIFO_BK,
  2956. };
  2957. static const u8 iwlagn_bss_ac_to_queue[] = {
  2958. 0, 1, 2, 3,
  2959. };
  2960. static const u8 iwlagn_pan_ac_to_fifo[] = {
  2961. IWL_TX_FIFO_VO_IPAN,
  2962. IWL_TX_FIFO_VI_IPAN,
  2963. IWL_TX_FIFO_BE_IPAN,
  2964. IWL_TX_FIFO_BK_IPAN,
  2965. };
  2966. static const u8 iwlagn_pan_ac_to_queue[] = {
  2967. 7, 6, 5, 4,
  2968. };
  2969. /* This function both allocates and initializes hw and priv. */
  2970. static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
  2971. {
  2972. struct iwl_priv *priv;
  2973. /* mac80211 allocates memory for this device instance, including
  2974. * space for this driver's private structure */
  2975. struct ieee80211_hw *hw;
  2976. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
  2977. if (hw == NULL) {
  2978. pr_err("%s: Can not allocate network device\n",
  2979. cfg->name);
  2980. goto out;
  2981. }
  2982. priv = hw->priv;
  2983. priv->hw = hw;
  2984. out:
  2985. return hw;
  2986. }
  2987. static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2988. {
  2989. int err = 0, i;
  2990. struct iwl_priv *priv;
  2991. struct ieee80211_hw *hw;
  2992. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  2993. unsigned long flags;
  2994. u16 pci_cmd, num_mac;
  2995. u32 hw_rev;
  2996. /************************
  2997. * 1. Allocating HW data
  2998. ************************/
  2999. hw = iwl_alloc_all(cfg);
  3000. if (!hw) {
  3001. err = -ENOMEM;
  3002. goto out;
  3003. }
  3004. priv = hw->priv;
  3005. /* At this point both hw and priv are allocated. */
  3006. priv->ucode_type = UCODE_SUBTYPE_NONE_LOADED;
  3007. /*
  3008. * The default context is always valid,
  3009. * more may be discovered when firmware
  3010. * is loaded.
  3011. */
  3012. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  3013. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  3014. priv->contexts[i].ctxid = i;
  3015. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  3016. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  3017. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  3018. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  3019. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  3020. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  3021. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  3022. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  3023. priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
  3024. priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
  3025. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  3026. BIT(NL80211_IFTYPE_ADHOC);
  3027. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  3028. BIT(NL80211_IFTYPE_STATION);
  3029. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  3030. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  3031. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  3032. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  3033. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  3034. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
  3035. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
  3036. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  3037. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  3038. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  3039. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  3040. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  3041. priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
  3042. priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
  3043. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  3044. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  3045. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  3046. #ifdef CONFIG_IWL_P2P
  3047. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  3048. BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
  3049. #endif
  3050. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  3051. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  3052. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  3053. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  3054. SET_IEEE80211_DEV(hw, &pdev->dev);
  3055. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3056. priv->cfg = cfg;
  3057. priv->pci_dev = pdev;
  3058. priv->inta_mask = CSR_INI_SET_MASK;
  3059. /* is antenna coupling more than 35dB ? */
  3060. priv->bt_ant_couple_ok =
  3061. (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  3062. true : false;
  3063. /* enable/disable bt channel inhibition */
  3064. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  3065. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  3066. (priv->bt_ch_announce) ? "On" : "Off");
  3067. if (iwl_alloc_traffic_mem(priv))
  3068. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3069. /**************************
  3070. * 2. Initializing PCI bus
  3071. **************************/
  3072. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  3073. PCIE_LINK_STATE_CLKPM);
  3074. if (pci_enable_device(pdev)) {
  3075. err = -ENODEV;
  3076. goto out_ieee80211_free_hw;
  3077. }
  3078. pci_set_master(pdev);
  3079. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  3080. if (!err)
  3081. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  3082. if (err) {
  3083. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3084. if (!err)
  3085. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3086. /* both attempts failed: */
  3087. if (err) {
  3088. IWL_WARN(priv, "No suitable DMA available.\n");
  3089. goto out_pci_disable_device;
  3090. }
  3091. }
  3092. err = pci_request_regions(pdev, DRV_NAME);
  3093. if (err)
  3094. goto out_pci_disable_device;
  3095. pci_set_drvdata(pdev, priv);
  3096. /***********************
  3097. * 3. Read REV register
  3098. ***********************/
  3099. priv->hw_base = pci_iomap(pdev, 0, 0);
  3100. if (!priv->hw_base) {
  3101. err = -ENODEV;
  3102. goto out_pci_release_regions;
  3103. }
  3104. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  3105. (unsigned long long) pci_resource_len(pdev, 0));
  3106. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  3107. /* these spin locks will be used in apm_ops.init and EEPROM access
  3108. * we should init now
  3109. */
  3110. spin_lock_init(&priv->reg_lock);
  3111. spin_lock_init(&priv->lock);
  3112. /*
  3113. * stop and reset the on-board processor just in case it is in a
  3114. * strange state ... like being left stranded by a primary kernel
  3115. * and this is now the kdump kernel trying to start up
  3116. */
  3117. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3118. hw_rev = iwl_hw_detect(priv);
  3119. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  3120. priv->cfg->name, hw_rev);
  3121. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3122. * PCI Tx retries from interfering with C3 CPU state */
  3123. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  3124. if (iwl_prepare_card_hw(priv)) {
  3125. IWL_WARN(priv, "Failed, HW not ready\n");
  3126. goto out_iounmap;
  3127. }
  3128. /*****************
  3129. * 4. Read EEPROM
  3130. *****************/
  3131. /* Read the EEPROM */
  3132. err = iwl_eeprom_init(priv, hw_rev);
  3133. if (err) {
  3134. IWL_ERR(priv, "Unable to init EEPROM\n");
  3135. goto out_iounmap;
  3136. }
  3137. err = iwl_eeprom_check_version(priv);
  3138. if (err)
  3139. goto out_free_eeprom;
  3140. err = iwl_eeprom_check_sku(priv);
  3141. if (err)
  3142. goto out_free_eeprom;
  3143. /* extract MAC Address */
  3144. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  3145. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  3146. priv->hw->wiphy->addresses = priv->addresses;
  3147. priv->hw->wiphy->n_addresses = 1;
  3148. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  3149. if (num_mac > 1) {
  3150. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  3151. ETH_ALEN);
  3152. priv->addresses[1].addr[5]++;
  3153. priv->hw->wiphy->n_addresses++;
  3154. }
  3155. /************************
  3156. * 5. Setup HW constants
  3157. ************************/
  3158. if (iwl_set_hw_params(priv)) {
  3159. IWL_ERR(priv, "failed to set hw parameters\n");
  3160. goto out_free_eeprom;
  3161. }
  3162. /*******************
  3163. * 6. Setup priv
  3164. *******************/
  3165. err = iwl_init_drv(priv);
  3166. if (err)
  3167. goto out_free_eeprom;
  3168. /* At this point both hw and priv are initialized. */
  3169. /********************
  3170. * 7. Setup services
  3171. ********************/
  3172. spin_lock_irqsave(&priv->lock, flags);
  3173. iwl_disable_interrupts(priv);
  3174. spin_unlock_irqrestore(&priv->lock, flags);
  3175. pci_enable_msi(priv->pci_dev);
  3176. iwl_alloc_isr_ict(priv);
  3177. err = request_irq(priv->pci_dev->irq, iwl_isr_ict,
  3178. IRQF_SHARED, DRV_NAME, priv);
  3179. if (err) {
  3180. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  3181. goto out_disable_msi;
  3182. }
  3183. iwl_setup_deferred_work(priv);
  3184. iwl_setup_rx_handlers(priv);
  3185. /*********************************************
  3186. * 8. Enable interrupts and read RFKILL state
  3187. *********************************************/
  3188. /* enable rfkill interrupt: hw bug w/a */
  3189. pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
  3190. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  3191. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  3192. pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
  3193. }
  3194. iwl_enable_rfkill_int(priv);
  3195. /* If platform's RF_KILL switch is NOT set to KILL */
  3196. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3197. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3198. else
  3199. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3200. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  3201. test_bit(STATUS_RF_KILL_HW, &priv->status));
  3202. iwl_power_initialize(priv);
  3203. iwl_tt_initialize(priv);
  3204. init_completion(&priv->_agn.firmware_loading_complete);
  3205. err = iwl_request_firmware(priv, true);
  3206. if (err)
  3207. goto out_destroy_workqueue;
  3208. return 0;
  3209. out_destroy_workqueue:
  3210. destroy_workqueue(priv->workqueue);
  3211. priv->workqueue = NULL;
  3212. free_irq(priv->pci_dev->irq, priv);
  3213. iwl_free_isr_ict(priv);
  3214. out_disable_msi:
  3215. pci_disable_msi(priv->pci_dev);
  3216. iwl_uninit_drv(priv);
  3217. out_free_eeprom:
  3218. iwl_eeprom_free(priv);
  3219. out_iounmap:
  3220. pci_iounmap(pdev, priv->hw_base);
  3221. out_pci_release_regions:
  3222. pci_set_drvdata(pdev, NULL);
  3223. pci_release_regions(pdev);
  3224. out_pci_disable_device:
  3225. pci_disable_device(pdev);
  3226. out_ieee80211_free_hw:
  3227. iwl_free_traffic_mem(priv);
  3228. ieee80211_free_hw(priv->hw);
  3229. out:
  3230. return err;
  3231. }
  3232. static void __devexit iwl_pci_remove(struct pci_dev *pdev)
  3233. {
  3234. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3235. unsigned long flags;
  3236. if (!priv)
  3237. return;
  3238. wait_for_completion(&priv->_agn.firmware_loading_complete);
  3239. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3240. iwl_dbgfs_unregister(priv);
  3241. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  3242. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  3243. * to be called and iwl_down since we are removing the device
  3244. * we need to set STATUS_EXIT_PENDING bit.
  3245. */
  3246. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3247. iwl_leds_exit(priv);
  3248. if (priv->mac80211_registered) {
  3249. ieee80211_unregister_hw(priv->hw);
  3250. priv->mac80211_registered = 0;
  3251. }
  3252. /* Reset to low power before unloading driver. */
  3253. iwl_apm_stop(priv);
  3254. iwl_tt_exit(priv);
  3255. /* make sure we flush any pending irq or
  3256. * tasklet for the driver
  3257. */
  3258. spin_lock_irqsave(&priv->lock, flags);
  3259. iwl_disable_interrupts(priv);
  3260. spin_unlock_irqrestore(&priv->lock, flags);
  3261. iwl_synchronize_irq(priv);
  3262. iwl_dealloc_ucode_pci(priv);
  3263. if (priv->rxq.bd)
  3264. iwlagn_rx_queue_free(priv, &priv->rxq);
  3265. iwlagn_hw_txq_ctx_free(priv);
  3266. iwl_eeprom_free(priv);
  3267. /*netif_stop_queue(dev); */
  3268. flush_workqueue(priv->workqueue);
  3269. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  3270. * priv->workqueue... so we can't take down the workqueue
  3271. * until now... */
  3272. destroy_workqueue(priv->workqueue);
  3273. priv->workqueue = NULL;
  3274. iwl_free_traffic_mem(priv);
  3275. free_irq(priv->pci_dev->irq, priv);
  3276. pci_disable_msi(priv->pci_dev);
  3277. pci_iounmap(pdev, priv->hw_base);
  3278. pci_release_regions(pdev);
  3279. pci_disable_device(pdev);
  3280. pci_set_drvdata(pdev, NULL);
  3281. iwl_uninit_drv(priv);
  3282. iwl_free_isr_ict(priv);
  3283. dev_kfree_skb(priv->beacon_skb);
  3284. ieee80211_free_hw(priv->hw);
  3285. }
  3286. /*****************************************************************************
  3287. *
  3288. * driver and module entry point
  3289. *
  3290. *****************************************************************************/
  3291. /* Hardware specific file defines the PCI IDs table for that hardware module */
  3292. static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
  3293. {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
  3294. {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
  3295. {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
  3296. {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
  3297. {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
  3298. {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3299. {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
  3300. {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
  3301. {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
  3302. {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
  3303. {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
  3304. {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
  3305. {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
  3306. {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3307. {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
  3308. {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
  3309. {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
  3310. {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
  3311. {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
  3312. {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
  3313. {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
  3314. {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3315. {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
  3316. {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
  3317. /* 5300 Series WiFi */
  3318. {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
  3319. {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
  3320. {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
  3321. {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
  3322. {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
  3323. {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
  3324. {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
  3325. {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
  3326. {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
  3327. {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
  3328. {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
  3329. {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
  3330. /* 5350 Series WiFi/WiMax */
  3331. {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
  3332. {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
  3333. {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
  3334. /* 5150 Series Wifi/WiMax */
  3335. {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
  3336. {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
  3337. {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
  3338. {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
  3339. {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
  3340. {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
  3341. {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
  3342. {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
  3343. {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
  3344. {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
  3345. /* 6x00 Series */
  3346. {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
  3347. {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
  3348. {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
  3349. {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
  3350. {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
  3351. {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
  3352. {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
  3353. {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
  3354. {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
  3355. {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
  3356. /* 6x05 Series */
  3357. {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)},
  3358. {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)},
  3359. {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)},
  3360. {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)},
  3361. {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)},
  3362. {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)},
  3363. {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)},
  3364. /* 6x30 Series */
  3365. {IWL_PCI_DEVICE(0x008A, 0x5305, iwl1030_bgn_cfg)},
  3366. {IWL_PCI_DEVICE(0x008A, 0x5307, iwl1030_bg_cfg)},
  3367. {IWL_PCI_DEVICE(0x008A, 0x5325, iwl1030_bgn_cfg)},
  3368. {IWL_PCI_DEVICE(0x008A, 0x5327, iwl1030_bg_cfg)},
  3369. {IWL_PCI_DEVICE(0x008B, 0x5315, iwl1030_bgn_cfg)},
  3370. {IWL_PCI_DEVICE(0x008B, 0x5317, iwl1030_bg_cfg)},
  3371. {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6030_2agn_cfg)},
  3372. {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6030_2bgn_cfg)},
  3373. {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6030_2abg_cfg)},
  3374. {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6030_2agn_cfg)},
  3375. {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6030_2bgn_cfg)},
  3376. {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6030_2abg_cfg)},
  3377. {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6030_2bg_cfg)},
  3378. {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6030_2agn_cfg)},
  3379. {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6030_2bgn_cfg)},
  3380. {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6030_2abg_cfg)},
  3381. /* 6x50 WiFi/WiMax Series */
  3382. {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
  3383. {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
  3384. {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
  3385. {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
  3386. {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
  3387. {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
  3388. /* 6150 WiFi/WiMax Series */
  3389. {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6150_bgn_cfg)},
  3390. {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6150_bgn_cfg)},
  3391. {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6150_bgn_cfg)},
  3392. {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6150_bgn_cfg)},
  3393. {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6150_bgn_cfg)},
  3394. {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6150_bgn_cfg)},
  3395. /* 1000 Series WiFi */
  3396. {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
  3397. {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
  3398. {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
  3399. {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
  3400. {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
  3401. {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
  3402. {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
  3403. {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
  3404. {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
  3405. {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
  3406. {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
  3407. {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
  3408. /* 100 Series WiFi */
  3409. {IWL_PCI_DEVICE(0x08AE, 0x1005, iwl100_bgn_cfg)},
  3410. {IWL_PCI_DEVICE(0x08AE, 0x1007, iwl100_bg_cfg)},
  3411. {IWL_PCI_DEVICE(0x08AF, 0x1015, iwl100_bgn_cfg)},
  3412. {IWL_PCI_DEVICE(0x08AF, 0x1017, iwl100_bg_cfg)},
  3413. {IWL_PCI_DEVICE(0x08AE, 0x1025, iwl100_bgn_cfg)},
  3414. {IWL_PCI_DEVICE(0x08AE, 0x1027, iwl100_bg_cfg)},
  3415. /* 130 Series WiFi */
  3416. {IWL_PCI_DEVICE(0x0896, 0x5005, iwl130_bgn_cfg)},
  3417. {IWL_PCI_DEVICE(0x0896, 0x5007, iwl130_bg_cfg)},
  3418. {IWL_PCI_DEVICE(0x0897, 0x5015, iwl130_bgn_cfg)},
  3419. {IWL_PCI_DEVICE(0x0897, 0x5017, iwl130_bg_cfg)},
  3420. {IWL_PCI_DEVICE(0x0896, 0x5025, iwl130_bgn_cfg)},
  3421. {IWL_PCI_DEVICE(0x0896, 0x5027, iwl130_bg_cfg)},
  3422. /* 2x00 Series */
  3423. {IWL_PCI_DEVICE(0x0890, 0x4022, iwl2000_2bgn_cfg)},
  3424. {IWL_PCI_DEVICE(0x0891, 0x4222, iwl2000_2bgn_cfg)},
  3425. {IWL_PCI_DEVICE(0x0890, 0x4422, iwl2000_2bgn_cfg)},
  3426. {IWL_PCI_DEVICE(0x0890, 0x4026, iwl2000_2bg_cfg)},
  3427. {IWL_PCI_DEVICE(0x0891, 0x4226, iwl2000_2bg_cfg)},
  3428. {IWL_PCI_DEVICE(0x0890, 0x4426, iwl2000_2bg_cfg)},
  3429. /* 2x30 Series */
  3430. {IWL_PCI_DEVICE(0x0887, 0x4062, iwl2030_2bgn_cfg)},
  3431. {IWL_PCI_DEVICE(0x0888, 0x4262, iwl2030_2bgn_cfg)},
  3432. {IWL_PCI_DEVICE(0x0887, 0x4462, iwl2030_2bgn_cfg)},
  3433. {IWL_PCI_DEVICE(0x0887, 0x4066, iwl2030_2bg_cfg)},
  3434. {IWL_PCI_DEVICE(0x0888, 0x4266, iwl2030_2bg_cfg)},
  3435. {IWL_PCI_DEVICE(0x0887, 0x4466, iwl2030_2bg_cfg)},
  3436. /* 6x35 Series */
  3437. {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)},
  3438. {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)},
  3439. {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)},
  3440. {IWL_PCI_DEVICE(0x088E, 0x4064, iwl6035_2abg_cfg)},
  3441. {IWL_PCI_DEVICE(0x088F, 0x4264, iwl6035_2abg_cfg)},
  3442. {IWL_PCI_DEVICE(0x088E, 0x4464, iwl6035_2abg_cfg)},
  3443. {IWL_PCI_DEVICE(0x088E, 0x4066, iwl6035_2bg_cfg)},
  3444. {IWL_PCI_DEVICE(0x088F, 0x4266, iwl6035_2bg_cfg)},
  3445. {IWL_PCI_DEVICE(0x088E, 0x4466, iwl6035_2bg_cfg)},
  3446. /* 200 Series */
  3447. {IWL_PCI_DEVICE(0x0894, 0x0022, iwl200_bgn_cfg)},
  3448. {IWL_PCI_DEVICE(0x0895, 0x0222, iwl200_bgn_cfg)},
  3449. {IWL_PCI_DEVICE(0x0894, 0x0422, iwl200_bgn_cfg)},
  3450. {IWL_PCI_DEVICE(0x0894, 0x0026, iwl200_bg_cfg)},
  3451. {IWL_PCI_DEVICE(0x0895, 0x0226, iwl200_bg_cfg)},
  3452. {IWL_PCI_DEVICE(0x0894, 0x0426, iwl200_bg_cfg)},
  3453. /* 230 Series */
  3454. {IWL_PCI_DEVICE(0x0892, 0x0062, iwl230_bgn_cfg)},
  3455. {IWL_PCI_DEVICE(0x0893, 0x0262, iwl230_bgn_cfg)},
  3456. {IWL_PCI_DEVICE(0x0892, 0x0462, iwl230_bgn_cfg)},
  3457. {IWL_PCI_DEVICE(0x0892, 0x0066, iwl230_bg_cfg)},
  3458. {IWL_PCI_DEVICE(0x0893, 0x0266, iwl230_bg_cfg)},
  3459. {IWL_PCI_DEVICE(0x0892, 0x0466, iwl230_bg_cfg)},
  3460. {0}
  3461. };
  3462. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  3463. static struct pci_driver iwl_driver = {
  3464. .name = DRV_NAME,
  3465. .id_table = iwl_hw_card_ids,
  3466. .probe = iwl_pci_probe,
  3467. .remove = __devexit_p(iwl_pci_remove),
  3468. .driver.pm = IWL_PM_OPS,
  3469. };
  3470. static int __init iwl_init(void)
  3471. {
  3472. int ret;
  3473. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3474. pr_info(DRV_COPYRIGHT "\n");
  3475. ret = iwlagn_rate_control_register();
  3476. if (ret) {
  3477. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3478. return ret;
  3479. }
  3480. ret = pci_register_driver(&iwl_driver);
  3481. if (ret) {
  3482. pr_err("Unable to initialize PCI module\n");
  3483. goto error_register;
  3484. }
  3485. return ret;
  3486. error_register:
  3487. iwlagn_rate_control_unregister();
  3488. return ret;
  3489. }
  3490. static void __exit iwl_exit(void)
  3491. {
  3492. pci_unregister_driver(&iwl_driver);
  3493. iwlagn_rate_control_unregister();
  3494. }
  3495. module_exit(iwl_exit);
  3496. module_init(iwl_init);
  3497. #ifdef CONFIG_IWLWIFI_DEBUG
  3498. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3499. MODULE_PARM_DESC(debug, "debug output mask");
  3500. #endif
  3501. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  3502. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  3503. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  3504. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  3505. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  3506. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  3507. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  3508. int, S_IRUGO);
  3509. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  3510. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  3511. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  3512. module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
  3513. S_IRUGO);
  3514. MODULE_PARM_DESC(ucode_alternative,
  3515. "specify ucode alternative to use from ucode file");
  3516. module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
  3517. MODULE_PARM_DESC(antenna_coupling,
  3518. "specify antenna coupling in dB (defualt: 0 dB)");
  3519. module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
  3520. MODULE_PARM_DESC(bt_ch_inhibition,
  3521. "Disable BT channel inhibition (default: enable)");
  3522. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  3523. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  3524. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  3525. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");