iwl-core.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  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. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/sched.h>
  32. #include <linux/slab.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h" /* FIXME: remove */
  36. #include "iwl-debug.h"
  37. #include "iwl-core.h"
  38. #include "iwl-io.h"
  39. #include "iwl-power.h"
  40. #include "iwl-sta.h"
  41. #include "iwl-helpers.h"
  42. MODULE_DESCRIPTION("iwl core");
  43. MODULE_VERSION(IWLWIFI_VERSION);
  44. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  45. MODULE_LICENSE("GPL");
  46. /*
  47. * set bt_coex_active to true, uCode will do kill/defer
  48. * every time the priority line is asserted (BT is sending signals on the
  49. * priority line in the PCIx).
  50. * set bt_coex_active to false, uCode will ignore the BT activity and
  51. * perform the normal operation
  52. *
  53. * User might experience transmit issue on some platform due to WiFi/BT
  54. * co-exist problem. The possible behaviors are:
  55. * Able to scan and finding all the available AP
  56. * Not able to associate with any AP
  57. * On those platforms, WiFi communication can be restored by set
  58. * "bt_coex_active" module parameter to "false"
  59. *
  60. * default: bt_coex_active = true (BT_COEX_ENABLE)
  61. */
  62. static bool bt_coex_active = true;
  63. module_param(bt_coex_active, bool, S_IRUGO);
  64. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
  65. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  66. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  67. IWL_RATE_SISO_##s##M_PLCP, \
  68. IWL_RATE_MIMO2_##s##M_PLCP,\
  69. IWL_RATE_MIMO3_##s##M_PLCP,\
  70. IWL_RATE_##r##M_IEEE, \
  71. IWL_RATE_##ip##M_INDEX, \
  72. IWL_RATE_##in##M_INDEX, \
  73. IWL_RATE_##rp##M_INDEX, \
  74. IWL_RATE_##rn##M_INDEX, \
  75. IWL_RATE_##pp##M_INDEX, \
  76. IWL_RATE_##np##M_INDEX }
  77. u32 iwl_debug_level;
  78. EXPORT_SYMBOL(iwl_debug_level);
  79. /*
  80. * Parameter order:
  81. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  82. *
  83. * If there isn't a valid next or previous rate then INV is used which
  84. * maps to IWL_RATE_INVALID
  85. *
  86. */
  87. const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
  88. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  89. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  90. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  91. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  92. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  93. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  94. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  95. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  96. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  97. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  98. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  99. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  100. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  101. /* FIXME:RS: ^^ should be INV (legacy) */
  102. };
  103. EXPORT_SYMBOL(iwl_rates);
  104. int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
  105. {
  106. int idx = 0;
  107. /* HT rate format */
  108. if (rate_n_flags & RATE_MCS_HT_MSK) {
  109. idx = (rate_n_flags & 0xff);
  110. if (idx >= IWL_RATE_MIMO3_6M_PLCP)
  111. idx = idx - IWL_RATE_MIMO3_6M_PLCP;
  112. else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
  113. idx = idx - IWL_RATE_MIMO2_6M_PLCP;
  114. idx += IWL_FIRST_OFDM_RATE;
  115. /* skip 9M not supported in ht*/
  116. if (idx >= IWL_RATE_9M_INDEX)
  117. idx += 1;
  118. if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
  119. return idx;
  120. /* legacy rate format, search for match in table */
  121. } else {
  122. for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
  123. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  124. return idx;
  125. }
  126. return -1;
  127. }
  128. EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
  129. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  130. {
  131. int i;
  132. u8 ind = ant;
  133. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  134. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  135. if (valid & BIT(ind))
  136. return ind;
  137. }
  138. return ant;
  139. }
  140. EXPORT_SYMBOL(iwl_toggle_tx_ant);
  141. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  142. EXPORT_SYMBOL(iwl_bcast_addr);
  143. /* This function both allocates and initializes hw and priv. */
  144. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  145. struct ieee80211_ops *hw_ops)
  146. {
  147. struct iwl_priv *priv;
  148. /* mac80211 allocates memory for this device instance, including
  149. * space for this driver's private structure */
  150. struct ieee80211_hw *hw =
  151. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  152. if (hw == NULL) {
  153. pr_err("%s: Can not allocate network device\n",
  154. cfg->name);
  155. goto out;
  156. }
  157. priv = hw->priv;
  158. priv->hw = hw;
  159. out:
  160. return hw;
  161. }
  162. EXPORT_SYMBOL(iwl_alloc_all);
  163. /*
  164. * QoS support
  165. */
  166. static void iwl_update_qos(struct iwl_priv *priv)
  167. {
  168. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  169. return;
  170. priv->qos_data.def_qos_parm.qos_flags = 0;
  171. if (priv->qos_data.qos_active)
  172. priv->qos_data.def_qos_parm.qos_flags |=
  173. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  174. if (priv->current_ht_config.is_ht)
  175. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  176. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  177. priv->qos_data.qos_active,
  178. priv->qos_data.def_qos_parm.qos_flags);
  179. iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
  180. sizeof(struct iwl_qosparam_cmd),
  181. &priv->qos_data.def_qos_parm, NULL);
  182. }
  183. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  184. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  185. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  186. struct ieee80211_sta_ht_cap *ht_info,
  187. enum ieee80211_band band)
  188. {
  189. u16 max_bit_rate = 0;
  190. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  191. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  192. ht_info->cap = 0;
  193. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  194. ht_info->ht_supported = true;
  195. if (priv->cfg->ht_greenfield_support)
  196. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  197. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  198. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  199. if (priv->hw_params.ht40_channel & BIT(band)) {
  200. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  201. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  202. ht_info->mcs.rx_mask[4] = 0x01;
  203. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  204. }
  205. if (priv->cfg->mod_params->amsdu_size_8K)
  206. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  207. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  208. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  209. ht_info->mcs.rx_mask[0] = 0xFF;
  210. if (rx_chains_num >= 2)
  211. ht_info->mcs.rx_mask[1] = 0xFF;
  212. if (rx_chains_num >= 3)
  213. ht_info->mcs.rx_mask[2] = 0xFF;
  214. /* Highest supported Rx data rate */
  215. max_bit_rate *= rx_chains_num;
  216. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  217. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  218. /* Tx MCS capabilities */
  219. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  220. if (tx_chains_num != rx_chains_num) {
  221. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  222. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  223. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  224. }
  225. }
  226. /**
  227. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  228. */
  229. int iwlcore_init_geos(struct iwl_priv *priv)
  230. {
  231. struct iwl_channel_info *ch;
  232. struct ieee80211_supported_band *sband;
  233. struct ieee80211_channel *channels;
  234. struct ieee80211_channel *geo_ch;
  235. struct ieee80211_rate *rates;
  236. int i = 0;
  237. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  238. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  239. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  240. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  241. return 0;
  242. }
  243. channels = kzalloc(sizeof(struct ieee80211_channel) *
  244. priv->channel_count, GFP_KERNEL);
  245. if (!channels)
  246. return -ENOMEM;
  247. rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
  248. GFP_KERNEL);
  249. if (!rates) {
  250. kfree(channels);
  251. return -ENOMEM;
  252. }
  253. /* 5.2GHz channels start after the 2.4GHz channels */
  254. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  255. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  256. /* just OFDM */
  257. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  258. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  259. if (priv->cfg->sku & IWL_SKU_N)
  260. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  261. IEEE80211_BAND_5GHZ);
  262. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  263. sband->channels = channels;
  264. /* OFDM & CCK */
  265. sband->bitrates = rates;
  266. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  267. if (priv->cfg->sku & IWL_SKU_N)
  268. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  269. IEEE80211_BAND_2GHZ);
  270. priv->ieee_channels = channels;
  271. priv->ieee_rates = rates;
  272. for (i = 0; i < priv->channel_count; i++) {
  273. ch = &priv->channel_info[i];
  274. /* FIXME: might be removed if scan is OK */
  275. if (!is_channel_valid(ch))
  276. continue;
  277. if (is_channel_a_band(ch))
  278. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  279. else
  280. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  281. geo_ch = &sband->channels[sband->n_channels++];
  282. geo_ch->center_freq =
  283. ieee80211_channel_to_frequency(ch->channel);
  284. geo_ch->max_power = ch->max_power_avg;
  285. geo_ch->max_antenna_gain = 0xff;
  286. geo_ch->hw_value = ch->channel;
  287. if (is_channel_valid(ch)) {
  288. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  289. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  290. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  291. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  292. if (ch->flags & EEPROM_CHANNEL_RADAR)
  293. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  294. geo_ch->flags |= ch->ht40_extension_channel;
  295. if (ch->max_power_avg > priv->tx_power_device_lmt)
  296. priv->tx_power_device_lmt = ch->max_power_avg;
  297. } else {
  298. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  299. }
  300. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  301. ch->channel, geo_ch->center_freq,
  302. is_channel_a_band(ch) ? "5.2" : "2.4",
  303. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  304. "restricted" : "valid",
  305. geo_ch->flags);
  306. }
  307. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  308. priv->cfg->sku & IWL_SKU_A) {
  309. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  310. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  311. priv->pci_dev->device,
  312. priv->pci_dev->subsystem_device);
  313. priv->cfg->sku &= ~IWL_SKU_A;
  314. }
  315. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  316. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  317. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  318. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  319. return 0;
  320. }
  321. EXPORT_SYMBOL(iwlcore_init_geos);
  322. /*
  323. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  324. */
  325. void iwlcore_free_geos(struct iwl_priv *priv)
  326. {
  327. kfree(priv->ieee_channels);
  328. kfree(priv->ieee_rates);
  329. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  330. }
  331. EXPORT_SYMBOL(iwlcore_free_geos);
  332. /*
  333. * iwlcore_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
  334. * function.
  335. */
  336. void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
  337. struct ieee80211_tx_info *info,
  338. __le16 fc, __le32 *tx_flags)
  339. {
  340. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  341. *tx_flags |= TX_CMD_FLG_RTS_MSK;
  342. *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  343. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  344. if (!ieee80211_is_mgmt(fc))
  345. return;
  346. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  347. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  348. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  349. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  350. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  351. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  352. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  353. break;
  354. }
  355. } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  356. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  357. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  358. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  359. }
  360. }
  361. EXPORT_SYMBOL(iwlcore_tx_cmd_protection);
  362. static bool is_single_rx_stream(struct iwl_priv *priv)
  363. {
  364. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  365. priv->current_ht_config.single_chain_sufficient;
  366. }
  367. static u8 iwl_is_channel_extension(struct iwl_priv *priv,
  368. enum ieee80211_band band,
  369. u16 channel, u8 extension_chan_offset)
  370. {
  371. const struct iwl_channel_info *ch_info;
  372. ch_info = iwl_get_channel_info(priv, band, channel);
  373. if (!is_channel_valid(ch_info))
  374. return 0;
  375. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  376. return !(ch_info->ht40_extension_channel &
  377. IEEE80211_CHAN_NO_HT40PLUS);
  378. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  379. return !(ch_info->ht40_extension_channel &
  380. IEEE80211_CHAN_NO_HT40MINUS);
  381. return 0;
  382. }
  383. u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
  384. struct ieee80211_sta_ht_cap *sta_ht_inf)
  385. {
  386. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  387. if (!ht_conf->is_ht || !ht_conf->is_40mhz)
  388. return 0;
  389. /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  390. * the bit will not set if it is pure 40MHz case
  391. */
  392. if (sta_ht_inf) {
  393. if (!sta_ht_inf->ht_supported)
  394. return 0;
  395. }
  396. #ifdef CONFIG_IWLWIFI_DEBUGFS
  397. if (priv->disable_ht40)
  398. return 0;
  399. #endif
  400. return iwl_is_channel_extension(priv, priv->band,
  401. le16_to_cpu(priv->staging_rxon.channel),
  402. ht_conf->extension_chan_offset);
  403. }
  404. EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
  405. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  406. {
  407. u16 new_val = 0;
  408. u16 beacon_factor = 0;
  409. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  410. new_val = beacon_val / beacon_factor;
  411. if (!new_val)
  412. new_val = max_beacon_val;
  413. return new_val;
  414. }
  415. void iwl_setup_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif)
  416. {
  417. u64 tsf;
  418. s32 interval_tm, rem;
  419. unsigned long flags;
  420. struct ieee80211_conf *conf = NULL;
  421. u16 beacon_int;
  422. conf = ieee80211_get_hw_conf(priv->hw);
  423. spin_lock_irqsave(&priv->lock, flags);
  424. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  425. priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
  426. beacon_int = vif->bss_conf.beacon_int;
  427. if (vif->type == NL80211_IFTYPE_ADHOC) {
  428. /* TODO: we need to get atim_window from upper stack
  429. * for now we set to 0 */
  430. priv->rxon_timing.atim_window = 0;
  431. } else {
  432. priv->rxon_timing.atim_window = 0;
  433. }
  434. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  435. priv->hw_params.max_beacon_itrvl * TIME_UNIT);
  436. priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
  437. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  438. interval_tm = beacon_int * TIME_UNIT;
  439. rem = do_div(tsf, interval_tm);
  440. priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  441. spin_unlock_irqrestore(&priv->lock, flags);
  442. IWL_DEBUG_ASSOC(priv,
  443. "beacon interval %d beacon timer %d beacon tim %d\n",
  444. le16_to_cpu(priv->rxon_timing.beacon_interval),
  445. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  446. le16_to_cpu(priv->rxon_timing.atim_window));
  447. }
  448. EXPORT_SYMBOL(iwl_setup_rxon_timing);
  449. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  450. {
  451. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  452. if (hw_decrypt)
  453. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  454. else
  455. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  456. }
  457. EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
  458. /**
  459. * iwl_check_rxon_cmd - validate RXON structure is valid
  460. *
  461. * NOTE: This is really only useful during development and can eventually
  462. * be #ifdef'd out once the driver is stable and folks aren't actively
  463. * making changes
  464. */
  465. int iwl_check_rxon_cmd(struct iwl_priv *priv)
  466. {
  467. int error = 0;
  468. int counter = 1;
  469. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  470. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  471. error |= le32_to_cpu(rxon->flags &
  472. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  473. RXON_FLG_RADAR_DETECT_MSK));
  474. if (error)
  475. IWL_WARN(priv, "check 24G fields %d | %d\n",
  476. counter++, error);
  477. } else {
  478. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  479. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  480. if (error)
  481. IWL_WARN(priv, "check 52 fields %d | %d\n",
  482. counter++, error);
  483. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  484. if (error)
  485. IWL_WARN(priv, "check 52 CCK %d | %d\n",
  486. counter++, error);
  487. }
  488. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  489. if (error)
  490. IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
  491. /* make sure basic rates 6Mbps and 1Mbps are supported */
  492. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  493. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  494. if (error)
  495. IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
  496. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  497. if (error)
  498. IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
  499. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  500. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  501. if (error)
  502. IWL_WARN(priv, "check CCK and short slot %d | %d\n",
  503. counter++, error);
  504. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  505. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  506. if (error)
  507. IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
  508. counter++, error);
  509. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  510. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  511. if (error)
  512. IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
  513. counter++, error);
  514. if (error)
  515. IWL_WARN(priv, "Tuning to channel %d\n",
  516. le16_to_cpu(rxon->channel));
  517. if (error) {
  518. IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
  519. return -1;
  520. }
  521. return 0;
  522. }
  523. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  524. /**
  525. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  526. * @priv: staging_rxon is compared to active_rxon
  527. *
  528. * If the RXON structure is changing enough to require a new tune,
  529. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  530. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  531. */
  532. int iwl_full_rxon_required(struct iwl_priv *priv)
  533. {
  534. /* These items are only settable from the full RXON command */
  535. if (!(iwl_is_associated(priv)) ||
  536. compare_ether_addr(priv->staging_rxon.bssid_addr,
  537. priv->active_rxon.bssid_addr) ||
  538. compare_ether_addr(priv->staging_rxon.node_addr,
  539. priv->active_rxon.node_addr) ||
  540. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  541. priv->active_rxon.wlap_bssid_addr) ||
  542. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  543. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  544. (priv->staging_rxon.air_propagation !=
  545. priv->active_rxon.air_propagation) ||
  546. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  547. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  548. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  549. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  550. (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
  551. priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
  552. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  553. return 1;
  554. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  555. * be updated with the RXON_ASSOC command -- however only some
  556. * flag transitions are allowed using RXON_ASSOC */
  557. /* Check if we are not switching bands */
  558. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  559. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  560. return 1;
  561. /* Check if we are switching association toggle */
  562. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  563. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  564. return 1;
  565. return 0;
  566. }
  567. EXPORT_SYMBOL(iwl_full_rxon_required);
  568. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
  569. {
  570. /*
  571. * Assign the lowest rate -- should really get this from
  572. * the beacon skb from mac80211.
  573. */
  574. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  575. return IWL_RATE_1M_PLCP;
  576. else
  577. return IWL_RATE_6M_PLCP;
  578. }
  579. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  580. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  581. {
  582. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  583. if (!ht_conf->is_ht) {
  584. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  585. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  586. RXON_FLG_HT40_PROT_MSK |
  587. RXON_FLG_HT_PROT_MSK);
  588. return;
  589. }
  590. /* FIXME: if the definition of ht_protection changed, the "translation"
  591. * will be needed for rxon->flags
  592. */
  593. rxon->flags |= cpu_to_le32(ht_conf->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
  594. /* Set up channel bandwidth:
  595. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  596. /* clear the HT channel mode before set the mode */
  597. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  598. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  599. if (iwl_is_ht40_tx_allowed(priv, NULL)) {
  600. /* pure ht40 */
  601. if (ht_conf->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  602. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  603. /* Note: control channel is opposite of extension channel */
  604. switch (ht_conf->extension_chan_offset) {
  605. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  606. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  607. break;
  608. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  609. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  610. break;
  611. }
  612. } else {
  613. /* Note: control channel is opposite of extension channel */
  614. switch (ht_conf->extension_chan_offset) {
  615. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  616. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  617. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  618. break;
  619. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  620. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  621. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  622. break;
  623. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  624. default:
  625. /* channel location only valid if in Mixed mode */
  626. IWL_ERR(priv, "invalid extension channel offset\n");
  627. break;
  628. }
  629. }
  630. } else {
  631. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  632. }
  633. if (priv->cfg->ops->hcmd->set_rxon_chain)
  634. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  635. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  636. "extension channel offset 0x%x\n",
  637. le32_to_cpu(rxon->flags), ht_conf->ht_protection,
  638. ht_conf->extension_chan_offset);
  639. }
  640. EXPORT_SYMBOL(iwl_set_rxon_ht);
  641. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  642. #define IWL_NUM_RX_CHAINS_SINGLE 2
  643. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  644. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  645. /*
  646. * Determine how many receiver/antenna chains to use.
  647. *
  648. * More provides better reception via diversity. Fewer saves power
  649. * at the expense of throughput, but only when not in powersave to
  650. * start with.
  651. *
  652. * MIMO (dual stream) requires at least 2, but works better with 3.
  653. * This does not determine *which* chains to use, just how many.
  654. */
  655. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  656. {
  657. /* # of Rx chains to use when expecting MIMO. */
  658. if (is_single_rx_stream(priv))
  659. return IWL_NUM_RX_CHAINS_SINGLE;
  660. else
  661. return IWL_NUM_RX_CHAINS_MULTIPLE;
  662. }
  663. /*
  664. * When we are in power saving mode, unless device support spatial
  665. * multiplexing power save, use the active count for rx chain count.
  666. */
  667. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  668. {
  669. /* # Rx chains when idling, depending on SMPS mode */
  670. switch (priv->current_ht_config.smps) {
  671. case IEEE80211_SMPS_STATIC:
  672. case IEEE80211_SMPS_DYNAMIC:
  673. return IWL_NUM_IDLE_CHAINS_SINGLE;
  674. case IEEE80211_SMPS_OFF:
  675. return active_cnt;
  676. default:
  677. WARN(1, "invalid SMPS mode %d",
  678. priv->current_ht_config.smps);
  679. return active_cnt;
  680. }
  681. }
  682. /* up to 4 chains */
  683. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  684. {
  685. u8 res;
  686. res = (chain_bitmap & BIT(0)) >> 0;
  687. res += (chain_bitmap & BIT(1)) >> 1;
  688. res += (chain_bitmap & BIT(2)) >> 2;
  689. res += (chain_bitmap & BIT(3)) >> 3;
  690. return res;
  691. }
  692. /**
  693. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  694. *
  695. * Selects how many and which Rx receivers/antennas/chains to use.
  696. * This should not be used for scan command ... it puts data in wrong place.
  697. */
  698. void iwl_set_rxon_chain(struct iwl_priv *priv)
  699. {
  700. bool is_single = is_single_rx_stream(priv);
  701. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  702. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  703. u32 active_chains;
  704. u16 rx_chain;
  705. /* Tell uCode which antennas are actually connected.
  706. * Before first association, we assume all antennas are connected.
  707. * Just after first association, iwl_chain_noise_calibration()
  708. * checks which antennas actually *are* connected. */
  709. if (priv->chain_noise_data.active_chains)
  710. active_chains = priv->chain_noise_data.active_chains;
  711. else
  712. active_chains = priv->hw_params.valid_rx_ant;
  713. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  714. /* How many receivers should we use? */
  715. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  716. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  717. /* correct rx chain count according hw settings
  718. * and chain noise calibration
  719. */
  720. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  721. if (valid_rx_cnt < active_rx_cnt)
  722. active_rx_cnt = valid_rx_cnt;
  723. if (valid_rx_cnt < idle_rx_cnt)
  724. idle_rx_cnt = valid_rx_cnt;
  725. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  726. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  727. priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
  728. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  729. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  730. else
  731. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  732. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  733. priv->staging_rxon.rx_chain,
  734. active_rx_cnt, idle_rx_cnt);
  735. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  736. active_rx_cnt < idle_rx_cnt);
  737. }
  738. EXPORT_SYMBOL(iwl_set_rxon_chain);
  739. /* Return valid channel */
  740. u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  741. enum ieee80211_band band)
  742. {
  743. const struct iwl_channel_info *ch_info;
  744. int i;
  745. u8 channel = 0;
  746. /* only scan single channel, good enough to reset the RF */
  747. /* pick the first valid not in-use channel */
  748. if (band == IEEE80211_BAND_5GHZ) {
  749. for (i = 14; i < priv->channel_count; i++) {
  750. if (priv->channel_info[i].channel !=
  751. le16_to_cpu(priv->staging_rxon.channel)) {
  752. channel = priv->channel_info[i].channel;
  753. ch_info = iwl_get_channel_info(priv,
  754. band, channel);
  755. if (is_channel_valid(ch_info))
  756. break;
  757. }
  758. }
  759. } else {
  760. for (i = 0; i < 14; i++) {
  761. if (priv->channel_info[i].channel !=
  762. le16_to_cpu(priv->staging_rxon.channel)) {
  763. channel =
  764. priv->channel_info[i].channel;
  765. ch_info = iwl_get_channel_info(priv,
  766. band, channel);
  767. if (is_channel_valid(ch_info))
  768. break;
  769. }
  770. }
  771. }
  772. return channel;
  773. }
  774. EXPORT_SYMBOL(iwl_get_single_channel_number);
  775. /**
  776. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  777. * @ch: requested channel as a pointer to struct ieee80211_channel
  778. * In addition to setting the staging RXON, priv->band is also set.
  779. *
  780. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  781. * in the staging RXON flag structure based on the ch->band
  782. */
  783. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
  784. {
  785. enum ieee80211_band band = ch->band;
  786. u16 channel = ch->hw_value;
  787. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  788. (priv->band == band))
  789. return 0;
  790. priv->staging_rxon.channel = cpu_to_le16(channel);
  791. if (band == IEEE80211_BAND_5GHZ)
  792. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  793. else
  794. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  795. priv->band = band;
  796. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  797. return 0;
  798. }
  799. EXPORT_SYMBOL(iwl_set_rxon_channel);
  800. void iwl_set_flags_for_band(struct iwl_priv *priv,
  801. enum ieee80211_band band,
  802. struct ieee80211_vif *vif)
  803. {
  804. if (band == IEEE80211_BAND_5GHZ) {
  805. priv->staging_rxon.flags &=
  806. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  807. | RXON_FLG_CCK_MSK);
  808. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  809. } else {
  810. /* Copied from iwl_post_associate() */
  811. if (vif && vif->bss_conf.use_short_slot)
  812. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  813. else
  814. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  815. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  816. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  817. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  818. }
  819. }
  820. EXPORT_SYMBOL(iwl_set_flags_for_band);
  821. /*
  822. * initialize rxon structure with default values from eeprom
  823. */
  824. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  825. struct ieee80211_vif *vif)
  826. {
  827. const struct iwl_channel_info *ch_info;
  828. enum nl80211_iftype type = NL80211_IFTYPE_STATION;
  829. if (vif)
  830. type = vif->type;
  831. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  832. switch (type) {
  833. case NL80211_IFTYPE_AP:
  834. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  835. break;
  836. case NL80211_IFTYPE_STATION:
  837. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  838. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  839. break;
  840. case NL80211_IFTYPE_ADHOC:
  841. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  842. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  843. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  844. RXON_FILTER_ACCEPT_GRP_MSK;
  845. break;
  846. default:
  847. IWL_ERR(priv, "Unsupported interface type %d\n", type);
  848. break;
  849. }
  850. #if 0
  851. /* TODO: Figure out when short_preamble would be set and cache from
  852. * that */
  853. if (!hw_to_local(priv->hw)->short_preamble)
  854. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  855. else
  856. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  857. #endif
  858. ch_info = iwl_get_channel_info(priv, priv->band,
  859. le16_to_cpu(priv->active_rxon.channel));
  860. if (!ch_info)
  861. ch_info = &priv->channel_info[0];
  862. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  863. priv->band = ch_info->band;
  864. iwl_set_flags_for_band(priv, priv->band, vif);
  865. priv->staging_rxon.ofdm_basic_rates =
  866. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  867. priv->staging_rxon.cck_basic_rates =
  868. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  869. /* clear both MIX and PURE40 mode flag */
  870. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  871. RXON_FLG_CHANNEL_MODE_PURE_40);
  872. if (vif)
  873. memcpy(priv->staging_rxon.node_addr, vif->addr, ETH_ALEN);
  874. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  875. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  876. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
  877. }
  878. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  879. void iwl_set_rate(struct iwl_priv *priv)
  880. {
  881. const struct ieee80211_supported_band *hw = NULL;
  882. struct ieee80211_rate *rate;
  883. int i;
  884. hw = iwl_get_hw_mode(priv, priv->band);
  885. if (!hw) {
  886. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  887. return;
  888. }
  889. priv->active_rate = 0;
  890. for (i = 0; i < hw->n_bitrates; i++) {
  891. rate = &(hw->bitrates[i]);
  892. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  893. priv->active_rate |= (1 << rate->hw_value);
  894. }
  895. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  896. priv->staging_rxon.cck_basic_rates =
  897. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  898. priv->staging_rxon.ofdm_basic_rates =
  899. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  900. }
  901. EXPORT_SYMBOL(iwl_set_rate);
  902. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  903. {
  904. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  905. return;
  906. if (priv->switch_rxon.switch_in_progress) {
  907. ieee80211_chswitch_done(priv->vif, is_success);
  908. mutex_lock(&priv->mutex);
  909. priv->switch_rxon.switch_in_progress = false;
  910. mutex_unlock(&priv->mutex);
  911. }
  912. }
  913. EXPORT_SYMBOL(iwl_chswitch_done);
  914. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  915. {
  916. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  917. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  918. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  919. if (priv->switch_rxon.switch_in_progress) {
  920. if (!le32_to_cpu(csa->status) &&
  921. (csa->channel == priv->switch_rxon.channel)) {
  922. rxon->channel = csa->channel;
  923. priv->staging_rxon.channel = csa->channel;
  924. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  925. le16_to_cpu(csa->channel));
  926. iwl_chswitch_done(priv, true);
  927. } else {
  928. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  929. le16_to_cpu(csa->channel));
  930. iwl_chswitch_done(priv, false);
  931. }
  932. }
  933. }
  934. EXPORT_SYMBOL(iwl_rx_csa);
  935. #ifdef CONFIG_IWLWIFI_DEBUG
  936. void iwl_print_rx_config_cmd(struct iwl_priv *priv)
  937. {
  938. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  939. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  940. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  941. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  942. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  943. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  944. le32_to_cpu(rxon->filter_flags));
  945. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  946. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  947. rxon->ofdm_basic_rates);
  948. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  949. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  950. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  951. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  952. }
  953. EXPORT_SYMBOL(iwl_print_rx_config_cmd);
  954. #endif
  955. /**
  956. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  957. */
  958. void iwl_irq_handle_error(struct iwl_priv *priv)
  959. {
  960. /* Set the FW error flag -- cleared on iwl_down */
  961. set_bit(STATUS_FW_ERROR, &priv->status);
  962. /* Cancel currently queued command. */
  963. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  964. IWL_ERR(priv, "Loaded firmware version: %s\n",
  965. priv->hw->wiphy->fw_version);
  966. priv->cfg->ops->lib->dump_nic_error_log(priv);
  967. if (priv->cfg->ops->lib->dump_csr)
  968. priv->cfg->ops->lib->dump_csr(priv);
  969. if (priv->cfg->ops->lib->dump_fh)
  970. priv->cfg->ops->lib->dump_fh(priv, NULL, false);
  971. priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
  972. #ifdef CONFIG_IWLWIFI_DEBUG
  973. if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
  974. iwl_print_rx_config_cmd(priv);
  975. #endif
  976. wake_up_interruptible(&priv->wait_command_queue);
  977. /* Keep the restart process from trying to send host
  978. * commands by clearing the INIT status bit */
  979. clear_bit(STATUS_READY, &priv->status);
  980. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  981. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  982. "Restarting adapter due to uCode error.\n");
  983. if (priv->cfg->mod_params->restart_fw)
  984. queue_work(priv->workqueue, &priv->restart);
  985. }
  986. }
  987. EXPORT_SYMBOL(iwl_irq_handle_error);
  988. static int iwl_apm_stop_master(struct iwl_priv *priv)
  989. {
  990. int ret = 0;
  991. /* stop device's busmaster DMA activity */
  992. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  993. ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
  994. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  995. if (ret)
  996. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  997. IWL_DEBUG_INFO(priv, "stop master\n");
  998. return ret;
  999. }
  1000. void iwl_apm_stop(struct iwl_priv *priv)
  1001. {
  1002. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  1003. /* Stop device's DMA activity */
  1004. iwl_apm_stop_master(priv);
  1005. /* Reset the entire device */
  1006. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  1007. udelay(10);
  1008. /*
  1009. * Clear "initialization complete" bit to move adapter from
  1010. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  1011. */
  1012. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  1013. }
  1014. EXPORT_SYMBOL(iwl_apm_stop);
  1015. /*
  1016. * Start up NIC's basic functionality after it has been reset
  1017. * (e.g. after platform boot, or shutdown via iwl_apm_stop())
  1018. * NOTE: This does not load uCode nor start the embedded processor
  1019. */
  1020. int iwl_apm_init(struct iwl_priv *priv)
  1021. {
  1022. int ret = 0;
  1023. u16 lctl;
  1024. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  1025. /*
  1026. * Use "set_bit" below rather than "write", to preserve any hardware
  1027. * bits already set by default after reset.
  1028. */
  1029. /* Disable L0S exit timer (platform NMI Work/Around) */
  1030. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  1031. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  1032. /*
  1033. * Disable L0s without affecting L1;
  1034. * don't wait for ICH L0s (ICH bug W/A)
  1035. */
  1036. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  1037. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  1038. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  1039. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  1040. /*
  1041. * Enable HAP INTA (interrupt from management bus) to
  1042. * wake device's PCI Express link L1a -> L0s
  1043. * NOTE: This is no-op for 3945 (non-existant bit)
  1044. */
  1045. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1046. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  1047. /*
  1048. * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
  1049. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  1050. * If so (likely), disable L0S, so device moves directly L0->L1;
  1051. * costs negligible amount of power savings.
  1052. * If not (unlikely), enable L0S, so there is at least some
  1053. * power savings, even without L1.
  1054. */
  1055. if (priv->cfg->set_l0s) {
  1056. lctl = iwl_pcie_link_ctl(priv);
  1057. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
  1058. PCI_CFG_LINK_CTRL_VAL_L1_EN) {
  1059. /* L1-ASPM enabled; disable(!) L0S */
  1060. iwl_set_bit(priv, CSR_GIO_REG,
  1061. CSR_GIO_REG_VAL_L0S_ENABLED);
  1062. IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
  1063. } else {
  1064. /* L1-ASPM disabled; enable(!) L0S */
  1065. iwl_clear_bit(priv, CSR_GIO_REG,
  1066. CSR_GIO_REG_VAL_L0S_ENABLED);
  1067. IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
  1068. }
  1069. }
  1070. /* Configure analog phase-lock-loop before activating to D0A */
  1071. if (priv->cfg->pll_cfg_val)
  1072. iwl_set_bit(priv, CSR_ANA_PLL_CFG, priv->cfg->pll_cfg_val);
  1073. /*
  1074. * Set "initialization complete" bit to move adapter from
  1075. * D0U* --> D0A* (powered-up active) state.
  1076. */
  1077. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  1078. /*
  1079. * Wait for clock stabilization; once stabilized, access to
  1080. * device-internal resources is supported, e.g. iwl_write_prph()
  1081. * and accesses to uCode SRAM.
  1082. */
  1083. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  1084. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  1085. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  1086. if (ret < 0) {
  1087. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  1088. goto out;
  1089. }
  1090. /*
  1091. * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
  1092. * BSM (Boostrap State Machine) is only in 3945 and 4965;
  1093. * later devices (i.e. 5000 and later) have non-volatile SRAM,
  1094. * and don't need BSM to restore data after power-saving sleep.
  1095. *
  1096. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  1097. * do not disable clocks. This preserves any hardware bits already
  1098. * set by default in "CLK_CTRL_REG" after reset.
  1099. */
  1100. if (priv->cfg->use_bsm)
  1101. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1102. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  1103. else
  1104. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1105. APMG_CLK_VAL_DMA_CLK_RQT);
  1106. udelay(20);
  1107. /* Disable L1-Active */
  1108. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  1109. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  1110. out:
  1111. return ret;
  1112. }
  1113. EXPORT_SYMBOL(iwl_apm_init);
  1114. void iwl_configure_filter(struct ieee80211_hw *hw,
  1115. unsigned int changed_flags,
  1116. unsigned int *total_flags,
  1117. u64 multicast)
  1118. {
  1119. struct iwl_priv *priv = hw->priv;
  1120. __le32 filter_or = 0, filter_nand = 0;
  1121. #define CHK(test, flag) do { \
  1122. if (*total_flags & (test)) \
  1123. filter_or |= (flag); \
  1124. else \
  1125. filter_nand |= (flag); \
  1126. } while (0)
  1127. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  1128. changed_flags, *total_flags);
  1129. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  1130. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
  1131. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  1132. #undef CHK
  1133. mutex_lock(&priv->mutex);
  1134. priv->staging_rxon.filter_flags &= ~filter_nand;
  1135. priv->staging_rxon.filter_flags |= filter_or;
  1136. iwlcore_commit_rxon(priv);
  1137. mutex_unlock(&priv->mutex);
  1138. /*
  1139. * Receiving all multicast frames is always enabled by the
  1140. * default flags setup in iwl_connection_init_rx_config()
  1141. * since we currently do not support programming multicast
  1142. * filters into the device.
  1143. */
  1144. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  1145. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  1146. }
  1147. EXPORT_SYMBOL(iwl_configure_filter);
  1148. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  1149. {
  1150. int ret = 0;
  1151. s8 prev_tx_power = priv->tx_power_user_lmt;
  1152. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  1153. IWL_WARN(priv,
  1154. "Requested user TXPOWER %d below lower limit %d.\n",
  1155. tx_power,
  1156. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  1157. return -EINVAL;
  1158. }
  1159. if (tx_power > priv->tx_power_device_lmt) {
  1160. IWL_WARN(priv,
  1161. "Requested user TXPOWER %d above upper limit %d.\n",
  1162. tx_power, priv->tx_power_device_lmt);
  1163. return -EINVAL;
  1164. }
  1165. if (priv->tx_power_user_lmt != tx_power)
  1166. force = true;
  1167. /* if nic is not up don't send command */
  1168. if (iwl_is_ready_rf(priv)) {
  1169. priv->tx_power_user_lmt = tx_power;
  1170. if (force && priv->cfg->ops->lib->send_tx_power)
  1171. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1172. else if (!priv->cfg->ops->lib->send_tx_power)
  1173. ret = -EOPNOTSUPP;
  1174. /*
  1175. * if fail to set tx_power, restore the orig. tx power
  1176. */
  1177. if (ret)
  1178. priv->tx_power_user_lmt = prev_tx_power;
  1179. }
  1180. /*
  1181. * Even this is an async host command, the command
  1182. * will always report success from uCode
  1183. * So once driver can placing the command into the queue
  1184. * successfully, driver can use priv->tx_power_user_lmt
  1185. * to reflect the current tx power
  1186. */
  1187. return ret;
  1188. }
  1189. EXPORT_SYMBOL(iwl_set_tx_power);
  1190. irqreturn_t iwl_isr_legacy(int irq, void *data)
  1191. {
  1192. struct iwl_priv *priv = data;
  1193. u32 inta, inta_mask;
  1194. u32 inta_fh;
  1195. unsigned long flags;
  1196. if (!priv)
  1197. return IRQ_NONE;
  1198. spin_lock_irqsave(&priv->lock, flags);
  1199. /* Disable (but don't clear!) interrupts here to avoid
  1200. * back-to-back ISRs and sporadic interrupts from our NIC.
  1201. * If we have something to service, the tasklet will re-enable ints.
  1202. * If we *don't* have something, we'll re-enable before leaving here. */
  1203. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1204. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1205. /* Discover which interrupts are active/pending */
  1206. inta = iwl_read32(priv, CSR_INT);
  1207. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1208. /* Ignore interrupt if there's nothing in NIC to service.
  1209. * This may be due to IRQ shared with another device,
  1210. * or due to sporadic interrupts thrown from our NIC. */
  1211. if (!inta && !inta_fh) {
  1212. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1213. goto none;
  1214. }
  1215. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1216. /* Hardware disappeared. It might have already raised
  1217. * an interrupt */
  1218. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1219. goto unplugged;
  1220. }
  1221. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1222. inta, inta_mask, inta_fh);
  1223. inta &= ~CSR_INT_BIT_SCD;
  1224. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1225. if (likely(inta || inta_fh))
  1226. tasklet_schedule(&priv->irq_tasklet);
  1227. unplugged:
  1228. spin_unlock_irqrestore(&priv->lock, flags);
  1229. return IRQ_HANDLED;
  1230. none:
  1231. /* re-enable interrupts here since we don't have anything to service. */
  1232. /* only Re-enable if diabled by irq */
  1233. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1234. iwl_enable_interrupts(priv);
  1235. spin_unlock_irqrestore(&priv->lock, flags);
  1236. return IRQ_NONE;
  1237. }
  1238. EXPORT_SYMBOL(iwl_isr_legacy);
  1239. void iwl_send_bt_config(struct iwl_priv *priv)
  1240. {
  1241. struct iwl_bt_cmd bt_cmd = {
  1242. .lead_time = BT_LEAD_TIME_DEF,
  1243. .max_kill = BT_MAX_KILL_DEF,
  1244. .kill_ack_mask = 0,
  1245. .kill_cts_mask = 0,
  1246. };
  1247. if (!bt_coex_active)
  1248. bt_cmd.flags = BT_COEX_DISABLE;
  1249. else
  1250. bt_cmd.flags = BT_COEX_ENABLE;
  1251. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  1252. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  1253. if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1254. sizeof(struct iwl_bt_cmd), &bt_cmd))
  1255. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1256. }
  1257. EXPORT_SYMBOL(iwl_send_bt_config);
  1258. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1259. {
  1260. struct iwl_statistics_cmd statistics_cmd = {
  1261. .configuration_flags =
  1262. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1263. };
  1264. if (flags & CMD_ASYNC)
  1265. return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1266. sizeof(struct iwl_statistics_cmd),
  1267. &statistics_cmd, NULL);
  1268. else
  1269. return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1270. sizeof(struct iwl_statistics_cmd),
  1271. &statistics_cmd);
  1272. }
  1273. EXPORT_SYMBOL(iwl_send_statistics_request);
  1274. /*
  1275. * CARD_STATE_CMD
  1276. *
  1277. * Use: Sets the device's internal card state to enable, disable, or halt
  1278. *
  1279. * When in the 'enable' state the card operates as normal.
  1280. * When in the 'disable' state, the card enters into a low power mode.
  1281. * When in the 'halt' state, the card is shut down and must be fully
  1282. * restarted to come back on.
  1283. */
  1284. int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  1285. {
  1286. struct iwl_host_cmd cmd = {
  1287. .id = REPLY_CARD_STATE_CMD,
  1288. .len = sizeof(u32),
  1289. .data = &flags,
  1290. .flags = meta_flag,
  1291. };
  1292. return iwl_send_cmd(priv, &cmd);
  1293. }
  1294. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1295. struct iwl_rx_mem_buffer *rxb)
  1296. {
  1297. #ifdef CONFIG_IWLWIFI_DEBUG
  1298. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1299. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1300. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1301. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1302. #endif
  1303. }
  1304. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1305. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1306. struct iwl_rx_mem_buffer *rxb)
  1307. {
  1308. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1309. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1310. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1311. "notification for %s:\n", len,
  1312. get_cmd_string(pkt->hdr.cmd));
  1313. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1314. }
  1315. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1316. void iwl_rx_reply_error(struct iwl_priv *priv,
  1317. struct iwl_rx_mem_buffer *rxb)
  1318. {
  1319. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1320. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1321. "seq 0x%04X ser 0x%08X\n",
  1322. le32_to_cpu(pkt->u.err_resp.error_type),
  1323. get_cmd_string(pkt->u.err_resp.cmd_id),
  1324. pkt->u.err_resp.cmd_id,
  1325. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1326. le32_to_cpu(pkt->u.err_resp.error_info));
  1327. }
  1328. EXPORT_SYMBOL(iwl_rx_reply_error);
  1329. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1330. {
  1331. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1332. }
  1333. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1334. const struct ieee80211_tx_queue_params *params)
  1335. {
  1336. struct iwl_priv *priv = hw->priv;
  1337. unsigned long flags;
  1338. int q;
  1339. IWL_DEBUG_MAC80211(priv, "enter\n");
  1340. if (!iwl_is_ready_rf(priv)) {
  1341. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1342. return -EIO;
  1343. }
  1344. if (queue >= AC_NUM) {
  1345. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1346. return 0;
  1347. }
  1348. q = AC_NUM - 1 - queue;
  1349. spin_lock_irqsave(&priv->lock, flags);
  1350. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  1351. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  1352. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1353. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  1354. cpu_to_le16((params->txop * 32));
  1355. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1356. spin_unlock_irqrestore(&priv->lock, flags);
  1357. IWL_DEBUG_MAC80211(priv, "leave\n");
  1358. return 0;
  1359. }
  1360. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1361. int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1362. {
  1363. struct iwl_priv *priv = hw->priv;
  1364. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1365. }
  1366. EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
  1367. static void iwl_ht_conf(struct iwl_priv *priv,
  1368. struct ieee80211_vif *vif)
  1369. {
  1370. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1371. struct ieee80211_sta *sta;
  1372. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1373. IWL_DEBUG_MAC80211(priv, "enter:\n");
  1374. if (!ht_conf->is_ht)
  1375. return;
  1376. ht_conf->ht_protection =
  1377. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  1378. ht_conf->non_GF_STA_present =
  1379. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1380. ht_conf->single_chain_sufficient = false;
  1381. switch (vif->type) {
  1382. case NL80211_IFTYPE_STATION:
  1383. rcu_read_lock();
  1384. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  1385. if (sta) {
  1386. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1387. int maxstreams;
  1388. maxstreams = (ht_cap->mcs.tx_params &
  1389. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1390. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1391. maxstreams += 1;
  1392. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  1393. (ht_cap->mcs.rx_mask[2] == 0))
  1394. ht_conf->single_chain_sufficient = true;
  1395. if (maxstreams <= 1)
  1396. ht_conf->single_chain_sufficient = true;
  1397. } else {
  1398. /*
  1399. * If at all, this can only happen through a race
  1400. * when the AP disconnects us while we're still
  1401. * setting up the connection, in that case mac80211
  1402. * will soon tell us about that.
  1403. */
  1404. ht_conf->single_chain_sufficient = true;
  1405. }
  1406. rcu_read_unlock();
  1407. break;
  1408. case NL80211_IFTYPE_ADHOC:
  1409. ht_conf->single_chain_sufficient = true;
  1410. break;
  1411. default:
  1412. break;
  1413. }
  1414. IWL_DEBUG_MAC80211(priv, "leave\n");
  1415. }
  1416. static inline void iwl_set_no_assoc(struct iwl_priv *priv)
  1417. {
  1418. iwl_led_disassociate(priv);
  1419. /*
  1420. * inform the ucode that there is no longer an
  1421. * association and that no more packets should be
  1422. * sent
  1423. */
  1424. priv->staging_rxon.filter_flags &=
  1425. ~RXON_FILTER_ASSOC_MSK;
  1426. priv->staging_rxon.assoc_id = 0;
  1427. iwlcore_commit_rxon(priv);
  1428. }
  1429. static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  1430. {
  1431. struct iwl_priv *priv = hw->priv;
  1432. unsigned long flags;
  1433. __le64 timestamp;
  1434. IWL_DEBUG_MAC80211(priv, "enter\n");
  1435. if (!iwl_is_ready_rf(priv)) {
  1436. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1437. return -EIO;
  1438. }
  1439. spin_lock_irqsave(&priv->lock, flags);
  1440. if (priv->ibss_beacon)
  1441. dev_kfree_skb(priv->ibss_beacon);
  1442. priv->ibss_beacon = skb;
  1443. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  1444. priv->timestamp = le64_to_cpu(timestamp);
  1445. IWL_DEBUG_MAC80211(priv, "leave\n");
  1446. spin_unlock_irqrestore(&priv->lock, flags);
  1447. priv->cfg->ops->lib->post_associate(priv, priv->vif);
  1448. return 0;
  1449. }
  1450. void iwl_bss_info_changed(struct ieee80211_hw *hw,
  1451. struct ieee80211_vif *vif,
  1452. struct ieee80211_bss_conf *bss_conf,
  1453. u32 changes)
  1454. {
  1455. struct iwl_priv *priv = hw->priv;
  1456. int ret;
  1457. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  1458. if (!iwl_is_alive(priv))
  1459. return;
  1460. mutex_lock(&priv->mutex);
  1461. if (changes & BSS_CHANGED_QOS) {
  1462. unsigned long flags;
  1463. spin_lock_irqsave(&priv->lock, flags);
  1464. priv->qos_data.qos_active = bss_conf->qos;
  1465. iwl_update_qos(priv);
  1466. spin_unlock_irqrestore(&priv->lock, flags);
  1467. }
  1468. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) {
  1469. dev_kfree_skb(priv->ibss_beacon);
  1470. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  1471. }
  1472. if (changes & BSS_CHANGED_BEACON_INT) {
  1473. /* TODO: in AP mode, do something to make this take effect */
  1474. }
  1475. if (changes & BSS_CHANGED_BSSID) {
  1476. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  1477. /*
  1478. * If there is currently a HW scan going on in the
  1479. * background then we need to cancel it else the RXON
  1480. * below/in post_associate will fail.
  1481. */
  1482. if (iwl_scan_cancel_timeout(priv, 100)) {
  1483. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  1484. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  1485. mutex_unlock(&priv->mutex);
  1486. return;
  1487. }
  1488. /* mac80211 only sets assoc when in STATION mode */
  1489. if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
  1490. memcpy(priv->staging_rxon.bssid_addr,
  1491. bss_conf->bssid, ETH_ALEN);
  1492. /* currently needed in a few places */
  1493. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1494. } else {
  1495. priv->staging_rxon.filter_flags &=
  1496. ~RXON_FILTER_ASSOC_MSK;
  1497. }
  1498. }
  1499. /*
  1500. * This needs to be after setting the BSSID in case
  1501. * mac80211 decides to do both changes at once because
  1502. * it will invoke post_associate.
  1503. */
  1504. if (vif->type == NL80211_IFTYPE_ADHOC &&
  1505. changes & BSS_CHANGED_BEACON) {
  1506. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  1507. if (beacon)
  1508. iwl_mac_beacon_update(hw, beacon);
  1509. }
  1510. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  1511. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  1512. bss_conf->use_short_preamble);
  1513. if (bss_conf->use_short_preamble)
  1514. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1515. else
  1516. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1517. }
  1518. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  1519. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
  1520. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  1521. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  1522. else
  1523. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  1524. if (bss_conf->use_cts_prot)
  1525. priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
  1526. else
  1527. priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
  1528. }
  1529. if (changes & BSS_CHANGED_BASIC_RATES) {
  1530. /* XXX use this information
  1531. *
  1532. * To do that, remove code from iwl_set_rate() and put something
  1533. * like this here:
  1534. *
  1535. if (A-band)
  1536. priv->staging_rxon.ofdm_basic_rates =
  1537. bss_conf->basic_rates;
  1538. else
  1539. priv->staging_rxon.ofdm_basic_rates =
  1540. bss_conf->basic_rates >> 4;
  1541. priv->staging_rxon.cck_basic_rates =
  1542. bss_conf->basic_rates & 0xF;
  1543. */
  1544. }
  1545. if (changes & BSS_CHANGED_HT) {
  1546. iwl_ht_conf(priv, vif);
  1547. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1548. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1549. }
  1550. if (changes & BSS_CHANGED_ASSOC) {
  1551. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  1552. if (bss_conf->assoc) {
  1553. priv->timestamp = bss_conf->timestamp;
  1554. iwl_led_associate(priv);
  1555. if (!iwl_is_rfkill(priv))
  1556. priv->cfg->ops->lib->post_associate(priv, vif);
  1557. } else
  1558. iwl_set_no_assoc(priv);
  1559. }
  1560. if (changes && iwl_is_associated(priv) && bss_conf->aid) {
  1561. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  1562. changes);
  1563. ret = iwl_send_rxon_assoc(priv);
  1564. if (!ret) {
  1565. /* Sync active_rxon with latest change. */
  1566. memcpy((void *)&priv->active_rxon,
  1567. &priv->staging_rxon,
  1568. sizeof(struct iwl_rxon_cmd));
  1569. }
  1570. }
  1571. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1572. if (vif->bss_conf.enable_beacon) {
  1573. memcpy(priv->staging_rxon.bssid_addr,
  1574. bss_conf->bssid, ETH_ALEN);
  1575. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1576. iwlcore_config_ap(priv, vif);
  1577. } else
  1578. iwl_set_no_assoc(priv);
  1579. }
  1580. if (changes & BSS_CHANGED_IBSS) {
  1581. ret = priv->cfg->ops->lib->manage_ibss_station(priv, vif,
  1582. bss_conf->ibss_joined);
  1583. if (ret)
  1584. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  1585. bss_conf->ibss_joined ? "add" : "remove",
  1586. bss_conf->bssid);
  1587. }
  1588. mutex_unlock(&priv->mutex);
  1589. IWL_DEBUG_MAC80211(priv, "leave\n");
  1590. }
  1591. EXPORT_SYMBOL(iwl_bss_info_changed);
  1592. static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
  1593. {
  1594. iwl_connection_init_rx_config(priv, vif);
  1595. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1596. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1597. return iwlcore_commit_rxon(priv);
  1598. }
  1599. int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1600. {
  1601. struct iwl_priv *priv = hw->priv;
  1602. int err = 0;
  1603. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1604. vif->type, vif->addr);
  1605. mutex_lock(&priv->mutex);
  1606. if (WARN_ON(!iwl_is_ready_rf(priv))) {
  1607. err = -EINVAL;
  1608. goto out;
  1609. }
  1610. if (priv->vif) {
  1611. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  1612. err = -EOPNOTSUPP;
  1613. goto out;
  1614. }
  1615. priv->vif = vif;
  1616. priv->iw_mode = vif->type;
  1617. err = iwl_set_mode(priv, vif);
  1618. if (err)
  1619. goto out_err;
  1620. goto out;
  1621. out_err:
  1622. priv->vif = NULL;
  1623. priv->iw_mode = NL80211_IFTYPE_STATION;
  1624. out:
  1625. mutex_unlock(&priv->mutex);
  1626. IWL_DEBUG_MAC80211(priv, "leave\n");
  1627. return err;
  1628. }
  1629. EXPORT_SYMBOL(iwl_mac_add_interface);
  1630. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  1631. struct ieee80211_vif *vif)
  1632. {
  1633. struct iwl_priv *priv = hw->priv;
  1634. bool scan_completed = false;
  1635. IWL_DEBUG_MAC80211(priv, "enter\n");
  1636. mutex_lock(&priv->mutex);
  1637. if (iwl_is_ready_rf(priv)) {
  1638. iwl_scan_cancel_timeout(priv, 100);
  1639. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1640. iwlcore_commit_rxon(priv);
  1641. }
  1642. if (priv->vif == vif) {
  1643. priv->vif = NULL;
  1644. if (priv->scan_vif == vif) {
  1645. scan_completed = true;
  1646. priv->scan_vif = NULL;
  1647. priv->scan_request = NULL;
  1648. }
  1649. memset(priv->bssid, 0, ETH_ALEN);
  1650. }
  1651. mutex_unlock(&priv->mutex);
  1652. if (scan_completed)
  1653. ieee80211_scan_completed(priv->hw, true);
  1654. IWL_DEBUG_MAC80211(priv, "leave\n");
  1655. }
  1656. EXPORT_SYMBOL(iwl_mac_remove_interface);
  1657. /**
  1658. * iwl_mac_config - mac80211 config callback
  1659. */
  1660. int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
  1661. {
  1662. struct iwl_priv *priv = hw->priv;
  1663. const struct iwl_channel_info *ch_info;
  1664. struct ieee80211_conf *conf = &hw->conf;
  1665. struct ieee80211_channel *channel = conf->channel;
  1666. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1667. unsigned long flags = 0;
  1668. int ret = 0;
  1669. u16 ch;
  1670. int scan_active = 0;
  1671. mutex_lock(&priv->mutex);
  1672. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  1673. channel->hw_value, changed);
  1674. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  1675. test_bit(STATUS_SCANNING, &priv->status))) {
  1676. scan_active = 1;
  1677. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  1678. }
  1679. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  1680. IEEE80211_CONF_CHANGE_CHANNEL)) {
  1681. /* mac80211 uses static for non-HT which is what we want */
  1682. priv->current_ht_config.smps = conf->smps_mode;
  1683. /*
  1684. * Recalculate chain counts.
  1685. *
  1686. * If monitor mode is enabled then mac80211 will
  1687. * set up the SM PS mode to OFF if an HT channel is
  1688. * configured.
  1689. */
  1690. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1691. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1692. }
  1693. /* during scanning mac80211 will delay channel setting until
  1694. * scan finish with changed = 0
  1695. */
  1696. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1697. if (scan_active)
  1698. goto set_ch_out;
  1699. ch = channel->hw_value;
  1700. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  1701. if (!is_channel_valid(ch_info)) {
  1702. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  1703. ret = -EINVAL;
  1704. goto set_ch_out;
  1705. }
  1706. spin_lock_irqsave(&priv->lock, flags);
  1707. /* Configure HT40 channels */
  1708. ht_conf->is_ht = conf_is_ht(conf);
  1709. if (ht_conf->is_ht) {
  1710. if (conf_is_ht40_minus(conf)) {
  1711. ht_conf->extension_chan_offset =
  1712. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1713. ht_conf->is_40mhz = true;
  1714. } else if (conf_is_ht40_plus(conf)) {
  1715. ht_conf->extension_chan_offset =
  1716. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1717. ht_conf->is_40mhz = true;
  1718. } else {
  1719. ht_conf->extension_chan_offset =
  1720. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1721. ht_conf->is_40mhz = false;
  1722. }
  1723. } else
  1724. ht_conf->is_40mhz = false;
  1725. /* Default to no protection. Protection mode will later be set
  1726. * from BSS config in iwl_ht_conf */
  1727. ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  1728. if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
  1729. priv->staging_rxon.flags = 0;
  1730. iwl_set_rxon_channel(priv, channel);
  1731. iwl_set_rxon_ht(priv, ht_conf);
  1732. iwl_set_flags_for_band(priv, channel->band, priv->vif);
  1733. spin_unlock_irqrestore(&priv->lock, flags);
  1734. if (priv->cfg->ops->lib->update_bcast_station)
  1735. ret = priv->cfg->ops->lib->update_bcast_station(priv);
  1736. set_ch_out:
  1737. /* The list of supported rates and rate mask can be different
  1738. * for each band; since the band may have changed, reset
  1739. * the rate mask to what mac80211 lists */
  1740. iwl_set_rate(priv);
  1741. }
  1742. if (changed & (IEEE80211_CONF_CHANGE_PS |
  1743. IEEE80211_CONF_CHANGE_IDLE)) {
  1744. ret = iwl_power_update_mode(priv, false);
  1745. if (ret)
  1746. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  1747. }
  1748. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1749. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  1750. priv->tx_power_user_lmt, conf->power_level);
  1751. iwl_set_tx_power(priv, conf->power_level, false);
  1752. }
  1753. if (!iwl_is_ready(priv)) {
  1754. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1755. goto out;
  1756. }
  1757. if (scan_active)
  1758. goto out;
  1759. if (memcmp(&priv->active_rxon,
  1760. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  1761. iwlcore_commit_rxon(priv);
  1762. else
  1763. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
  1764. out:
  1765. IWL_DEBUG_MAC80211(priv, "leave\n");
  1766. mutex_unlock(&priv->mutex);
  1767. return ret;
  1768. }
  1769. EXPORT_SYMBOL(iwl_mac_config);
  1770. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  1771. {
  1772. struct iwl_priv *priv = hw->priv;
  1773. unsigned long flags;
  1774. mutex_lock(&priv->mutex);
  1775. IWL_DEBUG_MAC80211(priv, "enter\n");
  1776. spin_lock_irqsave(&priv->lock, flags);
  1777. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
  1778. spin_unlock_irqrestore(&priv->lock, flags);
  1779. spin_lock_irqsave(&priv->lock, flags);
  1780. /* new association get rid of ibss beacon skb */
  1781. if (priv->ibss_beacon)
  1782. dev_kfree_skb(priv->ibss_beacon);
  1783. priv->ibss_beacon = NULL;
  1784. priv->timestamp = 0;
  1785. spin_unlock_irqrestore(&priv->lock, flags);
  1786. if (!iwl_is_ready_rf(priv)) {
  1787. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1788. mutex_unlock(&priv->mutex);
  1789. return;
  1790. }
  1791. /* we are restarting association process
  1792. * clear RXON_FILTER_ASSOC_MSK bit
  1793. */
  1794. iwl_scan_cancel_timeout(priv, 100);
  1795. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1796. iwlcore_commit_rxon(priv);
  1797. iwl_set_rate(priv);
  1798. mutex_unlock(&priv->mutex);
  1799. IWL_DEBUG_MAC80211(priv, "leave\n");
  1800. }
  1801. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  1802. int iwl_alloc_txq_mem(struct iwl_priv *priv)
  1803. {
  1804. if (!priv->txq)
  1805. priv->txq = kzalloc(
  1806. sizeof(struct iwl_tx_queue) * priv->cfg->num_of_queues,
  1807. GFP_KERNEL);
  1808. if (!priv->txq) {
  1809. IWL_ERR(priv, "Not enough memory for txq\n");
  1810. return -ENOMEM;
  1811. }
  1812. return 0;
  1813. }
  1814. EXPORT_SYMBOL(iwl_alloc_txq_mem);
  1815. void iwl_free_txq_mem(struct iwl_priv *priv)
  1816. {
  1817. kfree(priv->txq);
  1818. priv->txq = NULL;
  1819. }
  1820. EXPORT_SYMBOL(iwl_free_txq_mem);
  1821. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1822. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  1823. void iwl_reset_traffic_log(struct iwl_priv *priv)
  1824. {
  1825. priv->tx_traffic_idx = 0;
  1826. priv->rx_traffic_idx = 0;
  1827. if (priv->tx_traffic)
  1828. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1829. if (priv->rx_traffic)
  1830. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1831. }
  1832. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  1833. {
  1834. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  1835. if (iwl_debug_level & IWL_DL_TX) {
  1836. if (!priv->tx_traffic) {
  1837. priv->tx_traffic =
  1838. kzalloc(traffic_size, GFP_KERNEL);
  1839. if (!priv->tx_traffic)
  1840. return -ENOMEM;
  1841. }
  1842. }
  1843. if (iwl_debug_level & IWL_DL_RX) {
  1844. if (!priv->rx_traffic) {
  1845. priv->rx_traffic =
  1846. kzalloc(traffic_size, GFP_KERNEL);
  1847. if (!priv->rx_traffic)
  1848. return -ENOMEM;
  1849. }
  1850. }
  1851. iwl_reset_traffic_log(priv);
  1852. return 0;
  1853. }
  1854. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  1855. void iwl_free_traffic_mem(struct iwl_priv *priv)
  1856. {
  1857. kfree(priv->tx_traffic);
  1858. priv->tx_traffic = NULL;
  1859. kfree(priv->rx_traffic);
  1860. priv->rx_traffic = NULL;
  1861. }
  1862. EXPORT_SYMBOL(iwl_free_traffic_mem);
  1863. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  1864. u16 length, struct ieee80211_hdr *header)
  1865. {
  1866. __le16 fc;
  1867. u16 len;
  1868. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  1869. return;
  1870. if (!priv->tx_traffic)
  1871. return;
  1872. fc = header->frame_control;
  1873. if (ieee80211_is_data(fc)) {
  1874. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1875. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1876. memcpy((priv->tx_traffic +
  1877. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1878. header, len);
  1879. priv->tx_traffic_idx =
  1880. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1881. }
  1882. }
  1883. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  1884. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  1885. u16 length, struct ieee80211_hdr *header)
  1886. {
  1887. __le16 fc;
  1888. u16 len;
  1889. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  1890. return;
  1891. if (!priv->rx_traffic)
  1892. return;
  1893. fc = header->frame_control;
  1894. if (ieee80211_is_data(fc)) {
  1895. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1896. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1897. memcpy((priv->rx_traffic +
  1898. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1899. header, len);
  1900. priv->rx_traffic_idx =
  1901. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1902. }
  1903. }
  1904. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  1905. const char *get_mgmt_string(int cmd)
  1906. {
  1907. switch (cmd) {
  1908. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1909. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1910. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1911. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1912. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1913. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1914. IWL_CMD(MANAGEMENT_BEACON);
  1915. IWL_CMD(MANAGEMENT_ATIM);
  1916. IWL_CMD(MANAGEMENT_DISASSOC);
  1917. IWL_CMD(MANAGEMENT_AUTH);
  1918. IWL_CMD(MANAGEMENT_DEAUTH);
  1919. IWL_CMD(MANAGEMENT_ACTION);
  1920. default:
  1921. return "UNKNOWN";
  1922. }
  1923. }
  1924. const char *get_ctrl_string(int cmd)
  1925. {
  1926. switch (cmd) {
  1927. IWL_CMD(CONTROL_BACK_REQ);
  1928. IWL_CMD(CONTROL_BACK);
  1929. IWL_CMD(CONTROL_PSPOLL);
  1930. IWL_CMD(CONTROL_RTS);
  1931. IWL_CMD(CONTROL_CTS);
  1932. IWL_CMD(CONTROL_ACK);
  1933. IWL_CMD(CONTROL_CFEND);
  1934. IWL_CMD(CONTROL_CFENDACK);
  1935. default:
  1936. return "UNKNOWN";
  1937. }
  1938. }
  1939. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  1940. {
  1941. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1942. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1943. priv->led_tpt = 0;
  1944. }
  1945. /*
  1946. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  1947. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  1948. * Use debugFs to display the rx/rx_statistics
  1949. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  1950. * information will be recorded, but DATA pkt still will be recorded
  1951. * for the reason of iwl_led.c need to control the led blinking based on
  1952. * number of tx and rx data.
  1953. *
  1954. */
  1955. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1956. {
  1957. struct traffic_stats *stats;
  1958. if (is_tx)
  1959. stats = &priv->tx_stats;
  1960. else
  1961. stats = &priv->rx_stats;
  1962. if (ieee80211_is_mgmt(fc)) {
  1963. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1964. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1965. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1966. break;
  1967. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1968. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1969. break;
  1970. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1971. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1972. break;
  1973. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1974. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1975. break;
  1976. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1977. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1978. break;
  1979. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1980. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1981. break;
  1982. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1983. stats->mgmt[MANAGEMENT_BEACON]++;
  1984. break;
  1985. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1986. stats->mgmt[MANAGEMENT_ATIM]++;
  1987. break;
  1988. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1989. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1990. break;
  1991. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1992. stats->mgmt[MANAGEMENT_AUTH]++;
  1993. break;
  1994. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1995. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1996. break;
  1997. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1998. stats->mgmt[MANAGEMENT_ACTION]++;
  1999. break;
  2000. }
  2001. } else if (ieee80211_is_ctl(fc)) {
  2002. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2003. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  2004. stats->ctrl[CONTROL_BACK_REQ]++;
  2005. break;
  2006. case cpu_to_le16(IEEE80211_STYPE_BACK):
  2007. stats->ctrl[CONTROL_BACK]++;
  2008. break;
  2009. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  2010. stats->ctrl[CONTROL_PSPOLL]++;
  2011. break;
  2012. case cpu_to_le16(IEEE80211_STYPE_RTS):
  2013. stats->ctrl[CONTROL_RTS]++;
  2014. break;
  2015. case cpu_to_le16(IEEE80211_STYPE_CTS):
  2016. stats->ctrl[CONTROL_CTS]++;
  2017. break;
  2018. case cpu_to_le16(IEEE80211_STYPE_ACK):
  2019. stats->ctrl[CONTROL_ACK]++;
  2020. break;
  2021. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  2022. stats->ctrl[CONTROL_CFEND]++;
  2023. break;
  2024. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  2025. stats->ctrl[CONTROL_CFENDACK]++;
  2026. break;
  2027. }
  2028. } else {
  2029. /* data */
  2030. stats->data_cnt++;
  2031. stats->data_bytes += len;
  2032. }
  2033. iwl_leds_background(priv);
  2034. }
  2035. EXPORT_SYMBOL(iwl_update_stats);
  2036. #endif
  2037. static const char *get_csr_string(int cmd)
  2038. {
  2039. switch (cmd) {
  2040. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  2041. IWL_CMD(CSR_INT_COALESCING);
  2042. IWL_CMD(CSR_INT);
  2043. IWL_CMD(CSR_INT_MASK);
  2044. IWL_CMD(CSR_FH_INT_STATUS);
  2045. IWL_CMD(CSR_GPIO_IN);
  2046. IWL_CMD(CSR_RESET);
  2047. IWL_CMD(CSR_GP_CNTRL);
  2048. IWL_CMD(CSR_HW_REV);
  2049. IWL_CMD(CSR_EEPROM_REG);
  2050. IWL_CMD(CSR_EEPROM_GP);
  2051. IWL_CMD(CSR_OTP_GP_REG);
  2052. IWL_CMD(CSR_GIO_REG);
  2053. IWL_CMD(CSR_GP_UCODE_REG);
  2054. IWL_CMD(CSR_GP_DRIVER_REG);
  2055. IWL_CMD(CSR_UCODE_DRV_GP1);
  2056. IWL_CMD(CSR_UCODE_DRV_GP2);
  2057. IWL_CMD(CSR_LED_REG);
  2058. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  2059. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  2060. IWL_CMD(CSR_ANA_PLL_CFG);
  2061. IWL_CMD(CSR_HW_REV_WA_REG);
  2062. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  2063. default:
  2064. return "UNKNOWN";
  2065. }
  2066. }
  2067. void iwl_dump_csr(struct iwl_priv *priv)
  2068. {
  2069. int i;
  2070. u32 csr_tbl[] = {
  2071. CSR_HW_IF_CONFIG_REG,
  2072. CSR_INT_COALESCING,
  2073. CSR_INT,
  2074. CSR_INT_MASK,
  2075. CSR_FH_INT_STATUS,
  2076. CSR_GPIO_IN,
  2077. CSR_RESET,
  2078. CSR_GP_CNTRL,
  2079. CSR_HW_REV,
  2080. CSR_EEPROM_REG,
  2081. CSR_EEPROM_GP,
  2082. CSR_OTP_GP_REG,
  2083. CSR_GIO_REG,
  2084. CSR_GP_UCODE_REG,
  2085. CSR_GP_DRIVER_REG,
  2086. CSR_UCODE_DRV_GP1,
  2087. CSR_UCODE_DRV_GP2,
  2088. CSR_LED_REG,
  2089. CSR_DRAM_INT_TBL_REG,
  2090. CSR_GIO_CHICKEN_BITS,
  2091. CSR_ANA_PLL_CFG,
  2092. CSR_HW_REV_WA_REG,
  2093. CSR_DBG_HPET_MEM_REG
  2094. };
  2095. IWL_ERR(priv, "CSR values:\n");
  2096. IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
  2097. "CSR_INT_PERIODIC_REG)\n");
  2098. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  2099. IWL_ERR(priv, " %25s: 0X%08x\n",
  2100. get_csr_string(csr_tbl[i]),
  2101. iwl_read32(priv, csr_tbl[i]));
  2102. }
  2103. }
  2104. EXPORT_SYMBOL(iwl_dump_csr);
  2105. static const char *get_fh_string(int cmd)
  2106. {
  2107. switch (cmd) {
  2108. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  2109. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  2110. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  2111. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  2112. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  2113. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  2114. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  2115. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  2116. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  2117. default:
  2118. return "UNKNOWN";
  2119. }
  2120. }
  2121. int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
  2122. {
  2123. int i;
  2124. #ifdef CONFIG_IWLWIFI_DEBUG
  2125. int pos = 0;
  2126. size_t bufsz = 0;
  2127. #endif
  2128. u32 fh_tbl[] = {
  2129. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  2130. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  2131. FH_RSCSR_CHNL0_WPTR,
  2132. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  2133. FH_MEM_RSSR_SHARED_CTRL_REG,
  2134. FH_MEM_RSSR_RX_STATUS_REG,
  2135. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  2136. FH_TSSR_TX_STATUS_REG,
  2137. FH_TSSR_TX_ERROR_REG
  2138. };
  2139. #ifdef CONFIG_IWLWIFI_DEBUG
  2140. if (display) {
  2141. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  2142. *buf = kmalloc(bufsz, GFP_KERNEL);
  2143. if (!*buf)
  2144. return -ENOMEM;
  2145. pos += scnprintf(*buf + pos, bufsz - pos,
  2146. "FH register values:\n");
  2147. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2148. pos += scnprintf(*buf + pos, bufsz - pos,
  2149. " %34s: 0X%08x\n",
  2150. get_fh_string(fh_tbl[i]),
  2151. iwl_read_direct32(priv, fh_tbl[i]));
  2152. }
  2153. return pos;
  2154. }
  2155. #endif
  2156. IWL_ERR(priv, "FH register values:\n");
  2157. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2158. IWL_ERR(priv, " %34s: 0X%08x\n",
  2159. get_fh_string(fh_tbl[i]),
  2160. iwl_read_direct32(priv, fh_tbl[i]));
  2161. }
  2162. return 0;
  2163. }
  2164. EXPORT_SYMBOL(iwl_dump_fh);
  2165. static void iwl_force_rf_reset(struct iwl_priv *priv)
  2166. {
  2167. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2168. return;
  2169. if (!iwl_is_associated(priv)) {
  2170. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  2171. return;
  2172. }
  2173. /*
  2174. * There is no easy and better way to force reset the radio,
  2175. * the only known method is switching channel which will force to
  2176. * reset and tune the radio.
  2177. * Use internal short scan (single channel) operation to should
  2178. * achieve this objective.
  2179. * Driver should reset the radio when number of consecutive missed
  2180. * beacon, or any other uCode error condition detected.
  2181. */
  2182. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  2183. iwl_internal_short_hw_scan(priv);
  2184. }
  2185. int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
  2186. {
  2187. struct iwl_force_reset *force_reset;
  2188. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2189. return -EINVAL;
  2190. if (mode >= IWL_MAX_FORCE_RESET) {
  2191. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  2192. return -EINVAL;
  2193. }
  2194. force_reset = &priv->force_reset[mode];
  2195. force_reset->reset_request_count++;
  2196. if (!external) {
  2197. if (force_reset->last_force_reset_jiffies &&
  2198. time_after(force_reset->last_force_reset_jiffies +
  2199. force_reset->reset_duration, jiffies)) {
  2200. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  2201. force_reset->reset_reject_count++;
  2202. return -EAGAIN;
  2203. }
  2204. }
  2205. force_reset->reset_success_count++;
  2206. force_reset->last_force_reset_jiffies = jiffies;
  2207. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  2208. switch (mode) {
  2209. case IWL_RF_RESET:
  2210. iwl_force_rf_reset(priv);
  2211. break;
  2212. case IWL_FW_RESET:
  2213. /*
  2214. * if the request is from external(ex: debugfs),
  2215. * then always perform the request in regardless the module
  2216. * parameter setting
  2217. * if the request is from internal (uCode error or driver
  2218. * detect failure), then fw_restart module parameter
  2219. * need to be check before performing firmware reload
  2220. */
  2221. if (!external && !priv->cfg->mod_params->restart_fw) {
  2222. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  2223. "module parameter setting\n");
  2224. break;
  2225. }
  2226. IWL_ERR(priv, "On demand firmware reload\n");
  2227. /* Set the FW error flag -- cleared on iwl_down */
  2228. set_bit(STATUS_FW_ERROR, &priv->status);
  2229. wake_up_interruptible(&priv->wait_command_queue);
  2230. /*
  2231. * Keep the restart process from trying to send host
  2232. * commands by clearing the INIT status bit
  2233. */
  2234. clear_bit(STATUS_READY, &priv->status);
  2235. queue_work(priv->workqueue, &priv->restart);
  2236. break;
  2237. }
  2238. return 0;
  2239. }
  2240. EXPORT_SYMBOL(iwl_force_reset);
  2241. /**
  2242. * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
  2243. *
  2244. * During normal condition (no queue is stuck), the timer is continually set to
  2245. * execute every monitor_recover_period milliseconds after the last timer
  2246. * expired. When the queue read_ptr is at the same place, the timer is
  2247. * shorten to 100mSecs. This is
  2248. * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
  2249. * 2) to detect the stuck queues quicker before the station and AP can
  2250. * disassociate each other.
  2251. *
  2252. * This function monitors all the tx queues and recover from it if any
  2253. * of the queues are stuck.
  2254. * 1. It first check the cmd queue for stuck conditions. If it is stuck,
  2255. * it will recover by resetting the firmware and return.
  2256. * 2. Then, it checks for station association. If it associates it will check
  2257. * other queues. If any queue is stuck, it will recover by resetting
  2258. * the firmware.
  2259. * Note: It the number of times the queue read_ptr to be at the same place to
  2260. * be MAX_REPEAT+1 in order to consider to be stuck.
  2261. */
  2262. /*
  2263. * The maximum number of times the read pointer of the tx queue at the
  2264. * same place without considering to be stuck.
  2265. */
  2266. #define MAX_REPEAT (2)
  2267. static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
  2268. {
  2269. struct iwl_tx_queue *txq;
  2270. struct iwl_queue *q;
  2271. txq = &priv->txq[cnt];
  2272. q = &txq->q;
  2273. /* queue is empty, skip */
  2274. if (q->read_ptr != q->write_ptr) {
  2275. if (q->read_ptr == q->last_read_ptr) {
  2276. /* a queue has not been read from last time */
  2277. if (q->repeat_same_read_ptr > MAX_REPEAT) {
  2278. IWL_ERR(priv,
  2279. "queue %d stuck %d time. Fw reload.\n",
  2280. q->id, q->repeat_same_read_ptr);
  2281. q->repeat_same_read_ptr = 0;
  2282. iwl_force_reset(priv, IWL_FW_RESET, false);
  2283. } else {
  2284. q->repeat_same_read_ptr++;
  2285. IWL_DEBUG_RADIO(priv,
  2286. "queue %d, not read %d time\n",
  2287. q->id,
  2288. q->repeat_same_read_ptr);
  2289. mod_timer(&priv->monitor_recover, jiffies +
  2290. msecs_to_jiffies(IWL_ONE_HUNDRED_MSECS));
  2291. }
  2292. return 1;
  2293. } else {
  2294. q->last_read_ptr = q->read_ptr;
  2295. q->repeat_same_read_ptr = 0;
  2296. }
  2297. }
  2298. return 0;
  2299. }
  2300. void iwl_bg_monitor_recover(unsigned long data)
  2301. {
  2302. struct iwl_priv *priv = (struct iwl_priv *)data;
  2303. int cnt;
  2304. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2305. return;
  2306. /* monitor and check for stuck cmd queue */
  2307. if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM))
  2308. return;
  2309. /* monitor and check for other stuck queues */
  2310. if (iwl_is_associated(priv)) {
  2311. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  2312. /* skip as we already checked the command queue */
  2313. if (cnt == IWL_CMD_QUEUE_NUM)
  2314. continue;
  2315. if (iwl_check_stuck_queue(priv, cnt))
  2316. return;
  2317. }
  2318. }
  2319. /*
  2320. * Reschedule the timer to occur in
  2321. * priv->cfg->monitor_recover_period
  2322. */
  2323. mod_timer(&priv->monitor_recover,
  2324. jiffies + msecs_to_jiffies(priv->cfg->monitor_recover_period));
  2325. }
  2326. EXPORT_SYMBOL(iwl_bg_monitor_recover);
  2327. /*
  2328. * extended beacon time format
  2329. * time in usec will be changed into a 32-bit value in extended:internal format
  2330. * the extended part is the beacon counts
  2331. * the internal part is the time in usec within one beacon interval
  2332. */
  2333. u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
  2334. {
  2335. u32 quot;
  2336. u32 rem;
  2337. u32 interval = beacon_interval * TIME_UNIT;
  2338. if (!interval || !usec)
  2339. return 0;
  2340. quot = (usec / interval) &
  2341. (iwl_beacon_time_mask_high(priv,
  2342. priv->hw_params.beacon_time_tsf_bits) >>
  2343. priv->hw_params.beacon_time_tsf_bits);
  2344. rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
  2345. priv->hw_params.beacon_time_tsf_bits);
  2346. return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
  2347. }
  2348. EXPORT_SYMBOL(iwl_usecs_to_beacons);
  2349. /* base is usually what we get from ucode with each received frame,
  2350. * the same as HW timer counter counting down
  2351. */
  2352. __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
  2353. u32 addon, u32 beacon_interval)
  2354. {
  2355. u32 base_low = base & iwl_beacon_time_mask_low(priv,
  2356. priv->hw_params.beacon_time_tsf_bits);
  2357. u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
  2358. priv->hw_params.beacon_time_tsf_bits);
  2359. u32 interval = beacon_interval * TIME_UNIT;
  2360. u32 res = (base & iwl_beacon_time_mask_high(priv,
  2361. priv->hw_params.beacon_time_tsf_bits)) +
  2362. (addon & iwl_beacon_time_mask_high(priv,
  2363. priv->hw_params.beacon_time_tsf_bits));
  2364. if (base_low > addon_low)
  2365. res += base_low - addon_low;
  2366. else if (base_low < addon_low) {
  2367. res += interval + base_low - addon_low;
  2368. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2369. } else
  2370. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2371. return cpu_to_le32(res);
  2372. }
  2373. EXPORT_SYMBOL(iwl_add_beacon_time);
  2374. #ifdef CONFIG_PM
  2375. int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  2376. {
  2377. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2378. /*
  2379. * This function is called when system goes into suspend state
  2380. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2381. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2382. * it will not call apm_ops.stop() to stop the DMA operation.
  2383. * Calling apm_ops.stop here to make sure we stop the DMA.
  2384. */
  2385. priv->cfg->ops->lib->apm_ops.stop(priv);
  2386. pci_save_state(pdev);
  2387. pci_disable_device(pdev);
  2388. pci_set_power_state(pdev, PCI_D3hot);
  2389. return 0;
  2390. }
  2391. EXPORT_SYMBOL(iwl_pci_suspend);
  2392. int iwl_pci_resume(struct pci_dev *pdev)
  2393. {
  2394. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2395. int ret;
  2396. bool hw_rfkill = false;
  2397. /*
  2398. * We disable the RETRY_TIMEOUT register (0x41) to keep
  2399. * PCI Tx retries from interfering with C3 CPU state.
  2400. */
  2401. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2402. pci_set_power_state(pdev, PCI_D0);
  2403. ret = pci_enable_device(pdev);
  2404. if (ret)
  2405. return ret;
  2406. pci_restore_state(pdev);
  2407. iwl_enable_interrupts(priv);
  2408. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  2409. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  2410. hw_rfkill = true;
  2411. if (hw_rfkill)
  2412. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2413. else
  2414. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2415. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
  2416. return 0;
  2417. }
  2418. EXPORT_SYMBOL(iwl_pci_resume);
  2419. #endif /* CONFIG_PM */