62 #include <linux/types.h>
63 #include <linux/slab.h>
64 #include <linux/export.h>
71 #define ADDRESS_MSK 0x0000FFFF
72 #define INDIRECT_TYPE_MSK 0x000F0000
73 #define INDIRECT_HOST 0x00010000
74 #define INDIRECT_GENERAL 0x00020000
75 #define INDIRECT_REGULATORY 0x00030000
76 #define INDIRECT_CALIBRATION 0x00040000
77 #define INDIRECT_PROCESS_ADJST 0x00050000
78 #define INDIRECT_OTHERS 0x00060000
79 #define INDIRECT_TXP_LIMIT 0x00070000
80 #define INDIRECT_TXP_LIMIT_SIZE 0x00080000
81 #define INDIRECT_ADDRESS 0x00100000
84 #define EEPROM_LINK_HOST (2*0x64)
85 #define EEPROM_LINK_GENERAL (2*0x65)
86 #define EEPROM_LINK_REGULATORY (2*0x66)
87 #define EEPROM_LINK_CALIBRATION (2*0x67)
88 #define EEPROM_LINK_PROCESS_ADJST (2*0x68)
89 #define EEPROM_LINK_OTHERS (2*0x69)
90 #define EEPROM_LINK_TXP_LIMIT (2*0x6a)
91 #define EEPROM_LINK_TXP_LIMIT_SIZE (2*0x6b)
94 #define EEPROM_DEVICE_ID (2*0x08)
95 #define EEPROM_SUBSYSTEM_ID (2*0x0A)
96 #define EEPROM_MAC_ADDRESS (2*0x15)
97 #define EEPROM_BOARD_REVISION (2*0x35)
98 #define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1)
99 #define EEPROM_VERSION (2*0x44)
100 #define EEPROM_SKU_CAP (2*0x45)
101 #define EEPROM_OEM_MODE (2*0x46)
102 #define EEPROM_RADIO_CONFIG (2*0x48)
103 #define EEPROM_NUM_MAC_ADDRESS (2*0x4C)
112 #define EEPROM_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
113 #define EEPROM_XTAL ((2*0x128) | EEPROM_CALIB_ALL)
116 #define EEPROM_KELVIN_TEMPERATURE ((2*0x12A) | EEPROM_CALIB_ALL)
117 #define EEPROM_RAW_TEMPERATURE ((2*0x12B) | EEPROM_CALIB_ALL)
126 static const u8 iwl_eeprom_band_1[14] = {
127 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
130 static const u8 iwl_eeprom_band_2[] = {
131 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
134 static const u8 iwl_eeprom_band_3[] = {
135 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
138 static const u8 iwl_eeprom_band_4[] = {
139 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
142 static const u8 iwl_eeprom_band_5[] = {
143 145, 149, 153, 157, 161, 165
146 static const u8 iwl_eeprom_band_6[] = {
150 static const u8 iwl_eeprom_band_7[] = {
151 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
154 #define IWL_NUM_CHANNELS (ARRAY_SIZE(iwl_eeprom_band_1) + \
155 ARRAY_SIZE(iwl_eeprom_band_2) + \
156 ARRAY_SIZE(iwl_eeprom_band_3) + \
157 ARRAY_SIZE(iwl_eeprom_band_4) + \
158 ARRAY_SIZE(iwl_eeprom_band_5))
162 { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
163 { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
165 { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
167 { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
169 { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
170 { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
171 { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
172 { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
173 { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
174 { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
175 { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
176 { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
178 #define RATES_24_OFFS 0
179 #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
180 #define RATES_52_OFFS 4
181 #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
187 if (
WARN_ON(offset +
sizeof(
u16) > eeprom_size))
202 offset = iwl_eeprom_query16(eeprom, eeprom_size,
206 offset = iwl_eeprom_query16(eeprom, eeprom_size,
210 offset = iwl_eeprom_query16(eeprom, eeprom_size,
214 offset = iwl_eeprom_query16(eeprom, eeprom_size,
218 offset = iwl_eeprom_query16(eeprom, eeprom_size,
222 offset = iwl_eeprom_query16(eeprom, eeprom_size,
226 offset = iwl_eeprom_query16(eeprom, eeprom_size,
230 offset = iwl_eeprom_query16(eeprom, eeprom_size,
242 static const u8 *iwl_eeprom_query_addr(
const u8 *eeprom,
size_t eeprom_size,
245 u32 address = eeprom_indirect_address(eeprom, eeprom_size, offset);
247 if (
WARN_ON(address >= eeprom_size))
253 static int iwl_eeprom_read_calib(
const u8 *eeprom,
size_t eeprom_size,
258 hdr = (
void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
359 #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
360 #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
361 #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
363 #define TXP_CHECK_AND_PRINT(x) \
364 ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) ? # x " " : "")
369 int n_channels,
s8 max_txpower_avg)
377 for (ch_idx = 0; ch_idx < n_channels; ch_idx++) {
385 if (band != chan->
band)
394 static void iwl_eeprom_enhanced_txpower(
struct device *
dev,
396 const u8 *eeprom,
size_t eeprom_size,
402 s8 max_txp_avg_halfdbm;
407 txp_len = (
__le16 *)iwl_eeprom_query_addr(eeprom, eeprom_size,
411 txp_array = (
void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
414 for (idx = 0; idx <
entries; idx++) {
415 txp = &txp_array[
idx];
424 "Channel" :
"Common",
436 "\t\t chain_A: 0x%02x chain_B: 0X%02x chain_C: 0X%02x\n",
440 "\t\t MIMO2: 0x%02x MIMO3: 0x%02x High 20_on_40: 0x%02x Low 20_on_40: 0x%02x\n",
445 max_txp_avg_halfdbm = iwl_get_max_txpwr_half_dbm(data, txp);
447 iwl_eeprom_enh_txp_read_element(data, txp, n_channels,
455 static void iwl_init_band_reference(
const struct iwl_cfg *
cfg,
456 const u8 *eeprom,
size_t eeprom_size,
457 int eeprom_band,
int *eeprom_ch_count,
459 const u8 **eeprom_ch_array)
465 *ch_info = (
void *)iwl_eeprom_query_addr(eeprom, eeprom_size, offset);
467 switch (eeprom_band) {
469 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_1);
470 *eeprom_ch_array = iwl_eeprom_band_1;
473 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_2);
474 *eeprom_ch_array = iwl_eeprom_band_2;
477 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_3);
478 *eeprom_ch_array = iwl_eeprom_band_3;
481 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_4);
482 *eeprom_ch_array = iwl_eeprom_band_4;
485 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_5);
486 *eeprom_ch_array = iwl_eeprom_band_5;
489 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_6);
490 *eeprom_ch_array = iwl_eeprom_band_6;
493 *eeprom_ch_count =
ARRAY_SIZE(iwl_eeprom_band_7);
494 *eeprom_ch_array = iwl_eeprom_band_7;
497 *eeprom_ch_count = 0;
498 *eeprom_ch_array =
NULL;
503 #define CHECK_AND_PRINT(x) \
504 ((eeprom_ch->flags & EEPROM_CHANNEL_##x) ? # x " " : "")
506 static void iwl_mod_ht40_chan_info(
struct device *dev,
510 u8 clear_ht40_extension_channel)
515 for (i = 0; i < n_channels; i++) {
518 if (data->
channels[i].hw_value != channel)
528 "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
543 chan->
flags &= ~clear_ht40_extension_channel;
546 #define CHECK_AND_PRINT_I(x) \
547 ((eeprom_ch_info[ch_idx].flags & EEPROM_CHANNEL_##x) ? # x " " : "")
549 static int iwl_init_channel_map(
struct device *dev,
const struct iwl_cfg *cfg,
551 const u8 *eeprom,
size_t eeprom_size)
555 const u8 *eeprom_ch_array;
562 for (band = 1; band <= 5; band++) {
565 iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
566 &eeprom_ch_count, &eeprom_ch_info,
570 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
573 eeprom_ch = &eeprom_ch_info[ch_idx];
577 "Ch. %d Flags %x [%sGHz] - No traffic\n",
578 eeprom_ch_array[ch_idx],
579 eeprom_ch_info[ch_idx].
flags,
580 (band != 1) ?
"5.2" :
"2.4");
584 channel = &data->
channels[n_channels];
587 channel->
hw_value = eeprom_ch_array[ch_idx];
610 "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
612 (band != 1) ?
"5.2" :
"2.4",
619 eeprom_ch_info[ch_idx].
flags,
621 ((eeprom_ch_info[ch_idx].flags &
623 !(eeprom_ch_info[ch_idx].flags &
636 iwl_eeprom_enhanced_txpower(dev, data, eeprom, eeprom_size,
644 for (i = 0; i < n_channels; i++)
658 for (band = 6; band <= 7; band++) {
661 iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
662 &eeprom_ch_count, &eeprom_ch_info,
670 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
672 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
673 eeprom_ch_array[ch_idx],
674 &eeprom_ch_info[ch_idx],
678 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
679 eeprom_ch_array[ch_idx] + 4,
680 &eeprom_ch_info[ch_idx],
695 while (chan->
band != band && idx < n_channels)
700 while (chan->
band == band && idx < n_channels) {
710 #define MAX_BIT_RATE_40_MHZ 150
711 #define MAX_BIT_RATE_20_MHZ 72
713 static void iwl_init_ht_hw_capab(
const struct iwl_cfg *cfg,
718 int max_bit_rate = 0;
742 ht_info->
mcs.rx_mask[0] = 0xFF;
744 ht_info->
mcs.rx_mask[1] = 0xFF;
746 ht_info->
mcs.rx_mask[2] = 0xFF;
748 if (cfg->
ht_params->ht_greenfield_support)
757 ht_info->
mcs.rx_mask[4] = 0x01;
762 max_bit_rate *= rx_chains;
768 if (tx_chains != rx_chains) {
770 ht_info->
mcs.tx_params |= ((tx_chains - 1) <<
775 static void iwl_init_sbands(
struct device *dev,
const struct iwl_cfg *cfg,
777 const u8 *eeprom,
size_t eeprom_size)
779 int n_channels = iwl_init_channel_map(dev, cfg, data,
780 eeprom, eeprom_size);
788 n_used += iwl_init_sband_channels(data, sband, n_channels,
796 n_used += iwl_init_sband_channels(data, sband, n_channels,
800 if (n_channels != n_used)
801 IWL_ERR_DEV(dev,
"EEPROM: used only %d of %d channels\n",
809 const u8 *eeprom,
size_t eeprom_size)
817 data = kzalloc(
sizeof(*data) +
828 data->
n_hw_addrs = iwl_eeprom_query16(eeprom, eeprom_size,
831 if (iwl_eeprom_read_calib(eeprom, eeprom_size, data))
834 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
EEPROM_XTAL);
839 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
845 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
852 data->
radio_cfg = iwl_eeprom_query16(eeprom, eeprom_size,
854 data->
sku = iwl_eeprom_query16(eeprom, eeprom_size,
872 IWL_ERR_DEV(dev,
"invalid antennas (0x%x, 0x%x)\n",
877 iwl_init_sbands(dev, cfg, data, eeprom, eeprom_size);
892 IWL_INFO(trans,
"device EEPROM VER=0x%x, CALIB=0x%x\n",
898 "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",