iwl-core.c 84 KB

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