1 /******************************************************************************
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.
8 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/slab.h>
67 #include <linux/init.h>
69 #include <net/mac80211.h>
71 #include "iwl-commands.h"
74 #include "iwl-debug.h"
75 #include "iwl-eeprom.h"
78 /************************** EEPROM BANDS ****************************
80 * The il_eeprom_band definitions below provide the mapping from the
81 * EEPROM contents to the specific channel number supported for each
84 * For example, il_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.
89 * During init, we copy the eeprom information and channel map
90 * information into il->channel_info_24/52 and il->channel_map_24/52
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
97 * A value of 0xff stored in the channel_map indicates that the channel
98 * is not supported by the hardware at all.
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
107 *********************************************************************/
110 const u8 il_eeprom_band_1
[14] = {
111 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
115 static const u8 il_eeprom_band_2
[] = { /* 4915-5080MHz */
116 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
119 static const u8 il_eeprom_band_3
[] = { /* 5170-5320MHz */
120 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
123 static const u8 il_eeprom_band_4
[] = { /* 5500-5700MHz */
124 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
127 static const u8 il_eeprom_band_5
[] = { /* 5725-5825MHz */
128 145, 149, 153, 157, 161, 165
131 static const u8 il_eeprom_band_6
[] = { /* 2.4 ht40 channel */
135 static const u8 il_eeprom_band_7
[] = { /* 5.2 ht40 channel */
136 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
139 /******************************************************************************
141 * EEPROM related functions
143 ******************************************************************************/
145 static int il_eeprom_verify_signature(struct il_priv
*il
)
147 u32 gp
= _il_rd(il
, CSR_EEPROM_GP
) & CSR_EEPROM_GP_VALID_MSK
;
150 D_EEPROM("EEPROM signature=0x%08x\n", gp
);
152 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K
:
153 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K
:
156 IL_ERR("bad EEPROM signature,"
157 "EEPROM_GP=0x%08x\n", gp
);
165 *il_eeprom_query_addr(const struct il_priv
*il
, size_t offset
)
167 BUG_ON(offset
>= il
->cfg
->base_params
->eeprom_size
);
168 return &il
->eeprom
[offset
];
170 EXPORT_SYMBOL(il_eeprom_query_addr
);
172 u16
il_eeprom_query16(const struct il_priv
*il
, size_t offset
)
176 return (u16
)il
->eeprom
[offset
] | ((u16
)il
->eeprom
[offset
+ 1] << 8);
178 EXPORT_SYMBOL(il_eeprom_query16
);
181 * il_eeprom_init - read EEPROM contents
183 * Load the EEPROM contents from adapter into il->eeprom
185 * NOTE: This routine uses the non-debug IO access functions.
187 int il_eeprom_init(struct il_priv
*il
)
190 u32 gp
= _il_rd(il
, CSR_EEPROM_GP
);
195 /* allocate eeprom */
196 sz
= il
->cfg
->base_params
->eeprom_size
;
197 D_EEPROM("NVM size = %d\n", sz
);
198 il
->eeprom
= kzalloc(sz
, GFP_KERNEL
);
203 e
= (__le16
*)il
->eeprom
;
205 il
->cfg
->ops
->lib
->apm_ops
.init(il
);
207 ret
= il_eeprom_verify_signature(il
);
209 IL_ERR("EEPROM not found, EEPROM_GP=0x%08x\n", gp
);
214 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
215 ret
= il
->cfg
->ops
->lib
->eeprom_ops
.acquire_semaphore(il
);
217 IL_ERR("Failed to acquire EEPROM semaphore.\n");
222 /* eeprom is an array of 16bit values */
223 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
226 _il_wr(il
, CSR_EEPROM_REG
,
227 CSR_EEPROM_REG_MSK_ADDR
& (addr
<< 1));
229 ret
= _il_poll_bit(il
, CSR_EEPROM_REG
,
230 CSR_EEPROM_REG_READ_VALID_MSK
,
231 CSR_EEPROM_REG_READ_VALID_MSK
,
232 IL_EEPROM_ACCESS_TIMEOUT
);
234 IL_ERR("Time out reading EEPROM[%d]\n",
238 r
= _il_rd(il
, CSR_EEPROM_REG
);
239 e
[addr
/ 2] = cpu_to_le16(r
>> 16);
242 D_EEPROM("NVM Type: %s, version: 0x%x\n",
244 il_eeprom_query16(il
, EEPROM_VERSION
));
248 il
->cfg
->ops
->lib
->eeprom_ops
.release_semaphore(il
);
253 /* Reset chip to save power until we load uCode during "up". */
258 EXPORT_SYMBOL(il_eeprom_init
);
260 void il_eeprom_free(struct il_priv
*il
)
265 EXPORT_SYMBOL(il_eeprom_free
);
267 static void il_init_band_reference(const struct il_priv
*il
,
268 int eep_band
, int *eeprom_ch_count
,
269 const struct il_eeprom_channel
**eeprom_ch_info
,
270 const u8
**eeprom_ch_index
)
272 u32 offset
= il
->cfg
->ops
->lib
->
273 eeprom_ops
.regulatory_bands
[eep_band
- 1];
275 case 1: /* 2.4GHz band */
276 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_1
);
277 *eeprom_ch_info
= (struct il_eeprom_channel
*)
278 il_eeprom_query_addr(il
, offset
);
279 *eeprom_ch_index
= il_eeprom_band_1
;
281 case 2: /* 4.9GHz band */
282 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_2
);
283 *eeprom_ch_info
= (struct il_eeprom_channel
*)
284 il_eeprom_query_addr(il
, offset
);
285 *eeprom_ch_index
= il_eeprom_band_2
;
287 case 3: /* 5.2GHz band */
288 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_3
);
289 *eeprom_ch_info
= (struct il_eeprom_channel
*)
290 il_eeprom_query_addr(il
, offset
);
291 *eeprom_ch_index
= il_eeprom_band_3
;
293 case 4: /* 5.5GHz band */
294 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_4
);
295 *eeprom_ch_info
= (struct il_eeprom_channel
*)
296 il_eeprom_query_addr(il
, offset
);
297 *eeprom_ch_index
= il_eeprom_band_4
;
299 case 5: /* 5.7GHz band */
300 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_5
);
301 *eeprom_ch_info
= (struct il_eeprom_channel
*)
302 il_eeprom_query_addr(il
, offset
);
303 *eeprom_ch_index
= il_eeprom_band_5
;
305 case 6: /* 2.4GHz ht40 channels */
306 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_6
);
307 *eeprom_ch_info
= (struct il_eeprom_channel
*)
308 il_eeprom_query_addr(il
, offset
);
309 *eeprom_ch_index
= il_eeprom_band_6
;
311 case 7: /* 5 GHz ht40 channels */
312 *eeprom_ch_count
= ARRAY_SIZE(il_eeprom_band_7
);
313 *eeprom_ch_info
= (struct il_eeprom_channel
*)
314 il_eeprom_query_addr(il
, offset
);
315 *eeprom_ch_index
= il_eeprom_band_7
;
322 #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
325 * il_mod_ht40_chan_info - Copy ht40 channel info into driver's il.
327 * Does not set up a command, or touch hardware.
329 static int il_mod_ht40_chan_info(struct il_priv
*il
,
330 enum ieee80211_band band
, u16 channel
,
331 const struct il_eeprom_channel
*eeprom_ch
,
332 u8 clear_ht40_extension_channel
)
334 struct il_channel_info
*ch_info
;
336 ch_info
= (struct il_channel_info
*)
337 il_get_channel_info(il
, band
, channel
);
339 if (!il_is_channel_valid(ch_info
))
342 D_EEPROM("HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
343 " Ad-Hoc %ssupported\n",
345 il_is_channel_a_band(ch_info
) ?
347 CHECK_AND_PRINT(IBSS
),
348 CHECK_AND_PRINT(ACTIVE
),
349 CHECK_AND_PRINT(RADAR
),
350 CHECK_AND_PRINT(WIDE
),
351 CHECK_AND_PRINT(DFS
),
353 eeprom_ch
->max_power_avg
,
354 ((eeprom_ch
->flags
& EEPROM_CHANNEL_IBSS
)
355 && !(eeprom_ch
->flags
& EEPROM_CHANNEL_RADAR
)) ?
358 ch_info
->ht40_eeprom
= *eeprom_ch
;
359 ch_info
->ht40_max_power_avg
= eeprom_ch
->max_power_avg
;
360 ch_info
->ht40_flags
= eeprom_ch
->flags
;
361 if (eeprom_ch
->flags
& EEPROM_CHANNEL_VALID
)
362 ch_info
->ht40_extension_channel
&=
363 ~clear_ht40_extension_channel
;
368 #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
372 * il_init_channel_map - Set up driver's info for all possible channels
374 int il_init_channel_map(struct il_priv
*il
)
376 int eeprom_ch_count
= 0;
377 const u8
*eeprom_ch_index
= NULL
;
378 const struct il_eeprom_channel
*eeprom_ch_info
= NULL
;
380 struct il_channel_info
*ch_info
;
382 if (il
->channel_count
) {
383 D_EEPROM("Channel map already initialized.\n");
387 D_EEPROM("Initializing regulatory info from EEPROM\n");
390 ARRAY_SIZE(il_eeprom_band_1
) +
391 ARRAY_SIZE(il_eeprom_band_2
) +
392 ARRAY_SIZE(il_eeprom_band_3
) +
393 ARRAY_SIZE(il_eeprom_band_4
) +
394 ARRAY_SIZE(il_eeprom_band_5
);
396 D_EEPROM("Parsing data for %d channels.\n",
399 il
->channel_info
= kzalloc(sizeof(struct il_channel_info
) *
400 il
->channel_count
, GFP_KERNEL
);
401 if (!il
->channel_info
) {
402 IL_ERR("Could not allocate channel_info\n");
403 il
->channel_count
= 0;
407 ch_info
= il
->channel_info
;
409 /* Loop through the 5 EEPROM bands adding them in order to the
410 * channel map we maintain (that contains additional information than
411 * what just in the EEPROM) */
412 for (band
= 1; band
<= 5; band
++) {
414 il_init_band_reference(il
, band
, &eeprom_ch_count
,
415 &eeprom_ch_info
, &eeprom_ch_index
);
417 /* Loop through each band adding each of the channels */
418 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
419 ch_info
->channel
= eeprom_ch_index
[ch
];
420 ch_info
->band
= (band
== 1) ? IEEE80211_BAND_2GHZ
:
423 /* permanently store EEPROM's channel regulatory flags
424 * and max power in channel info database. */
425 ch_info
->eeprom
= eeprom_ch_info
[ch
];
427 /* Copy the run-time flags so they are there even on
428 * invalid channels */
429 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
430 /* First write that ht40 is not enabled, and then enable
432 ch_info
->ht40_extension_channel
=
433 IEEE80211_CHAN_NO_HT40
;
435 if (!(il_is_channel_valid(ch_info
))) {
437 "Ch. %d Flags %x [%sGHz] - "
441 il_is_channel_a_band(ch_info
) ?
447 /* Initialize regulatory-based run-time data */
448 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
449 eeprom_ch_info
[ch
].max_power_avg
;
450 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
451 ch_info
->min_power
= 0;
453 D_EEPROM("Ch. %d [%sGHz] "
454 "%s%s%s%s%s%s(0x%02x %ddBm):"
455 " Ad-Hoc %ssupported\n",
457 il_is_channel_a_band(ch_info
) ?
459 CHECK_AND_PRINT_I(VALID
),
460 CHECK_AND_PRINT_I(IBSS
),
461 CHECK_AND_PRINT_I(ACTIVE
),
462 CHECK_AND_PRINT_I(RADAR
),
463 CHECK_AND_PRINT_I(WIDE
),
464 CHECK_AND_PRINT_I(DFS
),
465 eeprom_ch_info
[ch
].flags
,
466 eeprom_ch_info
[ch
].max_power_avg
,
467 ((eeprom_ch_info
[ch
].
468 flags
& EEPROM_CHANNEL_IBSS
)
469 && !(eeprom_ch_info
[ch
].
470 flags
& EEPROM_CHANNEL_RADAR
))
477 /* Check if we do have HT40 channels */
478 if (il
->cfg
->ops
->lib
->eeprom_ops
.regulatory_bands
[5] ==
479 EEPROM_REGULATORY_BAND_NO_HT40
&&
480 il
->cfg
->ops
->lib
->eeprom_ops
.regulatory_bands
[6] ==
481 EEPROM_REGULATORY_BAND_NO_HT40
)
484 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
485 for (band
= 6; band
<= 7; band
++) {
486 enum ieee80211_band ieeeband
;
488 il_init_band_reference(il
, band
, &eeprom_ch_count
,
489 &eeprom_ch_info
, &eeprom_ch_index
);
491 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
493 (band
== 6) ? IEEE80211_BAND_2GHZ
: IEEE80211_BAND_5GHZ
;
495 /* Loop through each band adding each of the channels */
496 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
497 /* Set up driver's info for lower half */
498 il_mod_ht40_chan_info(il
, ieeeband
,
501 IEEE80211_CHAN_NO_HT40PLUS
);
503 /* Set up driver's info for upper half */
504 il_mod_ht40_chan_info(il
, ieeeband
,
505 eeprom_ch_index
[ch
] + 4,
507 IEEE80211_CHAN_NO_HT40MINUS
);
513 EXPORT_SYMBOL(il_init_channel_map
);
516 * il_free_channel_map - undo allocations in il_init_channel_map
518 void il_free_channel_map(struct il_priv
*il
)
520 kfree(il
->channel_info
);
521 il
->channel_count
= 0;
523 EXPORT_SYMBOL(il_free_channel_map
);
526 * il_get_channel_info - Find driver's ilate channel info
528 * Based on band and channel number.
531 il_channel_info
*il_get_channel_info(const struct il_priv
*il
,
532 enum ieee80211_band band
, u16 channel
)
537 case IEEE80211_BAND_5GHZ
:
538 for (i
= 14; i
< il
->channel_count
; i
++) {
539 if (il
->channel_info
[i
].channel
== channel
)
540 return &il
->channel_info
[i
];
543 case IEEE80211_BAND_2GHZ
:
544 if (channel
>= 1 && channel
<= 14)
545 return &il
->channel_info
[channel
- 1];
553 EXPORT_SYMBOL(il_get_channel_info
);