iwl-core.c 83 KB

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