iwl-dev.h 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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-fw.h"
  39. #include "iwl-eeprom.h"
  40. #include "iwl-csr.h"
  41. #include "iwl-debug.h"
  42. #include "iwl-agn-hw.h"
  43. #include "iwl-led.h"
  44. #include "iwl-power.h"
  45. #include "iwl-agn-rs.h"
  46. #include "iwl-agn-tt.h"
  47. #include "iwl-trans.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_STARTING: aggregation are starting (between start and oper)
  175. * @IWL_AGG_ON: aggregation session is up
  176. * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
  177. * HW queue to be empty from packets for this RA /TID.
  178. * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
  179. * HW queue to be empty from packets for this RA /TID.
  180. */
  181. enum iwl_agg_state {
  182. IWL_AGG_OFF = 0,
  183. IWL_AGG_STARTING,
  184. IWL_AGG_ON,
  185. IWL_EMPTYING_HW_QUEUE_ADDBA,
  186. IWL_EMPTYING_HW_QUEUE_DELBA,
  187. };
  188. /**
  189. * struct iwl_ht_agg - aggregation state machine
  190. * This structs holds the states for the BA agreement establishment and tear
  191. * down. It also holds the state during the BA session itself. This struct is
  192. * duplicated for each RA / TID.
  193. * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
  194. * Tx response (REPLY_TX), and the block ack notification
  195. * (REPLY_COMPRESSED_BA).
  196. * @state: state of the BA agreement establishment / tear down.
  197. * @txq_id: Tx queue used by the BA session
  198. * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
  199. * the first packet to be sent in legacy HW queue in Tx AGG stop flow.
  200. * Basically when next_reclaimed reaches ssn, we can tell mac80211 that
  201. * we are ready to finish the Tx AGG stop / start flow.
  202. * @wait_for_ba: Expect block-ack before next Tx reply
  203. */
  204. struct iwl_ht_agg {
  205. u32 rate_n_flags;
  206. enum iwl_agg_state state;
  207. u16 txq_id;
  208. u16 ssn;
  209. bool wait_for_ba;
  210. };
  211. /**
  212. * struct iwl_tid_data - one for each RA / TID
  213. * This structs holds the states for each RA / TID.
  214. * @seq_number: the next WiFi sequence number to use
  215. * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
  216. * This is basically (last acked packet++).
  217. * @agg: aggregation state machine
  218. */
  219. struct iwl_tid_data {
  220. u16 seq_number;
  221. u16 next_reclaimed;
  222. struct iwl_ht_agg agg;
  223. };
  224. /*
  225. * Structure should be accessed with sta_lock held. When station addition
  226. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  227. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  228. * held.
  229. */
  230. struct iwl_station_entry {
  231. struct iwl_addsta_cmd sta;
  232. u8 used, ctxid;
  233. struct iwl_link_quality_cmd *lq;
  234. };
  235. /*
  236. * iwl_station_priv: Driver's private station information
  237. *
  238. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  239. * in the structure for use by driver. This structure is places in that
  240. * space.
  241. */
  242. struct iwl_station_priv {
  243. struct iwl_rxon_context *ctx;
  244. struct iwl_lq_sta lq_sta;
  245. atomic_t pending_frames;
  246. bool client;
  247. bool asleep;
  248. u8 max_agg_bufsize;
  249. u8 sta_id;
  250. };
  251. /**
  252. * struct iwl_vif_priv - driver's private per-interface information
  253. *
  254. * When mac80211 allocates a virtual interface, it can allocate
  255. * space for us to put data into.
  256. */
  257. struct iwl_vif_priv {
  258. struct iwl_rxon_context *ctx;
  259. u8 ibss_bssid_sta_id;
  260. };
  261. struct iwl_sensitivity_ranges {
  262. u16 min_nrg_cck;
  263. u16 nrg_th_cck;
  264. u16 nrg_th_ofdm;
  265. u16 auto_corr_min_ofdm;
  266. u16 auto_corr_min_ofdm_mrc;
  267. u16 auto_corr_min_ofdm_x1;
  268. u16 auto_corr_min_ofdm_mrc_x1;
  269. u16 auto_corr_max_ofdm;
  270. u16 auto_corr_max_ofdm_mrc;
  271. u16 auto_corr_max_ofdm_x1;
  272. u16 auto_corr_max_ofdm_mrc_x1;
  273. u16 auto_corr_max_cck;
  274. u16 auto_corr_max_cck_mrc;
  275. u16 auto_corr_min_cck;
  276. u16 auto_corr_min_cck_mrc;
  277. u16 barker_corr_th_min;
  278. u16 barker_corr_th_min_mrc;
  279. u16 nrg_th_cca;
  280. };
  281. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  282. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  283. /******************************************************************************
  284. *
  285. * Functions implemented in core module which are forward declared here
  286. * for use by iwl-[4-5].c
  287. *
  288. * NOTE: The implementation of these functions are not hardware specific
  289. * which is why they are in the core module files.
  290. *
  291. * Naming convention --
  292. * iwl_ <-- Is part of iwlwifi
  293. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  294. *
  295. ****************************************************************************/
  296. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  297. extern const u8 iwl_bcast_addr[ETH_ALEN];
  298. #define IWL_OPERATION_MODE_AUTO 0
  299. #define IWL_OPERATION_MODE_HT_ONLY 1
  300. #define IWL_OPERATION_MODE_MIXED 2
  301. #define IWL_OPERATION_MODE_20MHZ 3
  302. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  303. /* Sensitivity and chain noise calibration */
  304. #define INITIALIZATION_VALUE 0xFFFF
  305. #define IWL_CAL_NUM_BEACONS 16
  306. #define MAXIMUM_ALLOWED_PATHLOSS 15
  307. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  308. #define MAX_FA_OFDM 50
  309. #define MIN_FA_OFDM 5
  310. #define MAX_FA_CCK 50
  311. #define MIN_FA_CCK 5
  312. #define AUTO_CORR_STEP_OFDM 1
  313. #define AUTO_CORR_STEP_CCK 3
  314. #define AUTO_CORR_MAX_TH_CCK 160
  315. #define NRG_DIFF 2
  316. #define NRG_STEP_CCK 2
  317. #define NRG_MARGIN 8
  318. #define MAX_NUMBER_CCK_NO_FA 100
  319. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  320. #define CHAIN_A 0
  321. #define CHAIN_B 1
  322. #define CHAIN_C 2
  323. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  324. #define ALL_BAND_FILTER 0xFF00
  325. #define IN_BAND_FILTER 0xFF
  326. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  327. #define NRG_NUM_PREV_STAT_L 20
  328. #define NUM_RX_CHAINS 3
  329. enum iwlagn_false_alarm_state {
  330. IWL_FA_TOO_MANY = 0,
  331. IWL_FA_TOO_FEW = 1,
  332. IWL_FA_GOOD_RANGE = 2,
  333. };
  334. enum iwlagn_chain_noise_state {
  335. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  336. IWL_CHAIN_NOISE_ACCUMULATE,
  337. IWL_CHAIN_NOISE_CALIBRATED,
  338. IWL_CHAIN_NOISE_DONE,
  339. };
  340. /* Sensitivity calib data */
  341. struct iwl_sensitivity_data {
  342. u32 auto_corr_ofdm;
  343. u32 auto_corr_ofdm_mrc;
  344. u32 auto_corr_ofdm_x1;
  345. u32 auto_corr_ofdm_mrc_x1;
  346. u32 auto_corr_cck;
  347. u32 auto_corr_cck_mrc;
  348. u32 last_bad_plcp_cnt_ofdm;
  349. u32 last_fa_cnt_ofdm;
  350. u32 last_bad_plcp_cnt_cck;
  351. u32 last_fa_cnt_cck;
  352. u32 nrg_curr_state;
  353. u32 nrg_prev_state;
  354. u32 nrg_value[10];
  355. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  356. u32 nrg_silence_ref;
  357. u32 nrg_energy_idx;
  358. u32 nrg_silence_idx;
  359. u32 nrg_th_cck;
  360. s32 nrg_auto_corr_silence_diff;
  361. u32 num_in_cck_no_fa;
  362. u32 nrg_th_ofdm;
  363. u16 barker_corr_th_min;
  364. u16 barker_corr_th_min_mrc;
  365. u16 nrg_th_cca;
  366. };
  367. /* Chain noise (differential Rx gain) calib data */
  368. struct iwl_chain_noise_data {
  369. u32 active_chains;
  370. u32 chain_noise_a;
  371. u32 chain_noise_b;
  372. u32 chain_noise_c;
  373. u32 chain_signal_a;
  374. u32 chain_signal_b;
  375. u32 chain_signal_c;
  376. u16 beacon_count;
  377. u8 disconn_array[NUM_RX_CHAINS];
  378. u8 delta_gain_code[NUM_RX_CHAINS];
  379. u8 radio_write;
  380. u8 state;
  381. };
  382. enum {
  383. MEASUREMENT_READY = (1 << 0),
  384. MEASUREMENT_ACTIVE = (1 << 1),
  385. };
  386. enum iwl_nvm_type {
  387. NVM_DEVICE_TYPE_EEPROM = 0,
  388. NVM_DEVICE_TYPE_OTP,
  389. };
  390. /*
  391. * Two types of OTP memory access modes
  392. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  393. * based on physical memory addressing
  394. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  395. * based on logical memory addressing
  396. */
  397. enum iwl_access_mode {
  398. IWL_OTP_ACCESS_ABSOLUTE,
  399. IWL_OTP_ACCESS_RELATIVE,
  400. };
  401. /* reply_tx_statistics (for _agn devices) */
  402. struct reply_tx_error_statistics {
  403. u32 pp_delay;
  404. u32 pp_few_bytes;
  405. u32 pp_bt_prio;
  406. u32 pp_quiet_period;
  407. u32 pp_calc_ttak;
  408. u32 int_crossed_retry;
  409. u32 short_limit;
  410. u32 long_limit;
  411. u32 fifo_underrun;
  412. u32 drain_flow;
  413. u32 rfkill_flush;
  414. u32 life_expire;
  415. u32 dest_ps;
  416. u32 host_abort;
  417. u32 bt_retry;
  418. u32 sta_invalid;
  419. u32 frag_drop;
  420. u32 tid_disable;
  421. u32 fifo_flush;
  422. u32 insuff_cf_poll;
  423. u32 fail_hw_drop;
  424. u32 sta_color_mismatch;
  425. u32 unknown;
  426. };
  427. /* reply_agg_tx_statistics (for _agn devices) */
  428. struct reply_agg_tx_error_statistics {
  429. u32 underrun;
  430. u32 bt_prio;
  431. u32 few_bytes;
  432. u32 abort;
  433. u32 last_sent_ttl;
  434. u32 last_sent_try;
  435. u32 last_sent_bt_kill;
  436. u32 scd_query;
  437. u32 bad_crc32;
  438. u32 response;
  439. u32 dump_tx;
  440. u32 delay_tx;
  441. u32 unknown;
  442. };
  443. /*
  444. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  445. * to perform continuous uCode event logging operation if enabled
  446. */
  447. #define UCODE_TRACE_PERIOD (10)
  448. /*
  449. * iwl_event_log: current uCode event log position
  450. *
  451. * @ucode_trace: enable/disable ucode continuous trace timer
  452. * @num_wraps: how many times the event buffer wraps
  453. * @next_entry: the entry just before the next one that uCode would fill
  454. * @non_wraps_count: counter for no wrap detected when dump ucode events
  455. * @wraps_once_count: counter for wrap once detected when dump ucode events
  456. * @wraps_more_count: counter for wrap more than once detected
  457. * when dump ucode events
  458. */
  459. struct iwl_event_log {
  460. bool ucode_trace;
  461. u32 num_wraps;
  462. u32 next_entry;
  463. int non_wraps_count;
  464. int wraps_once_count;
  465. int wraps_more_count;
  466. };
  467. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  468. /* BT Antenna Coupling Threshold (dB) */
  469. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  470. /* Firmware reload counter and Timestamp */
  471. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  472. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  473. struct iwl_rf_reset {
  474. int reset_request_count;
  475. int reset_success_count;
  476. int reset_reject_count;
  477. unsigned long last_reset_jiffies;
  478. };
  479. enum iwl_rxon_context_id {
  480. IWL_RXON_CTX_BSS,
  481. IWL_RXON_CTX_PAN,
  482. NUM_IWL_RXON_CTX
  483. };
  484. /* extend beacon time format bit shifting */
  485. /*
  486. * for _agn devices
  487. * bits 31:22 - extended
  488. * bits 21:0 - interval
  489. */
  490. #define IWLAGN_EXT_BEACON_TIME_POS 22
  491. struct iwl_rxon_context {
  492. struct ieee80211_vif *vif;
  493. u8 mcast_queue;
  494. u8 ac_to_queue[IEEE80211_NUM_ACS];
  495. u8 ac_to_fifo[IEEE80211_NUM_ACS];
  496. /*
  497. * We could use the vif to indicate active, but we
  498. * also need it to be active during disabling when
  499. * we already removed the vif for type setting.
  500. */
  501. bool always_active, is_active;
  502. bool ht_need_multiple_chains;
  503. enum iwl_rxon_context_id ctxid;
  504. u32 interface_modes, exclusive_interface_modes;
  505. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  506. /*
  507. * We declare this const so it can only be
  508. * changed via explicit cast within the
  509. * routines that actually update the physical
  510. * hardware.
  511. */
  512. const struct iwl_rxon_cmd active;
  513. struct iwl_rxon_cmd staging;
  514. struct iwl_rxon_time_cmd timing;
  515. struct iwl_qos_info qos_data;
  516. u8 bcast_sta_id, ap_sta_id;
  517. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  518. u8 qos_cmd;
  519. u8 wep_key_cmd;
  520. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  521. u8 key_mapping_keys;
  522. __le32 station_flags;
  523. int beacon_int;
  524. struct {
  525. bool non_gf_sta_present;
  526. u8 protection;
  527. bool enabled, is_40mhz;
  528. u8 extension_chan_offset;
  529. } ht;
  530. };
  531. enum iwl_scan_type {
  532. IWL_SCAN_NORMAL,
  533. IWL_SCAN_RADIO_RESET,
  534. IWL_SCAN_ROC,
  535. };
  536. /**
  537. * struct iwl_hw_params
  538. *
  539. * Holds the module parameters
  540. *
  541. * @tx_chains_num: Number of TX chains
  542. * @rx_chains_num: Number of RX chains
  543. * @valid_tx_ant: usable antennas for TX
  544. * @valid_rx_ant: usable antennas for RX
  545. * @ht40_channel: is 40MHz width possible: BIT(IEEE80211_BAND_XXX)
  546. * @sku: sku read from EEPROM
  547. * @ct_kill_threshold: temperature threshold - in hw dependent unit
  548. * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
  549. * relevant for 1000, 6000 and up
  550. * @struct iwl_sensitivity_ranges: range of sensitivity values
  551. * @use_rts_for_aggregation: use rts/cts protection for HT traffic
  552. */
  553. struct iwl_hw_params {
  554. u8 tx_chains_num;
  555. u8 rx_chains_num;
  556. u8 valid_tx_ant;
  557. u8 valid_rx_ant;
  558. u8 ht40_channel;
  559. bool use_rts_for_aggregation;
  560. u16 sku;
  561. u32 ct_kill_threshold;
  562. u32 ct_kill_exit_threshold;
  563. const struct iwl_sensitivity_ranges *sens;
  564. };
  565. struct iwl_lib_ops {
  566. /* set hw dependent parameters */
  567. void (*set_hw_params)(struct iwl_priv *priv);
  568. int (*set_channel_switch)(struct iwl_priv *priv,
  569. struct ieee80211_channel_switch *ch_switch);
  570. /* device specific configuration */
  571. void (*nic_config)(struct iwl_priv *priv);
  572. /* eeprom operations (as defined in iwl-eeprom.h) */
  573. struct iwl_eeprom_ops eeprom_ops;
  574. /* temperature */
  575. void (*temperature)(struct iwl_priv *priv);
  576. };
  577. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  578. struct iwl_testmode_trace {
  579. u32 buff_size;
  580. u32 total_size;
  581. u32 num_chunks;
  582. u8 *cpu_addr;
  583. u8 *trace_addr;
  584. dma_addr_t dma_addr;
  585. bool trace_enabled;
  586. };
  587. struct iwl_testmode_mem {
  588. u32 buff_size;
  589. u32 num_chunks;
  590. u8 *buff_addr;
  591. bool read_in_progress;
  592. };
  593. #endif
  594. struct iwl_wipan_noa_data {
  595. struct rcu_head rcu_head;
  596. u32 length;
  597. u8 data[];
  598. };
  599. /* Calibration disabling bit mask */
  600. enum {
  601. IWL_CALIB_ENABLE_ALL = 0,
  602. IWL_SENSITIVITY_CALIB_DISABLED = BIT(0),
  603. IWL_CHAIN_NOISE_CALIB_DISABLED = BIT(1),
  604. IWL_TX_POWER_CALIB_DISABLED = BIT(2),
  605. IWL_CALIB_DISABLE_ALL = 0xFFFFFFFF,
  606. };
  607. #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
  608. ((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
  609. #define IWL_MAC80211_GET_DVM(_hw) \
  610. ((struct iwl_priv *) ((struct iwl_op_mode *) \
  611. (_hw)->priv)->op_mode_specific)
  612. struct iwl_priv {
  613. struct iwl_trans *trans;
  614. struct device *dev; /* for debug prints only */
  615. const struct iwl_cfg *cfg;
  616. const struct iwl_fw *fw;
  617. const struct iwl_lib_ops *lib;
  618. unsigned long status;
  619. spinlock_t sta_lock;
  620. struct mutex mutex;
  621. unsigned long transport_queue_stop;
  622. bool passive_no_rx;
  623. #define IWL_INVALID_MAC80211_QUEUE 0xff
  624. u8 queue_to_mac80211[IWL_MAX_HW_QUEUES];
  625. atomic_t queue_stop_count[IWL_MAX_HW_QUEUES];
  626. unsigned long agg_q_alloc[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  627. /* ieee device used by generic ieee processing code */
  628. struct ieee80211_hw *hw;
  629. struct ieee80211_channel *ieee_channels;
  630. struct ieee80211_rate *ieee_rates;
  631. struct list_head calib_results;
  632. struct workqueue_struct *workqueue;
  633. struct iwl_hw_params hw_params;
  634. enum ieee80211_band band;
  635. u8 valid_contexts;
  636. void (*pre_rx_handler)(struct iwl_priv *priv,
  637. struct iwl_rx_cmd_buffer *rxb);
  638. int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  639. struct iwl_rx_cmd_buffer *rxb,
  640. struct iwl_device_cmd *cmd);
  641. struct iwl_notif_wait_data notif_wait;
  642. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  643. /* spectrum measurement report caching */
  644. struct iwl_spectrum_notification measure_report;
  645. u8 measurement_status;
  646. #define IWL_OWNERSHIP_DRIVER 0
  647. #define IWL_OWNERSHIP_TM 1
  648. u8 ucode_owner;
  649. /* ucode beacon time */
  650. u32 ucode_beacon_time;
  651. int missed_beacon_threshold;
  652. /* track IBSS manager (last beacon) status */
  653. u32 ibss_manager;
  654. /* jiffies when last recovery from statistics was performed */
  655. unsigned long rx_statistics_jiffies;
  656. /*counters */
  657. u32 rx_handlers_stats[REPLY_MAX];
  658. /* rf reset */
  659. struct iwl_rf_reset rf_reset;
  660. /* firmware reload counter and timestamp */
  661. unsigned long reload_jiffies;
  662. int reload_count;
  663. bool ucode_loaded;
  664. bool init_ucode_run; /* Don't run init uCode again */
  665. /* we allocate array of iwl_channel_info for NIC's valid channels.
  666. * Access via channel # using indirect index array */
  667. struct iwl_channel_info *channel_info; /* channel info array */
  668. u8 channel_count; /* # of channels */
  669. u8 plcp_delta_threshold;
  670. /* thermal calibration */
  671. s32 temperature; /* Celsius */
  672. s32 last_temperature;
  673. struct iwl_wipan_noa_data __rcu *noa_data;
  674. /* Scan related variables */
  675. unsigned long scan_start;
  676. unsigned long scan_start_tsf;
  677. void *scan_cmd;
  678. enum ieee80211_band scan_band;
  679. struct cfg80211_scan_request *scan_request;
  680. struct ieee80211_vif *scan_vif;
  681. enum iwl_scan_type scan_type;
  682. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  683. u8 mgmt_tx_ant;
  684. /* max number of station keys */
  685. u8 sta_key_max_num;
  686. bool new_scan_threshold_behaviour;
  687. bool wowlan;
  688. /* EEPROM MAC addresses */
  689. struct mac_address addresses[2];
  690. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  691. __le16 switch_channel;
  692. u8 start_calib;
  693. struct iwl_sensitivity_data sensitivity_data;
  694. struct iwl_chain_noise_data chain_noise_data;
  695. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  696. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  697. struct iwl_ht_config current_ht_config;
  698. /* Rate scaling data */
  699. u8 retry_rate;
  700. int activity_timer_active;
  701. struct iwl_power_mgr power_data;
  702. struct iwl_tt_mgmt thermal_throttle;
  703. /* station table variables */
  704. int num_stations;
  705. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  706. unsigned long ucode_key_table;
  707. struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
  708. u8 mac80211_registered;
  709. /* Indication if ieee80211_ops->open has been called */
  710. u8 is_open;
  711. enum nl80211_iftype iw_mode;
  712. /* Last Rx'd beacon timestamp */
  713. u64 timestamp;
  714. struct {
  715. __le32 flag;
  716. struct statistics_general_common common;
  717. struct statistics_rx_non_phy rx_non_phy;
  718. struct statistics_rx_phy rx_ofdm;
  719. struct statistics_rx_ht_phy rx_ofdm_ht;
  720. struct statistics_rx_phy rx_cck;
  721. struct statistics_tx tx;
  722. #ifdef CONFIG_IWLWIFI_DEBUGFS
  723. struct statistics_bt_activity bt_activity;
  724. __le32 num_bt_kills, accum_num_bt_kills;
  725. #endif
  726. spinlock_t lock;
  727. } statistics;
  728. #ifdef CONFIG_IWLWIFI_DEBUGFS
  729. struct {
  730. struct statistics_general_common common;
  731. struct statistics_rx_non_phy rx_non_phy;
  732. struct statistics_rx_phy rx_ofdm;
  733. struct statistics_rx_ht_phy rx_ofdm_ht;
  734. struct statistics_rx_phy rx_cck;
  735. struct statistics_tx tx;
  736. struct statistics_bt_activity bt_activity;
  737. } accum_stats, delta_stats, max_delta_stats;
  738. #endif
  739. /*
  740. * reporting the number of tids has AGG on. 0 means
  741. * no AGGREGATION
  742. */
  743. u8 agg_tids_count;
  744. struct iwl_rx_phy_res last_phy_res;
  745. bool last_phy_res_valid;
  746. /*
  747. * chain noise reset and gain commands are the
  748. * two extra calibration commands follows the standard
  749. * phy calibration commands
  750. */
  751. u8 phy_calib_chain_noise_reset_cmd;
  752. u8 phy_calib_chain_noise_gain_cmd;
  753. /* counts reply_tx error */
  754. struct reply_tx_error_statistics reply_tx_stats;
  755. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  756. /* remain-on-channel offload support */
  757. struct ieee80211_channel *hw_roc_channel;
  758. struct delayed_work hw_roc_disable_work;
  759. enum nl80211_channel_type hw_roc_chantype;
  760. int hw_roc_duration;
  761. bool hw_roc_setup, hw_roc_start_notified;
  762. /* bt coex */
  763. u8 bt_enable_flag;
  764. u8 bt_status;
  765. u8 bt_traffic_load, last_bt_traffic_load;
  766. bool bt_ch_announce;
  767. bool bt_full_concurrent;
  768. bool bt_ant_couple_ok;
  769. __le32 kill_ack_mask;
  770. __le32 kill_cts_mask;
  771. __le16 bt_valid;
  772. u16 bt_on_thresh;
  773. u16 bt_duration;
  774. u16 dynamic_frag_thresh;
  775. u8 bt_ci_compliance;
  776. struct work_struct bt_traffic_change_work;
  777. bool bt_enable_pspoll;
  778. struct iwl_rxon_context *cur_rssi_ctx;
  779. bool bt_is_sco;
  780. struct work_struct restart;
  781. struct work_struct scan_completed;
  782. struct work_struct abort_scan;
  783. struct work_struct beacon_update;
  784. struct iwl_rxon_context *beacon_ctx;
  785. struct sk_buff *beacon_skb;
  786. void *beacon_cmd;
  787. struct work_struct tt_work;
  788. struct work_struct ct_enter;
  789. struct work_struct ct_exit;
  790. struct work_struct start_internal_scan;
  791. struct work_struct tx_flush;
  792. struct work_struct bt_full_concurrency;
  793. struct work_struct bt_runtime_config;
  794. struct delayed_work scan_check;
  795. /* TX Power */
  796. s8 tx_power_user_lmt;
  797. s8 tx_power_device_lmt;
  798. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  799. s8 tx_power_next;
  800. #ifdef CONFIG_IWLWIFI_DEBUGFS
  801. /* debugfs */
  802. struct dentry *debugfs_dir;
  803. u32 dbgfs_sram_offset, dbgfs_sram_len;
  804. bool disable_ht40;
  805. void *wowlan_sram;
  806. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  807. /* eeprom -- this is in the card's little endian byte order */
  808. u8 *eeprom;
  809. enum iwl_nvm_type nvm_device_type;
  810. struct work_struct txpower_work;
  811. u32 calib_disabled;
  812. struct work_struct run_time_calib_work;
  813. struct timer_list statistics_periodic;
  814. struct timer_list ucode_trace;
  815. struct iwl_event_log event_log;
  816. struct led_classdev led;
  817. unsigned long blink_on, blink_off;
  818. bool led_registered;
  819. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  820. struct iwl_testmode_trace testmode_trace;
  821. struct iwl_testmode_mem testmode_mem;
  822. u32 tm_fixed_rate;
  823. #endif
  824. /* WoWLAN GTK rekey data */
  825. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  826. __le64 replay_ctr;
  827. __le16 last_seq_ctl;
  828. bool have_rekey_data;
  829. /* device_pointers: pointers to ucode event tables */
  830. struct {
  831. u32 error_event_table;
  832. u32 log_event_table;
  833. } device_pointers;
  834. /* indicator of loaded ucode image */
  835. enum iwl_ucode_type cur_ucode;
  836. }; /*iwl_priv */
  837. extern struct kmem_cache *iwl_tx_cmd_pool;
  838. static inline struct iwl_rxon_context *
  839. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  840. {
  841. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  842. return vif_priv->ctx;
  843. }
  844. #define for_each_context(priv, ctx) \
  845. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  846. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  847. if (priv->valid_contexts & BIT(ctx->ctxid))
  848. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  849. {
  850. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  851. }
  852. static inline int iwl_is_associated(struct iwl_priv *priv,
  853. enum iwl_rxon_context_id ctxid)
  854. {
  855. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  856. }
  857. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  858. {
  859. struct iwl_rxon_context *ctx;
  860. for_each_context(priv, ctx)
  861. if (iwl_is_associated_ctx(ctx))
  862. return true;
  863. return false;
  864. }
  865. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  866. {
  867. if (ch_info == NULL)
  868. return 0;
  869. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  870. }
  871. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  872. {
  873. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  874. }
  875. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  876. {
  877. return ch_info->band == IEEE80211_BAND_5GHZ;
  878. }
  879. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  880. {
  881. return ch_info->band == IEEE80211_BAND_2GHZ;
  882. }
  883. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  884. {
  885. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  886. }
  887. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  888. {
  889. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  890. }
  891. #endif /* __iwl_dev_h__ */