iwl-core.c 73 KB

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