iwl-dev.h 45 KB

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