iwl-core.c 78 KB

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