iwl-core.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 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 <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h" /* FIXME: remove */
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-power.h"
  38. #include "iwl-sta.h"
  39. #include "iwl-helpers.h"
  40. MODULE_DESCRIPTION("iwl core");
  41. MODULE_VERSION(IWLWIFI_VERSION);
  42. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  43. MODULE_LICENSE("GPL");
  44. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  45. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  46. IWL_RATE_SISO_##s##M_PLCP, \
  47. IWL_RATE_MIMO2_##s##M_PLCP,\
  48. IWL_RATE_MIMO3_##s##M_PLCP,\
  49. IWL_RATE_##r##M_IEEE, \
  50. IWL_RATE_##ip##M_INDEX, \
  51. IWL_RATE_##in##M_INDEX, \
  52. IWL_RATE_##rp##M_INDEX, \
  53. IWL_RATE_##rn##M_INDEX, \
  54. IWL_RATE_##pp##M_INDEX, \
  55. IWL_RATE_##np##M_INDEX }
  56. u32 iwl_debug_level;
  57. EXPORT_SYMBOL(iwl_debug_level);
  58. static irqreturn_t iwl_isr(int irq, void *data);
  59. /*
  60. * Parameter order:
  61. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  62. *
  63. * If there isn't a valid next or previous rate then INV is used which
  64. * maps to IWL_RATE_INVALID
  65. *
  66. */
  67. const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
  68. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  69. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  70. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  71. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  72. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  73. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  74. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  75. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  76. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  77. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  78. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  79. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  80. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  81. /* FIXME:RS: ^^ should be INV (legacy) */
  82. };
  83. EXPORT_SYMBOL(iwl_rates);
  84. /**
  85. * translate ucode response to mac80211 tx status control values
  86. */
  87. void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
  88. struct ieee80211_tx_info *info)
  89. {
  90. int rate_index;
  91. struct ieee80211_tx_rate *r = &info->control.rates[0];
  92. info->antenna_sel_tx =
  93. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  94. if (rate_n_flags & RATE_MCS_HT_MSK)
  95. r->flags |= IEEE80211_TX_RC_MCS;
  96. if (rate_n_flags & RATE_MCS_GF_MSK)
  97. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  98. if (rate_n_flags & RATE_MCS_HT40_MSK)
  99. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  100. if (rate_n_flags & RATE_MCS_DUP_MSK)
  101. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  102. if (rate_n_flags & RATE_MCS_SGI_MSK)
  103. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  104. rate_index = iwl_hwrate_to_plcp_idx(rate_n_flags);
  105. if (info->band == IEEE80211_BAND_5GHZ)
  106. rate_index -= IWL_FIRST_OFDM_RATE;
  107. r->idx = rate_index;
  108. }
  109. EXPORT_SYMBOL(iwl_hwrate_to_tx_control);
  110. int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
  111. {
  112. int idx = 0;
  113. /* HT rate format */
  114. if (rate_n_flags & RATE_MCS_HT_MSK) {
  115. idx = (rate_n_flags & 0xff);
  116. if (idx >= IWL_RATE_MIMO3_6M_PLCP)
  117. idx = idx - IWL_RATE_MIMO3_6M_PLCP;
  118. else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
  119. idx = idx - IWL_RATE_MIMO2_6M_PLCP;
  120. idx += IWL_FIRST_OFDM_RATE;
  121. /* skip 9M not supported in ht*/
  122. if (idx >= IWL_RATE_9M_INDEX)
  123. idx += 1;
  124. if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
  125. return idx;
  126. /* legacy rate format, search for match in table */
  127. } else {
  128. for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
  129. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  130. return idx;
  131. }
  132. return -1;
  133. }
  134. EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
  135. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant)
  136. {
  137. int i;
  138. u8 ind = ant;
  139. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  140. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  141. if (priv->hw_params.valid_tx_ant & BIT(ind))
  142. return ind;
  143. }
  144. return ant;
  145. }
  146. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  147. EXPORT_SYMBOL(iwl_bcast_addr);
  148. /* This function both allocates and initializes hw and priv. */
  149. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  150. struct ieee80211_ops *hw_ops)
  151. {
  152. struct iwl_priv *priv;
  153. /* mac80211 allocates memory for this device instance, including
  154. * space for this driver's private structure */
  155. struct ieee80211_hw *hw =
  156. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  157. if (hw == NULL) {
  158. printk(KERN_ERR "%s: Can not allocate network device\n",
  159. cfg->name);
  160. goto out;
  161. }
  162. priv = hw->priv;
  163. priv->hw = hw;
  164. out:
  165. return hw;
  166. }
  167. EXPORT_SYMBOL(iwl_alloc_all);
  168. void iwl_hw_detect(struct iwl_priv *priv)
  169. {
  170. priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
  171. priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
  172. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  173. }
  174. EXPORT_SYMBOL(iwl_hw_detect);
  175. int iwl_hw_nic_init(struct iwl_priv *priv)
  176. {
  177. unsigned long flags;
  178. struct iwl_rx_queue *rxq = &priv->rxq;
  179. int ret;
  180. /* nic_init */
  181. spin_lock_irqsave(&priv->lock, flags);
  182. priv->cfg->ops->lib->apm_ops.init(priv);
  183. iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
  184. spin_unlock_irqrestore(&priv->lock, flags);
  185. ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
  186. priv->cfg->ops->lib->apm_ops.config(priv);
  187. /* Allocate the RX queue, or reset if it is already allocated */
  188. if (!rxq->bd) {
  189. ret = iwl_rx_queue_alloc(priv);
  190. if (ret) {
  191. IWL_ERR(priv, "Unable to initialize Rx queue\n");
  192. return -ENOMEM;
  193. }
  194. } else
  195. iwl_rx_queue_reset(priv, rxq);
  196. iwl_rx_replenish(priv);
  197. iwl_rx_init(priv, rxq);
  198. spin_lock_irqsave(&priv->lock, flags);
  199. rxq->need_update = 1;
  200. iwl_rx_queue_update_write_ptr(priv, rxq);
  201. spin_unlock_irqrestore(&priv->lock, flags);
  202. /* Allocate and init all Tx and Command queues */
  203. ret = iwl_txq_ctx_reset(priv);
  204. if (ret)
  205. return ret;
  206. set_bit(STATUS_INIT, &priv->status);
  207. return 0;
  208. }
  209. EXPORT_SYMBOL(iwl_hw_nic_init);
  210. /*
  211. * QoS support
  212. */
  213. void iwl_activate_qos(struct iwl_priv *priv, u8 force)
  214. {
  215. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  216. return;
  217. priv->qos_data.def_qos_parm.qos_flags = 0;
  218. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  219. !priv->qos_data.qos_cap.q_AP.txop_request)
  220. priv->qos_data.def_qos_parm.qos_flags |=
  221. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  222. if (priv->qos_data.qos_active)
  223. priv->qos_data.def_qos_parm.qos_flags |=
  224. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  225. if (priv->current_ht_config.is_ht)
  226. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  227. if (force || iwl_is_associated(priv)) {
  228. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  229. priv->qos_data.qos_active,
  230. priv->qos_data.def_qos_parm.qos_flags);
  231. iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
  232. sizeof(struct iwl_qosparam_cmd),
  233. &priv->qos_data.def_qos_parm, NULL);
  234. }
  235. }
  236. EXPORT_SYMBOL(iwl_activate_qos);
  237. /*
  238. * AC CWmin CW max AIFSN TXOP Limit TXOP Limit
  239. * (802.11b) (802.11a/g)
  240. * AC_BK 15 1023 7 0 0
  241. * AC_BE 15 1023 3 0 0
  242. * AC_VI 7 15 2 6.016ms 3.008ms
  243. * AC_VO 3 7 2 3.264ms 1.504ms
  244. */
  245. void iwl_reset_qos(struct iwl_priv *priv)
  246. {
  247. u16 cw_min = 15;
  248. u16 cw_max = 1023;
  249. u8 aifs = 2;
  250. bool is_legacy = false;
  251. unsigned long flags;
  252. int i;
  253. spin_lock_irqsave(&priv->lock, flags);
  254. /* QoS always active in AP and ADHOC mode
  255. * In STA mode wait for association
  256. */
  257. if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
  258. priv->iw_mode == NL80211_IFTYPE_AP)
  259. priv->qos_data.qos_active = 1;
  260. else
  261. priv->qos_data.qos_active = 0;
  262. /* check for legacy mode */
  263. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  264. (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) ||
  265. (priv->iw_mode == NL80211_IFTYPE_STATION &&
  266. (priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) {
  267. cw_min = 31;
  268. is_legacy = 1;
  269. }
  270. if (priv->qos_data.qos_active)
  271. aifs = 3;
  272. /* AC_BE */
  273. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  274. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  275. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  276. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  277. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  278. if (priv->qos_data.qos_active) {
  279. /* AC_BK */
  280. i = 1;
  281. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  282. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  283. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  284. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  285. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  286. /* AC_VI */
  287. i = 2;
  288. priv->qos_data.def_qos_parm.ac[i].cw_min =
  289. cpu_to_le16((cw_min + 1) / 2 - 1);
  290. priv->qos_data.def_qos_parm.ac[i].cw_max =
  291. cpu_to_le16(cw_min);
  292. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  293. if (is_legacy)
  294. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  295. cpu_to_le16(6016);
  296. else
  297. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  298. cpu_to_le16(3008);
  299. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  300. /* AC_VO */
  301. i = 3;
  302. priv->qos_data.def_qos_parm.ac[i].cw_min =
  303. cpu_to_le16((cw_min + 1) / 4 - 1);
  304. priv->qos_data.def_qos_parm.ac[i].cw_max =
  305. cpu_to_le16((cw_min + 1) / 2 - 1);
  306. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  307. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  308. if (is_legacy)
  309. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  310. cpu_to_le16(3264);
  311. else
  312. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  313. cpu_to_le16(1504);
  314. } else {
  315. for (i = 1; i < 4; i++) {
  316. priv->qos_data.def_qos_parm.ac[i].cw_min =
  317. cpu_to_le16(cw_min);
  318. priv->qos_data.def_qos_parm.ac[i].cw_max =
  319. cpu_to_le16(cw_max);
  320. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  321. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  322. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  323. }
  324. }
  325. IWL_DEBUG_QOS(priv, "set QoS to default \n");
  326. spin_unlock_irqrestore(&priv->lock, flags);
  327. }
  328. EXPORT_SYMBOL(iwl_reset_qos);
  329. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  330. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  331. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  332. struct ieee80211_sta_ht_cap *ht_info,
  333. enum ieee80211_band band)
  334. {
  335. u16 max_bit_rate = 0;
  336. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  337. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  338. ht_info->cap = 0;
  339. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  340. ht_info->ht_supported = true;
  341. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  342. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  343. ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
  344. (WLAN_HT_CAP_SM_PS_DISABLED << 2));
  345. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  346. if (priv->hw_params.ht40_channel & BIT(band)) {
  347. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  348. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  349. ht_info->mcs.rx_mask[4] = 0x01;
  350. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  351. }
  352. if (priv->cfg->mod_params->amsdu_size_8K)
  353. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  354. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  355. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  356. ht_info->mcs.rx_mask[0] = 0xFF;
  357. if (rx_chains_num >= 2)
  358. ht_info->mcs.rx_mask[1] = 0xFF;
  359. if (rx_chains_num >= 3)
  360. ht_info->mcs.rx_mask[2] = 0xFF;
  361. /* Highest supported Rx data rate */
  362. max_bit_rate *= rx_chains_num;
  363. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  364. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  365. /* Tx MCS capabilities */
  366. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  367. if (tx_chains_num != rx_chains_num) {
  368. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  369. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  370. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  371. }
  372. }
  373. static void iwlcore_init_hw_rates(struct iwl_priv *priv,
  374. struct ieee80211_rate *rates)
  375. {
  376. int i;
  377. for (i = 0; i < IWL_RATE_COUNT; i++) {
  378. rates[i].bitrate = iwl_rates[i].ieee * 5;
  379. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  380. rates[i].hw_value_short = i;
  381. rates[i].flags = 0;
  382. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  383. /*
  384. * If CCK != 1M then set short preamble rate flag.
  385. */
  386. rates[i].flags |=
  387. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  388. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  389. }
  390. }
  391. }
  392. /**
  393. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  394. */
  395. int iwlcore_init_geos(struct iwl_priv *priv)
  396. {
  397. struct iwl_channel_info *ch;
  398. struct ieee80211_supported_band *sband;
  399. struct ieee80211_channel *channels;
  400. struct ieee80211_channel *geo_ch;
  401. struct ieee80211_rate *rates;
  402. int i = 0;
  403. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  404. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  405. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  406. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  407. return 0;
  408. }
  409. channels = kzalloc(sizeof(struct ieee80211_channel) *
  410. priv->channel_count, GFP_KERNEL);
  411. if (!channels)
  412. return -ENOMEM;
  413. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  414. GFP_KERNEL);
  415. if (!rates) {
  416. kfree(channels);
  417. return -ENOMEM;
  418. }
  419. /* 5.2GHz channels start after the 2.4GHz channels */
  420. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  421. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  422. /* just OFDM */
  423. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  424. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  425. if (priv->cfg->sku & IWL_SKU_N)
  426. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  427. IEEE80211_BAND_5GHZ);
  428. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  429. sband->channels = channels;
  430. /* OFDM & CCK */
  431. sband->bitrates = rates;
  432. sband->n_bitrates = IWL_RATE_COUNT;
  433. if (priv->cfg->sku & IWL_SKU_N)
  434. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  435. IEEE80211_BAND_2GHZ);
  436. priv->ieee_channels = channels;
  437. priv->ieee_rates = rates;
  438. for (i = 0; i < priv->channel_count; i++) {
  439. ch = &priv->channel_info[i];
  440. /* FIXME: might be removed if scan is OK */
  441. if (!is_channel_valid(ch))
  442. continue;
  443. if (is_channel_a_band(ch))
  444. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  445. else
  446. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  447. geo_ch = &sband->channels[sband->n_channels++];
  448. geo_ch->center_freq =
  449. ieee80211_channel_to_frequency(ch->channel);
  450. geo_ch->max_power = ch->max_power_avg;
  451. geo_ch->max_antenna_gain = 0xff;
  452. geo_ch->hw_value = ch->channel;
  453. if (is_channel_valid(ch)) {
  454. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  455. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  456. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  457. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  458. if (ch->flags & EEPROM_CHANNEL_RADAR)
  459. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  460. geo_ch->flags |= ch->ht40_extension_channel;
  461. if (ch->max_power_avg > priv->tx_power_channel_lmt)
  462. priv->tx_power_channel_lmt = ch->max_power_avg;
  463. } else {
  464. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  465. }
  466. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  467. ch->channel, geo_ch->center_freq,
  468. is_channel_a_band(ch) ? "5.2" : "2.4",
  469. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  470. "restricted" : "valid",
  471. geo_ch->flags);
  472. }
  473. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  474. priv->cfg->sku & IWL_SKU_A) {
  475. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  476. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  477. priv->pci_dev->device,
  478. priv->pci_dev->subsystem_device);
  479. priv->cfg->sku &= ~IWL_SKU_A;
  480. }
  481. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  482. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  483. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  484. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  485. return 0;
  486. }
  487. EXPORT_SYMBOL(iwlcore_init_geos);
  488. /*
  489. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  490. */
  491. void iwlcore_free_geos(struct iwl_priv *priv)
  492. {
  493. kfree(priv->ieee_channels);
  494. kfree(priv->ieee_rates);
  495. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  496. }
  497. EXPORT_SYMBOL(iwlcore_free_geos);
  498. static bool is_single_rx_stream(struct iwl_priv *priv)
  499. {
  500. return !priv->current_ht_config.is_ht ||
  501. ((priv->current_ht_config.mcs.rx_mask[1] == 0) &&
  502. (priv->current_ht_config.mcs.rx_mask[2] == 0));
  503. }
  504. static u8 iwl_is_channel_extension(struct iwl_priv *priv,
  505. enum ieee80211_band band,
  506. u16 channel, u8 extension_chan_offset)
  507. {
  508. const struct iwl_channel_info *ch_info;
  509. ch_info = iwl_get_channel_info(priv, band, channel);
  510. if (!is_channel_valid(ch_info))
  511. return 0;
  512. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  513. return !(ch_info->ht40_extension_channel &
  514. IEEE80211_CHAN_NO_HT40PLUS);
  515. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  516. return !(ch_info->ht40_extension_channel &
  517. IEEE80211_CHAN_NO_HT40MINUS);
  518. return 0;
  519. }
  520. u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
  521. struct ieee80211_sta_ht_cap *sta_ht_inf)
  522. {
  523. struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
  524. if ((!iwl_ht_conf->is_ht) ||
  525. (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ))
  526. return 0;
  527. /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  528. * the bit will not set if it is pure 40MHz case
  529. */
  530. if (sta_ht_inf) {
  531. if (!sta_ht_inf->ht_supported)
  532. return 0;
  533. }
  534. #ifdef CONFIG_IWLWIFI_DEBUG
  535. if (priv->disable_ht40)
  536. return 0;
  537. #endif
  538. return iwl_is_channel_extension(priv, priv->band,
  539. le16_to_cpu(priv->staging_rxon.channel),
  540. iwl_ht_conf->extension_chan_offset);
  541. }
  542. EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
  543. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  544. {
  545. u16 new_val = 0;
  546. u16 beacon_factor = 0;
  547. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  548. new_val = beacon_val / beacon_factor;
  549. if (!new_val)
  550. new_val = max_beacon_val;
  551. return new_val;
  552. }
  553. void iwl_setup_rxon_timing(struct iwl_priv *priv)
  554. {
  555. u64 tsf;
  556. s32 interval_tm, rem;
  557. unsigned long flags;
  558. struct ieee80211_conf *conf = NULL;
  559. u16 beacon_int;
  560. conf = ieee80211_get_hw_conf(priv->hw);
  561. spin_lock_irqsave(&priv->lock, flags);
  562. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  563. priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
  564. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  565. beacon_int = priv->beacon_int;
  566. priv->rxon_timing.atim_window = 0;
  567. } else {
  568. beacon_int = priv->vif->bss_conf.beacon_int;
  569. /* TODO: we need to get atim_window from upper stack
  570. * for now we set to 0 */
  571. priv->rxon_timing.atim_window = 0;
  572. }
  573. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  574. priv->hw_params.max_beacon_itrvl * 1024);
  575. priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
  576. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  577. interval_tm = beacon_int * 1024;
  578. rem = do_div(tsf, interval_tm);
  579. priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  580. spin_unlock_irqrestore(&priv->lock, flags);
  581. IWL_DEBUG_ASSOC(priv,
  582. "beacon interval %d beacon timer %d beacon tim %d\n",
  583. le16_to_cpu(priv->rxon_timing.beacon_interval),
  584. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  585. le16_to_cpu(priv->rxon_timing.atim_window));
  586. }
  587. EXPORT_SYMBOL(iwl_setup_rxon_timing);
  588. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  589. {
  590. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  591. if (hw_decrypt)
  592. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  593. else
  594. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  595. }
  596. EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
  597. /**
  598. * iwl_check_rxon_cmd - validate RXON structure is valid
  599. *
  600. * NOTE: This is really only useful during development and can eventually
  601. * be #ifdef'd out once the driver is stable and folks aren't actively
  602. * making changes
  603. */
  604. int iwl_check_rxon_cmd(struct iwl_priv *priv)
  605. {
  606. int error = 0;
  607. int counter = 1;
  608. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  609. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  610. error |= le32_to_cpu(rxon->flags &
  611. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  612. RXON_FLG_RADAR_DETECT_MSK));
  613. if (error)
  614. IWL_WARN(priv, "check 24G fields %d | %d\n",
  615. counter++, error);
  616. } else {
  617. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  618. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  619. if (error)
  620. IWL_WARN(priv, "check 52 fields %d | %d\n",
  621. counter++, error);
  622. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  623. if (error)
  624. IWL_WARN(priv, "check 52 CCK %d | %d\n",
  625. counter++, error);
  626. }
  627. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  628. if (error)
  629. IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
  630. /* make sure basic rates 6Mbps and 1Mbps are supported */
  631. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  632. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  633. if (error)
  634. IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
  635. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  636. if (error)
  637. IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
  638. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  639. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  640. if (error)
  641. IWL_WARN(priv, "check CCK and short slot %d | %d\n",
  642. counter++, error);
  643. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  644. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  645. if (error)
  646. IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
  647. counter++, error);
  648. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  649. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  650. if (error)
  651. IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
  652. counter++, error);
  653. if (error)
  654. IWL_WARN(priv, "Tuning to channel %d\n",
  655. le16_to_cpu(rxon->channel));
  656. if (error) {
  657. IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
  658. return -1;
  659. }
  660. return 0;
  661. }
  662. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  663. /**
  664. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  665. * @priv: staging_rxon is compared to active_rxon
  666. *
  667. * If the RXON structure is changing enough to require a new tune,
  668. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  669. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  670. */
  671. int iwl_full_rxon_required(struct iwl_priv *priv)
  672. {
  673. /* These items are only settable from the full RXON command */
  674. if (!(iwl_is_associated(priv)) ||
  675. compare_ether_addr(priv->staging_rxon.bssid_addr,
  676. priv->active_rxon.bssid_addr) ||
  677. compare_ether_addr(priv->staging_rxon.node_addr,
  678. priv->active_rxon.node_addr) ||
  679. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  680. priv->active_rxon.wlap_bssid_addr) ||
  681. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  682. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  683. (priv->staging_rxon.air_propagation !=
  684. priv->active_rxon.air_propagation) ||
  685. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  686. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  687. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  688. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  689. (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
  690. priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
  691. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  692. return 1;
  693. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  694. * be updated with the RXON_ASSOC command -- however only some
  695. * flag transitions are allowed using RXON_ASSOC */
  696. /* Check if we are not switching bands */
  697. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  698. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  699. return 1;
  700. /* Check if we are switching association toggle */
  701. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  702. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  703. return 1;
  704. return 0;
  705. }
  706. EXPORT_SYMBOL(iwl_full_rxon_required);
  707. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
  708. {
  709. int i;
  710. int rate_mask;
  711. /* Set rate mask*/
  712. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  713. rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
  714. else
  715. rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
  716. /* Find lowest valid rate */
  717. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  718. i = iwl_rates[i].next_ieee) {
  719. if (rate_mask & (1 << i))
  720. return iwl_rates[i].plcp;
  721. }
  722. /* No valid rate was found. Assign the lowest one */
  723. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  724. return IWL_RATE_1M_PLCP;
  725. else
  726. return IWL_RATE_6M_PLCP;
  727. }
  728. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  729. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
  730. {
  731. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  732. if (!ht_info->is_ht) {
  733. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  734. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  735. RXON_FLG_HT40_PROT_MSK |
  736. RXON_FLG_HT_PROT_MSK);
  737. return;
  738. }
  739. /* FIXME: if the definition of ht_protection changed, the "translation"
  740. * will be needed for rxon->flags
  741. */
  742. rxon->flags |= cpu_to_le32(ht_info->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
  743. /* Set up channel bandwidth:
  744. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  745. /* clear the HT channel mode before set the mode */
  746. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  747. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  748. if (iwl_is_ht40_tx_allowed(priv, NULL)) {
  749. /* pure ht40 */
  750. if (ht_info->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  751. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  752. /* Note: control channel is opposite of extension channel */
  753. switch (ht_info->extension_chan_offset) {
  754. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  755. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  756. break;
  757. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  758. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  759. break;
  760. }
  761. } else {
  762. /* Note: control channel is opposite of extension channel */
  763. switch (ht_info->extension_chan_offset) {
  764. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  765. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  766. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  767. break;
  768. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  769. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  770. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  771. break;
  772. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  773. default:
  774. /* channel location only valid if in Mixed mode */
  775. IWL_ERR(priv, "invalid extension channel offset\n");
  776. break;
  777. }
  778. }
  779. } else {
  780. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  781. }
  782. if (priv->cfg->ops->hcmd->set_rxon_chain)
  783. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  784. IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X "
  785. "rxon flags 0x%X operation mode :0x%X "
  786. "extension channel offset 0x%x\n",
  787. ht_info->mcs.rx_mask[0],
  788. ht_info->mcs.rx_mask[1],
  789. ht_info->mcs.rx_mask[2],
  790. le32_to_cpu(rxon->flags), ht_info->ht_protection,
  791. ht_info->extension_chan_offset);
  792. return;
  793. }
  794. EXPORT_SYMBOL(iwl_set_rxon_ht);
  795. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  796. #define IWL_NUM_RX_CHAINS_SINGLE 2
  797. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  798. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  799. /* Determine how many receiver/antenna chains to use.
  800. * More provides better reception via diversity. Fewer saves power.
  801. * MIMO (dual stream) requires at least 2, but works better with 3.
  802. * This does not determine *which* chains to use, just how many.
  803. */
  804. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  805. {
  806. bool is_single = is_single_rx_stream(priv);
  807. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  808. /* # of Rx chains to use when expecting MIMO. */
  809. if (is_single || (!is_cam && (priv->current_ht_config.sm_ps ==
  810. WLAN_HT_CAP_SM_PS_STATIC)))
  811. return IWL_NUM_RX_CHAINS_SINGLE;
  812. else
  813. return IWL_NUM_RX_CHAINS_MULTIPLE;
  814. }
  815. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  816. {
  817. int idle_cnt;
  818. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  819. /* # Rx chains when idling and maybe trying to save power */
  820. switch (priv->current_ht_config.sm_ps) {
  821. case WLAN_HT_CAP_SM_PS_STATIC:
  822. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  823. idle_cnt = (is_cam) ? IWL_NUM_IDLE_CHAINS_DUAL :
  824. IWL_NUM_IDLE_CHAINS_SINGLE;
  825. break;
  826. case WLAN_HT_CAP_SM_PS_DISABLED:
  827. idle_cnt = (is_cam) ? active_cnt : IWL_NUM_IDLE_CHAINS_SINGLE;
  828. break;
  829. case WLAN_HT_CAP_SM_PS_INVALID:
  830. default:
  831. IWL_ERR(priv, "invalid mimo ps mode %d\n",
  832. priv->current_ht_config.sm_ps);
  833. WARN_ON(1);
  834. idle_cnt = -1;
  835. break;
  836. }
  837. return idle_cnt;
  838. }
  839. /* up to 4 chains */
  840. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  841. {
  842. u8 res;
  843. res = (chain_bitmap & BIT(0)) >> 0;
  844. res += (chain_bitmap & BIT(1)) >> 1;
  845. res += (chain_bitmap & BIT(2)) >> 2;
  846. res += (chain_bitmap & BIT(4)) >> 4;
  847. return res;
  848. }
  849. /**
  850. * iwl_is_monitor_mode - Determine if interface in monitor mode
  851. *
  852. * priv->iw_mode is set in add_interface, but add_interface is
  853. * never called for monitor mode. The only way mac80211 informs us about
  854. * monitor mode is through configuring filters (call to configure_filter).
  855. */
  856. bool iwl_is_monitor_mode(struct iwl_priv *priv)
  857. {
  858. return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
  859. }
  860. EXPORT_SYMBOL(iwl_is_monitor_mode);
  861. /**
  862. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  863. *
  864. * Selects how many and which Rx receivers/antennas/chains to use.
  865. * This should not be used for scan command ... it puts data in wrong place.
  866. */
  867. void iwl_set_rxon_chain(struct iwl_priv *priv)
  868. {
  869. bool is_single = is_single_rx_stream(priv);
  870. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  871. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  872. u32 active_chains;
  873. u16 rx_chain;
  874. /* Tell uCode which antennas are actually connected.
  875. * Before first association, we assume all antennas are connected.
  876. * Just after first association, iwl_chain_noise_calibration()
  877. * checks which antennas actually *are* connected. */
  878. if (priv->chain_noise_data.active_chains)
  879. active_chains = priv->chain_noise_data.active_chains;
  880. else
  881. active_chains = priv->hw_params.valid_rx_ant;
  882. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  883. /* How many receivers should we use? */
  884. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  885. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  886. /* correct rx chain count according hw settings
  887. * and chain noise calibration
  888. */
  889. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  890. if (valid_rx_cnt < active_rx_cnt)
  891. active_rx_cnt = valid_rx_cnt;
  892. if (valid_rx_cnt < idle_rx_cnt)
  893. idle_rx_cnt = valid_rx_cnt;
  894. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  895. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  896. /* copied from 'iwl_bg_request_scan()' */
  897. /* Force use of chains B and C (0x6) for Rx for 4965
  898. * Avoid A (0x1) because of its off-channel reception on A-band.
  899. * MIMO is not used here, but value is required */
  900. if (iwl_is_monitor_mode(priv) &&
  901. !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) &&
  902. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) {
  903. rx_chain = ANT_ABC << RXON_RX_CHAIN_VALID_POS;
  904. rx_chain |= ANT_BC << RXON_RX_CHAIN_FORCE_SEL_POS;
  905. rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  906. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  907. }
  908. priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
  909. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  910. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  911. else
  912. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  913. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  914. priv->staging_rxon.rx_chain,
  915. active_rx_cnt, idle_rx_cnt);
  916. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  917. active_rx_cnt < idle_rx_cnt);
  918. }
  919. EXPORT_SYMBOL(iwl_set_rxon_chain);
  920. /**
  921. * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
  922. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  923. * @channel: Any channel valid for the requested phymode
  924. * In addition to setting the staging RXON, priv->phymode is also set.
  925. *
  926. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  927. * in the staging RXON flag structure based on the phymode
  928. */
  929. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
  930. {
  931. enum ieee80211_band band = ch->band;
  932. u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
  933. if (!iwl_get_channel_info(priv, band, channel)) {
  934. IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
  935. channel, band);
  936. return -EINVAL;
  937. }
  938. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  939. (priv->band == band))
  940. return 0;
  941. priv->staging_rxon.channel = cpu_to_le16(channel);
  942. if (band == IEEE80211_BAND_5GHZ)
  943. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  944. else
  945. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  946. priv->band = band;
  947. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  948. return 0;
  949. }
  950. EXPORT_SYMBOL(iwl_set_rxon_channel);
  951. void iwl_set_flags_for_band(struct iwl_priv *priv,
  952. enum ieee80211_band band)
  953. {
  954. if (band == IEEE80211_BAND_5GHZ) {
  955. priv->staging_rxon.flags &=
  956. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  957. | RXON_FLG_CCK_MSK);
  958. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  959. } else {
  960. /* Copied from iwl_post_associate() */
  961. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  962. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  963. else
  964. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  965. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  966. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  967. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  968. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  969. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  970. }
  971. }
  972. /*
  973. * initialize rxon structure with default values from eeprom
  974. */
  975. void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
  976. {
  977. const struct iwl_channel_info *ch_info;
  978. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  979. switch (mode) {
  980. case NL80211_IFTYPE_AP:
  981. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  982. break;
  983. case NL80211_IFTYPE_STATION:
  984. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  985. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  986. break;
  987. case NL80211_IFTYPE_ADHOC:
  988. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  989. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  990. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  991. RXON_FILTER_ACCEPT_GRP_MSK;
  992. break;
  993. default:
  994. IWL_ERR(priv, "Unsupported interface type %d\n", mode);
  995. break;
  996. }
  997. #if 0
  998. /* TODO: Figure out when short_preamble would be set and cache from
  999. * that */
  1000. if (!hw_to_local(priv->hw)->short_preamble)
  1001. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1002. else
  1003. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1004. #endif
  1005. ch_info = iwl_get_channel_info(priv, priv->band,
  1006. le16_to_cpu(priv->active_rxon.channel));
  1007. if (!ch_info)
  1008. ch_info = &priv->channel_info[0];
  1009. /*
  1010. * in some case A channels are all non IBSS
  1011. * in this case force B/G channel
  1012. */
  1013. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
  1014. !(is_channel_ibss(ch_info)))
  1015. ch_info = &priv->channel_info[0];
  1016. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  1017. priv->band = ch_info->band;
  1018. iwl_set_flags_for_band(priv, priv->band);
  1019. priv->staging_rxon.ofdm_basic_rates =
  1020. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1021. priv->staging_rxon.cck_basic_rates =
  1022. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1023. /* clear both MIX and PURE40 mode flag */
  1024. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  1025. RXON_FLG_CHANNEL_MODE_PURE_40);
  1026. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1027. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  1028. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  1029. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  1030. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
  1031. }
  1032. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  1033. static void iwl_set_rate(struct iwl_priv *priv)
  1034. {
  1035. const struct ieee80211_supported_band *hw = NULL;
  1036. struct ieee80211_rate *rate;
  1037. int i;
  1038. hw = iwl_get_hw_mode(priv, priv->band);
  1039. if (!hw) {
  1040. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  1041. return;
  1042. }
  1043. priv->active_rate = 0;
  1044. priv->active_rate_basic = 0;
  1045. for (i = 0; i < hw->n_bitrates; i++) {
  1046. rate = &(hw->bitrates[i]);
  1047. if (rate->hw_value < IWL_RATE_COUNT)
  1048. priv->active_rate |= (1 << rate->hw_value);
  1049. }
  1050. IWL_DEBUG_RATE(priv, "Set active_rate = %0x, active_rate_basic = %0x\n",
  1051. priv->active_rate, priv->active_rate_basic);
  1052. /*
  1053. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1054. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1055. * OFDM
  1056. */
  1057. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1058. priv->staging_rxon.cck_basic_rates =
  1059. ((priv->active_rate_basic &
  1060. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1061. else
  1062. priv->staging_rxon.cck_basic_rates =
  1063. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1064. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1065. priv->staging_rxon.ofdm_basic_rates =
  1066. ((priv->active_rate_basic &
  1067. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1068. IWL_FIRST_OFDM_RATE) & 0xFF;
  1069. else
  1070. priv->staging_rxon.ofdm_basic_rates =
  1071. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1072. }
  1073. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1074. {
  1075. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1076. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1077. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  1078. IWL_DEBUG_11H(priv, "CSA notif: channel %d, status %d\n",
  1079. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1080. rxon->channel = csa->channel;
  1081. priv->staging_rxon.channel = csa->channel;
  1082. }
  1083. EXPORT_SYMBOL(iwl_rx_csa);
  1084. #ifdef CONFIG_IWLWIFI_DEBUG
  1085. static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
  1086. {
  1087. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  1088. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  1089. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  1090. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  1091. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  1092. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  1093. le32_to_cpu(rxon->filter_flags));
  1094. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  1095. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  1096. rxon->ofdm_basic_rates);
  1097. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  1098. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  1099. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  1100. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  1101. }
  1102. static const char *desc_lookup_text[] = {
  1103. "OK",
  1104. "FAIL",
  1105. "BAD_PARAM",
  1106. "BAD_CHECKSUM",
  1107. "NMI_INTERRUPT_WDG",
  1108. "SYSASSERT",
  1109. "FATAL_ERROR",
  1110. "BAD_COMMAND",
  1111. "HW_ERROR_TUNE_LOCK",
  1112. "HW_ERROR_TEMPERATURE",
  1113. "ILLEGAL_CHAN_FREQ",
  1114. "VCC_NOT_STABLE",
  1115. "FH_ERROR",
  1116. "NMI_INTERRUPT_HOST",
  1117. "NMI_INTERRUPT_ACTION_PT",
  1118. "NMI_INTERRUPT_UNKNOWN",
  1119. "UCODE_VERSION_MISMATCH",
  1120. "HW_ERROR_ABS_LOCK",
  1121. "HW_ERROR_CAL_LOCK_FAIL",
  1122. "NMI_INTERRUPT_INST_ACTION_PT",
  1123. "NMI_INTERRUPT_DATA_ACTION_PT",
  1124. "NMI_TRM_HW_ER",
  1125. "NMI_INTERRUPT_TRM",
  1126. "NMI_INTERRUPT_BREAK_POINT"
  1127. "DEBUG_0",
  1128. "DEBUG_1",
  1129. "DEBUG_2",
  1130. "DEBUG_3",
  1131. "UNKNOWN"
  1132. };
  1133. static const char *desc_lookup(int i)
  1134. {
  1135. int max = ARRAY_SIZE(desc_lookup_text) - 1;
  1136. if (i < 0 || i > max)
  1137. i = max;
  1138. return desc_lookup_text[i];
  1139. }
  1140. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1141. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1142. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1143. {
  1144. u32 data2, line;
  1145. u32 desc, time, count, base, data1;
  1146. u32 blink1, blink2, ilink1, ilink2;
  1147. if (priv->ucode_type == UCODE_INIT)
  1148. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  1149. else
  1150. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1151. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1152. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1153. return;
  1154. }
  1155. count = iwl_read_targ_mem(priv, base);
  1156. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1157. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1158. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1159. priv->status, count);
  1160. }
  1161. desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
  1162. blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
  1163. blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
  1164. ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
  1165. ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
  1166. data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
  1167. data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
  1168. line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
  1169. time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
  1170. IWL_ERR(priv, "Desc Time "
  1171. "data1 data2 line\n");
  1172. IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
  1173. desc_lookup(desc), desc, time, data1, data2, line);
  1174. IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
  1175. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
  1176. ilink1, ilink2);
  1177. }
  1178. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1179. /**
  1180. * iwl_print_event_log - Dump error event log to syslog
  1181. *
  1182. */
  1183. static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1184. u32 num_events, u32 mode)
  1185. {
  1186. u32 i;
  1187. u32 base; /* SRAM byte address of event log header */
  1188. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1189. u32 ptr; /* SRAM byte address of log data */
  1190. u32 ev, time, data; /* event log data */
  1191. if (num_events == 0)
  1192. return;
  1193. if (priv->ucode_type == UCODE_INIT)
  1194. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1195. else
  1196. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1197. if (mode == 0)
  1198. event_size = 2 * sizeof(u32);
  1199. else
  1200. event_size = 3 * sizeof(u32);
  1201. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1202. /* "time" is actually "data" for mode 0 (no timestamp).
  1203. * place event id # at far right for easier visual parsing. */
  1204. for (i = 0; i < num_events; i++) {
  1205. ev = iwl_read_targ_mem(priv, ptr);
  1206. ptr += sizeof(u32);
  1207. time = iwl_read_targ_mem(priv, ptr);
  1208. ptr += sizeof(u32);
  1209. if (mode == 0) {
  1210. /* data, ev */
  1211. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
  1212. } else {
  1213. data = iwl_read_targ_mem(priv, ptr);
  1214. ptr += sizeof(u32);
  1215. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1216. time, data, ev);
  1217. }
  1218. }
  1219. }
  1220. void iwl_dump_nic_event_log(struct iwl_priv *priv)
  1221. {
  1222. u32 base; /* SRAM byte address of event log header */
  1223. u32 capacity; /* event log capacity in # entries */
  1224. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1225. u32 num_wraps; /* # times uCode wrapped to top of log */
  1226. u32 next_entry; /* index of next entry to be written by uCode */
  1227. u32 size; /* # entries that we'll print */
  1228. if (priv->ucode_type == UCODE_INIT)
  1229. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1230. else
  1231. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1232. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1233. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1234. return;
  1235. }
  1236. /* event log header */
  1237. capacity = iwl_read_targ_mem(priv, base);
  1238. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1239. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1240. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1241. size = num_wraps ? capacity : next_entry;
  1242. /* bail out if nothing in log */
  1243. if (size == 0) {
  1244. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1245. return;
  1246. }
  1247. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  1248. size, num_wraps);
  1249. /* if uCode has wrapped back to top of log, start at the oldest entry,
  1250. * i.e the next one that uCode would fill. */
  1251. if (num_wraps)
  1252. iwl_print_event_log(priv, next_entry,
  1253. capacity - next_entry, mode);
  1254. /* (then/else) start at top of log */
  1255. iwl_print_event_log(priv, 0, next_entry, mode);
  1256. }
  1257. #endif
  1258. /**
  1259. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  1260. */
  1261. void iwl_irq_handle_error(struct iwl_priv *priv)
  1262. {
  1263. /* Set the FW error flag -- cleared on iwl_down */
  1264. set_bit(STATUS_FW_ERROR, &priv->status);
  1265. /* Cancel currently queued command. */
  1266. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1267. #ifdef CONFIG_IWLWIFI_DEBUG
  1268. if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) {
  1269. iwl_dump_nic_error_log(priv);
  1270. iwl_dump_nic_event_log(priv);
  1271. iwl_print_rx_config_cmd(priv);
  1272. }
  1273. #endif
  1274. wake_up_interruptible(&priv->wait_command_queue);
  1275. /* Keep the restart process from trying to send host
  1276. * commands by clearing the INIT status bit */
  1277. clear_bit(STATUS_READY, &priv->status);
  1278. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1279. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  1280. "Restarting adapter due to uCode error.\n");
  1281. if (priv->cfg->mod_params->restart_fw)
  1282. queue_work(priv->workqueue, &priv->restart);
  1283. }
  1284. }
  1285. EXPORT_SYMBOL(iwl_irq_handle_error);
  1286. void iwl_configure_filter(struct ieee80211_hw *hw,
  1287. unsigned int changed_flags,
  1288. unsigned int *total_flags,
  1289. int mc_count, struct dev_addr_list *mc_list)
  1290. {
  1291. struct iwl_priv *priv = hw->priv;
  1292. __le32 *filter_flags = &priv->staging_rxon.filter_flags;
  1293. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  1294. changed_flags, *total_flags);
  1295. if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
  1296. if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
  1297. *filter_flags |= RXON_FILTER_PROMISC_MSK;
  1298. else
  1299. *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
  1300. }
  1301. if (changed_flags & FIF_ALLMULTI) {
  1302. if (*total_flags & FIF_ALLMULTI)
  1303. *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
  1304. else
  1305. *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
  1306. }
  1307. if (changed_flags & FIF_CONTROL) {
  1308. if (*total_flags & FIF_CONTROL)
  1309. *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
  1310. else
  1311. *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
  1312. }
  1313. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  1314. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  1315. *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
  1316. else
  1317. *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
  1318. }
  1319. /* We avoid iwl_commit_rxon here to commit the new filter flags
  1320. * since mac80211 will call ieee80211_hw_config immediately.
  1321. * (mc_list is not supported at this time). Otherwise, we need to
  1322. * queue a background iwl_commit_rxon work.
  1323. */
  1324. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  1325. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  1326. }
  1327. EXPORT_SYMBOL(iwl_configure_filter);
  1328. int iwl_setup_mac(struct iwl_priv *priv)
  1329. {
  1330. int ret;
  1331. struct ieee80211_hw *hw = priv->hw;
  1332. hw->rate_control_algorithm = "iwl-agn-rs";
  1333. /* Tell mac80211 our characteristics */
  1334. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1335. IEEE80211_HW_NOISE_DBM |
  1336. IEEE80211_HW_AMPDU_AGGREGATION |
  1337. IEEE80211_HW_SPECTRUM_MGMT |
  1338. IEEE80211_HW_SUPPORTS_PS |
  1339. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  1340. hw->wiphy->interface_modes =
  1341. BIT(NL80211_IFTYPE_STATION) |
  1342. BIT(NL80211_IFTYPE_ADHOC);
  1343. hw->wiphy->custom_regulatory = true;
  1344. /* Firmware does not support this */
  1345. hw->wiphy->disable_beacon_hints = true;
  1346. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  1347. /* we create the 802.11 header and a zero-length SSID element */
  1348. hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
  1349. /* Default value; 4 EDCA QOS priorities */
  1350. hw->queues = 4;
  1351. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  1352. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  1353. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1354. &priv->bands[IEEE80211_BAND_2GHZ];
  1355. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  1356. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1357. &priv->bands[IEEE80211_BAND_5GHZ];
  1358. ret = ieee80211_register_hw(priv->hw);
  1359. if (ret) {
  1360. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  1361. return ret;
  1362. }
  1363. priv->mac80211_registered = 1;
  1364. return 0;
  1365. }
  1366. EXPORT_SYMBOL(iwl_setup_mac);
  1367. int iwl_set_hw_params(struct iwl_priv *priv)
  1368. {
  1369. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  1370. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  1371. if (priv->cfg->mod_params->amsdu_size_8K)
  1372. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  1373. else
  1374. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  1375. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  1376. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  1377. if (priv->cfg->mod_params->disable_11n)
  1378. priv->cfg->sku &= ~IWL_SKU_N;
  1379. /* Device-specific setup */
  1380. return priv->cfg->ops->lib->set_hw_params(priv);
  1381. }
  1382. EXPORT_SYMBOL(iwl_set_hw_params);
  1383. int iwl_init_drv(struct iwl_priv *priv)
  1384. {
  1385. int ret;
  1386. priv->ibss_beacon = NULL;
  1387. spin_lock_init(&priv->lock);
  1388. spin_lock_init(&priv->sta_lock);
  1389. spin_lock_init(&priv->hcmd_lock);
  1390. INIT_LIST_HEAD(&priv->free_frames);
  1391. mutex_init(&priv->mutex);
  1392. /* Clear the driver's (not device's) station table */
  1393. iwl_clear_stations_table(priv);
  1394. priv->data_retry_limit = -1;
  1395. priv->ieee_channels = NULL;
  1396. priv->ieee_rates = NULL;
  1397. priv->band = IEEE80211_BAND_2GHZ;
  1398. priv->iw_mode = NL80211_IFTYPE_STATION;
  1399. priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
  1400. /* Choose which receivers/antennas to use */
  1401. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1402. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1403. iwl_init_scan_params(priv);
  1404. iwl_reset_qos(priv);
  1405. priv->qos_data.qos_active = 0;
  1406. priv->qos_data.qos_cap.val = 0;
  1407. priv->rates_mask = IWL_RATES_MASK;
  1408. priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MAX;
  1409. ret = iwl_init_channel_map(priv);
  1410. if (ret) {
  1411. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  1412. goto err;
  1413. }
  1414. ret = iwlcore_init_geos(priv);
  1415. if (ret) {
  1416. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  1417. goto err_free_channel_map;
  1418. }
  1419. iwlcore_init_hw_rates(priv, priv->ieee_rates);
  1420. return 0;
  1421. err_free_channel_map:
  1422. iwl_free_channel_map(priv);
  1423. err:
  1424. return ret;
  1425. }
  1426. EXPORT_SYMBOL(iwl_init_drv);
  1427. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  1428. {
  1429. int ret = 0;
  1430. if (tx_power < IWL_TX_POWER_TARGET_POWER_MIN) {
  1431. IWL_WARN(priv, "Requested user TXPOWER %d below lower limit %d.\n",
  1432. tx_power,
  1433. IWL_TX_POWER_TARGET_POWER_MIN);
  1434. return -EINVAL;
  1435. }
  1436. if (tx_power > IWL_TX_POWER_TARGET_POWER_MAX) {
  1437. IWL_WARN(priv, "Requested user TXPOWER %d above upper limit %d.\n",
  1438. tx_power,
  1439. IWL_TX_POWER_TARGET_POWER_MAX);
  1440. return -EINVAL;
  1441. }
  1442. if (priv->tx_power_user_lmt != tx_power)
  1443. force = true;
  1444. priv->tx_power_user_lmt = tx_power;
  1445. /* if nic is not up don't send command */
  1446. if (!iwl_is_ready_rf(priv))
  1447. return ret;
  1448. if (force && priv->cfg->ops->lib->send_tx_power)
  1449. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1450. return ret;
  1451. }
  1452. EXPORT_SYMBOL(iwl_set_tx_power);
  1453. void iwl_uninit_drv(struct iwl_priv *priv)
  1454. {
  1455. iwl_calib_free_results(priv);
  1456. iwlcore_free_geos(priv);
  1457. iwl_free_channel_map(priv);
  1458. kfree(priv->scan);
  1459. }
  1460. EXPORT_SYMBOL(iwl_uninit_drv);
  1461. #define ICT_COUNT (PAGE_SIZE/sizeof(u32))
  1462. /* Free dram table */
  1463. void iwl_free_isr_ict(struct iwl_priv *priv)
  1464. {
  1465. if (priv->ict_tbl_vir) {
  1466. pci_free_consistent(priv->pci_dev, (sizeof(u32) * ICT_COUNT) +
  1467. PAGE_SIZE, priv->ict_tbl_vir,
  1468. priv->ict_tbl_dma);
  1469. priv->ict_tbl_vir = NULL;
  1470. }
  1471. }
  1472. EXPORT_SYMBOL(iwl_free_isr_ict);
  1473. /* allocate dram shared table it is a PAGE_SIZE aligned
  1474. * also reset all data related to ICT table interrupt.
  1475. */
  1476. int iwl_alloc_isr_ict(struct iwl_priv *priv)
  1477. {
  1478. if (priv->cfg->use_isr_legacy)
  1479. return 0;
  1480. /* allocate shrared data table */
  1481. priv->ict_tbl_vir = pci_alloc_consistent(priv->pci_dev, (sizeof(u32) *
  1482. ICT_COUNT) + PAGE_SIZE,
  1483. &priv->ict_tbl_dma);
  1484. if (!priv->ict_tbl_vir)
  1485. return -ENOMEM;
  1486. /* align table to PAGE_SIZE boundry */
  1487. priv->aligned_ict_tbl_dma = ALIGN(priv->ict_tbl_dma, PAGE_SIZE);
  1488. IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
  1489. (unsigned long long)priv->ict_tbl_dma,
  1490. (unsigned long long)priv->aligned_ict_tbl_dma,
  1491. (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
  1492. priv->ict_tbl = priv->ict_tbl_vir +
  1493. (priv->aligned_ict_tbl_dma - priv->ict_tbl_dma);
  1494. IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
  1495. priv->ict_tbl, priv->ict_tbl_vir,
  1496. (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
  1497. /* reset table and index to all 0 */
  1498. memset(priv->ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
  1499. priv->ict_index = 0;
  1500. /* add periodic RX interrupt */
  1501. priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
  1502. return 0;
  1503. }
  1504. EXPORT_SYMBOL(iwl_alloc_isr_ict);
  1505. /* Device is going up inform it about using ICT interrupt table,
  1506. * also we need to tell the driver to start using ICT interrupt.
  1507. */
  1508. int iwl_reset_ict(struct iwl_priv *priv)
  1509. {
  1510. u32 val;
  1511. unsigned long flags;
  1512. if (!priv->ict_tbl_vir)
  1513. return 0;
  1514. spin_lock_irqsave(&priv->lock, flags);
  1515. iwl_disable_interrupts(priv);
  1516. memset(&priv->ict_tbl[0],0, sizeof(u32) * ICT_COUNT);
  1517. val = priv->aligned_ict_tbl_dma >> PAGE_SHIFT;
  1518. val |= CSR_DRAM_INT_TBL_ENABLE;
  1519. val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
  1520. IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
  1521. "aligned dma address %Lx\n",
  1522. val, (unsigned long long)priv->aligned_ict_tbl_dma);
  1523. iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
  1524. priv->use_ict = true;
  1525. priv->ict_index = 0;
  1526. iwl_write32(priv, CSR_INT, priv->inta_mask);
  1527. iwl_enable_interrupts(priv);
  1528. spin_unlock_irqrestore(&priv->lock, flags);
  1529. return 0;
  1530. }
  1531. EXPORT_SYMBOL(iwl_reset_ict);
  1532. /* Device is going down disable ict interrupt usage */
  1533. void iwl_disable_ict(struct iwl_priv *priv)
  1534. {
  1535. unsigned long flags;
  1536. spin_lock_irqsave(&priv->lock, flags);
  1537. priv->use_ict = false;
  1538. spin_unlock_irqrestore(&priv->lock, flags);
  1539. }
  1540. EXPORT_SYMBOL(iwl_disable_ict);
  1541. /* interrupt handler using ict table, with this interrupt driver will
  1542. * stop using INTA register to get device's interrupt, reading this register
  1543. * is expensive, device will write interrupts in ICT dram table, increment
  1544. * index then will fire interrupt to driver, driver will OR all ICT table
  1545. * entries from current index up to table entry with 0 value. the result is
  1546. * the interrupt we need to service, driver will set the entries back to 0 and
  1547. * set index.
  1548. */
  1549. irqreturn_t iwl_isr_ict(int irq, void *data)
  1550. {
  1551. struct iwl_priv *priv = data;
  1552. u32 inta, inta_mask;
  1553. u32 val = 0;
  1554. if (!priv)
  1555. return IRQ_NONE;
  1556. /* dram interrupt table not set yet,
  1557. * use legacy interrupt.
  1558. */
  1559. if (!priv->use_ict)
  1560. return iwl_isr(irq, data);
  1561. spin_lock(&priv->lock);
  1562. /* Disable (but don't clear!) interrupts here to avoid
  1563. * back-to-back ISRs and sporadic interrupts from our NIC.
  1564. * If we have something to service, the tasklet will re-enable ints.
  1565. * If we *don't* have something, we'll re-enable before leaving here.
  1566. */
  1567. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1568. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1569. /* Ignore interrupt if there's nothing in NIC to service.
  1570. * This may be due to IRQ shared with another device,
  1571. * or due to sporadic interrupts thrown from our NIC. */
  1572. if (!priv->ict_tbl[priv->ict_index]) {
  1573. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  1574. goto none;
  1575. }
  1576. /* read all entries that not 0 start with ict_index */
  1577. while (priv->ict_tbl[priv->ict_index]) {
  1578. val |= priv->ict_tbl[priv->ict_index];
  1579. IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
  1580. priv->ict_index,
  1581. priv->ict_tbl[priv->ict_index]);
  1582. priv->ict_tbl[priv->ict_index] = 0;
  1583. priv->ict_index = iwl_queue_inc_wrap(priv->ict_index,
  1584. ICT_COUNT);
  1585. }
  1586. /* We should not get this value, just ignore it. */
  1587. if (val == 0xffffffff)
  1588. val = 0;
  1589. inta = (0xff & val) | ((0xff00 & val) << 16);
  1590. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
  1591. inta, inta_mask, val);
  1592. inta &= priv->inta_mask;
  1593. priv->inta |= inta;
  1594. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1595. if (likely(inta))
  1596. tasklet_schedule(&priv->irq_tasklet);
  1597. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta) {
  1598. /* Allow interrupt if was disabled by this handler and
  1599. * no tasklet was schedules, We should not enable interrupt,
  1600. * tasklet will enable it.
  1601. */
  1602. iwl_enable_interrupts(priv);
  1603. }
  1604. spin_unlock(&priv->lock);
  1605. return IRQ_HANDLED;
  1606. none:
  1607. /* re-enable interrupts here since we don't have anything to service.
  1608. * only Re-enable if disabled by irq.
  1609. */
  1610. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1611. iwl_enable_interrupts(priv);
  1612. spin_unlock(&priv->lock);
  1613. return IRQ_NONE;
  1614. }
  1615. EXPORT_SYMBOL(iwl_isr_ict);
  1616. static irqreturn_t iwl_isr(int irq, void *data)
  1617. {
  1618. struct iwl_priv *priv = data;
  1619. u32 inta, inta_mask;
  1620. #ifdef CONFIG_IWLWIFI_DEBUG
  1621. u32 inta_fh;
  1622. #endif
  1623. if (!priv)
  1624. return IRQ_NONE;
  1625. spin_lock(&priv->lock);
  1626. /* Disable (but don't clear!) interrupts here to avoid
  1627. * back-to-back ISRs and sporadic interrupts from our NIC.
  1628. * If we have something to service, the tasklet will re-enable ints.
  1629. * If we *don't* have something, we'll re-enable before leaving here. */
  1630. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1631. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1632. /* Discover which interrupts are active/pending */
  1633. inta = iwl_read32(priv, CSR_INT);
  1634. /* Ignore interrupt if there's nothing in NIC to service.
  1635. * This may be due to IRQ shared with another device,
  1636. * or due to sporadic interrupts thrown from our NIC. */
  1637. if (!inta) {
  1638. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  1639. goto none;
  1640. }
  1641. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1642. /* Hardware disappeared. It might have already raised
  1643. * an interrupt */
  1644. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1645. goto unplugged;
  1646. }
  1647. #ifdef CONFIG_IWLWIFI_DEBUG
  1648. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1649. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1650. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
  1651. "fh 0x%08x\n", inta, inta_mask, inta_fh);
  1652. }
  1653. #endif
  1654. priv->inta |= inta;
  1655. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1656. if (likely(inta))
  1657. tasklet_schedule(&priv->irq_tasklet);
  1658. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1659. iwl_enable_interrupts(priv);
  1660. unplugged:
  1661. spin_unlock(&priv->lock);
  1662. return IRQ_HANDLED;
  1663. none:
  1664. /* re-enable interrupts here since we don't have anything to service. */
  1665. /* only Re-enable if diabled by irq and no schedules tasklet. */
  1666. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1667. iwl_enable_interrupts(priv);
  1668. spin_unlock(&priv->lock);
  1669. return IRQ_NONE;
  1670. }
  1671. irqreturn_t iwl_isr_legacy(int irq, void *data)
  1672. {
  1673. struct iwl_priv *priv = data;
  1674. u32 inta, inta_mask;
  1675. u32 inta_fh;
  1676. if (!priv)
  1677. return IRQ_NONE;
  1678. spin_lock(&priv->lock);
  1679. /* Disable (but don't clear!) interrupts here to avoid
  1680. * back-to-back ISRs and sporadic interrupts from our NIC.
  1681. * If we have something to service, the tasklet will re-enable ints.
  1682. * If we *don't* have something, we'll re-enable before leaving here. */
  1683. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1684. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1685. /* Discover which interrupts are active/pending */
  1686. inta = iwl_read32(priv, CSR_INT);
  1687. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1688. /* Ignore interrupt if there's nothing in NIC to service.
  1689. * This may be due to IRQ shared with another device,
  1690. * or due to sporadic interrupts thrown from our NIC. */
  1691. if (!inta && !inta_fh) {
  1692. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1693. goto none;
  1694. }
  1695. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1696. /* Hardware disappeared. It might have already raised
  1697. * an interrupt */
  1698. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1699. goto unplugged;
  1700. }
  1701. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1702. inta, inta_mask, inta_fh);
  1703. inta &= ~CSR_INT_BIT_SCD;
  1704. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1705. if (likely(inta || inta_fh))
  1706. tasklet_schedule(&priv->irq_tasklet);
  1707. unplugged:
  1708. spin_unlock(&priv->lock);
  1709. return IRQ_HANDLED;
  1710. none:
  1711. /* re-enable interrupts here since we don't have anything to service. */
  1712. /* only Re-enable if diabled by irq */
  1713. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1714. iwl_enable_interrupts(priv);
  1715. spin_unlock(&priv->lock);
  1716. return IRQ_NONE;
  1717. }
  1718. EXPORT_SYMBOL(iwl_isr_legacy);
  1719. int iwl_send_bt_config(struct iwl_priv *priv)
  1720. {
  1721. struct iwl_bt_cmd bt_cmd = {
  1722. .flags = 3,
  1723. .lead_time = 0xAA,
  1724. .max_kill = 1,
  1725. .kill_ack_mask = 0,
  1726. .kill_cts_mask = 0,
  1727. };
  1728. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1729. sizeof(struct iwl_bt_cmd), &bt_cmd);
  1730. }
  1731. EXPORT_SYMBOL(iwl_send_bt_config);
  1732. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
  1733. {
  1734. u32 stat_flags = 0;
  1735. struct iwl_host_cmd cmd = {
  1736. .id = REPLY_STATISTICS_CMD,
  1737. .flags = flags,
  1738. .len = sizeof(stat_flags),
  1739. .data = (u8 *) &stat_flags,
  1740. };
  1741. return iwl_send_cmd(priv, &cmd);
  1742. }
  1743. EXPORT_SYMBOL(iwl_send_statistics_request);
  1744. /**
  1745. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  1746. * using sample data 100 bytes apart. If these sample points are good,
  1747. * it's a pretty good bet that everything between them is good, too.
  1748. */
  1749. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  1750. {
  1751. u32 val;
  1752. int ret = 0;
  1753. u32 errcnt = 0;
  1754. u32 i;
  1755. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1756. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  1757. /* read data comes through single port, auto-incr addr */
  1758. /* NOTE: Use the debugless read so we don't flood kernel log
  1759. * if IWL_DL_IO is set */
  1760. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1761. i + IWL49_RTC_INST_LOWER_BOUND);
  1762. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1763. if (val != le32_to_cpu(*image)) {
  1764. ret = -EIO;
  1765. errcnt++;
  1766. if (errcnt >= 3)
  1767. break;
  1768. }
  1769. }
  1770. return ret;
  1771. }
  1772. /**
  1773. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  1774. * looking at all data.
  1775. */
  1776. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  1777. u32 len)
  1778. {
  1779. u32 val;
  1780. u32 save_len = len;
  1781. int ret = 0;
  1782. u32 errcnt;
  1783. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1784. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1785. IWL49_RTC_INST_LOWER_BOUND);
  1786. errcnt = 0;
  1787. for (; len > 0; len -= sizeof(u32), image++) {
  1788. /* read data comes through single port, auto-incr addr */
  1789. /* NOTE: Use the debugless read so we don't flood kernel log
  1790. * if IWL_DL_IO is set */
  1791. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1792. if (val != le32_to_cpu(*image)) {
  1793. IWL_ERR(priv, "uCode INST section is invalid at "
  1794. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1795. save_len - len, val, le32_to_cpu(*image));
  1796. ret = -EIO;
  1797. errcnt++;
  1798. if (errcnt >= 20)
  1799. break;
  1800. }
  1801. }
  1802. if (!errcnt)
  1803. IWL_DEBUG_INFO(priv,
  1804. "ucode image in INSTRUCTION memory is good\n");
  1805. return ret;
  1806. }
  1807. /**
  1808. * iwl_verify_ucode - determine which instruction image is in SRAM,
  1809. * and verify its contents
  1810. */
  1811. int iwl_verify_ucode(struct iwl_priv *priv)
  1812. {
  1813. __le32 *image;
  1814. u32 len;
  1815. int ret;
  1816. /* Try bootstrap */
  1817. image = (__le32 *)priv->ucode_boot.v_addr;
  1818. len = priv->ucode_boot.len;
  1819. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1820. if (!ret) {
  1821. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  1822. return 0;
  1823. }
  1824. /* Try initialize */
  1825. image = (__le32 *)priv->ucode_init.v_addr;
  1826. len = priv->ucode_init.len;
  1827. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1828. if (!ret) {
  1829. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  1830. return 0;
  1831. }
  1832. /* Try runtime/protocol */
  1833. image = (__le32 *)priv->ucode_code.v_addr;
  1834. len = priv->ucode_code.len;
  1835. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1836. if (!ret) {
  1837. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  1838. return 0;
  1839. }
  1840. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  1841. /* Since nothing seems to match, show first several data entries in
  1842. * instruction SRAM, so maybe visual inspection will give a clue.
  1843. * Selection of bootstrap image (vs. other images) is arbitrary. */
  1844. image = (__le32 *)priv->ucode_boot.v_addr;
  1845. len = priv->ucode_boot.len;
  1846. ret = iwl_verify_inst_full(priv, image, len);
  1847. return ret;
  1848. }
  1849. EXPORT_SYMBOL(iwl_verify_ucode);
  1850. void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1851. {
  1852. struct iwl_ct_kill_config cmd;
  1853. struct iwl_ct_kill_throttling_config adv_cmd;
  1854. unsigned long flags;
  1855. int ret = 0;
  1856. spin_lock_irqsave(&priv->lock, flags);
  1857. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1858. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1859. spin_unlock_irqrestore(&priv->lock, flags);
  1860. priv->thermal_throttle.ct_kill_toggle = false;
  1861. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  1862. case CSR_HW_REV_TYPE_1000:
  1863. case CSR_HW_REV_TYPE_6x00:
  1864. case CSR_HW_REV_TYPE_6x50:
  1865. adv_cmd.critical_temperature_enter =
  1866. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1867. adv_cmd.critical_temperature_exit =
  1868. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  1869. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1870. sizeof(adv_cmd), &adv_cmd);
  1871. if (ret)
  1872. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1873. else
  1874. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1875. "succeeded, "
  1876. "critical temperature enter is %d,"
  1877. "exit is %d\n",
  1878. priv->hw_params.ct_kill_threshold,
  1879. priv->hw_params.ct_kill_exit_threshold);
  1880. break;
  1881. default:
  1882. cmd.critical_temperature_R =
  1883. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1884. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1885. sizeof(cmd), &cmd);
  1886. if (ret)
  1887. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1888. else
  1889. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1890. "succeeded, "
  1891. "critical temperature is %d\n",
  1892. priv->hw_params.ct_kill_threshold);
  1893. break;
  1894. }
  1895. }
  1896. EXPORT_SYMBOL(iwl_rf_kill_ct_config);
  1897. /*
  1898. * CARD_STATE_CMD
  1899. *
  1900. * Use: Sets the device's internal card state to enable, disable, or halt
  1901. *
  1902. * When in the 'enable' state the card operates as normal.
  1903. * When in the 'disable' state, the card enters into a low power mode.
  1904. * When in the 'halt' state, the card is shut down and must be fully
  1905. * restarted to come back on.
  1906. */
  1907. int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  1908. {
  1909. struct iwl_host_cmd cmd = {
  1910. .id = REPLY_CARD_STATE_CMD,
  1911. .len = sizeof(u32),
  1912. .data = &flags,
  1913. .flags = meta_flag,
  1914. };
  1915. return iwl_send_cmd(priv, &cmd);
  1916. }
  1917. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1918. struct iwl_rx_mem_buffer *rxb)
  1919. {
  1920. #ifdef CONFIG_IWLWIFI_DEBUG
  1921. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1922. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1923. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1924. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1925. #endif
  1926. }
  1927. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1928. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1929. struct iwl_rx_mem_buffer *rxb)
  1930. {
  1931. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1932. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1933. "notification for %s:\n",
  1934. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1935. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1936. }
  1937. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1938. void iwl_rx_reply_error(struct iwl_priv *priv,
  1939. struct iwl_rx_mem_buffer *rxb)
  1940. {
  1941. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1942. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1943. "seq 0x%04X ser 0x%08X\n",
  1944. le32_to_cpu(pkt->u.err_resp.error_type),
  1945. get_cmd_string(pkt->u.err_resp.cmd_id),
  1946. pkt->u.err_resp.cmd_id,
  1947. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1948. le32_to_cpu(pkt->u.err_resp.error_info));
  1949. }
  1950. EXPORT_SYMBOL(iwl_rx_reply_error);
  1951. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1952. {
  1953. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1954. }
  1955. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1956. const struct ieee80211_tx_queue_params *params)
  1957. {
  1958. struct iwl_priv *priv = hw->priv;
  1959. unsigned long flags;
  1960. int q;
  1961. IWL_DEBUG_MAC80211(priv, "enter\n");
  1962. if (!iwl_is_ready_rf(priv)) {
  1963. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1964. return -EIO;
  1965. }
  1966. if (queue >= AC_NUM) {
  1967. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1968. return 0;
  1969. }
  1970. q = AC_NUM - 1 - queue;
  1971. spin_lock_irqsave(&priv->lock, flags);
  1972. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  1973. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  1974. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1975. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  1976. cpu_to_le16((params->txop * 32));
  1977. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1978. priv->qos_data.qos_active = 1;
  1979. if (priv->iw_mode == NL80211_IFTYPE_AP)
  1980. iwl_activate_qos(priv, 1);
  1981. else if (priv->assoc_id && iwl_is_associated(priv))
  1982. iwl_activate_qos(priv, 0);
  1983. spin_unlock_irqrestore(&priv->lock, flags);
  1984. IWL_DEBUG_MAC80211(priv, "leave\n");
  1985. return 0;
  1986. }
  1987. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1988. static void iwl_ht_conf(struct iwl_priv *priv,
  1989. struct ieee80211_bss_conf *bss_conf)
  1990. {
  1991. struct ieee80211_sta_ht_cap *ht_conf;
  1992. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  1993. struct ieee80211_sta *sta;
  1994. IWL_DEBUG_MAC80211(priv, "enter: \n");
  1995. if (!iwl_conf->is_ht)
  1996. return;
  1997. /*
  1998. * It is totally wrong to base global information on something
  1999. * that is valid only when associated, alas, this driver works
  2000. * that way and I don't know how to fix it.
  2001. */
  2002. rcu_read_lock();
  2003. sta = ieee80211_find_sta(priv->hw, priv->bssid);
  2004. if (!sta) {
  2005. rcu_read_unlock();
  2006. return;
  2007. }
  2008. ht_conf = &sta->ht_cap;
  2009. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  2010. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  2011. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  2012. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  2013. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  2014. iwl_conf->max_amsdu_size =
  2015. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  2016. iwl_conf->supported_chan_width =
  2017. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  2018. /*
  2019. * XXX: The HT configuration needs to be moved into iwl_mac_config()
  2020. * to be done there correctly.
  2021. */
  2022. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2023. if (conf_is_ht40_minus(&priv->hw->conf))
  2024. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2025. else if (conf_is_ht40_plus(&priv->hw->conf))
  2026. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2027. /* If no above or below channel supplied disable HT40 channel */
  2028. if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
  2029. iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  2030. iwl_conf->supported_chan_width = 0;
  2031. iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
  2032. memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
  2033. iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
  2034. iwl_conf->ht_protection =
  2035. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  2036. iwl_conf->non_GF_STA_present =
  2037. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  2038. rcu_read_unlock();
  2039. IWL_DEBUG_MAC80211(priv, "leave\n");
  2040. }
  2041. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  2042. void iwl_bss_info_changed(struct ieee80211_hw *hw,
  2043. struct ieee80211_vif *vif,
  2044. struct ieee80211_bss_conf *bss_conf,
  2045. u32 changes)
  2046. {
  2047. struct iwl_priv *priv = hw->priv;
  2048. int ret;
  2049. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  2050. if (!iwl_is_alive(priv))
  2051. return;
  2052. mutex_lock(&priv->mutex);
  2053. if (changes & BSS_CHANGED_BEACON &&
  2054. priv->iw_mode == NL80211_IFTYPE_AP) {
  2055. dev_kfree_skb(priv->ibss_beacon);
  2056. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  2057. }
  2058. if (changes & BSS_CHANGED_BEACON_INT) {
  2059. priv->beacon_int = bss_conf->beacon_int;
  2060. /* TODO: in AP mode, do something to make this take effect */
  2061. }
  2062. if (changes & BSS_CHANGED_BSSID) {
  2063. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  2064. /*
  2065. * If there is currently a HW scan going on in the
  2066. * background then we need to cancel it else the RXON
  2067. * below/in post_associate will fail.
  2068. */
  2069. if (iwl_scan_cancel_timeout(priv, 100)) {
  2070. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  2071. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  2072. mutex_unlock(&priv->mutex);
  2073. return;
  2074. }
  2075. /* mac80211 only sets assoc when in STATION mode */
  2076. if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
  2077. bss_conf->assoc) {
  2078. memcpy(priv->staging_rxon.bssid_addr,
  2079. bss_conf->bssid, ETH_ALEN);
  2080. /* currently needed in a few places */
  2081. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  2082. } else {
  2083. priv->staging_rxon.filter_flags &=
  2084. ~RXON_FILTER_ASSOC_MSK;
  2085. }
  2086. }
  2087. /*
  2088. * This needs to be after setting the BSSID in case
  2089. * mac80211 decides to do both changes at once because
  2090. * it will invoke post_associate.
  2091. */
  2092. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  2093. changes & BSS_CHANGED_BEACON) {
  2094. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  2095. if (beacon)
  2096. iwl_mac_beacon_update(hw, beacon);
  2097. }
  2098. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  2099. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  2100. bss_conf->use_short_preamble);
  2101. if (bss_conf->use_short_preamble)
  2102. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2103. else
  2104. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2105. }
  2106. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  2107. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
  2108. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  2109. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  2110. else
  2111. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  2112. }
  2113. if (changes & BSS_CHANGED_BASIC_RATES) {
  2114. /* XXX use this information
  2115. *
  2116. * To do that, remove code from iwl_set_rate() and put something
  2117. * like this here:
  2118. *
  2119. if (A-band)
  2120. priv->staging_rxon.ofdm_basic_rates =
  2121. bss_conf->basic_rates;
  2122. else
  2123. priv->staging_rxon.ofdm_basic_rates =
  2124. bss_conf->basic_rates >> 4;
  2125. priv->staging_rxon.cck_basic_rates =
  2126. bss_conf->basic_rates & 0xF;
  2127. */
  2128. }
  2129. if (changes & BSS_CHANGED_HT) {
  2130. iwl_ht_conf(priv, bss_conf);
  2131. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2132. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2133. }
  2134. if (changes & BSS_CHANGED_ASSOC) {
  2135. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  2136. if (bss_conf->assoc) {
  2137. priv->assoc_id = bss_conf->aid;
  2138. priv->beacon_int = bss_conf->beacon_int;
  2139. priv->timestamp = bss_conf->timestamp;
  2140. priv->assoc_capability = bss_conf->assoc_capability;
  2141. /*
  2142. * We have just associated, don't start scan too early
  2143. * leave time for EAPOL exchange to complete.
  2144. *
  2145. * XXX: do this in mac80211
  2146. */
  2147. priv->next_scan_jiffies = jiffies +
  2148. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  2149. if (!iwl_is_rfkill(priv))
  2150. priv->cfg->ops->lib->post_associate(priv);
  2151. } else
  2152. priv->assoc_id = 0;
  2153. }
  2154. if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  2155. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  2156. changes);
  2157. ret = iwl_send_rxon_assoc(priv);
  2158. if (!ret) {
  2159. /* Sync active_rxon with latest change. */
  2160. memcpy((void *)&priv->active_rxon,
  2161. &priv->staging_rxon,
  2162. sizeof(struct iwl_rxon_cmd));
  2163. }
  2164. }
  2165. mutex_unlock(&priv->mutex);
  2166. IWL_DEBUG_MAC80211(priv, "leave\n");
  2167. }
  2168. EXPORT_SYMBOL(iwl_bss_info_changed);
  2169. int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  2170. {
  2171. struct iwl_priv *priv = hw->priv;
  2172. unsigned long flags;
  2173. __le64 timestamp;
  2174. IWL_DEBUG_MAC80211(priv, "enter\n");
  2175. if (!iwl_is_ready_rf(priv)) {
  2176. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  2177. return -EIO;
  2178. }
  2179. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  2180. IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
  2181. return -EIO;
  2182. }
  2183. spin_lock_irqsave(&priv->lock, flags);
  2184. if (priv->ibss_beacon)
  2185. dev_kfree_skb(priv->ibss_beacon);
  2186. priv->ibss_beacon = skb;
  2187. priv->assoc_id = 0;
  2188. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  2189. priv->timestamp = le64_to_cpu(timestamp);
  2190. IWL_DEBUG_MAC80211(priv, "leave\n");
  2191. spin_unlock_irqrestore(&priv->lock, flags);
  2192. iwl_reset_qos(priv);
  2193. priv->cfg->ops->lib->post_associate(priv);
  2194. return 0;
  2195. }
  2196. EXPORT_SYMBOL(iwl_mac_beacon_update);
  2197. int iwl_set_mode(struct iwl_priv *priv, int mode)
  2198. {
  2199. if (mode == NL80211_IFTYPE_ADHOC) {
  2200. const struct iwl_channel_info *ch_info;
  2201. ch_info = iwl_get_channel_info(priv,
  2202. priv->band,
  2203. le16_to_cpu(priv->staging_rxon.channel));
  2204. if (!ch_info || !is_channel_ibss(ch_info)) {
  2205. IWL_ERR(priv, "channel %d not IBSS channel\n",
  2206. le16_to_cpu(priv->staging_rxon.channel));
  2207. return -EINVAL;
  2208. }
  2209. }
  2210. iwl_connection_init_rx_config(priv, mode);
  2211. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2212. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2213. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2214. iwl_clear_stations_table(priv);
  2215. /* dont commit rxon if rf-kill is on*/
  2216. if (!iwl_is_ready_rf(priv))
  2217. return -EAGAIN;
  2218. iwlcore_commit_rxon(priv);
  2219. return 0;
  2220. }
  2221. EXPORT_SYMBOL(iwl_set_mode);
  2222. int iwl_mac_add_interface(struct ieee80211_hw *hw,
  2223. struct ieee80211_if_init_conf *conf)
  2224. {
  2225. struct iwl_priv *priv = hw->priv;
  2226. unsigned long flags;
  2227. IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
  2228. if (priv->vif) {
  2229. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  2230. return -EOPNOTSUPP;
  2231. }
  2232. spin_lock_irqsave(&priv->lock, flags);
  2233. priv->vif = conf->vif;
  2234. priv->iw_mode = conf->type;
  2235. spin_unlock_irqrestore(&priv->lock, flags);
  2236. mutex_lock(&priv->mutex);
  2237. if (conf->mac_addr) {
  2238. IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
  2239. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  2240. }
  2241. if (iwl_set_mode(priv, conf->type) == -EAGAIN)
  2242. /* we are not ready, will run again when ready */
  2243. set_bit(STATUS_MODE_PENDING, &priv->status);
  2244. mutex_unlock(&priv->mutex);
  2245. IWL_DEBUG_MAC80211(priv, "leave\n");
  2246. return 0;
  2247. }
  2248. EXPORT_SYMBOL(iwl_mac_add_interface);
  2249. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  2250. struct ieee80211_if_init_conf *conf)
  2251. {
  2252. struct iwl_priv *priv = hw->priv;
  2253. IWL_DEBUG_MAC80211(priv, "enter\n");
  2254. mutex_lock(&priv->mutex);
  2255. if (iwl_is_ready_rf(priv)) {
  2256. iwl_scan_cancel_timeout(priv, 100);
  2257. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2258. iwlcore_commit_rxon(priv);
  2259. }
  2260. if (priv->vif == conf->vif) {
  2261. priv->vif = NULL;
  2262. memset(priv->bssid, 0, ETH_ALEN);
  2263. }
  2264. mutex_unlock(&priv->mutex);
  2265. IWL_DEBUG_MAC80211(priv, "leave\n");
  2266. }
  2267. EXPORT_SYMBOL(iwl_mac_remove_interface);
  2268. /**
  2269. * iwl_mac_config - mac80211 config callback
  2270. *
  2271. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  2272. * be set inappropriately and the driver currently sets the hardware up to
  2273. * use it whenever needed.
  2274. */
  2275. int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
  2276. {
  2277. struct iwl_priv *priv = hw->priv;
  2278. const struct iwl_channel_info *ch_info;
  2279. struct ieee80211_conf *conf = &hw->conf;
  2280. unsigned long flags = 0;
  2281. int ret = 0;
  2282. u16 ch;
  2283. int scan_active = 0;
  2284. mutex_lock(&priv->mutex);
  2285. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  2286. conf->channel->hw_value, changed);
  2287. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  2288. test_bit(STATUS_SCANNING, &priv->status))) {
  2289. scan_active = 1;
  2290. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  2291. }
  2292. /* during scanning mac80211 will delay channel setting until
  2293. * scan finish with changed = 0
  2294. */
  2295. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  2296. if (scan_active)
  2297. goto set_ch_out;
  2298. ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
  2299. ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
  2300. if (!is_channel_valid(ch_info)) {
  2301. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  2302. ret = -EINVAL;
  2303. goto set_ch_out;
  2304. }
  2305. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  2306. !is_channel_ibss(ch_info)) {
  2307. IWL_ERR(priv, "channel %d in band %d not "
  2308. "IBSS channel\n",
  2309. conf->channel->hw_value, conf->channel->band);
  2310. ret = -EINVAL;
  2311. goto set_ch_out;
  2312. }
  2313. priv->current_ht_config.is_ht = conf_is_ht(conf);
  2314. spin_lock_irqsave(&priv->lock, flags);
  2315. /* if we are switching from ht to 2.4 clear flags
  2316. * from any ht related info since 2.4 does not
  2317. * support ht */
  2318. if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
  2319. priv->staging_rxon.flags = 0;
  2320. iwl_set_rxon_channel(priv, conf->channel);
  2321. iwl_set_flags_for_band(priv, conf->channel->band);
  2322. spin_unlock_irqrestore(&priv->lock, flags);
  2323. set_ch_out:
  2324. /* The list of supported rates and rate mask can be different
  2325. * for each band; since the band may have changed, reset
  2326. * the rate mask to what mac80211 lists */
  2327. iwl_set_rate(priv);
  2328. }
  2329. if (changed & IEEE80211_CONF_CHANGE_PS) {
  2330. ret = iwl_power_update_mode(priv, false);
  2331. if (ret)
  2332. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  2333. }
  2334. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  2335. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  2336. priv->tx_power_user_lmt, conf->power_level);
  2337. iwl_set_tx_power(priv, conf->power_level, false);
  2338. }
  2339. /* call to ensure that 4965 rx_chain is set properly in monitor mode */
  2340. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2341. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2342. if (!iwl_is_ready(priv)) {
  2343. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  2344. goto out;
  2345. }
  2346. if (scan_active)
  2347. goto out;
  2348. if (memcmp(&priv->active_rxon,
  2349. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  2350. iwlcore_commit_rxon(priv);
  2351. else
  2352. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
  2353. out:
  2354. IWL_DEBUG_MAC80211(priv, "leave\n");
  2355. mutex_unlock(&priv->mutex);
  2356. return ret;
  2357. }
  2358. EXPORT_SYMBOL(iwl_mac_config);
  2359. int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
  2360. struct ieee80211_tx_queue_stats *stats)
  2361. {
  2362. struct iwl_priv *priv = hw->priv;
  2363. int i, avail;
  2364. struct iwl_tx_queue *txq;
  2365. struct iwl_queue *q;
  2366. unsigned long flags;
  2367. IWL_DEBUG_MAC80211(priv, "enter\n");
  2368. if (!iwl_is_ready_rf(priv)) {
  2369. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  2370. return -EIO;
  2371. }
  2372. spin_lock_irqsave(&priv->lock, flags);
  2373. for (i = 0; i < AC_NUM; i++) {
  2374. txq = &priv->txq[i];
  2375. q = &txq->q;
  2376. avail = iwl_queue_space(q);
  2377. stats[i].len = q->n_window - avail;
  2378. stats[i].limit = q->n_window - q->high_mark;
  2379. stats[i].count = q->n_window;
  2380. }
  2381. spin_unlock_irqrestore(&priv->lock, flags);
  2382. IWL_DEBUG_MAC80211(priv, "leave\n");
  2383. return 0;
  2384. }
  2385. EXPORT_SYMBOL(iwl_mac_get_tx_stats);
  2386. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  2387. {
  2388. struct iwl_priv *priv = hw->priv;
  2389. unsigned long flags;
  2390. mutex_lock(&priv->mutex);
  2391. IWL_DEBUG_MAC80211(priv, "enter\n");
  2392. spin_lock_irqsave(&priv->lock, flags);
  2393. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  2394. spin_unlock_irqrestore(&priv->lock, flags);
  2395. iwl_reset_qos(priv);
  2396. spin_lock_irqsave(&priv->lock, flags);
  2397. priv->assoc_id = 0;
  2398. priv->assoc_capability = 0;
  2399. priv->assoc_station_added = 0;
  2400. /* new association get rid of ibss beacon skb */
  2401. if (priv->ibss_beacon)
  2402. dev_kfree_skb(priv->ibss_beacon);
  2403. priv->ibss_beacon = NULL;
  2404. priv->beacon_int = priv->vif->bss_conf.beacon_int;
  2405. priv->timestamp = 0;
  2406. if ((priv->iw_mode == NL80211_IFTYPE_STATION))
  2407. priv->beacon_int = 0;
  2408. spin_unlock_irqrestore(&priv->lock, flags);
  2409. if (!iwl_is_ready_rf(priv)) {
  2410. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  2411. mutex_unlock(&priv->mutex);
  2412. return;
  2413. }
  2414. /* we are restarting association process
  2415. * clear RXON_FILTER_ASSOC_MSK bit
  2416. */
  2417. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  2418. iwl_scan_cancel_timeout(priv, 100);
  2419. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2420. iwlcore_commit_rxon(priv);
  2421. }
  2422. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  2423. IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
  2424. mutex_unlock(&priv->mutex);
  2425. return;
  2426. }
  2427. iwl_set_rate(priv);
  2428. mutex_unlock(&priv->mutex);
  2429. IWL_DEBUG_MAC80211(priv, "leave\n");
  2430. }
  2431. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  2432. #ifdef CONFIG_IWLWIFI_DEBUGFS
  2433. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  2434. void iwl_reset_traffic_log(struct iwl_priv *priv)
  2435. {
  2436. priv->tx_traffic_idx = 0;
  2437. priv->rx_traffic_idx = 0;
  2438. if (priv->tx_traffic)
  2439. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  2440. if (priv->rx_traffic)
  2441. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  2442. }
  2443. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  2444. {
  2445. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  2446. if (iwl_debug_level & IWL_DL_TX) {
  2447. if (!priv->tx_traffic) {
  2448. priv->tx_traffic =
  2449. kzalloc(traffic_size, GFP_KERNEL);
  2450. if (!priv->tx_traffic)
  2451. return -ENOMEM;
  2452. }
  2453. }
  2454. if (iwl_debug_level & IWL_DL_RX) {
  2455. if (!priv->rx_traffic) {
  2456. priv->rx_traffic =
  2457. kzalloc(traffic_size, GFP_KERNEL);
  2458. if (!priv->rx_traffic)
  2459. return -ENOMEM;
  2460. }
  2461. }
  2462. iwl_reset_traffic_log(priv);
  2463. return 0;
  2464. }
  2465. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  2466. void iwl_free_traffic_mem(struct iwl_priv *priv)
  2467. {
  2468. kfree(priv->tx_traffic);
  2469. priv->tx_traffic = NULL;
  2470. kfree(priv->rx_traffic);
  2471. priv->rx_traffic = NULL;
  2472. }
  2473. EXPORT_SYMBOL(iwl_free_traffic_mem);
  2474. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  2475. u16 length, struct ieee80211_hdr *header)
  2476. {
  2477. __le16 fc;
  2478. u16 len;
  2479. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  2480. return;
  2481. if (!priv->tx_traffic)
  2482. return;
  2483. fc = header->frame_control;
  2484. if (ieee80211_is_data(fc)) {
  2485. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  2486. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  2487. memcpy((priv->tx_traffic +
  2488. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  2489. header, len);
  2490. priv->tx_traffic_idx =
  2491. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  2492. }
  2493. }
  2494. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  2495. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  2496. u16 length, struct ieee80211_hdr *header)
  2497. {
  2498. __le16 fc;
  2499. u16 len;
  2500. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  2501. return;
  2502. if (!priv->rx_traffic)
  2503. return;
  2504. fc = header->frame_control;
  2505. if (ieee80211_is_data(fc)) {
  2506. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  2507. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  2508. memcpy((priv->rx_traffic +
  2509. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  2510. header, len);
  2511. priv->rx_traffic_idx =
  2512. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  2513. }
  2514. }
  2515. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  2516. const char *get_mgmt_string(int cmd)
  2517. {
  2518. switch (cmd) {
  2519. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  2520. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  2521. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  2522. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  2523. IWL_CMD(MANAGEMENT_PROBE_REQ);
  2524. IWL_CMD(MANAGEMENT_PROBE_RESP);
  2525. IWL_CMD(MANAGEMENT_BEACON);
  2526. IWL_CMD(MANAGEMENT_ATIM);
  2527. IWL_CMD(MANAGEMENT_DISASSOC);
  2528. IWL_CMD(MANAGEMENT_AUTH);
  2529. IWL_CMD(MANAGEMENT_DEAUTH);
  2530. IWL_CMD(MANAGEMENT_ACTION);
  2531. default:
  2532. return "UNKNOWN";
  2533. }
  2534. }
  2535. const char *get_ctrl_string(int cmd)
  2536. {
  2537. switch (cmd) {
  2538. IWL_CMD(CONTROL_BACK_REQ);
  2539. IWL_CMD(CONTROL_BACK);
  2540. IWL_CMD(CONTROL_PSPOLL);
  2541. IWL_CMD(CONTROL_RTS);
  2542. IWL_CMD(CONTROL_CTS);
  2543. IWL_CMD(CONTROL_ACK);
  2544. IWL_CMD(CONTROL_CFEND);
  2545. IWL_CMD(CONTROL_CFENDACK);
  2546. default:
  2547. return "UNKNOWN";
  2548. }
  2549. }
  2550. void iwl_clear_tx_stats(struct iwl_priv *priv)
  2551. {
  2552. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  2553. }
  2554. void iwl_clear_rx_stats(struct iwl_priv *priv)
  2555. {
  2556. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  2557. }
  2558. /*
  2559. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  2560. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  2561. * Use debugFs to display the rx/rx_statistics
  2562. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  2563. * information will be recorded, but DATA pkt still will be recorded
  2564. * for the reason of iwl_led.c need to control the led blinking based on
  2565. * number of tx and rx data.
  2566. *
  2567. */
  2568. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  2569. {
  2570. struct traffic_stats *stats;
  2571. if (is_tx)
  2572. stats = &priv->tx_stats;
  2573. else
  2574. stats = &priv->rx_stats;
  2575. if (ieee80211_is_mgmt(fc)) {
  2576. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2577. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  2578. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  2579. break;
  2580. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2581. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  2582. break;
  2583. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  2584. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  2585. break;
  2586. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2587. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  2588. break;
  2589. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2590. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  2591. break;
  2592. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2593. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  2594. break;
  2595. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2596. stats->mgmt[MANAGEMENT_BEACON]++;
  2597. break;
  2598. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  2599. stats->mgmt[MANAGEMENT_ATIM]++;
  2600. break;
  2601. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2602. stats->mgmt[MANAGEMENT_DISASSOC]++;
  2603. break;
  2604. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2605. stats->mgmt[MANAGEMENT_AUTH]++;
  2606. break;
  2607. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2608. stats->mgmt[MANAGEMENT_DEAUTH]++;
  2609. break;
  2610. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  2611. stats->mgmt[MANAGEMENT_ACTION]++;
  2612. break;
  2613. }
  2614. } else if (ieee80211_is_ctl(fc)) {
  2615. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2616. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  2617. stats->ctrl[CONTROL_BACK_REQ]++;
  2618. break;
  2619. case cpu_to_le16(IEEE80211_STYPE_BACK):
  2620. stats->ctrl[CONTROL_BACK]++;
  2621. break;
  2622. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  2623. stats->ctrl[CONTROL_PSPOLL]++;
  2624. break;
  2625. case cpu_to_le16(IEEE80211_STYPE_RTS):
  2626. stats->ctrl[CONTROL_RTS]++;
  2627. break;
  2628. case cpu_to_le16(IEEE80211_STYPE_CTS):
  2629. stats->ctrl[CONTROL_CTS]++;
  2630. break;
  2631. case cpu_to_le16(IEEE80211_STYPE_ACK):
  2632. stats->ctrl[CONTROL_ACK]++;
  2633. break;
  2634. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  2635. stats->ctrl[CONTROL_CFEND]++;
  2636. break;
  2637. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  2638. stats->ctrl[CONTROL_CFENDACK]++;
  2639. break;
  2640. }
  2641. } else {
  2642. /* data */
  2643. stats->data_cnt++;
  2644. stats->data_bytes += len;
  2645. }
  2646. }
  2647. EXPORT_SYMBOL(iwl_update_stats);
  2648. #endif
  2649. #ifdef CONFIG_PM
  2650. int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  2651. {
  2652. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2653. /*
  2654. * This function is called when system goes into suspend state
  2655. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2656. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2657. * it will not call apm_ops.stop() to stop the DMA operation.
  2658. * Calling apm_ops.stop here to make sure we stop the DMA.
  2659. */
  2660. priv->cfg->ops->lib->apm_ops.stop(priv);
  2661. pci_save_state(pdev);
  2662. pci_disable_device(pdev);
  2663. pci_set_power_state(pdev, PCI_D3hot);
  2664. return 0;
  2665. }
  2666. EXPORT_SYMBOL(iwl_pci_suspend);
  2667. int iwl_pci_resume(struct pci_dev *pdev)
  2668. {
  2669. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2670. int ret;
  2671. pci_set_power_state(pdev, PCI_D0);
  2672. ret = pci_enable_device(pdev);
  2673. if (ret)
  2674. return ret;
  2675. pci_restore_state(pdev);
  2676. iwl_enable_interrupts(priv);
  2677. return 0;
  2678. }
  2679. EXPORT_SYMBOL(iwl_pci_resume);
  2680. #endif /* CONFIG_PM */