iwl-agn.c 113 KB

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