iwl-core.c 81 KB

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