iwl-agn.c 96 KB

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