iwl-eeprom.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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-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 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. const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  176. {
  177. BUG_ON(offset >= priv->cfg->eeprom_size);
  178. return &priv->eeprom[offset];
  179. }
  180. EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
  181. /**
  182. * iwl_eeprom_init - read EEPROM contents
  183. *
  184. * Load the EEPROM contents from adapter into priv->eeprom
  185. *
  186. * NOTE: This routine uses the non-debug IO access functions.
  187. */
  188. int iwl_eeprom_init(struct iwl_priv *priv)
  189. {
  190. u16 *e;
  191. u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
  192. u32 r;
  193. int sz = priv->cfg->eeprom_size;
  194. int ret;
  195. int i;
  196. u16 addr;
  197. /* allocate eeprom */
  198. priv->eeprom = kzalloc(sz, GFP_KERNEL);
  199. if (!priv->eeprom) {
  200. ret = -ENOMEM;
  201. goto alloc_err;
  202. }
  203. e = (u16 *)priv->eeprom;
  204. ret = priv->cfg->ops->lib->eeprom_ops.verify_signature(priv);
  205. if (ret < 0) {
  206. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  207. ret = -ENOENT;
  208. goto err;
  209. }
  210. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  211. ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
  212. if (ret < 0) {
  213. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  214. ret = -ENOENT;
  215. goto err;
  216. }
  217. /* eeprom is an array of 16bit values */
  218. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  219. _iwl_write32(priv, CSR_EEPROM_REG, addr << 1);
  220. _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  221. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  222. i += IWL_EEPROM_ACCESS_DELAY) {
  223. r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
  224. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  225. break;
  226. udelay(IWL_EEPROM_ACCESS_DELAY);
  227. }
  228. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  229. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  230. ret = -ETIMEDOUT;
  231. goto done;
  232. }
  233. e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
  234. }
  235. ret = 0;
  236. done:
  237. priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
  238. err:
  239. if (ret)
  240. kfree(priv->eeprom);
  241. alloc_err:
  242. return ret;
  243. }
  244. EXPORT_SYMBOL(iwl_eeprom_init);
  245. void iwl_eeprom_free(struct iwl_priv *priv)
  246. {
  247. if(priv->eeprom)
  248. kfree(priv->eeprom);
  249. priv->eeprom = NULL;
  250. }
  251. EXPORT_SYMBOL(iwl_eeprom_free);
  252. int iwl_eeprom_check_version(struct iwl_priv *priv)
  253. {
  254. return priv->cfg->ops->lib->eeprom_ops.check_version(priv);
  255. }
  256. EXPORT_SYMBOL(iwl_eeprom_check_version);
  257. const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  258. {
  259. return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
  260. }
  261. EXPORT_SYMBOL(iwl_eeprom_query_addr);
  262. u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
  263. {
  264. return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
  265. }
  266. EXPORT_SYMBOL(iwl_eeprom_query16);
  267. void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
  268. {
  269. const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
  270. EEPROM_MAC_ADDRESS);
  271. memcpy(mac, addr, ETH_ALEN);
  272. }
  273. EXPORT_SYMBOL(iwl_eeprom_get_mac);
  274. static void iwl_init_band_reference(const struct iwl_priv *priv,
  275. int eep_band, int *eeprom_ch_count,
  276. const struct iwl_eeprom_channel **eeprom_ch_info,
  277. const u8 **eeprom_ch_index)
  278. {
  279. u32 offset = priv->cfg->ops->lib->
  280. eeprom_ops.regulatory_bands[eep_band - 1];
  281. switch (eep_band) {
  282. case 1: /* 2.4GHz band */
  283. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
  284. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  285. iwl_eeprom_query_addr(priv, offset);
  286. *eeprom_ch_index = iwl_eeprom_band_1;
  287. break;
  288. case 2: /* 4.9GHz band */
  289. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
  290. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  291. iwl_eeprom_query_addr(priv, offset);
  292. *eeprom_ch_index = iwl_eeprom_band_2;
  293. break;
  294. case 3: /* 5.2GHz band */
  295. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
  296. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  297. iwl_eeprom_query_addr(priv, offset);
  298. *eeprom_ch_index = iwl_eeprom_band_3;
  299. break;
  300. case 4: /* 5.5GHz band */
  301. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
  302. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  303. iwl_eeprom_query_addr(priv, offset);
  304. *eeprom_ch_index = iwl_eeprom_band_4;
  305. break;
  306. case 5: /* 5.7GHz band */
  307. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
  308. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  309. iwl_eeprom_query_addr(priv, offset);
  310. *eeprom_ch_index = iwl_eeprom_band_5;
  311. break;
  312. case 6: /* 2.4GHz FAT channels */
  313. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
  314. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  315. iwl_eeprom_query_addr(priv, offset);
  316. *eeprom_ch_index = iwl_eeprom_band_6;
  317. break;
  318. case 7: /* 5 GHz FAT channels */
  319. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
  320. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  321. iwl_eeprom_query_addr(priv, offset);
  322. *eeprom_ch_index = iwl_eeprom_band_7;
  323. break;
  324. default:
  325. BUG();
  326. return;
  327. }
  328. }
  329. #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
  330. ? # x " " : "")
  331. /**
  332. * iwl_set_fat_chan_info - Copy fat channel info into driver's priv.
  333. *
  334. * Does not set up a command, or touch hardware.
  335. */
  336. static int iwl_set_fat_chan_info(struct iwl_priv *priv,
  337. enum ieee80211_band band, u16 channel,
  338. const struct iwl_eeprom_channel *eeprom_ch,
  339. u8 fat_extension_channel)
  340. {
  341. struct iwl_channel_info *ch_info;
  342. ch_info = (struct iwl_channel_info *)
  343. iwl_get_channel_info(priv, band, channel);
  344. if (!is_channel_valid(ch_info))
  345. return -1;
  346. IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s(0x%02x"
  347. " %ddBm): Ad-Hoc %ssupported\n",
  348. ch_info->channel,
  349. is_channel_a_band(ch_info) ?
  350. "5.2" : "2.4",
  351. CHECK_AND_PRINT(IBSS),
  352. CHECK_AND_PRINT(ACTIVE),
  353. CHECK_AND_PRINT(RADAR),
  354. CHECK_AND_PRINT(WIDE),
  355. CHECK_AND_PRINT(DFS),
  356. eeprom_ch->flags,
  357. eeprom_ch->max_power_avg,
  358. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
  359. && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
  360. "" : "not ");
  361. ch_info->fat_eeprom = *eeprom_ch;
  362. ch_info->fat_max_power_avg = eeprom_ch->max_power_avg;
  363. ch_info->fat_curr_txpow = eeprom_ch->max_power_avg;
  364. ch_info->fat_min_power = 0;
  365. ch_info->fat_scan_power = eeprom_ch->max_power_avg;
  366. ch_info->fat_flags = eeprom_ch->flags;
  367. ch_info->fat_extension_channel = fat_extension_channel;
  368. return 0;
  369. }
  370. #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  371. ? # x " " : "")
  372. /**
  373. * iwl_init_channel_map - Set up driver's info for all possible channels
  374. */
  375. int iwl_init_channel_map(struct iwl_priv *priv)
  376. {
  377. int eeprom_ch_count = 0;
  378. const u8 *eeprom_ch_index = NULL;
  379. const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
  380. int band, ch;
  381. struct iwl_channel_info *ch_info;
  382. if (priv->channel_count) {
  383. IWL_DEBUG_INFO("Channel map already initialized.\n");
  384. return 0;
  385. }
  386. IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
  387. priv->channel_count =
  388. ARRAY_SIZE(iwl_eeprom_band_1) +
  389. ARRAY_SIZE(iwl_eeprom_band_2) +
  390. ARRAY_SIZE(iwl_eeprom_band_3) +
  391. ARRAY_SIZE(iwl_eeprom_band_4) +
  392. ARRAY_SIZE(iwl_eeprom_band_5);
  393. IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
  394. priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
  395. priv->channel_count, GFP_KERNEL);
  396. if (!priv->channel_info) {
  397. IWL_ERROR("Could not allocate channel_info\n");
  398. priv->channel_count = 0;
  399. return -ENOMEM;
  400. }
  401. ch_info = priv->channel_info;
  402. /* Loop through the 5 EEPROM bands adding them in order to the
  403. * channel map we maintain (that contains additional information than
  404. * what just in the EEPROM) */
  405. for (band = 1; band <= 5; band++) {
  406. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  407. &eeprom_ch_info, &eeprom_ch_index);
  408. /* Loop through each band adding each of the channels */
  409. for (ch = 0; ch < eeprom_ch_count; ch++) {
  410. ch_info->channel = eeprom_ch_index[ch];
  411. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  412. IEEE80211_BAND_5GHZ;
  413. /* permanently store EEPROM's channel regulatory flags
  414. * and max power in channel info database. */
  415. ch_info->eeprom = eeprom_ch_info[ch];
  416. /* Copy the run-time flags so they are there even on
  417. * invalid channels */
  418. ch_info->flags = eeprom_ch_info[ch].flags;
  419. if (!(is_channel_valid(ch_info))) {
  420. IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
  421. "No traffic\n",
  422. ch_info->channel,
  423. ch_info->flags,
  424. is_channel_a_band(ch_info) ?
  425. "5.2" : "2.4");
  426. ch_info++;
  427. continue;
  428. }
  429. /* Initialize regulatory-based run-time data */
  430. ch_info->max_power_avg = ch_info->curr_txpow =
  431. eeprom_ch_info[ch].max_power_avg;
  432. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  433. ch_info->min_power = 0;
  434. IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
  435. " %ddBm): Ad-Hoc %ssupported\n",
  436. ch_info->channel,
  437. is_channel_a_band(ch_info) ?
  438. "5.2" : "2.4",
  439. CHECK_AND_PRINT_I(VALID),
  440. CHECK_AND_PRINT_I(IBSS),
  441. CHECK_AND_PRINT_I(ACTIVE),
  442. CHECK_AND_PRINT_I(RADAR),
  443. CHECK_AND_PRINT_I(WIDE),
  444. CHECK_AND_PRINT_I(DFS),
  445. eeprom_ch_info[ch].flags,
  446. eeprom_ch_info[ch].max_power_avg,
  447. ((eeprom_ch_info[ch].
  448. flags & EEPROM_CHANNEL_IBSS)
  449. && !(eeprom_ch_info[ch].
  450. flags & EEPROM_CHANNEL_RADAR))
  451. ? "" : "not ");
  452. /* Set the user_txpower_limit to the highest power
  453. * supported by any channel */
  454. if (eeprom_ch_info[ch].max_power_avg >
  455. priv->user_txpower_limit)
  456. priv->user_txpower_limit =
  457. eeprom_ch_info[ch].max_power_avg;
  458. ch_info++;
  459. }
  460. }
  461. /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
  462. for (band = 6; band <= 7; band++) {
  463. enum ieee80211_band ieeeband;
  464. u8 fat_extension_chan;
  465. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  466. &eeprom_ch_info, &eeprom_ch_index);
  467. /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
  468. ieeeband =
  469. (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  470. /* Loop through each band adding each of the channels */
  471. for (ch = 0; ch < eeprom_ch_count; ch++) {
  472. if ((band == 6) &&
  473. ((eeprom_ch_index[ch] == 5) ||
  474. (eeprom_ch_index[ch] == 6) ||
  475. (eeprom_ch_index[ch] == 7)))
  476. fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
  477. else
  478. fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
  479. /* Set up driver's info for lower half */
  480. iwl_set_fat_chan_info(priv, ieeeband,
  481. eeprom_ch_index[ch],
  482. &(eeprom_ch_info[ch]),
  483. fat_extension_chan);
  484. /* Set up driver's info for upper half */
  485. iwl_set_fat_chan_info(priv, ieeeband,
  486. (eeprom_ch_index[ch] + 4),
  487. &(eeprom_ch_info[ch]),
  488. HT_IE_EXT_CHANNEL_BELOW);
  489. }
  490. }
  491. return 0;
  492. }
  493. EXPORT_SYMBOL(iwl_init_channel_map);
  494. /*
  495. * iwl_free_channel_map - undo allocations in iwl_init_channel_map
  496. */
  497. void iwl_free_channel_map(struct iwl_priv *priv)
  498. {
  499. kfree(priv->channel_info);
  500. priv->channel_count = 0;
  501. }
  502. /**
  503. * iwl_get_channel_info - Find driver's private channel info
  504. *
  505. * Based on band and channel number.
  506. */
  507. const struct iwl_channel_info *iwl_get_channel_info(
  508. const struct iwl_priv *priv,
  509. enum ieee80211_band band, u16 channel)
  510. {
  511. int i;
  512. switch (band) {
  513. case IEEE80211_BAND_5GHZ:
  514. for (i = 14; i < priv->channel_count; i++) {
  515. if (priv->channel_info[i].channel == channel)
  516. return &priv->channel_info[i];
  517. }
  518. break;
  519. case IEEE80211_BAND_2GHZ:
  520. if (channel >= 1 && channel <= 14)
  521. return &priv->channel_info[channel - 1];
  522. break;
  523. default:
  524. BUG();
  525. }
  526. return NULL;
  527. }
  528. EXPORT_SYMBOL(iwl_get_channel_info);