iwl-dev.h 30 KB

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