iwl-agn.c 115 KB

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