Commit | Line | Data |
---|---|---|
be663ab6 WYG |
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 | ||
63 | ||
64 | #include <linux/kernel.h> | |
65 | #include <linux/module.h> | |
66 | #include <linux/slab.h> | |
67 | #include <linux/init.h> | |
68 | ||
69 | #include <net/mac80211.h> | |
70 | ||
71 | #include "iwl-commands.h" | |
72 | #include "iwl-dev.h" | |
73 | #include "iwl-core.h" | |
74 | #include "iwl-debug.h" | |
75 | #include "iwl-eeprom.h" | |
76 | #include "iwl-io.h" | |
77 | ||
78 | /************************** EEPROM BANDS **************************** | |
79 | * | |
ef33417d | 80 | * The iwlegacy_eeprom_band definitions below provide the mapping from the |
be663ab6 WYG |
81 | * EEPROM contents to the specific channel number supported for each |
82 | * band. | |
83 | * | |
84 | * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 | |
85 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. | |
86 | * The specific geography and calibration information for that channel | |
87 | * is contained in the eeprom map itself. | |
88 | * | |
89 | * During init, we copy the eeprom information and channel map | |
90 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 | |
91 | * | |
92 | * channel_map_24/52 provides the index in the channel_info array for a | |
93 | * given channel. We have to have two separate maps as there is channel | |
94 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and | |
95 | * band_2 | |
96 | * | |
97 | * A value of 0xff stored in the channel_map indicates that the channel | |
98 | * is not supported by the hardware at all. | |
99 | * | |
100 | * A value of 0xfe in the channel_map indicates that the channel is not | |
101 | * valid for Tx with the current hardware. This means that | |
102 | * while the system can tune and receive on a given channel, it may not | |
103 | * be able to associate or transmit any frames on that | |
104 | * channel. There is no corresponding channel information for that | |
105 | * entry. | |
106 | * | |
107 | *********************************************************************/ | |
108 | ||
109 | /* 2.4 GHz */ | |
ef33417d | 110 | const u8 iwlegacy_eeprom_band_1[14] = { |
be663ab6 WYG |
111 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
112 | }; | |
113 | ||
114 | /* 5.2 GHz bands */ | |
ef33417d | 115 | static const u8 iwlegacy_eeprom_band_2[] = { /* 4915-5080MHz */ |
be663ab6 WYG |
116 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
117 | }; | |
118 | ||
ef33417d | 119 | static const u8 iwlegacy_eeprom_band_3[] = { /* 5170-5320MHz */ |
be663ab6 WYG |
120 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
121 | }; | |
122 | ||
ef33417d | 123 | static const u8 iwlegacy_eeprom_band_4[] = { /* 5500-5700MHz */ |
be663ab6 WYG |
124 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
125 | }; | |
126 | ||
ef33417d | 127 | static const u8 iwlegacy_eeprom_band_5[] = { /* 5725-5825MHz */ |
be663ab6 WYG |
128 | 145, 149, 153, 157, 161, 165 |
129 | }; | |
130 | ||
ef33417d | 131 | static const u8 iwlegacy_eeprom_band_6[] = { /* 2.4 ht40 channel */ |
be663ab6 WYG |
132 | 1, 2, 3, 4, 5, 6, 7 |
133 | }; | |
134 | ||
ef33417d | 135 | static const u8 iwlegacy_eeprom_band_7[] = { /* 5.2 ht40 channel */ |
be663ab6 WYG |
136 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
137 | }; | |
138 | ||
139 | /****************************************************************************** | |
140 | * | |
141 | * EEPROM related functions | |
142 | * | |
143 | ******************************************************************************/ | |
144 | ||
145 | static int iwl_legacy_eeprom_verify_signature(struct iwl_priv *priv) | |
146 | { | |
147 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK; | |
148 | int ret = 0; | |
149 | ||
150 | IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp); | |
151 | switch (gp) { | |
152 | case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K: | |
153 | case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K: | |
154 | break; | |
155 | default: | |
156 | IWL_ERR(priv, "bad EEPROM signature," | |
157 | "EEPROM_GP=0x%08x\n", gp); | |
158 | ret = -ENOENT; | |
159 | break; | |
160 | } | |
161 | return ret; | |
162 | } | |
163 | ||
164 | const u8 | |
165 | *iwl_legacy_eeprom_query_addr(const struct iwl_priv *priv, size_t offset) | |
166 | { | |
167 | BUG_ON(offset >= priv->cfg->base_params->eeprom_size); | |
168 | return &priv->eeprom[offset]; | |
169 | } | |
170 | EXPORT_SYMBOL(iwl_legacy_eeprom_query_addr); | |
171 | ||
172 | u16 iwl_legacy_eeprom_query16(const struct iwl_priv *priv, size_t offset) | |
173 | { | |
174 | if (!priv->eeprom) | |
175 | return 0; | |
176 | return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8); | |
177 | } | |
178 | EXPORT_SYMBOL(iwl_legacy_eeprom_query16); | |
179 | ||
180 | /** | |
181 | * iwl_legacy_eeprom_init - read EEPROM contents | |
182 | * | |
183 | * Load the EEPROM contents from adapter into priv->eeprom | |
184 | * | |
185 | * NOTE: This routine uses the non-debug IO access functions. | |
186 | */ | |
187 | int iwl_legacy_eeprom_init(struct iwl_priv *priv) | |
188 | { | |
189 | __le16 *e; | |
190 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); | |
191 | int sz; | |
192 | int ret; | |
193 | u16 addr; | |
194 | ||
195 | /* allocate eeprom */ | |
196 | sz = priv->cfg->base_params->eeprom_size; | |
197 | IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz); | |
198 | priv->eeprom = kzalloc(sz, GFP_KERNEL); | |
199 | if (!priv->eeprom) { | |
200 | ret = -ENOMEM; | |
201 | goto alloc_err; | |
202 | } | |
203 | e = (__le16 *)priv->eeprom; | |
204 | ||
205 | priv->cfg->ops->lib->apm_ops.init(priv); | |
206 | ||
207 | ret = iwl_legacy_eeprom_verify_signature(priv); | |
208 | if (ret < 0) { | |
209 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); | |
210 | ret = -ENOENT; | |
211 | goto err; | |
212 | } | |
213 | ||
214 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ | |
215 | ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv); | |
216 | if (ret < 0) { | |
217 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); | |
218 | ret = -ENOENT; | |
219 | goto err; | |
220 | } | |
221 | ||
222 | /* eeprom is an array of 16bit values */ | |
223 | for (addr = 0; addr < sz; addr += sizeof(u16)) { | |
224 | u32 r; | |
225 | ||
226 | _iwl_legacy_write32(priv, CSR_EEPROM_REG, | |
227 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); | |
228 | ||
229 | ret = iwl_poll_bit(priv, CSR_EEPROM_REG, | |
230 | CSR_EEPROM_REG_READ_VALID_MSK, | |
231 | CSR_EEPROM_REG_READ_VALID_MSK, | |
232 | IWL_EEPROM_ACCESS_TIMEOUT); | |
233 | if (ret < 0) { | |
234 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", | |
235 | addr); | |
236 | goto done; | |
237 | } | |
238 | r = _iwl_legacy_read_direct32(priv, CSR_EEPROM_REG); | |
239 | e[addr / 2] = cpu_to_le16(r >> 16); | |
240 | } | |
241 | ||
242 | IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n", | |
243 | "EEPROM", | |
244 | iwl_legacy_eeprom_query16(priv, EEPROM_VERSION)); | |
245 | ||
246 | ret = 0; | |
247 | done: | |
248 | priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv); | |
249 | ||
250 | err: | |
251 | if (ret) | |
252 | iwl_legacy_eeprom_free(priv); | |
253 | /* Reset chip to save power until we load uCode during "up". */ | |
254 | iwl_legacy_apm_stop(priv); | |
255 | alloc_err: | |
256 | return ret; | |
257 | } | |
258 | EXPORT_SYMBOL(iwl_legacy_eeprom_init); | |
259 | ||
260 | void iwl_legacy_eeprom_free(struct iwl_priv *priv) | |
261 | { | |
262 | kfree(priv->eeprom); | |
263 | priv->eeprom = NULL; | |
264 | } | |
265 | EXPORT_SYMBOL(iwl_legacy_eeprom_free); | |
266 | ||
267 | static void iwl_legacy_init_band_reference(const struct iwl_priv *priv, | |
268 | int eep_band, int *eeprom_ch_count, | |
269 | const struct iwl_eeprom_channel **eeprom_ch_info, | |
270 | const u8 **eeprom_ch_index) | |
271 | { | |
272 | u32 offset = priv->cfg->ops->lib-> | |
273 | eeprom_ops.regulatory_bands[eep_band - 1]; | |
274 | switch (eep_band) { | |
275 | case 1: /* 2.4GHz band */ | |
ef33417d | 276 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_1); |
be663ab6 WYG |
277 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
278 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 279 | *eeprom_ch_index = iwlegacy_eeprom_band_1; |
be663ab6 WYG |
280 | break; |
281 | case 2: /* 4.9GHz band */ | |
ef33417d | 282 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_2); |
be663ab6 WYG |
283 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
284 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 285 | *eeprom_ch_index = iwlegacy_eeprom_band_2; |
be663ab6 WYG |
286 | break; |
287 | case 3: /* 5.2GHz band */ | |
ef33417d | 288 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_3); |
be663ab6 WYG |
289 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
290 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 291 | *eeprom_ch_index = iwlegacy_eeprom_band_3; |
be663ab6 WYG |
292 | break; |
293 | case 4: /* 5.5GHz band */ | |
ef33417d | 294 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_4); |
be663ab6 WYG |
295 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
296 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 297 | *eeprom_ch_index = iwlegacy_eeprom_band_4; |
be663ab6 WYG |
298 | break; |
299 | case 5: /* 5.7GHz band */ | |
ef33417d | 300 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_5); |
be663ab6 WYG |
301 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
302 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 303 | *eeprom_ch_index = iwlegacy_eeprom_band_5; |
be663ab6 WYG |
304 | break; |
305 | case 6: /* 2.4GHz ht40 channels */ | |
ef33417d | 306 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_6); |
be663ab6 WYG |
307 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
308 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 309 | *eeprom_ch_index = iwlegacy_eeprom_band_6; |
be663ab6 WYG |
310 | break; |
311 | case 7: /* 5 GHz ht40 channels */ | |
ef33417d | 312 | *eeprom_ch_count = ARRAY_SIZE(iwlegacy_eeprom_band_7); |
be663ab6 WYG |
313 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
314 | iwl_legacy_eeprom_query_addr(priv, offset); | |
ef33417d | 315 | *eeprom_ch_index = iwlegacy_eeprom_band_7; |
be663ab6 WYG |
316 | break; |
317 | default: | |
318 | BUG(); | |
319 | return; | |
320 | } | |
321 | } | |
322 | ||
323 | #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \ | |
324 | ? # x " " : "") | |
325 | /** | |
326 | * iwl_legacy_mod_ht40_chan_info - Copy ht40 channel info into driver's priv. | |
327 | * | |
328 | * Does not set up a command, or touch hardware. | |
329 | */ | |
330 | static int iwl_legacy_mod_ht40_chan_info(struct iwl_priv *priv, | |
331 | enum ieee80211_band band, u16 channel, | |
332 | const struct iwl_eeprom_channel *eeprom_ch, | |
333 | u8 clear_ht40_extension_channel) | |
334 | { | |
335 | struct iwl_channel_info *ch_info; | |
336 | ||
337 | ch_info = (struct iwl_channel_info *) | |
338 | iwl_legacy_get_channel_info(priv, band, channel); | |
339 | ||
340 | if (!iwl_legacy_is_channel_valid(ch_info)) | |
341 | return -1; | |
342 | ||
343 | IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):" | |
344 | " Ad-Hoc %ssupported\n", | |
345 | ch_info->channel, | |
346 | iwl_legacy_is_channel_a_band(ch_info) ? | |
347 | "5.2" : "2.4", | |
348 | CHECK_AND_PRINT(IBSS), | |
349 | CHECK_AND_PRINT(ACTIVE), | |
350 | CHECK_AND_PRINT(RADAR), | |
351 | CHECK_AND_PRINT(WIDE), | |
352 | CHECK_AND_PRINT(DFS), | |
353 | eeprom_ch->flags, | |
354 | eeprom_ch->max_power_avg, | |
355 | ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS) | |
356 | && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ? | |
357 | "" : "not "); | |
358 | ||
359 | ch_info->ht40_eeprom = *eeprom_ch; | |
360 | ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg; | |
361 | ch_info->ht40_flags = eeprom_ch->flags; | |
362 | if (eeprom_ch->flags & EEPROM_CHANNEL_VALID) | |
363 | ch_info->ht40_extension_channel &= | |
364 | ~clear_ht40_extension_channel; | |
365 | ||
366 | return 0; | |
367 | } | |
368 | ||
369 | #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ | |
370 | ? # x " " : "") | |
371 | ||
372 | /** | |
373 | * iwl_legacy_init_channel_map - Set up driver's info for all possible channels | |
374 | */ | |
375 | int iwl_legacy_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 | ||
383 | if (priv->channel_count) { | |
384 | IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n"); | |
385 | return 0; | |
386 | } | |
387 | ||
388 | IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n"); | |
389 | ||
390 | priv->channel_count = | |
ef33417d JL |
391 | ARRAY_SIZE(iwlegacy_eeprom_band_1) + |
392 | ARRAY_SIZE(iwlegacy_eeprom_band_2) + | |
393 | ARRAY_SIZE(iwlegacy_eeprom_band_3) + | |
394 | ARRAY_SIZE(iwlegacy_eeprom_band_4) + | |
395 | ARRAY_SIZE(iwlegacy_eeprom_band_5); | |
be663ab6 WYG |
396 | |
397 | IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n", | |
398 | priv->channel_count); | |
399 | ||
400 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * | |
401 | priv->channel_count, GFP_KERNEL); | |
402 | if (!priv->channel_info) { | |
403 | IWL_ERR(priv, "Could not allocate channel_info\n"); | |
404 | priv->channel_count = 0; | |
405 | return -ENOMEM; | |
406 | } | |
407 | ||
408 | ch_info = priv->channel_info; | |
409 | ||
410 | /* Loop through the 5 EEPROM bands adding them in order to the | |
411 | * channel map we maintain (that contains additional information than | |
412 | * what just in the EEPROM) */ | |
413 | for (band = 1; band <= 5; band++) { | |
414 | ||
415 | iwl_legacy_init_band_reference(priv, band, &eeprom_ch_count, | |
416 | &eeprom_ch_info, &eeprom_ch_index); | |
417 | ||
418 | /* Loop through each band adding each of the channels */ | |
419 | for (ch = 0; ch < eeprom_ch_count; ch++) { | |
420 | ch_info->channel = eeprom_ch_index[ch]; | |
421 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : | |
422 | IEEE80211_BAND_5GHZ; | |
423 | ||
424 | /* permanently store EEPROM's channel regulatory flags | |
425 | * and max power in channel info database. */ | |
426 | ch_info->eeprom = eeprom_ch_info[ch]; | |
427 | ||
428 | /* Copy the run-time flags so they are there even on | |
429 | * invalid channels */ | |
430 | ch_info->flags = eeprom_ch_info[ch].flags; | |
431 | /* First write that ht40 is not enabled, and then enable | |
432 | * one by one */ | |
433 | ch_info->ht40_extension_channel = | |
434 | IEEE80211_CHAN_NO_HT40; | |
435 | ||
436 | if (!(iwl_legacy_is_channel_valid(ch_info))) { | |
437 | IWL_DEBUG_EEPROM(priv, | |
438 | "Ch. %d Flags %x [%sGHz] - " | |
439 | "No traffic\n", | |
440 | ch_info->channel, | |
441 | ch_info->flags, | |
442 | iwl_legacy_is_channel_a_band(ch_info) ? | |
443 | "5.2" : "2.4"); | |
444 | ch_info++; | |
445 | continue; | |
446 | } | |
447 | ||
448 | /* Initialize regulatory-based run-time data */ | |
449 | ch_info->max_power_avg = ch_info->curr_txpow = | |
450 | eeprom_ch_info[ch].max_power_avg; | |
451 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; | |
452 | ch_info->min_power = 0; | |
453 | ||
454 | IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] " | |
455 | "%s%s%s%s%s%s(0x%02x %ddBm):" | |
456 | " Ad-Hoc %ssupported\n", | |
457 | ch_info->channel, | |
458 | iwl_legacy_is_channel_a_band(ch_info) ? | |
459 | "5.2" : "2.4", | |
460 | CHECK_AND_PRINT_I(VALID), | |
461 | CHECK_AND_PRINT_I(IBSS), | |
462 | CHECK_AND_PRINT_I(ACTIVE), | |
463 | CHECK_AND_PRINT_I(RADAR), | |
464 | CHECK_AND_PRINT_I(WIDE), | |
465 | CHECK_AND_PRINT_I(DFS), | |
466 | eeprom_ch_info[ch].flags, | |
467 | eeprom_ch_info[ch].max_power_avg, | |
468 | ((eeprom_ch_info[ch]. | |
469 | flags & EEPROM_CHANNEL_IBSS) | |
470 | && !(eeprom_ch_info[ch]. | |
471 | flags & EEPROM_CHANNEL_RADAR)) | |
472 | ? "" : "not "); | |
473 | ||
474 | /* Set the tx_power_user_lmt to the highest power | |
475 | * supported by any channel */ | |
476 | if (eeprom_ch_info[ch].max_power_avg > | |
477 | priv->tx_power_user_lmt) | |
478 | priv->tx_power_user_lmt = | |
479 | eeprom_ch_info[ch].max_power_avg; | |
480 | ||
481 | ch_info++; | |
482 | } | |
483 | } | |
484 | ||
485 | /* Check if we do have HT40 channels */ | |
486 | if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] == | |
487 | EEPROM_REGULATORY_BAND_NO_HT40 && | |
488 | priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] == | |
489 | EEPROM_REGULATORY_BAND_NO_HT40) | |
490 | return 0; | |
491 | ||
492 | /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */ | |
493 | for (band = 6; band <= 7; band++) { | |
494 | enum ieee80211_band ieeeband; | |
495 | ||
496 | iwl_legacy_init_band_reference(priv, band, &eeprom_ch_count, | |
497 | &eeprom_ch_info, &eeprom_ch_index); | |
498 | ||
499 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ | |
500 | ieeeband = | |
501 | (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | |
502 | ||
503 | /* Loop through each band adding each of the channels */ | |
504 | for (ch = 0; ch < eeprom_ch_count; ch++) { | |
505 | /* Set up driver's info for lower half */ | |
506 | iwl_legacy_mod_ht40_chan_info(priv, ieeeband, | |
507 | eeprom_ch_index[ch], | |
508 | &eeprom_ch_info[ch], | |
509 | IEEE80211_CHAN_NO_HT40PLUS); | |
510 | ||
511 | /* Set up driver's info for upper half */ | |
512 | iwl_legacy_mod_ht40_chan_info(priv, ieeeband, | |
513 | eeprom_ch_index[ch] + 4, | |
514 | &eeprom_ch_info[ch], | |
515 | IEEE80211_CHAN_NO_HT40MINUS); | |
516 | } | |
517 | } | |
518 | ||
519 | return 0; | |
520 | } | |
521 | EXPORT_SYMBOL(iwl_legacy_init_channel_map); | |
522 | ||
523 | /* | |
524 | * iwl_legacy_free_channel_map - undo allocations in iwl_legacy_init_channel_map | |
525 | */ | |
526 | void iwl_legacy_free_channel_map(struct iwl_priv *priv) | |
527 | { | |
528 | kfree(priv->channel_info); | |
529 | priv->channel_count = 0; | |
530 | } | |
531 | EXPORT_SYMBOL(iwl_legacy_free_channel_map); | |
532 | ||
533 | /** | |
534 | * iwl_legacy_get_channel_info - Find driver's private channel info | |
535 | * | |
536 | * Based on band and channel number. | |
537 | */ | |
538 | const struct | |
539 | iwl_channel_info *iwl_legacy_get_channel_info(const struct iwl_priv *priv, | |
540 | enum ieee80211_band band, u16 channel) | |
541 | { | |
542 | int i; | |
543 | ||
544 | switch (band) { | |
545 | case IEEE80211_BAND_5GHZ: | |
546 | for (i = 14; i < priv->channel_count; i++) { | |
547 | if (priv->channel_info[i].channel == channel) | |
548 | return &priv->channel_info[i]; | |
549 | } | |
550 | break; | |
551 | case IEEE80211_BAND_2GHZ: | |
552 | if (channel >= 1 && channel <= 14) | |
553 | return &priv->channel_info[channel - 1]; | |
554 | break; | |
555 | default: | |
556 | BUG(); | |
557 | } | |
558 | ||
559 | return NULL; | |
560 | } | |
561 | EXPORT_SYMBOL(iwl_legacy_get_channel_info); |