iwl-dev.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. /*
  27. * Please use this file (iwl-dev.h) for driver implementation definitions.
  28. * Please use iwl-commands.h for uCode API definitions.
  29. */
  30. #ifndef __iwl_dev_h__
  31. #define __iwl_dev_h__
  32. #include <linux/interrupt.h>
  33. #include <linux/kernel.h>
  34. #include <linux/wait.h>
  35. #include <linux/leds.h>
  36. #include <linux/slab.h>
  37. #include <net/ieee80211_radiotap.h>
  38. #include "iwl-eeprom.h"
  39. #include "iwl-csr.h"
  40. #include "iwl-prph.h"
  41. #include "iwl-debug.h"
  42. #include "iwl-agn-hw.h"
  43. #include "iwl-led.h"
  44. #include "iwl-power.h"
  45. #include "iwl-agn-rs.h"
  46. #include "iwl-agn-tt.h"
  47. #include "iwl-bus.h"
  48. #include "iwl-trans.h"
  49. #include "iwl-shared.h"
  50. struct iwl_tx_queue;
  51. /* CT-KILL constants */
  52. #define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
  53. #define CT_KILL_THRESHOLD 114 /* in Celsius */
  54. #define CT_KILL_EXIT_THRESHOLD 95 /* in Celsius */
  55. /* Default noise level to report when noise measurement is not available.
  56. * This may be because we're:
  57. * 1) Not associated (4965, no beacon statistics being sent to driver)
  58. * 2) Scanning (noise measurement does not apply to associated channel)
  59. * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
  60. * Use default noise value of -127 ... this is below the range of measurable
  61. * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
  62. * Also, -127 works better than 0 when averaging frames with/without
  63. * noise info (e.g. averaging might be done in app); measured dBm values are
  64. * always negative ... using a negative value as the default keeps all
  65. * averages within an s8's (used in some apps) range of negative values. */
  66. #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
  67. /*
  68. * RTS threshold here is total size [2347] minus 4 FCS bytes
  69. * Per spec:
  70. * a value of 0 means RTS on all data/management packets
  71. * a value > max MSDU size means no RTS
  72. * else RTS for data/management frames where MPDU is larger
  73. * than RTS value.
  74. */
  75. #define DEFAULT_RTS_THRESHOLD 2347U
  76. #define MIN_RTS_THRESHOLD 0U
  77. #define MAX_RTS_THRESHOLD 2347U
  78. #define MAX_MSDU_SIZE 2304U
  79. #define MAX_MPDU_SIZE 2346U
  80. #define DEFAULT_BEACON_INTERVAL 200U
  81. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  82. #define DEFAULT_LONG_RETRY_LIMIT 4U
  83. #define IWL_NUM_SCAN_RATES (2)
  84. /*
  85. * One for each channel, holds all channel setup data
  86. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  87. * with one another!
  88. */
  89. struct iwl_channel_info {
  90. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  91. struct iwl_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
  92. * HT40 channel */
  93. u8 channel; /* channel number */
  94. u8 flags; /* flags copied from EEPROM */
  95. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  96. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  97. s8 min_power; /* always 0 */
  98. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  99. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  100. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  101. enum ieee80211_band band;
  102. /* HT40 channel info */
  103. s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  104. u8 ht40_flags; /* flags copied from EEPROM */
  105. u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  106. };
  107. /*
  108. * Minimum number of queues. MAX_NUM is defined in hw specific files.
  109. * Set the minimum to accommodate
  110. * - 4 standard TX queues
  111. * - the command queue
  112. * - 4 PAN TX queues
  113. * - the PAN multicast queue, and
  114. * - the AUX (TX during scan dwell) queue.
  115. */
  116. #define IWL_MIN_NUM_QUEUES 11
  117. /*
  118. * Command queue depends on iPAN support.
  119. */
  120. #define IWL_DEFAULT_CMD_QUEUE_NUM 4
  121. #define IWL_IPAN_CMD_QUEUE_NUM 9
  122. #define IEEE80211_DATA_LEN 2304
  123. #define IEEE80211_4ADDR_LEN 30
  124. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  125. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  126. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  127. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  128. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  129. #define IWL_SUPPORTED_RATES_IE_LEN 8
  130. #define IWL_INVALID_RATE 0xFF
  131. #define IWL_INVALID_VALUE -1
  132. union iwl_ht_rate_supp {
  133. u16 rates;
  134. struct {
  135. u8 siso_rate;
  136. u8 mimo_rate;
  137. };
  138. };
  139. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  140. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  141. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  142. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  143. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  144. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  145. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  146. /*
  147. * Maximal MPDU density for TX aggregation
  148. * 4 - 2us density
  149. * 5 - 4us density
  150. * 6 - 8us density
  151. * 7 - 16us density
  152. */
  153. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  154. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  155. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  156. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  157. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  158. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  159. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  160. struct iwl_ht_config {
  161. bool single_chain_sufficient;
  162. enum ieee80211_smps_mode smps; /* current smps mode */
  163. };
  164. /* QoS structures */
  165. struct iwl_qos_info {
  166. int qos_active;
  167. struct iwl_qosparam_cmd def_qos_parm;
  168. };
  169. /*
  170. * Structure should be accessed with sta_lock held. When station addition
  171. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  172. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  173. * held.
  174. */
  175. struct iwl_station_entry {
  176. struct iwl_addsta_cmd sta;
  177. u8 used, ctxid;
  178. struct iwl_link_quality_cmd *lq;
  179. };
  180. /*
  181. * iwl_station_priv: Driver's private station information
  182. *
  183. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  184. * in the structure for use by driver. This structure is places in that
  185. * space.
  186. */
  187. struct iwl_station_priv {
  188. struct iwl_rxon_context *ctx;
  189. struct iwl_lq_sta lq_sta;
  190. atomic_t pending_frames;
  191. bool client;
  192. bool asleep;
  193. u8 max_agg_bufsize;
  194. u8 sta_id;
  195. };
  196. /**
  197. * struct iwl_vif_priv - driver's private per-interface information
  198. *
  199. * When mac80211 allocates a virtual interface, it can allocate
  200. * space for us to put data into.
  201. */
  202. struct iwl_vif_priv {
  203. struct iwl_rxon_context *ctx;
  204. u8 ibss_bssid_sta_id;
  205. };
  206. /* one for each uCode image (inst/data, boot/init/runtime) */
  207. struct fw_desc {
  208. void *v_addr; /* access by driver */
  209. dma_addr_t p_addr; /* access by card's busmaster DMA */
  210. u32 len; /* bytes */
  211. };
  212. struct fw_img {
  213. struct fw_desc code, data;
  214. };
  215. /* v1/v2 uCode file layout */
  216. struct iwl_ucode_header {
  217. __le32 ver; /* major/minor/API/serial */
  218. union {
  219. struct {
  220. __le32 inst_size; /* bytes of runtime code */
  221. __le32 data_size; /* bytes of runtime data */
  222. __le32 init_size; /* bytes of init code */
  223. __le32 init_data_size; /* bytes of init data */
  224. __le32 boot_size; /* bytes of bootstrap code */
  225. u8 data[0]; /* in same order as sizes */
  226. } v1;
  227. struct {
  228. __le32 build; /* build number */
  229. __le32 inst_size; /* bytes of runtime code */
  230. __le32 data_size; /* bytes of runtime data */
  231. __le32 init_size; /* bytes of init code */
  232. __le32 init_data_size; /* bytes of init data */
  233. __le32 boot_size; /* bytes of bootstrap code */
  234. u8 data[0]; /* in same order as sizes */
  235. } v2;
  236. } u;
  237. };
  238. /*
  239. * new TLV uCode file layout
  240. *
  241. * The new TLV file format contains TLVs, that each specify
  242. * some piece of data. To facilitate "groups", for example
  243. * different instruction image with different capabilities,
  244. * bundled with the same init image, an alternative mechanism
  245. * is provided:
  246. * When the alternative field is 0, that means that the item
  247. * is always valid. When it is non-zero, then it is only
  248. * valid in conjunction with items of the same alternative,
  249. * in which case the driver (user) selects one alternative
  250. * to use.
  251. */
  252. enum iwl_ucode_tlv_type {
  253. IWL_UCODE_TLV_INVALID = 0, /* unused */
  254. IWL_UCODE_TLV_INST = 1,
  255. IWL_UCODE_TLV_DATA = 2,
  256. IWL_UCODE_TLV_INIT = 3,
  257. IWL_UCODE_TLV_INIT_DATA = 4,
  258. IWL_UCODE_TLV_BOOT = 5,
  259. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  260. IWL_UCODE_TLV_PAN = 7,
  261. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  262. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  263. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  264. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  265. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  266. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  267. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  268. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  269. IWL_UCODE_TLV_WOWLAN_INST = 16,
  270. IWL_UCODE_TLV_WOWLAN_DATA = 17,
  271. IWL_UCODE_TLV_FLAGS = 18,
  272. };
  273. /**
  274. * enum iwl_ucode_tlv_flag - ucode API flags
  275. * @IWL_UCODE_TLV_FLAGS_PAN: This is PAN capable microcode; this previously
  276. * was a separate TLV but moved here to save space.
  277. * @IWL_UCODE_TLV_FLAGS_NEWSCAN: new uCode scan behaviour on hidden SSID,
  278. * treats good CRC threshold as a boolean
  279. * @IWL_UCODE_TLV_FLAGS_MFP: This uCode image supports MFP (802.11w).
  280. * @IWL_UCODE_TLV_FLAGS_P2P: This uCode image supports P2P.
  281. */
  282. enum iwl_ucode_tlv_flag {
  283. IWL_UCODE_TLV_FLAGS_PAN = BIT(0),
  284. IWL_UCODE_TLV_FLAGS_NEWSCAN = BIT(1),
  285. IWL_UCODE_TLV_FLAGS_MFP = BIT(2),
  286. IWL_UCODE_TLV_FLAGS_P2P = BIT(3),
  287. };
  288. struct iwl_ucode_tlv {
  289. __le16 type; /* see above */
  290. __le16 alternative; /* see comment */
  291. __le32 length; /* not including type/length fields */
  292. u8 data[0];
  293. } __packed;
  294. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  295. struct iwl_tlv_ucode_header {
  296. /*
  297. * The TLV style ucode header is distinguished from
  298. * the v1/v2 style header by first four bytes being
  299. * zero, as such is an invalid combination of
  300. * major/minor/API/serial versions.
  301. */
  302. __le32 zero;
  303. __le32 magic;
  304. u8 human_readable[64];
  305. __le32 ver; /* major/minor/API/serial */
  306. __le32 build;
  307. __le64 alternatives; /* bitmask of valid alternatives */
  308. /*
  309. * The data contained herein has a TLV layout,
  310. * see above for the TLV header and types.
  311. * Note that each TLV is padded to a length
  312. * that is a multiple of 4 for alignment.
  313. */
  314. u8 data[0];
  315. };
  316. struct iwl_sensitivity_ranges {
  317. u16 min_nrg_cck;
  318. u16 max_nrg_cck;
  319. u16 nrg_th_cck;
  320. u16 nrg_th_ofdm;
  321. u16 auto_corr_min_ofdm;
  322. u16 auto_corr_min_ofdm_mrc;
  323. u16 auto_corr_min_ofdm_x1;
  324. u16 auto_corr_min_ofdm_mrc_x1;
  325. u16 auto_corr_max_ofdm;
  326. u16 auto_corr_max_ofdm_mrc;
  327. u16 auto_corr_max_ofdm_x1;
  328. u16 auto_corr_max_ofdm_mrc_x1;
  329. u16 auto_corr_max_cck;
  330. u16 auto_corr_max_cck_mrc;
  331. u16 auto_corr_min_cck;
  332. u16 auto_corr_min_cck_mrc;
  333. u16 barker_corr_th_min;
  334. u16 barker_corr_th_min_mrc;
  335. u16 nrg_th_cca;
  336. };
  337. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  338. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  339. /******************************************************************************
  340. *
  341. * Functions implemented in core module which are forward declared here
  342. * for use by iwl-[4-5].c
  343. *
  344. * NOTE: The implementation of these functions are not hardware specific
  345. * which is why they are in the core module files.
  346. *
  347. * Naming convention --
  348. * iwl_ <-- Is part of iwlwifi
  349. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  350. *
  351. ****************************************************************************/
  352. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  353. extern const u8 iwl_bcast_addr[ETH_ALEN];
  354. #define IWL_OPERATION_MODE_AUTO 0
  355. #define IWL_OPERATION_MODE_HT_ONLY 1
  356. #define IWL_OPERATION_MODE_MIXED 2
  357. #define IWL_OPERATION_MODE_20MHZ 3
  358. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  359. /* Sensitivity and chain noise calibration */
  360. #define INITIALIZATION_VALUE 0xFFFF
  361. #define IWL_CAL_NUM_BEACONS 16
  362. #define MAXIMUM_ALLOWED_PATHLOSS 15
  363. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  364. #define MAX_FA_OFDM 50
  365. #define MIN_FA_OFDM 5
  366. #define MAX_FA_CCK 50
  367. #define MIN_FA_CCK 5
  368. #define AUTO_CORR_STEP_OFDM 1
  369. #define AUTO_CORR_STEP_CCK 3
  370. #define AUTO_CORR_MAX_TH_CCK 160
  371. #define NRG_DIFF 2
  372. #define NRG_STEP_CCK 2
  373. #define NRG_MARGIN 8
  374. #define MAX_NUMBER_CCK_NO_FA 100
  375. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  376. #define CHAIN_A 0
  377. #define CHAIN_B 1
  378. #define CHAIN_C 2
  379. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  380. #define ALL_BAND_FILTER 0xFF00
  381. #define IN_BAND_FILTER 0xFF
  382. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  383. #define NRG_NUM_PREV_STAT_L 20
  384. #define NUM_RX_CHAINS 3
  385. enum iwlagn_false_alarm_state {
  386. IWL_FA_TOO_MANY = 0,
  387. IWL_FA_TOO_FEW = 1,
  388. IWL_FA_GOOD_RANGE = 2,
  389. };
  390. enum iwlagn_chain_noise_state {
  391. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  392. IWL_CHAIN_NOISE_ACCUMULATE,
  393. IWL_CHAIN_NOISE_CALIBRATED,
  394. IWL_CHAIN_NOISE_DONE,
  395. };
  396. /*
  397. * enum iwl_calib
  398. * defines the order in which results of initial calibrations
  399. * should be sent to the runtime uCode
  400. */
  401. enum iwl_calib {
  402. IWL_CALIB_XTAL,
  403. IWL_CALIB_DC,
  404. IWL_CALIB_LO,
  405. IWL_CALIB_TX_IQ,
  406. IWL_CALIB_TX_IQ_PERD,
  407. IWL_CALIB_BASE_BAND,
  408. IWL_CALIB_TEMP_OFFSET,
  409. IWL_CALIB_MAX
  410. };
  411. /* Opaque calibration results */
  412. struct iwl_calib_result {
  413. void *buf;
  414. size_t buf_len;
  415. };
  416. /* Sensitivity calib data */
  417. struct iwl_sensitivity_data {
  418. u32 auto_corr_ofdm;
  419. u32 auto_corr_ofdm_mrc;
  420. u32 auto_corr_ofdm_x1;
  421. u32 auto_corr_ofdm_mrc_x1;
  422. u32 auto_corr_cck;
  423. u32 auto_corr_cck_mrc;
  424. u32 last_bad_plcp_cnt_ofdm;
  425. u32 last_fa_cnt_ofdm;
  426. u32 last_bad_plcp_cnt_cck;
  427. u32 last_fa_cnt_cck;
  428. u32 nrg_curr_state;
  429. u32 nrg_prev_state;
  430. u32 nrg_value[10];
  431. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  432. u32 nrg_silence_ref;
  433. u32 nrg_energy_idx;
  434. u32 nrg_silence_idx;
  435. u32 nrg_th_cck;
  436. s32 nrg_auto_corr_silence_diff;
  437. u32 num_in_cck_no_fa;
  438. u32 nrg_th_ofdm;
  439. u16 barker_corr_th_min;
  440. u16 barker_corr_th_min_mrc;
  441. u16 nrg_th_cca;
  442. };
  443. /* Chain noise (differential Rx gain) calib data */
  444. struct iwl_chain_noise_data {
  445. u32 active_chains;
  446. u32 chain_noise_a;
  447. u32 chain_noise_b;
  448. u32 chain_noise_c;
  449. u32 chain_signal_a;
  450. u32 chain_signal_b;
  451. u32 chain_signal_c;
  452. u16 beacon_count;
  453. u8 disconn_array[NUM_RX_CHAINS];
  454. u8 delta_gain_code[NUM_RX_CHAINS];
  455. u8 radio_write;
  456. u8 state;
  457. };
  458. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  459. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  460. enum {
  461. MEASUREMENT_READY = (1 << 0),
  462. MEASUREMENT_ACTIVE = (1 << 1),
  463. };
  464. enum iwl_nvm_type {
  465. NVM_DEVICE_TYPE_EEPROM = 0,
  466. NVM_DEVICE_TYPE_OTP,
  467. };
  468. /*
  469. * Two types of OTP memory access modes
  470. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  471. * based on physical memory addressing
  472. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  473. * based on logical memory addressing
  474. */
  475. enum iwl_access_mode {
  476. IWL_OTP_ACCESS_ABSOLUTE,
  477. IWL_OTP_ACCESS_RELATIVE,
  478. };
  479. /**
  480. * enum iwl_pa_type - Power Amplifier type
  481. * @IWL_PA_SYSTEM: based on uCode configuration
  482. * @IWL_PA_INTERNAL: use Internal only
  483. */
  484. enum iwl_pa_type {
  485. IWL_PA_SYSTEM = 0,
  486. IWL_PA_INTERNAL = 1,
  487. };
  488. /* reply_tx_statistics (for _agn devices) */
  489. struct reply_tx_error_statistics {
  490. u32 pp_delay;
  491. u32 pp_few_bytes;
  492. u32 pp_bt_prio;
  493. u32 pp_quiet_period;
  494. u32 pp_calc_ttak;
  495. u32 int_crossed_retry;
  496. u32 short_limit;
  497. u32 long_limit;
  498. u32 fifo_underrun;
  499. u32 drain_flow;
  500. u32 rfkill_flush;
  501. u32 life_expire;
  502. u32 dest_ps;
  503. u32 host_abort;
  504. u32 bt_retry;
  505. u32 sta_invalid;
  506. u32 frag_drop;
  507. u32 tid_disable;
  508. u32 fifo_flush;
  509. u32 insuff_cf_poll;
  510. u32 fail_hw_drop;
  511. u32 sta_color_mismatch;
  512. u32 unknown;
  513. };
  514. /* reply_agg_tx_statistics (for _agn devices) */
  515. struct reply_agg_tx_error_statistics {
  516. u32 underrun;
  517. u32 bt_prio;
  518. u32 few_bytes;
  519. u32 abort;
  520. u32 last_sent_ttl;
  521. u32 last_sent_try;
  522. u32 last_sent_bt_kill;
  523. u32 scd_query;
  524. u32 bad_crc32;
  525. u32 response;
  526. u32 dump_tx;
  527. u32 delay_tx;
  528. u32 unknown;
  529. };
  530. /* management statistics */
  531. enum iwl_mgmt_stats {
  532. MANAGEMENT_ASSOC_REQ = 0,
  533. MANAGEMENT_ASSOC_RESP,
  534. MANAGEMENT_REASSOC_REQ,
  535. MANAGEMENT_REASSOC_RESP,
  536. MANAGEMENT_PROBE_REQ,
  537. MANAGEMENT_PROBE_RESP,
  538. MANAGEMENT_BEACON,
  539. MANAGEMENT_ATIM,
  540. MANAGEMENT_DISASSOC,
  541. MANAGEMENT_AUTH,
  542. MANAGEMENT_DEAUTH,
  543. MANAGEMENT_ACTION,
  544. MANAGEMENT_MAX,
  545. };
  546. /* control statistics */
  547. enum iwl_ctrl_stats {
  548. CONTROL_BACK_REQ = 0,
  549. CONTROL_BACK,
  550. CONTROL_PSPOLL,
  551. CONTROL_RTS,
  552. CONTROL_CTS,
  553. CONTROL_ACK,
  554. CONTROL_CFEND,
  555. CONTROL_CFENDACK,
  556. CONTROL_MAX,
  557. };
  558. struct traffic_stats {
  559. #ifdef CONFIG_IWLWIFI_DEBUGFS
  560. u32 mgmt[MANAGEMENT_MAX];
  561. u32 ctrl[CONTROL_MAX];
  562. u32 data_cnt;
  563. u64 data_bytes;
  564. #endif
  565. };
  566. /*
  567. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  568. * to perform continuous uCode event logging operation if enabled
  569. */
  570. #define UCODE_TRACE_PERIOD (100)
  571. /*
  572. * iwl_event_log: current uCode event log position
  573. *
  574. * @ucode_trace: enable/disable ucode continuous trace timer
  575. * @num_wraps: how many times the event buffer wraps
  576. * @next_entry: the entry just before the next one that uCode would fill
  577. * @non_wraps_count: counter for no wrap detected when dump ucode events
  578. * @wraps_once_count: counter for wrap once detected when dump ucode events
  579. * @wraps_more_count: counter for wrap more than once detected
  580. * when dump ucode events
  581. */
  582. struct iwl_event_log {
  583. bool ucode_trace;
  584. u32 num_wraps;
  585. u32 next_entry;
  586. int non_wraps_count;
  587. int wraps_once_count;
  588. int wraps_more_count;
  589. };
  590. /*
  591. * This is the threshold value of plcp error rate per 100mSecs. It is
  592. * used to set and check for the validity of plcp_delta.
  593. */
  594. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  595. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  596. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  597. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  598. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  599. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  600. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  601. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  602. /* TX queue watchdog timeouts in mSecs */
  603. #define IWL_DEF_WD_TIMEOUT (2000)
  604. #define IWL_LONG_WD_TIMEOUT (10000)
  605. #define IWL_MAX_WD_TIMEOUT (120000)
  606. /* BT Antenna Coupling Threshold (dB) */
  607. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  608. /* Firmware reload counter and Timestamp */
  609. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  610. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  611. enum iwl_reset {
  612. IWL_RF_RESET = 0,
  613. IWL_FW_RESET,
  614. IWL_MAX_FORCE_RESET,
  615. };
  616. struct iwl_force_reset {
  617. int reset_request_count;
  618. int reset_success_count;
  619. int reset_reject_count;
  620. unsigned long reset_duration;
  621. unsigned long last_force_reset_jiffies;
  622. };
  623. /* extend beacon time format bit shifting */
  624. /*
  625. * for _agn devices
  626. * bits 31:22 - extended
  627. * bits 21:0 - interval
  628. */
  629. #define IWLAGN_EXT_BEACON_TIME_POS 22
  630. /**
  631. * struct iwl_notification_wait - notification wait entry
  632. * @list: list head for global list
  633. * @fn: function called with the notification
  634. * @cmd: command ID
  635. *
  636. * This structure is not used directly, to wait for a
  637. * notification declare it on the stack, and call
  638. * iwlagn_init_notification_wait() with appropriate
  639. * parameters. Then do whatever will cause the ucode
  640. * to notify the driver, and to wait for that then
  641. * call iwlagn_wait_notification().
  642. *
  643. * Each notification is one-shot. If at some point we
  644. * need to support multi-shot notifications (which
  645. * can't be allocated on the stack) we need to modify
  646. * the code for them.
  647. */
  648. struct iwl_notification_wait {
  649. struct list_head list;
  650. void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
  651. void *data);
  652. void *fn_data;
  653. u8 cmd;
  654. bool triggered, aborted;
  655. };
  656. struct iwl_rxon_context {
  657. struct ieee80211_vif *vif;
  658. /*
  659. * We could use the vif to indicate active, but we
  660. * also need it to be active during disabling when
  661. * we already removed the vif for type setting.
  662. */
  663. bool always_active, is_active;
  664. bool ht_need_multiple_chains;
  665. enum iwl_rxon_context_id ctxid;
  666. u32 interface_modes, exclusive_interface_modes;
  667. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  668. /*
  669. * We declare this const so it can only be
  670. * changed via explicit cast within the
  671. * routines that actually update the physical
  672. * hardware.
  673. */
  674. const struct iwl_rxon_cmd active;
  675. struct iwl_rxon_cmd staging;
  676. struct iwl_rxon_time_cmd timing;
  677. struct iwl_qos_info qos_data;
  678. u8 bcast_sta_id, ap_sta_id;
  679. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  680. u8 qos_cmd;
  681. u8 wep_key_cmd;
  682. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  683. u8 key_mapping_keys;
  684. __le32 station_flags;
  685. int beacon_int;
  686. struct {
  687. bool non_gf_sta_present;
  688. u8 protection;
  689. bool enabled, is_40mhz;
  690. u8 extension_chan_offset;
  691. } ht;
  692. u8 bssid[ETH_ALEN];
  693. bool preauth_bssid;
  694. bool last_tx_rejected;
  695. };
  696. enum iwl_scan_type {
  697. IWL_SCAN_NORMAL,
  698. IWL_SCAN_RADIO_RESET,
  699. IWL_SCAN_ROC,
  700. };
  701. enum iwlagn_ucode_type {
  702. IWL_UCODE_NONE,
  703. IWL_UCODE_REGULAR,
  704. IWL_UCODE_INIT,
  705. IWL_UCODE_WOWLAN,
  706. };
  707. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  708. struct iwl_testmode_trace {
  709. u32 buff_size;
  710. u32 total_size;
  711. u32 num_chunks;
  712. u8 *cpu_addr;
  713. u8 *trace_addr;
  714. dma_addr_t dma_addr;
  715. bool trace_enabled;
  716. };
  717. #endif
  718. struct iwl_priv {
  719. /*data shared among all the driver's layers */
  720. struct iwl_shared _shrd;
  721. struct iwl_shared *shrd;
  722. /* ieee device used by generic ieee processing code */
  723. struct ieee80211_hw *hw;
  724. struct ieee80211_channel *ieee_channels;
  725. struct ieee80211_rate *ieee_rates;
  726. struct kmem_cache *tx_cmd_pool;
  727. struct iwl_cfg *cfg;
  728. enum ieee80211_band band;
  729. void (*pre_rx_handler)(struct iwl_priv *priv,
  730. struct iwl_rx_mem_buffer *rxb);
  731. int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  732. struct iwl_rx_mem_buffer *rxb,
  733. struct iwl_device_cmd *cmd);
  734. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  735. /* spectrum measurement report caching */
  736. struct iwl_spectrum_notification measure_report;
  737. u8 measurement_status;
  738. /* ucode beacon time */
  739. u32 ucode_beacon_time;
  740. int missed_beacon_threshold;
  741. /* track IBSS manager (last beacon) status */
  742. u32 ibss_manager;
  743. /* jiffies when last recovery from statistics was performed */
  744. unsigned long rx_statistics_jiffies;
  745. /*counters */
  746. u32 rx_handlers_stats[REPLY_MAX];
  747. /* force reset */
  748. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  749. /* firmware reload counter and timestamp */
  750. unsigned long reload_jiffies;
  751. int reload_count;
  752. /* we allocate array of iwl_channel_info for NIC's valid channels.
  753. * Access via channel # using indirect index array */
  754. struct iwl_channel_info *channel_info; /* channel info array */
  755. u8 channel_count; /* # of channels */
  756. /* thermal calibration */
  757. s32 temperature; /* Celsius */
  758. s32 last_temperature;
  759. /* init calibration results */
  760. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  761. /* Scan related variables */
  762. unsigned long scan_start;
  763. unsigned long scan_start_tsf;
  764. void *scan_cmd;
  765. enum ieee80211_band scan_band;
  766. struct cfg80211_scan_request *scan_request;
  767. struct ieee80211_vif *scan_vif;
  768. enum iwl_scan_type scan_type;
  769. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  770. u8 mgmt_tx_ant;
  771. /* max number of station keys */
  772. u8 sta_key_max_num;
  773. bool new_scan_threshold_behaviour;
  774. /* EEPROM MAC addresses */
  775. struct mac_address addresses[2];
  776. /* uCode images, save to reload in case of failure */
  777. int fw_index; /* firmware we're trying to load */
  778. u32 ucode_ver; /* version of ucode, copy of
  779. iwl_ucode.ver */
  780. struct fw_img ucode_rt;
  781. struct fw_img ucode_init;
  782. struct fw_img ucode_wowlan;
  783. enum iwlagn_ucode_type ucode_type;
  784. u8 ucode_write_complete; /* the image write is complete */
  785. char firmware_name[25];
  786. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  787. __le16 switch_channel;
  788. struct {
  789. u32 error_event_table;
  790. u32 log_event_table;
  791. } device_pointers;
  792. u16 active_rate;
  793. u8 start_calib;
  794. struct iwl_sensitivity_data sensitivity_data;
  795. struct iwl_chain_noise_data chain_noise_data;
  796. bool enhance_sensitivity_table;
  797. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  798. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  799. struct iwl_ht_config current_ht_config;
  800. /* Rate scaling data */
  801. u8 retry_rate;
  802. int activity_timer_active;
  803. /* counts mgmt, ctl, and data packets */
  804. struct traffic_stats tx_stats;
  805. struct traffic_stats rx_stats;
  806. struct iwl_power_mgr power_data;
  807. struct iwl_tt_mgmt thermal_throttle;
  808. /* station table variables */
  809. int num_stations;
  810. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  811. unsigned long ucode_key_table;
  812. u8 mac80211_registered;
  813. /* Indication if ieee80211_ops->open has been called */
  814. u8 is_open;
  815. /* eeprom -- this is in the card's little endian byte order */
  816. u8 *eeprom;
  817. int nvm_device_type;
  818. struct iwl_eeprom_calib_info *calib_info;
  819. enum nl80211_iftype iw_mode;
  820. /* Last Rx'd beacon timestamp */
  821. u64 timestamp;
  822. struct {
  823. __le32 flag;
  824. struct statistics_general_common common;
  825. struct statistics_rx_non_phy rx_non_phy;
  826. struct statistics_rx_phy rx_ofdm;
  827. struct statistics_rx_ht_phy rx_ofdm_ht;
  828. struct statistics_rx_phy rx_cck;
  829. struct statistics_tx tx;
  830. #ifdef CONFIG_IWLWIFI_DEBUGFS
  831. struct statistics_bt_activity bt_activity;
  832. __le32 num_bt_kills, accum_num_bt_kills;
  833. #endif
  834. } statistics;
  835. #ifdef CONFIG_IWLWIFI_DEBUGFS
  836. struct {
  837. struct statistics_general_common common;
  838. struct statistics_rx_non_phy rx_non_phy;
  839. struct statistics_rx_phy rx_ofdm;
  840. struct statistics_rx_ht_phy rx_ofdm_ht;
  841. struct statistics_rx_phy rx_cck;
  842. struct statistics_tx tx;
  843. struct statistics_bt_activity bt_activity;
  844. } accum_stats, delta_stats, max_delta_stats;
  845. #endif
  846. /*
  847. * reporting the number of tids has AGG on. 0 means
  848. * no AGGREGATION
  849. */
  850. u8 agg_tids_count;
  851. struct iwl_rx_phy_res last_phy_res;
  852. bool last_phy_res_valid;
  853. struct completion firmware_loading_complete;
  854. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  855. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  856. /*
  857. * chain noise reset and gain commands are the
  858. * two extra calibration commands follows the standard
  859. * phy calibration commands
  860. */
  861. u8 phy_calib_chain_noise_reset_cmd;
  862. u8 phy_calib_chain_noise_gain_cmd;
  863. /* counts reply_tx error */
  864. struct reply_tx_error_statistics reply_tx_stats;
  865. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  866. /* notification wait support */
  867. struct list_head notif_waits;
  868. spinlock_t notif_wait_lock;
  869. wait_queue_head_t notif_waitq;
  870. /* remain-on-channel offload support */
  871. struct ieee80211_channel *hw_roc_channel;
  872. struct delayed_work hw_roc_disable_work;
  873. enum nl80211_channel_type hw_roc_chantype;
  874. int hw_roc_duration;
  875. bool hw_roc_setup, hw_roc_start_notified;
  876. /* bt coex */
  877. u8 bt_enable_flag;
  878. u8 bt_status;
  879. u8 bt_traffic_load, last_bt_traffic_load;
  880. bool bt_ch_announce;
  881. bool bt_full_concurrent;
  882. bool bt_ant_couple_ok;
  883. __le32 kill_ack_mask;
  884. __le32 kill_cts_mask;
  885. __le16 bt_valid;
  886. u16 bt_on_thresh;
  887. u16 bt_duration;
  888. u16 dynamic_frag_thresh;
  889. u8 bt_ci_compliance;
  890. struct work_struct bt_traffic_change_work;
  891. bool bt_enable_pspoll;
  892. struct iwl_rxon_context *cur_rssi_ctx;
  893. bool bt_is_sco;
  894. struct work_struct restart;
  895. struct work_struct scan_completed;
  896. struct work_struct abort_scan;
  897. struct work_struct beacon_update;
  898. struct iwl_rxon_context *beacon_ctx;
  899. struct sk_buff *beacon_skb;
  900. void *beacon_cmd;
  901. struct work_struct tt_work;
  902. struct work_struct ct_enter;
  903. struct work_struct ct_exit;
  904. struct work_struct start_internal_scan;
  905. struct work_struct tx_flush;
  906. struct work_struct bt_full_concurrency;
  907. struct work_struct bt_runtime_config;
  908. struct delayed_work scan_check;
  909. /* TX Power */
  910. s8 tx_power_user_lmt;
  911. s8 tx_power_device_lmt;
  912. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  913. s8 tx_power_next;
  914. #ifdef CONFIG_IWLWIFI_DEBUGFS
  915. /* debugfs */
  916. u16 tx_traffic_idx;
  917. u16 rx_traffic_idx;
  918. u8 *tx_traffic;
  919. u8 *rx_traffic;
  920. struct dentry *debugfs_dir;
  921. u32 dbgfs_sram_offset, dbgfs_sram_len;
  922. bool disable_ht40;
  923. void *wowlan_sram;
  924. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  925. struct work_struct txpower_work;
  926. u32 disable_sens_cal;
  927. u32 disable_chain_noise_cal;
  928. struct work_struct run_time_calib_work;
  929. struct timer_list statistics_periodic;
  930. struct timer_list ucode_trace;
  931. struct timer_list watchdog;
  932. struct iwl_event_log event_log;
  933. struct led_classdev led;
  934. unsigned long blink_on, blink_off;
  935. bool led_registered;
  936. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  937. struct iwl_testmode_trace testmode_trace;
  938. u32 tm_fixed_rate;
  939. #endif
  940. /* WoWLAN GTK rekey data */
  941. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  942. __le64 replay_ctr;
  943. __le16 last_seq_ctl;
  944. bool have_rekey_data;
  945. }; /*iwl_priv */
  946. extern struct iwl_mod_params iwlagn_mod_params;
  947. static inline struct iwl_rxon_context *
  948. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  949. {
  950. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  951. return vif_priv->ctx;
  952. }
  953. #define for_each_context(priv, ctx) \
  954. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  955. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  956. if (priv->shrd->valid_contexts & BIT(ctx->ctxid))
  957. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  958. {
  959. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  960. }
  961. static inline int iwl_is_associated(struct iwl_priv *priv,
  962. enum iwl_rxon_context_id ctxid)
  963. {
  964. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  965. }
  966. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  967. {
  968. struct iwl_rxon_context *ctx;
  969. for_each_context(priv, ctx)
  970. if (iwl_is_associated_ctx(ctx))
  971. return true;
  972. return false;
  973. }
  974. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  975. {
  976. if (ch_info == NULL)
  977. return 0;
  978. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  979. }
  980. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  981. {
  982. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  983. }
  984. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  985. {
  986. return ch_info->band == IEEE80211_BAND_5GHZ;
  987. }
  988. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  989. {
  990. return ch_info->band == IEEE80211_BAND_2GHZ;
  991. }
  992. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  993. {
  994. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  995. }
  996. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  997. {
  998. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  999. }
  1000. #endif /* __iwl_dev_h__ */