dev.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2013 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 (dev.h) for driver implementation definitions.
  28. * Please use 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-fw.h"
  39. #include "iwl-eeprom-parse.h"
  40. #include "iwl-csr.h"
  41. #include "iwl-debug.h"
  42. #include "iwl-agn-hw.h"
  43. #include "iwl-op-mode.h"
  44. #include "iwl-notif-wait.h"
  45. #include "iwl-trans.h"
  46. #include "led.h"
  47. #include "power.h"
  48. #include "rs.h"
  49. #include "tt.h"
  50. #include "iwl-test.h"
  51. /* CT-KILL constants */
  52. #define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
  53. #define CT_KILL_THRESHOLD 114 /* in Celsius */
  54. #define CT_KILL_EXIT_THRESHOLD 95 /* in Celsius */
  55. /* Default noise level to report when noise measurement is not available.
  56. * This may be because we're:
  57. * 1) Not associated no beacon statistics being sent to driver)
  58. * 2) Scanning (noise measurement does not apply to associated channel)
  59. * Use default noise value of -127 ... this is below the range of measurable
  60. * Rx dBm for all agn devices, so it can indicate "unmeasurable" to user.
  61. * Also, -127 works better than 0 when averaging frames with/without
  62. * noise info (e.g. averaging might be done in app); measured dBm values are
  63. * always negative ... using a negative value as the default keeps all
  64. * averages within an s8's (used in some apps) range of negative values. */
  65. #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
  66. /*
  67. * RTS threshold here is total size [2347] minus 4 FCS bytes
  68. * Per spec:
  69. * a value of 0 means RTS on all data/management packets
  70. * a value > max MSDU size means no RTS
  71. * else RTS for data/management frames where MPDU is larger
  72. * than RTS value.
  73. */
  74. #define DEFAULT_RTS_THRESHOLD 2347U
  75. #define MIN_RTS_THRESHOLD 0U
  76. #define MAX_RTS_THRESHOLD 2347U
  77. #define MAX_MSDU_SIZE 2304U
  78. #define MAX_MPDU_SIZE 2346U
  79. #define DEFAULT_BEACON_INTERVAL 200U
  80. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  81. #define DEFAULT_LONG_RETRY_LIMIT 4U
  82. #define IWL_NUM_SCAN_RATES (2)
  83. #define IEEE80211_DATA_LEN 2304
  84. #define IEEE80211_4ADDR_LEN 30
  85. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  86. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  87. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  88. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  89. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  90. #define IWL_SUPPORTED_RATES_IE_LEN 8
  91. #define IWL_INVALID_RATE 0xFF
  92. #define IWL_INVALID_VALUE -1
  93. union iwl_ht_rate_supp {
  94. u16 rates;
  95. struct {
  96. u8 siso_rate;
  97. u8 mimo_rate;
  98. };
  99. };
  100. struct iwl_ht_config {
  101. bool single_chain_sufficient;
  102. enum ieee80211_smps_mode smps; /* current smps mode */
  103. };
  104. /* QoS structures */
  105. struct iwl_qos_info {
  106. int qos_active;
  107. struct iwl_qosparam_cmd def_qos_parm;
  108. };
  109. /**
  110. * enum iwl_agg_state
  111. *
  112. * The state machine of the BA agreement establishment / tear down.
  113. * These states relate to a specific RA / TID.
  114. *
  115. * @IWL_AGG_OFF: aggregation is not used
  116. * @IWL_AGG_STARTING: aggregation are starting (between start and oper)
  117. * @IWL_AGG_ON: aggregation session is up
  118. * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
  119. * HW queue to be empty from packets for this RA /TID.
  120. * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
  121. * HW queue to be empty from packets for this RA /TID.
  122. */
  123. enum iwl_agg_state {
  124. IWL_AGG_OFF = 0,
  125. IWL_AGG_STARTING,
  126. IWL_AGG_ON,
  127. IWL_EMPTYING_HW_QUEUE_ADDBA,
  128. IWL_EMPTYING_HW_QUEUE_DELBA,
  129. };
  130. /**
  131. * struct iwl_ht_agg - aggregation state machine
  132. * This structs holds the states for the BA agreement establishment and tear
  133. * down. It also holds the state during the BA session itself. This struct is
  134. * duplicated for each RA / TID.
  135. * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
  136. * Tx response (REPLY_TX), and the block ack notification
  137. * (REPLY_COMPRESSED_BA).
  138. * @state: state of the BA agreement establishment / tear down.
  139. * @txq_id: Tx queue used by the BA session
  140. * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
  141. * the first packet to be sent in legacy HW queue in Tx AGG stop flow.
  142. * Basically when next_reclaimed reaches ssn, we can tell mac80211 that
  143. * we are ready to finish the Tx AGG stop / start flow.
  144. * @wait_for_ba: Expect block-ack before next Tx reply
  145. */
  146. struct iwl_ht_agg {
  147. u32 rate_n_flags;
  148. enum iwl_agg_state state;
  149. u16 txq_id;
  150. u16 ssn;
  151. bool wait_for_ba;
  152. };
  153. /**
  154. * struct iwl_tid_data - one for each RA / TID
  155. * This structs holds the states for each RA / TID.
  156. * @seq_number: the next WiFi sequence number to use
  157. * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
  158. * This is basically (last acked packet++).
  159. * @agg: aggregation state machine
  160. */
  161. struct iwl_tid_data {
  162. u16 seq_number;
  163. u16 next_reclaimed;
  164. struct iwl_ht_agg agg;
  165. };
  166. /*
  167. * Structure should be accessed with sta_lock held. When station addition
  168. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  169. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  170. * held.
  171. */
  172. struct iwl_station_entry {
  173. struct iwl_addsta_cmd sta;
  174. u8 used, ctxid;
  175. struct iwl_link_quality_cmd *lq;
  176. };
  177. /*
  178. * iwl_station_priv: Driver's private station information
  179. *
  180. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  181. * in the structure for use by driver. This structure is places in that
  182. * space.
  183. */
  184. struct iwl_station_priv {
  185. struct iwl_rxon_context *ctx;
  186. struct iwl_lq_sta lq_sta;
  187. atomic_t pending_frames;
  188. bool client;
  189. bool asleep;
  190. u8 max_agg_bufsize;
  191. u8 sta_id;
  192. };
  193. /**
  194. * struct iwl_vif_priv - driver's private per-interface information
  195. *
  196. * When mac80211 allocates a virtual interface, it can allocate
  197. * space for us to put data into.
  198. */
  199. struct iwl_vif_priv {
  200. struct iwl_rxon_context *ctx;
  201. u8 ibss_bssid_sta_id;
  202. };
  203. struct iwl_sensitivity_ranges {
  204. u16 min_nrg_cck;
  205. u16 nrg_th_cck;
  206. u16 nrg_th_ofdm;
  207. u16 auto_corr_min_ofdm;
  208. u16 auto_corr_min_ofdm_mrc;
  209. u16 auto_corr_min_ofdm_x1;
  210. u16 auto_corr_min_ofdm_mrc_x1;
  211. u16 auto_corr_max_ofdm;
  212. u16 auto_corr_max_ofdm_mrc;
  213. u16 auto_corr_max_ofdm_x1;
  214. u16 auto_corr_max_ofdm_mrc_x1;
  215. u16 auto_corr_max_cck;
  216. u16 auto_corr_max_cck_mrc;
  217. u16 auto_corr_min_cck;
  218. u16 auto_corr_min_cck_mrc;
  219. u16 barker_corr_th_min;
  220. u16 barker_corr_th_min_mrc;
  221. u16 nrg_th_cca;
  222. };
  223. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  224. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  225. /******************************************************************************
  226. *
  227. * Functions implemented in core module which are forward declared here
  228. * for use by iwl-[4-5].c
  229. *
  230. * NOTE: The implementation of these functions are not hardware specific
  231. * which is why they are in the core module files.
  232. *
  233. * Naming convention --
  234. * iwl_ <-- Is part of iwlwifi
  235. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  236. *
  237. ****************************************************************************/
  238. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  239. extern const u8 iwl_bcast_addr[ETH_ALEN];
  240. #define IWL_OPERATION_MODE_AUTO 0
  241. #define IWL_OPERATION_MODE_HT_ONLY 1
  242. #define IWL_OPERATION_MODE_MIXED 2
  243. #define IWL_OPERATION_MODE_20MHZ 3
  244. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  245. /* Sensitivity and chain noise calibration */
  246. #define INITIALIZATION_VALUE 0xFFFF
  247. #define IWL_CAL_NUM_BEACONS 16
  248. #define MAXIMUM_ALLOWED_PATHLOSS 15
  249. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  250. #define MAX_FA_OFDM 50
  251. #define MIN_FA_OFDM 5
  252. #define MAX_FA_CCK 50
  253. #define MIN_FA_CCK 5
  254. #define AUTO_CORR_STEP_OFDM 1
  255. #define AUTO_CORR_STEP_CCK 3
  256. #define AUTO_CORR_MAX_TH_CCK 160
  257. #define NRG_DIFF 2
  258. #define NRG_STEP_CCK 2
  259. #define NRG_MARGIN 8
  260. #define MAX_NUMBER_CCK_NO_FA 100
  261. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  262. #define CHAIN_A 0
  263. #define CHAIN_B 1
  264. #define CHAIN_C 2
  265. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  266. #define ALL_BAND_FILTER 0xFF00
  267. #define IN_BAND_FILTER 0xFF
  268. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  269. #define NRG_NUM_PREV_STAT_L 20
  270. #define NUM_RX_CHAINS 3
  271. enum iwlagn_false_alarm_state {
  272. IWL_FA_TOO_MANY = 0,
  273. IWL_FA_TOO_FEW = 1,
  274. IWL_FA_GOOD_RANGE = 2,
  275. };
  276. enum iwlagn_chain_noise_state {
  277. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  278. IWL_CHAIN_NOISE_ACCUMULATE,
  279. IWL_CHAIN_NOISE_CALIBRATED,
  280. IWL_CHAIN_NOISE_DONE,
  281. };
  282. /* Sensitivity calib data */
  283. struct iwl_sensitivity_data {
  284. u32 auto_corr_ofdm;
  285. u32 auto_corr_ofdm_mrc;
  286. u32 auto_corr_ofdm_x1;
  287. u32 auto_corr_ofdm_mrc_x1;
  288. u32 auto_corr_cck;
  289. u32 auto_corr_cck_mrc;
  290. u32 last_bad_plcp_cnt_ofdm;
  291. u32 last_fa_cnt_ofdm;
  292. u32 last_bad_plcp_cnt_cck;
  293. u32 last_fa_cnt_cck;
  294. u32 nrg_curr_state;
  295. u32 nrg_prev_state;
  296. u32 nrg_value[10];
  297. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  298. u32 nrg_silence_ref;
  299. u32 nrg_energy_idx;
  300. u32 nrg_silence_idx;
  301. u32 nrg_th_cck;
  302. s32 nrg_auto_corr_silence_diff;
  303. u32 num_in_cck_no_fa;
  304. u32 nrg_th_ofdm;
  305. u16 barker_corr_th_min;
  306. u16 barker_corr_th_min_mrc;
  307. u16 nrg_th_cca;
  308. };
  309. /* Chain noise (differential Rx gain) calib data */
  310. struct iwl_chain_noise_data {
  311. u32 active_chains;
  312. u32 chain_noise_a;
  313. u32 chain_noise_b;
  314. u32 chain_noise_c;
  315. u32 chain_signal_a;
  316. u32 chain_signal_b;
  317. u32 chain_signal_c;
  318. u16 beacon_count;
  319. u8 disconn_array[NUM_RX_CHAINS];
  320. u8 delta_gain_code[NUM_RX_CHAINS];
  321. u8 radio_write;
  322. u8 state;
  323. };
  324. enum {
  325. MEASUREMENT_READY = (1 << 0),
  326. MEASUREMENT_ACTIVE = (1 << 1),
  327. };
  328. /* reply_tx_statistics (for _agn devices) */
  329. struct reply_tx_error_statistics {
  330. u32 pp_delay;
  331. u32 pp_few_bytes;
  332. u32 pp_bt_prio;
  333. u32 pp_quiet_period;
  334. u32 pp_calc_ttak;
  335. u32 int_crossed_retry;
  336. u32 short_limit;
  337. u32 long_limit;
  338. u32 fifo_underrun;
  339. u32 drain_flow;
  340. u32 rfkill_flush;
  341. u32 life_expire;
  342. u32 dest_ps;
  343. u32 host_abort;
  344. u32 bt_retry;
  345. u32 sta_invalid;
  346. u32 frag_drop;
  347. u32 tid_disable;
  348. u32 fifo_flush;
  349. u32 insuff_cf_poll;
  350. u32 fail_hw_drop;
  351. u32 sta_color_mismatch;
  352. u32 unknown;
  353. };
  354. /* reply_agg_tx_statistics (for _agn devices) */
  355. struct reply_agg_tx_error_statistics {
  356. u32 underrun;
  357. u32 bt_prio;
  358. u32 few_bytes;
  359. u32 abort;
  360. u32 last_sent_ttl;
  361. u32 last_sent_try;
  362. u32 last_sent_bt_kill;
  363. u32 scd_query;
  364. u32 bad_crc32;
  365. u32 response;
  366. u32 dump_tx;
  367. u32 delay_tx;
  368. u32 unknown;
  369. };
  370. /*
  371. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  372. * to perform continuous uCode event logging operation if enabled
  373. */
  374. #define UCODE_TRACE_PERIOD (10)
  375. /*
  376. * iwl_event_log: current uCode event log position
  377. *
  378. * @ucode_trace: enable/disable ucode continuous trace timer
  379. * @num_wraps: how many times the event buffer wraps
  380. * @next_entry: the entry just before the next one that uCode would fill
  381. * @non_wraps_count: counter for no wrap detected when dump ucode events
  382. * @wraps_once_count: counter for wrap once detected when dump ucode events
  383. * @wraps_more_count: counter for wrap more than once detected
  384. * when dump ucode events
  385. */
  386. struct iwl_event_log {
  387. bool ucode_trace;
  388. u32 num_wraps;
  389. u32 next_entry;
  390. int non_wraps_count;
  391. int wraps_once_count;
  392. int wraps_more_count;
  393. };
  394. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  395. /* BT Antenna Coupling Threshold (dB) */
  396. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  397. /* Firmware reload counter and Timestamp */
  398. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  399. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  400. struct iwl_rf_reset {
  401. int reset_request_count;
  402. int reset_success_count;
  403. int reset_reject_count;
  404. unsigned long last_reset_jiffies;
  405. };
  406. enum iwl_rxon_context_id {
  407. IWL_RXON_CTX_BSS,
  408. IWL_RXON_CTX_PAN,
  409. NUM_IWL_RXON_CTX
  410. };
  411. /* extend beacon time format bit shifting */
  412. /*
  413. * for _agn devices
  414. * bits 31:22 - extended
  415. * bits 21:0 - interval
  416. */
  417. #define IWLAGN_EXT_BEACON_TIME_POS 22
  418. struct iwl_rxon_context {
  419. struct ieee80211_vif *vif;
  420. u8 mcast_queue;
  421. u8 ac_to_queue[IEEE80211_NUM_ACS];
  422. u8 ac_to_fifo[IEEE80211_NUM_ACS];
  423. /*
  424. * We could use the vif to indicate active, but we
  425. * also need it to be active during disabling when
  426. * we already removed the vif for type setting.
  427. */
  428. bool always_active, is_active;
  429. bool ht_need_multiple_chains;
  430. enum iwl_rxon_context_id ctxid;
  431. u32 interface_modes, exclusive_interface_modes;
  432. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  433. /*
  434. * We declare this const so it can only be
  435. * changed via explicit cast within the
  436. * routines that actually update the physical
  437. * hardware.
  438. */
  439. const struct iwl_rxon_cmd active;
  440. struct iwl_rxon_cmd staging;
  441. struct iwl_rxon_time_cmd timing;
  442. struct iwl_qos_info qos_data;
  443. u8 bcast_sta_id, ap_sta_id;
  444. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  445. u8 qos_cmd;
  446. u8 wep_key_cmd;
  447. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  448. u8 key_mapping_keys;
  449. __le32 station_flags;
  450. int beacon_int;
  451. struct {
  452. bool non_gf_sta_present;
  453. u8 protection;
  454. bool enabled, is_40mhz;
  455. u8 extension_chan_offset;
  456. } ht;
  457. };
  458. enum iwl_scan_type {
  459. IWL_SCAN_NORMAL,
  460. IWL_SCAN_RADIO_RESET,
  461. IWL_SCAN_ROC,
  462. };
  463. /**
  464. * struct iwl_hw_params
  465. *
  466. * Holds the module parameters
  467. *
  468. * @tx_chains_num: Number of TX chains
  469. * @rx_chains_num: Number of RX chains
  470. * @ct_kill_threshold: temperature threshold - in hw dependent unit
  471. * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
  472. * relevant for 1000, 6000 and up
  473. * @struct iwl_sensitivity_ranges: range of sensitivity values
  474. * @use_rts_for_aggregation: use rts/cts protection for HT traffic
  475. */
  476. struct iwl_hw_params {
  477. u8 tx_chains_num;
  478. u8 rx_chains_num;
  479. bool use_rts_for_aggregation;
  480. u32 ct_kill_threshold;
  481. u32 ct_kill_exit_threshold;
  482. const struct iwl_sensitivity_ranges *sens;
  483. };
  484. struct iwl_lib_ops {
  485. /* set hw dependent parameters */
  486. void (*set_hw_params)(struct iwl_priv *priv);
  487. int (*set_channel_switch)(struct iwl_priv *priv,
  488. struct ieee80211_channel_switch *ch_switch);
  489. /* device specific configuration */
  490. void (*nic_config)(struct iwl_priv *priv);
  491. /* temperature */
  492. void (*temperature)(struct iwl_priv *priv);
  493. };
  494. struct iwl_wipan_noa_data {
  495. struct rcu_head rcu_head;
  496. u32 length;
  497. u8 data[];
  498. };
  499. /* Calibration disabling bit mask */
  500. enum {
  501. IWL_CALIB_ENABLE_ALL = 0,
  502. IWL_SENSITIVITY_CALIB_DISABLED = BIT(0),
  503. IWL_CHAIN_NOISE_CALIB_DISABLED = BIT(1),
  504. IWL_TX_POWER_CALIB_DISABLED = BIT(2),
  505. IWL_CALIB_DISABLE_ALL = 0xFFFFFFFF,
  506. };
  507. #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
  508. ((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
  509. #define IWL_MAC80211_GET_DVM(_hw) \
  510. ((struct iwl_priv *) ((struct iwl_op_mode *) \
  511. (_hw)->priv)->op_mode_specific)
  512. struct iwl_priv {
  513. struct iwl_trans *trans;
  514. struct device *dev; /* for debug prints only */
  515. const struct iwl_cfg *cfg;
  516. const struct iwl_fw *fw;
  517. const struct iwl_lib_ops *lib;
  518. unsigned long status;
  519. spinlock_t sta_lock;
  520. struct mutex mutex;
  521. unsigned long transport_queue_stop;
  522. bool passive_no_rx;
  523. #define IWL_INVALID_MAC80211_QUEUE 0xff
  524. u8 queue_to_mac80211[IWL_MAX_HW_QUEUES];
  525. atomic_t queue_stop_count[IWL_MAX_HW_QUEUES];
  526. unsigned long agg_q_alloc[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  527. /* ieee device used by generic ieee processing code */
  528. struct ieee80211_hw *hw;
  529. struct list_head calib_results;
  530. struct workqueue_struct *workqueue;
  531. struct iwl_hw_params hw_params;
  532. enum ieee80211_band band;
  533. u8 valid_contexts;
  534. int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  535. struct iwl_rx_cmd_buffer *rxb,
  536. struct iwl_device_cmd *cmd);
  537. struct iwl_notif_wait_data notif_wait;
  538. /* spectrum measurement report caching */
  539. struct iwl_spectrum_notification measure_report;
  540. u8 measurement_status;
  541. #define IWL_OWNERSHIP_DRIVER 0
  542. #define IWL_OWNERSHIP_TM 1
  543. u8 ucode_owner;
  544. /* ucode beacon time */
  545. u32 ucode_beacon_time;
  546. int missed_beacon_threshold;
  547. /* track IBSS manager (last beacon) status */
  548. u32 ibss_manager;
  549. /* jiffies when last recovery from statistics was performed */
  550. unsigned long rx_statistics_jiffies;
  551. /*counters */
  552. u32 rx_handlers_stats[REPLY_MAX];
  553. /* rf reset */
  554. struct iwl_rf_reset rf_reset;
  555. /* firmware reload counter and timestamp */
  556. unsigned long reload_jiffies;
  557. int reload_count;
  558. bool ucode_loaded;
  559. bool init_ucode_run; /* Don't run init uCode again */
  560. u8 plcp_delta_threshold;
  561. /* thermal calibration */
  562. s32 temperature; /* Celsius */
  563. s32 last_temperature;
  564. struct iwl_wipan_noa_data __rcu *noa_data;
  565. /* Scan related variables */
  566. unsigned long scan_start;
  567. unsigned long scan_start_tsf;
  568. void *scan_cmd;
  569. enum ieee80211_band scan_band;
  570. struct cfg80211_scan_request *scan_request;
  571. struct ieee80211_vif *scan_vif;
  572. enum iwl_scan_type scan_type;
  573. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  574. u8 mgmt_tx_ant;
  575. /* max number of station keys */
  576. u8 sta_key_max_num;
  577. bool new_scan_threshold_behaviour;
  578. bool wowlan;
  579. /* EEPROM MAC addresses */
  580. struct mac_address addresses[2];
  581. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  582. __le16 switch_channel;
  583. u8 start_calib;
  584. struct iwl_sensitivity_data sensitivity_data;
  585. struct iwl_chain_noise_data chain_noise_data;
  586. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  587. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  588. struct iwl_ht_config current_ht_config;
  589. /* Rate scaling data */
  590. u8 retry_rate;
  591. int activity_timer_active;
  592. struct iwl_power_mgr power_data;
  593. struct iwl_tt_mgmt thermal_throttle;
  594. /* station table variables */
  595. int num_stations;
  596. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  597. unsigned long ucode_key_table;
  598. struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
  599. atomic_t num_aux_in_flight;
  600. u8 mac80211_registered;
  601. /* Indication if ieee80211_ops->open has been called */
  602. u8 is_open;
  603. enum nl80211_iftype iw_mode;
  604. /* Last Rx'd beacon timestamp */
  605. u64 timestamp;
  606. struct {
  607. __le32 flag;
  608. struct statistics_general_common common;
  609. struct statistics_rx_non_phy rx_non_phy;
  610. struct statistics_rx_phy rx_ofdm;
  611. struct statistics_rx_ht_phy rx_ofdm_ht;
  612. struct statistics_rx_phy rx_cck;
  613. struct statistics_tx tx;
  614. #ifdef CONFIG_IWLWIFI_DEBUGFS
  615. struct statistics_bt_activity bt_activity;
  616. __le32 num_bt_kills, accum_num_bt_kills;
  617. #endif
  618. spinlock_t lock;
  619. } statistics;
  620. #ifdef CONFIG_IWLWIFI_DEBUGFS
  621. struct {
  622. struct statistics_general_common common;
  623. struct statistics_rx_non_phy rx_non_phy;
  624. struct statistics_rx_phy rx_ofdm;
  625. struct statistics_rx_ht_phy rx_ofdm_ht;
  626. struct statistics_rx_phy rx_cck;
  627. struct statistics_tx tx;
  628. struct statistics_bt_activity bt_activity;
  629. } accum_stats, delta_stats, max_delta_stats;
  630. #endif
  631. /*
  632. * reporting the number of tids has AGG on. 0 means
  633. * no AGGREGATION
  634. */
  635. u8 agg_tids_count;
  636. struct iwl_rx_phy_res last_phy_res;
  637. u32 ampdu_ref;
  638. bool last_phy_res_valid;
  639. /*
  640. * chain noise reset and gain commands are the
  641. * two extra calibration commands follows the standard
  642. * phy calibration commands
  643. */
  644. u8 phy_calib_chain_noise_reset_cmd;
  645. u8 phy_calib_chain_noise_gain_cmd;
  646. /* counts reply_tx error */
  647. struct reply_tx_error_statistics reply_tx_stats;
  648. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  649. /* remain-on-channel offload support */
  650. struct ieee80211_channel *hw_roc_channel;
  651. struct delayed_work hw_roc_disable_work;
  652. int hw_roc_duration;
  653. bool hw_roc_setup, hw_roc_start_notified;
  654. /* bt coex */
  655. u8 bt_enable_flag;
  656. u8 bt_status;
  657. u8 bt_traffic_load, last_bt_traffic_load;
  658. bool bt_ch_announce;
  659. bool bt_full_concurrent;
  660. bool bt_ant_couple_ok;
  661. __le32 kill_ack_mask;
  662. __le32 kill_cts_mask;
  663. __le16 bt_valid;
  664. bool reduced_txpower;
  665. u16 bt_on_thresh;
  666. u16 bt_duration;
  667. u16 dynamic_frag_thresh;
  668. u8 bt_ci_compliance;
  669. struct work_struct bt_traffic_change_work;
  670. bool bt_enable_pspoll;
  671. struct iwl_rxon_context *cur_rssi_ctx;
  672. bool bt_is_sco;
  673. struct work_struct restart;
  674. struct work_struct scan_completed;
  675. struct work_struct abort_scan;
  676. struct work_struct beacon_update;
  677. struct iwl_rxon_context *beacon_ctx;
  678. struct sk_buff *beacon_skb;
  679. void *beacon_cmd;
  680. struct work_struct tt_work;
  681. struct work_struct ct_enter;
  682. struct work_struct ct_exit;
  683. struct work_struct start_internal_scan;
  684. struct work_struct tx_flush;
  685. struct work_struct bt_full_concurrency;
  686. struct work_struct bt_runtime_config;
  687. struct delayed_work scan_check;
  688. /* TX Power settings */
  689. s8 tx_power_user_lmt;
  690. s8 tx_power_next;
  691. #ifdef CONFIG_IWLWIFI_DEBUGFS
  692. /* debugfs */
  693. struct dentry *debugfs_dir;
  694. u32 dbgfs_sram_offset, dbgfs_sram_len;
  695. bool disable_ht40;
  696. void *wowlan_sram;
  697. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  698. struct iwl_nvm_data *nvm_data;
  699. /* eeprom blob for debugfs/testmode */
  700. u8 *eeprom_blob;
  701. size_t eeprom_blob_size;
  702. struct work_struct txpower_work;
  703. u32 calib_disabled;
  704. struct work_struct run_time_calib_work;
  705. struct timer_list statistics_periodic;
  706. struct timer_list ucode_trace;
  707. struct iwl_event_log event_log;
  708. struct led_classdev led;
  709. unsigned long blink_on, blink_off;
  710. bool led_registered;
  711. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  712. struct iwl_test tst;
  713. u32 tm_fixed_rate;
  714. #endif
  715. /* WoWLAN GTK rekey data */
  716. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  717. __le64 replay_ctr;
  718. __le16 last_seq_ctl;
  719. bool have_rekey_data;
  720. /* device_pointers: pointers to ucode event tables */
  721. struct {
  722. u32 error_event_table;
  723. u32 log_event_table;
  724. } device_pointers;
  725. /* indicator of loaded ucode image */
  726. enum iwl_ucode_type cur_ucode;
  727. }; /*iwl_priv */
  728. static inline struct iwl_rxon_context *
  729. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  730. {
  731. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  732. return vif_priv->ctx;
  733. }
  734. #define for_each_context(priv, ctx) \
  735. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  736. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  737. if (priv->valid_contexts & BIT(ctx->ctxid))
  738. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  739. {
  740. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  741. }
  742. static inline int iwl_is_associated(struct iwl_priv *priv,
  743. enum iwl_rxon_context_id ctxid)
  744. {
  745. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  746. }
  747. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  748. {
  749. struct iwl_rxon_context *ctx;
  750. for_each_context(priv, ctx)
  751. if (iwl_is_associated_ctx(ctx))
  752. return true;
  753. return false;
  754. }
  755. #endif /* __iwl_dev_h__ */