iwl-agn.c 114 KB

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