iwl-core.c 95 KB

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