iwl-dev.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. /*
  27. * Please use this file (iwl-dev.h) for driver implementation definitions.
  28. * Please use iwl-commands.h for uCode API definitions.
  29. */
  30. #ifndef __iwl_dev_h__
  31. #define __iwl_dev_h__
  32. #include <linux/interrupt.h>
  33. #include <linux/pci.h> /* for struct pci_device_id */
  34. #include <linux/kernel.h>
  35. #include <linux/wait.h>
  36. #include <linux/leds.h>
  37. #include <net/ieee80211_radiotap.h>
  38. #include "iwl-eeprom.h"
  39. #include "iwl-csr.h"
  40. #include "iwl-prph.h"
  41. #include "iwl-fh.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-bus.h"
  49. #include "iwl-trans.h"
  50. #include "iwl-shared.h"
  51. #define DRV_NAME "iwlagn"
  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 (4965, no beacon statistics being sent to driver)
  60. * 2) Scanning (noise measurement does not apply to associated channel)
  61. * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
  62. * Use default noise value of -127 ... this is below the range of measurable
  63. * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
  64. * Also, -127 works better than 0 when averaging frames with/without
  65. * noise info (e.g. averaging might be done in app); measured dBm values are
  66. * always negative ... using a negative value as the default keeps all
  67. * averages within an s8's (used in some apps) range of negative values. */
  68. #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
  69. /*
  70. * RTS threshold here is total size [2347] minus 4 FCS bytes
  71. * Per spec:
  72. * a value of 0 means RTS on all data/management packets
  73. * a value > max MSDU size means no RTS
  74. * else RTS for data/management frames where MPDU is larger
  75. * than RTS value.
  76. */
  77. #define DEFAULT_RTS_THRESHOLD 2347U
  78. #define MIN_RTS_THRESHOLD 0U
  79. #define MAX_RTS_THRESHOLD 2347U
  80. #define MAX_MSDU_SIZE 2304U
  81. #define MAX_MPDU_SIZE 2346U
  82. #define DEFAULT_BEACON_INTERVAL 200U
  83. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  84. #define DEFAULT_LONG_RETRY_LIMIT 4U
  85. /* defined below */
  86. struct iwl_device_cmd;
  87. struct iwl_cmd_meta {
  88. /* only for SYNC commands, iff the reply skb is wanted */
  89. struct iwl_host_cmd *source;
  90. /*
  91. * only for ASYNC commands
  92. * (which is somewhat stupid -- look at iwl-sta.c for instance
  93. * which duplicates a bunch of code because the callback isn't
  94. * invoked for SYNC commands, if it were and its result passed
  95. * through it would be simpler...)
  96. */
  97. void (*callback)(struct iwl_priv *priv,
  98. struct iwl_device_cmd *cmd,
  99. struct iwl_rx_packet *pkt);
  100. u32 flags;
  101. DEFINE_DMA_UNMAP_ADDR(mapping);
  102. DEFINE_DMA_UNMAP_LEN(len);
  103. };
  104. /*
  105. * Generic queue structure
  106. *
  107. * Contains common data for Rx and Tx queues.
  108. *
  109. * Note the difference between n_bd and n_window: the hardware
  110. * always assumes 256 descriptors, so n_bd is always 256 (unless
  111. * there might be HW changes in the future). For the normal TX
  112. * queues, n_window, which is the size of the software queue data
  113. * is also 256; however, for the command queue, n_window is only
  114. * 32 since we don't need so many commands pending. Since the HW
  115. * still uses 256 BDs for DMA though, n_bd stays 256. As a result,
  116. * the software buffers (in the variables @meta, @txb in struct
  117. * iwl_tx_queue) only have 32 entries, while the HW buffers (@tfds
  118. * in the same struct) have 256.
  119. * This means that we end up with the following:
  120. * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
  121. * SW entries: | 0 | ... | 31 |
  122. * where N is a number between 0 and 7. This means that the SW
  123. * data is a window overlayed over the HW queue.
  124. */
  125. struct iwl_queue {
  126. int n_bd; /* number of BDs in this queue */
  127. int write_ptr; /* 1-st empty entry (index) host_w*/
  128. int read_ptr; /* last used entry (index) host_r*/
  129. /* use for monitoring and recovering the stuck queue */
  130. dma_addr_t dma_addr; /* physical addr for BD's */
  131. int n_window; /* safe queue window */
  132. u32 id;
  133. int low_mark; /* low watermark, resume queue if free
  134. * space more than this */
  135. int high_mark; /* high watermark, stop queue if free
  136. * space less than this */
  137. };
  138. /* One for each TFD */
  139. struct iwl_tx_info {
  140. struct sk_buff *skb;
  141. struct iwl_rxon_context *ctx;
  142. };
  143. /**
  144. * struct iwl_tx_queue - Tx Queue for DMA
  145. * @q: generic Rx/Tx queue descriptor
  146. * @bd: base of circular buffer of TFDs
  147. * @cmd: array of command/TX buffer pointers
  148. * @meta: array of meta data for each command/tx buffer
  149. * @dma_addr_cmd: physical address of cmd/tx buffer array
  150. * @txb: array of per-TFD driver data
  151. * @time_stamp: time (in jiffies) of last read_ptr change
  152. * @need_update: indicates need to update read/write index
  153. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  154. *
  155. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  156. * descriptors) and required locking structures.
  157. */
  158. #define TFD_TX_CMD_SLOTS 256
  159. #define TFD_CMD_SLOTS 32
  160. struct iwl_tx_queue {
  161. struct iwl_queue q;
  162. struct iwl_tfd *tfds;
  163. struct iwl_device_cmd **cmd;
  164. struct iwl_cmd_meta *meta;
  165. struct iwl_tx_info *txb;
  166. unsigned long time_stamp;
  167. u8 need_update;
  168. u8 sched_retry;
  169. u8 active;
  170. u8 swq_id;
  171. };
  172. #define IWL_NUM_SCAN_RATES (2)
  173. /*
  174. * One for each channel, holds all channel setup data
  175. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  176. * with one another!
  177. */
  178. struct iwl_channel_info {
  179. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  180. struct iwl_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
  181. * HT40 channel */
  182. u8 channel; /* channel number */
  183. u8 flags; /* flags copied from EEPROM */
  184. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  185. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  186. s8 min_power; /* always 0 */
  187. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  188. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  189. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  190. enum ieee80211_band band;
  191. /* HT40 channel info */
  192. s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  193. u8 ht40_flags; /* flags copied from EEPROM */
  194. u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  195. };
  196. #define IWL_TX_FIFO_BK 0 /* shared */
  197. #define IWL_TX_FIFO_BE 1
  198. #define IWL_TX_FIFO_VI 2 /* shared */
  199. #define IWL_TX_FIFO_VO 3
  200. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  201. #define IWL_TX_FIFO_BE_IPAN 4
  202. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  203. #define IWL_TX_FIFO_VO_IPAN 5
  204. /* re-uses the VO FIFO, uCode will properly flush/schedule */
  205. #define IWL_TX_FIFO_AUX 5
  206. #define IWL_TX_FIFO_UNUSED -1
  207. /* AUX (TX during scan dwell) queue */
  208. #define IWL_AUX_QUEUE 10
  209. /*
  210. * Minimum number of queues. MAX_NUM is defined in hw specific files.
  211. * Set the minimum to accommodate
  212. * - 4 standard TX queues
  213. * - the command queue
  214. * - 4 PAN TX queues
  215. * - the PAN multicast queue, and
  216. * - the AUX (TX during scan dwell) queue.
  217. */
  218. #define IWL_MIN_NUM_QUEUES 11
  219. /*
  220. * Command queue depends on iPAN support.
  221. */
  222. #define IWL_DEFAULT_CMD_QUEUE_NUM 4
  223. #define IWL_IPAN_CMD_QUEUE_NUM 9
  224. /*
  225. * This queue number is required for proper operation
  226. * because the ucode will stop/start the scheduler as
  227. * required.
  228. */
  229. #define IWL_IPAN_MCAST_QUEUE 8
  230. #define IEEE80211_DATA_LEN 2304
  231. #define IEEE80211_4ADDR_LEN 30
  232. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  233. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  234. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  235. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  236. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  237. enum {
  238. CMD_SYNC = 0,
  239. CMD_ASYNC = BIT(0),
  240. CMD_WANT_SKB = BIT(1),
  241. CMD_ON_DEMAND = BIT(2),
  242. };
  243. #define DEF_CMD_PAYLOAD_SIZE 320
  244. /**
  245. * struct iwl_device_cmd
  246. *
  247. * For allocation of the command and tx queues, this establishes the overall
  248. * size of the largest command we send to uCode, except for commands that
  249. * aren't fully copied and use other TFD space.
  250. */
  251. struct iwl_device_cmd {
  252. struct iwl_cmd_header hdr; /* uCode API */
  253. union {
  254. u32 flags;
  255. u8 val8;
  256. u16 val16;
  257. u32 val32;
  258. struct iwl_tx_cmd tx;
  259. struct iwl6000_channel_switch_cmd chswitch;
  260. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  261. } __packed cmd;
  262. } __packed;
  263. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  264. #define IWL_MAX_CMD_TFDS 2
  265. enum iwl_hcmd_dataflag {
  266. IWL_HCMD_DFL_NOCOPY = BIT(0),
  267. };
  268. /**
  269. * struct iwl_host_cmd - Host command to the uCode
  270. * @data: array of chunks that composes the data of the host command
  271. * @reply_page: pointer to the page that holds the response to the host command
  272. * @callback:
  273. * @flags: can be CMD_* note CMD_WANT_SKB is incompatible withe CMD_ASYNC
  274. * @len: array of the lenths of the chunks in data
  275. * @dataflags:
  276. * @id: id of the host command
  277. */
  278. struct iwl_host_cmd {
  279. const void *data[IWL_MAX_CMD_TFDS];
  280. unsigned long reply_page;
  281. void (*callback)(struct iwl_priv *priv,
  282. struct iwl_device_cmd *cmd,
  283. struct iwl_rx_packet *pkt);
  284. u32 flags;
  285. u16 len[IWL_MAX_CMD_TFDS];
  286. u8 dataflags[IWL_MAX_CMD_TFDS];
  287. u8 id;
  288. };
  289. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  290. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  291. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  292. #define IWL_SUPPORTED_RATES_IE_LEN 8
  293. #define MAX_TID_COUNT 9
  294. #define IWL_INVALID_RATE 0xFF
  295. #define IWL_INVALID_VALUE -1
  296. /**
  297. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  298. * @txq_id: Tx queue used for Tx attempt
  299. * @frame_count: # frames attempted by Tx command
  300. * @wait_for_ba: Expect block-ack before next Tx reply
  301. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  302. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  303. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  304. * @rate_n_flags: Rate at which Tx was attempted
  305. *
  306. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  307. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  308. * until block ack arrives.
  309. */
  310. struct iwl_ht_agg {
  311. u16 txq_id;
  312. u16 frame_count;
  313. u16 wait_for_ba;
  314. u16 start_idx;
  315. u64 bitmap;
  316. u32 rate_n_flags;
  317. #define IWL_AGG_OFF 0
  318. #define IWL_AGG_ON 1
  319. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  320. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  321. u8 state;
  322. u8 tx_fifo;
  323. };
  324. struct iwl_tid_data {
  325. u16 seq_number; /* agn only */
  326. u16 tfds_in_queue;
  327. struct iwl_ht_agg agg;
  328. };
  329. union iwl_ht_rate_supp {
  330. u16 rates;
  331. struct {
  332. u8 siso_rate;
  333. u8 mimo_rate;
  334. };
  335. };
  336. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  337. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  338. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  339. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  340. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  341. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  342. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  343. /*
  344. * Maximal MPDU density for TX aggregation
  345. * 4 - 2us density
  346. * 5 - 4us density
  347. * 6 - 8us density
  348. * 7 - 16us density
  349. */
  350. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  351. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  352. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  353. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  354. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  355. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  356. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  357. struct iwl_ht_config {
  358. bool single_chain_sufficient;
  359. enum ieee80211_smps_mode smps; /* current smps mode */
  360. };
  361. /* QoS structures */
  362. struct iwl_qos_info {
  363. int qos_active;
  364. struct iwl_qosparam_cmd def_qos_parm;
  365. };
  366. /*
  367. * Structure should be accessed with sta_lock held. When station addition
  368. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  369. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  370. * held.
  371. */
  372. struct iwl_station_entry {
  373. struct iwl_addsta_cmd sta;
  374. struct iwl_tid_data tid[MAX_TID_COUNT];
  375. u8 used, ctxid;
  376. struct iwl_link_quality_cmd *lq;
  377. };
  378. struct iwl_station_priv_common {
  379. struct iwl_rxon_context *ctx;
  380. u8 sta_id;
  381. };
  382. /*
  383. * iwl_station_priv: Driver's private station information
  384. *
  385. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  386. * in the structure for use by driver. This structure is places in that
  387. * space.
  388. */
  389. struct iwl_station_priv {
  390. struct iwl_station_priv_common common;
  391. struct iwl_lq_sta lq_sta;
  392. atomic_t pending_frames;
  393. bool client;
  394. bool asleep;
  395. u8 max_agg_bufsize;
  396. };
  397. /**
  398. * struct iwl_vif_priv - driver's private per-interface information
  399. *
  400. * When mac80211 allocates a virtual interface, it can allocate
  401. * space for us to put data into.
  402. */
  403. struct iwl_vif_priv {
  404. struct iwl_rxon_context *ctx;
  405. u8 ibss_bssid_sta_id;
  406. };
  407. /* one for each uCode image (inst/data, boot/init/runtime) */
  408. struct fw_desc {
  409. void *v_addr; /* access by driver */
  410. dma_addr_t p_addr; /* access by card's busmaster DMA */
  411. u32 len; /* bytes */
  412. };
  413. struct fw_img {
  414. struct fw_desc code, data;
  415. };
  416. /* v1/v2 uCode file layout */
  417. struct iwl_ucode_header {
  418. __le32 ver; /* major/minor/API/serial */
  419. union {
  420. struct {
  421. __le32 inst_size; /* bytes of runtime code */
  422. __le32 data_size; /* bytes of runtime data */
  423. __le32 init_size; /* bytes of init code */
  424. __le32 init_data_size; /* bytes of init data */
  425. __le32 boot_size; /* bytes of bootstrap code */
  426. u8 data[0]; /* in same order as sizes */
  427. } v1;
  428. struct {
  429. __le32 build; /* build number */
  430. __le32 inst_size; /* bytes of runtime code */
  431. __le32 data_size; /* bytes of runtime data */
  432. __le32 init_size; /* bytes of init code */
  433. __le32 init_data_size; /* bytes of init data */
  434. __le32 boot_size; /* bytes of bootstrap code */
  435. u8 data[0]; /* in same order as sizes */
  436. } v2;
  437. } u;
  438. };
  439. /*
  440. * new TLV uCode file layout
  441. *
  442. * The new TLV file format contains TLVs, that each specify
  443. * some piece of data. To facilitate "groups", for example
  444. * different instruction image with different capabilities,
  445. * bundled with the same init image, an alternative mechanism
  446. * is provided:
  447. * When the alternative field is 0, that means that the item
  448. * is always valid. When it is non-zero, then it is only
  449. * valid in conjunction with items of the same alternative,
  450. * in which case the driver (user) selects one alternative
  451. * to use.
  452. */
  453. enum iwl_ucode_tlv_type {
  454. IWL_UCODE_TLV_INVALID = 0, /* unused */
  455. IWL_UCODE_TLV_INST = 1,
  456. IWL_UCODE_TLV_DATA = 2,
  457. IWL_UCODE_TLV_INIT = 3,
  458. IWL_UCODE_TLV_INIT_DATA = 4,
  459. IWL_UCODE_TLV_BOOT = 5,
  460. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  461. IWL_UCODE_TLV_PAN = 7,
  462. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  463. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  464. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  465. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  466. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  467. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  468. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  469. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  470. IWL_UCODE_TLV_WOWLAN_INST = 16,
  471. IWL_UCODE_TLV_WOWLAN_DATA = 17,
  472. IWL_UCODE_TLV_FLAGS = 18,
  473. };
  474. /**
  475. * enum iwl_ucode_tlv_flag - ucode API flags
  476. * @IWL_UCODE_TLV_FLAGS_PAN: This is PAN capable microcode; this previously
  477. * was a separate TLV but moved here to save space.
  478. * @IWL_UCODE_TLV_FLAGS_NEWSCAN: new uCode scan behaviour on hidden SSID,
  479. * treats good CRC threshold as a boolean
  480. * @IWL_UCODE_TLV_FLAGS_MFP: This uCode image supports MFP (802.11w).
  481. * @IWL_UCODE_TLV_FLAGS_P2P: This uCode image supports P2P.
  482. */
  483. enum iwl_ucode_tlv_flag {
  484. IWL_UCODE_TLV_FLAGS_PAN = BIT(0),
  485. IWL_UCODE_TLV_FLAGS_NEWSCAN = BIT(1),
  486. IWL_UCODE_TLV_FLAGS_MFP = BIT(2),
  487. IWL_UCODE_TLV_FLAGS_P2P = BIT(3),
  488. };
  489. struct iwl_ucode_tlv {
  490. __le16 type; /* see above */
  491. __le16 alternative; /* see comment */
  492. __le32 length; /* not including type/length fields */
  493. u8 data[0];
  494. } __packed;
  495. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  496. struct iwl_tlv_ucode_header {
  497. /*
  498. * The TLV style ucode header is distinguished from
  499. * the v1/v2 style header by first four bytes being
  500. * zero, as such is an invalid combination of
  501. * major/minor/API/serial versions.
  502. */
  503. __le32 zero;
  504. __le32 magic;
  505. u8 human_readable[64];
  506. __le32 ver; /* major/minor/API/serial */
  507. __le32 build;
  508. __le64 alternatives; /* bitmask of valid alternatives */
  509. /*
  510. * The data contained herein has a TLV layout,
  511. * see above for the TLV header and types.
  512. * Note that each TLV is padded to a length
  513. * that is a multiple of 4 for alignment.
  514. */
  515. u8 data[0];
  516. };
  517. struct iwl_sensitivity_ranges {
  518. u16 min_nrg_cck;
  519. u16 max_nrg_cck;
  520. u16 nrg_th_cck;
  521. u16 nrg_th_ofdm;
  522. u16 auto_corr_min_ofdm;
  523. u16 auto_corr_min_ofdm_mrc;
  524. u16 auto_corr_min_ofdm_x1;
  525. u16 auto_corr_min_ofdm_mrc_x1;
  526. u16 auto_corr_max_ofdm;
  527. u16 auto_corr_max_ofdm_mrc;
  528. u16 auto_corr_max_ofdm_x1;
  529. u16 auto_corr_max_ofdm_mrc_x1;
  530. u16 auto_corr_max_cck;
  531. u16 auto_corr_max_cck_mrc;
  532. u16 auto_corr_min_cck;
  533. u16 auto_corr_min_cck_mrc;
  534. u16 barker_corr_th_min;
  535. u16 barker_corr_th_min_mrc;
  536. u16 nrg_th_cca;
  537. };
  538. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  539. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  540. /******************************************************************************
  541. *
  542. * Functions implemented in core module which are forward declared here
  543. * for use by iwl-[4-5].c
  544. *
  545. * NOTE: The implementation of these functions are not hardware specific
  546. * which is why they are in the core module files.
  547. *
  548. * Naming convention --
  549. * iwl_ <-- Is part of iwlwifi
  550. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  551. *
  552. ****************************************************************************/
  553. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  554. extern const u8 iwl_bcast_addr[ETH_ALEN];
  555. extern int iwl_queue_space(const struct iwl_queue *q);
  556. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  557. {
  558. return q->write_ptr >= q->read_ptr ?
  559. (i >= q->read_ptr && i < q->write_ptr) :
  560. !(i < q->read_ptr && i >= q->write_ptr);
  561. }
  562. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
  563. {
  564. return index & (q->n_window - 1);
  565. }
  566. struct iwl_dma_ptr {
  567. dma_addr_t dma;
  568. void *addr;
  569. size_t size;
  570. };
  571. #define IWL_OPERATION_MODE_AUTO 0
  572. #define IWL_OPERATION_MODE_HT_ONLY 1
  573. #define IWL_OPERATION_MODE_MIXED 2
  574. #define IWL_OPERATION_MODE_20MHZ 3
  575. #define IWL_TX_CRC_SIZE 4
  576. #define IWL_TX_DELIMITER_SIZE 4
  577. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  578. /* Sensitivity and chain noise calibration */
  579. #define INITIALIZATION_VALUE 0xFFFF
  580. #define IWL_CAL_NUM_BEACONS 16
  581. #define MAXIMUM_ALLOWED_PATHLOSS 15
  582. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  583. #define MAX_FA_OFDM 50
  584. #define MIN_FA_OFDM 5
  585. #define MAX_FA_CCK 50
  586. #define MIN_FA_CCK 5
  587. #define AUTO_CORR_STEP_OFDM 1
  588. #define AUTO_CORR_STEP_CCK 3
  589. #define AUTO_CORR_MAX_TH_CCK 160
  590. #define NRG_DIFF 2
  591. #define NRG_STEP_CCK 2
  592. #define NRG_MARGIN 8
  593. #define MAX_NUMBER_CCK_NO_FA 100
  594. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  595. #define CHAIN_A 0
  596. #define CHAIN_B 1
  597. #define CHAIN_C 2
  598. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  599. #define ALL_BAND_FILTER 0xFF00
  600. #define IN_BAND_FILTER 0xFF
  601. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  602. #define NRG_NUM_PREV_STAT_L 20
  603. #define NUM_RX_CHAINS 3
  604. enum iwlagn_false_alarm_state {
  605. IWL_FA_TOO_MANY = 0,
  606. IWL_FA_TOO_FEW = 1,
  607. IWL_FA_GOOD_RANGE = 2,
  608. };
  609. enum iwlagn_chain_noise_state {
  610. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  611. IWL_CHAIN_NOISE_ACCUMULATE,
  612. IWL_CHAIN_NOISE_CALIBRATED,
  613. IWL_CHAIN_NOISE_DONE,
  614. };
  615. /*
  616. * enum iwl_calib
  617. * defines the order in which results of initial calibrations
  618. * should be sent to the runtime uCode
  619. */
  620. enum iwl_calib {
  621. IWL_CALIB_XTAL,
  622. IWL_CALIB_DC,
  623. IWL_CALIB_LO,
  624. IWL_CALIB_TX_IQ,
  625. IWL_CALIB_TX_IQ_PERD,
  626. IWL_CALIB_BASE_BAND,
  627. IWL_CALIB_TEMP_OFFSET,
  628. IWL_CALIB_MAX
  629. };
  630. /* Opaque calibration results */
  631. struct iwl_calib_result {
  632. void *buf;
  633. size_t buf_len;
  634. };
  635. /* Sensitivity calib data */
  636. struct iwl_sensitivity_data {
  637. u32 auto_corr_ofdm;
  638. u32 auto_corr_ofdm_mrc;
  639. u32 auto_corr_ofdm_x1;
  640. u32 auto_corr_ofdm_mrc_x1;
  641. u32 auto_corr_cck;
  642. u32 auto_corr_cck_mrc;
  643. u32 last_bad_plcp_cnt_ofdm;
  644. u32 last_fa_cnt_ofdm;
  645. u32 last_bad_plcp_cnt_cck;
  646. u32 last_fa_cnt_cck;
  647. u32 nrg_curr_state;
  648. u32 nrg_prev_state;
  649. u32 nrg_value[10];
  650. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  651. u32 nrg_silence_ref;
  652. u32 nrg_energy_idx;
  653. u32 nrg_silence_idx;
  654. u32 nrg_th_cck;
  655. s32 nrg_auto_corr_silence_diff;
  656. u32 num_in_cck_no_fa;
  657. u32 nrg_th_ofdm;
  658. u16 barker_corr_th_min;
  659. u16 barker_corr_th_min_mrc;
  660. u16 nrg_th_cca;
  661. };
  662. /* Chain noise (differential Rx gain) calib data */
  663. struct iwl_chain_noise_data {
  664. u32 active_chains;
  665. u32 chain_noise_a;
  666. u32 chain_noise_b;
  667. u32 chain_noise_c;
  668. u32 chain_signal_a;
  669. u32 chain_signal_b;
  670. u32 chain_signal_c;
  671. u16 beacon_count;
  672. u8 disconn_array[NUM_RX_CHAINS];
  673. u8 delta_gain_code[NUM_RX_CHAINS];
  674. u8 radio_write;
  675. u8 state;
  676. };
  677. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  678. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  679. #define IWL_TRAFFIC_ENTRIES (256)
  680. #define IWL_TRAFFIC_ENTRY_SIZE (64)
  681. enum {
  682. MEASUREMENT_READY = (1 << 0),
  683. MEASUREMENT_ACTIVE = (1 << 1),
  684. };
  685. enum iwl_nvm_type {
  686. NVM_DEVICE_TYPE_EEPROM = 0,
  687. NVM_DEVICE_TYPE_OTP,
  688. };
  689. /*
  690. * Two types of OTP memory access modes
  691. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  692. * based on physical memory addressing
  693. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  694. * based on logical memory addressing
  695. */
  696. enum iwl_access_mode {
  697. IWL_OTP_ACCESS_ABSOLUTE,
  698. IWL_OTP_ACCESS_RELATIVE,
  699. };
  700. /**
  701. * enum iwl_pa_type - Power Amplifier type
  702. * @IWL_PA_SYSTEM: based on uCode configuration
  703. * @IWL_PA_INTERNAL: use Internal only
  704. */
  705. enum iwl_pa_type {
  706. IWL_PA_SYSTEM = 0,
  707. IWL_PA_INTERNAL = 1,
  708. };
  709. /* reply_tx_statistics (for _agn devices) */
  710. struct reply_tx_error_statistics {
  711. u32 pp_delay;
  712. u32 pp_few_bytes;
  713. u32 pp_bt_prio;
  714. u32 pp_quiet_period;
  715. u32 pp_calc_ttak;
  716. u32 int_crossed_retry;
  717. u32 short_limit;
  718. u32 long_limit;
  719. u32 fifo_underrun;
  720. u32 drain_flow;
  721. u32 rfkill_flush;
  722. u32 life_expire;
  723. u32 dest_ps;
  724. u32 host_abort;
  725. u32 bt_retry;
  726. u32 sta_invalid;
  727. u32 frag_drop;
  728. u32 tid_disable;
  729. u32 fifo_flush;
  730. u32 insuff_cf_poll;
  731. u32 fail_hw_drop;
  732. u32 sta_color_mismatch;
  733. u32 unknown;
  734. };
  735. /* reply_agg_tx_statistics (for _agn devices) */
  736. struct reply_agg_tx_error_statistics {
  737. u32 underrun;
  738. u32 bt_prio;
  739. u32 few_bytes;
  740. u32 abort;
  741. u32 last_sent_ttl;
  742. u32 last_sent_try;
  743. u32 last_sent_bt_kill;
  744. u32 scd_query;
  745. u32 bad_crc32;
  746. u32 response;
  747. u32 dump_tx;
  748. u32 delay_tx;
  749. u32 unknown;
  750. };
  751. /* management statistics */
  752. enum iwl_mgmt_stats {
  753. MANAGEMENT_ASSOC_REQ = 0,
  754. MANAGEMENT_ASSOC_RESP,
  755. MANAGEMENT_REASSOC_REQ,
  756. MANAGEMENT_REASSOC_RESP,
  757. MANAGEMENT_PROBE_REQ,
  758. MANAGEMENT_PROBE_RESP,
  759. MANAGEMENT_BEACON,
  760. MANAGEMENT_ATIM,
  761. MANAGEMENT_DISASSOC,
  762. MANAGEMENT_AUTH,
  763. MANAGEMENT_DEAUTH,
  764. MANAGEMENT_ACTION,
  765. MANAGEMENT_MAX,
  766. };
  767. /* control statistics */
  768. enum iwl_ctrl_stats {
  769. CONTROL_BACK_REQ = 0,
  770. CONTROL_BACK,
  771. CONTROL_PSPOLL,
  772. CONTROL_RTS,
  773. CONTROL_CTS,
  774. CONTROL_ACK,
  775. CONTROL_CFEND,
  776. CONTROL_CFENDACK,
  777. CONTROL_MAX,
  778. };
  779. struct traffic_stats {
  780. #ifdef CONFIG_IWLWIFI_DEBUGFS
  781. u32 mgmt[MANAGEMENT_MAX];
  782. u32 ctrl[CONTROL_MAX];
  783. u32 data_cnt;
  784. u64 data_bytes;
  785. #endif
  786. };
  787. /*
  788. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  789. * to perform continuous uCode event logging operation if enabled
  790. */
  791. #define UCODE_TRACE_PERIOD (100)
  792. /*
  793. * iwl_event_log: current uCode event log position
  794. *
  795. * @ucode_trace: enable/disable ucode continuous trace timer
  796. * @num_wraps: how many times the event buffer wraps
  797. * @next_entry: the entry just before the next one that uCode would fill
  798. * @non_wraps_count: counter for no wrap detected when dump ucode events
  799. * @wraps_once_count: counter for wrap once detected when dump ucode events
  800. * @wraps_more_count: counter for wrap more than once detected
  801. * when dump ucode events
  802. */
  803. struct iwl_event_log {
  804. bool ucode_trace;
  805. u32 num_wraps;
  806. u32 next_entry;
  807. int non_wraps_count;
  808. int wraps_once_count;
  809. int wraps_more_count;
  810. };
  811. /*
  812. * host interrupt timeout value
  813. * used with setting interrupt coalescing timer
  814. * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
  815. *
  816. * default interrupt coalescing timer is 64 x 32 = 2048 usecs
  817. * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
  818. */
  819. #define IWL_HOST_INT_TIMEOUT_MAX (0xFF)
  820. #define IWL_HOST_INT_TIMEOUT_DEF (0x40)
  821. #define IWL_HOST_INT_TIMEOUT_MIN (0x0)
  822. #define IWL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
  823. #define IWL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
  824. #define IWL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
  825. /*
  826. * This is the threshold value of plcp error rate per 100mSecs. It is
  827. * used to set and check for the validity of plcp_delta.
  828. */
  829. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  830. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  831. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  832. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  833. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  834. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  835. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  836. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  837. /* TX queue watchdog timeouts in mSecs */
  838. #define IWL_DEF_WD_TIMEOUT (2000)
  839. #define IWL_LONG_WD_TIMEOUT (10000)
  840. #define IWL_MAX_WD_TIMEOUT (120000)
  841. /* BT Antenna Coupling Threshold (dB) */
  842. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  843. /* Firmware reload counter and Timestamp */
  844. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  845. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  846. enum iwl_reset {
  847. IWL_RF_RESET = 0,
  848. IWL_FW_RESET,
  849. IWL_MAX_FORCE_RESET,
  850. };
  851. struct iwl_force_reset {
  852. int reset_request_count;
  853. int reset_success_count;
  854. int reset_reject_count;
  855. unsigned long reset_duration;
  856. unsigned long last_force_reset_jiffies;
  857. };
  858. /* extend beacon time format bit shifting */
  859. /*
  860. * for _agn devices
  861. * bits 31:22 - extended
  862. * bits 21:0 - interval
  863. */
  864. #define IWLAGN_EXT_BEACON_TIME_POS 22
  865. /**
  866. * struct iwl_notification_wait - notification wait entry
  867. * @list: list head for global list
  868. * @fn: function called with the notification
  869. * @cmd: command ID
  870. *
  871. * This structure is not used directly, to wait for a
  872. * notification declare it on the stack, and call
  873. * iwlagn_init_notification_wait() with appropriate
  874. * parameters. Then do whatever will cause the ucode
  875. * to notify the driver, and to wait for that then
  876. * call iwlagn_wait_notification().
  877. *
  878. * Each notification is one-shot. If at some point we
  879. * need to support multi-shot notifications (which
  880. * can't be allocated on the stack) we need to modify
  881. * the code for them.
  882. */
  883. struct iwl_notification_wait {
  884. struct list_head list;
  885. void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
  886. void *data);
  887. void *fn_data;
  888. u8 cmd;
  889. bool triggered, aborted;
  890. };
  891. enum iwl_rxon_context_id {
  892. IWL_RXON_CTX_BSS,
  893. IWL_RXON_CTX_PAN,
  894. NUM_IWL_RXON_CTX
  895. };
  896. struct iwl_rxon_context {
  897. struct ieee80211_vif *vif;
  898. const u8 *ac_to_fifo;
  899. const u8 *ac_to_queue;
  900. u8 mcast_queue;
  901. /*
  902. * We could use the vif to indicate active, but we
  903. * also need it to be active during disabling when
  904. * we already removed the vif for type setting.
  905. */
  906. bool always_active, is_active;
  907. bool ht_need_multiple_chains;
  908. enum iwl_rxon_context_id ctxid;
  909. u32 interface_modes, exclusive_interface_modes;
  910. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  911. /*
  912. * We declare this const so it can only be
  913. * changed via explicit cast within the
  914. * routines that actually update the physical
  915. * hardware.
  916. */
  917. const struct iwl_rxon_cmd active;
  918. struct iwl_rxon_cmd staging;
  919. struct iwl_rxon_time_cmd timing;
  920. struct iwl_qos_info qos_data;
  921. u8 bcast_sta_id, ap_sta_id;
  922. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  923. u8 qos_cmd;
  924. u8 wep_key_cmd;
  925. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  926. u8 key_mapping_keys;
  927. __le32 station_flags;
  928. int beacon_int;
  929. struct {
  930. bool non_gf_sta_present;
  931. u8 protection;
  932. bool enabled, is_40mhz;
  933. u8 extension_chan_offset;
  934. } ht;
  935. bool last_tx_rejected;
  936. };
  937. enum iwl_scan_type {
  938. IWL_SCAN_NORMAL,
  939. IWL_SCAN_RADIO_RESET,
  940. IWL_SCAN_ROC,
  941. };
  942. enum iwlagn_ucode_type {
  943. IWL_UCODE_NONE,
  944. IWL_UCODE_REGULAR,
  945. IWL_UCODE_INIT,
  946. IWL_UCODE_WOWLAN,
  947. };
  948. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  949. struct iwl_testmode_trace {
  950. u32 buff_size;
  951. u32 total_size;
  952. u32 num_chunks;
  953. u8 *cpu_addr;
  954. u8 *trace_addr;
  955. dma_addr_t dma_addr;
  956. bool trace_enabled;
  957. };
  958. #endif
  959. /* uCode ownership */
  960. #define IWL_OWNERSHIP_DRIVER 0
  961. #define IWL_OWNERSHIP_TM 1
  962. struct iwl_priv {
  963. /*data shared among all the driver's layers */
  964. struct iwl_shared _shrd;
  965. struct iwl_shared *shrd;
  966. /* ieee device used by generic ieee processing code */
  967. struct ieee80211_hw *hw;
  968. struct ieee80211_channel *ieee_channels;
  969. struct ieee80211_rate *ieee_rates;
  970. struct iwl_cfg *cfg;
  971. enum ieee80211_band band;
  972. void (*pre_rx_handler)(struct iwl_priv *priv,
  973. struct iwl_rx_mem_buffer *rxb);
  974. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  975. struct iwl_rx_mem_buffer *rxb);
  976. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  977. /* spectrum measurement report caching */
  978. struct iwl_spectrum_notification measure_report;
  979. u8 measurement_status;
  980. /* ucode beacon time */
  981. u32 ucode_beacon_time;
  982. int missed_beacon_threshold;
  983. /* track IBSS manager (last beacon) status */
  984. u32 ibss_manager;
  985. /* jiffies when last recovery from statistics was performed */
  986. unsigned long rx_statistics_jiffies;
  987. /*counters */
  988. u32 rx_handlers_stats[REPLY_MAX];
  989. /* force reset */
  990. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  991. /* firmware reload counter and timestamp */
  992. unsigned long reload_jiffies;
  993. int reload_count;
  994. /* we allocate array of iwl_channel_info for NIC's valid channels.
  995. * Access via channel # using indirect index array */
  996. struct iwl_channel_info *channel_info; /* channel info array */
  997. u8 channel_count; /* # of channels */
  998. /* thermal calibration */
  999. s32 temperature; /* degrees Kelvin */
  1000. s32 last_temperature;
  1001. /* init calibration results */
  1002. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  1003. /* Scan related variables */
  1004. unsigned long scan_start;
  1005. unsigned long scan_start_tsf;
  1006. void *scan_cmd;
  1007. enum ieee80211_band scan_band;
  1008. struct cfg80211_scan_request *scan_request;
  1009. struct ieee80211_vif *scan_vif;
  1010. enum iwl_scan_type scan_type;
  1011. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  1012. u8 mgmt_tx_ant;
  1013. /* spinlock */
  1014. spinlock_t hcmd_lock; /* protect hcmd */
  1015. spinlock_t reg_lock; /* protect hw register access */
  1016. /*TODO: remove these pointers - use bus(priv) instead */
  1017. struct iwl_bus *bus; /* bus specific data */
  1018. /* microcode/device supports multiple contexts */
  1019. u8 valid_contexts;
  1020. /* max number of station keys */
  1021. u8 sta_key_max_num;
  1022. bool new_scan_threshold_behaviour;
  1023. /* EEPROM MAC addresses */
  1024. struct mac_address addresses[2];
  1025. /* uCode images, save to reload in case of failure */
  1026. int fw_index; /* firmware we're trying to load */
  1027. u32 ucode_ver; /* version of ucode, copy of
  1028. iwl_ucode.ver */
  1029. /* uCode owner: default: IWL_OWNERSHIP_DRIVER */
  1030. u8 ucode_owner;
  1031. struct fw_img ucode_rt;
  1032. struct fw_img ucode_init;
  1033. struct fw_img ucode_wowlan;
  1034. enum iwlagn_ucode_type ucode_type;
  1035. u8 ucode_write_complete; /* the image write is complete */
  1036. char firmware_name[25];
  1037. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  1038. __le16 switch_channel;
  1039. struct {
  1040. u32 error_event_table;
  1041. u32 log_event_table;
  1042. } device_pointers;
  1043. u16 active_rate;
  1044. u8 start_calib;
  1045. struct iwl_sensitivity_data sensitivity_data;
  1046. struct iwl_chain_noise_data chain_noise_data;
  1047. bool enhance_sensitivity_table;
  1048. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  1049. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  1050. struct iwl_ht_config current_ht_config;
  1051. /* Rate scaling data */
  1052. u8 retry_rate;
  1053. wait_queue_head_t wait_command_queue;
  1054. int activity_timer_active;
  1055. /* Tx DMA processing queues */
  1056. struct iwl_tx_queue *txq;
  1057. unsigned long txq_ctx_active_msk;
  1058. struct iwl_dma_ptr kw; /* keep warm address */
  1059. struct iwl_dma_ptr scd_bc_tbls;
  1060. u32 scd_base_addr; /* scheduler sram base address */
  1061. /* counts mgmt, ctl, and data packets */
  1062. struct traffic_stats tx_stats;
  1063. struct traffic_stats rx_stats;
  1064. struct iwl_power_mgr power_data;
  1065. struct iwl_tt_mgmt thermal_throttle;
  1066. /* station table variables */
  1067. int num_stations;
  1068. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  1069. unsigned long ucode_key_table;
  1070. /* queue refcounts */
  1071. #define IWL_MAX_HW_QUEUES 32
  1072. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  1073. /* for each AC */
  1074. atomic_t queue_stop_count[4];
  1075. /* Indication if ieee80211_ops->open has been called */
  1076. u8 is_open;
  1077. u8 mac80211_registered;
  1078. /* eeprom -- this is in the card's little endian byte order */
  1079. u8 *eeprom;
  1080. int nvm_device_type;
  1081. struct iwl_eeprom_calib_info *calib_info;
  1082. enum nl80211_iftype iw_mode;
  1083. /* Last Rx'd beacon timestamp */
  1084. u64 timestamp;
  1085. struct {
  1086. __le32 flag;
  1087. struct statistics_general_common common;
  1088. struct statistics_rx_non_phy rx_non_phy;
  1089. struct statistics_rx_phy rx_ofdm;
  1090. struct statistics_rx_ht_phy rx_ofdm_ht;
  1091. struct statistics_rx_phy rx_cck;
  1092. struct statistics_tx tx;
  1093. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1094. struct statistics_bt_activity bt_activity;
  1095. __le32 num_bt_kills, accum_num_bt_kills;
  1096. #endif
  1097. } statistics;
  1098. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1099. struct {
  1100. struct statistics_general_common common;
  1101. struct statistics_rx_non_phy rx_non_phy;
  1102. struct statistics_rx_phy rx_ofdm;
  1103. struct statistics_rx_ht_phy rx_ofdm_ht;
  1104. struct statistics_rx_phy rx_cck;
  1105. struct statistics_tx tx;
  1106. struct statistics_bt_activity bt_activity;
  1107. } accum_stats, delta_stats, max_delta_stats;
  1108. #endif
  1109. /*
  1110. * reporting the number of tids has AGG on. 0 means
  1111. * no AGGREGATION
  1112. */
  1113. u8 agg_tids_count;
  1114. struct iwl_rx_phy_res last_phy_res;
  1115. bool last_phy_res_valid;
  1116. struct completion firmware_loading_complete;
  1117. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1118. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1119. /*
  1120. * chain noise reset and gain commands are the
  1121. * two extra calibration commands follows the standard
  1122. * phy calibration commands
  1123. */
  1124. u8 phy_calib_chain_noise_reset_cmd;
  1125. u8 phy_calib_chain_noise_gain_cmd;
  1126. /* counts reply_tx error */
  1127. struct reply_tx_error_statistics reply_tx_stats;
  1128. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  1129. /* notification wait support */
  1130. struct list_head notif_waits;
  1131. spinlock_t notif_wait_lock;
  1132. wait_queue_head_t notif_waitq;
  1133. /* remain-on-channel offload support */
  1134. struct ieee80211_channel *hw_roc_channel;
  1135. struct delayed_work hw_roc_disable_work;
  1136. enum nl80211_channel_type hw_roc_chantype;
  1137. int hw_roc_duration;
  1138. bool hw_roc_setup;
  1139. /* bt coex */
  1140. u8 bt_enable_flag;
  1141. u8 bt_status;
  1142. u8 bt_traffic_load, last_bt_traffic_load;
  1143. bool bt_ch_announce;
  1144. bool bt_full_concurrent;
  1145. bool bt_ant_couple_ok;
  1146. __le32 kill_ack_mask;
  1147. __le32 kill_cts_mask;
  1148. __le16 bt_valid;
  1149. u16 bt_on_thresh;
  1150. u16 bt_duration;
  1151. u16 dynamic_frag_thresh;
  1152. u8 bt_ci_compliance;
  1153. struct work_struct bt_traffic_change_work;
  1154. bool bt_enable_pspoll;
  1155. struct iwl_rxon_context *cur_rssi_ctx;
  1156. bool bt_is_sco;
  1157. struct work_struct restart;
  1158. struct work_struct scan_completed;
  1159. struct work_struct abort_scan;
  1160. struct work_struct beacon_update;
  1161. struct iwl_rxon_context *beacon_ctx;
  1162. struct sk_buff *beacon_skb;
  1163. void *beacon_cmd;
  1164. struct work_struct tt_work;
  1165. struct work_struct ct_enter;
  1166. struct work_struct ct_exit;
  1167. struct work_struct start_internal_scan;
  1168. struct work_struct tx_flush;
  1169. struct work_struct bt_full_concurrency;
  1170. struct work_struct bt_runtime_config;
  1171. struct delayed_work scan_check;
  1172. /* TX Power */
  1173. s8 tx_power_user_lmt;
  1174. s8 tx_power_device_lmt;
  1175. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  1176. s8 tx_power_next;
  1177. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1178. /* debugfs */
  1179. u16 tx_traffic_idx;
  1180. u16 rx_traffic_idx;
  1181. u8 *tx_traffic;
  1182. u8 *rx_traffic;
  1183. struct dentry *debugfs_dir;
  1184. u32 dbgfs_sram_offset, dbgfs_sram_len;
  1185. bool disable_ht40;
  1186. void *wowlan_sram;
  1187. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  1188. struct work_struct txpower_work;
  1189. u32 disable_sens_cal;
  1190. u32 disable_chain_noise_cal;
  1191. struct work_struct run_time_calib_work;
  1192. struct timer_list statistics_periodic;
  1193. struct timer_list ucode_trace;
  1194. struct timer_list watchdog;
  1195. struct iwl_event_log event_log;
  1196. struct led_classdev led;
  1197. unsigned long blink_on, blink_off;
  1198. bool led_registered;
  1199. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  1200. struct iwl_testmode_trace testmode_trace;
  1201. u32 tm_fixed_rate;
  1202. #endif
  1203. /* WoWLAN GTK rekey data */
  1204. u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
  1205. __le64 replay_ctr;
  1206. __le16 last_seq_ctl;
  1207. bool have_rekey_data;
  1208. }; /*iwl_priv */
  1209. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1210. {
  1211. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1212. }
  1213. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1214. {
  1215. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1216. }
  1217. extern struct iwl_mod_params iwlagn_mod_params;
  1218. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  1219. int txq_id, int idx)
  1220. {
  1221. if (priv->txq[txq_id].txb[idx].skb)
  1222. return (struct ieee80211_hdr *)priv->txq[txq_id].
  1223. txb[idx].skb->data;
  1224. return NULL;
  1225. }
  1226. static inline struct iwl_rxon_context *
  1227. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  1228. {
  1229. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1230. return vif_priv->ctx;
  1231. }
  1232. #define for_each_context(priv, ctx) \
  1233. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  1234. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  1235. if (priv->valid_contexts & BIT(ctx->ctxid))
  1236. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  1237. {
  1238. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1239. }
  1240. static inline int iwl_is_associated(struct iwl_priv *priv,
  1241. enum iwl_rxon_context_id ctxid)
  1242. {
  1243. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  1244. }
  1245. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  1246. {
  1247. struct iwl_rxon_context *ctx;
  1248. for_each_context(priv, ctx)
  1249. if (iwl_is_associated_ctx(ctx))
  1250. return true;
  1251. return false;
  1252. }
  1253. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  1254. {
  1255. if (ch_info == NULL)
  1256. return 0;
  1257. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  1258. }
  1259. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  1260. {
  1261. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  1262. }
  1263. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  1264. {
  1265. return ch_info->band == IEEE80211_BAND_5GHZ;
  1266. }
  1267. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  1268. {
  1269. return ch_info->band == IEEE80211_BAND_2GHZ;
  1270. }
  1271. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  1272. {
  1273. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  1274. }
  1275. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  1276. {
  1277. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  1278. }
  1279. static inline void __iwl_free_pages(struct iwl_priv *priv, struct page *page)
  1280. {
  1281. __free_pages(page, hw_params(priv).rx_page_order);
  1282. }
  1283. static inline void iwl_free_pages(struct iwl_priv *priv, unsigned long page)
  1284. {
  1285. free_pages(page, hw_params(priv).rx_page_order);
  1286. }
  1287. #endif /* __iwl_dev_h__ */