iwl-dev.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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. /* v1/v2 uCode file layout */
  207. struct iwl_ucode_header {
  208. __le32 ver; /* major/minor/API/serial */
  209. union {
  210. struct {
  211. __le32 inst_size; /* bytes of runtime code */
  212. __le32 data_size; /* bytes of runtime data */
  213. __le32 init_size; /* bytes of init code */
  214. __le32 init_data_size; /* bytes of init data */
  215. __le32 boot_size; /* bytes of bootstrap code */
  216. u8 data[0]; /* in same order as sizes */
  217. } v1;
  218. struct {
  219. __le32 build; /* build number */
  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. } v2;
  227. } u;
  228. };
  229. /*
  230. * new TLV uCode file layout
  231. *
  232. * The new TLV file format contains TLVs, that each specify
  233. * some piece of data. To facilitate "groups", for example
  234. * different instruction image with different capabilities,
  235. * bundled with the same init image, an alternative mechanism
  236. * is provided:
  237. * When the alternative field is 0, that means that the item
  238. * is always valid. When it is non-zero, then it is only
  239. * valid in conjunction with items of the same alternative,
  240. * in which case the driver (user) selects one alternative
  241. * to use.
  242. */
  243. enum iwl_ucode_tlv_type {
  244. IWL_UCODE_TLV_INVALID = 0, /* unused */
  245. IWL_UCODE_TLV_INST = 1,
  246. IWL_UCODE_TLV_DATA = 2,
  247. IWL_UCODE_TLV_INIT = 3,
  248. IWL_UCODE_TLV_INIT_DATA = 4,
  249. IWL_UCODE_TLV_BOOT = 5,
  250. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  251. IWL_UCODE_TLV_PAN = 7,
  252. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  253. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  254. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  255. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  256. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  257. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  258. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  259. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  260. IWL_UCODE_TLV_WOWLAN_INST = 16,
  261. IWL_UCODE_TLV_WOWLAN_DATA = 17,
  262. IWL_UCODE_TLV_FLAGS = 18,
  263. };
  264. /**
  265. * enum iwl_ucode_tlv_flag - ucode API flags
  266. * @IWL_UCODE_TLV_FLAGS_PAN: This is PAN capable microcode; this previously
  267. * was a separate TLV but moved here to save space.
  268. * @IWL_UCODE_TLV_FLAGS_NEWSCAN: new uCode scan behaviour on hidden SSID,
  269. * treats good CRC threshold as a boolean
  270. * @IWL_UCODE_TLV_FLAGS_MFP: This uCode image supports MFP (802.11w).
  271. * @IWL_UCODE_TLV_FLAGS_P2P: This uCode image supports P2P.
  272. */
  273. enum iwl_ucode_tlv_flag {
  274. IWL_UCODE_TLV_FLAGS_PAN = BIT(0),
  275. IWL_UCODE_TLV_FLAGS_NEWSCAN = BIT(1),
  276. IWL_UCODE_TLV_FLAGS_MFP = BIT(2),
  277. IWL_UCODE_TLV_FLAGS_P2P = BIT(3),
  278. };
  279. struct iwl_ucode_tlv {
  280. __le16 type; /* see above */
  281. __le16 alternative; /* see comment */
  282. __le32 length; /* not including type/length fields */
  283. u8 data[0];
  284. } __packed;
  285. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  286. struct iwl_tlv_ucode_header {
  287. /*
  288. * The TLV style ucode header is distinguished from
  289. * the v1/v2 style header by first four bytes being
  290. * zero, as such is an invalid combination of
  291. * major/minor/API/serial versions.
  292. */
  293. __le32 zero;
  294. __le32 magic;
  295. u8 human_readable[64];
  296. __le32 ver; /* major/minor/API/serial */
  297. __le32 build;
  298. __le64 alternatives; /* bitmask of valid alternatives */
  299. /*
  300. * The data contained herein has a TLV layout,
  301. * see above for the TLV header and types.
  302. * Note that each TLV is padded to a length
  303. * that is a multiple of 4 for alignment.
  304. */
  305. u8 data[0];
  306. };
  307. struct iwl_sensitivity_ranges {
  308. u16 min_nrg_cck;
  309. u16 max_nrg_cck;
  310. u16 nrg_th_cck;
  311. u16 nrg_th_ofdm;
  312. u16 auto_corr_min_ofdm;
  313. u16 auto_corr_min_ofdm_mrc;
  314. u16 auto_corr_min_ofdm_x1;
  315. u16 auto_corr_min_ofdm_mrc_x1;
  316. u16 auto_corr_max_ofdm;
  317. u16 auto_corr_max_ofdm_mrc;
  318. u16 auto_corr_max_ofdm_x1;
  319. u16 auto_corr_max_ofdm_mrc_x1;
  320. u16 auto_corr_max_cck;
  321. u16 auto_corr_max_cck_mrc;
  322. u16 auto_corr_min_cck;
  323. u16 auto_corr_min_cck_mrc;
  324. u16 barker_corr_th_min;
  325. u16 barker_corr_th_min_mrc;
  326. u16 nrg_th_cca;
  327. };
  328. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  329. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  330. /******************************************************************************
  331. *
  332. * Functions implemented in core module which are forward declared here
  333. * for use by iwl-[4-5].c
  334. *
  335. * NOTE: The implementation of these functions are not hardware specific
  336. * which is why they are in the core module files.
  337. *
  338. * Naming convention --
  339. * iwl_ <-- Is part of iwlwifi
  340. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  341. *
  342. ****************************************************************************/
  343. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  344. extern const u8 iwl_bcast_addr[ETH_ALEN];
  345. #define IWL_OPERATION_MODE_AUTO 0
  346. #define IWL_OPERATION_MODE_HT_ONLY 1
  347. #define IWL_OPERATION_MODE_MIXED 2
  348. #define IWL_OPERATION_MODE_20MHZ 3
  349. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  350. /* Sensitivity and chain noise calibration */
  351. #define INITIALIZATION_VALUE 0xFFFF
  352. #define IWL_CAL_NUM_BEACONS 16
  353. #define MAXIMUM_ALLOWED_PATHLOSS 15
  354. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  355. #define MAX_FA_OFDM 50
  356. #define MIN_FA_OFDM 5
  357. #define MAX_FA_CCK 50
  358. #define MIN_FA_CCK 5
  359. #define AUTO_CORR_STEP_OFDM 1
  360. #define AUTO_CORR_STEP_CCK 3
  361. #define AUTO_CORR_MAX_TH_CCK 160
  362. #define NRG_DIFF 2
  363. #define NRG_STEP_CCK 2
  364. #define NRG_MARGIN 8
  365. #define MAX_NUMBER_CCK_NO_FA 100
  366. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  367. #define CHAIN_A 0
  368. #define CHAIN_B 1
  369. #define CHAIN_C 2
  370. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  371. #define ALL_BAND_FILTER 0xFF00
  372. #define IN_BAND_FILTER 0xFF
  373. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  374. #define NRG_NUM_PREV_STAT_L 20
  375. #define NUM_RX_CHAINS 3
  376. enum iwlagn_false_alarm_state {
  377. IWL_FA_TOO_MANY = 0,
  378. IWL_FA_TOO_FEW = 1,
  379. IWL_FA_GOOD_RANGE = 2,
  380. };
  381. enum iwlagn_chain_noise_state {
  382. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  383. IWL_CHAIN_NOISE_ACCUMULATE,
  384. IWL_CHAIN_NOISE_CALIBRATED,
  385. IWL_CHAIN_NOISE_DONE,
  386. };
  387. /* Opaque calibration results */
  388. struct iwl_calib_result {
  389. struct list_head list;
  390. size_t cmd_len;
  391. struct iwl_calib_hdr hdr;
  392. /* data follows */
  393. };
  394. /* Sensitivity calib data */
  395. struct iwl_sensitivity_data {
  396. u32 auto_corr_ofdm;
  397. u32 auto_corr_ofdm_mrc;
  398. u32 auto_corr_ofdm_x1;
  399. u32 auto_corr_ofdm_mrc_x1;
  400. u32 auto_corr_cck;
  401. u32 auto_corr_cck_mrc;
  402. u32 last_bad_plcp_cnt_ofdm;
  403. u32 last_fa_cnt_ofdm;
  404. u32 last_bad_plcp_cnt_cck;
  405. u32 last_fa_cnt_cck;
  406. u32 nrg_curr_state;
  407. u32 nrg_prev_state;
  408. u32 nrg_value[10];
  409. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  410. u32 nrg_silence_ref;
  411. u32 nrg_energy_idx;
  412. u32 nrg_silence_idx;
  413. u32 nrg_th_cck;
  414. s32 nrg_auto_corr_silence_diff;
  415. u32 num_in_cck_no_fa;
  416. u32 nrg_th_ofdm;
  417. u16 barker_corr_th_min;
  418. u16 barker_corr_th_min_mrc;
  419. u16 nrg_th_cca;
  420. };
  421. /* Chain noise (differential Rx gain) calib data */
  422. struct iwl_chain_noise_data {
  423. u32 active_chains;
  424. u32 chain_noise_a;
  425. u32 chain_noise_b;
  426. u32 chain_noise_c;
  427. u32 chain_signal_a;
  428. u32 chain_signal_b;
  429. u32 chain_signal_c;
  430. u16 beacon_count;
  431. u8 disconn_array[NUM_RX_CHAINS];
  432. u8 delta_gain_code[NUM_RX_CHAINS];
  433. u8 radio_write;
  434. u8 state;
  435. };
  436. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  437. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  438. enum {
  439. MEASUREMENT_READY = (1 << 0),
  440. MEASUREMENT_ACTIVE = (1 << 1),
  441. };
  442. enum iwl_nvm_type {
  443. NVM_DEVICE_TYPE_EEPROM = 0,
  444. NVM_DEVICE_TYPE_OTP,
  445. };
  446. /*
  447. * Two types of OTP memory access modes
  448. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  449. * based on physical memory addressing
  450. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  451. * based on logical memory addressing
  452. */
  453. enum iwl_access_mode {
  454. IWL_OTP_ACCESS_ABSOLUTE,
  455. IWL_OTP_ACCESS_RELATIVE,
  456. };
  457. /**
  458. * enum iwl_pa_type - Power Amplifier type
  459. * @IWL_PA_SYSTEM: based on uCode configuration
  460. * @IWL_PA_INTERNAL: use Internal only
  461. */
  462. enum iwl_pa_type {
  463. IWL_PA_SYSTEM = 0,
  464. IWL_PA_INTERNAL = 1,
  465. };
  466. /* reply_tx_statistics (for _agn devices) */
  467. struct reply_tx_error_statistics {
  468. u32 pp_delay;
  469. u32 pp_few_bytes;
  470. u32 pp_bt_prio;
  471. u32 pp_quiet_period;
  472. u32 pp_calc_ttak;
  473. u32 int_crossed_retry;
  474. u32 short_limit;
  475. u32 long_limit;
  476. u32 fifo_underrun;
  477. u32 drain_flow;
  478. u32 rfkill_flush;
  479. u32 life_expire;
  480. u32 dest_ps;
  481. u32 host_abort;
  482. u32 bt_retry;
  483. u32 sta_invalid;
  484. u32 frag_drop;
  485. u32 tid_disable;
  486. u32 fifo_flush;
  487. u32 insuff_cf_poll;
  488. u32 fail_hw_drop;
  489. u32 sta_color_mismatch;
  490. u32 unknown;
  491. };
  492. /* reply_agg_tx_statistics (for _agn devices) */
  493. struct reply_agg_tx_error_statistics {
  494. u32 underrun;
  495. u32 bt_prio;
  496. u32 few_bytes;
  497. u32 abort;
  498. u32 last_sent_ttl;
  499. u32 last_sent_try;
  500. u32 last_sent_bt_kill;
  501. u32 scd_query;
  502. u32 bad_crc32;
  503. u32 response;
  504. u32 dump_tx;
  505. u32 delay_tx;
  506. u32 unknown;
  507. };
  508. /* management statistics */
  509. enum iwl_mgmt_stats {
  510. MANAGEMENT_ASSOC_REQ = 0,
  511. MANAGEMENT_ASSOC_RESP,
  512. MANAGEMENT_REASSOC_REQ,
  513. MANAGEMENT_REASSOC_RESP,
  514. MANAGEMENT_PROBE_REQ,
  515. MANAGEMENT_PROBE_RESP,
  516. MANAGEMENT_BEACON,
  517. MANAGEMENT_ATIM,
  518. MANAGEMENT_DISASSOC,
  519. MANAGEMENT_AUTH,
  520. MANAGEMENT_DEAUTH,
  521. MANAGEMENT_ACTION,
  522. MANAGEMENT_MAX,
  523. };
  524. /* control statistics */
  525. enum iwl_ctrl_stats {
  526. CONTROL_BACK_REQ = 0,
  527. CONTROL_BACK,
  528. CONTROL_PSPOLL,
  529. CONTROL_RTS,
  530. CONTROL_CTS,
  531. CONTROL_ACK,
  532. CONTROL_CFEND,
  533. CONTROL_CFENDACK,
  534. CONTROL_MAX,
  535. };
  536. struct traffic_stats {
  537. #ifdef CONFIG_IWLWIFI_DEBUGFS
  538. u32 mgmt[MANAGEMENT_MAX];
  539. u32 ctrl[CONTROL_MAX];
  540. u32 data_cnt;
  541. u64 data_bytes;
  542. #endif
  543. };
  544. /*
  545. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  546. * to perform continuous uCode event logging operation if enabled
  547. */
  548. #define UCODE_TRACE_PERIOD (100)
  549. /*
  550. * iwl_event_log: current uCode event log position
  551. *
  552. * @ucode_trace: enable/disable ucode continuous trace timer
  553. * @num_wraps: how many times the event buffer wraps
  554. * @next_entry: the entry just before the next one that uCode would fill
  555. * @non_wraps_count: counter for no wrap detected when dump ucode events
  556. * @wraps_once_count: counter for wrap once detected when dump ucode events
  557. * @wraps_more_count: counter for wrap more than once detected
  558. * when dump ucode events
  559. */
  560. struct iwl_event_log {
  561. bool ucode_trace;
  562. u32 num_wraps;
  563. u32 next_entry;
  564. int non_wraps_count;
  565. int wraps_once_count;
  566. int wraps_more_count;
  567. };
  568. /*
  569. * This is the threshold value of plcp error rate per 100mSecs. It is
  570. * used to set and check for the validity of plcp_delta.
  571. */
  572. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  573. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  574. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  575. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  576. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  577. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  578. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  579. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  580. /* TX queue watchdog timeouts in mSecs */
  581. #define IWL_DEF_WD_TIMEOUT (2000)
  582. #define IWL_LONG_WD_TIMEOUT (10000)
  583. #define IWL_MAX_WD_TIMEOUT (120000)
  584. /* BT Antenna Coupling Threshold (dB) */
  585. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  586. /* Firmware reload counter and Timestamp */
  587. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  588. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  589. enum iwl_reset {
  590. IWL_RF_RESET = 0,
  591. IWL_FW_RESET,
  592. IWL_MAX_FORCE_RESET,
  593. };
  594. struct iwl_force_reset {
  595. int reset_request_count;
  596. int reset_success_count;
  597. int reset_reject_count;
  598. unsigned long reset_duration;
  599. unsigned long last_force_reset_jiffies;
  600. };
  601. /* extend beacon time format bit shifting */
  602. /*
  603. * for _agn devices
  604. * bits 31:22 - extended
  605. * bits 21:0 - interval
  606. */
  607. #define IWLAGN_EXT_BEACON_TIME_POS 22
  608. /**
  609. * struct iwl_notification_wait - notification wait entry
  610. * @list: list head for global list
  611. * @fn: function called with the notification
  612. * @cmd: command ID
  613. *
  614. * This structure is not used directly, to wait for a
  615. * notification declare it on the stack, and call
  616. * iwlagn_init_notification_wait() with appropriate
  617. * parameters. Then do whatever will cause the ucode
  618. * to notify the driver, and to wait for that then
  619. * call iwlagn_wait_notification().
  620. *
  621. * Each notification is one-shot. If at some point we
  622. * need to support multi-shot notifications (which
  623. * can't be allocated on the stack) we need to modify
  624. * the code for them.
  625. */
  626. struct iwl_notification_wait {
  627. struct list_head list;
  628. void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
  629. void *data);
  630. void *fn_data;
  631. u8 cmd;
  632. bool triggered, aborted;
  633. };
  634. struct iwl_rxon_context {
  635. struct ieee80211_vif *vif;
  636. /*
  637. * We could use the vif to indicate active, but we
  638. * also need it to be active during disabling when
  639. * we already removed the vif for type setting.
  640. */
  641. bool always_active, is_active;
  642. bool ht_need_multiple_chains;
  643. enum iwl_rxon_context_id ctxid;
  644. u32 interface_modes, exclusive_interface_modes;
  645. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  646. /*
  647. * We declare this const so it can only be
  648. * changed via explicit cast within the
  649. * routines that actually update the physical
  650. * hardware.
  651. */
  652. const struct iwl_rxon_cmd active;
  653. struct iwl_rxon_cmd staging;
  654. struct iwl_rxon_time_cmd timing;
  655. struct iwl_qos_info qos_data;
  656. u8 bcast_sta_id, ap_sta_id;
  657. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  658. u8 qos_cmd;
  659. u8 wep_key_cmd;
  660. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  661. u8 key_mapping_keys;
  662. __le32 station_flags;
  663. int beacon_int;
  664. struct {
  665. bool non_gf_sta_present;
  666. u8 protection;
  667. bool enabled, is_40mhz;
  668. u8 extension_chan_offset;
  669. } ht;
  670. u8 bssid[ETH_ALEN];
  671. bool preauth_bssid;
  672. bool last_tx_rejected;
  673. };
  674. enum iwl_scan_type {
  675. IWL_SCAN_NORMAL,
  676. IWL_SCAN_RADIO_RESET,
  677. IWL_SCAN_ROC,
  678. };
  679. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  680. struct iwl_testmode_trace {
  681. u32 buff_size;
  682. u32 total_size;
  683. u32 num_chunks;
  684. u8 *cpu_addr;
  685. u8 *trace_addr;
  686. dma_addr_t dma_addr;
  687. bool trace_enabled;
  688. };
  689. struct iwl_testmode_sram {
  690. u32 buff_size;
  691. u32 num_chunks;
  692. u8 *buff_addr;
  693. bool sram_readed;
  694. };
  695. #endif
  696. struct iwl_wipan_noa_data {
  697. struct rcu_head rcu_head;
  698. u32 length;
  699. u8 data[];
  700. };
  701. struct iwl_priv {
  702. /*data shared among all the driver's layers */
  703. struct iwl_shared _shrd;
  704. struct iwl_shared *shrd;
  705. /* ieee device used by generic ieee processing code */
  706. struct ieee80211_hw *hw;
  707. struct ieee80211_channel *ieee_channels;
  708. struct ieee80211_rate *ieee_rates;
  709. struct kmem_cache *tx_cmd_pool;
  710. struct iwl_cfg *cfg;
  711. enum ieee80211_band band;
  712. void (*pre_rx_handler)(struct iwl_priv *priv,
  713. struct iwl_rx_mem_buffer *rxb);
  714. int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  715. struct iwl_rx_mem_buffer *rxb,
  716. struct iwl_device_cmd *cmd);
  717. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  718. /* spectrum measurement report caching */
  719. struct iwl_spectrum_notification measure_report;
  720. u8 measurement_status;
  721. /* ucode beacon time */
  722. u32 ucode_beacon_time;
  723. int missed_beacon_threshold;
  724. /* track IBSS manager (last beacon) status */
  725. u32 ibss_manager;
  726. /* jiffies when last recovery from statistics was performed */
  727. unsigned long rx_statistics_jiffies;
  728. /*counters */
  729. u32 rx_handlers_stats[REPLY_MAX];
  730. /* force reset */
  731. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  732. /* firmware reload counter and timestamp */
  733. unsigned long reload_jiffies;
  734. int reload_count;
  735. /* we allocate array of iwl_channel_info for NIC's valid channels.
  736. * Access via channel # using indirect index array */
  737. struct iwl_channel_info *channel_info; /* channel info array */
  738. u8 channel_count; /* # of channels */
  739. /* thermal calibration */
  740. s32 temperature; /* Celsius */
  741. s32 last_temperature;
  742. /* init calibration results */
  743. struct list_head calib_results;
  744. struct iwl_wipan_noa_data __rcu *noa_data;
  745. /* Scan related variables */
  746. unsigned long scan_start;
  747. unsigned long scan_start_tsf;
  748. void *scan_cmd;
  749. enum ieee80211_band scan_band;
  750. struct cfg80211_scan_request *scan_request;
  751. struct ieee80211_vif *scan_vif;
  752. enum iwl_scan_type scan_type;
  753. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  754. u8 mgmt_tx_ant;
  755. /* max number of station keys */
  756. u8 sta_key_max_num;
  757. bool new_scan_threshold_behaviour;
  758. /* EEPROM MAC addresses */
  759. struct mac_address addresses[2];
  760. /* uCode images, save to reload in case of failure */
  761. int fw_index; /* firmware we're trying to load */
  762. u32 ucode_ver; /* version of ucode, copy of
  763. iwl_ucode.ver */
  764. enum iwl_ucode_type ucode_type;
  765. char firmware_name[25];
  766. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  767. __le16 switch_channel;
  768. struct {
  769. u32 error_event_table;
  770. u32 log_event_table;
  771. } device_pointers;
  772. u16 active_rate;
  773. u8 start_calib;
  774. struct iwl_sensitivity_data sensitivity_data;
  775. struct iwl_chain_noise_data chain_noise_data;
  776. bool enhance_sensitivity_table;
  777. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  778. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  779. struct iwl_ht_config current_ht_config;
  780. /* Rate scaling data */
  781. u8 retry_rate;
  782. int activity_timer_active;
  783. /* counts mgmt, ctl, and data packets */
  784. struct traffic_stats tx_stats;
  785. struct traffic_stats rx_stats;
  786. struct iwl_power_mgr power_data;
  787. struct iwl_tt_mgmt thermal_throttle;
  788. /* station table variables */
  789. int num_stations;
  790. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  791. unsigned long ucode_key_table;
  792. u8 mac80211_registered;
  793. /* Indication if ieee80211_ops->open has been called */
  794. u8 is_open;
  795. /* eeprom -- this is in the card's little endian byte order */
  796. u8 *eeprom;
  797. struct iwl_eeprom_calib_info *calib_info;
  798. enum nl80211_iftype iw_mode;
  799. /* Last Rx'd beacon timestamp */
  800. u64 timestamp;
  801. struct {
  802. __le32 flag;
  803. struct statistics_general_common common;
  804. struct statistics_rx_non_phy rx_non_phy;
  805. struct statistics_rx_phy rx_ofdm;
  806. struct statistics_rx_ht_phy rx_ofdm_ht;
  807. struct statistics_rx_phy rx_cck;
  808. struct statistics_tx tx;
  809. #ifdef CONFIG_IWLWIFI_DEBUGFS
  810. struct statistics_bt_activity bt_activity;
  811. __le32 num_bt_kills, accum_num_bt_kills;
  812. #endif
  813. } statistics;
  814. #ifdef CONFIG_IWLWIFI_DEBUGFS
  815. struct {
  816. struct statistics_general_common common;
  817. struct statistics_rx_non_phy rx_non_phy;
  818. struct statistics_rx_phy rx_ofdm;
  819. struct statistics_rx_ht_phy rx_ofdm_ht;
  820. struct statistics_rx_phy rx_cck;
  821. struct statistics_tx tx;
  822. struct statistics_bt_activity bt_activity;
  823. } accum_stats, delta_stats, max_delta_stats;
  824. #endif
  825. /*
  826. * reporting the number of tids has AGG on. 0 means
  827. * no AGGREGATION
  828. */
  829. u8 agg_tids_count;
  830. struct iwl_rx_phy_res last_phy_res;
  831. bool last_phy_res_valid;
  832. struct completion firmware_loading_complete;
  833. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  834. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  835. /*
  836. * chain noise reset and gain commands are the
  837. * two extra calibration commands follows the standard
  838. * phy calibration commands
  839. */
  840. u8 phy_calib_chain_noise_reset_cmd;
  841. u8 phy_calib_chain_noise_gain_cmd;
  842. /* counts reply_tx error */
  843. struct reply_tx_error_statistics reply_tx_stats;
  844. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  845. /* notification wait support */
  846. struct list_head notif_waits;
  847. spinlock_t notif_wait_lock;
  848. wait_queue_head_t notif_waitq;
  849. /* remain-on-channel offload support */
  850. struct ieee80211_channel *hw_roc_channel;
  851. struct delayed_work hw_roc_disable_work;
  852. enum nl80211_channel_type hw_roc_chantype;
  853. int hw_roc_duration;
  854. bool hw_roc_setup, hw_roc_start_notified;
  855. /* bt coex */
  856. u8 bt_enable_flag;
  857. u8 bt_status;
  858. u8 bt_traffic_load, last_bt_traffic_load;
  859. bool bt_ch_announce;
  860. bool bt_full_concurrent;
  861. bool bt_ant_couple_ok;
  862. __le32 kill_ack_mask;
  863. __le32 kill_cts_mask;
  864. __le16 bt_valid;
  865. u16 bt_on_thresh;
  866. u16 bt_duration;
  867. u16 dynamic_frag_thresh;
  868. u8 bt_ci_compliance;
  869. struct work_struct bt_traffic_change_work;
  870. bool bt_enable_pspoll;
  871. struct iwl_rxon_context *cur_rssi_ctx;
  872. bool bt_is_sco;
  873. struct work_struct restart;
  874. struct work_struct scan_completed;
  875. struct work_struct abort_scan;
  876. struct work_struct beacon_update;
  877. struct iwl_rxon_context *beacon_ctx;
  878. struct sk_buff *beacon_skb;
  879. void *beacon_cmd;
  880. struct work_struct tt_work;
  881. struct work_struct ct_enter;
  882. struct work_struct ct_exit;
  883. struct work_struct start_internal_scan;
  884. struct work_struct tx_flush;
  885. struct work_struct bt_full_concurrency;
  886. struct work_struct bt_runtime_config;
  887. struct delayed_work scan_check;
  888. /* TX Power */
  889. s8 tx_power_user_lmt;
  890. s8 tx_power_device_lmt;
  891. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  892. s8 tx_power_next;
  893. #ifdef CONFIG_IWLWIFI_DEBUGFS
  894. /* debugfs */
  895. u16 tx_traffic_idx;
  896. u16 rx_traffic_idx;
  897. u8 *tx_traffic;
  898. u8 *rx_traffic;
  899. struct dentry *debugfs_dir;
  900. u32 dbgfs_sram_offset, dbgfs_sram_len;
  901. bool disable_ht40;
  902. void *wowlan_sram;
  903. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  904. struct work_struct txpower_work;
  905. u32 disable_sens_cal;
  906. u32 disable_chain_noise_cal;
  907. struct work_struct run_time_calib_work;
  908. struct timer_list statistics_periodic;
  909. struct timer_list ucode_trace;
  910. struct timer_list watchdog;
  911. struct iwl_event_log event_log;
  912. struct led_classdev led;
  913. unsigned long blink_on, blink_off;
  914. bool led_registered;
  915. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  916. struct iwl_testmode_trace testmode_trace;
  917. struct iwl_testmode_sram testmode_sram;
  918. u32 tm_fixed_rate;
  919. #endif
  920. /* WoWLAN GTK rekey data */
  921. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  922. __le64 replay_ctr;
  923. __le16 last_seq_ctl;
  924. bool have_rekey_data;
  925. }; /*iwl_priv */
  926. extern struct iwl_mod_params iwlagn_mod_params;
  927. static inline struct iwl_rxon_context *
  928. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  929. {
  930. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  931. return vif_priv->ctx;
  932. }
  933. #define for_each_context(priv, ctx) \
  934. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  935. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  936. if (priv->shrd->valid_contexts & BIT(ctx->ctxid))
  937. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  938. {
  939. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  940. }
  941. static inline int iwl_is_associated(struct iwl_priv *priv,
  942. enum iwl_rxon_context_id ctxid)
  943. {
  944. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  945. }
  946. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  947. {
  948. struct iwl_rxon_context *ctx;
  949. for_each_context(priv, ctx)
  950. if (iwl_is_associated_ctx(ctx))
  951. return true;
  952. return false;
  953. }
  954. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  955. {
  956. if (ch_info == NULL)
  957. return 0;
  958. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  959. }
  960. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  961. {
  962. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  963. }
  964. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  965. {
  966. return ch_info->band == IEEE80211_BAND_5GHZ;
  967. }
  968. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  969. {
  970. return ch_info->band == IEEE80211_BAND_2GHZ;
  971. }
  972. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  973. {
  974. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  975. }
  976. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  977. {
  978. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  979. }
  980. #endif /* __iwl_dev_h__ */