iwl-dev.h 43 KB

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