iwl-eeprom-parse.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *****************************************************************************/
  64. #include <linux/types.h>
  65. #include <linux/slab.h>
  66. #include <linux/export.h>
  67. #include "iwl-drv.h"
  68. #include "iwl-modparams.h"
  69. #include "iwl-eeprom-parse.h"
  70. /* EEPROM offset definitions */
  71. /* indirect access definitions */
  72. #define ADDRESS_MSK 0x0000FFFF
  73. #define INDIRECT_TYPE_MSK 0x000F0000
  74. #define INDIRECT_HOST 0x00010000
  75. #define INDIRECT_GENERAL 0x00020000
  76. #define INDIRECT_REGULATORY 0x00030000
  77. #define INDIRECT_CALIBRATION 0x00040000
  78. #define INDIRECT_PROCESS_ADJST 0x00050000
  79. #define INDIRECT_OTHERS 0x00060000
  80. #define INDIRECT_TXP_LIMIT 0x00070000
  81. #define INDIRECT_TXP_LIMIT_SIZE 0x00080000
  82. #define INDIRECT_ADDRESS 0x00100000
  83. /* corresponding link offsets in EEPROM */
  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)
  92. /* General */
  93. #define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
  94. #define EEPROM_SUBSYSTEM_ID (2*0x0A) /* 2 bytes */
  95. #define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
  96. #define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
  97. #define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
  98. #define EEPROM_VERSION (2*0x44) /* 2 bytes */
  99. #define EEPROM_SKU_CAP (2*0x45) /* 2 bytes */
  100. #define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
  101. #define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
  102. #define EEPROM_NUM_MAC_ADDRESS (2*0x4C) /* 2 bytes */
  103. /* calibration */
  104. struct iwl_eeprom_calib_hdr {
  105. u8 version;
  106. u8 pa_type;
  107. __le16 voltage;
  108. } __packed;
  109. #define EEPROM_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
  110. #define EEPROM_XTAL ((2*0x128) | EEPROM_CALIB_ALL)
  111. /* temperature */
  112. #define EEPROM_KELVIN_TEMPERATURE ((2*0x12A) | EEPROM_CALIB_ALL)
  113. #define EEPROM_RAW_TEMPERATURE ((2*0x12B) | EEPROM_CALIB_ALL)
  114. /* SKU Capabilities (actual values from EEPROM definition) */
  115. enum eeprom_sku_bits {
  116. EEPROM_SKU_CAP_BAND_24GHZ = BIT(4),
  117. EEPROM_SKU_CAP_BAND_52GHZ = BIT(5),
  118. EEPROM_SKU_CAP_11N_ENABLE = BIT(6),
  119. EEPROM_SKU_CAP_AMT_ENABLE = BIT(7),
  120. EEPROM_SKU_CAP_IPAN_ENABLE = BIT(8)
  121. };
  122. /* radio config bits (actual values from EEPROM definition) */
  123. #define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
  124. #define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
  125. #define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
  126. #define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
  127. #define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
  128. #define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
  129. /*
  130. * EEPROM bands
  131. * These are the channel numbers from each band in the order
  132. * that they are stored in the EEPROM band information. Note
  133. * that EEPROM bands aren't the same as mac80211 bands, and
  134. * there are even special "ht40 bands" in the EEPROM.
  135. */
  136. static const u8 iwl_eeprom_band_1[14] = { /* 2.4 GHz */
  137. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  138. };
  139. static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
  140. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  141. };
  142. static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
  143. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  144. };
  145. static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
  146. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  147. };
  148. static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
  149. 145, 149, 153, 157, 161, 165
  150. };
  151. static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
  152. 1, 2, 3, 4, 5, 6, 7
  153. };
  154. static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
  155. 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
  156. };
  157. #define IWL_NUM_CHANNELS (ARRAY_SIZE(iwl_eeprom_band_1) + \
  158. ARRAY_SIZE(iwl_eeprom_band_2) + \
  159. ARRAY_SIZE(iwl_eeprom_band_3) + \
  160. ARRAY_SIZE(iwl_eeprom_band_4) + \
  161. ARRAY_SIZE(iwl_eeprom_band_5))
  162. /* rate data (static) */
  163. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  164. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  165. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  166. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  167. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  168. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  169. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  170. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  171. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  172. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  173. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  174. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  175. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  176. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  177. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  178. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  179. };
  180. #define RATES_24_OFFS 0
  181. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  182. #define RATES_52_OFFS 4
  183. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  184. /* EEPROM reading functions */
  185. static u16 iwl_eeprom_query16(const u8 *eeprom, size_t eeprom_size, int offset)
  186. {
  187. if (WARN_ON(offset + sizeof(u16) > eeprom_size))
  188. return 0;
  189. return le16_to_cpup((__le16 *)(eeprom + offset));
  190. }
  191. static u32 eeprom_indirect_address(const u8 *eeprom, size_t eeprom_size,
  192. u32 address)
  193. {
  194. u16 offset = 0;
  195. if ((address & INDIRECT_ADDRESS) == 0)
  196. return address;
  197. switch (address & INDIRECT_TYPE_MSK) {
  198. case INDIRECT_HOST:
  199. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  200. EEPROM_LINK_HOST);
  201. break;
  202. case INDIRECT_GENERAL:
  203. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  204. EEPROM_LINK_GENERAL);
  205. break;
  206. case INDIRECT_REGULATORY:
  207. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  208. EEPROM_LINK_REGULATORY);
  209. break;
  210. case INDIRECT_TXP_LIMIT:
  211. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  212. EEPROM_LINK_TXP_LIMIT);
  213. break;
  214. case INDIRECT_TXP_LIMIT_SIZE:
  215. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  216. EEPROM_LINK_TXP_LIMIT_SIZE);
  217. break;
  218. case INDIRECT_CALIBRATION:
  219. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  220. EEPROM_LINK_CALIBRATION);
  221. break;
  222. case INDIRECT_PROCESS_ADJST:
  223. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  224. EEPROM_LINK_PROCESS_ADJST);
  225. break;
  226. case INDIRECT_OTHERS:
  227. offset = iwl_eeprom_query16(eeprom, eeprom_size,
  228. EEPROM_LINK_OTHERS);
  229. break;
  230. default:
  231. WARN_ON(1);
  232. break;
  233. }
  234. /* translate the offset from words to byte */
  235. return (address & ADDRESS_MSK) + (offset << 1);
  236. }
  237. static const u8 *iwl_eeprom_query_addr(const u8 *eeprom, size_t eeprom_size,
  238. u32 offset)
  239. {
  240. u32 address = eeprom_indirect_address(eeprom, eeprom_size, offset);
  241. if (WARN_ON(address >= eeprom_size))
  242. return NULL;
  243. return &eeprom[address];
  244. }
  245. static int iwl_eeprom_read_calib(const u8 *eeprom, size_t eeprom_size,
  246. struct iwl_nvm_data *data)
  247. {
  248. struct iwl_eeprom_calib_hdr *hdr;
  249. hdr = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
  250. EEPROM_CALIB_ALL);
  251. if (!hdr)
  252. return -ENODATA;
  253. data->calib_version = hdr->version;
  254. data->calib_voltage = hdr->voltage;
  255. return 0;
  256. }
  257. /**
  258. * enum iwl_eeprom_channel_flags - channel flags in EEPROM
  259. * @EEPROM_CHANNEL_VALID: channel is usable for this SKU/geo
  260. * @EEPROM_CHANNEL_IBSS: usable as an IBSS channel
  261. * @EEPROM_CHANNEL_ACTIVE: active scanning allowed
  262. * @EEPROM_CHANNEL_RADAR: radar detection required
  263. * @EEPROM_CHANNEL_WIDE: 20 MHz channel okay (?)
  264. * @EEPROM_CHANNEL_DFS: dynamic freq selection candidate
  265. */
  266. enum iwl_eeprom_channel_flags {
  267. EEPROM_CHANNEL_VALID = BIT(0),
  268. EEPROM_CHANNEL_IBSS = BIT(1),
  269. EEPROM_CHANNEL_ACTIVE = BIT(3),
  270. EEPROM_CHANNEL_RADAR = BIT(4),
  271. EEPROM_CHANNEL_WIDE = BIT(5),
  272. EEPROM_CHANNEL_DFS = BIT(7),
  273. };
  274. /**
  275. * struct iwl_eeprom_channel - EEPROM channel data
  276. * @flags: %EEPROM_CHANNEL_* flags
  277. * @max_power_avg: max power (in dBm) on this channel, at most 31 dBm
  278. */
  279. struct iwl_eeprom_channel {
  280. u8 flags;
  281. s8 max_power_avg;
  282. } __packed;
  283. enum iwl_eeprom_enhanced_txpwr_flags {
  284. IWL_EEPROM_ENH_TXP_FL_VALID = BIT(0),
  285. IWL_EEPROM_ENH_TXP_FL_BAND_52G = BIT(1),
  286. IWL_EEPROM_ENH_TXP_FL_OFDM = BIT(2),
  287. IWL_EEPROM_ENH_TXP_FL_40MHZ = BIT(3),
  288. IWL_EEPROM_ENH_TXP_FL_HT_AP = BIT(4),
  289. IWL_EEPROM_ENH_TXP_FL_RES1 = BIT(5),
  290. IWL_EEPROM_ENH_TXP_FL_RES2 = BIT(6),
  291. IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE = BIT(7),
  292. };
  293. /**
  294. * iwl_eeprom_enhanced_txpwr structure
  295. * @flags: entry flags
  296. * @channel: channel number
  297. * @chain_a_max_pwr: chain a max power in 1/2 dBm
  298. * @chain_b_max_pwr: chain b max power in 1/2 dBm
  299. * @chain_c_max_pwr: chain c max power in 1/2 dBm
  300. * @delta_20_in_40: 20-in-40 deltas (hi/lo)
  301. * @mimo2_max_pwr: mimo2 max power in 1/2 dBm
  302. * @mimo3_max_pwr: mimo3 max power in 1/2 dBm
  303. *
  304. * This structure presents the enhanced regulatory tx power limit layout
  305. * in an EEPROM image.
  306. */
  307. struct iwl_eeprom_enhanced_txpwr {
  308. u8 flags;
  309. u8 channel;
  310. s8 chain_a_max;
  311. s8 chain_b_max;
  312. s8 chain_c_max;
  313. u8 delta_20_in_40;
  314. s8 mimo2_max;
  315. s8 mimo3_max;
  316. } __packed;
  317. static s8 iwl_get_max_txpwr_half_dbm(const struct iwl_nvm_data *data,
  318. struct iwl_eeprom_enhanced_txpwr *txp)
  319. {
  320. s8 result = 0; /* (.5 dBm) */
  321. /* Take the highest tx power from any valid chains */
  322. if (data->valid_tx_ant & ANT_A && txp->chain_a_max > result)
  323. result = txp->chain_a_max;
  324. if (data->valid_tx_ant & ANT_B && txp->chain_b_max > result)
  325. result = txp->chain_b_max;
  326. if (data->valid_tx_ant & ANT_C && txp->chain_c_max > result)
  327. result = txp->chain_c_max;
  328. if ((data->valid_tx_ant == ANT_AB ||
  329. data->valid_tx_ant == ANT_BC ||
  330. data->valid_tx_ant == ANT_AC) && txp->mimo2_max > result)
  331. result = txp->mimo2_max;
  332. if (data->valid_tx_ant == ANT_ABC && txp->mimo3_max > result)
  333. result = txp->mimo3_max;
  334. return result;
  335. }
  336. #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
  337. #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
  338. #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
  339. #define TXP_CHECK_AND_PRINT(x) \
  340. ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) ? # x " " : "")
  341. static void
  342. iwl_eeprom_enh_txp_read_element(struct iwl_nvm_data *data,
  343. struct iwl_eeprom_enhanced_txpwr *txp,
  344. int n_channels, s8 max_txpower_avg)
  345. {
  346. int ch_idx;
  347. enum ieee80211_band band;
  348. band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
  349. IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
  350. for (ch_idx = 0; ch_idx < n_channels; ch_idx++) {
  351. struct ieee80211_channel *chan = &data->channels[ch_idx];
  352. /* update matching channel or from common data only */
  353. if (txp->channel != 0 && chan->hw_value != txp->channel)
  354. continue;
  355. /* update matching band only */
  356. if (band != chan->band)
  357. continue;
  358. if (chan->max_power < max_txpower_avg &&
  359. !(txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ))
  360. chan->max_power = max_txpower_avg;
  361. }
  362. }
  363. static void iwl_eeprom_enhanced_txpower(struct device *dev,
  364. struct iwl_nvm_data *data,
  365. const u8 *eeprom, size_t eeprom_size,
  366. int n_channels)
  367. {
  368. struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
  369. int idx, entries;
  370. __le16 *txp_len;
  371. s8 max_txp_avg_halfdbm;
  372. BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
  373. /* the length is in 16-bit words, but we want entries */
  374. txp_len = (__le16 *)iwl_eeprom_query_addr(eeprom, eeprom_size,
  375. EEPROM_TXP_SZ_OFFS);
  376. entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
  377. txp_array = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
  378. EEPROM_TXP_OFFS);
  379. for (idx = 0; idx < entries; idx++) {
  380. txp = &txp_array[idx];
  381. /* skip invalid entries */
  382. if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
  383. continue;
  384. IWL_DEBUG_EEPROM(dev, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n",
  385. (txp->channel && (txp->flags &
  386. IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ?
  387. "Common " : (txp->channel) ?
  388. "Channel" : "Common",
  389. (txp->channel),
  390. TXP_CHECK_AND_PRINT(VALID),
  391. TXP_CHECK_AND_PRINT(BAND_52G),
  392. TXP_CHECK_AND_PRINT(OFDM),
  393. TXP_CHECK_AND_PRINT(40MHZ),
  394. TXP_CHECK_AND_PRINT(HT_AP),
  395. TXP_CHECK_AND_PRINT(RES1),
  396. TXP_CHECK_AND_PRINT(RES2),
  397. TXP_CHECK_AND_PRINT(COMMON_TYPE),
  398. txp->flags);
  399. IWL_DEBUG_EEPROM(dev,
  400. "\t\t chain_A: 0x%02x chain_B: 0X%02x chain_C: 0X%02x\n",
  401. txp->chain_a_max, txp->chain_b_max,
  402. txp->chain_c_max);
  403. IWL_DEBUG_EEPROM(dev,
  404. "\t\t MIMO2: 0x%02x MIMO3: 0x%02x High 20_on_40: 0x%02x Low 20_on_40: 0x%02x\n",
  405. txp->mimo2_max, txp->mimo3_max,
  406. ((txp->delta_20_in_40 & 0xf0) >> 4),
  407. (txp->delta_20_in_40 & 0x0f));
  408. max_txp_avg_halfdbm = iwl_get_max_txpwr_half_dbm(data, txp);
  409. iwl_eeprom_enh_txp_read_element(data, txp, n_channels,
  410. DIV_ROUND_UP(max_txp_avg_halfdbm, 2));
  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. static void iwl_init_band_reference(const struct iwl_cfg *cfg,
  416. const u8 *eeprom, size_t eeprom_size,
  417. int eeprom_band, int *eeprom_ch_count,
  418. const struct iwl_eeprom_channel **ch_info,
  419. const u8 **eeprom_ch_array)
  420. {
  421. u32 offset = cfg->eeprom_params->regulatory_bands[eeprom_band - 1];
  422. offset |= INDIRECT_ADDRESS | INDIRECT_REGULATORY;
  423. *ch_info = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size, offset);
  424. switch (eeprom_band) {
  425. case 1: /* 2.4GHz band */
  426. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
  427. *eeprom_ch_array = iwl_eeprom_band_1;
  428. break;
  429. case 2: /* 4.9GHz band */
  430. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
  431. *eeprom_ch_array = iwl_eeprom_band_2;
  432. break;
  433. case 3: /* 5.2GHz band */
  434. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
  435. *eeprom_ch_array = iwl_eeprom_band_3;
  436. break;
  437. case 4: /* 5.5GHz band */
  438. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
  439. *eeprom_ch_array = iwl_eeprom_band_4;
  440. break;
  441. case 5: /* 5.7GHz band */
  442. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
  443. *eeprom_ch_array = iwl_eeprom_band_5;
  444. break;
  445. case 6: /* 2.4GHz ht40 channels */
  446. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
  447. *eeprom_ch_array = iwl_eeprom_band_6;
  448. break;
  449. case 7: /* 5 GHz ht40 channels */
  450. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
  451. *eeprom_ch_array = iwl_eeprom_band_7;
  452. break;
  453. default:
  454. *eeprom_ch_count = 0;
  455. *eeprom_ch_array = NULL;
  456. WARN_ON(1);
  457. }
  458. }
  459. #define CHECK_AND_PRINT(x) \
  460. ((eeprom_ch->flags & EEPROM_CHANNEL_##x) ? # x " " : "")
  461. static void iwl_mod_ht40_chan_info(struct device *dev,
  462. struct iwl_nvm_data *data, int n_channels,
  463. enum ieee80211_band band, u16 channel,
  464. const struct iwl_eeprom_channel *eeprom_ch,
  465. u8 clear_ht40_extension_channel)
  466. {
  467. struct ieee80211_channel *chan = NULL;
  468. int i;
  469. for (i = 0; i < n_channels; i++) {
  470. if (data->channels[i].band != band)
  471. continue;
  472. if (data->channels[i].hw_value != channel)
  473. continue;
  474. chan = &data->channels[i];
  475. break;
  476. }
  477. if (!chan)
  478. return;
  479. IWL_DEBUG_EEPROM(dev,
  480. "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
  481. channel,
  482. band == IEEE80211_BAND_5GHZ ? "5.2" : "2.4",
  483. CHECK_AND_PRINT(IBSS),
  484. CHECK_AND_PRINT(ACTIVE),
  485. CHECK_AND_PRINT(RADAR),
  486. CHECK_AND_PRINT(WIDE),
  487. CHECK_AND_PRINT(DFS),
  488. eeprom_ch->flags,
  489. eeprom_ch->max_power_avg,
  490. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS) &&
  491. !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ? ""
  492. : "not ");
  493. if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
  494. chan->flags &= ~clear_ht40_extension_channel;
  495. }
  496. #define CHECK_AND_PRINT_I(x) \
  497. ((eeprom_ch_info[ch_idx].flags & EEPROM_CHANNEL_##x) ? # x " " : "")
  498. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  499. struct iwl_nvm_data *data,
  500. const u8 *eeprom, size_t eeprom_size)
  501. {
  502. int band, ch_idx;
  503. const struct iwl_eeprom_channel *eeprom_ch_info;
  504. const u8 *eeprom_ch_array;
  505. int eeprom_ch_count;
  506. int n_channels = 0;
  507. /*
  508. * Loop through the 5 EEPROM bands and add them to the parse list
  509. */
  510. for (band = 1; band <= 5; band++) {
  511. struct ieee80211_channel *channel;
  512. iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
  513. &eeprom_ch_count, &eeprom_ch_info,
  514. &eeprom_ch_array);
  515. /* Loop through each band adding each of the channels */
  516. for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
  517. const struct iwl_eeprom_channel *eeprom_ch;
  518. eeprom_ch = &eeprom_ch_info[ch_idx];
  519. if (!(eeprom_ch->flags & EEPROM_CHANNEL_VALID)) {
  520. IWL_DEBUG_EEPROM(dev,
  521. "Ch. %d Flags %x [%sGHz] - No traffic\n",
  522. eeprom_ch_array[ch_idx],
  523. eeprom_ch_info[ch_idx].flags,
  524. (band != 1) ? "5.2" : "2.4");
  525. continue;
  526. }
  527. channel = &data->channels[n_channels];
  528. n_channels++;
  529. channel->hw_value = eeprom_ch_array[ch_idx];
  530. channel->band = (band == 1) ? IEEE80211_BAND_2GHZ
  531. : IEEE80211_BAND_5GHZ;
  532. channel->center_freq =
  533. ieee80211_channel_to_frequency(
  534. channel->hw_value, channel->band);
  535. /* set no-HT40, will enable as appropriate later */
  536. channel->flags = IEEE80211_CHAN_NO_HT40;
  537. if (!(eeprom_ch->flags & EEPROM_CHANNEL_IBSS))
  538. channel->flags |= IEEE80211_CHAN_NO_IR;
  539. if (!(eeprom_ch->flags & EEPROM_CHANNEL_ACTIVE))
  540. channel->flags |= IEEE80211_CHAN_NO_IR;
  541. if (eeprom_ch->flags & EEPROM_CHANNEL_RADAR)
  542. channel->flags |= IEEE80211_CHAN_RADAR;
  543. /* Initialize regulatory-based run-time data */
  544. channel->max_power =
  545. eeprom_ch_info[ch_idx].max_power_avg;
  546. IWL_DEBUG_EEPROM(dev,
  547. "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
  548. channel->hw_value,
  549. (band != 1) ? "5.2" : "2.4",
  550. CHECK_AND_PRINT_I(VALID),
  551. CHECK_AND_PRINT_I(IBSS),
  552. CHECK_AND_PRINT_I(ACTIVE),
  553. CHECK_AND_PRINT_I(RADAR),
  554. CHECK_AND_PRINT_I(WIDE),
  555. CHECK_AND_PRINT_I(DFS),
  556. eeprom_ch_info[ch_idx].flags,
  557. eeprom_ch_info[ch_idx].max_power_avg,
  558. ((eeprom_ch_info[ch_idx].flags &
  559. EEPROM_CHANNEL_IBSS) &&
  560. !(eeprom_ch_info[ch_idx].flags &
  561. EEPROM_CHANNEL_RADAR))
  562. ? "" : "not ");
  563. }
  564. }
  565. if (cfg->eeprom_params->enhanced_txpower) {
  566. /*
  567. * for newer device (6000 series and up)
  568. * EEPROM contain enhanced tx power information
  569. * driver need to process addition information
  570. * to determine the max channel tx power limits
  571. */
  572. iwl_eeprom_enhanced_txpower(dev, data, eeprom, eeprom_size,
  573. n_channels);
  574. } else {
  575. /* All others use data from channel map */
  576. int i;
  577. data->max_tx_pwr_half_dbm = -128;
  578. for (i = 0; i < n_channels; i++)
  579. data->max_tx_pwr_half_dbm =
  580. max_t(s8, data->max_tx_pwr_half_dbm,
  581. data->channels[i].max_power * 2);
  582. }
  583. /* Check if we do have HT40 channels */
  584. if (cfg->eeprom_params->regulatory_bands[5] ==
  585. EEPROM_REGULATORY_BAND_NO_HT40 &&
  586. cfg->eeprom_params->regulatory_bands[6] ==
  587. EEPROM_REGULATORY_BAND_NO_HT40)
  588. return n_channels;
  589. /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
  590. for (band = 6; band <= 7; band++) {
  591. enum ieee80211_band ieeeband;
  592. iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
  593. &eeprom_ch_count, &eeprom_ch_info,
  594. &eeprom_ch_array);
  595. /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
  596. ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ
  597. : IEEE80211_BAND_5GHZ;
  598. /* Loop through each band adding each of the channels */
  599. for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
  600. /* Set up driver's info for lower half */
  601. iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
  602. eeprom_ch_array[ch_idx],
  603. &eeprom_ch_info[ch_idx],
  604. IEEE80211_CHAN_NO_HT40PLUS);
  605. /* Set up driver's info for upper half */
  606. iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
  607. eeprom_ch_array[ch_idx] + 4,
  608. &eeprom_ch_info[ch_idx],
  609. IEEE80211_CHAN_NO_HT40MINUS);
  610. }
  611. }
  612. return n_channels;
  613. }
  614. int iwl_init_sband_channels(struct iwl_nvm_data *data,
  615. struct ieee80211_supported_band *sband,
  616. int n_channels, enum ieee80211_band band)
  617. {
  618. struct ieee80211_channel *chan = &data->channels[0];
  619. int n = 0, idx = 0;
  620. while (idx < n_channels && chan->band != band)
  621. chan = &data->channels[++idx];
  622. sband->channels = &data->channels[idx];
  623. while (idx < n_channels && chan->band == band) {
  624. chan = &data->channels[++idx];
  625. n++;
  626. }
  627. sband->n_channels = n;
  628. return n;
  629. }
  630. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  631. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  632. void iwl_init_ht_hw_capab(const struct iwl_cfg *cfg,
  633. struct iwl_nvm_data *data,
  634. struct ieee80211_sta_ht_cap *ht_info,
  635. enum ieee80211_band band,
  636. u8 tx_chains, u8 rx_chains)
  637. {
  638. int max_bit_rate = 0;
  639. tx_chains = hweight8(tx_chains);
  640. if (cfg->rx_with_siso_diversity)
  641. rx_chains = 1;
  642. else
  643. rx_chains = hweight8(rx_chains);
  644. if (!(data->sku_cap_11n_enable) || !cfg->ht_params) {
  645. ht_info->ht_supported = false;
  646. return;
  647. }
  648. if (data->sku_cap_mimo_disabled)
  649. rx_chains = 1;
  650. ht_info->ht_supported = true;
  651. ht_info->cap = IEEE80211_HT_CAP_DSSSCCK40;
  652. if (cfg->ht_params->stbc) {
  653. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  654. if (tx_chains > 1)
  655. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  656. }
  657. if (cfg->ht_params->ldpc)
  658. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  659. if (iwlwifi_mod_params.amsdu_size_8K)
  660. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  661. ht_info->ampdu_factor = cfg->max_ht_ampdu_exponent;
  662. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_4;
  663. ht_info->mcs.rx_mask[0] = 0xFF;
  664. if (rx_chains >= 2)
  665. ht_info->mcs.rx_mask[1] = 0xFF;
  666. if (rx_chains >= 3)
  667. ht_info->mcs.rx_mask[2] = 0xFF;
  668. if (cfg->ht_params->ht_greenfield_support)
  669. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  670. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  671. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  672. if (cfg->ht_params->ht40_bands & BIT(band)) {
  673. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  674. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  675. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  676. }
  677. /* Highest supported Rx data rate */
  678. max_bit_rate *= rx_chains;
  679. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  680. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  681. /* Tx MCS capabilities */
  682. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  683. if (tx_chains != rx_chains) {
  684. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  685. ht_info->mcs.tx_params |= ((tx_chains - 1) <<
  686. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  687. }
  688. }
  689. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  690. struct iwl_nvm_data *data,
  691. const u8 *eeprom, size_t eeprom_size)
  692. {
  693. int n_channels = iwl_init_channel_map(dev, cfg, data,
  694. eeprom, eeprom_size);
  695. int n_used = 0;
  696. struct ieee80211_supported_band *sband;
  697. sband = &data->bands[IEEE80211_BAND_2GHZ];
  698. sband->band = IEEE80211_BAND_2GHZ;
  699. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  700. sband->n_bitrates = N_RATES_24;
  701. n_used += iwl_init_sband_channels(data, sband, n_channels,
  702. IEEE80211_BAND_2GHZ);
  703. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_2GHZ,
  704. data->valid_tx_ant, data->valid_rx_ant);
  705. sband = &data->bands[IEEE80211_BAND_5GHZ];
  706. sband->band = IEEE80211_BAND_5GHZ;
  707. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  708. sband->n_bitrates = N_RATES_52;
  709. n_used += iwl_init_sband_channels(data, sband, n_channels,
  710. IEEE80211_BAND_5GHZ);
  711. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_5GHZ,
  712. data->valid_tx_ant, data->valid_rx_ant);
  713. if (n_channels != n_used)
  714. IWL_ERR_DEV(dev, "EEPROM: used only %d of %d channels\n",
  715. n_used, n_channels);
  716. }
  717. /* EEPROM data functions */
  718. struct iwl_nvm_data *
  719. iwl_parse_eeprom_data(struct device *dev, const struct iwl_cfg *cfg,
  720. const u8 *eeprom, size_t eeprom_size)
  721. {
  722. struct iwl_nvm_data *data;
  723. const void *tmp;
  724. u16 radio_cfg, sku;
  725. if (WARN_ON(!cfg || !cfg->eeprom_params))
  726. return NULL;
  727. data = kzalloc(sizeof(*data) +
  728. sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
  729. GFP_KERNEL);
  730. if (!data)
  731. return NULL;
  732. /* get MAC address(es) */
  733. tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_MAC_ADDRESS);
  734. if (!tmp)
  735. goto err_free;
  736. memcpy(data->hw_addr, tmp, ETH_ALEN);
  737. data->n_hw_addrs = iwl_eeprom_query16(eeprom, eeprom_size,
  738. EEPROM_NUM_MAC_ADDRESS);
  739. if (iwl_eeprom_read_calib(eeprom, eeprom_size, data))
  740. goto err_free;
  741. tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_XTAL);
  742. if (!tmp)
  743. goto err_free;
  744. memcpy(data->xtal_calib, tmp, sizeof(data->xtal_calib));
  745. tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
  746. EEPROM_RAW_TEMPERATURE);
  747. if (!tmp)
  748. goto err_free;
  749. data->raw_temperature = *(__le16 *)tmp;
  750. tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
  751. EEPROM_KELVIN_TEMPERATURE);
  752. if (!tmp)
  753. goto err_free;
  754. data->kelvin_temperature = *(__le16 *)tmp;
  755. data->kelvin_voltage = *((__le16 *)tmp + 1);
  756. radio_cfg = iwl_eeprom_query16(eeprom, eeprom_size,
  757. EEPROM_RADIO_CONFIG);
  758. data->radio_cfg_dash = EEPROM_RF_CFG_DASH_MSK(radio_cfg);
  759. data->radio_cfg_pnum = EEPROM_RF_CFG_PNUM_MSK(radio_cfg);
  760. data->radio_cfg_step = EEPROM_RF_CFG_STEP_MSK(radio_cfg);
  761. data->radio_cfg_type = EEPROM_RF_CFG_TYPE_MSK(radio_cfg);
  762. data->valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
  763. data->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
  764. sku = iwl_eeprom_query16(eeprom, eeprom_size,
  765. EEPROM_SKU_CAP);
  766. data->sku_cap_11n_enable = sku & EEPROM_SKU_CAP_11N_ENABLE;
  767. data->sku_cap_amt_enable = sku & EEPROM_SKU_CAP_AMT_ENABLE;
  768. data->sku_cap_band_24GHz_enable = sku & EEPROM_SKU_CAP_BAND_24GHZ;
  769. data->sku_cap_band_52GHz_enable = sku & EEPROM_SKU_CAP_BAND_52GHZ;
  770. data->sku_cap_ipan_enable = sku & EEPROM_SKU_CAP_IPAN_ENABLE;
  771. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  772. data->sku_cap_11n_enable = false;
  773. data->nvm_version = iwl_eeprom_query16(eeprom, eeprom_size,
  774. EEPROM_VERSION);
  775. /* check overrides (some devices have wrong EEPROM) */
  776. if (cfg->valid_tx_ant)
  777. data->valid_tx_ant = cfg->valid_tx_ant;
  778. if (cfg->valid_rx_ant)
  779. data->valid_rx_ant = cfg->valid_rx_ant;
  780. if (!data->valid_tx_ant || !data->valid_rx_ant) {
  781. IWL_ERR_DEV(dev, "invalid antennas (0x%x, 0x%x)\n",
  782. data->valid_tx_ant, data->valid_rx_ant);
  783. goto err_free;
  784. }
  785. iwl_init_sbands(dev, cfg, data, eeprom, eeprom_size);
  786. return data;
  787. err_free:
  788. kfree(data);
  789. return NULL;
  790. }
  791. IWL_EXPORT_SYMBOL(iwl_parse_eeprom_data);
  792. /* helper functions */
  793. int iwl_nvm_check_version(struct iwl_nvm_data *data,
  794. struct iwl_trans *trans)
  795. {
  796. if (data->nvm_version >= trans->cfg->nvm_ver ||
  797. data->calib_version >= trans->cfg->nvm_calib_ver) {
  798. IWL_DEBUG_INFO(trans, "device EEPROM VER=0x%x, CALIB=0x%x\n",
  799. data->nvm_version, data->calib_version);
  800. return 0;
  801. }
  802. IWL_ERR(trans,
  803. "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  804. data->nvm_version, trans->cfg->nvm_ver,
  805. data->calib_version, trans->cfg->nvm_calib_ver);
  806. return -EINVAL;
  807. }
  808. IWL_EXPORT_SYMBOL(iwl_nvm_check_version);