iwl-eeprom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 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. * Tomas Winkler <tomas.winkler@intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2008 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/version.h>
  65. #include <linux/init.h>
  66. #include <net/mac80211.h>
  67. #include "iwl-4965-commands.h"
  68. #include "iwl-4965.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 iwl_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 iwl_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 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
  109. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  110. };
  111. static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
  112. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  113. };
  114. static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
  115. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  116. };
  117. static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
  118. 145, 149, 153, 157, 161, 165
  119. };
  120. static const u8 iwl_eeprom_band_6[] = { /* 2.4 FAT channel */
  121. 1, 2, 3, 4, 5, 6, 7
  122. };
  123. static const u8 iwl_eeprom_band_7[] = { /* 5.2 FAT channel */
  124. 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
  125. };
  126. /******************************************************************************
  127. *
  128. * EEPROM related functions
  129. *
  130. ******************************************************************************/
  131. int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
  132. {
  133. u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
  134. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  135. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  136. return -ENOENT;
  137. }
  138. return 0;
  139. }
  140. EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
  141. /*
  142. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  143. * when accessing the EEPROM; each access is a series of pulses to/from the
  144. * EEPROM chip, not a single event, so even reads could conflict if they
  145. * weren't arbitrated by the semaphore.
  146. */
  147. int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
  148. {
  149. u16 count;
  150. int ret;
  151. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  152. /* Request semaphore */
  153. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  154. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  155. /* See if we got it */
  156. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  157. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  158. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  159. EEPROM_SEM_TIMEOUT);
  160. if (ret >= 0) {
  161. IWL_DEBUG_IO("Acquired semaphore after %d tries.\n",
  162. count+1);
  163. return ret;
  164. }
  165. }
  166. return ret;
  167. }
  168. EXPORT_SYMBOL(iwlcore_eeprom_acquire_semaphore);
  169. void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
  170. {
  171. iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  172. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  173. }
  174. EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
  175. /**
  176. * iwl_eeprom_init - read EEPROM contents
  177. *
  178. * Load the EEPROM contents from adapter into priv->eeprom
  179. *
  180. * NOTE: This routine uses the non-debug IO access functions.
  181. */
  182. int iwl_eeprom_init(struct iwl_priv *priv)
  183. {
  184. u16 *e = (u16 *)&priv->eeprom;
  185. u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
  186. u32 r;
  187. int sz = sizeof(priv->eeprom);
  188. int ret;
  189. int i;
  190. u16 addr;
  191. /* The EEPROM structure has several padding buffers within it
  192. * and when adding new EEPROM maps is subject to programmer errors
  193. * which may be very difficult to identify without explicitly
  194. * checking the resulting size of the eeprom map. */
  195. BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
  196. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  197. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  198. return -ENOENT;
  199. }
  200. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  201. ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
  202. if (ret < 0) {
  203. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  204. return -ENOENT;
  205. }
  206. /* eeprom is an array of 16bit values */
  207. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  208. _iwl_write32(priv, CSR_EEPROM_REG, addr << 1);
  209. _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  210. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  211. i += IWL_EEPROM_ACCESS_DELAY) {
  212. r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
  213. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  214. break;
  215. udelay(IWL_EEPROM_ACCESS_DELAY);
  216. }
  217. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  218. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  219. ret = -ETIMEDOUT;
  220. goto done;
  221. }
  222. e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
  223. }
  224. ret = 0;
  225. done:
  226. priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
  227. return ret;
  228. }
  229. EXPORT_SYMBOL(iwl_eeprom_init);
  230. void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
  231. {
  232. memcpy(mac, priv->eeprom.mac_address, 6);
  233. }
  234. EXPORT_SYMBOL(iwl_eeprom_get_mac);
  235. static void iwl_init_band_reference(const struct iwl_priv *priv,
  236. int band,
  237. int *eeprom_ch_count,
  238. const struct iwl4965_eeprom_channel
  239. **eeprom_ch_info,
  240. const u8 **eeprom_ch_index)
  241. {
  242. switch (band) {
  243. case 1: /* 2.4GHz band */
  244. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
  245. *eeprom_ch_info = priv->eeprom.band_1_channels;
  246. *eeprom_ch_index = iwl_eeprom_band_1;
  247. break;
  248. case 2: /* 4.9GHz band */
  249. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
  250. *eeprom_ch_info = priv->eeprom.band_2_channels;
  251. *eeprom_ch_index = iwl_eeprom_band_2;
  252. break;
  253. case 3: /* 5.2GHz band */
  254. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
  255. *eeprom_ch_info = priv->eeprom.band_3_channels;
  256. *eeprom_ch_index = iwl_eeprom_band_3;
  257. break;
  258. case 4: /* 5.5GHz band */
  259. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
  260. *eeprom_ch_info = priv->eeprom.band_4_channels;
  261. *eeprom_ch_index = iwl_eeprom_band_4;
  262. break;
  263. case 5: /* 5.7GHz band */
  264. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
  265. *eeprom_ch_info = priv->eeprom.band_5_channels;
  266. *eeprom_ch_index = iwl_eeprom_band_5;
  267. break;
  268. case 6: /* 2.4GHz FAT channels */
  269. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
  270. *eeprom_ch_info = priv->eeprom.band_24_channels;
  271. *eeprom_ch_index = iwl_eeprom_band_6;
  272. break;
  273. case 7: /* 5 GHz FAT channels */
  274. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
  275. *eeprom_ch_info = priv->eeprom.band_52_channels;
  276. *eeprom_ch_index = iwl_eeprom_band_7;
  277. break;
  278. default:
  279. BUG();
  280. return;
  281. }
  282. }
  283. #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
  284. ? # x " " : "")
  285. /**
  286. * iwl4965_set_fat_chan_info - Copy fat channel info into driver's priv.
  287. *
  288. * Does not set up a command, or touch hardware.
  289. */
  290. static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
  291. enum ieee80211_band band, u16 channel,
  292. const struct iwl4965_eeprom_channel *eeprom_ch,
  293. u8 fat_extension_channel)
  294. {
  295. struct iwl_channel_info *ch_info;
  296. ch_info = (struct iwl_channel_info *)
  297. iwl_get_channel_info(priv, band, channel);
  298. if (!is_channel_valid(ch_info))
  299. return -1;
  300. IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
  301. " %ddBm): Ad-Hoc %ssupported\n",
  302. ch_info->channel,
  303. is_channel_a_band(ch_info) ?
  304. "5.2" : "2.4",
  305. CHECK_AND_PRINT(IBSS),
  306. CHECK_AND_PRINT(ACTIVE),
  307. CHECK_AND_PRINT(RADAR),
  308. CHECK_AND_PRINT(WIDE),
  309. CHECK_AND_PRINT(NARROW),
  310. CHECK_AND_PRINT(DFS),
  311. eeprom_ch->flags,
  312. eeprom_ch->max_power_avg,
  313. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
  314. && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
  315. "" : "not ");
  316. ch_info->fat_eeprom = *eeprom_ch;
  317. ch_info->fat_max_power_avg = eeprom_ch->max_power_avg;
  318. ch_info->fat_curr_txpow = eeprom_ch->max_power_avg;
  319. ch_info->fat_min_power = 0;
  320. ch_info->fat_scan_power = eeprom_ch->max_power_avg;
  321. ch_info->fat_flags = eeprom_ch->flags;
  322. ch_info->fat_extension_channel = fat_extension_channel;
  323. return 0;
  324. }
  325. #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  326. ? # x " " : "")
  327. /**
  328. * iwl_init_channel_map - Set up driver's info for all possible channels
  329. */
  330. int iwl_init_channel_map(struct iwl_priv *priv)
  331. {
  332. int eeprom_ch_count = 0;
  333. const u8 *eeprom_ch_index = NULL;
  334. const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
  335. int band, ch;
  336. struct iwl_channel_info *ch_info;
  337. if (priv->channel_count) {
  338. IWL_DEBUG_INFO("Channel map already initialized.\n");
  339. return 0;
  340. }
  341. if (priv->eeprom.version < 0x2f) {
  342. IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
  343. priv->eeprom.version);
  344. return -EINVAL;
  345. }
  346. IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
  347. priv->channel_count =
  348. ARRAY_SIZE(iwl_eeprom_band_1) +
  349. ARRAY_SIZE(iwl_eeprom_band_2) +
  350. ARRAY_SIZE(iwl_eeprom_band_3) +
  351. ARRAY_SIZE(iwl_eeprom_band_4) +
  352. ARRAY_SIZE(iwl_eeprom_band_5);
  353. IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
  354. priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
  355. priv->channel_count, GFP_KERNEL);
  356. if (!priv->channel_info) {
  357. IWL_ERROR("Could not allocate channel_info\n");
  358. priv->channel_count = 0;
  359. return -ENOMEM;
  360. }
  361. ch_info = priv->channel_info;
  362. /* Loop through the 5 EEPROM bands adding them in order to the
  363. * channel map we maintain (that contains additional information than
  364. * what just in the EEPROM) */
  365. for (band = 1; band <= 5; band++) {
  366. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  367. &eeprom_ch_info, &eeprom_ch_index);
  368. /* Loop through each band adding each of the channels */
  369. for (ch = 0; ch < eeprom_ch_count; ch++) {
  370. ch_info->channel = eeprom_ch_index[ch];
  371. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  372. IEEE80211_BAND_5GHZ;
  373. /* permanently store EEPROM's channel regulatory flags
  374. * and max power in channel info database. */
  375. ch_info->eeprom = eeprom_ch_info[ch];
  376. /* Copy the run-time flags so they are there even on
  377. * invalid channels */
  378. ch_info->flags = eeprom_ch_info[ch].flags;
  379. if (!(is_channel_valid(ch_info))) {
  380. IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
  381. "No traffic\n",
  382. ch_info->channel,
  383. ch_info->flags,
  384. is_channel_a_band(ch_info) ?
  385. "5.2" : "2.4");
  386. ch_info++;
  387. continue;
  388. }
  389. /* Initialize regulatory-based run-time data */
  390. ch_info->max_power_avg = ch_info->curr_txpow =
  391. eeprom_ch_info[ch].max_power_avg;
  392. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  393. ch_info->min_power = 0;
  394. IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x"
  395. " %ddBm): Ad-Hoc %ssupported\n",
  396. ch_info->channel,
  397. is_channel_a_band(ch_info) ?
  398. "5.2" : "2.4",
  399. CHECK_AND_PRINT_I(VALID),
  400. CHECK_AND_PRINT_I(IBSS),
  401. CHECK_AND_PRINT_I(ACTIVE),
  402. CHECK_AND_PRINT_I(RADAR),
  403. CHECK_AND_PRINT_I(WIDE),
  404. CHECK_AND_PRINT_I(NARROW),
  405. CHECK_AND_PRINT_I(DFS),
  406. eeprom_ch_info[ch].flags,
  407. eeprom_ch_info[ch].max_power_avg,
  408. ((eeprom_ch_info[ch].
  409. flags & EEPROM_CHANNEL_IBSS)
  410. && !(eeprom_ch_info[ch].
  411. flags & EEPROM_CHANNEL_RADAR))
  412. ? "" : "not ");
  413. /* Set the user_txpower_limit to the highest power
  414. * supported by any channel */
  415. if (eeprom_ch_info[ch].max_power_avg >
  416. priv->user_txpower_limit)
  417. priv->user_txpower_limit =
  418. eeprom_ch_info[ch].max_power_avg;
  419. ch_info++;
  420. }
  421. }
  422. /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
  423. for (band = 6; band <= 7; band++) {
  424. enum ieee80211_band ieeeband;
  425. u8 fat_extension_chan;
  426. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  427. &eeprom_ch_info, &eeprom_ch_index);
  428. /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
  429. ieeeband =
  430. (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  431. /* Loop through each band adding each of the channels */
  432. for (ch = 0; ch < eeprom_ch_count; ch++) {
  433. if ((band == 6) &&
  434. ((eeprom_ch_index[ch] == 5) ||
  435. (eeprom_ch_index[ch] == 6) ||
  436. (eeprom_ch_index[ch] == 7)))
  437. fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
  438. else
  439. fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
  440. /* Set up driver's info for lower half */
  441. iwl4965_set_fat_chan_info(priv, ieeeband,
  442. eeprom_ch_index[ch],
  443. &(eeprom_ch_info[ch]),
  444. fat_extension_chan);
  445. /* Set up driver's info for upper half */
  446. iwl4965_set_fat_chan_info(priv, ieeeband,
  447. (eeprom_ch_index[ch] + 4),
  448. &(eeprom_ch_info[ch]),
  449. HT_IE_EXT_CHANNEL_BELOW);
  450. }
  451. }
  452. return 0;
  453. }
  454. EXPORT_SYMBOL(iwl_init_channel_map);
  455. /*
  456. * iwl_free_channel_map - undo allocations in iwl4965_init_channel_map
  457. */
  458. void iwl_free_channel_map(struct iwl_priv *priv)
  459. {
  460. kfree(priv->channel_info);
  461. priv->channel_count = 0;
  462. }
  463. EXPORT_SYMBOL(iwl_free_channel_map);
  464. /**
  465. * iwl_get_channel_info - Find driver's private channel info
  466. *
  467. * Based on band and channel number.
  468. */
  469. const struct iwl_channel_info *iwl_get_channel_info(
  470. 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_get_channel_info);