iwl-agn.c 112 KB

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