iwl-core.c 79 KB

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