1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2005-2014, 2018-2019, 2021, 2024-2025 Intel Corporation 4 */ 5 #include <linux/types.h> 6 #include <linux/slab.h> 7 #include <linux/export.h> 8 9 #include "iwl-drv.h" 10 #include "iwl-debug.h" 11 #include "iwl-io.h" 12 #include "iwl-prph.h" 13 #include "iwl-csr.h" 14 #include "agn.h" 15 16 /* EEPROM offset definitions */ 17 18 /* indirect access definitions */ 19 #define ADDRESS_MSK 0x0000FFFF 20 #define INDIRECT_TYPE_MSK 0x000F0000 21 #define INDIRECT_HOST 0x00010000 22 #define INDIRECT_GENERAL 0x00020000 23 #define INDIRECT_REGULATORY 0x00030000 24 #define INDIRECT_CALIBRATION 0x00040000 25 #define INDIRECT_PROCESS_ADJST 0x00050000 26 #define INDIRECT_OTHERS 0x00060000 27 #define INDIRECT_TXP_LIMIT 0x00070000 28 #define INDIRECT_TXP_LIMIT_SIZE 0x00080000 29 #define INDIRECT_ADDRESS 0x00100000 30 31 /* corresponding link offsets in EEPROM */ 32 #define EEPROM_LINK_HOST (2*0x64) 33 #define EEPROM_LINK_GENERAL (2*0x65) 34 #define EEPROM_LINK_REGULATORY (2*0x66) 35 #define EEPROM_LINK_CALIBRATION (2*0x67) 36 #define EEPROM_LINK_PROCESS_ADJST (2*0x68) 37 #define EEPROM_LINK_OTHERS (2*0x69) 38 #define EEPROM_LINK_TXP_LIMIT (2*0x6a) 39 #define EEPROM_LINK_TXP_LIMIT_SIZE (2*0x6b) 40 41 /* General */ 42 #define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */ 43 #define EEPROM_SUBSYSTEM_ID (2*0x0A) /* 2 bytes */ 44 #define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */ 45 #define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */ 46 #define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */ 47 #define EEPROM_VERSION (2*0x44) /* 2 bytes */ 48 #define EEPROM_SKU_CAP (2*0x45) /* 2 bytes */ 49 #define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */ 50 #define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */ 51 #define EEPROM_NUM_MAC_ADDRESS (2*0x4C) /* 2 bytes */ 52 53 /* calibration */ 54 struct iwl_eeprom_calib_hdr { 55 u8 version; 56 u8 pa_type; 57 __le16 voltage; 58 } __packed; 59 60 #define EEPROM_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION) 61 #define EEPROM_XTAL ((2*0x128) | EEPROM_CALIB_ALL) 62 63 /* temperature */ 64 #define EEPROM_KELVIN_TEMPERATURE ((2*0x12A) | EEPROM_CALIB_ALL) 65 #define EEPROM_RAW_TEMPERATURE ((2*0x12B) | EEPROM_CALIB_ALL) 66 67 /* SKU Capabilities (actual values from EEPROM definition) */ 68 enum eeprom_sku_bits { 69 EEPROM_SKU_CAP_BAND_24GHZ = BIT(4), 70 EEPROM_SKU_CAP_BAND_52GHZ = BIT(5), 71 EEPROM_SKU_CAP_11N_ENABLE = BIT(6), 72 EEPROM_SKU_CAP_AMT_ENABLE = BIT(7), 73 EEPROM_SKU_CAP_IPAN_ENABLE = BIT(8) 74 }; 75 76 /* radio config bits (actual values from EEPROM definition) */ 77 #define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */ 78 #define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */ 79 #define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */ 80 #define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */ 81 #define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */ 82 #define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */ 83 84 /* 85 * EEPROM bands 86 * These are the channel numbers from each band in the order 87 * that they are stored in the EEPROM band information. Note 88 * that EEPROM bands aren't the same as mac80211 bands, and 89 * there are even special "ht40 bands" in the EEPROM. 90 */ 91 static const u8 iwl_eeprom_band_1[14] = { /* 2.4 GHz */ 92 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 93 }; 94 95 static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */ 96 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 97 }; 98 99 static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */ 100 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 101 }; 102 103 static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */ 104 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 105 }; 106 107 static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */ 108 145, 149, 153, 157, 161, 165 109 }; 110 111 static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */ 112 1, 2, 3, 4, 5, 6, 7 113 }; 114 115 static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */ 116 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 117 }; 118 119 #define IWL_NUM_CHANNELS (ARRAY_SIZE(iwl_eeprom_band_1) + \ 120 ARRAY_SIZE(iwl_eeprom_band_2) + \ 121 ARRAY_SIZE(iwl_eeprom_band_3) + \ 122 ARRAY_SIZE(iwl_eeprom_band_4) + \ 123 ARRAY_SIZE(iwl_eeprom_band_5)) 124 125 /* rate data (static) */ 126 static struct ieee80211_rate iwl_cfg80211_rates[] = { 127 { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, }, 128 { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1, 129 .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, 130 { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2, 131 .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, 132 { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3, 133 .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, 134 { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, }, 135 { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, }, 136 { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, }, 137 { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, }, 138 { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, }, 139 { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, }, 140 { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, }, 141 { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, }, 142 }; 143 #define RATES_24_OFFS 0 144 #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates) 145 #define RATES_52_OFFS 4 146 #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS) 147 148 /* EEPROM reading functions */ 149 150 static u16 iwl_eeprom_query16(const u8 *eeprom, size_t eeprom_size, int offset) 151 { 152 if (WARN_ON(offset + sizeof(u16) > eeprom_size)) 153 return 0; 154 return le16_to_cpup((const __le16 *)(eeprom + offset)); 155 } 156 157 static u32 eeprom_indirect_address(const u8 *eeprom, size_t eeprom_size, 158 u32 address) 159 { 160 u16 offset = 0; 161 162 if ((address & INDIRECT_ADDRESS) == 0) 163 return address; 164 165 switch (address & INDIRECT_TYPE_MSK) { 166 case INDIRECT_HOST: 167 offset = iwl_eeprom_query16(eeprom, eeprom_size, 168 EEPROM_LINK_HOST); 169 break; 170 case INDIRECT_GENERAL: 171 offset = iwl_eeprom_query16(eeprom, eeprom_size, 172 EEPROM_LINK_GENERAL); 173 break; 174 case INDIRECT_REGULATORY: 175 offset = iwl_eeprom_query16(eeprom, eeprom_size, 176 EEPROM_LINK_REGULATORY); 177 break; 178 case INDIRECT_TXP_LIMIT: 179 offset = iwl_eeprom_query16(eeprom, eeprom_size, 180 EEPROM_LINK_TXP_LIMIT); 181 break; 182 case INDIRECT_TXP_LIMIT_SIZE: 183 offset = iwl_eeprom_query16(eeprom, eeprom_size, 184 EEPROM_LINK_TXP_LIMIT_SIZE); 185 break; 186 case INDIRECT_CALIBRATION: 187 offset = iwl_eeprom_query16(eeprom, eeprom_size, 188 EEPROM_LINK_CALIBRATION); 189 break; 190 case INDIRECT_PROCESS_ADJST: 191 offset = iwl_eeprom_query16(eeprom, eeprom_size, 192 EEPROM_LINK_PROCESS_ADJST); 193 break; 194 case INDIRECT_OTHERS: 195 offset = iwl_eeprom_query16(eeprom, eeprom_size, 196 EEPROM_LINK_OTHERS); 197 break; 198 default: 199 WARN_ON(1); 200 break; 201 } 202 203 /* translate the offset from words to byte */ 204 return (address & ADDRESS_MSK) + (offset << 1); 205 } 206 207 static const void *iwl_eeprom_query_addr(const u8 *eeprom, size_t eeprom_size, 208 u32 offset) 209 { 210 u32 address = eeprom_indirect_address(eeprom, eeprom_size, offset); 211 212 if (WARN_ON(address >= eeprom_size)) 213 return NULL; 214 215 return &eeprom[address]; 216 } 217 218 static int iwl_eeprom_read_calib(const u8 *eeprom, size_t eeprom_size, 219 struct iwl_nvm_data *data) 220 { 221 const struct iwl_eeprom_calib_hdr *hdr; 222 223 hdr = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_CALIB_ALL); 224 if (!hdr) 225 return -ENODATA; 226 data->calib_version = hdr->version; 227 data->calib_voltage = hdr->voltage; 228 229 return 0; 230 } 231 232 /** 233 * enum iwl_eeprom_channel_flags - channel flags in EEPROM 234 * @EEPROM_CHANNEL_VALID: channel is usable for this SKU/geo 235 * @EEPROM_CHANNEL_IBSS: usable as an IBSS channel 236 * @EEPROM_CHANNEL_ACTIVE: active scanning allowed 237 * @EEPROM_CHANNEL_RADAR: radar detection required 238 * @EEPROM_CHANNEL_WIDE: 20 MHz channel okay (?) 239 * @EEPROM_CHANNEL_DFS: dynamic freq selection candidate 240 */ 241 enum iwl_eeprom_channel_flags { 242 EEPROM_CHANNEL_VALID = BIT(0), 243 EEPROM_CHANNEL_IBSS = BIT(1), 244 EEPROM_CHANNEL_ACTIVE = BIT(3), 245 EEPROM_CHANNEL_RADAR = BIT(4), 246 EEPROM_CHANNEL_WIDE = BIT(5), 247 EEPROM_CHANNEL_DFS = BIT(7), 248 }; 249 250 /** 251 * struct iwl_eeprom_channel - EEPROM channel data 252 * @flags: %EEPROM_CHANNEL_* flags 253 * @max_power_avg: max power (in dBm) on this channel, at most 31 dBm 254 */ 255 struct iwl_eeprom_channel { 256 u8 flags; 257 s8 max_power_avg; 258 } __packed; 259 260 enum iwl_eeprom_enhanced_txpwr_flags { 261 IWL_EEPROM_ENH_TXP_FL_VALID = BIT(0), 262 IWL_EEPROM_ENH_TXP_FL_BAND_52G = BIT(1), 263 IWL_EEPROM_ENH_TXP_FL_OFDM = BIT(2), 264 IWL_EEPROM_ENH_TXP_FL_40MHZ = BIT(3), 265 IWL_EEPROM_ENH_TXP_FL_HT_AP = BIT(4), 266 IWL_EEPROM_ENH_TXP_FL_RES1 = BIT(5), 267 IWL_EEPROM_ENH_TXP_FL_RES2 = BIT(6), 268 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE = BIT(7), 269 }; 270 271 /** 272 * struct iwl_eeprom_enhanced_txpwr - enhanced regulatory TX power limits 273 * @flags: entry flags 274 * @channel: channel number 275 * @chain_a_max: chain a max power in 1/2 dBm 276 * @chain_b_max: chain b max power in 1/2 dBm 277 * @chain_c_max: chain c max power in 1/2 dBm 278 * @delta_20_in_40: 20-in-40 deltas (hi/lo) 279 * @mimo2_max: mimo2 max power in 1/2 dBm 280 * @mimo3_max: mimo3 max power in 1/2 dBm 281 * 282 * This structure presents the enhanced regulatory tx power limit layout 283 * in an EEPROM image. 284 */ 285 struct iwl_eeprom_enhanced_txpwr { 286 u8 flags; 287 u8 channel; 288 s8 chain_a_max; 289 s8 chain_b_max; 290 s8 chain_c_max; 291 u8 delta_20_in_40; 292 s8 mimo2_max; 293 s8 mimo3_max; 294 } __packed; 295 296 static s8 iwl_get_max_txpwr_half_dbm(const struct iwl_nvm_data *data, 297 const struct iwl_eeprom_enhanced_txpwr *txp) 298 { 299 s8 result = 0; /* (.5 dBm) */ 300 301 /* Take the highest tx power from any valid chains */ 302 if (data->valid_tx_ant & ANT_A && txp->chain_a_max > result) 303 result = txp->chain_a_max; 304 305 if (data->valid_tx_ant & ANT_B && txp->chain_b_max > result) 306 result = txp->chain_b_max; 307 308 if (data->valid_tx_ant & ANT_C && txp->chain_c_max > result) 309 result = txp->chain_c_max; 310 311 if ((data->valid_tx_ant == ANT_AB || 312 data->valid_tx_ant == ANT_BC || 313 data->valid_tx_ant == ANT_AC) && txp->mimo2_max > result) 314 result = txp->mimo2_max; 315 316 if (data->valid_tx_ant == ANT_ABC && txp->mimo3_max > result) 317 result = txp->mimo3_max; 318 319 return result; 320 } 321 322 #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT) 323 #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr) 324 #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE) 325 326 #define TXP_CHECK_AND_PRINT(x) \ 327 ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) ? # x " " : "") 328 329 static void 330 iwl_eeprom_enh_txp_read_element(struct iwl_nvm_data *data, 331 const struct iwl_eeprom_enhanced_txpwr *txp, 332 int n_channels, s8 max_txpower_avg) 333 { 334 int ch_idx; 335 enum nl80211_band band; 336 337 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ? 338 NL80211_BAND_5GHZ : NL80211_BAND_2GHZ; 339 340 for (ch_idx = 0; ch_idx < n_channels; ch_idx++) { 341 struct ieee80211_channel *chan = &data->channels[ch_idx]; 342 343 /* update matching channel or from common data only */ 344 if (txp->channel != 0 && chan->hw_value != txp->channel) 345 continue; 346 347 /* update matching band only */ 348 if (band != chan->band) 349 continue; 350 351 if (chan->max_power < max_txpower_avg && 352 !(txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ)) 353 chan->max_power = max_txpower_avg; 354 } 355 } 356 357 static void iwl_eeprom_enhanced_txpower(struct device *dev, 358 struct iwl_nvm_data *data, 359 const u8 *eeprom, size_t eeprom_size, 360 int n_channels) 361 { 362 const struct iwl_eeprom_enhanced_txpwr *txp_array, *txp; 363 int idx, entries; 364 const __le16 *txp_len; 365 s8 max_txp_avg_halfdbm; 366 367 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8); 368 369 /* the length is in 16-bit words, but we want entries */ 370 txp_len = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_TXP_SZ_OFFS); 371 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN; 372 373 txp_array = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_TXP_OFFS); 374 375 for (idx = 0; idx < entries; idx++) { 376 txp = &txp_array[idx]; 377 /* skip invalid entries */ 378 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID)) 379 continue; 380 381 IWL_DEBUG_EEPROM(dev, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n", 382 (txp->channel && (txp->flags & 383 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ? 384 "Common " : (txp->channel) ? 385 "Channel" : "Common", 386 (txp->channel), 387 TXP_CHECK_AND_PRINT(VALID), 388 TXP_CHECK_AND_PRINT(BAND_52G), 389 TXP_CHECK_AND_PRINT(OFDM), 390 TXP_CHECK_AND_PRINT(40MHZ), 391 TXP_CHECK_AND_PRINT(HT_AP), 392 TXP_CHECK_AND_PRINT(RES1), 393 TXP_CHECK_AND_PRINT(RES2), 394 TXP_CHECK_AND_PRINT(COMMON_TYPE), 395 txp->flags); 396 IWL_DEBUG_EEPROM(dev, 397 "\t\t chain_A: %d chain_B: %d chain_C: %d\n", 398 txp->chain_a_max, txp->chain_b_max, 399 txp->chain_c_max); 400 IWL_DEBUG_EEPROM(dev, 401 "\t\t MIMO2: %d MIMO3: %d High 20_on_40: 0x%02x Low 20_on_40: 0x%02x\n", 402 txp->mimo2_max, txp->mimo3_max, 403 ((txp->delta_20_in_40 & 0xf0) >> 4), 404 (txp->delta_20_in_40 & 0x0f)); 405 406 max_txp_avg_halfdbm = iwl_get_max_txpwr_half_dbm(data, txp); 407 408 iwl_eeprom_enh_txp_read_element(data, txp, n_channels, 409 DIV_ROUND_UP(max_txp_avg_halfdbm, 2)); 410 411 if (max_txp_avg_halfdbm > data->max_tx_pwr_half_dbm) 412 data->max_tx_pwr_half_dbm = max_txp_avg_halfdbm; 413 } 414 } 415 416 static void iwl_init_band_reference(const struct iwl_rf_cfg *cfg, 417 const u8 *eeprom, size_t eeprom_size, 418 int eeprom_band, int *eeprom_ch_count, 419 const struct iwl_eeprom_channel **ch_info, 420 const u8 **eeprom_ch_array) 421 { 422 u32 offset = cfg->eeprom_params->regulatory_bands[eeprom_band - 1]; 423 424 offset |= INDIRECT_ADDRESS | INDIRECT_REGULATORY; 425 426 *ch_info = iwl_eeprom_query_addr(eeprom, eeprom_size, offset); 427 428 switch (eeprom_band) { 429 case 1: /* 2.4GHz band */ 430 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); 431 *eeprom_ch_array = iwl_eeprom_band_1; 432 break; 433 case 2: /* 4.9GHz band */ 434 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); 435 *eeprom_ch_array = iwl_eeprom_band_2; 436 break; 437 case 3: /* 5.2GHz band */ 438 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); 439 *eeprom_ch_array = iwl_eeprom_band_3; 440 break; 441 case 4: /* 5.5GHz band */ 442 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); 443 *eeprom_ch_array = iwl_eeprom_band_4; 444 break; 445 case 5: /* 5.7GHz band */ 446 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); 447 *eeprom_ch_array = iwl_eeprom_band_5; 448 break; 449 case 6: /* 2.4GHz ht40 channels */ 450 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); 451 *eeprom_ch_array = iwl_eeprom_band_6; 452 break; 453 case 7: /* 5 GHz ht40 channels */ 454 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); 455 *eeprom_ch_array = iwl_eeprom_band_7; 456 break; 457 default: 458 *eeprom_ch_count = 0; 459 *eeprom_ch_array = NULL; 460 WARN_ON(1); 461 } 462 } 463 464 #define CHECK_AND_PRINT(x) \ 465 ((eeprom_ch->flags & EEPROM_CHANNEL_##x) ? # x " " : "") 466 467 static void iwl_mod_ht40_chan_info(struct device *dev, 468 struct iwl_nvm_data *data, int n_channels, 469 enum nl80211_band band, u16 channel, 470 const struct iwl_eeprom_channel *eeprom_ch, 471 u8 clear_ht40_extension_channel) 472 { 473 struct ieee80211_channel *chan = NULL; 474 int i; 475 476 for (i = 0; i < n_channels; i++) { 477 if (data->channels[i].band != band) 478 continue; 479 if (data->channels[i].hw_value != channel) 480 continue; 481 chan = &data->channels[i]; 482 break; 483 } 484 485 if (!chan) 486 return; 487 488 IWL_DEBUG_EEPROM(dev, 489 "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n", 490 channel, 491 band == NL80211_BAND_5GHZ ? "5.2" : "2.4", 492 CHECK_AND_PRINT(IBSS), 493 CHECK_AND_PRINT(ACTIVE), 494 CHECK_AND_PRINT(RADAR), 495 CHECK_AND_PRINT(WIDE), 496 CHECK_AND_PRINT(DFS), 497 eeprom_ch->flags, 498 eeprom_ch->max_power_avg, 499 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS) && 500 !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ? "" 501 : "not "); 502 503 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID) 504 chan->flags &= ~clear_ht40_extension_channel; 505 } 506 507 #define CHECK_AND_PRINT_I(x) \ 508 ((eeprom_ch_info[ch_idx].flags & EEPROM_CHANNEL_##x) ? # x " " : "") 509 510 static int iwl_init_channel_map(struct device *dev, const struct iwl_rf_cfg *cfg, 511 struct iwl_nvm_data *data, 512 const u8 *eeprom, size_t eeprom_size) 513 { 514 int band, ch_idx; 515 const struct iwl_eeprom_channel *eeprom_ch_info; 516 const u8 *eeprom_ch_array; 517 int eeprom_ch_count; 518 int n_channels = 0; 519 520 /* 521 * Loop through the 5 EEPROM bands and add them to the parse list 522 */ 523 for (band = 1; band <= 5; band++) { 524 struct ieee80211_channel *channel; 525 526 iwl_init_band_reference(cfg, eeprom, eeprom_size, band, 527 &eeprom_ch_count, &eeprom_ch_info, 528 &eeprom_ch_array); 529 530 /* Loop through each band adding each of the channels */ 531 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) { 532 const struct iwl_eeprom_channel *eeprom_ch; 533 534 eeprom_ch = &eeprom_ch_info[ch_idx]; 535 536 if (!(eeprom_ch->flags & EEPROM_CHANNEL_VALID)) { 537 IWL_DEBUG_EEPROM(dev, 538 "Ch. %d Flags %x [%sGHz] - No traffic\n", 539 eeprom_ch_array[ch_idx], 540 eeprom_ch_info[ch_idx].flags, 541 (band != 1) ? "5.2" : "2.4"); 542 continue; 543 } 544 545 channel = &data->channels[n_channels]; 546 n_channels++; 547 548 channel->hw_value = eeprom_ch_array[ch_idx]; 549 channel->band = (band == 1) ? NL80211_BAND_2GHZ 550 : NL80211_BAND_5GHZ; 551 channel->center_freq = 552 ieee80211_channel_to_frequency( 553 channel->hw_value, channel->band); 554 555 /* set no-HT40, will enable as appropriate later */ 556 channel->flags = IEEE80211_CHAN_NO_HT40; 557 558 if (!(eeprom_ch->flags & EEPROM_CHANNEL_IBSS)) 559 channel->flags |= IEEE80211_CHAN_NO_IR; 560 561 if (!(eeprom_ch->flags & EEPROM_CHANNEL_ACTIVE)) 562 channel->flags |= IEEE80211_CHAN_NO_IR; 563 564 if (eeprom_ch->flags & EEPROM_CHANNEL_RADAR) 565 channel->flags |= IEEE80211_CHAN_RADAR; 566 567 /* Initialize regulatory-based run-time data */ 568 channel->max_power = 569 eeprom_ch_info[ch_idx].max_power_avg; 570 IWL_DEBUG_EEPROM(dev, 571 "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n", 572 channel->hw_value, 573 (band != 1) ? "5.2" : "2.4", 574 CHECK_AND_PRINT_I(VALID), 575 CHECK_AND_PRINT_I(IBSS), 576 CHECK_AND_PRINT_I(ACTIVE), 577 CHECK_AND_PRINT_I(RADAR), 578 CHECK_AND_PRINT_I(WIDE), 579 CHECK_AND_PRINT_I(DFS), 580 eeprom_ch_info[ch_idx].flags, 581 eeprom_ch_info[ch_idx].max_power_avg, 582 ((eeprom_ch_info[ch_idx].flags & 583 EEPROM_CHANNEL_IBSS) && 584 !(eeprom_ch_info[ch_idx].flags & 585 EEPROM_CHANNEL_RADAR)) 586 ? "" : "not "); 587 } 588 } 589 590 if (cfg->eeprom_params->enhanced_txpower) { 591 /* 592 * for newer device (6000 series and up) 593 * EEPROM contain enhanced tx power information 594 * driver need to process addition information 595 * to determine the max channel tx power limits 596 */ 597 iwl_eeprom_enhanced_txpower(dev, data, eeprom, eeprom_size, 598 n_channels); 599 } else { 600 /* All others use data from channel map */ 601 int i; 602 603 data->max_tx_pwr_half_dbm = -128; 604 605 for (i = 0; i < n_channels; i++) 606 data->max_tx_pwr_half_dbm = 607 max_t(s8, data->max_tx_pwr_half_dbm, 608 data->channels[i].max_power * 2); 609 } 610 611 /* Check if we do have HT40 channels */ 612 if (cfg->eeprom_params->regulatory_bands[5] == 613 EEPROM_REGULATORY_BAND_NO_HT40 && 614 cfg->eeprom_params->regulatory_bands[6] == 615 EEPROM_REGULATORY_BAND_NO_HT40) 616 return n_channels; 617 618 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */ 619 for (band = 6; band <= 7; band++) { 620 enum nl80211_band ieeeband; 621 622 iwl_init_band_reference(cfg, eeprom, eeprom_size, band, 623 &eeprom_ch_count, &eeprom_ch_info, 624 &eeprom_ch_array); 625 626 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ 627 ieeeband = (band == 6) ? NL80211_BAND_2GHZ 628 : NL80211_BAND_5GHZ; 629 630 /* Loop through each band adding each of the channels */ 631 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) { 632 /* Set up driver's info for lower half */ 633 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband, 634 eeprom_ch_array[ch_idx], 635 &eeprom_ch_info[ch_idx], 636 IEEE80211_CHAN_NO_HT40PLUS); 637 638 /* Set up driver's info for upper half */ 639 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband, 640 eeprom_ch_array[ch_idx] + 4, 641 &eeprom_ch_info[ch_idx], 642 IEEE80211_CHAN_NO_HT40MINUS); 643 } 644 } 645 646 return n_channels; 647 } 648 /* 649 * EEPROM access time values: 650 * 651 * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG. 652 * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1). 653 * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec. 654 * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG. 655 */ 656 #define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ 657 658 /* 659 * The device's EEPROM semaphore prevents conflicts between driver and uCode 660 * when accessing the EEPROM; each access is a series of pulses to/from the 661 * EEPROM chip, not a single event, so even reads could conflict if they 662 * weren't arbitrated by the semaphore. 663 */ 664 #define IWL_EEPROM_SEM_TIMEOUT 10 /* microseconds */ 665 #define IWL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ 666 667 668 static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans) 669 { 670 u16 count; 671 int ret; 672 673 for (count = 0; count < IWL_EEPROM_SEM_RETRY_LIMIT; count++) { 674 /* Request semaphore */ 675 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, 676 CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); 677 678 /* See if we got it */ 679 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG, 680 CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM, 681 CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM, 682 IWL_EEPROM_SEM_TIMEOUT); 683 if (ret >= 0) { 684 IWL_DEBUG_EEPROM(trans->dev, 685 "Acquired semaphore after %d tries.\n", 686 count+1); 687 return ret; 688 } 689 } 690 691 return ret; 692 } 693 694 static void iwl_eeprom_release_semaphore(struct iwl_trans *trans) 695 { 696 iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG, 697 CSR_HW_IF_CONFIG_REG_EEPROM_OWN_SEM); 698 } 699 700 static int iwl_eeprom_verify_signature(struct iwl_trans *trans, bool nvm_is_otp) 701 { 702 u32 gp = iwl_read32(trans, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK; 703 704 IWL_DEBUG_EEPROM(trans->dev, "EEPROM signature=0x%08x\n", gp); 705 706 switch (gp) { 707 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP: 708 if (!nvm_is_otp) { 709 IWL_ERR(trans, "EEPROM with bad signature: 0x%08x\n", 710 gp); 711 return -ENOENT; 712 } 713 return 0; 714 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K: 715 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K: 716 if (nvm_is_otp) { 717 IWL_ERR(trans, "OTP with bad signature: 0x%08x\n", gp); 718 return -ENOENT; 719 } 720 return 0; 721 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP: 722 default: 723 IWL_ERR(trans, 724 "bad EEPROM/OTP signature, type=%s, EEPROM_GP=0x%08x\n", 725 nvm_is_otp ? "OTP" : "EEPROM", gp); 726 return -ENOENT; 727 } 728 } 729 730 /****************************************************************************** 731 * 732 * OTP related functions 733 * 734 ******************************************************************************/ 735 736 static void iwl_set_otp_access_absolute(struct iwl_trans *trans) 737 { 738 iwl_read32(trans, CSR_OTP_GP_REG); 739 740 iwl_clear_bit(trans, CSR_OTP_GP_REG, 741 CSR_OTP_GP_REG_OTP_ACCESS_MODE); 742 } 743 744 static int iwl_nvm_is_otp(struct iwl_trans *trans) 745 { 746 u32 otpgp; 747 748 /* OTP only valid for CP/PP and after */ 749 switch (trans->info.hw_rev & CSR_HW_REV_TYPE_MSK) { 750 case CSR_HW_REV_TYPE_NONE: 751 IWL_ERR(trans, "Unknown hardware type\n"); 752 return -EIO; 753 case CSR_HW_REV_TYPE_5300: 754 case CSR_HW_REV_TYPE_5350: 755 case CSR_HW_REV_TYPE_5100: 756 case CSR_HW_REV_TYPE_5150: 757 return 0; 758 default: 759 otpgp = iwl_read32(trans, CSR_OTP_GP_REG); 760 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT) 761 return 1; 762 return 0; 763 } 764 } 765 766 static int iwl_init_otp_access(struct iwl_trans *trans) 767 { 768 int ret; 769 770 ret = iwl_finish_nic_init(trans); 771 if (ret) 772 return ret; 773 774 iwl_set_bits_prph(trans, APMG_PS_CTRL_REG, 775 APMG_PS_CTRL_VAL_RESET_REQ); 776 udelay(5); 777 iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG, 778 APMG_PS_CTRL_VAL_RESET_REQ); 779 780 /* 781 * CSR auto clock gate disable bit - 782 * this is only applicable for HW with OTP shadow RAM 783 */ 784 if (trans->mac_cfg->base->shadow_ram_support) 785 iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, 786 CSR_RESET_LINK_PWR_MGMT_DISABLED); 787 788 return 0; 789 } 790 791 static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, 792 __le16 *eeprom_data) 793 { 794 int ret = 0; 795 u32 r; 796 u32 otpgp; 797 798 iwl_write32(trans, CSR_EEPROM_REG, 799 CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); 800 ret = iwl_poll_bit(trans, CSR_EEPROM_REG, 801 CSR_EEPROM_REG_READ_VALID_MSK, 802 CSR_EEPROM_REG_READ_VALID_MSK, 803 IWL_EEPROM_ACCESS_TIMEOUT); 804 if (ret < 0) { 805 IWL_ERR(trans, "Time out reading OTP[%d]\n", addr); 806 return ret; 807 } 808 r = iwl_read32(trans, CSR_EEPROM_REG); 809 /* check for ECC errors: */ 810 otpgp = iwl_read32(trans, CSR_OTP_GP_REG); 811 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) { 812 /* stop in this case */ 813 /* set the uncorrectable OTP ECC bit for acknowledgment */ 814 iwl_set_bit(trans, CSR_OTP_GP_REG, 815 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); 816 IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n"); 817 return -EINVAL; 818 } 819 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) { 820 /* continue in this case */ 821 /* set the correctable OTP ECC bit for acknowledgment */ 822 iwl_set_bit(trans, CSR_OTP_GP_REG, 823 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK); 824 IWL_ERR(trans, "Correctable OTP ECC error, continue read\n"); 825 } 826 *eeprom_data = cpu_to_le16(r >> 16); 827 return 0; 828 } 829 830 /* 831 * iwl_is_otp_empty: check for empty OTP 832 */ 833 static bool iwl_is_otp_empty(struct iwl_trans *trans) 834 { 835 u16 next_link_addr = 0; 836 __le16 link_value; 837 bool is_empty = false; 838 839 /* locate the beginning of OTP link list */ 840 if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) { 841 if (!link_value) { 842 IWL_ERR(trans, "OTP is empty\n"); 843 is_empty = true; 844 } 845 } else { 846 IWL_ERR(trans, "Unable to read first block of OTP list.\n"); 847 is_empty = true; 848 } 849 850 return is_empty; 851 } 852 853 854 /* 855 * iwl_find_otp_image: find EEPROM image in OTP 856 * finding the OTP block that contains the EEPROM image. 857 * the last valid block on the link list (the block _before_ the last block) 858 * is the block we should read and used to configure the device. 859 * If all the available OTP blocks are full, the last block will be the block 860 * we should read and used to configure the device. 861 * only perform this operation if shadow RAM is disabled 862 */ 863 static int iwl_find_otp_image(struct iwl_trans *trans, 864 u16 *validblockaddr) 865 { 866 u16 next_link_addr = 0, valid_addr; 867 __le16 link_value = 0; 868 int usedblocks = 0; 869 870 /* set addressing mode to absolute to traverse the link list */ 871 iwl_set_otp_access_absolute(trans); 872 873 /* checking for empty OTP or error */ 874 if (iwl_is_otp_empty(trans)) 875 return -EINVAL; 876 877 /* 878 * start traverse link list 879 * until reach the max number of OTP blocks 880 * different devices have different number of OTP blocks 881 */ 882 do { 883 /* save current valid block address 884 * check for more block on the link list 885 */ 886 valid_addr = next_link_addr; 887 next_link_addr = le16_to_cpu(link_value) * sizeof(u16); 888 IWL_DEBUG_EEPROM(trans->dev, "OTP blocks %d addr 0x%x\n", 889 usedblocks, next_link_addr); 890 if (iwl_read_otp_word(trans, next_link_addr, &link_value)) 891 return -EINVAL; 892 if (!link_value) { 893 /* 894 * reach the end of link list, return success and 895 * set address point to the starting address 896 * of the image 897 */ 898 *validblockaddr = valid_addr; 899 /* skip first 2 bytes (link list pointer) */ 900 *validblockaddr += 2; 901 return 0; 902 } 903 /* more in the link list, continue */ 904 usedblocks++; 905 } while (usedblocks <= trans->mac_cfg->base->max_ll_items); 906 907 /* OTP has no valid blocks */ 908 IWL_DEBUG_EEPROM(trans->dev, "OTP has no valid blocks\n"); 909 return -EINVAL; 910 } 911 912 /* 913 * iwl_read_eeprom - read EEPROM contents 914 * 915 * Load the EEPROM contents from adapter and return it 916 * and its size. 917 * 918 * NOTE: This routine uses the non-debug IO access functions. 919 */ 920 int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size) 921 { 922 __le16 *e; 923 u32 gp = iwl_read32(trans, CSR_EEPROM_GP); 924 int sz; 925 int ret; 926 u16 addr; 927 u16 validblockaddr = 0; 928 u16 cache_addr = 0; 929 int nvm_is_otp; 930 931 if (!eeprom || !eeprom_size) 932 return -EINVAL; 933 934 nvm_is_otp = iwl_nvm_is_otp(trans); 935 if (nvm_is_otp < 0) 936 return nvm_is_otp; 937 938 sz = trans->mac_cfg->base->eeprom_size; 939 IWL_DEBUG_EEPROM(trans->dev, "NVM size = %d\n", sz); 940 941 e = kmalloc(sz, GFP_KERNEL); 942 if (!e) 943 return -ENOMEM; 944 945 ret = iwl_eeprom_verify_signature(trans, nvm_is_otp); 946 if (ret < 0) { 947 IWL_ERR(trans, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); 948 goto err_free; 949 } 950 951 /* Make sure driver (instead of uCode) is allowed to read EEPROM */ 952 ret = iwl_eeprom_acquire_semaphore(trans); 953 if (ret < 0) { 954 IWL_ERR(trans, "Failed to acquire EEPROM semaphore.\n"); 955 goto err_free; 956 } 957 958 if (nvm_is_otp) { 959 ret = iwl_init_otp_access(trans); 960 if (ret) { 961 IWL_ERR(trans, "Failed to initialize OTP access.\n"); 962 goto err_unlock; 963 } 964 965 iwl_write32(trans, CSR_EEPROM_GP, 966 iwl_read32(trans, CSR_EEPROM_GP) & 967 ~CSR_EEPROM_GP_IF_OWNER_MSK); 968 969 iwl_set_bit(trans, CSR_OTP_GP_REG, 970 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK | 971 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); 972 /* traversing the linked list if no shadow ram supported */ 973 if (!trans->mac_cfg->base->shadow_ram_support) { 974 ret = iwl_find_otp_image(trans, &validblockaddr); 975 if (ret) 976 goto err_unlock; 977 } 978 for (addr = validblockaddr; addr < validblockaddr + sz; 979 addr += sizeof(u16)) { 980 __le16 eeprom_data; 981 982 ret = iwl_read_otp_word(trans, addr, &eeprom_data); 983 if (ret) 984 goto err_unlock; 985 e[cache_addr / 2] = eeprom_data; 986 cache_addr += sizeof(u16); 987 } 988 } else { 989 /* eeprom is an array of 16bit values */ 990 for (addr = 0; addr < sz; addr += sizeof(u16)) { 991 u32 r; 992 993 iwl_write32(trans, CSR_EEPROM_REG, 994 CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); 995 996 ret = iwl_poll_bit(trans, CSR_EEPROM_REG, 997 CSR_EEPROM_REG_READ_VALID_MSK, 998 CSR_EEPROM_REG_READ_VALID_MSK, 999 IWL_EEPROM_ACCESS_TIMEOUT); 1000 if (ret < 0) { 1001 IWL_ERR(trans, 1002 "Time out reading EEPROM[%d]\n", addr); 1003 goto err_unlock; 1004 } 1005 r = iwl_read32(trans, CSR_EEPROM_REG); 1006 e[addr / 2] = cpu_to_le16(r >> 16); 1007 } 1008 } 1009 1010 IWL_DEBUG_EEPROM(trans->dev, "NVM Type: %s\n", 1011 nvm_is_otp ? "OTP" : "EEPROM"); 1012 1013 iwl_eeprom_release_semaphore(trans); 1014 1015 *eeprom_size = sz; 1016 *eeprom = (u8 *)e; 1017 return 0; 1018 1019 err_unlock: 1020 iwl_eeprom_release_semaphore(trans); 1021 err_free: 1022 kfree(e); 1023 1024 return ret; 1025 } 1026 1027 static void iwl_init_sbands(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg, 1028 struct iwl_nvm_data *data, 1029 const u8 *eeprom, size_t eeprom_size) 1030 { 1031 struct device *dev = trans->dev; 1032 int n_channels = iwl_init_channel_map(dev, cfg, data, 1033 eeprom, eeprom_size); 1034 int n_used = 0; 1035 struct ieee80211_supported_band *sband; 1036 1037 sband = &data->bands[NL80211_BAND_2GHZ]; 1038 sband->band = NL80211_BAND_2GHZ; 1039 sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS]; 1040 sband->n_bitrates = N_RATES_24; 1041 n_used += iwl_init_sband_channels(data, sband, n_channels, 1042 NL80211_BAND_2GHZ); 1043 iwl_init_ht_hw_capab(trans, data, &sband->ht_cap, NL80211_BAND_2GHZ, 1044 data->valid_tx_ant, data->valid_rx_ant); 1045 1046 sband = &data->bands[NL80211_BAND_5GHZ]; 1047 sband->band = NL80211_BAND_5GHZ; 1048 sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS]; 1049 sband->n_bitrates = N_RATES_52; 1050 n_used += iwl_init_sband_channels(data, sband, n_channels, 1051 NL80211_BAND_5GHZ); 1052 iwl_init_ht_hw_capab(trans, data, &sband->ht_cap, NL80211_BAND_5GHZ, 1053 data->valid_tx_ant, data->valid_rx_ant); 1054 1055 if (n_channels != n_used) 1056 IWL_ERR_DEV(dev, "EEPROM: used only %d of %d channels\n", 1057 n_used, n_channels); 1058 } 1059 1060 /* EEPROM data functions */ 1061 struct iwl_nvm_data * 1062 iwl_parse_eeprom_data(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg, 1063 const u8 *eeprom, size_t eeprom_size) 1064 { 1065 struct iwl_nvm_data *data; 1066 struct device *dev = trans->dev; 1067 const void *tmp; 1068 u16 radio_cfg, sku; 1069 1070 if (WARN_ON(!cfg || !cfg->eeprom_params)) 1071 return NULL; 1072 1073 data = kzalloc(struct_size(data, channels, IWL_NUM_CHANNELS), 1074 GFP_KERNEL); 1075 if (!data) 1076 return NULL; 1077 1078 /* get MAC address(es) */ 1079 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_MAC_ADDRESS); 1080 if (!tmp) 1081 goto err_free; 1082 memcpy(data->hw_addr, tmp, ETH_ALEN); 1083 data->n_hw_addrs = iwl_eeprom_query16(eeprom, eeprom_size, 1084 EEPROM_NUM_MAC_ADDRESS); 1085 1086 if (iwl_eeprom_read_calib(eeprom, eeprom_size, data)) 1087 goto err_free; 1088 1089 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_XTAL); 1090 if (!tmp) 1091 goto err_free; 1092 memcpy(data->xtal_calib, tmp, sizeof(data->xtal_calib)); 1093 1094 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, 1095 EEPROM_RAW_TEMPERATURE); 1096 if (!tmp) 1097 goto err_free; 1098 data->raw_temperature = *(const __le16 *)tmp; 1099 1100 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, 1101 EEPROM_KELVIN_TEMPERATURE); 1102 if (!tmp) 1103 goto err_free; 1104 data->kelvin_temperature = *(const __le16 *)tmp; 1105 data->kelvin_voltage = *((const __le16 *)tmp + 1); 1106 1107 radio_cfg = 1108 iwl_eeprom_query16(eeprom, eeprom_size, EEPROM_RADIO_CONFIG); 1109 data->radio_cfg_dash = EEPROM_RF_CFG_DASH_MSK(radio_cfg); 1110 data->radio_cfg_pnum = EEPROM_RF_CFG_PNUM_MSK(radio_cfg); 1111 data->radio_cfg_step = EEPROM_RF_CFG_STEP_MSK(radio_cfg); 1112 data->radio_cfg_type = EEPROM_RF_CFG_TYPE_MSK(radio_cfg); 1113 data->valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg); 1114 data->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg); 1115 1116 sku = iwl_eeprom_query16(eeprom, eeprom_size, 1117 EEPROM_SKU_CAP); 1118 data->sku_cap_11n_enable = sku & EEPROM_SKU_CAP_11N_ENABLE; 1119 data->sku_cap_amt_enable = sku & EEPROM_SKU_CAP_AMT_ENABLE; 1120 data->sku_cap_band_24ghz_enable = sku & EEPROM_SKU_CAP_BAND_24GHZ; 1121 data->sku_cap_band_52ghz_enable = sku & EEPROM_SKU_CAP_BAND_52GHZ; 1122 data->sku_cap_ipan_enable = sku & EEPROM_SKU_CAP_IPAN_ENABLE; 1123 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL) 1124 data->sku_cap_11n_enable = false; 1125 1126 data->nvm_version = iwl_eeprom_query16(eeprom, eeprom_size, 1127 EEPROM_VERSION); 1128 1129 /* check overrides (some devices have wrong EEPROM) */ 1130 if (cfg->valid_tx_ant) 1131 data->valid_tx_ant = cfg->valid_tx_ant; 1132 if (cfg->valid_rx_ant) 1133 data->valid_rx_ant = cfg->valid_rx_ant; 1134 1135 if (!data->valid_tx_ant || !data->valid_rx_ant) { 1136 IWL_ERR_DEV(dev, "invalid antennas (0x%x, 0x%x)\n", 1137 data->valid_tx_ant, data->valid_rx_ant); 1138 goto err_free; 1139 } 1140 1141 iwl_init_sbands(trans, cfg, data, eeprom, eeprom_size); 1142 1143 return data; 1144 err_free: 1145 kfree(data); 1146 return NULL; 1147 } 1148