iwl-dev.h 29 KB

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