iwl-eeprom-parse.c 29 KB

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