iwl-eeprom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *****************************************************************************/
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/slab.h>
  65. #include <linux/init.h>
  66. #include <net/mac80211.h>
  67. #include "iwl-commands.h"
  68. #include "iwl-dev.h"
  69. #include "iwl-core.h"
  70. #include "iwl-debug.h"
  71. #include "iwl-eeprom.h"
  72. #include "iwl-io.h"
  73. /************************** EEPROM BANDS ****************************
  74. *
  75. * The iwlegacy_eeprom_band definitions below provide the mapping from the
  76. * EEPROM contents to the specific channel number supported for each
  77. * band.
  78. *
  79. * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
  80. * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  81. * The specific geography and calibration information for that channel
  82. * is contained in the eeprom map itself.
  83. *
  84. * During init, we copy the eeprom information and channel map
  85. * information into priv->channel_info_24/52 and priv->channel_map_24/52
  86. *
  87. * channel_map_24/52 provides the index in the channel_info array for a
  88. * given channel. We have to have two separate maps as there is channel
  89. * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
  90. * band_2
  91. *
  92. * A value of 0xff stored in the channel_map indicates that the channel
  93. * is not supported by the hardware at all.
  94. *
  95. * A value of 0xfe in the channel_map indicates that the channel is not
  96. * valid for Tx with the current hardware. This means that
  97. * while the system can tune and receive on a given channel, it may not
  98. * be able to associate or transmit any frames on that
  99. * channel. There is no corresponding channel information for that
  100. * entry.
  101. *
  102. *********************************************************************/
  103. /* 2.4 GHz */
  104. const u8 iwlegacy_eeprom_band_1[14] = {
  105. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  106. };
  107. /* 5.2 GHz bands */
  108. static const u8 iwlegacy_eeprom_band_2[] = { /* 4915-5080MHz */
  109. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  110. };
  111. static const u8 iwlegacy_eeprom_band_3[] = { /* 5170-5320MHz */
  112. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  113. };
  114. static const u8 iwlegacy_eeprom_band_4[] = { /* 5500-5700MHz */
  115. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  116. };
  117. static const u8 iwlegacy_eeprom_band_5[] = { /* 5725-5825MHz */
  118. 145, 149, 153, 157, 161, 165
  119. };
  120. static const u8 iwlegacy_eeprom_band_6[] = { /* 2.4 ht40 channel */
  121. 1, 2, 3, 4, 5, 6, 7
  122. };
  123. static const u8 iwlegacy_eeprom_band_7[] = { /* 5.2 ht40 channel */
  124. 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
  125. };
  126. /******************************************************************************
  127. *
  128. * EEPROM related functions
  129. *
  130. ******************************************************************************/
  131. static int iwl_legacy_eeprom_verify_signature(struct iwl_priv *priv)
  132. {
  133. u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
  134. int ret = 0;
  135. IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
  136. switch (gp) {
  137. case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
  138. case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
  139. break;
  140. default:
  141. IWL_ERR(priv, "bad EEPROM signature,"
  142. "EEPROM_GP=0x%08x\n", gp);
  143. ret = -ENOENT;
  144. break;
  145. }
  146. return ret;
  147. }
  148. const u8
  149. *iwl_legacy_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  150. {
  151. BUG_ON(offset >= priv->cfg->base_params->eeprom_size);
  152. return &priv->eeprom[offset];
  153. }
  154. EXPORT_SYMBOL(iwl_legacy_eeprom_query_addr);
  155. u16 iwl_legacy_eeprom_query16(const struct iwl_priv *priv, size_t offset)
  156. {
  157. if (!priv->eeprom)
  158. return 0;
  159. return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
  160. }
  161. EXPORT_SYMBOL(iwl_legacy_eeprom_query16);
  162. /**
  163. * iwl_legacy_eeprom_init - read EEPROM contents
  164. *
  165. * Load the EEPROM contents from adapter into priv->eeprom
  166. *
  167. * NOTE: This routine uses the non-debug IO access functions.
  168. */
  169. int iwl_legacy_eeprom_init(struct iwl_priv *priv)
  170. {
  171. __le16 *e;
  172. u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
  173. int sz;
  174. int ret;
  175. u16 addr;
  176. /* allocate eeprom */
  177. sz = priv->cfg->base_params->eeprom_size;
  178. IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
  179. priv->eeprom = kzalloc(sz, GFP_KERNEL);
  180. if (!priv->eeprom) {
  181. ret = -ENOMEM;
  182. goto alloc_err;
  183. }
  184. e = (__le16 *)priv->eeprom;
  185. priv->cfg->ops->lib->apm_ops.init(priv);
  186. ret = iwl_legacy_eeprom_verify_signature(priv);
  187. if (ret < 0) {
  188. IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
  189. ret = -ENOENT;
  190. goto err;
  191. }
  192. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  193. ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
  194. if (ret < 0) {
  195. IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
  196. ret = -ENOENT;
  197. goto err;
  198. }
  199. /* eeprom is an array of 16bit values */
  200. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  201. u32 r;
  202. _iwl_legacy_write32(priv, CSR_EEPROM_REG,
  203. CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
  204. ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
  205. CSR_EEPROM_REG_READ_VALID_MSK,
  206. CSR_EEPROM_REG_READ_VALID_MSK,
  207. IWL_EEPROM_ACCESS_TIMEOUT);
  208. if (ret < 0) {
  209. IWL_ERR(priv, "Time out reading EEPROM[%d]\n",
  210. addr);
  211. goto done;
  212. }
  213. r = _iwl_legacy_read_direct32(priv, CSR_EEPROM_REG);
  214. e[addr / 2] = cpu_to_le16(r >> 16);
  215. }
  216. IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
  217. "EEPROM",
  218. iwl_legacy_eeprom_query16(priv, EEPROM_VERSION));
  219. ret = 0;
  220. done:
  221. priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
  222. err:
  223. if (ret)
  224. iwl_legacy_eeprom_free(priv);
  225. /* Reset chip to save power until we load uCode during "up". */
  226. iwl_legacy_apm_stop(priv);
  227. alloc_err:
  228. return ret;
  229. }
  230. EXPORT_SYMBOL(iwl_legacy_eeprom_init);
  231. void iwl_legacy_eeprom_free(struct iwl_priv *priv)
  232. {
  233. kfree(priv->eeprom);
  234. priv->eeprom = NULL;
  235. }
  236. EXPORT_SYMBOL(iwl_legacy_eeprom_free);
  237. static void iwl_legacy_init_band_reference(const struct iwl_priv *priv,
  238. int eep_band, int *eeprom_ch_count,
  239. const struct iwl_eeprom_channel **eeprom_ch_info,
  240. const u8 **eeprom_ch_index)
  241. {
  242. u32 offset = priv->cfg->ops->lib->
  243. eeprom_ops.regulatory_bands[eep_band - 1];
  244. switch (eep_band) {
  245. case 1: /* 2.4GHz band */
  246. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_1);
  247. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  248. iwl_legacy_eeprom_query_addr(priv, offset);
  249. *eeprom_ch_index = iwlegacy_eeprom_band_1;
  250. break;
  251. case 2: /* 4.9GHz band */
  252. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_2);
  253. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  254. iwl_legacy_eeprom_query_addr(priv, offset);
  255. *eeprom_ch_index = iwlegacy_eeprom_band_2;
  256. break;
  257. case 3: /* 5.2GHz band */
  258. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_3);
  259. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  260. iwl_legacy_eeprom_query_addr(priv, offset);
  261. *eeprom_ch_index = iwlegacy_eeprom_band_3;
  262. break;
  263. case 4: /* 5.5GHz band */
  264. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_4);
  265. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  266. iwl_legacy_eeprom_query_addr(priv, offset);
  267. *eeprom_ch_index = iwlegacy_eeprom_band_4;
  268. break;
  269. case 5: /* 5.7GHz band */
  270. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_5);
  271. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  272. iwl_legacy_eeprom_query_addr(priv, offset);
  273. *eeprom_ch_index = iwlegacy_eeprom_band_5;
  274. break;
  275. case 6: /* 2.4GHz ht40 channels */
  276. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_6);
  277. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  278. iwl_legacy_eeprom_query_addr(priv, offset);
  279. *eeprom_ch_index = iwlegacy_eeprom_band_6;
  280. break;
  281. case 7: /* 5 GHz ht40 channels */
  282. *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_7);
  283. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  284. iwl_legacy_eeprom_query_addr(priv, offset);
  285. *eeprom_ch_index = iwlegacy_eeprom_band_7;
  286. break;
  287. default:
  288. BUG();
  289. return;
  290. }
  291. }
  292. #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
  293. ? # x " " : "")
  294. /**
  295. * iwl_legacy_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
  296. *
  297. * Does not set up a command, or touch hardware.
  298. */
  299. static int iwl_legacy_mod_ht40_chan_info(struct iwl_priv *priv,
  300. enum ieee80211_band band, u16 channel,
  301. const struct iwl_eeprom_channel *eeprom_ch,
  302. u8 clear_ht40_extension_channel)
  303. {
  304. struct iwl_channel_info *ch_info;
  305. ch_info = (struct iwl_channel_info *)
  306. iwl_legacy_get_channel_info(priv, band, channel);
  307. if (!iwl_legacy_is_channel_valid(ch_info))
  308. return -1;
  309. IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
  310. " Ad-Hoc %ssupported\n",
  311. ch_info->channel,
  312. iwl_legacy_is_channel_a_band(ch_info) ?
  313. "5.2" : "2.4",
  314. CHECK_AND_PRINT(IBSS),
  315. CHECK_AND_PRINT(ACTIVE),
  316. CHECK_AND_PRINT(RADAR),
  317. CHECK_AND_PRINT(WIDE),
  318. CHECK_AND_PRINT(DFS),
  319. eeprom_ch->flags,
  320. eeprom_ch->max_power_avg,
  321. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
  322. && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
  323. "" : "not ");
  324. ch_info->ht40_eeprom = *eeprom_ch;
  325. ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
  326. ch_info->ht40_flags = eeprom_ch->flags;
  327. if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
  328. ch_info->ht40_extension_channel &=
  329. ~clear_ht40_extension_channel;
  330. return 0;
  331. }
  332. #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  333. ? # x " " : "")
  334. /**
  335. * iwl_legacy_init_channel_map - Set up driver's info for all possible channels
  336. */
  337. int iwl_legacy_init_channel_map(struct iwl_priv *priv)
  338. {
  339. int eeprom_ch_count = 0;
  340. const u8 *eeprom_ch_index = NULL;
  341. const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
  342. int band, ch;
  343. struct iwl_channel_info *ch_info;
  344. if (priv->channel_count) {
  345. IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
  346. return 0;
  347. }
  348. IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
  349. priv->channel_count =
  350. ARRAY_SIZE(iwlegacy_eeprom_band_1) +
  351. ARRAY_SIZE(iwlegacy_eeprom_band_2) +
  352. ARRAY_SIZE(iwlegacy_eeprom_band_3) +
  353. ARRAY_SIZE(iwlegacy_eeprom_band_4) +
  354. ARRAY_SIZE(iwlegacy_eeprom_band_5);
  355. IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
  356. priv->channel_count);
  357. priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
  358. priv->channel_count, GFP_KERNEL);
  359. if (!priv->channel_info) {
  360. IWL_ERR(priv, "Could not allocate channel_info\n");
  361. priv->channel_count = 0;
  362. return -ENOMEM;
  363. }
  364. ch_info = priv->channel_info;
  365. /* Loop through the 5 EEPROM bands adding them in order to the
  366. * channel map we maintain (that contains additional information than
  367. * what just in the EEPROM) */
  368. for (band = 1; band <= 5; band++) {
  369. iwl_legacy_init_band_reference(priv, band, &eeprom_ch_count,
  370. &eeprom_ch_info, &eeprom_ch_index);
  371. /* Loop through each band adding each of the channels */
  372. for (ch = 0; ch < eeprom_ch_count; ch++) {
  373. ch_info->channel = eeprom_ch_index[ch];
  374. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  375. IEEE80211_BAND_5GHZ;
  376. /* permanently store EEPROM's channel regulatory flags
  377. * and max power in channel info database. */
  378. ch_info->eeprom = eeprom_ch_info[ch];
  379. /* Copy the run-time flags so they are there even on
  380. * invalid channels */
  381. ch_info->flags = eeprom_ch_info[ch].flags;
  382. /* First write that ht40 is not enabled, and then enable
  383. * one by one */
  384. ch_info->ht40_extension_channel =
  385. IEEE80211_CHAN_NO_HT40;
  386. if (!(iwl_legacy_is_channel_valid(ch_info))) {
  387. IWL_DEBUG_EEPROM(priv,
  388. "Ch. %d Flags %x [%sGHz] - "
  389. "No traffic\n",
  390. ch_info->channel,
  391. ch_info->flags,
  392. iwl_legacy_is_channel_a_band(ch_info) ?
  393. "5.2" : "2.4");
  394. ch_info++;
  395. continue;
  396. }
  397. /* Initialize regulatory-based run-time data */
  398. ch_info->max_power_avg = ch_info->curr_txpow =
  399. eeprom_ch_info[ch].max_power_avg;
  400. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  401. ch_info->min_power = 0;
  402. IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
  403. "%s%s%s%s%s%s(0x%02x %ddBm):"
  404. " Ad-Hoc %ssupported\n",
  405. ch_info->channel,
  406. iwl_legacy_is_channel_a_band(ch_info) ?
  407. "5.2" : "2.4",
  408. CHECK_AND_PRINT_I(VALID),
  409. CHECK_AND_PRINT_I(IBSS),
  410. CHECK_AND_PRINT_I(ACTIVE),
  411. CHECK_AND_PRINT_I(RADAR),
  412. CHECK_AND_PRINT_I(WIDE),
  413. CHECK_AND_PRINT_I(DFS),
  414. eeprom_ch_info[ch].flags,
  415. eeprom_ch_info[ch].max_power_avg,
  416. ((eeprom_ch_info[ch].
  417. flags & EEPROM_CHANNEL_IBSS)
  418. && !(eeprom_ch_info[ch].
  419. flags & EEPROM_CHANNEL_RADAR))
  420. ? "" : "not ");
  421. ch_info++;
  422. }
  423. }
  424. /* Check if we do have HT40 channels */
  425. if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
  426. EEPROM_REGULATORY_BAND_NO_HT40 &&
  427. priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
  428. EEPROM_REGULATORY_BAND_NO_HT40)
  429. return 0;
  430. /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
  431. for (band = 6; band <= 7; band++) {
  432. enum ieee80211_band ieeeband;
  433. iwl_legacy_init_band_reference(priv, band, &eeprom_ch_count,
  434. &eeprom_ch_info, &eeprom_ch_index);
  435. /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
  436. ieeeband =
  437. (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  438. /* Loop through each band adding each of the channels */
  439. for (ch = 0; ch < eeprom_ch_count; ch++) {
  440. /* Set up driver's info for lower half */
  441. iwl_legacy_mod_ht40_chan_info(priv, ieeeband,
  442. eeprom_ch_index[ch],
  443. &eeprom_ch_info[ch],
  444. IEEE80211_CHAN_NO_HT40PLUS);
  445. /* Set up driver's info for upper half */
  446. iwl_legacy_mod_ht40_chan_info(priv, ieeeband,
  447. eeprom_ch_index[ch] + 4,
  448. &eeprom_ch_info[ch],
  449. IEEE80211_CHAN_NO_HT40MINUS);
  450. }
  451. }
  452. return 0;
  453. }
  454. EXPORT_SYMBOL(iwl_legacy_init_channel_map);
  455. /*
  456. * iwl_legacy_free_channel_map - undo allocations in iwl_legacy_init_channel_map
  457. */
  458. void iwl_legacy_free_channel_map(struct iwl_priv *priv)
  459. {
  460. kfree(priv->channel_info);
  461. priv->channel_count = 0;
  462. }
  463. EXPORT_SYMBOL(iwl_legacy_free_channel_map);
  464. /**
  465. * iwl_legacy_get_channel_info - Find driver's private channel info
  466. *
  467. * Based on band and channel number.
  468. */
  469. const struct
  470. iwl_channel_info *iwl_legacy_get_channel_info(const struct iwl_priv *priv,
  471. enum ieee80211_band band, u16 channel)
  472. {
  473. int i;
  474. switch (band) {
  475. case IEEE80211_BAND_5GHZ:
  476. for (i = 14; i < priv->channel_count; i++) {
  477. if (priv->channel_info[i].channel == channel)
  478. return &priv->channel_info[i];
  479. }
  480. break;
  481. case IEEE80211_BAND_2GHZ:
  482. if (channel >= 1 && channel <= 14)
  483. return &priv->channel_info[channel - 1];
  484. break;
  485. default:
  486. BUG();
  487. }
  488. return NULL;
  489. }
  490. EXPORT_SYMBOL(iwl_legacy_get_channel_info);