iwl-dev.h 27 KB

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