iwl-core.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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 <linux/slab.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h"
  36. #include "iwl-debug.h"
  37. #include "iwl-core.h"
  38. #include "iwl-io.h"
  39. #include "iwl-power.h"
  40. #include "iwl-sta.h"
  41. #include "iwl-helpers.h"
  42. MODULE_DESCRIPTION("iwl-legacy: common functions for 3945 and 4965");
  43. MODULE_VERSION(IWLWIFI_VERSION);
  44. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  45. MODULE_LICENSE("GPL");
  46. /*
  47. * set bt_coex_active to true, uCode will do kill/defer
  48. * every time the priority line is asserted (BT is sending signals on the
  49. * priority line in the PCIx).
  50. * set bt_coex_active to false, uCode will ignore the BT activity and
  51. * perform the normal operation
  52. *
  53. * User might experience transmit issue on some platform due to WiFi/BT
  54. * co-exist problem. The possible behaviors are:
  55. * Able to scan and finding all the available AP
  56. * Not able to associate with any AP
  57. * On those platforms, WiFi communication can be restored by set
  58. * "bt_coex_active" module parameter to "false"
  59. *
  60. * default: bt_coex_active = true (BT_COEX_ENABLE)
  61. */
  62. static bool bt_coex_active = true;
  63. module_param(bt_coex_active, bool, S_IRUGO);
  64. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
  65. u32 iwlegacy_debug_level;
  66. EXPORT_SYMBOL(iwlegacy_debug_level);
  67. const u8 iwlegacy_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  68. EXPORT_SYMBOL(iwlegacy_bcast_addr);
  69. /* This function both allocates and initializes hw and priv. */
  70. struct ieee80211_hw *iwl_legacy_alloc_all(struct iwl_cfg *cfg)
  71. {
  72. struct iwl_priv *priv;
  73. /* mac80211 allocates memory for this device instance, including
  74. * space for this driver's private structure */
  75. struct ieee80211_hw *hw;
  76. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv),
  77. cfg->ops->ieee80211_ops);
  78. if (hw == NULL) {
  79. pr_err("%s: Can not allocate network device\n",
  80. cfg->name);
  81. goto out;
  82. }
  83. priv = hw->priv;
  84. priv->hw = hw;
  85. out:
  86. return hw;
  87. }
  88. EXPORT_SYMBOL(iwl_legacy_alloc_all);
  89. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  90. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  91. static void iwl_legacy_init_ht_hw_capab(const struct iwl_priv *priv,
  92. struct ieee80211_sta_ht_cap *ht_info,
  93. enum ieee80211_band band)
  94. {
  95. u16 max_bit_rate = 0;
  96. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  97. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  98. ht_info->cap = 0;
  99. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  100. ht_info->ht_supported = true;
  101. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  102. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  103. if (priv->hw_params.ht40_channel & BIT(band)) {
  104. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  105. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  106. ht_info->mcs.rx_mask[4] = 0x01;
  107. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  108. }
  109. if (priv->cfg->mod_params->amsdu_size_8K)
  110. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  111. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  112. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  113. ht_info->mcs.rx_mask[0] = 0xFF;
  114. if (rx_chains_num >= 2)
  115. ht_info->mcs.rx_mask[1] = 0xFF;
  116. if (rx_chains_num >= 3)
  117. ht_info->mcs.rx_mask[2] = 0xFF;
  118. /* Highest supported Rx data rate */
  119. max_bit_rate *= rx_chains_num;
  120. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  121. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  122. /* Tx MCS capabilities */
  123. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  124. if (tx_chains_num != rx_chains_num) {
  125. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  126. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  127. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  128. }
  129. }
  130. /**
  131. * iwl_legacy_init_geos - Initialize mac80211's geo/channel info based from eeprom
  132. */
  133. int iwl_legacy_init_geos(struct iwl_priv *priv)
  134. {
  135. struct iwl_channel_info *ch;
  136. struct ieee80211_supported_band *sband;
  137. struct ieee80211_channel *channels;
  138. struct ieee80211_channel *geo_ch;
  139. struct ieee80211_rate *rates;
  140. int i = 0;
  141. s8 max_tx_power = 0;
  142. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  143. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  144. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  145. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  146. return 0;
  147. }
  148. channels = kzalloc(sizeof(struct ieee80211_channel) *
  149. priv->channel_count, GFP_KERNEL);
  150. if (!channels)
  151. return -ENOMEM;
  152. rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
  153. GFP_KERNEL);
  154. if (!rates) {
  155. kfree(channels);
  156. return -ENOMEM;
  157. }
  158. /* 5.2GHz channels start after the 2.4GHz channels */
  159. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  160. sband->channels = &channels[ARRAY_SIZE(iwlegacy_eeprom_band_1)];
  161. /* just OFDM */
  162. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  163. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  164. if (priv->cfg->sku & IWL_SKU_N)
  165. iwl_legacy_init_ht_hw_capab(priv, &sband->ht_cap,
  166. IEEE80211_BAND_5GHZ);
  167. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  168. sband->channels = channels;
  169. /* OFDM & CCK */
  170. sband->bitrates = rates;
  171. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  172. if (priv->cfg->sku & IWL_SKU_N)
  173. iwl_legacy_init_ht_hw_capab(priv, &sband->ht_cap,
  174. IEEE80211_BAND_2GHZ);
  175. priv->ieee_channels = channels;
  176. priv->ieee_rates = rates;
  177. for (i = 0; i < priv->channel_count; i++) {
  178. ch = &priv->channel_info[i];
  179. if (!iwl_legacy_is_channel_valid(ch))
  180. continue;
  181. if (iwl_legacy_is_channel_a_band(ch))
  182. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  183. else
  184. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  185. geo_ch = &sband->channels[sband->n_channels++];
  186. geo_ch->center_freq =
  187. ieee80211_channel_to_frequency(ch->channel, ch->band);
  188. geo_ch->max_power = ch->max_power_avg;
  189. geo_ch->max_antenna_gain = 0xff;
  190. geo_ch->hw_value = ch->channel;
  191. if (iwl_legacy_is_channel_valid(ch)) {
  192. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  193. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  194. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  195. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  196. if (ch->flags & EEPROM_CHANNEL_RADAR)
  197. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  198. geo_ch->flags |= ch->ht40_extension_channel;
  199. if (ch->max_power_avg > max_tx_power)
  200. max_tx_power = ch->max_power_avg;
  201. } else {
  202. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  203. }
  204. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  205. ch->channel, geo_ch->center_freq,
  206. iwl_legacy_is_channel_a_band(ch) ? "5.2" : "2.4",
  207. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  208. "restricted" : "valid",
  209. geo_ch->flags);
  210. }
  211. priv->tx_power_device_lmt = max_tx_power;
  212. priv->tx_power_user_lmt = max_tx_power;
  213. priv->tx_power_next = max_tx_power;
  214. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  215. priv->cfg->sku & IWL_SKU_A) {
  216. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  217. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  218. priv->pci_dev->device,
  219. priv->pci_dev->subsystem_device);
  220. priv->cfg->sku &= ~IWL_SKU_A;
  221. }
  222. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  223. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  224. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  225. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  226. return 0;
  227. }
  228. EXPORT_SYMBOL(iwl_legacy_init_geos);
  229. /*
  230. * iwl_legacy_free_geos - undo allocations in iwl_legacy_init_geos
  231. */
  232. void iwl_legacy_free_geos(struct iwl_priv *priv)
  233. {
  234. kfree(priv->ieee_channels);
  235. kfree(priv->ieee_rates);
  236. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  237. }
  238. EXPORT_SYMBOL(iwl_legacy_free_geos);
  239. static bool iwl_legacy_is_channel_extension(struct iwl_priv *priv,
  240. enum ieee80211_band band,
  241. u16 channel, u8 extension_chan_offset)
  242. {
  243. const struct iwl_channel_info *ch_info;
  244. ch_info = iwl_legacy_get_channel_info(priv, band, channel);
  245. if (!iwl_legacy_is_channel_valid(ch_info))
  246. return false;
  247. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  248. return !(ch_info->ht40_extension_channel &
  249. IEEE80211_CHAN_NO_HT40PLUS);
  250. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  251. return !(ch_info->ht40_extension_channel &
  252. IEEE80211_CHAN_NO_HT40MINUS);
  253. return false;
  254. }
  255. bool iwl_legacy_is_ht40_tx_allowed(struct iwl_priv *priv,
  256. struct iwl_rxon_context *ctx,
  257. struct ieee80211_sta_ht_cap *ht_cap)
  258. {
  259. if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
  260. return false;
  261. /*
  262. * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  263. * the bit will not set if it is pure 40MHz case
  264. */
  265. if (ht_cap && !ht_cap->ht_supported)
  266. return false;
  267. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
  268. if (priv->disable_ht40)
  269. return false;
  270. #endif
  271. return iwl_legacy_is_channel_extension(priv, priv->band,
  272. le16_to_cpu(ctx->staging.channel),
  273. ctx->ht.extension_chan_offset);
  274. }
  275. EXPORT_SYMBOL(iwl_legacy_is_ht40_tx_allowed);
  276. static u16 iwl_legacy_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  277. {
  278. u16 new_val;
  279. u16 beacon_factor;
  280. /*
  281. * If mac80211 hasn't given us a beacon interval, program
  282. * the default into the device.
  283. */
  284. if (!beacon_val)
  285. return DEFAULT_BEACON_INTERVAL;
  286. /*
  287. * If the beacon interval we obtained from the peer
  288. * is too large, we'll have to wake up more often
  289. * (and in IBSS case, we'll beacon too much)
  290. *
  291. * For example, if max_beacon_val is 4096, and the
  292. * requested beacon interval is 7000, we'll have to
  293. * use 3500 to be able to wake up on the beacons.
  294. *
  295. * This could badly influence beacon detection stats.
  296. */
  297. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  298. new_val = beacon_val / beacon_factor;
  299. if (!new_val)
  300. new_val = max_beacon_val;
  301. return new_val;
  302. }
  303. int
  304. iwl_legacy_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  305. {
  306. u64 tsf;
  307. s32 interval_tm, rem;
  308. struct ieee80211_conf *conf = NULL;
  309. u16 beacon_int;
  310. struct ieee80211_vif *vif = ctx->vif;
  311. conf = iwl_legacy_ieee80211_get_hw_conf(priv->hw);
  312. lockdep_assert_held(&priv->mutex);
  313. memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
  314. ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
  315. ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
  316. beacon_int = vif ? vif->bss_conf.beacon_int : 0;
  317. /*
  318. * TODO: For IBSS we need to get atim_window from mac80211,
  319. * for now just always use 0
  320. */
  321. ctx->timing.atim_window = 0;
  322. beacon_int = iwl_legacy_adjust_beacon_interval(beacon_int,
  323. priv->hw_params.max_beacon_itrvl * TIME_UNIT);
  324. ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
  325. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  326. interval_tm = beacon_int * TIME_UNIT;
  327. rem = do_div(tsf, interval_tm);
  328. ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  329. ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
  330. IWL_DEBUG_ASSOC(priv,
  331. "beacon interval %d beacon timer %d beacon tim %d\n",
  332. le16_to_cpu(ctx->timing.beacon_interval),
  333. le32_to_cpu(ctx->timing.beacon_init_val),
  334. le16_to_cpu(ctx->timing.atim_window));
  335. return iwl_legacy_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
  336. sizeof(ctx->timing), &ctx->timing);
  337. }
  338. EXPORT_SYMBOL(iwl_legacy_send_rxon_timing);
  339. void
  340. iwl_legacy_set_rxon_hwcrypto(struct iwl_priv *priv,
  341. struct iwl_rxon_context *ctx,
  342. int hw_decrypt)
  343. {
  344. struct iwl_legacy_rxon_cmd *rxon = &ctx->staging;
  345. if (hw_decrypt)
  346. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  347. else
  348. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  349. }
  350. EXPORT_SYMBOL(iwl_legacy_set_rxon_hwcrypto);
  351. /* validate RXON structure is valid */
  352. int
  353. iwl_legacy_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  354. {
  355. struct iwl_legacy_rxon_cmd *rxon = &ctx->staging;
  356. bool error = false;
  357. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  358. if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
  359. IWL_WARN(priv, "check 2.4G: wrong narrow\n");
  360. error = true;
  361. }
  362. if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
  363. IWL_WARN(priv, "check 2.4G: wrong radar\n");
  364. error = true;
  365. }
  366. } else {
  367. if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
  368. IWL_WARN(priv, "check 5.2G: not short slot!\n");
  369. error = true;
  370. }
  371. if (rxon->flags & RXON_FLG_CCK_MSK) {
  372. IWL_WARN(priv, "check 5.2G: CCK!\n");
  373. error = true;
  374. }
  375. }
  376. if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
  377. IWL_WARN(priv, "mac/bssid mcast!\n");
  378. error = true;
  379. }
  380. /* make sure basic rates 6Mbps and 1Mbps are supported */
  381. if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
  382. (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
  383. IWL_WARN(priv, "neither 1 nor 6 are basic\n");
  384. error = true;
  385. }
  386. if (le16_to_cpu(rxon->assoc_id) > 2007) {
  387. IWL_WARN(priv, "aid > 2007\n");
  388. error = true;
  389. }
  390. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  391. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
  392. IWL_WARN(priv, "CCK and short slot\n");
  393. error = true;
  394. }
  395. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  396. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
  397. IWL_WARN(priv, "CCK and auto detect");
  398. error = true;
  399. }
  400. if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  401. RXON_FLG_TGG_PROTECT_MSK)) ==
  402. RXON_FLG_TGG_PROTECT_MSK) {
  403. IWL_WARN(priv, "TGg but no auto-detect\n");
  404. error = true;
  405. }
  406. if (error)
  407. IWL_WARN(priv, "Tuning to channel %d\n",
  408. le16_to_cpu(rxon->channel));
  409. if (error) {
  410. IWL_ERR(priv, "Invalid RXON\n");
  411. return -EINVAL;
  412. }
  413. return 0;
  414. }
  415. EXPORT_SYMBOL(iwl_legacy_check_rxon_cmd);
  416. /**
  417. * iwl_legacy_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  418. * @priv: staging_rxon is compared to active_rxon
  419. *
  420. * If the RXON structure is changing enough to require a new tune,
  421. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  422. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  423. */
  424. int iwl_legacy_full_rxon_required(struct iwl_priv *priv,
  425. struct iwl_rxon_context *ctx)
  426. {
  427. const struct iwl_legacy_rxon_cmd *staging = &ctx->staging;
  428. const struct iwl_legacy_rxon_cmd *active = &ctx->active;
  429. #define CHK(cond) \
  430. if ((cond)) { \
  431. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  432. return 1; \
  433. }
  434. #define CHK_NEQ(c1, c2) \
  435. if ((c1) != (c2)) { \
  436. IWL_DEBUG_INFO(priv, "need full RXON - " \
  437. #c1 " != " #c2 " - %d != %d\n", \
  438. (c1), (c2)); \
  439. return 1; \
  440. }
  441. /* These items are only settable from the full RXON command */
  442. CHK(!iwl_legacy_is_associated_ctx(ctx));
  443. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  444. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  445. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  446. active->wlap_bssid_addr));
  447. CHK_NEQ(staging->dev_type, active->dev_type);
  448. CHK_NEQ(staging->channel, active->channel);
  449. CHK_NEQ(staging->air_propagation, active->air_propagation);
  450. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  451. active->ofdm_ht_single_stream_basic_rates);
  452. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  453. active->ofdm_ht_dual_stream_basic_rates);
  454. CHK_NEQ(staging->assoc_id, active->assoc_id);
  455. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  456. * be updated with the RXON_ASSOC command -- however only some
  457. * flag transitions are allowed using RXON_ASSOC */
  458. /* Check if we are not switching bands */
  459. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  460. active->flags & RXON_FLG_BAND_24G_MSK);
  461. /* Check if we are switching association toggle */
  462. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  463. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  464. #undef CHK
  465. #undef CHK_NEQ
  466. return 0;
  467. }
  468. EXPORT_SYMBOL(iwl_legacy_full_rxon_required);
  469. u8 iwl_legacy_get_lowest_plcp(struct iwl_priv *priv,
  470. struct iwl_rxon_context *ctx)
  471. {
  472. /*
  473. * Assign the lowest rate -- should really get this from
  474. * the beacon skb from mac80211.
  475. */
  476. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
  477. return IWL_RATE_1M_PLCP;
  478. else
  479. return IWL_RATE_6M_PLCP;
  480. }
  481. EXPORT_SYMBOL(iwl_legacy_get_lowest_plcp);
  482. static void _iwl_legacy_set_rxon_ht(struct iwl_priv *priv,
  483. struct iwl_ht_config *ht_conf,
  484. struct iwl_rxon_context *ctx)
  485. {
  486. struct iwl_legacy_rxon_cmd *rxon = &ctx->staging;
  487. if (!ctx->ht.enabled) {
  488. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  489. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  490. RXON_FLG_HT40_PROT_MSK |
  491. RXON_FLG_HT_PROT_MSK);
  492. return;
  493. }
  494. rxon->flags |= cpu_to_le32(ctx->ht.protection <<
  495. RXON_FLG_HT_OPERATING_MODE_POS);
  496. /* Set up channel bandwidth:
  497. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  498. /* clear the HT channel mode before set the mode */
  499. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  500. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  501. if (iwl_legacy_is_ht40_tx_allowed(priv, ctx, NULL)) {
  502. /* pure ht40 */
  503. if (ctx->ht.protection ==
  504. IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  505. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  506. /* Note: control channel is opposite of extension channel */
  507. switch (ctx->ht.extension_chan_offset) {
  508. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  509. rxon->flags &=
  510. ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  511. break;
  512. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  513. rxon->flags |=
  514. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  515. break;
  516. }
  517. } else {
  518. /* Note: control channel is opposite of extension channel */
  519. switch (ctx->ht.extension_chan_offset) {
  520. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  521. rxon->flags &=
  522. ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  523. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  524. break;
  525. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  526. rxon->flags |=
  527. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  528. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  529. break;
  530. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  531. default:
  532. /* channel location only valid if in Mixed mode */
  533. IWL_ERR(priv,
  534. "invalid extension channel offset\n");
  535. break;
  536. }
  537. }
  538. } else {
  539. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  540. }
  541. if (priv->cfg->ops->hcmd->set_rxon_chain)
  542. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  543. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  544. "extension channel offset 0x%x\n",
  545. le32_to_cpu(rxon->flags), ctx->ht.protection,
  546. ctx->ht.extension_chan_offset);
  547. }
  548. void iwl_legacy_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  549. {
  550. struct iwl_rxon_context *ctx;
  551. for_each_context(priv, ctx)
  552. _iwl_legacy_set_rxon_ht(priv, ht_conf, ctx);
  553. }
  554. EXPORT_SYMBOL(iwl_legacy_set_rxon_ht);
  555. /* Return valid, unused, channel for a passive scan to reset the RF */
  556. u8 iwl_legacy_get_single_channel_number(struct iwl_priv *priv,
  557. enum ieee80211_band band)
  558. {
  559. const struct iwl_channel_info *ch_info;
  560. int i;
  561. u8 channel = 0;
  562. u8 min, max;
  563. struct iwl_rxon_context *ctx;
  564. if (band == IEEE80211_BAND_5GHZ) {
  565. min = 14;
  566. max = priv->channel_count;
  567. } else {
  568. min = 0;
  569. max = 14;
  570. }
  571. for (i = min; i < max; i++) {
  572. bool busy = false;
  573. for_each_context(priv, ctx) {
  574. busy = priv->channel_info[i].channel ==
  575. le16_to_cpu(ctx->staging.channel);
  576. if (busy)
  577. break;
  578. }
  579. if (busy)
  580. continue;
  581. channel = priv->channel_info[i].channel;
  582. ch_info = iwl_legacy_get_channel_info(priv, band, channel);
  583. if (iwl_legacy_is_channel_valid(ch_info))
  584. break;
  585. }
  586. return channel;
  587. }
  588. EXPORT_SYMBOL(iwl_legacy_get_single_channel_number);
  589. /**
  590. * iwl_legacy_set_rxon_channel - Set the band and channel values in staging RXON
  591. * @ch: requested channel as a pointer to struct ieee80211_channel
  592. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  593. * in the staging RXON flag structure based on the ch->band
  594. */
  595. int
  596. iwl_legacy_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  597. struct iwl_rxon_context *ctx)
  598. {
  599. enum ieee80211_band band = ch->band;
  600. u16 channel = ch->hw_value;
  601. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  602. (priv->band == band))
  603. return 0;
  604. ctx->staging.channel = cpu_to_le16(channel);
  605. if (band == IEEE80211_BAND_5GHZ)
  606. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  607. else
  608. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  609. priv->band = band;
  610. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  611. return 0;
  612. }
  613. EXPORT_SYMBOL(iwl_legacy_set_rxon_channel);
  614. void iwl_legacy_set_flags_for_band(struct iwl_priv *priv,
  615. struct iwl_rxon_context *ctx,
  616. enum ieee80211_band band,
  617. struct ieee80211_vif *vif)
  618. {
  619. if (band == IEEE80211_BAND_5GHZ) {
  620. ctx->staging.flags &=
  621. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  622. | RXON_FLG_CCK_MSK);
  623. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  624. } else {
  625. /* Copied from iwl_post_associate() */
  626. if (vif && vif->bss_conf.use_short_slot)
  627. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  628. else
  629. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  630. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  631. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  632. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  633. }
  634. }
  635. EXPORT_SYMBOL(iwl_legacy_set_flags_for_band);
  636. /*
  637. * initialize rxon structure with default values from eeprom
  638. */
  639. void iwl_legacy_connection_init_rx_config(struct iwl_priv *priv,
  640. struct iwl_rxon_context *ctx)
  641. {
  642. const struct iwl_channel_info *ch_info;
  643. memset(&ctx->staging, 0, sizeof(ctx->staging));
  644. if (!ctx->vif) {
  645. ctx->staging.dev_type = ctx->unused_devtype;
  646. } else
  647. switch (ctx->vif->type) {
  648. case NL80211_IFTYPE_STATION:
  649. ctx->staging.dev_type = ctx->station_devtype;
  650. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  651. break;
  652. case NL80211_IFTYPE_ADHOC:
  653. ctx->staging.dev_type = ctx->ibss_devtype;
  654. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  655. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  656. RXON_FILTER_ACCEPT_GRP_MSK;
  657. break;
  658. default:
  659. IWL_ERR(priv, "Unsupported interface type %d\n",
  660. ctx->vif->type);
  661. break;
  662. }
  663. #if 0
  664. /* TODO: Figure out when short_preamble would be set and cache from
  665. * that */
  666. if (!hw_to_local(priv->hw)->short_preamble)
  667. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  668. else
  669. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  670. #endif
  671. ch_info = iwl_legacy_get_channel_info(priv, priv->band,
  672. le16_to_cpu(ctx->active.channel));
  673. if (!ch_info)
  674. ch_info = &priv->channel_info[0];
  675. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  676. priv->band = ch_info->band;
  677. iwl_legacy_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  678. ctx->staging.ofdm_basic_rates =
  679. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  680. ctx->staging.cck_basic_rates =
  681. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  682. /* clear both MIX and PURE40 mode flag */
  683. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  684. RXON_FLG_CHANNEL_MODE_PURE_40);
  685. if (ctx->vif)
  686. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  687. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  688. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  689. }
  690. EXPORT_SYMBOL(iwl_legacy_connection_init_rx_config);
  691. void iwl_legacy_set_rate(struct iwl_priv *priv)
  692. {
  693. const struct ieee80211_supported_band *hw = NULL;
  694. struct ieee80211_rate *rate;
  695. struct iwl_rxon_context *ctx;
  696. int i;
  697. hw = iwl_get_hw_mode(priv, priv->band);
  698. if (!hw) {
  699. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  700. return;
  701. }
  702. priv->active_rate = 0;
  703. for (i = 0; i < hw->n_bitrates; i++) {
  704. rate = &(hw->bitrates[i]);
  705. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  706. priv->active_rate |= (1 << rate->hw_value);
  707. }
  708. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  709. for_each_context(priv, ctx) {
  710. ctx->staging.cck_basic_rates =
  711. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  712. ctx->staging.ofdm_basic_rates =
  713. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  714. }
  715. }
  716. EXPORT_SYMBOL(iwl_legacy_set_rate);
  717. void iwl_legacy_chswitch_done(struct iwl_priv *priv, bool is_success)
  718. {
  719. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  720. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  721. return;
  722. if (priv->switch_rxon.switch_in_progress) {
  723. ieee80211_chswitch_done(ctx->vif, is_success);
  724. mutex_lock(&priv->mutex);
  725. priv->switch_rxon.switch_in_progress = false;
  726. mutex_unlock(&priv->mutex);
  727. }
  728. }
  729. EXPORT_SYMBOL(iwl_legacy_chswitch_done);
  730. void iwl_legacy_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  731. {
  732. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  733. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  734. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  735. struct iwl_legacy_rxon_cmd *rxon = (void *)&ctx->active;
  736. if (priv->switch_rxon.switch_in_progress) {
  737. if (!le32_to_cpu(csa->status) &&
  738. (csa->channel == priv->switch_rxon.channel)) {
  739. rxon->channel = csa->channel;
  740. ctx->staging.channel = csa->channel;
  741. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  742. le16_to_cpu(csa->channel));
  743. iwl_legacy_chswitch_done(priv, true);
  744. } else {
  745. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  746. le16_to_cpu(csa->channel));
  747. iwl_legacy_chswitch_done(priv, false);
  748. }
  749. }
  750. }
  751. EXPORT_SYMBOL(iwl_legacy_rx_csa);
  752. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  753. void iwl_legacy_print_rx_config_cmd(struct iwl_priv *priv,
  754. struct iwl_rxon_context *ctx)
  755. {
  756. struct iwl_legacy_rxon_cmd *rxon = &ctx->staging;
  757. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  758. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  759. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
  760. le16_to_cpu(rxon->channel));
  761. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  762. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  763. le32_to_cpu(rxon->filter_flags));
  764. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  765. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  766. rxon->ofdm_basic_rates);
  767. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
  768. rxon->cck_basic_rates);
  769. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  770. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  771. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
  772. le16_to_cpu(rxon->assoc_id));
  773. }
  774. EXPORT_SYMBOL(iwl_legacy_print_rx_config_cmd);
  775. #endif
  776. /**
  777. * iwl_legacy_irq_handle_error - called for HW or SW error interrupt from card
  778. */
  779. void iwl_legacy_irq_handle_error(struct iwl_priv *priv)
  780. {
  781. /* Set the FW error flag -- cleared on iwl_down */
  782. set_bit(STATUS_FW_ERROR, &priv->status);
  783. /* Cancel currently queued command. */
  784. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  785. IWL_ERR(priv, "Loaded firmware version: %s\n",
  786. priv->hw->wiphy->fw_version);
  787. priv->cfg->ops->lib->dump_nic_error_log(priv);
  788. if (priv->cfg->ops->lib->dump_fh)
  789. priv->cfg->ops->lib->dump_fh(priv, NULL, false);
  790. priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
  791. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  792. if (iwl_legacy_get_debug_level(priv) & IWL_DL_FW_ERRORS)
  793. iwl_legacy_print_rx_config_cmd(priv,
  794. &priv->contexts[IWL_RXON_CTX_BSS]);
  795. #endif
  796. wake_up_interruptible(&priv->wait_command_queue);
  797. /* Keep the restart process from trying to send host
  798. * commands by clearing the INIT status bit */
  799. clear_bit(STATUS_READY, &priv->status);
  800. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  801. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  802. "Restarting adapter due to uCode error.\n");
  803. if (priv->cfg->mod_params->restart_fw)
  804. queue_work(priv->workqueue, &priv->restart);
  805. }
  806. }
  807. EXPORT_SYMBOL(iwl_legacy_irq_handle_error);
  808. static int iwl_legacy_apm_stop_master(struct iwl_priv *priv)
  809. {
  810. int ret = 0;
  811. /* stop device's busmaster DMA activity */
  812. iwl_legacy_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  813. ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
  814. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  815. if (ret)
  816. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  817. IWL_DEBUG_INFO(priv, "stop master\n");
  818. return ret;
  819. }
  820. void iwl_legacy_apm_stop(struct iwl_priv *priv)
  821. {
  822. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  823. /* Stop device's DMA activity */
  824. iwl_legacy_apm_stop_master(priv);
  825. /* Reset the entire device */
  826. iwl_legacy_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  827. udelay(10);
  828. /*
  829. * Clear "initialization complete" bit to move adapter from
  830. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  831. */
  832. iwl_legacy_clear_bit(priv, CSR_GP_CNTRL,
  833. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  834. }
  835. EXPORT_SYMBOL(iwl_legacy_apm_stop);
  836. /*
  837. * Start up NIC's basic functionality after it has been reset
  838. * (e.g. after platform boot, or shutdown via iwl_legacy_apm_stop())
  839. * NOTE: This does not load uCode nor start the embedded processor
  840. */
  841. int iwl_legacy_apm_init(struct iwl_priv *priv)
  842. {
  843. int ret = 0;
  844. u16 lctl;
  845. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  846. /*
  847. * Use "set_bit" below rather than "write", to preserve any hardware
  848. * bits already set by default after reset.
  849. */
  850. /* Disable L0S exit timer (platform NMI Work/Around) */
  851. iwl_legacy_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  852. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  853. /*
  854. * Disable L0s without affecting L1;
  855. * don't wait for ICH L0s (ICH bug W/A)
  856. */
  857. iwl_legacy_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  858. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  859. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  860. iwl_legacy_set_bit(priv, CSR_DBG_HPET_MEM_REG,
  861. CSR_DBG_HPET_MEM_REG_VAL);
  862. /*
  863. * Enable HAP INTA (interrupt from management bus) to
  864. * wake device's PCI Express link L1a -> L0s
  865. * NOTE: This is no-op for 3945 (non-existent bit)
  866. */
  867. iwl_legacy_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  868. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  869. /*
  870. * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
  871. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  872. * If so (likely), disable L0S, so device moves directly L0->L1;
  873. * costs negligible amount of power savings.
  874. * If not (unlikely), enable L0S, so there is at least some
  875. * power savings, even without L1.
  876. */
  877. if (priv->cfg->base_params->set_l0s) {
  878. lctl = iwl_legacy_pcie_link_ctl(priv);
  879. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
  880. PCI_CFG_LINK_CTRL_VAL_L1_EN) {
  881. /* L1-ASPM enabled; disable(!) L0S */
  882. iwl_legacy_set_bit(priv, CSR_GIO_REG,
  883. CSR_GIO_REG_VAL_L0S_ENABLED);
  884. IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
  885. } else {
  886. /* L1-ASPM disabled; enable(!) L0S */
  887. iwl_legacy_clear_bit(priv, CSR_GIO_REG,
  888. CSR_GIO_REG_VAL_L0S_ENABLED);
  889. IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
  890. }
  891. }
  892. /* Configure analog phase-lock-loop before activating to D0A */
  893. if (priv->cfg->base_params->pll_cfg_val)
  894. iwl_legacy_set_bit(priv, CSR_ANA_PLL_CFG,
  895. priv->cfg->base_params->pll_cfg_val);
  896. /*
  897. * Set "initialization complete" bit to move adapter from
  898. * D0U* --> D0A* (powered-up active) state.
  899. */
  900. iwl_legacy_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  901. /*
  902. * Wait for clock stabilization; once stabilized, access to
  903. * device-internal resources is supported, e.g. iwl_legacy_write_prph()
  904. * and accesses to uCode SRAM.
  905. */
  906. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  907. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  908. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  909. if (ret < 0) {
  910. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  911. goto out;
  912. }
  913. /*
  914. * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
  915. * BSM (Boostrap State Machine) is only in 3945 and 4965.
  916. *
  917. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  918. * do not disable clocks. This preserves any hardware bits already
  919. * set by default in "CLK_CTRL_REG" after reset.
  920. */
  921. if (priv->cfg->base_params->use_bsm)
  922. iwl_legacy_write_prph(priv, APMG_CLK_EN_REG,
  923. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  924. else
  925. iwl_legacy_write_prph(priv, APMG_CLK_EN_REG,
  926. APMG_CLK_VAL_DMA_CLK_RQT);
  927. udelay(20);
  928. /* Disable L1-Active */
  929. iwl_legacy_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  930. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  931. out:
  932. return ret;
  933. }
  934. EXPORT_SYMBOL(iwl_legacy_apm_init);
  935. int iwl_legacy_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  936. {
  937. int ret;
  938. s8 prev_tx_power;
  939. bool defer;
  940. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  941. lockdep_assert_held(&priv->mutex);
  942. if (priv->tx_power_user_lmt == tx_power && !force)
  943. return 0;
  944. if (!priv->cfg->ops->lib->send_tx_power)
  945. return -EOPNOTSUPP;
  946. /* 0 dBm mean 1 milliwatt */
  947. if (tx_power < 0) {
  948. IWL_WARN(priv,
  949. "Requested user TXPOWER %d below 1 mW.\n",
  950. tx_power);
  951. return -EINVAL;
  952. }
  953. if (tx_power > priv->tx_power_device_lmt) {
  954. IWL_WARN(priv,
  955. "Requested user TXPOWER %d above upper limit %d.\n",
  956. tx_power, priv->tx_power_device_lmt);
  957. return -EINVAL;
  958. }
  959. if (!iwl_legacy_is_ready_rf(priv))
  960. return -EIO;
  961. /* scan complete and commit_rxon use tx_power_next value,
  962. * it always need to be updated for newest request */
  963. priv->tx_power_next = tx_power;
  964. /* do not set tx power when scanning or channel changing */
  965. defer = test_bit(STATUS_SCANNING, &priv->status) ||
  966. memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
  967. if (defer && !force) {
  968. IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
  969. return 0;
  970. }
  971. prev_tx_power = priv->tx_power_user_lmt;
  972. priv->tx_power_user_lmt = tx_power;
  973. ret = priv->cfg->ops->lib->send_tx_power(priv);
  974. /* if fail to set tx_power, restore the orig. tx power */
  975. if (ret) {
  976. priv->tx_power_user_lmt = prev_tx_power;
  977. priv->tx_power_next = prev_tx_power;
  978. }
  979. return ret;
  980. }
  981. EXPORT_SYMBOL(iwl_legacy_set_tx_power);
  982. void iwl_legacy_send_bt_config(struct iwl_priv *priv)
  983. {
  984. struct iwl_bt_cmd bt_cmd = {
  985. .lead_time = BT_LEAD_TIME_DEF,
  986. .max_kill = BT_MAX_KILL_DEF,
  987. .kill_ack_mask = 0,
  988. .kill_cts_mask = 0,
  989. };
  990. if (!bt_coex_active)
  991. bt_cmd.flags = BT_COEX_DISABLE;
  992. else
  993. bt_cmd.flags = BT_COEX_ENABLE;
  994. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  995. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  996. if (iwl_legacy_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  997. sizeof(struct iwl_bt_cmd), &bt_cmd))
  998. IWL_ERR(priv, "failed to send BT Coex Config\n");
  999. }
  1000. EXPORT_SYMBOL(iwl_legacy_send_bt_config);
  1001. int iwl_legacy_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1002. {
  1003. struct iwl_statistics_cmd statistics_cmd = {
  1004. .configuration_flags =
  1005. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1006. };
  1007. if (flags & CMD_ASYNC)
  1008. return iwl_legacy_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1009. sizeof(struct iwl_statistics_cmd),
  1010. &statistics_cmd, NULL);
  1011. else
  1012. return iwl_legacy_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1013. sizeof(struct iwl_statistics_cmd),
  1014. &statistics_cmd);
  1015. }
  1016. EXPORT_SYMBOL(iwl_legacy_send_statistics_request);
  1017. void iwl_legacy_rx_pm_sleep_notif(struct iwl_priv *priv,
  1018. struct iwl_rx_mem_buffer *rxb)
  1019. {
  1020. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  1021. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1022. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1023. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1024. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1025. #endif
  1026. }
  1027. EXPORT_SYMBOL(iwl_legacy_rx_pm_sleep_notif);
  1028. void iwl_legacy_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1029. struct iwl_rx_mem_buffer *rxb)
  1030. {
  1031. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1032. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1033. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1034. "notification for %s:\n", len,
  1035. iwl_legacy_get_cmd_string(pkt->hdr.cmd));
  1036. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1037. }
  1038. EXPORT_SYMBOL(iwl_legacy_rx_pm_debug_statistics_notif);
  1039. void iwl_legacy_rx_reply_error(struct iwl_priv *priv,
  1040. struct iwl_rx_mem_buffer *rxb)
  1041. {
  1042. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1043. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1044. "seq 0x%04X ser 0x%08X\n",
  1045. le32_to_cpu(pkt->u.err_resp.error_type),
  1046. iwl_legacy_get_cmd_string(pkt->u.err_resp.cmd_id),
  1047. pkt->u.err_resp.cmd_id,
  1048. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1049. le32_to_cpu(pkt->u.err_resp.error_info));
  1050. }
  1051. EXPORT_SYMBOL(iwl_legacy_rx_reply_error);
  1052. void iwl_legacy_clear_isr_stats(struct iwl_priv *priv)
  1053. {
  1054. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1055. }
  1056. int iwl_legacy_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1057. const struct ieee80211_tx_queue_params *params)
  1058. {
  1059. struct iwl_priv *priv = hw->priv;
  1060. struct iwl_rxon_context *ctx;
  1061. unsigned long flags;
  1062. int q;
  1063. IWL_DEBUG_MAC80211(priv, "enter\n");
  1064. if (!iwl_legacy_is_ready_rf(priv)) {
  1065. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1066. return -EIO;
  1067. }
  1068. if (queue >= AC_NUM) {
  1069. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1070. return 0;
  1071. }
  1072. q = AC_NUM - 1 - queue;
  1073. spin_lock_irqsave(&priv->lock, flags);
  1074. for_each_context(priv, ctx) {
  1075. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1076. cpu_to_le16(params->cw_min);
  1077. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1078. cpu_to_le16(params->cw_max);
  1079. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1080. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1081. cpu_to_le16((params->txop * 32));
  1082. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1083. }
  1084. spin_unlock_irqrestore(&priv->lock, flags);
  1085. IWL_DEBUG_MAC80211(priv, "leave\n");
  1086. return 0;
  1087. }
  1088. EXPORT_SYMBOL(iwl_legacy_mac_conf_tx);
  1089. int iwl_legacy_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1090. {
  1091. struct iwl_priv *priv = hw->priv;
  1092. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1093. }
  1094. EXPORT_SYMBOL_GPL(iwl_legacy_mac_tx_last_beacon);
  1095. static int
  1096. iwl_legacy_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1097. {
  1098. iwl_legacy_connection_init_rx_config(priv, ctx);
  1099. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1100. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1101. return iwl_legacy_commit_rxon(priv, ctx);
  1102. }
  1103. static int iwl_legacy_setup_interface(struct iwl_priv *priv,
  1104. struct iwl_rxon_context *ctx)
  1105. {
  1106. struct ieee80211_vif *vif = ctx->vif;
  1107. int err;
  1108. lockdep_assert_held(&priv->mutex);
  1109. /*
  1110. * This variable will be correct only when there's just
  1111. * a single context, but all code using it is for hardware
  1112. * that supports only one context.
  1113. */
  1114. priv->iw_mode = vif->type;
  1115. ctx->is_active = true;
  1116. err = iwl_legacy_set_mode(priv, ctx);
  1117. if (err) {
  1118. if (!ctx->always_active)
  1119. ctx->is_active = false;
  1120. return err;
  1121. }
  1122. return 0;
  1123. }
  1124. int
  1125. iwl_legacy_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1126. {
  1127. struct iwl_priv *priv = hw->priv;
  1128. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1129. struct iwl_rxon_context *tmp, *ctx = NULL;
  1130. int err;
  1131. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1132. vif->type, vif->addr);
  1133. mutex_lock(&priv->mutex);
  1134. if (!iwl_legacy_is_ready_rf(priv)) {
  1135. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1136. err = -EINVAL;
  1137. goto out;
  1138. }
  1139. for_each_context(priv, tmp) {
  1140. u32 possible_modes =
  1141. tmp->interface_modes | tmp->exclusive_interface_modes;
  1142. if (tmp->vif) {
  1143. /* check if this busy context is exclusive */
  1144. if (tmp->exclusive_interface_modes &
  1145. BIT(tmp->vif->type)) {
  1146. err = -EINVAL;
  1147. goto out;
  1148. }
  1149. continue;
  1150. }
  1151. if (!(possible_modes & BIT(vif->type)))
  1152. continue;
  1153. /* have maybe usable context w/o interface */
  1154. ctx = tmp;
  1155. break;
  1156. }
  1157. if (!ctx) {
  1158. err = -EOPNOTSUPP;
  1159. goto out;
  1160. }
  1161. vif_priv->ctx = ctx;
  1162. ctx->vif = vif;
  1163. err = iwl_legacy_setup_interface(priv, ctx);
  1164. if (!err)
  1165. goto out;
  1166. ctx->vif = NULL;
  1167. priv->iw_mode = NL80211_IFTYPE_STATION;
  1168. out:
  1169. mutex_unlock(&priv->mutex);
  1170. IWL_DEBUG_MAC80211(priv, "leave\n");
  1171. return err;
  1172. }
  1173. EXPORT_SYMBOL(iwl_legacy_mac_add_interface);
  1174. static void iwl_legacy_teardown_interface(struct iwl_priv *priv,
  1175. struct ieee80211_vif *vif,
  1176. bool mode_change)
  1177. {
  1178. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  1179. lockdep_assert_held(&priv->mutex);
  1180. if (priv->scan_vif == vif) {
  1181. iwl_legacy_scan_cancel_timeout(priv, 200);
  1182. iwl_legacy_force_scan_end(priv);
  1183. }
  1184. if (!mode_change) {
  1185. iwl_legacy_set_mode(priv, ctx);
  1186. if (!ctx->always_active)
  1187. ctx->is_active = false;
  1188. }
  1189. }
  1190. void iwl_legacy_mac_remove_interface(struct ieee80211_hw *hw,
  1191. struct ieee80211_vif *vif)
  1192. {
  1193. struct iwl_priv *priv = hw->priv;
  1194. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  1195. IWL_DEBUG_MAC80211(priv, "enter\n");
  1196. mutex_lock(&priv->mutex);
  1197. WARN_ON(ctx->vif != vif);
  1198. ctx->vif = NULL;
  1199. iwl_legacy_teardown_interface(priv, vif, false);
  1200. memset(priv->bssid, 0, ETH_ALEN);
  1201. mutex_unlock(&priv->mutex);
  1202. IWL_DEBUG_MAC80211(priv, "leave\n");
  1203. }
  1204. EXPORT_SYMBOL(iwl_legacy_mac_remove_interface);
  1205. int iwl_legacy_alloc_txq_mem(struct iwl_priv *priv)
  1206. {
  1207. if (!priv->txq)
  1208. priv->txq = kzalloc(
  1209. sizeof(struct iwl_tx_queue) *
  1210. priv->cfg->base_params->num_of_queues,
  1211. GFP_KERNEL);
  1212. if (!priv->txq) {
  1213. IWL_ERR(priv, "Not enough memory for txq\n");
  1214. return -ENOMEM;
  1215. }
  1216. return 0;
  1217. }
  1218. EXPORT_SYMBOL(iwl_legacy_alloc_txq_mem);
  1219. void iwl_legacy_txq_mem(struct iwl_priv *priv)
  1220. {
  1221. kfree(priv->txq);
  1222. priv->txq = NULL;
  1223. }
  1224. EXPORT_SYMBOL(iwl_legacy_txq_mem);
  1225. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
  1226. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  1227. void iwl_legacy_reset_traffic_log(struct iwl_priv *priv)
  1228. {
  1229. priv->tx_traffic_idx = 0;
  1230. priv->rx_traffic_idx = 0;
  1231. if (priv->tx_traffic)
  1232. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1233. if (priv->rx_traffic)
  1234. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1235. }
  1236. int iwl_legacy_alloc_traffic_mem(struct iwl_priv *priv)
  1237. {
  1238. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  1239. if (iwlegacy_debug_level & IWL_DL_TX) {
  1240. if (!priv->tx_traffic) {
  1241. priv->tx_traffic =
  1242. kzalloc(traffic_size, GFP_KERNEL);
  1243. if (!priv->tx_traffic)
  1244. return -ENOMEM;
  1245. }
  1246. }
  1247. if (iwlegacy_debug_level & IWL_DL_RX) {
  1248. if (!priv->rx_traffic) {
  1249. priv->rx_traffic =
  1250. kzalloc(traffic_size, GFP_KERNEL);
  1251. if (!priv->rx_traffic)
  1252. return -ENOMEM;
  1253. }
  1254. }
  1255. iwl_legacy_reset_traffic_log(priv);
  1256. return 0;
  1257. }
  1258. EXPORT_SYMBOL(iwl_legacy_alloc_traffic_mem);
  1259. void iwl_legacy_free_traffic_mem(struct iwl_priv *priv)
  1260. {
  1261. kfree(priv->tx_traffic);
  1262. priv->tx_traffic = NULL;
  1263. kfree(priv->rx_traffic);
  1264. priv->rx_traffic = NULL;
  1265. }
  1266. EXPORT_SYMBOL(iwl_legacy_free_traffic_mem);
  1267. void iwl_legacy_dbg_log_tx_data_frame(struct iwl_priv *priv,
  1268. u16 length, struct ieee80211_hdr *header)
  1269. {
  1270. __le16 fc;
  1271. u16 len;
  1272. if (likely(!(iwlegacy_debug_level & IWL_DL_TX)))
  1273. return;
  1274. if (!priv->tx_traffic)
  1275. return;
  1276. fc = header->frame_control;
  1277. if (ieee80211_is_data(fc)) {
  1278. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1279. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1280. memcpy((priv->tx_traffic +
  1281. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1282. header, len);
  1283. priv->tx_traffic_idx =
  1284. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1285. }
  1286. }
  1287. EXPORT_SYMBOL(iwl_legacy_dbg_log_tx_data_frame);
  1288. void iwl_legacy_dbg_log_rx_data_frame(struct iwl_priv *priv,
  1289. u16 length, struct ieee80211_hdr *header)
  1290. {
  1291. __le16 fc;
  1292. u16 len;
  1293. if (likely(!(iwlegacy_debug_level & IWL_DL_RX)))
  1294. return;
  1295. if (!priv->rx_traffic)
  1296. return;
  1297. fc = header->frame_control;
  1298. if (ieee80211_is_data(fc)) {
  1299. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1300. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1301. memcpy((priv->rx_traffic +
  1302. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1303. header, len);
  1304. priv->rx_traffic_idx =
  1305. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1306. }
  1307. }
  1308. EXPORT_SYMBOL(iwl_legacy_dbg_log_rx_data_frame);
  1309. const char *iwl_legacy_get_mgmt_string(int cmd)
  1310. {
  1311. switch (cmd) {
  1312. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1313. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1314. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1315. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1316. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1317. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1318. IWL_CMD(MANAGEMENT_BEACON);
  1319. IWL_CMD(MANAGEMENT_ATIM);
  1320. IWL_CMD(MANAGEMENT_DISASSOC);
  1321. IWL_CMD(MANAGEMENT_AUTH);
  1322. IWL_CMD(MANAGEMENT_DEAUTH);
  1323. IWL_CMD(MANAGEMENT_ACTION);
  1324. default:
  1325. return "UNKNOWN";
  1326. }
  1327. }
  1328. const char *iwl_legacy_get_ctrl_string(int cmd)
  1329. {
  1330. switch (cmd) {
  1331. IWL_CMD(CONTROL_BACK_REQ);
  1332. IWL_CMD(CONTROL_BACK);
  1333. IWL_CMD(CONTROL_PSPOLL);
  1334. IWL_CMD(CONTROL_RTS);
  1335. IWL_CMD(CONTROL_CTS);
  1336. IWL_CMD(CONTROL_ACK);
  1337. IWL_CMD(CONTROL_CFEND);
  1338. IWL_CMD(CONTROL_CFENDACK);
  1339. default:
  1340. return "UNKNOWN";
  1341. }
  1342. }
  1343. void iwl_legacy_clear_traffic_stats(struct iwl_priv *priv)
  1344. {
  1345. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1346. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1347. }
  1348. /*
  1349. * if CONFIG_IWLWIFI_LEGACY_DEBUGFS defined,
  1350. * iwl_legacy_update_stats function will
  1351. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass
  1352. * Use debugFs to display the rx/rx_statistics
  1353. * if CONFIG_IWLWIFI_LEGACY_DEBUGFS not being defined, then no MGMT and CTRL
  1354. * information will be recorded, but DATA pkt still will be recorded
  1355. * for the reason of iwl_led.c need to control the led blinking based on
  1356. * number of tx and rx data.
  1357. *
  1358. */
  1359. void
  1360. iwl_legacy_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1361. {
  1362. struct traffic_stats *stats;
  1363. if (is_tx)
  1364. stats = &priv->tx_stats;
  1365. else
  1366. stats = &priv->rx_stats;
  1367. if (ieee80211_is_mgmt(fc)) {
  1368. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1369. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1370. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1371. break;
  1372. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1373. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1374. break;
  1375. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1376. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1377. break;
  1378. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1379. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1380. break;
  1381. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1382. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1383. break;
  1384. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1385. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1386. break;
  1387. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1388. stats->mgmt[MANAGEMENT_BEACON]++;
  1389. break;
  1390. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1391. stats->mgmt[MANAGEMENT_ATIM]++;
  1392. break;
  1393. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1394. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1395. break;
  1396. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1397. stats->mgmt[MANAGEMENT_AUTH]++;
  1398. break;
  1399. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1400. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1401. break;
  1402. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1403. stats->mgmt[MANAGEMENT_ACTION]++;
  1404. break;
  1405. }
  1406. } else if (ieee80211_is_ctl(fc)) {
  1407. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1408. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  1409. stats->ctrl[CONTROL_BACK_REQ]++;
  1410. break;
  1411. case cpu_to_le16(IEEE80211_STYPE_BACK):
  1412. stats->ctrl[CONTROL_BACK]++;
  1413. break;
  1414. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  1415. stats->ctrl[CONTROL_PSPOLL]++;
  1416. break;
  1417. case cpu_to_le16(IEEE80211_STYPE_RTS):
  1418. stats->ctrl[CONTROL_RTS]++;
  1419. break;
  1420. case cpu_to_le16(IEEE80211_STYPE_CTS):
  1421. stats->ctrl[CONTROL_CTS]++;
  1422. break;
  1423. case cpu_to_le16(IEEE80211_STYPE_ACK):
  1424. stats->ctrl[CONTROL_ACK]++;
  1425. break;
  1426. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  1427. stats->ctrl[CONTROL_CFEND]++;
  1428. break;
  1429. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  1430. stats->ctrl[CONTROL_CFENDACK]++;
  1431. break;
  1432. }
  1433. } else {
  1434. /* data */
  1435. stats->data_cnt++;
  1436. stats->data_bytes += len;
  1437. }
  1438. }
  1439. EXPORT_SYMBOL(iwl_legacy_update_stats);
  1440. #endif
  1441. static void _iwl_legacy_force_rf_reset(struct iwl_priv *priv)
  1442. {
  1443. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1444. return;
  1445. if (!iwl_legacy_is_any_associated(priv)) {
  1446. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  1447. return;
  1448. }
  1449. /*
  1450. * There is no easy and better way to force reset the radio,
  1451. * the only known method is switching channel which will force to
  1452. * reset and tune the radio.
  1453. * Use internal short scan (single channel) operation to should
  1454. * achieve this objective.
  1455. * Driver should reset the radio when number of consecutive missed
  1456. * beacon, or any other uCode error condition detected.
  1457. */
  1458. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  1459. iwl_legacy_internal_short_hw_scan(priv);
  1460. }
  1461. int iwl_legacy_force_reset(struct iwl_priv *priv, int mode, bool external)
  1462. {
  1463. struct iwl_force_reset *force_reset;
  1464. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1465. return -EINVAL;
  1466. if (mode >= IWL_MAX_FORCE_RESET) {
  1467. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  1468. return -EINVAL;
  1469. }
  1470. force_reset = &priv->force_reset[mode];
  1471. force_reset->reset_request_count++;
  1472. if (!external) {
  1473. if (force_reset->last_force_reset_jiffies &&
  1474. time_after(force_reset->last_force_reset_jiffies +
  1475. force_reset->reset_duration, jiffies)) {
  1476. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  1477. force_reset->reset_reject_count++;
  1478. return -EAGAIN;
  1479. }
  1480. }
  1481. force_reset->reset_success_count++;
  1482. force_reset->last_force_reset_jiffies = jiffies;
  1483. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  1484. switch (mode) {
  1485. case IWL_RF_RESET:
  1486. _iwl_legacy_force_rf_reset(priv);
  1487. break;
  1488. case IWL_FW_RESET:
  1489. /*
  1490. * if the request is from external(ex: debugfs),
  1491. * then always perform the request in regardless the module
  1492. * parameter setting
  1493. * if the request is from internal (uCode error or driver
  1494. * detect failure), then fw_restart module parameter
  1495. * need to be check before performing firmware reload
  1496. */
  1497. if (!external && !priv->cfg->mod_params->restart_fw) {
  1498. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  1499. "module parameter setting\n");
  1500. break;
  1501. }
  1502. IWL_ERR(priv, "On demand firmware reload\n");
  1503. /* Set the FW error flag -- cleared on iwl_down */
  1504. set_bit(STATUS_FW_ERROR, &priv->status);
  1505. wake_up_interruptible(&priv->wait_command_queue);
  1506. /*
  1507. * Keep the restart process from trying to send host
  1508. * commands by clearing the INIT status bit
  1509. */
  1510. clear_bit(STATUS_READY, &priv->status);
  1511. queue_work(priv->workqueue, &priv->restart);
  1512. break;
  1513. }
  1514. return 0;
  1515. }
  1516. int
  1517. iwl_legacy_mac_change_interface(struct ieee80211_hw *hw,
  1518. struct ieee80211_vif *vif,
  1519. enum nl80211_iftype newtype, bool newp2p)
  1520. {
  1521. struct iwl_priv *priv = hw->priv;
  1522. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  1523. struct iwl_rxon_context *tmp;
  1524. u32 interface_modes;
  1525. int err;
  1526. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1527. mutex_lock(&priv->mutex);
  1528. if (!ctx->vif || !iwl_legacy_is_ready_rf(priv)) {
  1529. /*
  1530. * Huh? But wait ... this can maybe happen when
  1531. * we're in the middle of a firmware restart!
  1532. */
  1533. err = -EBUSY;
  1534. goto out;
  1535. }
  1536. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1537. if (!(interface_modes & BIT(newtype))) {
  1538. err = -EBUSY;
  1539. goto out;
  1540. }
  1541. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1542. for_each_context(priv, tmp) {
  1543. if (ctx == tmp)
  1544. continue;
  1545. if (!tmp->vif)
  1546. continue;
  1547. /*
  1548. * The current mode switch would be exclusive, but
  1549. * another context is active ... refuse the switch.
  1550. */
  1551. err = -EBUSY;
  1552. goto out;
  1553. }
  1554. }
  1555. /* success */
  1556. iwl_legacy_teardown_interface(priv, vif, true);
  1557. vif->type = newtype;
  1558. vif->p2p = newp2p;
  1559. err = iwl_legacy_setup_interface(priv, ctx);
  1560. WARN_ON(err);
  1561. /*
  1562. * We've switched internally, but submitting to the
  1563. * device may have failed for some reason. Mask this
  1564. * error, because otherwise mac80211 will not switch
  1565. * (and set the interface type back) and we'll be
  1566. * out of sync with it.
  1567. */
  1568. err = 0;
  1569. out:
  1570. mutex_unlock(&priv->mutex);
  1571. return err;
  1572. }
  1573. EXPORT_SYMBOL(iwl_legacy_mac_change_interface);
  1574. /*
  1575. * On every watchdog tick we check (latest) time stamp. If it does not
  1576. * change during timeout period and queue is not empty we reset firmware.
  1577. */
  1578. static int iwl_legacy_check_stuck_queue(struct iwl_priv *priv, int cnt)
  1579. {
  1580. struct iwl_tx_queue *txq = &priv->txq[cnt];
  1581. struct iwl_queue *q = &txq->q;
  1582. unsigned long timeout;
  1583. int ret;
  1584. if (q->read_ptr == q->write_ptr) {
  1585. txq->time_stamp = jiffies;
  1586. return 0;
  1587. }
  1588. timeout = txq->time_stamp +
  1589. msecs_to_jiffies(priv->cfg->base_params->wd_timeout);
  1590. if (time_after(jiffies, timeout)) {
  1591. IWL_ERR(priv, "Queue %d stuck for %u ms.\n",
  1592. q->id, priv->cfg->base_params->wd_timeout);
  1593. ret = iwl_legacy_force_reset(priv, IWL_FW_RESET, false);
  1594. return (ret == -EAGAIN) ? 0 : 1;
  1595. }
  1596. return 0;
  1597. }
  1598. /*
  1599. * Making watchdog tick be a quarter of timeout assure we will
  1600. * discover the queue hung between timeout and 1.25*timeout
  1601. */
  1602. #define IWL_WD_TICK(timeout) ((timeout) / 4)
  1603. /*
  1604. * Watchdog timer callback, we check each tx queue for stuck, if if hung
  1605. * we reset the firmware. If everything is fine just rearm the timer.
  1606. */
  1607. void iwl_legacy_bg_watchdog(unsigned long data)
  1608. {
  1609. struct iwl_priv *priv = (struct iwl_priv *)data;
  1610. int cnt;
  1611. unsigned long timeout;
  1612. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1613. return;
  1614. timeout = priv->cfg->base_params->wd_timeout;
  1615. if (timeout == 0)
  1616. return;
  1617. /* monitor and check for stuck cmd queue */
  1618. if (iwl_legacy_check_stuck_queue(priv, priv->cmd_queue))
  1619. return;
  1620. /* monitor and check for other stuck queues */
  1621. if (iwl_legacy_is_any_associated(priv)) {
  1622. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  1623. /* skip as we already checked the command queue */
  1624. if (cnt == priv->cmd_queue)
  1625. continue;
  1626. if (iwl_legacy_check_stuck_queue(priv, cnt))
  1627. return;
  1628. }
  1629. }
  1630. mod_timer(&priv->watchdog, jiffies +
  1631. msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1632. }
  1633. EXPORT_SYMBOL(iwl_legacy_bg_watchdog);
  1634. void iwl_legacy_setup_watchdog(struct iwl_priv *priv)
  1635. {
  1636. unsigned int timeout = priv->cfg->base_params->wd_timeout;
  1637. if (timeout)
  1638. mod_timer(&priv->watchdog,
  1639. jiffies + msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1640. else
  1641. del_timer(&priv->watchdog);
  1642. }
  1643. EXPORT_SYMBOL(iwl_legacy_setup_watchdog);
  1644. /*
  1645. * extended beacon time format
  1646. * time in usec will be changed into a 32-bit value in extended:internal format
  1647. * the extended part is the beacon counts
  1648. * the internal part is the time in usec within one beacon interval
  1649. */
  1650. u32
  1651. iwl_legacy_usecs_to_beacons(struct iwl_priv *priv,
  1652. u32 usec, u32 beacon_interval)
  1653. {
  1654. u32 quot;
  1655. u32 rem;
  1656. u32 interval = beacon_interval * TIME_UNIT;
  1657. if (!interval || !usec)
  1658. return 0;
  1659. quot = (usec / interval) &
  1660. (iwl_legacy_beacon_time_mask_high(priv,
  1661. priv->hw_params.beacon_time_tsf_bits) >>
  1662. priv->hw_params.beacon_time_tsf_bits);
  1663. rem = (usec % interval) & iwl_legacy_beacon_time_mask_low(priv,
  1664. priv->hw_params.beacon_time_tsf_bits);
  1665. return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
  1666. }
  1667. EXPORT_SYMBOL(iwl_legacy_usecs_to_beacons);
  1668. /* base is usually what we get from ucode with each received frame,
  1669. * the same as HW timer counter counting down
  1670. */
  1671. __le32 iwl_legacy_add_beacon_time(struct iwl_priv *priv, u32 base,
  1672. u32 addon, u32 beacon_interval)
  1673. {
  1674. u32 base_low = base & iwl_legacy_beacon_time_mask_low(priv,
  1675. priv->hw_params.beacon_time_tsf_bits);
  1676. u32 addon_low = addon & iwl_legacy_beacon_time_mask_low(priv,
  1677. priv->hw_params.beacon_time_tsf_bits);
  1678. u32 interval = beacon_interval * TIME_UNIT;
  1679. u32 res = (base & iwl_legacy_beacon_time_mask_high(priv,
  1680. priv->hw_params.beacon_time_tsf_bits)) +
  1681. (addon & iwl_legacy_beacon_time_mask_high(priv,
  1682. priv->hw_params.beacon_time_tsf_bits));
  1683. if (base_low > addon_low)
  1684. res += base_low - addon_low;
  1685. else if (base_low < addon_low) {
  1686. res += interval + base_low - addon_low;
  1687. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  1688. } else
  1689. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  1690. return cpu_to_le32(res);
  1691. }
  1692. EXPORT_SYMBOL(iwl_legacy_add_beacon_time);
  1693. #ifdef CONFIG_PM
  1694. int iwl_legacy_pci_suspend(struct device *device)
  1695. {
  1696. struct pci_dev *pdev = to_pci_dev(device);
  1697. struct iwl_priv *priv = pci_get_drvdata(pdev);
  1698. /*
  1699. * This function is called when system goes into suspend state
  1700. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  1701. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  1702. * it will not call apm_ops.stop() to stop the DMA operation.
  1703. * Calling apm_ops.stop here to make sure we stop the DMA.
  1704. */
  1705. iwl_legacy_apm_stop(priv);
  1706. return 0;
  1707. }
  1708. EXPORT_SYMBOL(iwl_legacy_pci_suspend);
  1709. int iwl_legacy_pci_resume(struct device *device)
  1710. {
  1711. struct pci_dev *pdev = to_pci_dev(device);
  1712. struct iwl_priv *priv = pci_get_drvdata(pdev);
  1713. bool hw_rfkill = false;
  1714. /*
  1715. * We disable the RETRY_TIMEOUT register (0x41) to keep
  1716. * PCI Tx retries from interfering with C3 CPU state.
  1717. */
  1718. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1719. iwl_legacy_enable_interrupts(priv);
  1720. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1721. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1722. hw_rfkill = true;
  1723. if (hw_rfkill)
  1724. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1725. else
  1726. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1727. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
  1728. return 0;
  1729. }
  1730. EXPORT_SYMBOL(iwl_legacy_pci_resume);
  1731. const struct dev_pm_ops iwl_legacy_pm_ops = {
  1732. .suspend = iwl_legacy_pci_suspend,
  1733. .resume = iwl_legacy_pci_resume,
  1734. .freeze = iwl_legacy_pci_suspend,
  1735. .thaw = iwl_legacy_pci_resume,
  1736. .poweroff = iwl_legacy_pci_suspend,
  1737. .restore = iwl_legacy_pci_resume,
  1738. };
  1739. EXPORT_SYMBOL(iwl_legacy_pm_ops);
  1740. #endif /* CONFIG_PM */
  1741. static void
  1742. iwl_legacy_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1743. {
  1744. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1745. return;
  1746. if (!ctx->is_active)
  1747. return;
  1748. ctx->qos_data.def_qos_parm.qos_flags = 0;
  1749. if (ctx->qos_data.qos_active)
  1750. ctx->qos_data.def_qos_parm.qos_flags |=
  1751. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  1752. if (ctx->ht.enabled)
  1753. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  1754. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  1755. ctx->qos_data.qos_active,
  1756. ctx->qos_data.def_qos_parm.qos_flags);
  1757. iwl_legacy_send_cmd_pdu_async(priv, ctx->qos_cmd,
  1758. sizeof(struct iwl_qosparam_cmd),
  1759. &ctx->qos_data.def_qos_parm, NULL);
  1760. }
  1761. /**
  1762. * iwl_legacy_mac_config - mac80211 config callback
  1763. */
  1764. int iwl_legacy_mac_config(struct ieee80211_hw *hw, u32 changed)
  1765. {
  1766. struct iwl_priv *priv = hw->priv;
  1767. const struct iwl_channel_info *ch_info;
  1768. struct ieee80211_conf *conf = &hw->conf;
  1769. struct ieee80211_channel *channel = conf->channel;
  1770. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1771. struct iwl_rxon_context *ctx;
  1772. unsigned long flags = 0;
  1773. int ret = 0;
  1774. u16 ch;
  1775. int scan_active = 0;
  1776. bool ht_changed[NUM_IWL_RXON_CTX] = {};
  1777. if (WARN_ON(!priv->cfg->ops->legacy))
  1778. return -EOPNOTSUPP;
  1779. mutex_lock(&priv->mutex);
  1780. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  1781. channel->hw_value, changed);
  1782. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  1783. test_bit(STATUS_SCANNING, &priv->status))) {
  1784. scan_active = 1;
  1785. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  1786. }
  1787. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  1788. IEEE80211_CONF_CHANGE_CHANNEL)) {
  1789. /* mac80211 uses static for non-HT which is what we want */
  1790. priv->current_ht_config.smps = conf->smps_mode;
  1791. /*
  1792. * Recalculate chain counts.
  1793. *
  1794. * If monitor mode is enabled then mac80211 will
  1795. * set up the SM PS mode to OFF if an HT channel is
  1796. * configured.
  1797. */
  1798. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1799. for_each_context(priv, ctx)
  1800. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1801. }
  1802. /* during scanning mac80211 will delay channel setting until
  1803. * scan finish with changed = 0
  1804. */
  1805. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1806. if (scan_active)
  1807. goto set_ch_out;
  1808. ch = channel->hw_value;
  1809. ch_info = iwl_legacy_get_channel_info(priv, channel->band, ch);
  1810. if (!iwl_legacy_is_channel_valid(ch_info)) {
  1811. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  1812. ret = -EINVAL;
  1813. goto set_ch_out;
  1814. }
  1815. spin_lock_irqsave(&priv->lock, flags);
  1816. for_each_context(priv, ctx) {
  1817. /* Configure HT40 channels */
  1818. if (ctx->ht.enabled != conf_is_ht(conf)) {
  1819. ctx->ht.enabled = conf_is_ht(conf);
  1820. ht_changed[ctx->ctxid] = true;
  1821. }
  1822. if (ctx->ht.enabled) {
  1823. if (conf_is_ht40_minus(conf)) {
  1824. ctx->ht.extension_chan_offset =
  1825. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1826. ctx->ht.is_40mhz = true;
  1827. } else if (conf_is_ht40_plus(conf)) {
  1828. ctx->ht.extension_chan_offset =
  1829. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1830. ctx->ht.is_40mhz = true;
  1831. } else {
  1832. ctx->ht.extension_chan_offset =
  1833. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1834. ctx->ht.is_40mhz = false;
  1835. }
  1836. } else
  1837. ctx->ht.is_40mhz = false;
  1838. /*
  1839. * Default to no protection. Protection mode will
  1840. * later be set from BSS config in iwl_ht_conf
  1841. */
  1842. ctx->ht.protection =
  1843. IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  1844. /* if we are switching from ht to 2.4 clear flags
  1845. * from any ht related info since 2.4 does not
  1846. * support ht */
  1847. if ((le16_to_cpu(ctx->staging.channel) != ch))
  1848. ctx->staging.flags = 0;
  1849. iwl_legacy_set_rxon_channel(priv, channel, ctx);
  1850. iwl_legacy_set_rxon_ht(priv, ht_conf);
  1851. iwl_legacy_set_flags_for_band(priv, ctx, channel->band,
  1852. ctx->vif);
  1853. }
  1854. spin_unlock_irqrestore(&priv->lock, flags);
  1855. if (priv->cfg->ops->legacy->update_bcast_stations)
  1856. ret =
  1857. priv->cfg->ops->legacy->update_bcast_stations(priv);
  1858. set_ch_out:
  1859. /* The list of supported rates and rate mask can be different
  1860. * for each band; since the band may have changed, reset
  1861. * the rate mask to what mac80211 lists */
  1862. iwl_legacy_set_rate(priv);
  1863. }
  1864. if (changed & (IEEE80211_CONF_CHANGE_PS |
  1865. IEEE80211_CONF_CHANGE_IDLE)) {
  1866. ret = iwl_legacy_power_update_mode(priv, false);
  1867. if (ret)
  1868. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  1869. }
  1870. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1871. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  1872. priv->tx_power_user_lmt, conf->power_level);
  1873. iwl_legacy_set_tx_power(priv, conf->power_level, false);
  1874. }
  1875. if (!iwl_legacy_is_ready(priv)) {
  1876. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1877. goto out;
  1878. }
  1879. if (scan_active)
  1880. goto out;
  1881. for_each_context(priv, ctx) {
  1882. if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
  1883. iwl_legacy_commit_rxon(priv, ctx);
  1884. else
  1885. IWL_DEBUG_INFO(priv,
  1886. "Not re-sending same RXON configuration.\n");
  1887. if (ht_changed[ctx->ctxid])
  1888. iwl_legacy_update_qos(priv, ctx);
  1889. }
  1890. out:
  1891. IWL_DEBUG_MAC80211(priv, "leave\n");
  1892. mutex_unlock(&priv->mutex);
  1893. return ret;
  1894. }
  1895. EXPORT_SYMBOL(iwl_legacy_mac_config);
  1896. void iwl_legacy_mac_reset_tsf(struct ieee80211_hw *hw)
  1897. {
  1898. struct iwl_priv *priv = hw->priv;
  1899. unsigned long flags;
  1900. /* IBSS can only be the IWL_RXON_CTX_BSS context */
  1901. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1902. if (WARN_ON(!priv->cfg->ops->legacy))
  1903. return;
  1904. mutex_lock(&priv->mutex);
  1905. IWL_DEBUG_MAC80211(priv, "enter\n");
  1906. spin_lock_irqsave(&priv->lock, flags);
  1907. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
  1908. spin_unlock_irqrestore(&priv->lock, flags);
  1909. spin_lock_irqsave(&priv->lock, flags);
  1910. /* new association get rid of ibss beacon skb */
  1911. if (priv->beacon_skb)
  1912. dev_kfree_skb(priv->beacon_skb);
  1913. priv->beacon_skb = NULL;
  1914. priv->timestamp = 0;
  1915. spin_unlock_irqrestore(&priv->lock, flags);
  1916. iwl_legacy_scan_cancel_timeout(priv, 100);
  1917. if (!iwl_legacy_is_ready_rf(priv)) {
  1918. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1919. mutex_unlock(&priv->mutex);
  1920. return;
  1921. }
  1922. /* we are restarting association process
  1923. * clear RXON_FILTER_ASSOC_MSK bit
  1924. */
  1925. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1926. iwl_legacy_commit_rxon(priv, ctx);
  1927. iwl_legacy_set_rate(priv);
  1928. mutex_unlock(&priv->mutex);
  1929. IWL_DEBUG_MAC80211(priv, "leave\n");
  1930. }
  1931. EXPORT_SYMBOL(iwl_legacy_mac_reset_tsf);
  1932. static void iwl_legacy_ht_conf(struct iwl_priv *priv,
  1933. struct ieee80211_vif *vif)
  1934. {
  1935. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1936. struct ieee80211_sta *sta;
  1937. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1938. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  1939. IWL_DEBUG_ASSOC(priv, "enter:\n");
  1940. if (!ctx->ht.enabled)
  1941. return;
  1942. ctx->ht.protection =
  1943. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  1944. ctx->ht.non_gf_sta_present =
  1945. !!(bss_conf->ht_operation_mode &
  1946. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1947. ht_conf->single_chain_sufficient = false;
  1948. switch (vif->type) {
  1949. case NL80211_IFTYPE_STATION:
  1950. rcu_read_lock();
  1951. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  1952. if (sta) {
  1953. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1954. int maxstreams;
  1955. maxstreams = (ht_cap->mcs.tx_params &
  1956. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1957. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1958. maxstreams += 1;
  1959. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  1960. (ht_cap->mcs.rx_mask[2] == 0))
  1961. ht_conf->single_chain_sufficient = true;
  1962. if (maxstreams <= 1)
  1963. ht_conf->single_chain_sufficient = true;
  1964. } else {
  1965. /*
  1966. * If at all, this can only happen through a race
  1967. * when the AP disconnects us while we're still
  1968. * setting up the connection, in that case mac80211
  1969. * will soon tell us about that.
  1970. */
  1971. ht_conf->single_chain_sufficient = true;
  1972. }
  1973. rcu_read_unlock();
  1974. break;
  1975. case NL80211_IFTYPE_ADHOC:
  1976. ht_conf->single_chain_sufficient = true;
  1977. break;
  1978. default:
  1979. break;
  1980. }
  1981. IWL_DEBUG_ASSOC(priv, "leave\n");
  1982. }
  1983. static inline void iwl_legacy_set_no_assoc(struct iwl_priv *priv,
  1984. struct ieee80211_vif *vif)
  1985. {
  1986. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  1987. /*
  1988. * inform the ucode that there is no longer an
  1989. * association and that no more packets should be
  1990. * sent
  1991. */
  1992. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1993. ctx->staging.assoc_id = 0;
  1994. iwl_legacy_commit_rxon(priv, ctx);
  1995. }
  1996. static void iwl_legacy_beacon_update(struct ieee80211_hw *hw,
  1997. struct ieee80211_vif *vif)
  1998. {
  1999. struct iwl_priv *priv = hw->priv;
  2000. unsigned long flags;
  2001. __le64 timestamp;
  2002. struct sk_buff *skb = ieee80211_beacon_get(hw, vif);
  2003. if (!skb)
  2004. return;
  2005. IWL_DEBUG_MAC80211(priv, "enter\n");
  2006. lockdep_assert_held(&priv->mutex);
  2007. if (!priv->beacon_ctx) {
  2008. IWL_ERR(priv, "update beacon but no beacon context!\n");
  2009. dev_kfree_skb(skb);
  2010. return;
  2011. }
  2012. spin_lock_irqsave(&priv->lock, flags);
  2013. if (priv->beacon_skb)
  2014. dev_kfree_skb(priv->beacon_skb);
  2015. priv->beacon_skb = skb;
  2016. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  2017. priv->timestamp = le64_to_cpu(timestamp);
  2018. IWL_DEBUG_MAC80211(priv, "leave\n");
  2019. spin_unlock_irqrestore(&priv->lock, flags);
  2020. if (!iwl_legacy_is_ready_rf(priv)) {
  2021. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  2022. return;
  2023. }
  2024. priv->cfg->ops->legacy->post_associate(priv);
  2025. }
  2026. void iwl_legacy_mac_bss_info_changed(struct ieee80211_hw *hw,
  2027. struct ieee80211_vif *vif,
  2028. struct ieee80211_bss_conf *bss_conf,
  2029. u32 changes)
  2030. {
  2031. struct iwl_priv *priv = hw->priv;
  2032. struct iwl_rxon_context *ctx = iwl_legacy_rxon_ctx_from_vif(vif);
  2033. int ret;
  2034. if (WARN_ON(!priv->cfg->ops->legacy))
  2035. return;
  2036. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  2037. if (!iwl_legacy_is_alive(priv))
  2038. return;
  2039. mutex_lock(&priv->mutex);
  2040. if (changes & BSS_CHANGED_QOS) {
  2041. unsigned long flags;
  2042. spin_lock_irqsave(&priv->lock, flags);
  2043. ctx->qos_data.qos_active = bss_conf->qos;
  2044. iwl_legacy_update_qos(priv, ctx);
  2045. spin_unlock_irqrestore(&priv->lock, flags);
  2046. }
  2047. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  2048. /*
  2049. * the add_interface code must make sure we only ever
  2050. * have a single interface that could be beaconing at
  2051. * any time.
  2052. */
  2053. if (vif->bss_conf.enable_beacon)
  2054. priv->beacon_ctx = ctx;
  2055. else
  2056. priv->beacon_ctx = NULL;
  2057. }
  2058. if (changes & BSS_CHANGED_BSSID) {
  2059. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  2060. /*
  2061. * If there is currently a HW scan going on in the
  2062. * background then we need to cancel it else the RXON
  2063. * below/in post_associate will fail.
  2064. */
  2065. if (iwl_legacy_scan_cancel_timeout(priv, 100)) {
  2066. IWL_WARN(priv,
  2067. "Aborted scan still in progress after 100ms\n");
  2068. IWL_DEBUG_MAC80211(priv,
  2069. "leaving - scan abort failed.\n");
  2070. mutex_unlock(&priv->mutex);
  2071. return;
  2072. }
  2073. /* mac80211 only sets assoc when in STATION mode */
  2074. if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
  2075. memcpy(ctx->staging.bssid_addr,
  2076. bss_conf->bssid, ETH_ALEN);
  2077. /* currently needed in a few places */
  2078. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  2079. } else {
  2080. ctx->staging.filter_flags &=
  2081. ~RXON_FILTER_ASSOC_MSK;
  2082. }
  2083. }
  2084. /*
  2085. * This needs to be after setting the BSSID in case
  2086. * mac80211 decides to do both changes at once because
  2087. * it will invoke post_associate.
  2088. */
  2089. if (vif->type == NL80211_IFTYPE_ADHOC && changes & BSS_CHANGED_BEACON)
  2090. iwl_legacy_beacon_update(hw, vif);
  2091. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  2092. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  2093. bss_conf->use_short_preamble);
  2094. if (bss_conf->use_short_preamble)
  2095. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2096. else
  2097. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2098. }
  2099. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  2100. IWL_DEBUG_MAC80211(priv,
  2101. "ERP_CTS %d\n", bss_conf->use_cts_prot);
  2102. if (bss_conf->use_cts_prot &&
  2103. (priv->band != IEEE80211_BAND_5GHZ))
  2104. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  2105. else
  2106. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  2107. if (bss_conf->use_cts_prot)
  2108. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  2109. else
  2110. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  2111. }
  2112. if (changes & BSS_CHANGED_BASIC_RATES) {
  2113. /* XXX use this information
  2114. *
  2115. * To do that, remove code from iwl_legacy_set_rate() and put something
  2116. * like this here:
  2117. *
  2118. if (A-band)
  2119. ctx->staging.ofdm_basic_rates =
  2120. bss_conf->basic_rates;
  2121. else
  2122. ctx->staging.ofdm_basic_rates =
  2123. bss_conf->basic_rates >> 4;
  2124. ctx->staging.cck_basic_rates =
  2125. bss_conf->basic_rates & 0xF;
  2126. */
  2127. }
  2128. if (changes & BSS_CHANGED_HT) {
  2129. iwl_legacy_ht_conf(priv, vif);
  2130. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2131. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  2132. }
  2133. if (changes & BSS_CHANGED_ASSOC) {
  2134. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  2135. if (bss_conf->assoc) {
  2136. priv->timestamp = bss_conf->timestamp;
  2137. if (!iwl_legacy_is_rfkill(priv))
  2138. priv->cfg->ops->legacy->post_associate(priv);
  2139. } else
  2140. iwl_legacy_set_no_assoc(priv, vif);
  2141. }
  2142. if (changes && iwl_legacy_is_associated_ctx(ctx) && bss_conf->aid) {
  2143. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  2144. changes);
  2145. ret = iwl_legacy_send_rxon_assoc(priv, ctx);
  2146. if (!ret) {
  2147. /* Sync active_rxon with latest change. */
  2148. memcpy((void *)&ctx->active,
  2149. &ctx->staging,
  2150. sizeof(struct iwl_legacy_rxon_cmd));
  2151. }
  2152. }
  2153. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  2154. if (vif->bss_conf.enable_beacon) {
  2155. memcpy(ctx->staging.bssid_addr,
  2156. bss_conf->bssid, ETH_ALEN);
  2157. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  2158. priv->cfg->ops->legacy->config_ap(priv);
  2159. } else
  2160. iwl_legacy_set_no_assoc(priv, vif);
  2161. }
  2162. if (changes & BSS_CHANGED_IBSS) {
  2163. ret = priv->cfg->ops->legacy->manage_ibss_station(priv, vif,
  2164. bss_conf->ibss_joined);
  2165. if (ret)
  2166. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  2167. bss_conf->ibss_joined ? "add" : "remove",
  2168. bss_conf->bssid);
  2169. }
  2170. mutex_unlock(&priv->mutex);
  2171. IWL_DEBUG_MAC80211(priv, "leave\n");
  2172. }
  2173. EXPORT_SYMBOL(iwl_legacy_mac_bss_info_changed);
  2174. irqreturn_t iwl_legacy_isr(int irq, void *data)
  2175. {
  2176. struct iwl_priv *priv = data;
  2177. u32 inta, inta_mask;
  2178. u32 inta_fh;
  2179. unsigned long flags;
  2180. if (!priv)
  2181. return IRQ_NONE;
  2182. spin_lock_irqsave(&priv->lock, flags);
  2183. /* Disable (but don't clear!) interrupts here to avoid
  2184. * back-to-back ISRs and sporadic interrupts from our NIC.
  2185. * If we have something to service, the tasklet will re-enable ints.
  2186. * If we *don't* have something, we'll re-enable before leaving here. */
  2187. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2188. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2189. /* Discover which interrupts are active/pending */
  2190. inta = iwl_read32(priv, CSR_INT);
  2191. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2192. /* Ignore interrupt if there's nothing in NIC to service.
  2193. * This may be due to IRQ shared with another device,
  2194. * or due to sporadic interrupts thrown from our NIC. */
  2195. if (!inta && !inta_fh) {
  2196. IWL_DEBUG_ISR(priv,
  2197. "Ignore interrupt, inta == 0, inta_fh == 0\n");
  2198. goto none;
  2199. }
  2200. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2201. /* Hardware disappeared. It might have already raised
  2202. * an interrupt */
  2203. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  2204. goto unplugged;
  2205. }
  2206. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2207. inta, inta_mask, inta_fh);
  2208. inta &= ~CSR_INT_BIT_SCD;
  2209. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  2210. if (likely(inta || inta_fh))
  2211. tasklet_schedule(&priv->irq_tasklet);
  2212. unplugged:
  2213. spin_unlock_irqrestore(&priv->lock, flags);
  2214. return IRQ_HANDLED;
  2215. none:
  2216. /* re-enable interrupts here since we don't have anything to service. */
  2217. /* only Re-enable if diabled by irq */
  2218. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2219. iwl_legacy_enable_interrupts(priv);
  2220. spin_unlock_irqrestore(&priv->lock, flags);
  2221. return IRQ_NONE;
  2222. }
  2223. EXPORT_SYMBOL(iwl_legacy_isr);
  2224. /*
  2225. * iwl_legacy_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
  2226. * function.
  2227. */
  2228. void iwl_legacy_tx_cmd_protection(struct iwl_priv *priv,
  2229. struct ieee80211_tx_info *info,
  2230. __le16 fc, __le32 *tx_flags)
  2231. {
  2232. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  2233. *tx_flags |= TX_CMD_FLG_RTS_MSK;
  2234. *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  2235. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  2236. if (!ieee80211_is_mgmt(fc))
  2237. return;
  2238. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  2239. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2240. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2241. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  2242. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  2243. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2244. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  2245. break;
  2246. }
  2247. } else if (info->control.rates[0].flags &
  2248. IEEE80211_TX_RC_USE_CTS_PROTECT) {
  2249. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2250. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  2251. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  2252. }
  2253. }
  2254. EXPORT_SYMBOL(iwl_legacy_tx_cmd_protection);