iwl-eeprom.c 16.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/******************************************************************************
 *
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * GPL LICENSE SUMMARY
 *
 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
 * USA
 *
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.GPL.
 *
 * Contact Information:
 *  Intel Linux Wireless <ilw@linux.intel.com>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 * BSD LICENSE
 *
 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name Intel Corporation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>

#include <net/mac80211.h>

#include "iwl-commands.h"
#include "iwl-dev.h"
#include "iwl-core.h"
#include "iwl-debug.h"
#include "iwl-eeprom.h"
#include "iwl-io.h"

/************************** EEPROM BANDS ****************************
 *
80
 * The il_eeprom_band definitions below provide the mapping from the
81 82 83
 * EEPROM contents to the specific channel number supported for each
 * band.
 *
S
Stanislaw Gruszka 已提交
84
 * For example, il_priv->eeprom.band_3_channels[4] from the band_3
85 86 87 88 89
 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
 * The specific geography and calibration information for that channel
 * is contained in the eeprom map itself.
 *
 * During init, we copy the eeprom information and channel map
S
Stanislaw Gruszka 已提交
90
 * information into il->channel_info_24/52 and il->channel_map_24/52
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
 *
 * channel_map_24/52 provides the index in the channel_info array for a
 * given channel.  We have to have two separate maps as there is channel
 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
 * band_2
 *
 * A value of 0xff stored in the channel_map indicates that the channel
 * is not supported by the hardware at all.
 *
 * A value of 0xfe in the channel_map indicates that the channel is not
 * valid for Tx with the current hardware.  This means that
 * while the system can tune and receive on a given channel, it may not
 * be able to associate or transmit any frames on that
 * channel.  There is no corresponding channel information for that
 * entry.
 *
 *********************************************************************/

/* 2.4 GHz */
110
const u8 il_eeprom_band_1[14] = {
111 112 113 114
	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
};

/* 5.2 GHz bands */
115
static const u8 il_eeprom_band_2[] = {	/* 4915-5080MHz */
116 117 118
	183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
};

119
static const u8 il_eeprom_band_3[] = {	/* 5170-5320MHz */
120 121 122
	34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
};

123
static const u8 il_eeprom_band_4[] = {	/* 5500-5700MHz */
124 125 126
	100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
};

127
static const u8 il_eeprom_band_5[] = {	/* 5725-5825MHz */
128 129 130
	145, 149, 153, 157, 161, 165
};

131
static const u8 il_eeprom_band_6[] = {       /* 2.4 ht40 channel */
132 133 134
	1, 2, 3, 4, 5, 6, 7
};

135
static const u8 il_eeprom_band_7[] = {       /* 5.2 ht40 channel */
136 137 138 139 140 141 142 143 144
	36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
};

/******************************************************************************
 *
 * EEPROM related functions
 *
******************************************************************************/

S
Stanislaw Gruszka 已提交
145
static int il_eeprom_verify_signature(struct il_priv *il)
146
{
S
Stanislaw Gruszka 已提交
147
	u32 gp = il_read32(il, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
148 149
	int ret = 0;

150
	D_EEPROM("EEPROM signature=0x%08x\n", gp);
151 152 153 154 155
	switch (gp) {
	case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
	case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
		break;
	default:
156
		IL_ERR("bad EEPROM signature,"
157 158 159 160 161 162 163 164
			"EEPROM_GP=0x%08x\n", gp);
		ret = -ENOENT;
		break;
	}
	return ret;
}

const u8
S
Stanislaw Gruszka 已提交
165
*il_eeprom_query_addr(const struct il_priv *il, size_t offset)
166
{
S
Stanislaw Gruszka 已提交
167 168
	BUG_ON(offset >= il->cfg->base_params->eeprom_size);
	return &il->eeprom[offset];
169
}
S
Stanislaw Gruszka 已提交
170
EXPORT_SYMBOL(il_eeprom_query_addr);
171

S
Stanislaw Gruszka 已提交
172
u16 il_eeprom_query16(const struct il_priv *il, size_t offset)
173
{
S
Stanislaw Gruszka 已提交
174
	if (!il->eeprom)
175
		return 0;
S
Stanislaw Gruszka 已提交
176
	return (u16)il->eeprom[offset] | ((u16)il->eeprom[offset + 1] << 8);
177
}
S
Stanislaw Gruszka 已提交
178
EXPORT_SYMBOL(il_eeprom_query16);
179 180

/**
S
Stanislaw Gruszka 已提交
181
 * il_eeprom_init - read EEPROM contents
182
 *
S
Stanislaw Gruszka 已提交
183
 * Load the EEPROM contents from adapter into il->eeprom
184 185 186
 *
 * NOTE:  This routine uses the non-debug IO access functions.
 */
S
Stanislaw Gruszka 已提交
187
int il_eeprom_init(struct il_priv *il)
188 189
{
	__le16 *e;
S
Stanislaw Gruszka 已提交
190
	u32 gp = il_read32(il, CSR_EEPROM_GP);
191 192 193 194 195
	int sz;
	int ret;
	u16 addr;

	/* allocate eeprom */
S
Stanislaw Gruszka 已提交
196
	sz = il->cfg->base_params->eeprom_size;
197
	D_EEPROM("NVM size = %d\n", sz);
S
Stanislaw Gruszka 已提交
198 199
	il->eeprom = kzalloc(sz, GFP_KERNEL);
	if (!il->eeprom) {
200 201 202
		ret = -ENOMEM;
		goto alloc_err;
	}
S
Stanislaw Gruszka 已提交
203
	e = (__le16 *)il->eeprom;
204

S
Stanislaw Gruszka 已提交
205
	il->cfg->ops->lib->apm_ops.init(il);
206

S
Stanislaw Gruszka 已提交
207
	ret = il_eeprom_verify_signature(il);
208
	if (ret < 0) {
209
		IL_ERR("EEPROM not found, EEPROM_GP=0x%08x\n", gp);
210 211 212 213 214
		ret = -ENOENT;
		goto err;
	}

	/* Make sure driver (instead of uCode) is allowed to read EEPROM */
S
Stanislaw Gruszka 已提交
215
	ret = il->cfg->ops->lib->eeprom_ops.acquire_semaphore(il);
216
	if (ret < 0) {
217
		IL_ERR("Failed to acquire EEPROM semaphore.\n");
218 219 220 221 222 223 224 225
		ret = -ENOENT;
		goto err;
	}

	/* eeprom is an array of 16bit values */
	for (addr = 0; addr < sz; addr += sizeof(u16)) {
		u32 r;

S
Stanislaw Gruszka 已提交
226
		_il_write32(il, CSR_EEPROM_REG,
227 228
			     CSR_EEPROM_REG_MSK_ADDR & (addr << 1));

S
Stanislaw Gruszka 已提交
229
		ret = il_poll_bit(il, CSR_EEPROM_REG,
230 231
					  CSR_EEPROM_REG_READ_VALID_MSK,
					  CSR_EEPROM_REG_READ_VALID_MSK,
S
Stanislaw Gruszka 已提交
232
					  IL_EEPROM_ACCESS_TIMEOUT);
233
		if (ret < 0) {
234
			IL_ERR("Time out reading EEPROM[%d]\n",
235 236 237
							addr);
			goto done;
		}
S
Stanislaw Gruszka 已提交
238
		r = _il_read_direct32(il, CSR_EEPROM_REG);
239 240 241
		e[addr / 2] = cpu_to_le16(r >> 16);
	}

242
	D_EEPROM("NVM Type: %s, version: 0x%x\n",
243
		       "EEPROM",
S
Stanislaw Gruszka 已提交
244
		       il_eeprom_query16(il, EEPROM_VERSION));
245 246 247

	ret = 0;
done:
S
Stanislaw Gruszka 已提交
248
	il->cfg->ops->lib->eeprom_ops.release_semaphore(il);
249 250 251

err:
	if (ret)
S
Stanislaw Gruszka 已提交
252
		il_eeprom_free(il);
253
	/* Reset chip to save power until we load uCode during "up". */
S
Stanislaw Gruszka 已提交
254
	il_apm_stop(il);
255 256 257
alloc_err:
	return ret;
}
S
Stanislaw Gruszka 已提交
258
EXPORT_SYMBOL(il_eeprom_init);
259

S
Stanislaw Gruszka 已提交
260
void il_eeprom_free(struct il_priv *il)
261
{
S
Stanislaw Gruszka 已提交
262 263
	kfree(il->eeprom);
	il->eeprom = NULL;
264
}
S
Stanislaw Gruszka 已提交
265
EXPORT_SYMBOL(il_eeprom_free);
266

S
Stanislaw Gruszka 已提交
267
static void il_init_band_reference(const struct il_priv *il,
268
			int eep_band, int *eeprom_ch_count,
S
Stanislaw Gruszka 已提交
269
			const struct il_eeprom_channel **eeprom_ch_info,
270 271
			const u8 **eeprom_ch_index)
{
S
Stanislaw Gruszka 已提交
272
	u32 offset = il->cfg->ops->lib->
273 274 275
			eeprom_ops.regulatory_bands[eep_band - 1];
	switch (eep_band) {
	case 1:		/* 2.4GHz band */
276
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_1);
S
Stanislaw Gruszka 已提交
277
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
278
				il_eeprom_query_addr(il, offset);
279
		*eeprom_ch_index = il_eeprom_band_1;
280 281
		break;
	case 2:		/* 4.9GHz band */
282
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_2);
S
Stanislaw Gruszka 已提交
283
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
284
				il_eeprom_query_addr(il, offset);
285
		*eeprom_ch_index = il_eeprom_band_2;
286 287
		break;
	case 3:		/* 5.2GHz band */
288
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_3);
S
Stanislaw Gruszka 已提交
289
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
290
				il_eeprom_query_addr(il, offset);
291
		*eeprom_ch_index = il_eeprom_band_3;
292 293
		break;
	case 4:		/* 5.5GHz band */
294
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_4);
S
Stanislaw Gruszka 已提交
295
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
296
				il_eeprom_query_addr(il, offset);
297
		*eeprom_ch_index = il_eeprom_band_4;
298 299
		break;
	case 5:		/* 5.7GHz band */
300
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_5);
S
Stanislaw Gruszka 已提交
301
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
302
				il_eeprom_query_addr(il, offset);
303
		*eeprom_ch_index = il_eeprom_band_5;
304 305
		break;
	case 6:		/* 2.4GHz ht40 channels */
306
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_6);
S
Stanislaw Gruszka 已提交
307
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
308
				il_eeprom_query_addr(il, offset);
309
		*eeprom_ch_index = il_eeprom_band_6;
310 311
		break;
	case 7:		/* 5 GHz ht40 channels */
312
		*eeprom_ch_count = ARRAY_SIZE(il_eeprom_band_7);
S
Stanislaw Gruszka 已提交
313
		*eeprom_ch_info = (struct il_eeprom_channel *)
S
Stanislaw Gruszka 已提交
314
				il_eeprom_query_addr(il, offset);
315
		*eeprom_ch_index = il_eeprom_band_7;
316 317 318 319 320 321 322 323 324
		break;
	default:
		BUG();
	}
}

#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
			    ? # x " " : "")
/**
S
Stanislaw Gruszka 已提交
325
 * il_mod_ht40_chan_info - Copy ht40 channel info into driver's il.
326 327 328
 *
 * Does not set up a command, or touch hardware.
 */
S
Stanislaw Gruszka 已提交
329
static int il_mod_ht40_chan_info(struct il_priv *il,
330
			      enum ieee80211_band band, u16 channel,
S
Stanislaw Gruszka 已提交
331
			      const struct il_eeprom_channel *eeprom_ch,
332 333
			      u8 clear_ht40_extension_channel)
{
S
Stanislaw Gruszka 已提交
334
	struct il_channel_info *ch_info;
335

S
Stanislaw Gruszka 已提交
336
	ch_info = (struct il_channel_info *)
S
Stanislaw Gruszka 已提交
337
			il_get_channel_info(il, band, channel);
338

S
Stanislaw Gruszka 已提交
339
	if (!il_is_channel_valid(ch_info))
340 341
		return -1;

342
	D_EEPROM("HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
343 344
			" Ad-Hoc %ssupported\n",
			ch_info->channel,
S
Stanislaw Gruszka 已提交
345
			il_is_channel_a_band(ch_info) ?
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
			"5.2" : "2.4",
			CHECK_AND_PRINT(IBSS),
			CHECK_AND_PRINT(ACTIVE),
			CHECK_AND_PRINT(RADAR),
			CHECK_AND_PRINT(WIDE),
			CHECK_AND_PRINT(DFS),
			eeprom_ch->flags,
			eeprom_ch->max_power_avg,
			((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
			 && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
			"" : "not ");

	ch_info->ht40_eeprom = *eeprom_ch;
	ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
	ch_info->ht40_flags = eeprom_ch->flags;
	if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
		ch_info->ht40_extension_channel &=
					~clear_ht40_extension_channel;

	return 0;
}

#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
			    ? # x " " : "")

/**
S
Stanislaw Gruszka 已提交
372
 * il_init_channel_map - Set up driver's info for all possible channels
373
 */
S
Stanislaw Gruszka 已提交
374
int il_init_channel_map(struct il_priv *il)
375 376 377
{
	int eeprom_ch_count = 0;
	const u8 *eeprom_ch_index = NULL;
S
Stanislaw Gruszka 已提交
378
	const struct il_eeprom_channel *eeprom_ch_info = NULL;
379
	int band, ch;
S
Stanislaw Gruszka 已提交
380
	struct il_channel_info *ch_info;
381

S
Stanislaw Gruszka 已提交
382
	if (il->channel_count) {
383
		D_EEPROM("Channel map already initialized.\n");
384 385 386
		return 0;
	}

387
	D_EEPROM("Initializing regulatory info from EEPROM\n");
388

S
Stanislaw Gruszka 已提交
389
	il->channel_count =
390 391 392 393 394
	    ARRAY_SIZE(il_eeprom_band_1) +
	    ARRAY_SIZE(il_eeprom_band_2) +
	    ARRAY_SIZE(il_eeprom_band_3) +
	    ARRAY_SIZE(il_eeprom_band_4) +
	    ARRAY_SIZE(il_eeprom_band_5);
395

396
	D_EEPROM("Parsing data for %d channels.\n",
S
Stanislaw Gruszka 已提交
397
			il->channel_count);
398

S
Stanislaw Gruszka 已提交
399 400 401
	il->channel_info = kzalloc(sizeof(struct il_channel_info) *
				     il->channel_count, GFP_KERNEL);
	if (!il->channel_info) {
402
		IL_ERR("Could not allocate channel_info\n");
S
Stanislaw Gruszka 已提交
403
		il->channel_count = 0;
404 405 406
		return -ENOMEM;
	}

S
Stanislaw Gruszka 已提交
407
	ch_info = il->channel_info;
408 409 410 411 412 413

	/* Loop through the 5 EEPROM bands adding them in order to the
	 * channel map we maintain (that contains additional information than
	 * what just in the EEPROM) */
	for (band = 1; band <= 5; band++) {

S
Stanislaw Gruszka 已提交
414
		il_init_band_reference(il, band, &eeprom_ch_count,
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
					&eeprom_ch_info, &eeprom_ch_index);

		/* Loop through each band adding each of the channels */
		for (ch = 0; ch < eeprom_ch_count; ch++) {
			ch_info->channel = eeprom_ch_index[ch];
			ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
			    IEEE80211_BAND_5GHZ;

			/* permanently store EEPROM's channel regulatory flags
			 *   and max power in channel info database. */
			ch_info->eeprom = eeprom_ch_info[ch];

			/* Copy the run-time flags so they are there even on
			 * invalid channels */
			ch_info->flags = eeprom_ch_info[ch].flags;
			/* First write that ht40 is not enabled, and then enable
			 * one by one */
			ch_info->ht40_extension_channel =
					IEEE80211_CHAN_NO_HT40;

S
Stanislaw Gruszka 已提交
435
			if (!(il_is_channel_valid(ch_info))) {
436
				D_EEPROM(
437 438 439 440
					       "Ch. %d Flags %x [%sGHz] - "
					       "No traffic\n",
					       ch_info->channel,
					       ch_info->flags,
S
Stanislaw Gruszka 已提交
441
					       il_is_channel_a_band(ch_info) ?
442 443 444 445 446 447 448 449 450 451 452
					       "5.2" : "2.4");
				ch_info++;
				continue;
			}

			/* Initialize regulatory-based run-time data */
			ch_info->max_power_avg = ch_info->curr_txpow =
			    eeprom_ch_info[ch].max_power_avg;
			ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
			ch_info->min_power = 0;

453
			D_EEPROM("Ch. %d [%sGHz] "
454 455 456
				       "%s%s%s%s%s%s(0x%02x %ddBm):"
				       " Ad-Hoc %ssupported\n",
				       ch_info->channel,
S
Stanislaw Gruszka 已提交
457
				       il_is_channel_a_band(ch_info) ?
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
				       "5.2" : "2.4",
				       CHECK_AND_PRINT_I(VALID),
				       CHECK_AND_PRINT_I(IBSS),
				       CHECK_AND_PRINT_I(ACTIVE),
				       CHECK_AND_PRINT_I(RADAR),
				       CHECK_AND_PRINT_I(WIDE),
				       CHECK_AND_PRINT_I(DFS),
				       eeprom_ch_info[ch].flags,
				       eeprom_ch_info[ch].max_power_avg,
				       ((eeprom_ch_info[ch].
					 flags & EEPROM_CHANNEL_IBSS)
					&& !(eeprom_ch_info[ch].
					     flags & EEPROM_CHANNEL_RADAR))
				       ? "" : "not ");

			ch_info++;
		}
	}

	/* Check if we do have HT40 channels */
S
Stanislaw Gruszka 已提交
478
	if (il->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
479
	    EEPROM_REGULATORY_BAND_NO_HT40 &&
S
Stanislaw Gruszka 已提交
480
	    il->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
481 482 483 484 485 486 487
	    EEPROM_REGULATORY_BAND_NO_HT40)
		return 0;

	/* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
	for (band = 6; band <= 7; band++) {
		enum ieee80211_band ieeeband;

S
Stanislaw Gruszka 已提交
488
		il_init_band_reference(il, band, &eeprom_ch_count,
489 490 491 492 493 494 495 496 497
					&eeprom_ch_info, &eeprom_ch_index);

		/* EEPROM band 6 is 2.4, band 7 is 5 GHz */
		ieeeband =
			(band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;

		/* Loop through each band adding each of the channels */
		for (ch = 0; ch < eeprom_ch_count; ch++) {
			/* Set up driver's info for lower half */
S
Stanislaw Gruszka 已提交
498
			il_mod_ht40_chan_info(il, ieeeband,
499 500 501 502 503
						eeprom_ch_index[ch],
						&eeprom_ch_info[ch],
						IEEE80211_CHAN_NO_HT40PLUS);

			/* Set up driver's info for upper half */
S
Stanislaw Gruszka 已提交
504
			il_mod_ht40_chan_info(il, ieeeband,
505 506 507 508 509 510 511 512
						eeprom_ch_index[ch] + 4,
						&eeprom_ch_info[ch],
						IEEE80211_CHAN_NO_HT40MINUS);
		}
	}

	return 0;
}
S
Stanislaw Gruszka 已提交
513
EXPORT_SYMBOL(il_init_channel_map);
514 515

/*
S
Stanislaw Gruszka 已提交
516
 * il_free_channel_map - undo allocations in il_init_channel_map
517
 */
S
Stanislaw Gruszka 已提交
518
void il_free_channel_map(struct il_priv *il)
519
{
S
Stanislaw Gruszka 已提交
520 521
	kfree(il->channel_info);
	il->channel_count = 0;
522
}
S
Stanislaw Gruszka 已提交
523
EXPORT_SYMBOL(il_free_channel_map);
524 525

/**
S
Stanislaw Gruszka 已提交
526
 * il_get_channel_info - Find driver's ilate channel info
527 528 529 530
 *
 * Based on band and channel number.
 */
const struct
S
Stanislaw Gruszka 已提交
531
il_channel_info *il_get_channel_info(const struct il_priv *il,
532 533 534 535 536 537
					enum ieee80211_band band, u16 channel)
{
	int i;

	switch (band) {
	case IEEE80211_BAND_5GHZ:
S
Stanislaw Gruszka 已提交
538 539 540
		for (i = 14; i < il->channel_count; i++) {
			if (il->channel_info[i].channel == channel)
				return &il->channel_info[i];
541 542 543 544
		}
		break;
	case IEEE80211_BAND_2GHZ:
		if (channel >= 1 && channel <= 14)
S
Stanislaw Gruszka 已提交
545
			return &il->channel_info[channel - 1];
546 547 548 549 550 551 552
		break;
	default:
		BUG();
	}

	return NULL;
}
S
Stanislaw Gruszka 已提交
553
EXPORT_SYMBOL(il_get_channel_info);