iwl-agn.c 112 KB

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