iwl-dev.h 44 KB

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