iwl-agn.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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/slab.h>
  33. #include <linux/delay.h>
  34. #include <linux/sched.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/firmware.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom.h"
  43. #include "iwl-dev.h"
  44. #include "iwl-core.h"
  45. #include "iwl-io.h"
  46. #include "iwl-agn-calib.h"
  47. #include "iwl-agn.h"
  48. #include "iwl-shared.h"
  49. #include "iwl-bus.h"
  50. #include "iwl-trans.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. #define DRV_VERSION IWLWIFI_VERSION VD
  66. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  67. MODULE_VERSION(DRV_VERSION);
  68. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  69. MODULE_LICENSE("GPL");
  70. MODULE_ALIAS("iwlagn");
  71. void iwl_update_chain_flags(struct iwl_priv *priv)
  72. {
  73. struct iwl_rxon_context *ctx;
  74. for_each_context(priv, ctx) {
  75. iwlagn_set_rxon_chain(priv, ctx);
  76. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  77. iwlagn_commit_rxon(priv, ctx);
  78. }
  79. }
  80. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  81. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  82. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  83. u8 *beacon, u32 frame_size)
  84. {
  85. u16 tim_idx;
  86. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  87. /*
  88. * The index is relative to frame start but we start looking at the
  89. * variable-length part of the beacon.
  90. */
  91. tim_idx = mgmt->u.beacon.variable - beacon;
  92. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  93. while ((tim_idx < (frame_size - 2)) &&
  94. (beacon[tim_idx] != WLAN_EID_TIM))
  95. tim_idx += beacon[tim_idx+1] + 2;
  96. /* If TIM field was found, set variables */
  97. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  98. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  99. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  100. } else
  101. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  102. }
  103. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  104. {
  105. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  106. struct iwl_host_cmd cmd = {
  107. .id = REPLY_TX_BEACON,
  108. .flags = CMD_SYNC,
  109. };
  110. struct ieee80211_tx_info *info;
  111. u32 frame_size;
  112. u32 rate_flags;
  113. u32 rate;
  114. /*
  115. * We have to set up the TX command, the TX Beacon command, and the
  116. * beacon contents.
  117. */
  118. lockdep_assert_held(&priv->shrd->mutex);
  119. if (!priv->beacon_ctx) {
  120. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  121. return 0;
  122. }
  123. if (WARN_ON(!priv->beacon_skb))
  124. return -EINVAL;
  125. /* Allocate beacon command */
  126. if (!priv->beacon_cmd)
  127. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  128. tx_beacon_cmd = priv->beacon_cmd;
  129. if (!tx_beacon_cmd)
  130. return -ENOMEM;
  131. frame_size = priv->beacon_skb->len;
  132. /* Set up TX command fields */
  133. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  134. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  135. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  136. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  137. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  138. /* Set up TX beacon command fields */
  139. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  140. frame_size);
  141. /* Set up packet rate and flags */
  142. info = IEEE80211_SKB_CB(priv->beacon_skb);
  143. /*
  144. * Let's set up the rate at least somewhat correctly;
  145. * it will currently not actually be used by the uCode,
  146. * it uses the broadcast station's rate instead.
  147. */
  148. if (info->control.rates[0].idx < 0 ||
  149. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  150. rate = 0;
  151. else
  152. rate = info->control.rates[0].idx;
  153. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  154. hw_params(priv).valid_tx_ant);
  155. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  156. /* In mac80211, rates for 5 GHz start at 0 */
  157. if (info->band == IEEE80211_BAND_5GHZ)
  158. rate += IWL_FIRST_OFDM_RATE;
  159. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  160. rate_flags |= RATE_MCS_CCK_MSK;
  161. tx_beacon_cmd->tx.rate_n_flags =
  162. iwl_hw_set_rate_n_flags(rate, rate_flags);
  163. /* Submit command */
  164. cmd.len[0] = sizeof(*tx_beacon_cmd);
  165. cmd.data[0] = tx_beacon_cmd;
  166. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  167. cmd.len[1] = frame_size;
  168. cmd.data[1] = priv->beacon_skb->data;
  169. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  170. return iwl_trans_send_cmd(trans(priv), &cmd);
  171. }
  172. static void iwl_bg_beacon_update(struct work_struct *work)
  173. {
  174. struct iwl_priv *priv =
  175. container_of(work, struct iwl_priv, beacon_update);
  176. struct sk_buff *beacon;
  177. mutex_lock(&priv->shrd->mutex);
  178. if (!priv->beacon_ctx) {
  179. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  180. goto out;
  181. }
  182. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  183. /*
  184. * The ucode will send beacon notifications even in
  185. * IBSS mode, but we don't want to process them. But
  186. * we need to defer the type check to here due to
  187. * requiring locking around the beacon_ctx access.
  188. */
  189. goto out;
  190. }
  191. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  192. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  193. if (!beacon) {
  194. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  195. goto out;
  196. }
  197. /* new beacon skb is allocated every time; dispose previous.*/
  198. dev_kfree_skb(priv->beacon_skb);
  199. priv->beacon_skb = beacon;
  200. iwlagn_send_beacon_cmd(priv);
  201. out:
  202. mutex_unlock(&priv->shrd->mutex);
  203. }
  204. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  205. {
  206. struct iwl_priv *priv =
  207. container_of(work, struct iwl_priv, bt_runtime_config);
  208. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  209. return;
  210. /* dont send host command if rf-kill is on */
  211. if (!iwl_is_ready_rf(priv->shrd))
  212. return;
  213. iwlagn_send_advance_bt_config(priv);
  214. }
  215. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  216. {
  217. struct iwl_priv *priv =
  218. container_of(work, struct iwl_priv, bt_full_concurrency);
  219. struct iwl_rxon_context *ctx;
  220. mutex_lock(&priv->shrd->mutex);
  221. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  222. goto out;
  223. /* dont send host command if rf-kill is on */
  224. if (!iwl_is_ready_rf(priv->shrd))
  225. goto out;
  226. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  227. priv->bt_full_concurrent ?
  228. "full concurrency" : "3-wire");
  229. /*
  230. * LQ & RXON updated cmds must be sent before BT Config cmd
  231. * to avoid 3-wire collisions
  232. */
  233. for_each_context(priv, ctx) {
  234. iwlagn_set_rxon_chain(priv, ctx);
  235. iwlagn_commit_rxon(priv, ctx);
  236. }
  237. iwlagn_send_advance_bt_config(priv);
  238. out:
  239. mutex_unlock(&priv->shrd->mutex);
  240. }
  241. /**
  242. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  243. *
  244. * This callback is provided in order to send a statistics request.
  245. *
  246. * This timer function is continually reset to execute within
  247. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  248. * was received. We need to ensure we receive the statistics in order
  249. * to update the temperature used for calibrating the TXPOWER.
  250. */
  251. static void iwl_bg_statistics_periodic(unsigned long data)
  252. {
  253. struct iwl_priv *priv = (struct iwl_priv *)data;
  254. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  255. return;
  256. /* dont send host command if rf-kill is on */
  257. if (!iwl_is_ready_rf(priv->shrd))
  258. return;
  259. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  260. }
  261. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  262. u32 start_idx, u32 num_events,
  263. u32 mode)
  264. {
  265. u32 i;
  266. u32 ptr; /* SRAM byte address of log data */
  267. u32 ev, time, data; /* event log data */
  268. unsigned long reg_flags;
  269. if (mode == 0)
  270. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  271. else
  272. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  273. /* Make sure device is powered up for SRAM reads */
  274. spin_lock_irqsave(&bus(priv)->reg_lock, reg_flags);
  275. if (iwl_grab_nic_access(bus(priv))) {
  276. spin_unlock_irqrestore(&bus(priv)->reg_lock, reg_flags);
  277. return;
  278. }
  279. /* Set starting address; reads will auto-increment */
  280. iwl_write32(bus(priv), HBUS_TARG_MEM_RADDR, ptr);
  281. rmb();
  282. /*
  283. * "time" is actually "data" for mode 0 (no timestamp).
  284. * place event id # at far right for easier visual parsing.
  285. */
  286. for (i = 0; i < num_events; i++) {
  287. ev = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  288. time = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  289. if (mode == 0) {
  290. trace_iwlwifi_dev_ucode_cont_event(priv,
  291. 0, time, ev);
  292. } else {
  293. data = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  294. trace_iwlwifi_dev_ucode_cont_event(priv,
  295. time, data, ev);
  296. }
  297. }
  298. /* Allow device to power down */
  299. iwl_release_nic_access(bus(priv));
  300. spin_unlock_irqrestore(&bus(priv)->reg_lock, reg_flags);
  301. }
  302. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  303. {
  304. u32 capacity; /* event log capacity in # entries */
  305. u32 base; /* SRAM byte address of event log header */
  306. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  307. u32 num_wraps; /* # times uCode wrapped to top of log */
  308. u32 next_entry; /* index of next entry to be written by uCode */
  309. base = priv->device_pointers.error_event_table;
  310. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  311. capacity = iwl_read_targ_mem(bus(priv), base);
  312. num_wraps = iwl_read_targ_mem(bus(priv),
  313. base + (2 * sizeof(u32)));
  314. mode = iwl_read_targ_mem(bus(priv), base + (1 * sizeof(u32)));
  315. next_entry = iwl_read_targ_mem(bus(priv),
  316. base + (3 * sizeof(u32)));
  317. } else
  318. return;
  319. if (num_wraps == priv->event_log.num_wraps) {
  320. iwl_print_cont_event_trace(priv,
  321. base, priv->event_log.next_entry,
  322. next_entry - priv->event_log.next_entry,
  323. mode);
  324. priv->event_log.non_wraps_count++;
  325. } else {
  326. if ((num_wraps - priv->event_log.num_wraps) > 1)
  327. priv->event_log.wraps_more_count++;
  328. else
  329. priv->event_log.wraps_once_count++;
  330. trace_iwlwifi_dev_ucode_wrap_event(priv,
  331. num_wraps - priv->event_log.num_wraps,
  332. next_entry, priv->event_log.next_entry);
  333. if (next_entry < priv->event_log.next_entry) {
  334. iwl_print_cont_event_trace(priv, base,
  335. priv->event_log.next_entry,
  336. capacity - priv->event_log.next_entry,
  337. mode);
  338. iwl_print_cont_event_trace(priv, base, 0,
  339. next_entry, mode);
  340. } else {
  341. iwl_print_cont_event_trace(priv, base,
  342. next_entry, capacity - next_entry,
  343. mode);
  344. iwl_print_cont_event_trace(priv, base, 0,
  345. next_entry, mode);
  346. }
  347. }
  348. priv->event_log.num_wraps = num_wraps;
  349. priv->event_log.next_entry = next_entry;
  350. }
  351. /**
  352. * iwl_bg_ucode_trace - Timer callback to log ucode event
  353. *
  354. * The timer is continually set to execute every
  355. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  356. * this function is to perform continuous uCode event logging operation
  357. * if enabled
  358. */
  359. static void iwl_bg_ucode_trace(unsigned long data)
  360. {
  361. struct iwl_priv *priv = (struct iwl_priv *)data;
  362. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  363. return;
  364. if (priv->event_log.ucode_trace) {
  365. iwl_continuous_event_trace(priv);
  366. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  367. mod_timer(&priv->ucode_trace,
  368. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  369. }
  370. }
  371. static void iwl_bg_tx_flush(struct work_struct *work)
  372. {
  373. struct iwl_priv *priv =
  374. container_of(work, struct iwl_priv, tx_flush);
  375. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  376. return;
  377. /* do nothing if rf-kill is on */
  378. if (!iwl_is_ready_rf(priv->shrd))
  379. return;
  380. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  381. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  382. }
  383. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  384. {
  385. int i;
  386. /*
  387. * The default context is always valid,
  388. * the PAN context depends on uCode.
  389. */
  390. priv->shrd->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  391. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  392. priv->shrd->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  393. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  394. priv->contexts[i].ctxid = i;
  395. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  396. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  397. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  398. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  399. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  400. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  401. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  402. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  403. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  404. BIT(NL80211_IFTYPE_ADHOC);
  405. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  406. BIT(NL80211_IFTYPE_STATION);
  407. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  408. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  409. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  410. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  411. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  412. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  413. REPLY_WIPAN_RXON_TIMING;
  414. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  415. REPLY_WIPAN_RXON_ASSOC;
  416. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  417. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  418. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  419. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  420. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  421. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  422. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  423. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  424. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  425. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  426. BIT(NL80211_IFTYPE_P2P_GO);
  427. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  428. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  429. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  430. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  431. }
  432. struct iwlagn_ucode_capabilities {
  433. u32 max_probe_length;
  434. u32 standard_phy_calibration_size;
  435. u32 flags;
  436. };
  437. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  438. static int iwlagn_mac_setup_register(struct iwl_priv *priv,
  439. struct iwlagn_ucode_capabilities *capa);
  440. #define UCODE_EXPERIMENTAL_INDEX 100
  441. #define UCODE_EXPERIMENTAL_TAG "exp"
  442. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  443. {
  444. const char *name_pre = priv->cfg->fw_name_pre;
  445. char tag[8];
  446. if (first) {
  447. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  448. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  449. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  450. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  451. #endif
  452. priv->fw_index = priv->cfg->ucode_api_max;
  453. sprintf(tag, "%d", priv->fw_index);
  454. } else {
  455. priv->fw_index--;
  456. sprintf(tag, "%d", priv->fw_index);
  457. }
  458. if (priv->fw_index < priv->cfg->ucode_api_min) {
  459. IWL_ERR(priv, "no suitable firmware found!\n");
  460. return -ENOENT;
  461. }
  462. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  463. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  464. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  465. ? "EXPERIMENTAL " : "",
  466. priv->firmware_name);
  467. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  468. bus(priv)->dev,
  469. GFP_KERNEL, priv, iwl_ucode_callback);
  470. }
  471. struct iwlagn_firmware_pieces {
  472. const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data;
  473. size_t inst_size, data_size, init_size, init_data_size,
  474. wowlan_inst_size, wowlan_data_size;
  475. u32 build;
  476. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  477. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  478. };
  479. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  480. const struct firmware *ucode_raw,
  481. struct iwlagn_firmware_pieces *pieces)
  482. {
  483. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  484. u32 api_ver, hdr_size;
  485. const u8 *src;
  486. priv->ucode_ver = le32_to_cpu(ucode->ver);
  487. api_ver = IWL_UCODE_API(priv->ucode_ver);
  488. switch (api_ver) {
  489. default:
  490. hdr_size = 28;
  491. if (ucode_raw->size < hdr_size) {
  492. IWL_ERR(priv, "File size too small!\n");
  493. return -EINVAL;
  494. }
  495. pieces->build = le32_to_cpu(ucode->u.v2.build);
  496. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  497. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  498. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  499. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  500. src = ucode->u.v2.data;
  501. break;
  502. case 0:
  503. case 1:
  504. case 2:
  505. hdr_size = 24;
  506. if (ucode_raw->size < hdr_size) {
  507. IWL_ERR(priv, "File size too small!\n");
  508. return -EINVAL;
  509. }
  510. pieces->build = 0;
  511. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  512. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  513. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  514. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  515. src = ucode->u.v1.data;
  516. break;
  517. }
  518. /* Verify size of file vs. image size info in file's header */
  519. if (ucode_raw->size != hdr_size + pieces->inst_size +
  520. pieces->data_size + pieces->init_size +
  521. pieces->init_data_size) {
  522. IWL_ERR(priv,
  523. "uCode file size %d does not match expected size\n",
  524. (int)ucode_raw->size);
  525. return -EINVAL;
  526. }
  527. pieces->inst = src;
  528. src += pieces->inst_size;
  529. pieces->data = src;
  530. src += pieces->data_size;
  531. pieces->init = src;
  532. src += pieces->init_size;
  533. pieces->init_data = src;
  534. src += pieces->init_data_size;
  535. return 0;
  536. }
  537. static int iwlagn_load_firmware(struct iwl_priv *priv,
  538. const struct firmware *ucode_raw,
  539. struct iwlagn_firmware_pieces *pieces,
  540. struct iwlagn_ucode_capabilities *capa)
  541. {
  542. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  543. struct iwl_ucode_tlv *tlv;
  544. size_t len = ucode_raw->size;
  545. const u8 *data;
  546. int wanted_alternative = iwlagn_mod_params.wanted_ucode_alternative;
  547. int tmp;
  548. u64 alternatives;
  549. u32 tlv_len;
  550. enum iwl_ucode_tlv_type tlv_type;
  551. const u8 *tlv_data;
  552. if (len < sizeof(*ucode)) {
  553. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  554. return -EINVAL;
  555. }
  556. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  557. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  558. le32_to_cpu(ucode->magic));
  559. return -EINVAL;
  560. }
  561. /*
  562. * Check which alternatives are present, and "downgrade"
  563. * when the chosen alternative is not present, warning
  564. * the user when that happens. Some files may not have
  565. * any alternatives, so don't warn in that case.
  566. */
  567. alternatives = le64_to_cpu(ucode->alternatives);
  568. tmp = wanted_alternative;
  569. if (wanted_alternative > 63)
  570. wanted_alternative = 63;
  571. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  572. wanted_alternative--;
  573. if (wanted_alternative && wanted_alternative != tmp)
  574. IWL_WARN(priv,
  575. "uCode alternative %d not available, choosing %d\n",
  576. tmp, wanted_alternative);
  577. priv->ucode_ver = le32_to_cpu(ucode->ver);
  578. pieces->build = le32_to_cpu(ucode->build);
  579. data = ucode->data;
  580. len -= sizeof(*ucode);
  581. while (len >= sizeof(*tlv)) {
  582. u16 tlv_alt;
  583. len -= sizeof(*tlv);
  584. tlv = (void *)data;
  585. tlv_len = le32_to_cpu(tlv->length);
  586. tlv_type = le16_to_cpu(tlv->type);
  587. tlv_alt = le16_to_cpu(tlv->alternative);
  588. tlv_data = tlv->data;
  589. if (len < tlv_len) {
  590. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  591. len, tlv_len);
  592. return -EINVAL;
  593. }
  594. len -= ALIGN(tlv_len, 4);
  595. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  596. /*
  597. * Alternative 0 is always valid.
  598. *
  599. * Skip alternative TLVs that are not selected.
  600. */
  601. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  602. continue;
  603. switch (tlv_type) {
  604. case IWL_UCODE_TLV_INST:
  605. pieces->inst = tlv_data;
  606. pieces->inst_size = tlv_len;
  607. break;
  608. case IWL_UCODE_TLV_DATA:
  609. pieces->data = tlv_data;
  610. pieces->data_size = tlv_len;
  611. break;
  612. case IWL_UCODE_TLV_INIT:
  613. pieces->init = tlv_data;
  614. pieces->init_size = tlv_len;
  615. break;
  616. case IWL_UCODE_TLV_INIT_DATA:
  617. pieces->init_data = tlv_data;
  618. pieces->init_data_size = tlv_len;
  619. break;
  620. case IWL_UCODE_TLV_BOOT:
  621. IWL_ERR(priv, "Found unexpected BOOT ucode\n");
  622. break;
  623. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  624. if (tlv_len != sizeof(u32))
  625. goto invalid_tlv_len;
  626. capa->max_probe_length =
  627. le32_to_cpup((__le32 *)tlv_data);
  628. break;
  629. case IWL_UCODE_TLV_PAN:
  630. if (tlv_len)
  631. goto invalid_tlv_len;
  632. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  633. break;
  634. case IWL_UCODE_TLV_FLAGS:
  635. /* must be at least one u32 */
  636. if (tlv_len < sizeof(u32))
  637. goto invalid_tlv_len;
  638. /* and a proper number of u32s */
  639. if (tlv_len % sizeof(u32))
  640. goto invalid_tlv_len;
  641. /*
  642. * This driver only reads the first u32 as
  643. * right now no more features are defined,
  644. * if that changes then either the driver
  645. * will not work with the new firmware, or
  646. * it'll not take advantage of new features.
  647. */
  648. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  649. break;
  650. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  651. if (tlv_len != sizeof(u32))
  652. goto invalid_tlv_len;
  653. pieces->init_evtlog_ptr =
  654. le32_to_cpup((__le32 *)tlv_data);
  655. break;
  656. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  657. if (tlv_len != sizeof(u32))
  658. goto invalid_tlv_len;
  659. pieces->init_evtlog_size =
  660. le32_to_cpup((__le32 *)tlv_data);
  661. break;
  662. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  663. if (tlv_len != sizeof(u32))
  664. goto invalid_tlv_len;
  665. pieces->init_errlog_ptr =
  666. le32_to_cpup((__le32 *)tlv_data);
  667. break;
  668. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  669. if (tlv_len != sizeof(u32))
  670. goto invalid_tlv_len;
  671. pieces->inst_evtlog_ptr =
  672. le32_to_cpup((__le32 *)tlv_data);
  673. break;
  674. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  675. if (tlv_len != sizeof(u32))
  676. goto invalid_tlv_len;
  677. pieces->inst_evtlog_size =
  678. le32_to_cpup((__le32 *)tlv_data);
  679. break;
  680. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  681. if (tlv_len != sizeof(u32))
  682. goto invalid_tlv_len;
  683. pieces->inst_errlog_ptr =
  684. le32_to_cpup((__le32 *)tlv_data);
  685. break;
  686. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  687. if (tlv_len)
  688. goto invalid_tlv_len;
  689. priv->enhance_sensitivity_table = true;
  690. break;
  691. case IWL_UCODE_TLV_WOWLAN_INST:
  692. pieces->wowlan_inst = tlv_data;
  693. pieces->wowlan_inst_size = tlv_len;
  694. break;
  695. case IWL_UCODE_TLV_WOWLAN_DATA:
  696. pieces->wowlan_data = tlv_data;
  697. pieces->wowlan_data_size = tlv_len;
  698. break;
  699. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  700. if (tlv_len != sizeof(u32))
  701. goto invalid_tlv_len;
  702. capa->standard_phy_calibration_size =
  703. le32_to_cpup((__le32 *)tlv_data);
  704. break;
  705. default:
  706. IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
  707. break;
  708. }
  709. }
  710. if (len) {
  711. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  712. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  713. return -EINVAL;
  714. }
  715. return 0;
  716. invalid_tlv_len:
  717. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  718. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  719. return -EINVAL;
  720. }
  721. /**
  722. * iwl_ucode_callback - callback when firmware was loaded
  723. *
  724. * If loaded successfully, copies the firmware into buffers
  725. * for the card to fetch (via DMA).
  726. */
  727. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  728. {
  729. struct iwl_priv *priv = context;
  730. struct iwl_ucode_header *ucode;
  731. int err;
  732. struct iwlagn_firmware_pieces pieces;
  733. const unsigned int api_max = priv->cfg->ucode_api_max;
  734. unsigned int api_ok = priv->cfg->ucode_api_ok;
  735. const unsigned int api_min = priv->cfg->ucode_api_min;
  736. u32 api_ver;
  737. char buildstr[25];
  738. u32 build;
  739. struct iwlagn_ucode_capabilities ucode_capa = {
  740. .max_probe_length = 200,
  741. .standard_phy_calibration_size =
  742. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  743. };
  744. if (!api_ok)
  745. api_ok = api_max;
  746. memset(&pieces, 0, sizeof(pieces));
  747. if (!ucode_raw) {
  748. if (priv->fw_index <= api_ok)
  749. IWL_ERR(priv,
  750. "request for firmware file '%s' failed.\n",
  751. priv->firmware_name);
  752. goto try_again;
  753. }
  754. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  755. priv->firmware_name, ucode_raw->size);
  756. /* Make sure that we got at least the API version number */
  757. if (ucode_raw->size < 4) {
  758. IWL_ERR(priv, "File size way too small!\n");
  759. goto try_again;
  760. }
  761. /* Data from ucode file: header followed by uCode images */
  762. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  763. if (ucode->ver)
  764. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  765. else
  766. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  767. &ucode_capa);
  768. if (err)
  769. goto try_again;
  770. api_ver = IWL_UCODE_API(priv->ucode_ver);
  771. build = pieces.build;
  772. /*
  773. * api_ver should match the api version forming part of the
  774. * firmware filename ... but we don't check for that and only rely
  775. * on the API version read from firmware header from here on forward
  776. */
  777. /* no api version check required for experimental uCode */
  778. if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  779. if (api_ver < api_min || api_ver > api_max) {
  780. IWL_ERR(priv,
  781. "Driver unable to support your firmware API. "
  782. "Driver supports v%u, firmware is v%u.\n",
  783. api_max, api_ver);
  784. goto try_again;
  785. }
  786. if (api_ver < api_ok) {
  787. if (api_ok != api_max)
  788. IWL_ERR(priv, "Firmware has old API version, "
  789. "expected v%u through v%u, got v%u.\n",
  790. api_ok, api_max, api_ver);
  791. else
  792. IWL_ERR(priv, "Firmware has old API version, "
  793. "expected v%u, got v%u.\n",
  794. api_max, api_ver);
  795. IWL_ERR(priv, "New firmware can be obtained from "
  796. "http://www.intellinuxwireless.org/.\n");
  797. }
  798. }
  799. if (build)
  800. sprintf(buildstr, " build %u%s", build,
  801. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  802. ? " (EXP)" : "");
  803. else
  804. buildstr[0] = '\0';
  805. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  806. IWL_UCODE_MAJOR(priv->ucode_ver),
  807. IWL_UCODE_MINOR(priv->ucode_ver),
  808. IWL_UCODE_API(priv->ucode_ver),
  809. IWL_UCODE_SERIAL(priv->ucode_ver),
  810. buildstr);
  811. snprintf(priv->hw->wiphy->fw_version,
  812. sizeof(priv->hw->wiphy->fw_version),
  813. "%u.%u.%u.%u%s",
  814. IWL_UCODE_MAJOR(priv->ucode_ver),
  815. IWL_UCODE_MINOR(priv->ucode_ver),
  816. IWL_UCODE_API(priv->ucode_ver),
  817. IWL_UCODE_SERIAL(priv->ucode_ver),
  818. buildstr);
  819. /*
  820. * For any of the failures below (before allocating pci memory)
  821. * we will try to load a version with a smaller API -- maybe the
  822. * user just got a corrupted version of the latest API.
  823. */
  824. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  825. priv->ucode_ver);
  826. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  827. pieces.inst_size);
  828. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  829. pieces.data_size);
  830. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  831. pieces.init_size);
  832. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  833. pieces.init_data_size);
  834. /* Verify that uCode images will fit in card's SRAM */
  835. if (pieces.inst_size > hw_params(priv).max_inst_size) {
  836. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  837. pieces.inst_size);
  838. goto try_again;
  839. }
  840. if (pieces.data_size > hw_params(priv).max_data_size) {
  841. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  842. pieces.data_size);
  843. goto try_again;
  844. }
  845. if (pieces.init_size > hw_params(priv).max_inst_size) {
  846. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  847. pieces.init_size);
  848. goto try_again;
  849. }
  850. if (pieces.init_data_size > hw_params(priv).max_data_size) {
  851. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  852. pieces.init_data_size);
  853. goto try_again;
  854. }
  855. /* Allocate ucode buffers for card's bus-master loading ... */
  856. /* Runtime instructions and 2 copies of data:
  857. * 1) unmodified from disk
  858. * 2) backup cache for save/restore during power-downs */
  859. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_rt.code,
  860. pieces.inst, pieces.inst_size))
  861. goto err_pci_alloc;
  862. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_rt.data,
  863. pieces.data, pieces.data_size))
  864. goto err_pci_alloc;
  865. /* Initialization instructions and data */
  866. if (pieces.init_size && pieces.init_data_size) {
  867. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_init.code,
  868. pieces.init, pieces.init_size))
  869. goto err_pci_alloc;
  870. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_init.data,
  871. pieces.init_data, pieces.init_data_size))
  872. goto err_pci_alloc;
  873. }
  874. /* WoWLAN instructions and data */
  875. if (pieces.wowlan_inst_size && pieces.wowlan_data_size) {
  876. if (iwl_alloc_fw_desc(bus(priv),
  877. &trans(priv)->ucode_wowlan.code,
  878. pieces.wowlan_inst,
  879. pieces.wowlan_inst_size))
  880. goto err_pci_alloc;
  881. if (iwl_alloc_fw_desc(bus(priv),
  882. &trans(priv)->ucode_wowlan.data,
  883. pieces.wowlan_data,
  884. pieces.wowlan_data_size))
  885. goto err_pci_alloc;
  886. }
  887. /* Now that we can no longer fail, copy information */
  888. /*
  889. * The (size - 16) / 12 formula is based on the information recorded
  890. * for each event, which is of mode 1 (including timestamp) for all
  891. * new microcodes that include this information.
  892. */
  893. priv->init_evtlog_ptr = pieces.init_evtlog_ptr;
  894. if (pieces.init_evtlog_size)
  895. priv->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  896. else
  897. priv->init_evtlog_size =
  898. priv->cfg->base_params->max_event_log_size;
  899. priv->init_errlog_ptr = pieces.init_errlog_ptr;
  900. priv->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  901. if (pieces.inst_evtlog_size)
  902. priv->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  903. else
  904. priv->inst_evtlog_size =
  905. priv->cfg->base_params->max_event_log_size;
  906. priv->inst_errlog_ptr = pieces.inst_errlog_ptr;
  907. priv->new_scan_threshold_behaviour =
  908. !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  909. if (!(priv->cfg->sku & EEPROM_SKU_CAP_IPAN_ENABLE))
  910. ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  911. /*
  912. * if not PAN, then don't support P2P -- might be a uCode
  913. * packaging bug or due to the eeprom check above
  914. */
  915. if (!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN))
  916. ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  917. if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
  918. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  919. priv->shrd->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  920. } else {
  921. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  922. priv->shrd->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  923. }
  924. /*
  925. * figure out the offset of chain noise reset and gain commands
  926. * base on the size of standard phy calibration commands table size
  927. */
  928. if (ucode_capa.standard_phy_calibration_size >
  929. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  930. ucode_capa.standard_phy_calibration_size =
  931. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  932. priv->phy_calib_chain_noise_reset_cmd =
  933. ucode_capa.standard_phy_calibration_size;
  934. priv->phy_calib_chain_noise_gain_cmd =
  935. ucode_capa.standard_phy_calibration_size + 1;
  936. /* initialize all valid contexts */
  937. iwl_init_context(priv, ucode_capa.flags);
  938. /**************************************************
  939. * This is still part of probe() in a sense...
  940. *
  941. * 9. Setup and register with mac80211 and debugfs
  942. **************************************************/
  943. err = iwlagn_mac_setup_register(priv, &ucode_capa);
  944. if (err)
  945. goto out_unbind;
  946. err = iwl_dbgfs_register(priv, DRV_NAME);
  947. if (err)
  948. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  949. /* We have our copies now, allow OS release its copies */
  950. release_firmware(ucode_raw);
  951. complete(&priv->firmware_loading_complete);
  952. return;
  953. try_again:
  954. /* try next, if any */
  955. if (iwl_request_firmware(priv, false))
  956. goto out_unbind;
  957. release_firmware(ucode_raw);
  958. return;
  959. err_pci_alloc:
  960. IWL_ERR(priv, "failed to allocate pci memory\n");
  961. iwl_dealloc_ucode(trans(priv));
  962. out_unbind:
  963. complete(&priv->firmware_loading_complete);
  964. device_release_driver(bus(priv)->dev);
  965. release_firmware(ucode_raw);
  966. }
  967. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  968. {
  969. struct iwl_ct_kill_config cmd;
  970. struct iwl_ct_kill_throttling_config adv_cmd;
  971. unsigned long flags;
  972. int ret = 0;
  973. spin_lock_irqsave(&priv->shrd->lock, flags);
  974. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
  975. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  976. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  977. priv->thermal_throttle.ct_kill_toggle = false;
  978. if (priv->cfg->base_params->support_ct_kill_exit) {
  979. adv_cmd.critical_temperature_enter =
  980. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  981. adv_cmd.critical_temperature_exit =
  982. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  983. ret = iwl_trans_send_cmd_pdu(trans(priv),
  984. REPLY_CT_KILL_CONFIG_CMD,
  985. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  986. if (ret)
  987. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  988. else
  989. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  990. "succeeded, critical temperature enter is %d,"
  991. "exit is %d\n",
  992. hw_params(priv).ct_kill_threshold,
  993. hw_params(priv).ct_kill_exit_threshold);
  994. } else {
  995. cmd.critical_temperature_R =
  996. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  997. ret = iwl_trans_send_cmd_pdu(trans(priv),
  998. REPLY_CT_KILL_CONFIG_CMD,
  999. CMD_SYNC, sizeof(cmd), &cmd);
  1000. if (ret)
  1001. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1002. else
  1003. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1004. "succeeded, "
  1005. "critical temperature is %d\n",
  1006. hw_params(priv).ct_kill_threshold);
  1007. }
  1008. }
  1009. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  1010. {
  1011. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  1012. struct iwl_host_cmd cmd = {
  1013. .id = CALIBRATION_CFG_CMD,
  1014. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  1015. .data = { &calib_cfg_cmd, },
  1016. };
  1017. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  1018. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  1019. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  1020. return iwl_trans_send_cmd(trans(priv), &cmd);
  1021. }
  1022. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  1023. {
  1024. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  1025. .valid = cpu_to_le32(valid_tx_ant),
  1026. };
  1027. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  1028. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  1029. return iwl_trans_send_cmd_pdu(trans(priv),
  1030. TX_ANT_CONFIGURATION_CMD,
  1031. CMD_SYNC,
  1032. sizeof(struct iwl_tx_ant_config_cmd),
  1033. &tx_ant_cmd);
  1034. } else {
  1035. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  1036. return -EOPNOTSUPP;
  1037. }
  1038. }
  1039. /**
  1040. * iwl_alive_start - called after REPLY_ALIVE notification received
  1041. * from protocol/runtime uCode (initialization uCode's
  1042. * Alive gets handled by iwl_init_alive_start()).
  1043. */
  1044. int iwl_alive_start(struct iwl_priv *priv)
  1045. {
  1046. int ret = 0;
  1047. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1048. /*TODO: this should go to the transport layer */
  1049. iwl_reset_ict(trans(priv));
  1050. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1051. /* After the ALIVE response, we can send host commands to the uCode */
  1052. set_bit(STATUS_ALIVE, &priv->shrd->status);
  1053. /* Enable watchdog to monitor the driver tx queues */
  1054. iwl_setup_watchdog(priv);
  1055. if (iwl_is_rfkill(priv->shrd))
  1056. return -ERFKILL;
  1057. /* download priority table before any calibration request */
  1058. if (priv->cfg->bt_params &&
  1059. priv->cfg->bt_params->advanced_bt_coexist) {
  1060. /* Configure Bluetooth device coexistence support */
  1061. if (priv->cfg->bt_params->bt_sco_disable)
  1062. priv->bt_enable_pspoll = false;
  1063. else
  1064. priv->bt_enable_pspoll = true;
  1065. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1066. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1067. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1068. iwlagn_send_advance_bt_config(priv);
  1069. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  1070. priv->cur_rssi_ctx = NULL;
  1071. iwlagn_send_prio_tbl(priv);
  1072. /* FIXME: w/a to force change uCode BT state machine */
  1073. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  1074. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1075. if (ret)
  1076. return ret;
  1077. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  1078. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1079. if (ret)
  1080. return ret;
  1081. } else {
  1082. /*
  1083. * default is 2-wire BT coexexistence support
  1084. */
  1085. iwl_send_bt_config(priv);
  1086. }
  1087. if (hw_params(priv).calib_rt_cfg)
  1088. iwlagn_send_calib_cfg_rt(priv,
  1089. hw_params(priv).calib_rt_cfg);
  1090. ieee80211_wake_queues(priv->hw);
  1091. priv->active_rate = IWL_RATES_MASK;
  1092. /* Configure Tx antenna selection based on H/W config */
  1093. iwlagn_send_tx_ant_config(priv, priv->cfg->valid_tx_ant);
  1094. if (iwl_is_associated_ctx(ctx) && !priv->shrd->wowlan) {
  1095. struct iwl_rxon_cmd *active_rxon =
  1096. (struct iwl_rxon_cmd *)&ctx->active;
  1097. /* apply any changes in staging */
  1098. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1099. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1100. } else {
  1101. struct iwl_rxon_context *tmp;
  1102. /* Initialize our rx_config data */
  1103. for_each_context(priv, tmp)
  1104. iwl_connection_init_rx_config(priv, tmp);
  1105. iwlagn_set_rxon_chain(priv, ctx);
  1106. }
  1107. if (!priv->shrd->wowlan) {
  1108. /* WoWLAN ucode will not reply in the same way, skip it */
  1109. iwl_reset_run_time_calib(priv);
  1110. }
  1111. set_bit(STATUS_READY, &priv->shrd->status);
  1112. /* Configure the adapter for unassociated operation */
  1113. ret = iwlagn_commit_rxon(priv, ctx);
  1114. if (ret)
  1115. return ret;
  1116. /* At this point, the NIC is initialized and operational */
  1117. iwl_rf_kill_ct_config(priv);
  1118. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1119. return iwl_power_update_mode(priv, true);
  1120. }
  1121. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1122. static void __iwl_down(struct iwl_priv *priv)
  1123. {
  1124. int exit_pending;
  1125. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1126. iwl_scan_cancel_timeout(priv, 200);
  1127. /*
  1128. * If active, scanning won't cancel it, so say it expired.
  1129. * No race since we hold the mutex here and a new one
  1130. * can't come in at this time.
  1131. */
  1132. ieee80211_remain_on_channel_expired(priv->hw);
  1133. exit_pending =
  1134. test_and_set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1135. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1136. * to prevent rearm timer */
  1137. del_timer_sync(&priv->watchdog);
  1138. iwl_clear_ucode_stations(priv, NULL);
  1139. iwl_dealloc_bcast_stations(priv);
  1140. iwl_clear_driver_stations(priv);
  1141. /* reset BT coex data */
  1142. priv->bt_status = 0;
  1143. priv->cur_rssi_ctx = NULL;
  1144. priv->bt_is_sco = 0;
  1145. if (priv->cfg->bt_params)
  1146. priv->bt_traffic_load =
  1147. priv->cfg->bt_params->bt_init_traffic_load;
  1148. else
  1149. priv->bt_traffic_load = 0;
  1150. priv->bt_full_concurrent = false;
  1151. priv->bt_ci_compliance = 0;
  1152. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1153. * exiting the module */
  1154. if (!exit_pending)
  1155. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1156. if (priv->mac80211_registered)
  1157. ieee80211_stop_queues(priv->hw);
  1158. iwl_trans_stop_device(trans(priv));
  1159. /* Clear out all status bits but a few that are stable across reset */
  1160. priv->shrd->status &=
  1161. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status) <<
  1162. STATUS_RF_KILL_HW |
  1163. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) <<
  1164. STATUS_GEO_CONFIGURED |
  1165. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  1166. STATUS_FW_ERROR |
  1167. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) <<
  1168. STATUS_EXIT_PENDING;
  1169. dev_kfree_skb(priv->beacon_skb);
  1170. priv->beacon_skb = NULL;
  1171. }
  1172. static void iwl_down(struct iwl_priv *priv)
  1173. {
  1174. mutex_lock(&priv->shrd->mutex);
  1175. __iwl_down(priv);
  1176. mutex_unlock(&priv->shrd->mutex);
  1177. iwl_cancel_deferred_work(priv);
  1178. }
  1179. #define MAX_HW_RESTARTS 5
  1180. static int __iwl_up(struct iwl_priv *priv)
  1181. {
  1182. struct iwl_rxon_context *ctx;
  1183. int ret;
  1184. lockdep_assert_held(&priv->shrd->mutex);
  1185. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  1186. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  1187. return -EIO;
  1188. }
  1189. for_each_context(priv, ctx) {
  1190. ret = iwlagn_alloc_bcast_station(priv, ctx);
  1191. if (ret) {
  1192. iwl_dealloc_bcast_stations(priv);
  1193. return ret;
  1194. }
  1195. }
  1196. ret = iwlagn_run_init_ucode(priv);
  1197. if (ret) {
  1198. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  1199. goto error;
  1200. }
  1201. ret = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
  1202. if (ret) {
  1203. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  1204. goto error;
  1205. }
  1206. ret = iwl_alive_start(priv);
  1207. if (ret)
  1208. goto error;
  1209. return 0;
  1210. error:
  1211. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1212. __iwl_down(priv);
  1213. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1214. IWL_ERR(priv, "Unable to initialize device.\n");
  1215. return ret;
  1216. }
  1217. /*****************************************************************************
  1218. *
  1219. * Workqueue callbacks
  1220. *
  1221. *****************************************************************************/
  1222. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  1223. {
  1224. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1225. run_time_calib_work);
  1226. mutex_lock(&priv->shrd->mutex);
  1227. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  1228. test_bit(STATUS_SCANNING, &priv->shrd->status)) {
  1229. mutex_unlock(&priv->shrd->mutex);
  1230. return;
  1231. }
  1232. if (priv->start_calib) {
  1233. iwl_chain_noise_calibration(priv);
  1234. iwl_sensitivity_calibration(priv);
  1235. }
  1236. mutex_unlock(&priv->shrd->mutex);
  1237. }
  1238. static void iwlagn_prepare_restart(struct iwl_priv *priv)
  1239. {
  1240. struct iwl_rxon_context *ctx;
  1241. bool bt_full_concurrent;
  1242. u8 bt_ci_compliance;
  1243. u8 bt_load;
  1244. u8 bt_status;
  1245. bool bt_is_sco;
  1246. lockdep_assert_held(&priv->shrd->mutex);
  1247. for_each_context(priv, ctx)
  1248. ctx->vif = NULL;
  1249. priv->is_open = 0;
  1250. /*
  1251. * __iwl_down() will clear the BT status variables,
  1252. * which is correct, but when we restart we really
  1253. * want to keep them so restore them afterwards.
  1254. *
  1255. * The restart process will later pick them up and
  1256. * re-configure the hw when we reconfigure the BT
  1257. * command.
  1258. */
  1259. bt_full_concurrent = priv->bt_full_concurrent;
  1260. bt_ci_compliance = priv->bt_ci_compliance;
  1261. bt_load = priv->bt_traffic_load;
  1262. bt_status = priv->bt_status;
  1263. bt_is_sco = priv->bt_is_sco;
  1264. __iwl_down(priv);
  1265. priv->bt_full_concurrent = bt_full_concurrent;
  1266. priv->bt_ci_compliance = bt_ci_compliance;
  1267. priv->bt_traffic_load = bt_load;
  1268. priv->bt_status = bt_status;
  1269. priv->bt_is_sco = bt_is_sco;
  1270. }
  1271. static void iwl_bg_restart(struct work_struct *data)
  1272. {
  1273. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  1274. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1275. return;
  1276. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  1277. mutex_lock(&priv->shrd->mutex);
  1278. iwlagn_prepare_restart(priv);
  1279. mutex_unlock(&priv->shrd->mutex);
  1280. iwl_cancel_deferred_work(priv);
  1281. ieee80211_restart_hw(priv->hw);
  1282. } else {
  1283. WARN_ON(1);
  1284. }
  1285. }
  1286. /*****************************************************************************
  1287. *
  1288. * mac80211 entry point functions
  1289. *
  1290. *****************************************************************************/
  1291. static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
  1292. {
  1293. .max = 1,
  1294. .types = BIT(NL80211_IFTYPE_STATION),
  1295. },
  1296. {
  1297. .max = 1,
  1298. .types = BIT(NL80211_IFTYPE_AP),
  1299. },
  1300. };
  1301. static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
  1302. {
  1303. .max = 2,
  1304. .types = BIT(NL80211_IFTYPE_STATION),
  1305. },
  1306. };
  1307. static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
  1308. {
  1309. .max = 1,
  1310. .types = BIT(NL80211_IFTYPE_STATION),
  1311. },
  1312. {
  1313. .max = 1,
  1314. .types = BIT(NL80211_IFTYPE_P2P_GO) |
  1315. BIT(NL80211_IFTYPE_AP),
  1316. },
  1317. };
  1318. static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
  1319. {
  1320. .max = 2,
  1321. .types = BIT(NL80211_IFTYPE_STATION),
  1322. },
  1323. {
  1324. .max = 1,
  1325. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  1326. },
  1327. };
  1328. static const struct ieee80211_iface_combination
  1329. iwlagn_iface_combinations_dualmode[] = {
  1330. { .num_different_channels = 1,
  1331. .max_interfaces = 2,
  1332. .beacon_int_infra_match = true,
  1333. .limits = iwlagn_sta_ap_limits,
  1334. .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
  1335. },
  1336. { .num_different_channels = 1,
  1337. .max_interfaces = 2,
  1338. .limits = iwlagn_2sta_limits,
  1339. .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
  1340. },
  1341. };
  1342. static const struct ieee80211_iface_combination
  1343. iwlagn_iface_combinations_p2p[] = {
  1344. { .num_different_channels = 1,
  1345. .max_interfaces = 2,
  1346. .beacon_int_infra_match = true,
  1347. .limits = iwlagn_p2p_sta_go_limits,
  1348. .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
  1349. },
  1350. { .num_different_channels = 1,
  1351. .max_interfaces = 2,
  1352. .limits = iwlagn_p2p_2sta_limits,
  1353. .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
  1354. },
  1355. };
  1356. /*
  1357. * Not a mac80211 entry point function, but it fits in with all the
  1358. * other mac80211 functions grouped here.
  1359. */
  1360. static int iwlagn_mac_setup_register(struct iwl_priv *priv,
  1361. struct iwlagn_ucode_capabilities *capa)
  1362. {
  1363. int ret;
  1364. struct ieee80211_hw *hw = priv->hw;
  1365. struct iwl_rxon_context *ctx;
  1366. hw->rate_control_algorithm = "iwl-agn-rs";
  1367. /* Tell mac80211 our characteristics */
  1368. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1369. IEEE80211_HW_AMPDU_AGGREGATION |
  1370. IEEE80211_HW_NEED_DTIM_PERIOD |
  1371. IEEE80211_HW_SPECTRUM_MGMT |
  1372. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  1373. /*
  1374. * Including the following line will crash some AP's. This
  1375. * workaround removes the stimulus which causes the crash until
  1376. * the AP software can be fixed.
  1377. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  1378. */
  1379. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  1380. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  1381. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  1382. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  1383. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  1384. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  1385. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  1386. hw->sta_data_size = sizeof(struct iwl_station_priv);
  1387. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  1388. for_each_context(priv, ctx) {
  1389. hw->wiphy->interface_modes |= ctx->interface_modes;
  1390. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  1391. }
  1392. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  1393. if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
  1394. hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
  1395. hw->wiphy->n_iface_combinations =
  1396. ARRAY_SIZE(iwlagn_iface_combinations_p2p);
  1397. } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  1398. hw->wiphy->iface_combinations = iwlagn_iface_combinations_dualmode;
  1399. hw->wiphy->n_iface_combinations =
  1400. ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
  1401. }
  1402. hw->wiphy->max_remain_on_channel_duration = 1000;
  1403. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  1404. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  1405. WIPHY_FLAG_IBSS_RSN;
  1406. if (trans(priv)->ucode_wowlan.code.len &&
  1407. device_can_wakeup(bus(priv)->dev)) {
  1408. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  1409. WIPHY_WOWLAN_DISCONNECT |
  1410. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  1411. WIPHY_WOWLAN_RFKILL_RELEASE;
  1412. if (!iwlagn_mod_params.sw_crypto)
  1413. hw->wiphy->wowlan.flags |=
  1414. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  1415. WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  1416. hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
  1417. hw->wiphy->wowlan.pattern_min_len =
  1418. IWLAGN_WOWLAN_MIN_PATTERN_LEN;
  1419. hw->wiphy->wowlan.pattern_max_len =
  1420. IWLAGN_WOWLAN_MAX_PATTERN_LEN;
  1421. }
  1422. if (iwlagn_mod_params.power_save)
  1423. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1424. else
  1425. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1426. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  1427. /* we create the 802.11 header and a zero-length SSID element */
  1428. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  1429. /* Default value; 4 EDCA QOS priorities */
  1430. hw->queues = 4;
  1431. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  1432. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  1433. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1434. &priv->bands[IEEE80211_BAND_2GHZ];
  1435. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  1436. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1437. &priv->bands[IEEE80211_BAND_5GHZ];
  1438. iwl_leds_init(priv);
  1439. ret = ieee80211_register_hw(priv->hw);
  1440. if (ret) {
  1441. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  1442. return ret;
  1443. }
  1444. priv->mac80211_registered = 1;
  1445. return 0;
  1446. }
  1447. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  1448. {
  1449. struct iwl_priv *priv = hw->priv;
  1450. int ret;
  1451. IWL_DEBUG_MAC80211(priv, "enter\n");
  1452. /* we should be verifying the device is ready to be opened */
  1453. mutex_lock(&priv->shrd->mutex);
  1454. ret = __iwl_up(priv);
  1455. mutex_unlock(&priv->shrd->mutex);
  1456. if (ret)
  1457. return ret;
  1458. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  1459. /* Now we should be done, and the READY bit should be set. */
  1460. if (WARN_ON(!test_bit(STATUS_READY, &priv->shrd->status)))
  1461. ret = -EIO;
  1462. iwlagn_led_enable(priv);
  1463. priv->is_open = 1;
  1464. IWL_DEBUG_MAC80211(priv, "leave\n");
  1465. return 0;
  1466. }
  1467. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  1468. {
  1469. struct iwl_priv *priv = hw->priv;
  1470. IWL_DEBUG_MAC80211(priv, "enter\n");
  1471. if (!priv->is_open)
  1472. return;
  1473. priv->is_open = 0;
  1474. iwl_down(priv);
  1475. flush_workqueue(priv->shrd->workqueue);
  1476. /* User space software may expect getting rfkill changes
  1477. * even if interface is down */
  1478. iwl_write32(bus(priv), CSR_INT, 0xFFFFFFFF);
  1479. iwl_enable_rfkill_int(priv);
  1480. IWL_DEBUG_MAC80211(priv, "leave\n");
  1481. }
  1482. #ifdef CONFIG_PM_SLEEP
  1483. static int iwlagn_send_patterns(struct iwl_priv *priv,
  1484. struct cfg80211_wowlan *wowlan)
  1485. {
  1486. struct iwlagn_wowlan_patterns_cmd *pattern_cmd;
  1487. struct iwl_host_cmd cmd = {
  1488. .id = REPLY_WOWLAN_PATTERNS,
  1489. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  1490. .flags = CMD_SYNC,
  1491. };
  1492. int i, err;
  1493. if (!wowlan->n_patterns)
  1494. return 0;
  1495. cmd.len[0] = sizeof(*pattern_cmd) +
  1496. wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
  1497. pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
  1498. if (!pattern_cmd)
  1499. return -ENOMEM;
  1500. pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
  1501. for (i = 0; i < wowlan->n_patterns; i++) {
  1502. int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
  1503. memcpy(&pattern_cmd->patterns[i].mask,
  1504. wowlan->patterns[i].mask, mask_len);
  1505. memcpy(&pattern_cmd->patterns[i].pattern,
  1506. wowlan->patterns[i].pattern,
  1507. wowlan->patterns[i].pattern_len);
  1508. pattern_cmd->patterns[i].mask_size = mask_len;
  1509. pattern_cmd->patterns[i].pattern_size =
  1510. wowlan->patterns[i].pattern_len;
  1511. }
  1512. cmd.data[0] = pattern_cmd;
  1513. err = iwl_trans_send_cmd(trans(priv), &cmd);
  1514. kfree(pattern_cmd);
  1515. return err;
  1516. }
  1517. #endif
  1518. static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
  1519. struct ieee80211_vif *vif,
  1520. struct cfg80211_gtk_rekey_data *data)
  1521. {
  1522. struct iwl_priv *priv = hw->priv;
  1523. if (iwlagn_mod_params.sw_crypto)
  1524. return;
  1525. IWL_DEBUG_MAC80211(priv, "enter\n");
  1526. mutex_lock(&priv->shrd->mutex);
  1527. if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
  1528. goto out;
  1529. memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
  1530. memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
  1531. priv->replay_ctr = cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
  1532. priv->have_rekey_data = true;
  1533. out:
  1534. mutex_unlock(&priv->shrd->mutex);
  1535. IWL_DEBUG_MAC80211(priv, "leave\n");
  1536. }
  1537. struct wowlan_key_data {
  1538. struct iwl_rxon_context *ctx;
  1539. struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc;
  1540. struct iwlagn_wowlan_tkip_params_cmd *tkip;
  1541. const u8 *bssid;
  1542. bool error, use_rsc_tsc, use_tkip;
  1543. };
  1544. #ifdef CONFIG_PM_SLEEP
  1545. static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
  1546. {
  1547. int i;
  1548. for (i = 0; i < IWLAGN_P1K_SIZE; i++)
  1549. out[i] = cpu_to_le16(p1k[i]);
  1550. }
  1551. static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw,
  1552. struct ieee80211_vif *vif,
  1553. struct ieee80211_sta *sta,
  1554. struct ieee80211_key_conf *key,
  1555. void *_data)
  1556. {
  1557. struct iwl_priv *priv = hw->priv;
  1558. struct wowlan_key_data *data = _data;
  1559. struct iwl_rxon_context *ctx = data->ctx;
  1560. struct aes_sc *aes_sc, *aes_tx_sc = NULL;
  1561. struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
  1562. struct iwlagn_p1k_cache *rx_p1ks;
  1563. u8 *rx_mic_key;
  1564. struct ieee80211_key_seq seq;
  1565. u32 cur_rx_iv32 = 0;
  1566. u16 p1k[IWLAGN_P1K_SIZE];
  1567. int ret, i;
  1568. mutex_lock(&priv->shrd->mutex);
  1569. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  1570. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  1571. !sta && !ctx->key_mapping_keys)
  1572. ret = iwl_set_default_wep_key(priv, ctx, key);
  1573. else
  1574. ret = iwl_set_dynamic_key(priv, ctx, key, sta);
  1575. if (ret) {
  1576. IWL_ERR(priv, "Error setting key during suspend!\n");
  1577. data->error = true;
  1578. }
  1579. switch (key->cipher) {
  1580. case WLAN_CIPHER_SUITE_TKIP:
  1581. if (sta) {
  1582. tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
  1583. tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
  1584. rx_p1ks = data->tkip->rx_uni;
  1585. ieee80211_get_key_tx_seq(key, &seq);
  1586. tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
  1587. tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
  1588. ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
  1589. iwlagn_convert_p1k(p1k, data->tkip->tx.p1k);
  1590. memcpy(data->tkip->mic_keys.tx,
  1591. &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
  1592. IWLAGN_MIC_KEY_SIZE);
  1593. rx_mic_key = data->tkip->mic_keys.rx_unicast;
  1594. } else {
  1595. tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
  1596. rx_p1ks = data->tkip->rx_multi;
  1597. rx_mic_key = data->tkip->mic_keys.rx_mcast;
  1598. }
  1599. /*
  1600. * For non-QoS this relies on the fact that both the uCode and
  1601. * mac80211 use TID 0 (as they need to to avoid replay attacks)
  1602. * for checking the IV in the frames.
  1603. */
  1604. for (i = 0; i < IWLAGN_NUM_RSC; i++) {
  1605. ieee80211_get_key_rx_seq(key, i, &seq);
  1606. tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
  1607. tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
  1608. /* wrapping isn't allowed, AP must rekey */
  1609. if (seq.tkip.iv32 > cur_rx_iv32)
  1610. cur_rx_iv32 = seq.tkip.iv32;
  1611. }
  1612. ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k);
  1613. iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k);
  1614. ieee80211_get_tkip_rx_p1k(key, data->bssid,
  1615. cur_rx_iv32 + 1, p1k);
  1616. iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k);
  1617. memcpy(rx_mic_key,
  1618. &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
  1619. IWLAGN_MIC_KEY_SIZE);
  1620. data->use_tkip = true;
  1621. data->use_rsc_tsc = true;
  1622. break;
  1623. case WLAN_CIPHER_SUITE_CCMP:
  1624. if (sta) {
  1625. u8 *pn = seq.ccmp.pn;
  1626. aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
  1627. aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
  1628. ieee80211_get_key_tx_seq(key, &seq);
  1629. aes_tx_sc->pn = cpu_to_le64(
  1630. (u64)pn[5] |
  1631. ((u64)pn[4] << 8) |
  1632. ((u64)pn[3] << 16) |
  1633. ((u64)pn[2] << 24) |
  1634. ((u64)pn[1] << 32) |
  1635. ((u64)pn[0] << 40));
  1636. } else
  1637. aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
  1638. /*
  1639. * For non-QoS this relies on the fact that both the uCode and
  1640. * mac80211 use TID 0 for checking the IV in the frames.
  1641. */
  1642. for (i = 0; i < IWLAGN_NUM_RSC; i++) {
  1643. u8 *pn = seq.ccmp.pn;
  1644. ieee80211_get_key_rx_seq(key, i, &seq);
  1645. aes_sc->pn = cpu_to_le64(
  1646. (u64)pn[5] |
  1647. ((u64)pn[4] << 8) |
  1648. ((u64)pn[3] << 16) |
  1649. ((u64)pn[2] << 24) |
  1650. ((u64)pn[1] << 32) |
  1651. ((u64)pn[0] << 40));
  1652. }
  1653. data->use_rsc_tsc = true;
  1654. break;
  1655. }
  1656. mutex_unlock(&priv->shrd->mutex);
  1657. }
  1658. static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
  1659. struct cfg80211_wowlan *wowlan)
  1660. {
  1661. struct iwl_priv *priv = hw->priv;
  1662. struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd;
  1663. struct iwl_rxon_cmd rxon;
  1664. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1665. struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd;
  1666. struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {};
  1667. struct wowlan_key_data key_data = {
  1668. .ctx = ctx,
  1669. .bssid = ctx->active.bssid_addr,
  1670. .use_rsc_tsc = false,
  1671. .tkip = &tkip_cmd,
  1672. .use_tkip = false,
  1673. };
  1674. struct iwlagn_d3_config_cmd d3_cfg_cmd = {};
  1675. int ret, i;
  1676. u16 seq;
  1677. if (WARN_ON(!wowlan))
  1678. return -EINVAL;
  1679. IWL_DEBUG_MAC80211(priv, "enter\n");
  1680. mutex_lock(&priv->shrd->mutex);
  1681. /* Don't attempt WoWLAN when not associated, tear down instead. */
  1682. if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
  1683. !iwl_is_associated_ctx(ctx)) {
  1684. ret = 1;
  1685. goto out;
  1686. }
  1687. key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
  1688. if (!key_data.rsc_tsc) {
  1689. ret = -ENOMEM;
  1690. goto out;
  1691. }
  1692. memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd));
  1693. /*
  1694. * We know the last used seqno, and the uCode expects to know that
  1695. * one, it will increment before TX.
  1696. */
  1697. seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ;
  1698. wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq);
  1699. /*
  1700. * For QoS counters, we store the one to use next, so subtract 0x10
  1701. * since the uCode will add 0x10 before using the value.
  1702. */
  1703. for (i = 0; i < 8; i++) {
  1704. seq = priv->shrd->tid_data[IWL_AP_ID][i].seq_number;
  1705. seq -= 0x10;
  1706. wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq);
  1707. }
  1708. if (wowlan->disconnect)
  1709. wakeup_filter_cmd.enabled |=
  1710. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
  1711. IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE);
  1712. if (wowlan->magic_pkt)
  1713. wakeup_filter_cmd.enabled |=
  1714. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET);
  1715. if (wowlan->gtk_rekey_failure)
  1716. wakeup_filter_cmd.enabled |=
  1717. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
  1718. if (wowlan->eap_identity_req)
  1719. wakeup_filter_cmd.enabled |=
  1720. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ);
  1721. if (wowlan->four_way_handshake)
  1722. wakeup_filter_cmd.enabled |=
  1723. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
  1724. if (wowlan->n_patterns)
  1725. wakeup_filter_cmd.enabled |=
  1726. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH);
  1727. if (wowlan->rfkill_release)
  1728. d3_cfg_cmd.wakeup_flags |=
  1729. cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL);
  1730. iwl_scan_cancel_timeout(priv, 200);
  1731. memcpy(&rxon, &ctx->active, sizeof(rxon));
  1732. iwl_trans_stop_device(trans(priv));
  1733. priv->shrd->wowlan = true;
  1734. ret = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
  1735. if (ret)
  1736. goto error;
  1737. /* now configure WoWLAN ucode */
  1738. ret = iwl_alive_start(priv);
  1739. if (ret)
  1740. goto error;
  1741. memcpy(&ctx->staging, &rxon, sizeof(rxon));
  1742. ret = iwlagn_commit_rxon(priv, ctx);
  1743. if (ret)
  1744. goto error;
  1745. ret = iwl_power_update_mode(priv, true);
  1746. if (ret)
  1747. goto error;
  1748. if (!iwlagn_mod_params.sw_crypto) {
  1749. /* mark all keys clear */
  1750. priv->ucode_key_table = 0;
  1751. ctx->key_mapping_keys = 0;
  1752. /*
  1753. * This needs to be unlocked due to lock ordering
  1754. * constraints. Since we're in the suspend path
  1755. * that isn't really a problem though.
  1756. */
  1757. mutex_unlock(&priv->shrd->mutex);
  1758. ieee80211_iter_keys(priv->hw, ctx->vif,
  1759. iwlagn_wowlan_program_keys,
  1760. &key_data);
  1761. mutex_lock(&priv->shrd->mutex);
  1762. if (key_data.error) {
  1763. ret = -EIO;
  1764. goto error;
  1765. }
  1766. if (key_data.use_rsc_tsc) {
  1767. struct iwl_host_cmd rsc_tsc_cmd = {
  1768. .id = REPLY_WOWLAN_TSC_RSC_PARAMS,
  1769. .flags = CMD_SYNC,
  1770. .data[0] = key_data.rsc_tsc,
  1771. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  1772. .len[0] = sizeof(*key_data.rsc_tsc),
  1773. };
  1774. ret = iwl_trans_send_cmd(trans(priv), &rsc_tsc_cmd);
  1775. if (ret)
  1776. goto error;
  1777. }
  1778. if (key_data.use_tkip) {
  1779. ret = iwl_trans_send_cmd_pdu(trans(priv),
  1780. REPLY_WOWLAN_TKIP_PARAMS,
  1781. CMD_SYNC, sizeof(tkip_cmd),
  1782. &tkip_cmd);
  1783. if (ret)
  1784. goto error;
  1785. }
  1786. if (priv->have_rekey_data) {
  1787. memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
  1788. memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN);
  1789. kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
  1790. memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN);
  1791. kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
  1792. kek_kck_cmd.replay_ctr = priv->replay_ctr;
  1793. ret = iwl_trans_send_cmd_pdu(trans(priv),
  1794. REPLY_WOWLAN_KEK_KCK_MATERIAL,
  1795. CMD_SYNC, sizeof(kek_kck_cmd),
  1796. &kek_kck_cmd);
  1797. if (ret)
  1798. goto error;
  1799. }
  1800. }
  1801. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_D3_CONFIG, CMD_SYNC,
  1802. sizeof(d3_cfg_cmd), &d3_cfg_cmd);
  1803. if (ret)
  1804. goto error;
  1805. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_WOWLAN_WAKEUP_FILTER,
  1806. CMD_SYNC, sizeof(wakeup_filter_cmd),
  1807. &wakeup_filter_cmd);
  1808. if (ret)
  1809. goto error;
  1810. ret = iwlagn_send_patterns(priv, wowlan);
  1811. if (ret)
  1812. goto error;
  1813. device_set_wakeup_enable(bus(priv)->dev, true);
  1814. /* Now let the ucode operate on its own */
  1815. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_SET,
  1816. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  1817. goto out;
  1818. error:
  1819. priv->shrd->wowlan = false;
  1820. iwlagn_prepare_restart(priv);
  1821. ieee80211_restart_hw(priv->hw);
  1822. out:
  1823. mutex_unlock(&priv->shrd->mutex);
  1824. kfree(key_data.rsc_tsc);
  1825. IWL_DEBUG_MAC80211(priv, "leave\n");
  1826. return ret;
  1827. }
  1828. static int iwlagn_mac_resume(struct ieee80211_hw *hw)
  1829. {
  1830. struct iwl_priv *priv = hw->priv;
  1831. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1832. struct ieee80211_vif *vif;
  1833. unsigned long flags;
  1834. u32 base, status = 0xffffffff;
  1835. int ret = -EIO;
  1836. IWL_DEBUG_MAC80211(priv, "enter\n");
  1837. mutex_lock(&priv->shrd->mutex);
  1838. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
  1839. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  1840. base = priv->device_pointers.error_event_table;
  1841. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  1842. spin_lock_irqsave(&bus(priv)->reg_lock, flags);
  1843. ret = iwl_grab_nic_access_silent(bus(priv));
  1844. if (ret == 0) {
  1845. iwl_write32(bus(priv), HBUS_TARG_MEM_RADDR, base);
  1846. status = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  1847. iwl_release_nic_access(bus(priv));
  1848. }
  1849. spin_unlock_irqrestore(&bus(priv)->reg_lock, flags);
  1850. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1851. if (ret == 0) {
  1852. struct iwl_trans *trans = trans(priv);
  1853. if (!priv->wowlan_sram)
  1854. priv->wowlan_sram =
  1855. kzalloc(trans->ucode_wowlan.data.len,
  1856. GFP_KERNEL);
  1857. if (priv->wowlan_sram)
  1858. _iwl_read_targ_mem_words(
  1859. bus(priv), 0x800000, priv->wowlan_sram,
  1860. trans->ucode_wowlan.data.len / 4);
  1861. }
  1862. #endif
  1863. }
  1864. /* we'll clear ctx->vif during iwlagn_prepare_restart() */
  1865. vif = ctx->vif;
  1866. priv->shrd->wowlan = false;
  1867. device_set_wakeup_enable(bus(priv)->dev, false);
  1868. iwlagn_prepare_restart(priv);
  1869. memset((void *)&ctx->active, 0, sizeof(ctx->active));
  1870. iwl_connection_init_rx_config(priv, ctx);
  1871. iwlagn_set_rxon_chain(priv, ctx);
  1872. mutex_unlock(&priv->shrd->mutex);
  1873. IWL_DEBUG_MAC80211(priv, "leave\n");
  1874. ieee80211_resume_disconnect(vif);
  1875. return 1;
  1876. }
  1877. #endif
  1878. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  1879. {
  1880. struct iwl_priv *priv = hw->priv;
  1881. IWL_DEBUG_MACDUMP(priv, "enter\n");
  1882. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  1883. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  1884. if (iwlagn_tx_skb(priv, skb))
  1885. dev_kfree_skb_any(skb);
  1886. IWL_DEBUG_MACDUMP(priv, "leave\n");
  1887. }
  1888. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  1889. struct ieee80211_vif *vif,
  1890. struct ieee80211_key_conf *keyconf,
  1891. struct ieee80211_sta *sta,
  1892. u32 iv32, u16 *phase1key)
  1893. {
  1894. struct iwl_priv *priv = hw->priv;
  1895. iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
  1896. }
  1897. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1898. struct ieee80211_vif *vif,
  1899. struct ieee80211_sta *sta,
  1900. struct ieee80211_key_conf *key)
  1901. {
  1902. struct iwl_priv *priv = hw->priv;
  1903. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1904. struct iwl_rxon_context *ctx = vif_priv->ctx;
  1905. int ret;
  1906. bool is_default_wep_key = false;
  1907. IWL_DEBUG_MAC80211(priv, "enter\n");
  1908. if (iwlagn_mod_params.sw_crypto) {
  1909. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  1910. return -EOPNOTSUPP;
  1911. }
  1912. /*
  1913. * We could program these keys into the hardware as well, but we
  1914. * don't expect much multicast traffic in IBSS and having keys
  1915. * for more stations is probably more useful.
  1916. *
  1917. * Mark key TX-only and return 0.
  1918. */
  1919. if (vif->type == NL80211_IFTYPE_ADHOC &&
  1920. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1921. key->hw_key_idx = WEP_INVALID_OFFSET;
  1922. return 0;
  1923. }
  1924. /* If they key was TX-only, accept deletion */
  1925. if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
  1926. return 0;
  1927. mutex_lock(&priv->shrd->mutex);
  1928. iwl_scan_cancel_timeout(priv, 100);
  1929. BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
  1930. /*
  1931. * If we are getting WEP group key and we didn't receive any key mapping
  1932. * so far, we are in legacy wep mode (group key only), otherwise we are
  1933. * in 1X mode.
  1934. * In legacy wep mode, we use another host command to the uCode.
  1935. */
  1936. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  1937. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  1938. if (cmd == SET_KEY)
  1939. is_default_wep_key = !ctx->key_mapping_keys;
  1940. else
  1941. is_default_wep_key =
  1942. key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
  1943. }
  1944. switch (cmd) {
  1945. case SET_KEY:
  1946. if (is_default_wep_key) {
  1947. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  1948. break;
  1949. }
  1950. ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
  1951. if (ret) {
  1952. /*
  1953. * can't add key for RX, but we don't need it
  1954. * in the device for TX so still return 0
  1955. */
  1956. ret = 0;
  1957. key->hw_key_idx = WEP_INVALID_OFFSET;
  1958. }
  1959. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  1960. break;
  1961. case DISABLE_KEY:
  1962. if (is_default_wep_key)
  1963. ret = iwl_remove_default_wep_key(priv, ctx, key);
  1964. else
  1965. ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
  1966. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  1967. break;
  1968. default:
  1969. ret = -EINVAL;
  1970. }
  1971. mutex_unlock(&priv->shrd->mutex);
  1972. IWL_DEBUG_MAC80211(priv, "leave\n");
  1973. return ret;
  1974. }
  1975. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  1976. struct ieee80211_vif *vif,
  1977. enum ieee80211_ampdu_mlme_action action,
  1978. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  1979. u8 buf_size)
  1980. {
  1981. struct iwl_priv *priv = hw->priv;
  1982. int ret = -EINVAL;
  1983. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  1984. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1985. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  1986. sta->addr, tid);
  1987. if (!(priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE))
  1988. return -EACCES;
  1989. IWL_DEBUG_MAC80211(priv, "enter\n");
  1990. mutex_lock(&priv->shrd->mutex);
  1991. switch (action) {
  1992. case IEEE80211_AMPDU_RX_START:
  1993. IWL_DEBUG_HT(priv, "start Rx\n");
  1994. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  1995. break;
  1996. case IEEE80211_AMPDU_RX_STOP:
  1997. IWL_DEBUG_HT(priv, "stop Rx\n");
  1998. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  1999. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  2000. ret = 0;
  2001. break;
  2002. case IEEE80211_AMPDU_TX_START:
  2003. IWL_DEBUG_HT(priv, "start Tx\n");
  2004. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  2005. break;
  2006. case IEEE80211_AMPDU_TX_STOP:
  2007. IWL_DEBUG_HT(priv, "stop Tx\n");
  2008. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  2009. if ((ret == 0) && (priv->agg_tids_count > 0)) {
  2010. priv->agg_tids_count--;
  2011. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  2012. priv->agg_tids_count);
  2013. }
  2014. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  2015. ret = 0;
  2016. if (!priv->agg_tids_count && priv->cfg->ht_params &&
  2017. priv->cfg->ht_params->use_rts_for_aggregation) {
  2018. /*
  2019. * switch off RTS/CTS if it was previously enabled
  2020. */
  2021. sta_priv->lq_sta.lq.general_params.flags &=
  2022. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2023. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2024. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2025. }
  2026. break;
  2027. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2028. buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
  2029. iwl_trans_tx_agg_setup(trans(priv), ctx->ctxid, iwl_sta_id(sta),
  2030. tid, buf_size);
  2031. /*
  2032. * If the limit is 0, then it wasn't initialised yet,
  2033. * use the default. We can do that since we take the
  2034. * minimum below, and we don't want to go above our
  2035. * default due to hardware restrictions.
  2036. */
  2037. if (sta_priv->max_agg_bufsize == 0)
  2038. sta_priv->max_agg_bufsize =
  2039. LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2040. /*
  2041. * Even though in theory the peer could have different
  2042. * aggregation reorder buffer sizes for different sessions,
  2043. * our ucode doesn't allow for that and has a global limit
  2044. * for each station. Therefore, use the minimum of all the
  2045. * aggregation sessions and our default value.
  2046. */
  2047. sta_priv->max_agg_bufsize =
  2048. min(sta_priv->max_agg_bufsize, buf_size);
  2049. if (priv->cfg->ht_params &&
  2050. priv->cfg->ht_params->use_rts_for_aggregation) {
  2051. /*
  2052. * switch to RTS/CTS if it is the prefer protection
  2053. * method for HT traffic
  2054. */
  2055. sta_priv->lq_sta.lq.general_params.flags |=
  2056. LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2057. }
  2058. priv->agg_tids_count++;
  2059. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  2060. priv->agg_tids_count);
  2061. sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
  2062. sta_priv->max_agg_bufsize;
  2063. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2064. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2065. IWL_INFO(priv, "Tx aggregation enabled on ra = %pM tid = %d\n",
  2066. sta->addr, tid);
  2067. ret = 0;
  2068. break;
  2069. }
  2070. mutex_unlock(&priv->shrd->mutex);
  2071. IWL_DEBUG_MAC80211(priv, "leave\n");
  2072. return ret;
  2073. }
  2074. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  2075. struct ieee80211_vif *vif,
  2076. struct ieee80211_sta *sta)
  2077. {
  2078. struct iwl_priv *priv = hw->priv;
  2079. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  2080. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2081. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2082. int ret = 0;
  2083. u8 sta_id;
  2084. IWL_DEBUG_MAC80211(priv, "received request to add station %pM\n",
  2085. sta->addr);
  2086. mutex_lock(&priv->shrd->mutex);
  2087. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2088. sta->addr);
  2089. sta_priv->sta_id = IWL_INVALID_STATION;
  2090. atomic_set(&sta_priv->pending_frames, 0);
  2091. if (vif->type == NL80211_IFTYPE_AP)
  2092. sta_priv->client = true;
  2093. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  2094. is_ap, sta, &sta_id);
  2095. if (ret) {
  2096. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2097. sta->addr, ret);
  2098. /* Should we return success if return code is EEXIST ? */
  2099. goto out;
  2100. }
  2101. sta_priv->sta_id = sta_id;
  2102. /* Initialize rate scaling */
  2103. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2104. sta->addr);
  2105. iwl_rs_rate_init(priv, sta, sta_id);
  2106. out:
  2107. mutex_unlock(&priv->shrd->mutex);
  2108. IWL_DEBUG_MAC80211(priv, "leave\n");
  2109. return ret;
  2110. }
  2111. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  2112. struct ieee80211_channel_switch *ch_switch)
  2113. {
  2114. struct iwl_priv *priv = hw->priv;
  2115. const struct iwl_channel_info *ch_info;
  2116. struct ieee80211_conf *conf = &hw->conf;
  2117. struct ieee80211_channel *channel = ch_switch->channel;
  2118. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  2119. /*
  2120. * MULTI-FIXME
  2121. * When we add support for multiple interfaces, we need to
  2122. * revisit this. The channel switch command in the device
  2123. * only affects the BSS context, but what does that really
  2124. * mean? And what if we get a CSA on the second interface?
  2125. * This needs a lot of work.
  2126. */
  2127. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2128. u16 ch;
  2129. IWL_DEBUG_MAC80211(priv, "enter\n");
  2130. mutex_lock(&priv->shrd->mutex);
  2131. if (iwl_is_rfkill(priv->shrd))
  2132. goto out;
  2133. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  2134. test_bit(STATUS_SCANNING, &priv->shrd->status) ||
  2135. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
  2136. goto out;
  2137. if (!iwl_is_associated_ctx(ctx))
  2138. goto out;
  2139. if (!priv->cfg->lib->set_channel_switch)
  2140. goto out;
  2141. ch = channel->hw_value;
  2142. if (le16_to_cpu(ctx->active.channel) == ch)
  2143. goto out;
  2144. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  2145. if (!is_channel_valid(ch_info)) {
  2146. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  2147. goto out;
  2148. }
  2149. spin_lock_irq(&priv->shrd->lock);
  2150. priv->current_ht_config.smps = conf->smps_mode;
  2151. /* Configure HT40 channels */
  2152. ctx->ht.enabled = conf_is_ht(conf);
  2153. if (ctx->ht.enabled) {
  2154. if (conf_is_ht40_minus(conf)) {
  2155. ctx->ht.extension_chan_offset =
  2156. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2157. ctx->ht.is_40mhz = true;
  2158. } else if (conf_is_ht40_plus(conf)) {
  2159. ctx->ht.extension_chan_offset =
  2160. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2161. ctx->ht.is_40mhz = true;
  2162. } else {
  2163. ctx->ht.extension_chan_offset =
  2164. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2165. ctx->ht.is_40mhz = false;
  2166. }
  2167. } else
  2168. ctx->ht.is_40mhz = false;
  2169. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2170. ctx->staging.flags = 0;
  2171. iwl_set_rxon_channel(priv, channel, ctx);
  2172. iwl_set_rxon_ht(priv, ht_conf);
  2173. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  2174. spin_unlock_irq(&priv->shrd->lock);
  2175. iwl_set_rate(priv);
  2176. /*
  2177. * at this point, staging_rxon has the
  2178. * configuration for channel switch
  2179. */
  2180. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  2181. priv->switch_channel = cpu_to_le16(ch);
  2182. if (priv->cfg->lib->set_channel_switch(priv, ch_switch)) {
  2183. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  2184. priv->switch_channel = 0;
  2185. ieee80211_chswitch_done(ctx->vif, false);
  2186. }
  2187. out:
  2188. mutex_unlock(&priv->shrd->mutex);
  2189. IWL_DEBUG_MAC80211(priv, "leave\n");
  2190. }
  2191. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  2192. unsigned int changed_flags,
  2193. unsigned int *total_flags,
  2194. u64 multicast)
  2195. {
  2196. struct iwl_priv *priv = hw->priv;
  2197. __le32 filter_or = 0, filter_nand = 0;
  2198. struct iwl_rxon_context *ctx;
  2199. #define CHK(test, flag) do { \
  2200. if (*total_flags & (test)) \
  2201. filter_or |= (flag); \
  2202. else \
  2203. filter_nand |= (flag); \
  2204. } while (0)
  2205. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2206. changed_flags, *total_flags);
  2207. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2208. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2209. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2210. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2211. #undef CHK
  2212. mutex_lock(&priv->shrd->mutex);
  2213. for_each_context(priv, ctx) {
  2214. ctx->staging.filter_flags &= ~filter_nand;
  2215. ctx->staging.filter_flags |= filter_or;
  2216. /*
  2217. * Not committing directly because hardware can perform a scan,
  2218. * but we'll eventually commit the filter flags change anyway.
  2219. */
  2220. }
  2221. mutex_unlock(&priv->shrd->mutex);
  2222. /*
  2223. * Receiving all multicast frames is always enabled by the
  2224. * default flags setup in iwl_connection_init_rx_config()
  2225. * since we currently do not support programming multicast
  2226. * filters into the device.
  2227. */
  2228. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2229. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2230. }
  2231. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  2232. {
  2233. struct iwl_priv *priv = hw->priv;
  2234. mutex_lock(&priv->shrd->mutex);
  2235. IWL_DEBUG_MAC80211(priv, "enter\n");
  2236. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  2237. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  2238. goto done;
  2239. }
  2240. if (iwl_is_rfkill(priv->shrd)) {
  2241. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  2242. goto done;
  2243. }
  2244. /*
  2245. * mac80211 will not push any more frames for transmit
  2246. * until the flush is completed
  2247. */
  2248. if (drop) {
  2249. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  2250. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  2251. IWL_ERR(priv, "flush request fail\n");
  2252. goto done;
  2253. }
  2254. }
  2255. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  2256. iwl_trans_wait_tx_queue_empty(trans(priv));
  2257. done:
  2258. mutex_unlock(&priv->shrd->mutex);
  2259. IWL_DEBUG_MAC80211(priv, "leave\n");
  2260. }
  2261. void iwlagn_disable_roc(struct iwl_priv *priv)
  2262. {
  2263. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  2264. lockdep_assert_held(&priv->shrd->mutex);
  2265. if (!priv->hw_roc_setup)
  2266. return;
  2267. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  2268. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2269. priv->hw_roc_channel = NULL;
  2270. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  2271. iwlagn_commit_rxon(priv, ctx);
  2272. ctx->is_active = false;
  2273. priv->hw_roc_setup = false;
  2274. }
  2275. static void iwlagn_disable_roc_work(struct work_struct *work)
  2276. {
  2277. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2278. hw_roc_disable_work.work);
  2279. mutex_lock(&priv->shrd->mutex);
  2280. iwlagn_disable_roc(priv);
  2281. mutex_unlock(&priv->shrd->mutex);
  2282. }
  2283. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  2284. struct ieee80211_channel *channel,
  2285. enum nl80211_channel_type channel_type,
  2286. int duration)
  2287. {
  2288. struct iwl_priv *priv = hw->priv;
  2289. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  2290. int err = 0;
  2291. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2292. return -EOPNOTSUPP;
  2293. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  2294. return -EOPNOTSUPP;
  2295. IWL_DEBUG_MAC80211(priv, "enter\n");
  2296. mutex_lock(&priv->shrd->mutex);
  2297. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
  2298. err = -EBUSY;
  2299. goto out;
  2300. }
  2301. priv->hw_roc_channel = channel;
  2302. priv->hw_roc_chantype = channel_type;
  2303. priv->hw_roc_duration = duration;
  2304. priv->hw_roc_start_notified = false;
  2305. cancel_delayed_work(&priv->hw_roc_disable_work);
  2306. if (!ctx->is_active) {
  2307. ctx->is_active = true;
  2308. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  2309. memcpy(ctx->staging.node_addr,
  2310. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  2311. ETH_ALEN);
  2312. memcpy(ctx->staging.bssid_addr,
  2313. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  2314. ETH_ALEN);
  2315. err = iwlagn_commit_rxon(priv, ctx);
  2316. if (err)
  2317. goto out;
  2318. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  2319. RXON_FILTER_PROMISC_MSK |
  2320. RXON_FILTER_CTL2HOST_MSK;
  2321. err = iwlagn_commit_rxon(priv, ctx);
  2322. if (err) {
  2323. iwlagn_disable_roc(priv);
  2324. goto out;
  2325. }
  2326. priv->hw_roc_setup = true;
  2327. }
  2328. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  2329. if (err)
  2330. iwlagn_disable_roc(priv);
  2331. out:
  2332. mutex_unlock(&priv->shrd->mutex);
  2333. IWL_DEBUG_MAC80211(priv, "leave\n");
  2334. return err;
  2335. }
  2336. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2337. {
  2338. struct iwl_priv *priv = hw->priv;
  2339. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2340. return -EOPNOTSUPP;
  2341. IWL_DEBUG_MAC80211(priv, "enter\n");
  2342. mutex_lock(&priv->shrd->mutex);
  2343. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  2344. iwlagn_disable_roc(priv);
  2345. mutex_unlock(&priv->shrd->mutex);
  2346. IWL_DEBUG_MAC80211(priv, "leave\n");
  2347. return 0;
  2348. }
  2349. static int iwlagn_mac_tx_sync(struct ieee80211_hw *hw,
  2350. struct ieee80211_vif *vif,
  2351. const u8 *bssid,
  2352. enum ieee80211_tx_sync_type type)
  2353. {
  2354. struct iwl_priv *priv = hw->priv;
  2355. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2356. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2357. int ret;
  2358. u8 sta_id;
  2359. IWL_DEBUG_MAC80211(priv, "enter\n");
  2360. mutex_lock(&priv->shrd->mutex);
  2361. if (iwl_is_associated_ctx(ctx)) {
  2362. ret = 0;
  2363. goto out;
  2364. }
  2365. if (ctx->preauth_bssid || test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
  2366. ret = -EBUSY;
  2367. goto out;
  2368. }
  2369. ret = iwl_add_station_common(priv, ctx, bssid, true, NULL, &sta_id);
  2370. if (ret)
  2371. goto out;
  2372. if (WARN_ON(sta_id != ctx->ap_sta_id)) {
  2373. ret = -EIO;
  2374. goto out_remove_sta;
  2375. }
  2376. memcpy(ctx->bssid, bssid, ETH_ALEN);
  2377. ctx->preauth_bssid = true;
  2378. ret = iwlagn_commit_rxon(priv, ctx);
  2379. if (ret == 0)
  2380. goto out;
  2381. out_remove_sta:
  2382. iwl_remove_station(priv, sta_id, bssid);
  2383. out:
  2384. mutex_unlock(&priv->shrd->mutex);
  2385. IWL_DEBUG_MAC80211(priv, "leave\n");
  2386. return ret;
  2387. }
  2388. static void iwlagn_mac_finish_tx_sync(struct ieee80211_hw *hw,
  2389. struct ieee80211_vif *vif,
  2390. const u8 *bssid,
  2391. enum ieee80211_tx_sync_type type)
  2392. {
  2393. struct iwl_priv *priv = hw->priv;
  2394. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2395. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2396. IWL_DEBUG_MAC80211(priv, "enter\n");
  2397. mutex_lock(&priv->shrd->mutex);
  2398. if (iwl_is_associated_ctx(ctx))
  2399. goto out;
  2400. iwl_remove_station(priv, ctx->ap_sta_id, bssid);
  2401. ctx->preauth_bssid = false;
  2402. /* no need to commit */
  2403. out:
  2404. mutex_unlock(&priv->shrd->mutex);
  2405. IWL_DEBUG_MAC80211(priv, "leave\n");
  2406. }
  2407. /*****************************************************************************
  2408. *
  2409. * driver setup and teardown
  2410. *
  2411. *****************************************************************************/
  2412. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  2413. {
  2414. priv->shrd->workqueue = create_singlethread_workqueue(DRV_NAME);
  2415. init_waitqueue_head(&priv->shrd->wait_command_queue);
  2416. INIT_WORK(&priv->restart, iwl_bg_restart);
  2417. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  2418. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  2419. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  2420. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  2421. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  2422. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  2423. iwlagn_disable_roc_work);
  2424. iwl_setup_scan_deferred_work(priv);
  2425. if (priv->cfg->lib->bt_setup_deferred_work)
  2426. priv->cfg->lib->bt_setup_deferred_work(priv);
  2427. init_timer(&priv->statistics_periodic);
  2428. priv->statistics_periodic.data = (unsigned long)priv;
  2429. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  2430. init_timer(&priv->ucode_trace);
  2431. priv->ucode_trace.data = (unsigned long)priv;
  2432. priv->ucode_trace.function = iwl_bg_ucode_trace;
  2433. init_timer(&priv->watchdog);
  2434. priv->watchdog.data = (unsigned long)priv;
  2435. priv->watchdog.function = iwl_bg_watchdog;
  2436. }
  2437. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  2438. {
  2439. if (priv->cfg->lib->cancel_deferred_work)
  2440. priv->cfg->lib->cancel_deferred_work(priv);
  2441. cancel_work_sync(&priv->run_time_calib_work);
  2442. cancel_work_sync(&priv->beacon_update);
  2443. iwl_cancel_scan_deferred_work(priv);
  2444. cancel_work_sync(&priv->bt_full_concurrency);
  2445. cancel_work_sync(&priv->bt_runtime_config);
  2446. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  2447. del_timer_sync(&priv->statistics_periodic);
  2448. del_timer_sync(&priv->ucode_trace);
  2449. }
  2450. static void iwl_init_hw_rates(struct iwl_priv *priv,
  2451. struct ieee80211_rate *rates)
  2452. {
  2453. int i;
  2454. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  2455. rates[i].bitrate = iwl_rates[i].ieee * 5;
  2456. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2457. rates[i].hw_value_short = i;
  2458. rates[i].flags = 0;
  2459. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  2460. /*
  2461. * If CCK != 1M then set short preamble rate flag.
  2462. */
  2463. rates[i].flags |=
  2464. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  2465. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2466. }
  2467. }
  2468. }
  2469. static int iwl_init_drv(struct iwl_priv *priv)
  2470. {
  2471. int ret;
  2472. spin_lock_init(&priv->shrd->sta_lock);
  2473. mutex_init(&priv->shrd->mutex);
  2474. priv->ieee_channels = NULL;
  2475. priv->ieee_rates = NULL;
  2476. priv->band = IEEE80211_BAND_2GHZ;
  2477. priv->iw_mode = NL80211_IFTYPE_STATION;
  2478. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2479. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  2480. priv->agg_tids_count = 0;
  2481. /* initialize force reset */
  2482. priv->force_reset[IWL_RF_RESET].reset_duration =
  2483. IWL_DELAY_NEXT_FORCE_RF_RESET;
  2484. priv->force_reset[IWL_FW_RESET].reset_duration =
  2485. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  2486. priv->rx_statistics_jiffies = jiffies;
  2487. /* Choose which receivers/antennas to use */
  2488. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  2489. iwl_init_scan_params(priv);
  2490. /* init bt coex */
  2491. if (priv->cfg->bt_params &&
  2492. priv->cfg->bt_params->advanced_bt_coexist) {
  2493. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  2494. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  2495. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  2496. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  2497. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  2498. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  2499. }
  2500. ret = iwl_init_channel_map(priv);
  2501. if (ret) {
  2502. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  2503. goto err;
  2504. }
  2505. ret = iwl_init_geos(priv);
  2506. if (ret) {
  2507. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  2508. goto err_free_channel_map;
  2509. }
  2510. iwl_init_hw_rates(priv, priv->ieee_rates);
  2511. return 0;
  2512. err_free_channel_map:
  2513. iwl_free_channel_map(priv);
  2514. err:
  2515. return ret;
  2516. }
  2517. static void iwl_uninit_drv(struct iwl_priv *priv)
  2518. {
  2519. iwl_calib_free_results(priv);
  2520. iwl_free_geos(priv);
  2521. iwl_free_channel_map(priv);
  2522. if (priv->tx_cmd_pool)
  2523. kmem_cache_destroy(priv->tx_cmd_pool);
  2524. kfree(priv->scan_cmd);
  2525. kfree(priv->beacon_cmd);
  2526. kfree(rcu_dereference_raw(priv->noa_data));
  2527. #ifdef CONFIG_IWLWIFI_DEBUGFS
  2528. kfree(priv->wowlan_sram);
  2529. #endif
  2530. }
  2531. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  2532. enum ieee80211_rssi_event rssi_event)
  2533. {
  2534. struct iwl_priv *priv = hw->priv;
  2535. IWL_DEBUG_MAC80211(priv, "enter\n");
  2536. mutex_lock(&priv->shrd->mutex);
  2537. if (priv->cfg->bt_params &&
  2538. priv->cfg->bt_params->advanced_bt_coexist) {
  2539. if (rssi_event == RSSI_EVENT_LOW)
  2540. priv->bt_enable_pspoll = true;
  2541. else if (rssi_event == RSSI_EVENT_HIGH)
  2542. priv->bt_enable_pspoll = false;
  2543. iwlagn_send_advance_bt_config(priv);
  2544. } else {
  2545. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  2546. "ignoring RSSI callback\n");
  2547. }
  2548. mutex_unlock(&priv->shrd->mutex);
  2549. IWL_DEBUG_MAC80211(priv, "leave\n");
  2550. }
  2551. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  2552. struct ieee80211_sta *sta, bool set)
  2553. {
  2554. struct iwl_priv *priv = hw->priv;
  2555. queue_work(priv->shrd->workqueue, &priv->beacon_update);
  2556. return 0;
  2557. }
  2558. struct ieee80211_ops iwlagn_hw_ops = {
  2559. .tx = iwlagn_mac_tx,
  2560. .start = iwlagn_mac_start,
  2561. .stop = iwlagn_mac_stop,
  2562. #ifdef CONFIG_PM_SLEEP
  2563. .suspend = iwlagn_mac_suspend,
  2564. .resume = iwlagn_mac_resume,
  2565. #endif
  2566. .add_interface = iwlagn_mac_add_interface,
  2567. .remove_interface = iwlagn_mac_remove_interface,
  2568. .change_interface = iwlagn_mac_change_interface,
  2569. .config = iwlagn_mac_config,
  2570. .configure_filter = iwlagn_configure_filter,
  2571. .set_key = iwlagn_mac_set_key,
  2572. .update_tkip_key = iwlagn_mac_update_tkip_key,
  2573. .set_rekey_data = iwlagn_mac_set_rekey_data,
  2574. .conf_tx = iwlagn_mac_conf_tx,
  2575. .bss_info_changed = iwlagn_bss_info_changed,
  2576. .ampdu_action = iwlagn_mac_ampdu_action,
  2577. .hw_scan = iwlagn_mac_hw_scan,
  2578. .sta_notify = iwlagn_mac_sta_notify,
  2579. .sta_add = iwlagn_mac_sta_add,
  2580. .sta_remove = iwlagn_mac_sta_remove,
  2581. .channel_switch = iwlagn_mac_channel_switch,
  2582. .flush = iwlagn_mac_flush,
  2583. .tx_last_beacon = iwlagn_mac_tx_last_beacon,
  2584. .remain_on_channel = iwlagn_mac_remain_on_channel,
  2585. .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
  2586. .rssi_callback = iwlagn_mac_rssi_callback,
  2587. CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
  2588. CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
  2589. .tx_sync = iwlagn_mac_tx_sync,
  2590. .finish_tx_sync = iwlagn_mac_finish_tx_sync,
  2591. .set_tim = iwlagn_mac_set_tim,
  2592. };
  2593. static u32 iwl_hw_detect(struct iwl_priv *priv)
  2594. {
  2595. return iwl_read32(bus(priv), CSR_HW_REV);
  2596. }
  2597. /* Size of one Rx buffer in host DRAM */
  2598. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  2599. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  2600. static int iwl_set_hw_params(struct iwl_priv *priv)
  2601. {
  2602. if (iwlagn_mod_params.amsdu_size_8K)
  2603. hw_params(priv).rx_page_order =
  2604. get_order(IWL_RX_BUF_SIZE_8K);
  2605. else
  2606. hw_params(priv).rx_page_order =
  2607. get_order(IWL_RX_BUF_SIZE_4K);
  2608. if (iwlagn_mod_params.disable_11n)
  2609. priv->cfg->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  2610. hw_params(priv).num_ampdu_queues =
  2611. priv->cfg->base_params->num_of_ampdu_queues;
  2612. hw_params(priv).shadow_reg_enable =
  2613. priv->cfg->base_params->shadow_reg_enable;
  2614. hw_params(priv).sku = priv->cfg->sku;
  2615. hw_params(priv).wd_timeout = priv->cfg->base_params->wd_timeout;
  2616. /* Device-specific setup */
  2617. return priv->cfg->lib->set_hw_params(priv);
  2618. }
  2619. /* This function both allocates and initializes hw and priv. */
  2620. static struct ieee80211_hw *iwl_alloc_all(void)
  2621. {
  2622. struct iwl_priv *priv;
  2623. /* mac80211 allocates memory for this device instance, including
  2624. * space for this driver's private structure */
  2625. struct ieee80211_hw *hw;
  2626. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
  2627. if (!hw)
  2628. goto out;
  2629. priv = hw->priv;
  2630. priv->hw = hw;
  2631. out:
  2632. return hw;
  2633. }
  2634. int iwl_probe(struct iwl_bus *bus, const struct iwl_trans_ops *trans_ops,
  2635. struct iwl_cfg *cfg)
  2636. {
  2637. int err = 0;
  2638. struct iwl_priv *priv;
  2639. struct ieee80211_hw *hw;
  2640. u16 num_mac;
  2641. u32 hw_rev;
  2642. /************************
  2643. * 1. Allocating HW data
  2644. ************************/
  2645. hw = iwl_alloc_all();
  2646. if (!hw) {
  2647. pr_err("%s: Cannot allocate network device\n", cfg->name);
  2648. err = -ENOMEM;
  2649. goto out;
  2650. }
  2651. priv = hw->priv;
  2652. priv->shrd = &priv->_shrd;
  2653. bus->shrd = priv->shrd;
  2654. priv->shrd->bus = bus;
  2655. priv->shrd->priv = priv;
  2656. priv->shrd->trans = trans_ops->alloc(priv->shrd);
  2657. if (priv->shrd->trans == NULL) {
  2658. err = -ENOMEM;
  2659. goto out_free_traffic_mem;
  2660. }
  2661. /* At this point both hw and priv are allocated. */
  2662. SET_IEEE80211_DEV(hw, bus(priv)->dev);
  2663. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  2664. priv->cfg = cfg;
  2665. /* is antenna coupling more than 35dB ? */
  2666. priv->bt_ant_couple_ok =
  2667. (iwlagn_mod_params.ant_coupling >
  2668. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  2669. true : false;
  2670. /* enable/disable bt channel inhibition */
  2671. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  2672. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  2673. (priv->bt_ch_announce) ? "On" : "Off");
  2674. if (iwl_alloc_traffic_mem(priv))
  2675. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  2676. /* these spin locks will be used in apm_ops.init and EEPROM access
  2677. * we should init now
  2678. */
  2679. spin_lock_init(&bus(priv)->reg_lock);
  2680. spin_lock_init(&priv->shrd->lock);
  2681. /*
  2682. * stop and reset the on-board processor just in case it is in a
  2683. * strange state ... like being left stranded by a primary kernel
  2684. * and this is now the kdump kernel trying to start up
  2685. */
  2686. iwl_write32(bus(priv), CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2687. /***********************
  2688. * 3. Read REV register
  2689. ***********************/
  2690. hw_rev = iwl_hw_detect(priv);
  2691. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  2692. priv->cfg->name, hw_rev);
  2693. err = iwl_trans_request_irq(trans(priv));
  2694. if (err)
  2695. goto out_free_trans;
  2696. if (iwl_trans_prepare_card_hw(trans(priv))) {
  2697. err = -EIO;
  2698. IWL_WARN(priv, "Failed, HW not ready\n");
  2699. goto out_free_trans;
  2700. }
  2701. /*****************
  2702. * 4. Read EEPROM
  2703. *****************/
  2704. /* Read the EEPROM */
  2705. err = iwl_eeprom_init(priv, hw_rev);
  2706. if (err) {
  2707. IWL_ERR(priv, "Unable to init EEPROM\n");
  2708. goto out_free_trans;
  2709. }
  2710. err = iwl_eeprom_check_version(priv);
  2711. if (err)
  2712. goto out_free_eeprom;
  2713. err = iwl_eeprom_check_sku(priv);
  2714. if (err)
  2715. goto out_free_eeprom;
  2716. /* extract MAC Address */
  2717. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  2718. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  2719. priv->hw->wiphy->addresses = priv->addresses;
  2720. priv->hw->wiphy->n_addresses = 1;
  2721. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  2722. if (num_mac > 1) {
  2723. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  2724. ETH_ALEN);
  2725. priv->addresses[1].addr[5]++;
  2726. priv->hw->wiphy->n_addresses++;
  2727. }
  2728. /************************
  2729. * 5. Setup HW constants
  2730. ************************/
  2731. if (iwl_set_hw_params(priv)) {
  2732. err = -ENOENT;
  2733. IWL_ERR(priv, "failed to set hw parameters\n");
  2734. goto out_free_eeprom;
  2735. }
  2736. /*******************
  2737. * 6. Setup priv
  2738. *******************/
  2739. err = iwl_init_drv(priv);
  2740. if (err)
  2741. goto out_free_eeprom;
  2742. /* At this point both hw and priv are initialized. */
  2743. /********************
  2744. * 7. Setup services
  2745. ********************/
  2746. iwl_setup_deferred_work(priv);
  2747. iwl_setup_rx_handlers(priv);
  2748. iwl_testmode_init(priv);
  2749. /*********************************************
  2750. * 8. Enable interrupts
  2751. *********************************************/
  2752. iwl_enable_rfkill_int(priv);
  2753. /* If platform's RF_KILL switch is NOT set to KILL */
  2754. if (iwl_read32(bus(priv),
  2755. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2756. clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  2757. else
  2758. set_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  2759. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  2760. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  2761. iwl_power_initialize(priv);
  2762. iwl_tt_initialize(priv);
  2763. init_completion(&priv->firmware_loading_complete);
  2764. err = iwl_request_firmware(priv, true);
  2765. if (err)
  2766. goto out_destroy_workqueue;
  2767. return 0;
  2768. out_destroy_workqueue:
  2769. destroy_workqueue(priv->shrd->workqueue);
  2770. priv->shrd->workqueue = NULL;
  2771. iwl_uninit_drv(priv);
  2772. out_free_eeprom:
  2773. iwl_eeprom_free(priv);
  2774. out_free_trans:
  2775. iwl_trans_free(trans(priv));
  2776. out_free_traffic_mem:
  2777. iwl_free_traffic_mem(priv);
  2778. ieee80211_free_hw(priv->hw);
  2779. out:
  2780. return err;
  2781. }
  2782. void __devexit iwl_remove(struct iwl_priv * priv)
  2783. {
  2784. wait_for_completion(&priv->firmware_loading_complete);
  2785. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  2786. iwl_dbgfs_unregister(priv);
  2787. /* ieee80211_unregister_hw call wil cause iwlagn_mac_stop to
  2788. * to be called and iwl_down since we are removing the device
  2789. * we need to set STATUS_EXIT_PENDING bit.
  2790. */
  2791. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  2792. iwl_testmode_cleanup(priv);
  2793. iwl_leds_exit(priv);
  2794. if (priv->mac80211_registered) {
  2795. ieee80211_unregister_hw(priv->hw);
  2796. priv->mac80211_registered = 0;
  2797. }
  2798. iwl_tt_exit(priv);
  2799. /*This will stop the queues, move the device to low power state */
  2800. iwl_trans_stop_device(trans(priv));
  2801. iwl_dealloc_ucode(trans(priv));
  2802. iwl_eeprom_free(priv);
  2803. /*netif_stop_queue(dev); */
  2804. flush_workqueue(priv->shrd->workqueue);
  2805. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  2806. * priv->shrd->workqueue... so we can't take down the workqueue
  2807. * until now... */
  2808. destroy_workqueue(priv->shrd->workqueue);
  2809. priv->shrd->workqueue = NULL;
  2810. iwl_free_traffic_mem(priv);
  2811. iwl_trans_free(trans(priv));
  2812. iwl_uninit_drv(priv);
  2813. dev_kfree_skb(priv->beacon_skb);
  2814. ieee80211_free_hw(priv->hw);
  2815. }
  2816. /*****************************************************************************
  2817. *
  2818. * driver and module entry point
  2819. *
  2820. *****************************************************************************/
  2821. static int __init iwl_init(void)
  2822. {
  2823. int ret;
  2824. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  2825. pr_info(DRV_COPYRIGHT "\n");
  2826. ret = iwlagn_rate_control_register();
  2827. if (ret) {
  2828. pr_err("Unable to register rate control algorithm: %d\n", ret);
  2829. return ret;
  2830. }
  2831. ret = iwl_pci_register_driver();
  2832. if (ret)
  2833. goto error_register;
  2834. return ret;
  2835. error_register:
  2836. iwlagn_rate_control_unregister();
  2837. return ret;
  2838. }
  2839. static void __exit iwl_exit(void)
  2840. {
  2841. iwl_pci_unregister_driver();
  2842. iwlagn_rate_control_unregister();
  2843. }
  2844. module_exit(iwl_exit);
  2845. module_init(iwl_init);
  2846. #ifdef CONFIG_IWLWIFI_DEBUG
  2847. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  2848. S_IRUGO | S_IWUSR);
  2849. MODULE_PARM_DESC(debug, "debug output mask");
  2850. #endif
  2851. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  2852. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  2853. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  2854. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  2855. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  2856. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  2857. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  2858. int, S_IRUGO);
  2859. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  2860. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  2861. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  2862. module_param_named(ucode_alternative,
  2863. iwlagn_mod_params.wanted_ucode_alternative,
  2864. int, S_IRUGO);
  2865. MODULE_PARM_DESC(ucode_alternative,
  2866. "specify ucode alternative to use from ucode file");
  2867. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  2868. int, S_IRUGO);
  2869. MODULE_PARM_DESC(antenna_coupling,
  2870. "specify antenna coupling in dB (defualt: 0 dB)");
  2871. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  2872. bool, S_IRUGO);
  2873. MODULE_PARM_DESC(bt_ch_inhibition,
  2874. "Enable BT channel inhibition (default: enable)");
  2875. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  2876. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  2877. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  2878. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  2879. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, bool, S_IRUGO);
  2880. MODULE_PARM_DESC(wd_disable,
  2881. "Disable stuck queue watchdog timer (default: 0 [enabled])");
  2882. /*
  2883. * set bt_coex_active to true, uCode will do kill/defer
  2884. * every time the priority line is asserted (BT is sending signals on the
  2885. * priority line in the PCIx).
  2886. * set bt_coex_active to false, uCode will ignore the BT activity and
  2887. * perform the normal operation
  2888. *
  2889. * User might experience transmit issue on some platform due to WiFi/BT
  2890. * co-exist problem. The possible behaviors are:
  2891. * Able to scan and finding all the available AP
  2892. * Not able to associate with any AP
  2893. * On those platforms, WiFi communication can be restored by set
  2894. * "bt_coex_active" module parameter to "false"
  2895. *
  2896. * default: bt_coex_active = true (BT_COEX_ENABLE)
  2897. */
  2898. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  2899. bool, S_IRUGO);
  2900. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  2901. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  2902. MODULE_PARM_DESC(led_mode, "0=system default, "
  2903. "1=On(RF On)/Off(RF Off), 2=blinking (default: 0)");
  2904. module_param_named(power_save, iwlagn_mod_params.power_save,
  2905. bool, S_IRUGO);
  2906. MODULE_PARM_DESC(power_save,
  2907. "enable WiFi power management (default: disable)");
  2908. module_param_named(power_level, iwlagn_mod_params.power_level,
  2909. int, S_IRUGO);
  2910. MODULE_PARM_DESC(power_level,
  2911. "default power save level (range from 1 - 5, default: 1)");
  2912. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  2913. bool, S_IRUGO);
  2914. MODULE_PARM_DESC(auto_agg,
  2915. "enable agg w/o check traffic load (default: enable)");
  2916. /*
  2917. * For now, keep using power level 1 instead of automatically
  2918. * adjusting ...
  2919. */
  2920. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  2921. bool, S_IRUGO);
  2922. MODULE_PARM_DESC(no_sleep_autoadjust,
  2923. "don't automatically adjust sleep level "
  2924. "according to maximum network latency (default: true)");