iwl-core.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983
  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. int 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. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1274. sizeof(struct iwl_bt_cmd), &bt_cmd);
  1275. }
  1276. EXPORT_SYMBOL(iwl_send_bt_config);
  1277. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1278. {
  1279. struct iwl_statistics_cmd statistics_cmd = {
  1280. .configuration_flags =
  1281. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1282. };
  1283. if (flags & CMD_ASYNC)
  1284. return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1285. sizeof(struct iwl_statistics_cmd),
  1286. &statistics_cmd, NULL);
  1287. else
  1288. return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1289. sizeof(struct iwl_statistics_cmd),
  1290. &statistics_cmd);
  1291. }
  1292. EXPORT_SYMBOL(iwl_send_statistics_request);
  1293. /**
  1294. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  1295. * using sample data 100 bytes apart. If these sample points are good,
  1296. * it's a pretty good bet that everything between them is good, too.
  1297. */
  1298. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  1299. {
  1300. u32 val;
  1301. int ret = 0;
  1302. u32 errcnt = 0;
  1303. u32 i;
  1304. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1305. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  1306. /* read data comes through single port, auto-incr addr */
  1307. /* NOTE: Use the debugless read so we don't flood kernel log
  1308. * if IWL_DL_IO is set */
  1309. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1310. i + IWL49_RTC_INST_LOWER_BOUND);
  1311. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1312. if (val != le32_to_cpu(*image)) {
  1313. ret = -EIO;
  1314. errcnt++;
  1315. if (errcnt >= 3)
  1316. break;
  1317. }
  1318. }
  1319. return ret;
  1320. }
  1321. /**
  1322. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  1323. * looking at all data.
  1324. */
  1325. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  1326. u32 len)
  1327. {
  1328. u32 val;
  1329. u32 save_len = len;
  1330. int ret = 0;
  1331. u32 errcnt;
  1332. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1333. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1334. IWL49_RTC_INST_LOWER_BOUND);
  1335. errcnt = 0;
  1336. for (; len > 0; len -= sizeof(u32), image++) {
  1337. /* read data comes through single port, auto-incr addr */
  1338. /* NOTE: Use the debugless read so we don't flood kernel log
  1339. * if IWL_DL_IO is set */
  1340. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1341. if (val != le32_to_cpu(*image)) {
  1342. IWL_ERR(priv, "uCode INST section is invalid at "
  1343. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1344. save_len - len, val, le32_to_cpu(*image));
  1345. ret = -EIO;
  1346. errcnt++;
  1347. if (errcnt >= 20)
  1348. break;
  1349. }
  1350. }
  1351. if (!errcnt)
  1352. IWL_DEBUG_INFO(priv,
  1353. "ucode image in INSTRUCTION memory is good\n");
  1354. return ret;
  1355. }
  1356. /**
  1357. * iwl_verify_ucode - determine which instruction image is in SRAM,
  1358. * and verify its contents
  1359. */
  1360. int iwl_verify_ucode(struct iwl_priv *priv)
  1361. {
  1362. __le32 *image;
  1363. u32 len;
  1364. int ret;
  1365. /* Try bootstrap */
  1366. image = (__le32 *)priv->ucode_boot.v_addr;
  1367. len = priv->ucode_boot.len;
  1368. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1369. if (!ret) {
  1370. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  1371. return 0;
  1372. }
  1373. /* Try initialize */
  1374. image = (__le32 *)priv->ucode_init.v_addr;
  1375. len = priv->ucode_init.len;
  1376. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1377. if (!ret) {
  1378. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  1379. return 0;
  1380. }
  1381. /* Try runtime/protocol */
  1382. image = (__le32 *)priv->ucode_code.v_addr;
  1383. len = priv->ucode_code.len;
  1384. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1385. if (!ret) {
  1386. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  1387. return 0;
  1388. }
  1389. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  1390. /* Since nothing seems to match, show first several data entries in
  1391. * instruction SRAM, so maybe visual inspection will give a clue.
  1392. * Selection of bootstrap image (vs. other images) is arbitrary. */
  1393. image = (__le32 *)priv->ucode_boot.v_addr;
  1394. len = priv->ucode_boot.len;
  1395. ret = iwl_verify_inst_full(priv, image, len);
  1396. return ret;
  1397. }
  1398. EXPORT_SYMBOL(iwl_verify_ucode);
  1399. void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1400. {
  1401. struct iwl_ct_kill_config cmd;
  1402. struct iwl_ct_kill_throttling_config adv_cmd;
  1403. unsigned long flags;
  1404. int ret = 0;
  1405. spin_lock_irqsave(&priv->lock, flags);
  1406. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1407. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1408. spin_unlock_irqrestore(&priv->lock, flags);
  1409. priv->thermal_throttle.ct_kill_toggle = false;
  1410. if (priv->cfg->support_ct_kill_exit) {
  1411. adv_cmd.critical_temperature_enter =
  1412. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1413. adv_cmd.critical_temperature_exit =
  1414. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  1415. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1416. sizeof(adv_cmd), &adv_cmd);
  1417. if (ret)
  1418. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1419. else
  1420. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1421. "succeeded, "
  1422. "critical temperature enter is %d,"
  1423. "exit is %d\n",
  1424. priv->hw_params.ct_kill_threshold,
  1425. priv->hw_params.ct_kill_exit_threshold);
  1426. } else {
  1427. cmd.critical_temperature_R =
  1428. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1429. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1430. sizeof(cmd), &cmd);
  1431. if (ret)
  1432. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1433. else
  1434. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1435. "succeeded, "
  1436. "critical temperature is %d\n",
  1437. priv->hw_params.ct_kill_threshold);
  1438. }
  1439. }
  1440. EXPORT_SYMBOL(iwl_rf_kill_ct_config);
  1441. /*
  1442. * CARD_STATE_CMD
  1443. *
  1444. * Use: Sets the device's internal card state to enable, disable, or halt
  1445. *
  1446. * When in the 'enable' state the card operates as normal.
  1447. * When in the 'disable' state, the card enters into a low power mode.
  1448. * When in the 'halt' state, the card is shut down and must be fully
  1449. * restarted to come back on.
  1450. */
  1451. int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  1452. {
  1453. struct iwl_host_cmd cmd = {
  1454. .id = REPLY_CARD_STATE_CMD,
  1455. .len = sizeof(u32),
  1456. .data = &flags,
  1457. .flags = meta_flag,
  1458. };
  1459. return iwl_send_cmd(priv, &cmd);
  1460. }
  1461. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1462. struct iwl_rx_mem_buffer *rxb)
  1463. {
  1464. #ifdef CONFIG_IWLWIFI_DEBUG
  1465. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1466. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1467. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1468. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1469. #endif
  1470. }
  1471. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1472. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1473. struct iwl_rx_mem_buffer *rxb)
  1474. {
  1475. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1476. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1477. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1478. "notification for %s:\n", len,
  1479. get_cmd_string(pkt->hdr.cmd));
  1480. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1481. }
  1482. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1483. void iwl_rx_reply_error(struct iwl_priv *priv,
  1484. struct iwl_rx_mem_buffer *rxb)
  1485. {
  1486. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1487. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1488. "seq 0x%04X ser 0x%08X\n",
  1489. le32_to_cpu(pkt->u.err_resp.error_type),
  1490. get_cmd_string(pkt->u.err_resp.cmd_id),
  1491. pkt->u.err_resp.cmd_id,
  1492. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1493. le32_to_cpu(pkt->u.err_resp.error_info));
  1494. }
  1495. EXPORT_SYMBOL(iwl_rx_reply_error);
  1496. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1497. {
  1498. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1499. }
  1500. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1501. const struct ieee80211_tx_queue_params *params)
  1502. {
  1503. struct iwl_priv *priv = hw->priv;
  1504. unsigned long flags;
  1505. int q;
  1506. IWL_DEBUG_MAC80211(priv, "enter\n");
  1507. if (!iwl_is_ready_rf(priv)) {
  1508. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1509. return -EIO;
  1510. }
  1511. if (queue >= AC_NUM) {
  1512. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1513. return 0;
  1514. }
  1515. q = AC_NUM - 1 - queue;
  1516. spin_lock_irqsave(&priv->lock, flags);
  1517. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  1518. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  1519. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1520. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  1521. cpu_to_le16((params->txop * 32));
  1522. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1523. spin_unlock_irqrestore(&priv->lock, flags);
  1524. IWL_DEBUG_MAC80211(priv, "leave\n");
  1525. return 0;
  1526. }
  1527. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1528. static void iwl_ht_conf(struct iwl_priv *priv,
  1529. struct ieee80211_bss_conf *bss_conf)
  1530. {
  1531. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1532. struct ieee80211_sta *sta;
  1533. IWL_DEBUG_MAC80211(priv, "enter:\n");
  1534. if (!ht_conf->is_ht)
  1535. return;
  1536. ht_conf->ht_protection =
  1537. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  1538. ht_conf->non_GF_STA_present =
  1539. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1540. ht_conf->single_chain_sufficient = false;
  1541. switch (priv->iw_mode) {
  1542. case NL80211_IFTYPE_STATION:
  1543. rcu_read_lock();
  1544. sta = ieee80211_find_sta(priv->vif, priv->bssid);
  1545. if (sta) {
  1546. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1547. int maxstreams;
  1548. maxstreams = (ht_cap->mcs.tx_params &
  1549. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1550. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1551. maxstreams += 1;
  1552. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  1553. (ht_cap->mcs.rx_mask[2] == 0))
  1554. ht_conf->single_chain_sufficient = true;
  1555. if (maxstreams <= 1)
  1556. ht_conf->single_chain_sufficient = true;
  1557. } else {
  1558. /*
  1559. * If at all, this can only happen through a race
  1560. * when the AP disconnects us while we're still
  1561. * setting up the connection, in that case mac80211
  1562. * will soon tell us about that.
  1563. */
  1564. ht_conf->single_chain_sufficient = true;
  1565. }
  1566. rcu_read_unlock();
  1567. break;
  1568. case NL80211_IFTYPE_ADHOC:
  1569. ht_conf->single_chain_sufficient = true;
  1570. break;
  1571. default:
  1572. break;
  1573. }
  1574. IWL_DEBUG_MAC80211(priv, "leave\n");
  1575. }
  1576. static inline void iwl_set_no_assoc(struct iwl_priv *priv)
  1577. {
  1578. priv->assoc_id = 0;
  1579. iwl_led_disassociate(priv);
  1580. /*
  1581. * inform the ucode that there is no longer an
  1582. * association and that no more packets should be
  1583. * sent
  1584. */
  1585. priv->staging_rxon.filter_flags &=
  1586. ~RXON_FILTER_ASSOC_MSK;
  1587. priv->staging_rxon.assoc_id = 0;
  1588. iwlcore_commit_rxon(priv);
  1589. }
  1590. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  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. /*
  1692. * We have just associated, don't start scan too early
  1693. * leave time for EAPOL exchange to complete.
  1694. *
  1695. * XXX: do this in mac80211
  1696. */
  1697. priv->next_scan_jiffies = jiffies +
  1698. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  1699. if (!iwl_is_rfkill(priv))
  1700. priv->cfg->ops->lib->post_associate(priv);
  1701. } else
  1702. iwl_set_no_assoc(priv);
  1703. }
  1704. if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  1705. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  1706. changes);
  1707. ret = iwl_send_rxon_assoc(priv);
  1708. if (!ret) {
  1709. /* Sync active_rxon with latest change. */
  1710. memcpy((void *)&priv->active_rxon,
  1711. &priv->staging_rxon,
  1712. sizeof(struct iwl_rxon_cmd));
  1713. }
  1714. }
  1715. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1716. if (vif->bss_conf.enable_beacon) {
  1717. memcpy(priv->staging_rxon.bssid_addr,
  1718. bss_conf->bssid, ETH_ALEN);
  1719. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1720. iwlcore_config_ap(priv);
  1721. } else
  1722. iwl_set_no_assoc(priv);
  1723. }
  1724. mutex_unlock(&priv->mutex);
  1725. IWL_DEBUG_MAC80211(priv, "leave\n");
  1726. }
  1727. EXPORT_SYMBOL(iwl_bss_info_changed);
  1728. int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  1729. {
  1730. struct iwl_priv *priv = hw->priv;
  1731. unsigned long flags;
  1732. __le64 timestamp;
  1733. IWL_DEBUG_MAC80211(priv, "enter\n");
  1734. if (!iwl_is_ready_rf(priv)) {
  1735. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1736. return -EIO;
  1737. }
  1738. spin_lock_irqsave(&priv->lock, flags);
  1739. if (priv->ibss_beacon)
  1740. dev_kfree_skb(priv->ibss_beacon);
  1741. priv->ibss_beacon = skb;
  1742. priv->assoc_id = 0;
  1743. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  1744. priv->timestamp = le64_to_cpu(timestamp);
  1745. IWL_DEBUG_MAC80211(priv, "leave\n");
  1746. spin_unlock_irqrestore(&priv->lock, flags);
  1747. priv->cfg->ops->lib->post_associate(priv);
  1748. return 0;
  1749. }
  1750. EXPORT_SYMBOL(iwl_mac_beacon_update);
  1751. static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
  1752. {
  1753. iwl_connection_init_rx_config(priv, vif->type);
  1754. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1755. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1756. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1757. return iwlcore_commit_rxon(priv);
  1758. }
  1759. int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1760. {
  1761. struct iwl_priv *priv = hw->priv;
  1762. int err = 0;
  1763. IWL_DEBUG_MAC80211(priv, "enter: type %d\n", vif->type);
  1764. mutex_lock(&priv->mutex);
  1765. if (WARN_ON(!iwl_is_ready_rf(priv))) {
  1766. err = -EINVAL;
  1767. goto out;
  1768. }
  1769. if (priv->vif) {
  1770. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  1771. err = -EOPNOTSUPP;
  1772. goto out;
  1773. }
  1774. priv->vif = vif;
  1775. priv->iw_mode = vif->type;
  1776. IWL_DEBUG_MAC80211(priv, "Set %pM\n", vif->addr);
  1777. memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
  1778. err = iwl_set_mode(priv, vif);
  1779. if (err)
  1780. goto out_err;
  1781. /* Add the broadcast address so we can send broadcast frames */
  1782. priv->cfg->ops->lib->add_bcast_station(priv);
  1783. goto out;
  1784. out_err:
  1785. priv->vif = NULL;
  1786. priv->iw_mode = NL80211_IFTYPE_STATION;
  1787. out:
  1788. mutex_unlock(&priv->mutex);
  1789. IWL_DEBUG_MAC80211(priv, "leave\n");
  1790. return err;
  1791. }
  1792. EXPORT_SYMBOL(iwl_mac_add_interface);
  1793. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  1794. struct ieee80211_vif *vif)
  1795. {
  1796. struct iwl_priv *priv = hw->priv;
  1797. IWL_DEBUG_MAC80211(priv, "enter\n");
  1798. mutex_lock(&priv->mutex);
  1799. iwl_clear_ucode_stations(priv, true);
  1800. if (iwl_is_ready_rf(priv)) {
  1801. iwl_scan_cancel_timeout(priv, 100);
  1802. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1803. iwlcore_commit_rxon(priv);
  1804. }
  1805. if (priv->vif == vif) {
  1806. priv->vif = NULL;
  1807. memset(priv->bssid, 0, ETH_ALEN);
  1808. }
  1809. mutex_unlock(&priv->mutex);
  1810. IWL_DEBUG_MAC80211(priv, "leave\n");
  1811. }
  1812. EXPORT_SYMBOL(iwl_mac_remove_interface);
  1813. /**
  1814. * iwl_mac_config - mac80211 config callback
  1815. *
  1816. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  1817. * be set inappropriately and the driver currently sets the hardware up to
  1818. * use it whenever needed.
  1819. */
  1820. int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
  1821. {
  1822. struct iwl_priv *priv = hw->priv;
  1823. const struct iwl_channel_info *ch_info;
  1824. struct ieee80211_conf *conf = &hw->conf;
  1825. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1826. unsigned long flags = 0;
  1827. int ret = 0;
  1828. u16 ch;
  1829. int scan_active = 0;
  1830. mutex_lock(&priv->mutex);
  1831. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  1832. conf->channel->hw_value, changed);
  1833. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  1834. test_bit(STATUS_SCANNING, &priv->status))) {
  1835. scan_active = 1;
  1836. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  1837. }
  1838. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  1839. IEEE80211_CONF_CHANGE_CHANNEL)) {
  1840. /* mac80211 uses static for non-HT which is what we want */
  1841. priv->current_ht_config.smps = conf->smps_mode;
  1842. /*
  1843. * Recalculate chain counts.
  1844. *
  1845. * If monitor mode is enabled then mac80211 will
  1846. * set up the SM PS mode to OFF if an HT channel is
  1847. * configured.
  1848. */
  1849. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1850. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1851. }
  1852. /* during scanning mac80211 will delay channel setting until
  1853. * scan finish with changed = 0
  1854. */
  1855. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1856. if (scan_active)
  1857. goto set_ch_out;
  1858. ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
  1859. ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
  1860. if (!is_channel_valid(ch_info)) {
  1861. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  1862. ret = -EINVAL;
  1863. goto set_ch_out;
  1864. }
  1865. spin_lock_irqsave(&priv->lock, flags);
  1866. /* Configure HT40 channels */
  1867. ht_conf->is_ht = conf_is_ht(conf);
  1868. if (ht_conf->is_ht) {
  1869. if (conf_is_ht40_minus(conf)) {
  1870. ht_conf->extension_chan_offset =
  1871. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1872. ht_conf->is_40mhz = true;
  1873. } else if (conf_is_ht40_plus(conf)) {
  1874. ht_conf->extension_chan_offset =
  1875. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1876. ht_conf->is_40mhz = true;
  1877. } else {
  1878. ht_conf->extension_chan_offset =
  1879. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1880. ht_conf->is_40mhz = false;
  1881. }
  1882. } else
  1883. ht_conf->is_40mhz = false;
  1884. /* Default to no protection. Protection mode will later be set
  1885. * from BSS config in iwl_ht_conf */
  1886. ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  1887. /* if we are switching from ht to 2.4 clear flags
  1888. * from any ht related info since 2.4 does not
  1889. * support ht */
  1890. if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
  1891. priv->staging_rxon.flags = 0;
  1892. iwl_set_rxon_channel(priv, conf->channel);
  1893. iwl_set_rxon_ht(priv, ht_conf);
  1894. iwl_set_flags_for_band(priv, conf->channel->band);
  1895. spin_unlock_irqrestore(&priv->lock, flags);
  1896. if (iwl_is_associated(priv) &&
  1897. (le16_to_cpu(priv->active_rxon.channel) != ch) &&
  1898. priv->cfg->ops->lib->set_channel_switch) {
  1899. iwl_set_rate(priv);
  1900. /*
  1901. * at this point, staging_rxon has the
  1902. * configuration for channel switch
  1903. */
  1904. ret = priv->cfg->ops->lib->set_channel_switch(priv,
  1905. ch);
  1906. if (!ret) {
  1907. iwl_print_rx_config_cmd(priv);
  1908. goto out;
  1909. }
  1910. priv->switch_rxon.switch_in_progress = false;
  1911. }
  1912. set_ch_out:
  1913. /* The list of supported rates and rate mask can be different
  1914. * for each band; since the band may have changed, reset
  1915. * the rate mask to what mac80211 lists */
  1916. iwl_set_rate(priv);
  1917. }
  1918. if (changed & (IEEE80211_CONF_CHANGE_PS |
  1919. IEEE80211_CONF_CHANGE_IDLE)) {
  1920. ret = iwl_power_update_mode(priv, false);
  1921. if (ret)
  1922. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  1923. }
  1924. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1925. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  1926. priv->tx_power_user_lmt, conf->power_level);
  1927. iwl_set_tx_power(priv, conf->power_level, false);
  1928. }
  1929. if (changed & IEEE80211_CONF_CHANGE_QOS) {
  1930. bool qos_active = !!(conf->flags & IEEE80211_CONF_QOS);
  1931. spin_lock_irqsave(&priv->lock, flags);
  1932. priv->qos_data.qos_active = qos_active;
  1933. iwl_update_qos(priv);
  1934. spin_unlock_irqrestore(&priv->lock, flags);
  1935. }
  1936. if (!iwl_is_ready(priv)) {
  1937. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1938. goto out;
  1939. }
  1940. if (scan_active)
  1941. goto out;
  1942. if (memcmp(&priv->active_rxon,
  1943. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  1944. iwlcore_commit_rxon(priv);
  1945. else
  1946. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
  1947. out:
  1948. IWL_DEBUG_MAC80211(priv, "leave\n");
  1949. mutex_unlock(&priv->mutex);
  1950. return ret;
  1951. }
  1952. EXPORT_SYMBOL(iwl_mac_config);
  1953. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  1954. {
  1955. struct iwl_priv *priv = hw->priv;
  1956. unsigned long flags;
  1957. mutex_lock(&priv->mutex);
  1958. IWL_DEBUG_MAC80211(priv, "enter\n");
  1959. spin_lock_irqsave(&priv->lock, flags);
  1960. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
  1961. spin_unlock_irqrestore(&priv->lock, flags);
  1962. spin_lock_irqsave(&priv->lock, flags);
  1963. priv->assoc_id = 0;
  1964. priv->assoc_capability = 0;
  1965. /* new association get rid of ibss beacon skb */
  1966. if (priv->ibss_beacon)
  1967. dev_kfree_skb(priv->ibss_beacon);
  1968. priv->ibss_beacon = NULL;
  1969. priv->beacon_int = priv->vif->bss_conf.beacon_int;
  1970. priv->timestamp = 0;
  1971. spin_unlock_irqrestore(&priv->lock, flags);
  1972. if (!iwl_is_ready_rf(priv)) {
  1973. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1974. mutex_unlock(&priv->mutex);
  1975. return;
  1976. }
  1977. /* we are restarting association process
  1978. * clear RXON_FILTER_ASSOC_MSK bit
  1979. */
  1980. iwl_scan_cancel_timeout(priv, 100);
  1981. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1982. iwlcore_commit_rxon(priv);
  1983. iwl_set_rate(priv);
  1984. mutex_unlock(&priv->mutex);
  1985. IWL_DEBUG_MAC80211(priv, "leave\n");
  1986. }
  1987. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  1988. int iwl_alloc_txq_mem(struct iwl_priv *priv)
  1989. {
  1990. if (!priv->txq)
  1991. priv->txq = kzalloc(
  1992. sizeof(struct iwl_tx_queue) * priv->cfg->num_of_queues,
  1993. GFP_KERNEL);
  1994. if (!priv->txq) {
  1995. IWL_ERR(priv, "Not enough memory for txq\n");
  1996. return -ENOMEM;
  1997. }
  1998. return 0;
  1999. }
  2000. EXPORT_SYMBOL(iwl_alloc_txq_mem);
  2001. void iwl_free_txq_mem(struct iwl_priv *priv)
  2002. {
  2003. kfree(priv->txq);
  2004. priv->txq = NULL;
  2005. }
  2006. EXPORT_SYMBOL(iwl_free_txq_mem);
  2007. int iwl_send_wimax_coex(struct iwl_priv *priv)
  2008. {
  2009. struct iwl_wimax_coex_cmd coex_cmd;
  2010. if (priv->cfg->support_wimax_coexist) {
  2011. /* UnMask wake up src at associated sleep */
  2012. coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
  2013. /* UnMask wake up src at unassociated sleep */
  2014. coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
  2015. memcpy(coex_cmd.sta_prio, cu_priorities,
  2016. sizeof(struct iwl_wimax_coex_event_entry) *
  2017. COEX_NUM_OF_EVENTS);
  2018. /* enabling the coexistence feature */
  2019. coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
  2020. /* enabling the priorities tables */
  2021. coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
  2022. } else {
  2023. /* coexistence is disabled */
  2024. memset(&coex_cmd, 0, sizeof(coex_cmd));
  2025. }
  2026. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  2027. sizeof(coex_cmd), &coex_cmd);
  2028. }
  2029. EXPORT_SYMBOL(iwl_send_wimax_coex);
  2030. #ifdef CONFIG_IWLWIFI_DEBUGFS
  2031. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  2032. void iwl_reset_traffic_log(struct iwl_priv *priv)
  2033. {
  2034. priv->tx_traffic_idx = 0;
  2035. priv->rx_traffic_idx = 0;
  2036. if (priv->tx_traffic)
  2037. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  2038. if (priv->rx_traffic)
  2039. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  2040. }
  2041. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  2042. {
  2043. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  2044. if (iwl_debug_level & IWL_DL_TX) {
  2045. if (!priv->tx_traffic) {
  2046. priv->tx_traffic =
  2047. kzalloc(traffic_size, GFP_KERNEL);
  2048. if (!priv->tx_traffic)
  2049. return -ENOMEM;
  2050. }
  2051. }
  2052. if (iwl_debug_level & IWL_DL_RX) {
  2053. if (!priv->rx_traffic) {
  2054. priv->rx_traffic =
  2055. kzalloc(traffic_size, GFP_KERNEL);
  2056. if (!priv->rx_traffic)
  2057. return -ENOMEM;
  2058. }
  2059. }
  2060. iwl_reset_traffic_log(priv);
  2061. return 0;
  2062. }
  2063. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  2064. void iwl_free_traffic_mem(struct iwl_priv *priv)
  2065. {
  2066. kfree(priv->tx_traffic);
  2067. priv->tx_traffic = NULL;
  2068. kfree(priv->rx_traffic);
  2069. priv->rx_traffic = NULL;
  2070. }
  2071. EXPORT_SYMBOL(iwl_free_traffic_mem);
  2072. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  2073. u16 length, struct ieee80211_hdr *header)
  2074. {
  2075. __le16 fc;
  2076. u16 len;
  2077. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  2078. return;
  2079. if (!priv->tx_traffic)
  2080. return;
  2081. fc = header->frame_control;
  2082. if (ieee80211_is_data(fc)) {
  2083. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  2084. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  2085. memcpy((priv->tx_traffic +
  2086. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  2087. header, len);
  2088. priv->tx_traffic_idx =
  2089. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  2090. }
  2091. }
  2092. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  2093. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  2094. u16 length, struct ieee80211_hdr *header)
  2095. {
  2096. __le16 fc;
  2097. u16 len;
  2098. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  2099. return;
  2100. if (!priv->rx_traffic)
  2101. return;
  2102. fc = header->frame_control;
  2103. if (ieee80211_is_data(fc)) {
  2104. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  2105. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  2106. memcpy((priv->rx_traffic +
  2107. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  2108. header, len);
  2109. priv->rx_traffic_idx =
  2110. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  2111. }
  2112. }
  2113. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  2114. const char *get_mgmt_string(int cmd)
  2115. {
  2116. switch (cmd) {
  2117. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  2118. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  2119. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  2120. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  2121. IWL_CMD(MANAGEMENT_PROBE_REQ);
  2122. IWL_CMD(MANAGEMENT_PROBE_RESP);
  2123. IWL_CMD(MANAGEMENT_BEACON);
  2124. IWL_CMD(MANAGEMENT_ATIM);
  2125. IWL_CMD(MANAGEMENT_DISASSOC);
  2126. IWL_CMD(MANAGEMENT_AUTH);
  2127. IWL_CMD(MANAGEMENT_DEAUTH);
  2128. IWL_CMD(MANAGEMENT_ACTION);
  2129. default:
  2130. return "UNKNOWN";
  2131. }
  2132. }
  2133. const char *get_ctrl_string(int cmd)
  2134. {
  2135. switch (cmd) {
  2136. IWL_CMD(CONTROL_BACK_REQ);
  2137. IWL_CMD(CONTROL_BACK);
  2138. IWL_CMD(CONTROL_PSPOLL);
  2139. IWL_CMD(CONTROL_RTS);
  2140. IWL_CMD(CONTROL_CTS);
  2141. IWL_CMD(CONTROL_ACK);
  2142. IWL_CMD(CONTROL_CFEND);
  2143. IWL_CMD(CONTROL_CFENDACK);
  2144. default:
  2145. return "UNKNOWN";
  2146. }
  2147. }
  2148. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  2149. {
  2150. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  2151. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  2152. priv->led_tpt = 0;
  2153. }
  2154. /*
  2155. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  2156. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  2157. * Use debugFs to display the rx/rx_statistics
  2158. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  2159. * information will be recorded, but DATA pkt still will be recorded
  2160. * for the reason of iwl_led.c need to control the led blinking based on
  2161. * number of tx and rx data.
  2162. *
  2163. */
  2164. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  2165. {
  2166. struct traffic_stats *stats;
  2167. if (is_tx)
  2168. stats = &priv->tx_stats;
  2169. else
  2170. stats = &priv->rx_stats;
  2171. if (ieee80211_is_mgmt(fc)) {
  2172. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2173. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  2174. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  2175. break;
  2176. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2177. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  2178. break;
  2179. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  2180. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  2181. break;
  2182. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2183. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  2184. break;
  2185. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2186. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  2187. break;
  2188. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2189. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  2190. break;
  2191. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2192. stats->mgmt[MANAGEMENT_BEACON]++;
  2193. break;
  2194. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  2195. stats->mgmt[MANAGEMENT_ATIM]++;
  2196. break;
  2197. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2198. stats->mgmt[MANAGEMENT_DISASSOC]++;
  2199. break;
  2200. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2201. stats->mgmt[MANAGEMENT_AUTH]++;
  2202. break;
  2203. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2204. stats->mgmt[MANAGEMENT_DEAUTH]++;
  2205. break;
  2206. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  2207. stats->mgmt[MANAGEMENT_ACTION]++;
  2208. break;
  2209. }
  2210. } else if (ieee80211_is_ctl(fc)) {
  2211. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2212. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  2213. stats->ctrl[CONTROL_BACK_REQ]++;
  2214. break;
  2215. case cpu_to_le16(IEEE80211_STYPE_BACK):
  2216. stats->ctrl[CONTROL_BACK]++;
  2217. break;
  2218. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  2219. stats->ctrl[CONTROL_PSPOLL]++;
  2220. break;
  2221. case cpu_to_le16(IEEE80211_STYPE_RTS):
  2222. stats->ctrl[CONTROL_RTS]++;
  2223. break;
  2224. case cpu_to_le16(IEEE80211_STYPE_CTS):
  2225. stats->ctrl[CONTROL_CTS]++;
  2226. break;
  2227. case cpu_to_le16(IEEE80211_STYPE_ACK):
  2228. stats->ctrl[CONTROL_ACK]++;
  2229. break;
  2230. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  2231. stats->ctrl[CONTROL_CFEND]++;
  2232. break;
  2233. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  2234. stats->ctrl[CONTROL_CFENDACK]++;
  2235. break;
  2236. }
  2237. } else {
  2238. /* data */
  2239. stats->data_cnt++;
  2240. stats->data_bytes += len;
  2241. }
  2242. iwl_leds_background(priv);
  2243. }
  2244. EXPORT_SYMBOL(iwl_update_stats);
  2245. #endif
  2246. const static char *get_csr_string(int cmd)
  2247. {
  2248. switch (cmd) {
  2249. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  2250. IWL_CMD(CSR_INT_COALESCING);
  2251. IWL_CMD(CSR_INT);
  2252. IWL_CMD(CSR_INT_MASK);
  2253. IWL_CMD(CSR_FH_INT_STATUS);
  2254. IWL_CMD(CSR_GPIO_IN);
  2255. IWL_CMD(CSR_RESET);
  2256. IWL_CMD(CSR_GP_CNTRL);
  2257. IWL_CMD(CSR_HW_REV);
  2258. IWL_CMD(CSR_EEPROM_REG);
  2259. IWL_CMD(CSR_EEPROM_GP);
  2260. IWL_CMD(CSR_OTP_GP_REG);
  2261. IWL_CMD(CSR_GIO_REG);
  2262. IWL_CMD(CSR_GP_UCODE_REG);
  2263. IWL_CMD(CSR_GP_DRIVER_REG);
  2264. IWL_CMD(CSR_UCODE_DRV_GP1);
  2265. IWL_CMD(CSR_UCODE_DRV_GP2);
  2266. IWL_CMD(CSR_LED_REG);
  2267. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  2268. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  2269. IWL_CMD(CSR_ANA_PLL_CFG);
  2270. IWL_CMD(CSR_HW_REV_WA_REG);
  2271. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  2272. default:
  2273. return "UNKNOWN";
  2274. }
  2275. }
  2276. void iwl_dump_csr(struct iwl_priv *priv)
  2277. {
  2278. int i;
  2279. u32 csr_tbl[] = {
  2280. CSR_HW_IF_CONFIG_REG,
  2281. CSR_INT_COALESCING,
  2282. CSR_INT,
  2283. CSR_INT_MASK,
  2284. CSR_FH_INT_STATUS,
  2285. CSR_GPIO_IN,
  2286. CSR_RESET,
  2287. CSR_GP_CNTRL,
  2288. CSR_HW_REV,
  2289. CSR_EEPROM_REG,
  2290. CSR_EEPROM_GP,
  2291. CSR_OTP_GP_REG,
  2292. CSR_GIO_REG,
  2293. CSR_GP_UCODE_REG,
  2294. CSR_GP_DRIVER_REG,
  2295. CSR_UCODE_DRV_GP1,
  2296. CSR_UCODE_DRV_GP2,
  2297. CSR_LED_REG,
  2298. CSR_DRAM_INT_TBL_REG,
  2299. CSR_GIO_CHICKEN_BITS,
  2300. CSR_ANA_PLL_CFG,
  2301. CSR_HW_REV_WA_REG,
  2302. CSR_DBG_HPET_MEM_REG
  2303. };
  2304. IWL_ERR(priv, "CSR values:\n");
  2305. IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
  2306. "CSR_INT_PERIODIC_REG)\n");
  2307. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  2308. IWL_ERR(priv, " %25s: 0X%08x\n",
  2309. get_csr_string(csr_tbl[i]),
  2310. iwl_read32(priv, csr_tbl[i]));
  2311. }
  2312. }
  2313. EXPORT_SYMBOL(iwl_dump_csr);
  2314. const static char *get_fh_string(int cmd)
  2315. {
  2316. switch (cmd) {
  2317. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  2318. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  2319. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  2320. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  2321. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  2322. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  2323. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  2324. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  2325. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  2326. default:
  2327. return "UNKNOWN";
  2328. }
  2329. }
  2330. int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
  2331. {
  2332. int i;
  2333. #ifdef CONFIG_IWLWIFI_DEBUG
  2334. int pos = 0;
  2335. size_t bufsz = 0;
  2336. #endif
  2337. u32 fh_tbl[] = {
  2338. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  2339. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  2340. FH_RSCSR_CHNL0_WPTR,
  2341. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  2342. FH_MEM_RSSR_SHARED_CTRL_REG,
  2343. FH_MEM_RSSR_RX_STATUS_REG,
  2344. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  2345. FH_TSSR_TX_STATUS_REG,
  2346. FH_TSSR_TX_ERROR_REG
  2347. };
  2348. #ifdef CONFIG_IWLWIFI_DEBUG
  2349. if (display) {
  2350. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  2351. *buf = kmalloc(bufsz, GFP_KERNEL);
  2352. if (!*buf)
  2353. return -ENOMEM;
  2354. pos += scnprintf(*buf + pos, bufsz - pos,
  2355. "FH register values:\n");
  2356. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2357. pos += scnprintf(*buf + pos, bufsz - pos,
  2358. " %34s: 0X%08x\n",
  2359. get_fh_string(fh_tbl[i]),
  2360. iwl_read_direct32(priv, fh_tbl[i]));
  2361. }
  2362. return pos;
  2363. }
  2364. #endif
  2365. IWL_ERR(priv, "FH register values:\n");
  2366. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2367. IWL_ERR(priv, " %34s: 0X%08x\n",
  2368. get_fh_string(fh_tbl[i]),
  2369. iwl_read_direct32(priv, fh_tbl[i]));
  2370. }
  2371. return 0;
  2372. }
  2373. EXPORT_SYMBOL(iwl_dump_fh);
  2374. static void iwl_force_rf_reset(struct iwl_priv *priv)
  2375. {
  2376. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2377. return;
  2378. if (!iwl_is_associated(priv)) {
  2379. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  2380. return;
  2381. }
  2382. /*
  2383. * There is no easy and better way to force reset the radio,
  2384. * the only known method is switching channel which will force to
  2385. * reset and tune the radio.
  2386. * Use internal short scan (single channel) operation to should
  2387. * achieve this objective.
  2388. * Driver should reset the radio when number of consecutive missed
  2389. * beacon, or any other uCode error condition detected.
  2390. */
  2391. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  2392. iwl_internal_short_hw_scan(priv);
  2393. return;
  2394. }
  2395. int iwl_force_reset(struct iwl_priv *priv, int mode)
  2396. {
  2397. struct iwl_force_reset *force_reset;
  2398. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2399. return -EINVAL;
  2400. if (mode >= IWL_MAX_FORCE_RESET) {
  2401. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  2402. return -EINVAL;
  2403. }
  2404. force_reset = &priv->force_reset[mode];
  2405. force_reset->reset_request_count++;
  2406. if (force_reset->last_force_reset_jiffies &&
  2407. time_after(force_reset->last_force_reset_jiffies +
  2408. force_reset->reset_duration, jiffies)) {
  2409. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  2410. force_reset->reset_reject_count++;
  2411. return -EAGAIN;
  2412. }
  2413. force_reset->reset_success_count++;
  2414. force_reset->last_force_reset_jiffies = jiffies;
  2415. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  2416. switch (mode) {
  2417. case IWL_RF_RESET:
  2418. iwl_force_rf_reset(priv);
  2419. break;
  2420. case IWL_FW_RESET:
  2421. IWL_ERR(priv, "On demand firmware reload\n");
  2422. /* Set the FW error flag -- cleared on iwl_down */
  2423. set_bit(STATUS_FW_ERROR, &priv->status);
  2424. wake_up_interruptible(&priv->wait_command_queue);
  2425. /*
  2426. * Keep the restart process from trying to send host
  2427. * commands by clearing the INIT status bit
  2428. */
  2429. clear_bit(STATUS_READY, &priv->status);
  2430. queue_work(priv->workqueue, &priv->restart);
  2431. break;
  2432. }
  2433. return 0;
  2434. }
  2435. EXPORT_SYMBOL(iwl_force_reset);
  2436. /**
  2437. * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
  2438. *
  2439. * During normal condition (no queue is stuck), the timer is continually set to
  2440. * execute every monitor_recover_period milliseconds after the last timer
  2441. * expired. When the queue read_ptr is at the same place, the timer is
  2442. * shorten to 100mSecs. This is
  2443. * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
  2444. * 2) to detect the stuck queues quicker before the station and AP can
  2445. * disassociate each other.
  2446. *
  2447. * This function monitors all the tx queues and recover from it if any
  2448. * of the queues are stuck.
  2449. * 1. It first check the cmd queue for stuck conditions. If it is stuck,
  2450. * it will recover by resetting the firmware and return.
  2451. * 2. Then, it checks for station association. If it associates it will check
  2452. * other queues. If any queue is stuck, it will recover by resetting
  2453. * the firmware.
  2454. * Note: It the number of times the queue read_ptr to be at the same place to
  2455. * be MAX_REPEAT+1 in order to consider to be stuck.
  2456. */
  2457. /*
  2458. * The maximum number of times the read pointer of the tx queue at the
  2459. * same place without considering to be stuck.
  2460. */
  2461. #define MAX_REPEAT (2)
  2462. static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
  2463. {
  2464. struct iwl_tx_queue *txq;
  2465. struct iwl_queue *q;
  2466. txq = &priv->txq[cnt];
  2467. q = &txq->q;
  2468. /* queue is empty, skip */
  2469. if (q->read_ptr != q->write_ptr) {
  2470. if (q->read_ptr == q->last_read_ptr) {
  2471. /* a queue has not been read from last time */
  2472. if (q->repeat_same_read_ptr > MAX_REPEAT) {
  2473. IWL_ERR(priv,
  2474. "queue %d stuck %d time. Fw reload.\n",
  2475. q->id, q->repeat_same_read_ptr);
  2476. q->repeat_same_read_ptr = 0;
  2477. iwl_force_reset(priv, IWL_FW_RESET);
  2478. } else {
  2479. q->repeat_same_read_ptr++;
  2480. IWL_DEBUG_RADIO(priv,
  2481. "queue %d, not read %d time\n",
  2482. q->id,
  2483. q->repeat_same_read_ptr);
  2484. mod_timer(&priv->monitor_recover, jiffies +
  2485. msecs_to_jiffies(IWL_ONE_HUNDRED_MSECS));
  2486. }
  2487. return 1;
  2488. } else {
  2489. q->last_read_ptr = q->read_ptr;
  2490. q->repeat_same_read_ptr = 0;
  2491. }
  2492. }
  2493. return 0;
  2494. }
  2495. void iwl_bg_monitor_recover(unsigned long data)
  2496. {
  2497. struct iwl_priv *priv = (struct iwl_priv *)data;
  2498. int cnt;
  2499. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2500. return;
  2501. /* monitor and check for stuck cmd queue */
  2502. if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM))
  2503. return;
  2504. /* monitor and check for other stuck queues */
  2505. if (iwl_is_associated(priv)) {
  2506. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  2507. /* skip as we already checked the command queue */
  2508. if (cnt == IWL_CMD_QUEUE_NUM)
  2509. continue;
  2510. if (iwl_check_stuck_queue(priv, cnt))
  2511. return;
  2512. }
  2513. }
  2514. /*
  2515. * Reschedule the timer to occur in
  2516. * priv->cfg->monitor_recover_period
  2517. */
  2518. mod_timer(&priv->monitor_recover,
  2519. jiffies + msecs_to_jiffies(priv->cfg->monitor_recover_period));
  2520. }
  2521. EXPORT_SYMBOL(iwl_bg_monitor_recover);
  2522. #ifdef CONFIG_PM
  2523. int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  2524. {
  2525. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2526. /*
  2527. * This function is called when system goes into suspend state
  2528. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2529. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2530. * it will not call apm_ops.stop() to stop the DMA operation.
  2531. * Calling apm_ops.stop here to make sure we stop the DMA.
  2532. */
  2533. priv->cfg->ops->lib->apm_ops.stop(priv);
  2534. pci_save_state(pdev);
  2535. pci_disable_device(pdev);
  2536. pci_set_power_state(pdev, PCI_D3hot);
  2537. return 0;
  2538. }
  2539. EXPORT_SYMBOL(iwl_pci_suspend);
  2540. int iwl_pci_resume(struct pci_dev *pdev)
  2541. {
  2542. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2543. int ret;
  2544. pci_set_power_state(pdev, PCI_D0);
  2545. ret = pci_enable_device(pdev);
  2546. if (ret)
  2547. return ret;
  2548. pci_restore_state(pdev);
  2549. iwl_enable_interrupts(priv);
  2550. return 0;
  2551. }
  2552. EXPORT_SYMBOL(iwl_pci_resume);
  2553. #endif /* CONFIG_PM */