iwl-core.c 90 KB

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