iwl-dev.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 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. * Please use iwl-4965-hw.h for hardware-related definitions.
  30. */
  31. #ifndef __iwl_dev_h__
  32. #define __iwl_dev_h__
  33. #include <linux/pci.h> /* for struct pci_device_id */
  34. #include <linux/kernel.h>
  35. #include <net/ieee80211_radiotap.h>
  36. #include "iwl-eeprom.h"
  37. #include "iwl-csr.h"
  38. #include "iwl-prph.h"
  39. #include "iwl-fh.h"
  40. #include "iwl-debug.h"
  41. #include "iwl-4965-hw.h"
  42. #include "iwl-3945-hw.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. 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 100U
  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. /* The CMD_SIZE_HUGE flag bit indicates that the command
  103. * structure is stored at the end of the shared queue memory. */
  104. u32 flags;
  105. DEFINE_DMA_UNMAP_ADDR(mapping);
  106. DEFINE_DMA_UNMAP_LEN(len);
  107. };
  108. /*
  109. * Generic queue structure
  110. *
  111. * Contains common data for Rx and Tx queues
  112. */
  113. struct iwl_queue {
  114. int n_bd; /* number of BDs in this queue */
  115. int write_ptr; /* 1-st empty entry (index) host_w*/
  116. int read_ptr; /* last used entry (index) host_r*/
  117. /* use for monitoring and recovering the stuck queue */
  118. int last_read_ptr; /* storing the last read_ptr */
  119. /* number of time read_ptr and last_read_ptr are the same */
  120. u8 repeat_same_read_ptr;
  121. dma_addr_t dma_addr; /* physical addr for BD's */
  122. int n_window; /* safe queue window */
  123. u32 id;
  124. int low_mark; /* low watermark, resume queue if free
  125. * space more than this */
  126. int high_mark; /* high watermark, stop queue if free
  127. * space less than this */
  128. } __packed;
  129. /* One for each TFD */
  130. struct iwl_tx_info {
  131. struct sk_buff *skb;
  132. struct iwl_rxon_context *ctx;
  133. };
  134. /**
  135. * struct iwl_tx_queue - Tx Queue for DMA
  136. * @q: generic Rx/Tx queue descriptor
  137. * @bd: base of circular buffer of TFDs
  138. * @cmd: array of command/TX buffer pointers
  139. * @meta: array of meta data for each command/tx buffer
  140. * @dma_addr_cmd: physical address of cmd/tx buffer array
  141. * @txb: array of per-TFD driver data
  142. * @need_update: indicates need to update read/write index
  143. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  144. *
  145. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  146. * descriptors) and required locking structures.
  147. */
  148. #define TFD_TX_CMD_SLOTS 256
  149. #define TFD_CMD_SLOTS 32
  150. struct iwl_tx_queue {
  151. struct iwl_queue q;
  152. void *tfds;
  153. struct iwl_device_cmd **cmd;
  154. struct iwl_cmd_meta *meta;
  155. struct iwl_tx_info *txb;
  156. u8 need_update;
  157. u8 sched_retry;
  158. u8 active;
  159. u8 swq_id;
  160. };
  161. #define IWL_NUM_SCAN_RATES (2)
  162. struct iwl4965_channel_tgd_info {
  163. u8 type;
  164. s8 max_power;
  165. };
  166. struct iwl4965_channel_tgh_info {
  167. s64 last_radar_time;
  168. };
  169. #define IWL4965_MAX_RATE (33)
  170. struct iwl3945_clip_group {
  171. /* maximum power level to prevent clipping for each rate, derived by
  172. * us from this band's saturation power in EEPROM */
  173. const s8 clip_powers[IWL_MAX_RATES];
  174. };
  175. /* current Tx power values to use, one for each rate for each channel.
  176. * requested power is limited by:
  177. * -- regulatory EEPROM limits for this channel
  178. * -- hardware capabilities (clip-powers)
  179. * -- spectrum management
  180. * -- user preference (e.g. iwconfig)
  181. * when requested power is set, base power index must also be set. */
  182. struct iwl3945_channel_power_info {
  183. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  184. s8 power_table_index; /* actual (compenst'd) index into gain table */
  185. s8 base_power_index; /* gain index for power at factory temp. */
  186. s8 requested_power; /* power (dBm) requested for this chnl/rate */
  187. };
  188. /* current scan Tx power values to use, one for each scan rate for each
  189. * channel. */
  190. struct iwl3945_scan_power_info {
  191. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  192. s8 power_table_index; /* actual (compenst'd) index into gain table */
  193. s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
  194. };
  195. /*
  196. * One for each channel, holds all channel setup data
  197. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  198. * with one another!
  199. */
  200. struct iwl_channel_info {
  201. struct iwl4965_channel_tgd_info tgd;
  202. struct iwl4965_channel_tgh_info tgh;
  203. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  204. struct iwl_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
  205. * HT40 channel */
  206. u8 channel; /* channel number */
  207. u8 flags; /* flags copied from EEPROM */
  208. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  209. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  210. s8 min_power; /* always 0 */
  211. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  212. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  213. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  214. enum ieee80211_band band;
  215. /* HT40 channel info */
  216. s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  217. u8 ht40_flags; /* flags copied from EEPROM */
  218. u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  219. /* Radio/DSP gain settings for each "normal" data Tx rate.
  220. * These include, in addition to RF and DSP gain, a few fields for
  221. * remembering/modifying gain settings (indexes). */
  222. struct iwl3945_channel_power_info power_info[IWL4965_MAX_RATE];
  223. /* Radio/DSP gain settings for each scan rate, for directed scans. */
  224. struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
  225. };
  226. #define IWL_TX_FIFO_BK 0 /* shared */
  227. #define IWL_TX_FIFO_BE 1
  228. #define IWL_TX_FIFO_VI 2 /* shared */
  229. #define IWL_TX_FIFO_VO 3
  230. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  231. #define IWL_TX_FIFO_BE_IPAN 4
  232. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  233. #define IWL_TX_FIFO_VO_IPAN 5
  234. #define IWL_TX_FIFO_UNUSED -1
  235. /* Minimum number of queues. MAX_NUM is defined in hw specific files.
  236. * Set the minimum to accommodate the 4 standard TX queues, 1 command
  237. * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
  238. #define IWL_MIN_NUM_QUEUES 10
  239. /*
  240. * Command queue depends on iPAN support.
  241. */
  242. #define IWL_DEFAULT_CMD_QUEUE_NUM 4
  243. #define IWL_IPAN_CMD_QUEUE_NUM 9
  244. /*
  245. * This queue number is required for proper operation
  246. * because the ucode will stop/start the scheduler as
  247. * required.
  248. */
  249. #define IWL_IPAN_MCAST_QUEUE 8
  250. /* Power management (not Tx power) structures */
  251. enum iwl_pwr_src {
  252. IWL_PWR_SRC_VMAIN,
  253. IWL_PWR_SRC_VAUX,
  254. };
  255. #define IEEE80211_DATA_LEN 2304
  256. #define IEEE80211_4ADDR_LEN 30
  257. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  258. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  259. struct iwl_frame {
  260. union {
  261. struct ieee80211_hdr frame;
  262. struct iwl_tx_beacon_cmd beacon;
  263. u8 raw[IEEE80211_FRAME_LEN];
  264. u8 cmd[360];
  265. } u;
  266. struct list_head list;
  267. };
  268. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  269. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  270. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  271. enum {
  272. CMD_SYNC = 0,
  273. CMD_SIZE_NORMAL = 0,
  274. CMD_NO_SKB = 0,
  275. CMD_SIZE_HUGE = (1 << 0),
  276. CMD_ASYNC = (1 << 1),
  277. CMD_WANT_SKB = (1 << 2),
  278. };
  279. #define DEF_CMD_PAYLOAD_SIZE 320
  280. /**
  281. * struct iwl_device_cmd
  282. *
  283. * For allocation of the command and tx queues, this establishes the overall
  284. * size of the largest command we send to uCode, except for a scan command
  285. * (which is relatively huge; space is allocated separately).
  286. */
  287. struct iwl_device_cmd {
  288. struct iwl_cmd_header hdr; /* uCode API */
  289. union {
  290. u32 flags;
  291. u8 val8;
  292. u16 val16;
  293. u32 val32;
  294. struct iwl_tx_cmd tx;
  295. struct iwl6000_channel_switch_cmd chswitch;
  296. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  297. } __packed cmd;
  298. } __packed;
  299. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  300. struct iwl_host_cmd {
  301. const void *data;
  302. unsigned long reply_page;
  303. void (*callback)(struct iwl_priv *priv,
  304. struct iwl_device_cmd *cmd,
  305. struct iwl_rx_packet *pkt);
  306. u32 flags;
  307. u16 len;
  308. u8 id;
  309. };
  310. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  311. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  312. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  313. /**
  314. * struct iwl_rx_queue - Rx queue
  315. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  316. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  317. * @read: Shared index to newest available Rx buffer
  318. * @write: Shared index to oldest written Rx packet
  319. * @free_count: Number of pre-allocated buffers in rx_free
  320. * @rx_free: list of free SKBs for use
  321. * @rx_used: List of Rx buffers with no SKB
  322. * @need_update: flag to indicate we need to update read/write index
  323. * @rb_stts: driver's pointer to receive buffer status
  324. * @rb_stts_dma: bus address of receive buffer status
  325. *
  326. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  327. */
  328. struct iwl_rx_queue {
  329. __le32 *bd;
  330. dma_addr_t bd_dma;
  331. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  332. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  333. u32 read;
  334. u32 write;
  335. u32 free_count;
  336. u32 write_actual;
  337. struct list_head rx_free;
  338. struct list_head rx_used;
  339. int need_update;
  340. struct iwl_rb_status *rb_stts;
  341. dma_addr_t rb_stts_dma;
  342. spinlock_t lock;
  343. };
  344. #define IWL_SUPPORTED_RATES_IE_LEN 8
  345. #define MAX_TID_COUNT 9
  346. #define IWL_INVALID_RATE 0xFF
  347. #define IWL_INVALID_VALUE -1
  348. /**
  349. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  350. * @txq_id: Tx queue used for Tx attempt
  351. * @frame_count: # frames attempted by Tx command
  352. * @wait_for_ba: Expect block-ack before next Tx reply
  353. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  354. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  355. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  356. * @rate_n_flags: Rate at which Tx was attempted
  357. *
  358. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  359. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  360. * until block ack arrives.
  361. */
  362. struct iwl_ht_agg {
  363. u16 txq_id;
  364. u16 frame_count;
  365. u16 wait_for_ba;
  366. u16 start_idx;
  367. u64 bitmap;
  368. u32 rate_n_flags;
  369. #define IWL_AGG_OFF 0
  370. #define IWL_AGG_ON 1
  371. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  372. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  373. u8 state;
  374. };
  375. struct iwl_tid_data {
  376. u16 seq_number; /* agn only */
  377. u16 tfds_in_queue;
  378. struct iwl_ht_agg agg;
  379. };
  380. struct iwl_hw_key {
  381. u32 cipher;
  382. int keylen;
  383. u8 keyidx;
  384. u8 key[32];
  385. };
  386. union iwl_ht_rate_supp {
  387. u16 rates;
  388. struct {
  389. u8 siso_rate;
  390. u8 mimo_rate;
  391. };
  392. };
  393. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  394. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  395. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  396. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  397. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  398. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  399. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  400. /*
  401. * Maximal MPDU density for TX aggregation
  402. * 4 - 2us density
  403. * 5 - 4us density
  404. * 6 - 8us density
  405. * 7 - 16us density
  406. */
  407. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  408. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  409. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  410. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  411. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  412. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  413. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  414. struct iwl_ht_config {
  415. /* self configuration data */
  416. bool is_ht;
  417. bool is_40mhz;
  418. bool single_chain_sufficient;
  419. enum ieee80211_smps_mode smps; /* current smps mode */
  420. /* BSS related data */
  421. u8 extension_chan_offset;
  422. u8 ht_protection;
  423. u8 non_GF_STA_present;
  424. };
  425. /* QoS structures */
  426. struct iwl_qos_info {
  427. int qos_active;
  428. struct iwl_qosparam_cmd def_qos_parm;
  429. };
  430. /*
  431. * Structure should be accessed with sta_lock held. When station addition
  432. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  433. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  434. * held.
  435. */
  436. struct iwl_station_entry {
  437. struct iwl_addsta_cmd sta;
  438. struct iwl_tid_data tid[MAX_TID_COUNT];
  439. u8 used, ctxid;
  440. struct iwl_hw_key keyinfo;
  441. struct iwl_link_quality_cmd *lq;
  442. };
  443. struct iwl_station_priv_common {
  444. u8 sta_id;
  445. };
  446. /*
  447. * iwl_station_priv: Driver's private station information
  448. *
  449. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  450. * in the structure for use by driver. This structure is places in that
  451. * space.
  452. *
  453. * The common struct MUST be first because it is shared between
  454. * 3945 and agn!
  455. */
  456. struct iwl_station_priv {
  457. struct iwl_station_priv_common common;
  458. struct iwl_lq_sta lq_sta;
  459. atomic_t pending_frames;
  460. bool client;
  461. bool asleep;
  462. };
  463. /**
  464. * struct iwl_vif_priv - driver's private per-interface information
  465. *
  466. * When mac80211 allocates a virtual interface, it can allocate
  467. * space for us to put data into.
  468. */
  469. struct iwl_vif_priv {
  470. struct iwl_rxon_context *ctx;
  471. u8 ibss_bssid_sta_id;
  472. };
  473. /* one for each uCode image (inst/data, boot/init/runtime) */
  474. struct fw_desc {
  475. void *v_addr; /* access by driver */
  476. dma_addr_t p_addr; /* access by card's busmaster DMA */
  477. u32 len; /* bytes */
  478. };
  479. /* v1/v2 uCode file layout */
  480. struct iwl_ucode_header {
  481. __le32 ver; /* major/minor/API/serial */
  482. union {
  483. struct {
  484. __le32 inst_size; /* bytes of runtime code */
  485. __le32 data_size; /* bytes of runtime data */
  486. __le32 init_size; /* bytes of init code */
  487. __le32 init_data_size; /* bytes of init data */
  488. __le32 boot_size; /* bytes of bootstrap code */
  489. u8 data[0]; /* in same order as sizes */
  490. } v1;
  491. struct {
  492. __le32 build; /* build number */
  493. __le32 inst_size; /* bytes of runtime code */
  494. __le32 data_size; /* bytes of runtime data */
  495. __le32 init_size; /* bytes of init code */
  496. __le32 init_data_size; /* bytes of init data */
  497. __le32 boot_size; /* bytes of bootstrap code */
  498. u8 data[0]; /* in same order as sizes */
  499. } v2;
  500. } u;
  501. };
  502. /*
  503. * new TLV uCode file layout
  504. *
  505. * The new TLV file format contains TLVs, that each specify
  506. * some piece of data. To facilitate "groups", for example
  507. * different instruction image with different capabilities,
  508. * bundled with the same init image, an alternative mechanism
  509. * is provided:
  510. * When the alternative field is 0, that means that the item
  511. * is always valid. When it is non-zero, then it is only
  512. * valid in conjunction with items of the same alternative,
  513. * in which case the driver (user) selects one alternative
  514. * to use.
  515. */
  516. enum iwl_ucode_tlv_type {
  517. IWL_UCODE_TLV_INVALID = 0, /* unused */
  518. IWL_UCODE_TLV_INST = 1,
  519. IWL_UCODE_TLV_DATA = 2,
  520. IWL_UCODE_TLV_INIT = 3,
  521. IWL_UCODE_TLV_INIT_DATA = 4,
  522. IWL_UCODE_TLV_BOOT = 5,
  523. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  524. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  525. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  526. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  527. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  528. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  529. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  530. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  531. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  532. };
  533. struct iwl_ucode_tlv {
  534. __le16 type; /* see above */
  535. __le16 alternative; /* see comment */
  536. __le32 length; /* not including type/length fields */
  537. u8 data[0];
  538. } __packed;
  539. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  540. struct iwl_tlv_ucode_header {
  541. /*
  542. * The TLV style ucode header is distinguished from
  543. * the v1/v2 style header by first four bytes being
  544. * zero, as such is an invalid combination of
  545. * major/minor/API/serial versions.
  546. */
  547. __le32 zero;
  548. __le32 magic;
  549. u8 human_readable[64];
  550. __le32 ver; /* major/minor/API/serial */
  551. __le32 build;
  552. __le64 alternatives; /* bitmask of valid alternatives */
  553. /*
  554. * The data contained herein has a TLV layout,
  555. * see above for the TLV header and types.
  556. * Note that each TLV is padded to a length
  557. * that is a multiple of 4 for alignment.
  558. */
  559. u8 data[0];
  560. };
  561. struct iwl4965_ibss_seq {
  562. u8 mac[ETH_ALEN];
  563. u16 seq_num;
  564. u16 frag_num;
  565. unsigned long packet_time;
  566. struct list_head list;
  567. };
  568. struct iwl_sensitivity_ranges {
  569. u16 min_nrg_cck;
  570. u16 max_nrg_cck;
  571. u16 nrg_th_cck;
  572. u16 nrg_th_ofdm;
  573. u16 auto_corr_min_ofdm;
  574. u16 auto_corr_min_ofdm_mrc;
  575. u16 auto_corr_min_ofdm_x1;
  576. u16 auto_corr_min_ofdm_mrc_x1;
  577. u16 auto_corr_max_ofdm;
  578. u16 auto_corr_max_ofdm_mrc;
  579. u16 auto_corr_max_ofdm_x1;
  580. u16 auto_corr_max_ofdm_mrc_x1;
  581. u16 auto_corr_max_cck;
  582. u16 auto_corr_max_cck_mrc;
  583. u16 auto_corr_min_cck;
  584. u16 auto_corr_min_cck_mrc;
  585. u16 barker_corr_th_min;
  586. u16 barker_corr_th_min_mrc;
  587. u16 nrg_th_cca;
  588. };
  589. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  590. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  591. /**
  592. * struct iwl_hw_params
  593. * @max_txq_num: Max # Tx queues supported
  594. * @dma_chnl_num: Number of Tx DMA/FIFO channels
  595. * @scd_bc_tbls_size: size of scheduler byte count tables
  596. * @tfd_size: TFD size
  597. * @tx/rx_chains_num: Number of TX/RX chains
  598. * @valid_tx/rx_ant: usable antennas
  599. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  600. * @max_rxq_log: Log-base-2 of max_rxq_size
  601. * @rx_page_order: Rx buffer page order
  602. * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
  603. * @max_stations:
  604. * @ht40_channel: is 40MHz width possible in band 2.4
  605. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  606. * @sw_crypto: 0 for hw, 1 for sw
  607. * @max_xxx_size: for ucode uses
  608. * @ct_kill_threshold: temperature threshold
  609. * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
  610. * @calib_init_cfg: setup initial calibrations for the hw
  611. * @struct iwl_sensitivity_ranges: range of sensitivity values
  612. */
  613. struct iwl_hw_params {
  614. u8 max_txq_num;
  615. u8 dma_chnl_num;
  616. u16 scd_bc_tbls_size;
  617. u32 tfd_size;
  618. u8 tx_chains_num;
  619. u8 rx_chains_num;
  620. u8 valid_tx_ant;
  621. u8 valid_rx_ant;
  622. u16 max_rxq_size;
  623. u16 max_rxq_log;
  624. u32 rx_page_order;
  625. u32 rx_wrt_ptr_reg;
  626. u8 max_stations;
  627. u8 ht40_channel;
  628. u8 max_beacon_itrvl; /* in 1024 ms */
  629. u32 max_inst_size;
  630. u32 max_data_size;
  631. u32 max_bsm_size;
  632. u32 ct_kill_threshold; /* value in hw-dependent units */
  633. u32 ct_kill_exit_threshold; /* value in hw-dependent units */
  634. /* for 1000, 6000 series and up */
  635. u16 beacon_time_tsf_bits;
  636. u32 calib_init_cfg;
  637. const struct iwl_sensitivity_ranges *sens;
  638. };
  639. /******************************************************************************
  640. *
  641. * Functions implemented in core module which are forward declared here
  642. * for use by iwl-[4-5].c
  643. *
  644. * NOTE: The implementation of these functions are not hardware specific
  645. * which is why they are in the core module files.
  646. *
  647. * Naming convention --
  648. * iwl_ <-- Is part of iwlwifi
  649. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  650. * iwl4965_bg_ <-- Called from work queue context
  651. * iwl4965_mac_ <-- mac80211 callback
  652. *
  653. ****************************************************************************/
  654. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  655. extern int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
  656. extern const u8 iwl_bcast_addr[ETH_ALEN];
  657. extern int iwl_rxq_stop(struct iwl_priv *priv);
  658. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  659. extern int iwl_queue_space(const struct iwl_queue *q);
  660. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  661. {
  662. return q->write_ptr >= q->read_ptr ?
  663. (i >= q->read_ptr && i < q->write_ptr) :
  664. !(i < q->read_ptr && i >= q->write_ptr);
  665. }
  666. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
  667. {
  668. /*
  669. * This is for init calibration result and scan command which
  670. * required buffer > TFD_MAX_PAYLOAD_SIZE,
  671. * the big buffer at end of command array
  672. */
  673. if (is_huge)
  674. return q->n_window; /* must be power of 2 */
  675. /* Otherwise, use normal size buffers */
  676. return index & (q->n_window - 1);
  677. }
  678. struct iwl_dma_ptr {
  679. dma_addr_t dma;
  680. void *addr;
  681. size_t size;
  682. };
  683. #define IWL_OPERATION_MODE_AUTO 0
  684. #define IWL_OPERATION_MODE_HT_ONLY 1
  685. #define IWL_OPERATION_MODE_MIXED 2
  686. #define IWL_OPERATION_MODE_20MHZ 3
  687. #define IWL_TX_CRC_SIZE 4
  688. #define IWL_TX_DELIMITER_SIZE 4
  689. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  690. /* Sensitivity and chain noise calibration */
  691. #define INITIALIZATION_VALUE 0xFFFF
  692. #define IWL4965_CAL_NUM_BEACONS 20
  693. #define IWL_CAL_NUM_BEACONS 16
  694. #define MAXIMUM_ALLOWED_PATHLOSS 15
  695. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  696. #define MAX_FA_OFDM 50
  697. #define MIN_FA_OFDM 5
  698. #define MAX_FA_CCK 50
  699. #define MIN_FA_CCK 5
  700. #define AUTO_CORR_STEP_OFDM 1
  701. #define AUTO_CORR_STEP_CCK 3
  702. #define AUTO_CORR_MAX_TH_CCK 160
  703. #define NRG_DIFF 2
  704. #define NRG_STEP_CCK 2
  705. #define NRG_MARGIN 8
  706. #define MAX_NUMBER_CCK_NO_FA 100
  707. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  708. #define CHAIN_A 0
  709. #define CHAIN_B 1
  710. #define CHAIN_C 2
  711. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  712. #define ALL_BAND_FILTER 0xFF00
  713. #define IN_BAND_FILTER 0xFF
  714. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  715. #define NRG_NUM_PREV_STAT_L 20
  716. #define NUM_RX_CHAINS 3
  717. enum iwl4965_false_alarm_state {
  718. IWL_FA_TOO_MANY = 0,
  719. IWL_FA_TOO_FEW = 1,
  720. IWL_FA_GOOD_RANGE = 2,
  721. };
  722. enum iwl4965_chain_noise_state {
  723. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  724. IWL_CHAIN_NOISE_ACCUMULATE,
  725. IWL_CHAIN_NOISE_CALIBRATED,
  726. IWL_CHAIN_NOISE_DONE,
  727. };
  728. enum iwl4965_calib_enabled_state {
  729. IWL_CALIB_DISABLED = 0, /* must be 0 */
  730. IWL_CALIB_ENABLED = 1,
  731. };
  732. /*
  733. * enum iwl_calib
  734. * defines the order in which results of initial calibrations
  735. * should be sent to the runtime uCode
  736. */
  737. enum iwl_calib {
  738. IWL_CALIB_XTAL,
  739. IWL_CALIB_DC,
  740. IWL_CALIB_LO,
  741. IWL_CALIB_TX_IQ,
  742. IWL_CALIB_TX_IQ_PERD,
  743. IWL_CALIB_BASE_BAND,
  744. IWL_CALIB_MAX
  745. };
  746. /* Opaque calibration results */
  747. struct iwl_calib_result {
  748. void *buf;
  749. size_t buf_len;
  750. };
  751. enum ucode_type {
  752. UCODE_NONE = 0,
  753. UCODE_INIT,
  754. UCODE_RT
  755. };
  756. /* Sensitivity calib data */
  757. struct iwl_sensitivity_data {
  758. u32 auto_corr_ofdm;
  759. u32 auto_corr_ofdm_mrc;
  760. u32 auto_corr_ofdm_x1;
  761. u32 auto_corr_ofdm_mrc_x1;
  762. u32 auto_corr_cck;
  763. u32 auto_corr_cck_mrc;
  764. u32 last_bad_plcp_cnt_ofdm;
  765. u32 last_fa_cnt_ofdm;
  766. u32 last_bad_plcp_cnt_cck;
  767. u32 last_fa_cnt_cck;
  768. u32 nrg_curr_state;
  769. u32 nrg_prev_state;
  770. u32 nrg_value[10];
  771. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  772. u32 nrg_silence_ref;
  773. u32 nrg_energy_idx;
  774. u32 nrg_silence_idx;
  775. u32 nrg_th_cck;
  776. s32 nrg_auto_corr_silence_diff;
  777. u32 num_in_cck_no_fa;
  778. u32 nrg_th_ofdm;
  779. u16 barker_corr_th_min;
  780. u16 barker_corr_th_min_mrc;
  781. u16 nrg_th_cca;
  782. };
  783. /* Chain noise (differential Rx gain) calib data */
  784. struct iwl_chain_noise_data {
  785. u32 active_chains;
  786. u32 chain_noise_a;
  787. u32 chain_noise_b;
  788. u32 chain_noise_c;
  789. u32 chain_signal_a;
  790. u32 chain_signal_b;
  791. u32 chain_signal_c;
  792. u16 beacon_count;
  793. u8 disconn_array[NUM_RX_CHAINS];
  794. u8 delta_gain_code[NUM_RX_CHAINS];
  795. u8 radio_write;
  796. u8 state;
  797. };
  798. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  799. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  800. #define IWL_TRAFFIC_ENTRIES (256)
  801. #define IWL_TRAFFIC_ENTRY_SIZE (64)
  802. enum {
  803. MEASUREMENT_READY = (1 << 0),
  804. MEASUREMENT_ACTIVE = (1 << 1),
  805. };
  806. enum iwl_nvm_type {
  807. NVM_DEVICE_TYPE_EEPROM = 0,
  808. NVM_DEVICE_TYPE_OTP,
  809. };
  810. /*
  811. * Two types of OTP memory access modes
  812. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  813. * based on physical memory addressing
  814. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  815. * based on logical memory addressing
  816. */
  817. enum iwl_access_mode {
  818. IWL_OTP_ACCESS_ABSOLUTE,
  819. IWL_OTP_ACCESS_RELATIVE,
  820. };
  821. /**
  822. * enum iwl_pa_type - Power Amplifier type
  823. * @IWL_PA_SYSTEM: based on uCode configuration
  824. * @IWL_PA_INTERNAL: use Internal only
  825. */
  826. enum iwl_pa_type {
  827. IWL_PA_SYSTEM = 0,
  828. IWL_PA_INTERNAL = 1,
  829. };
  830. /* interrupt statistics */
  831. struct isr_statistics {
  832. u32 hw;
  833. u32 sw;
  834. u32 sw_err;
  835. u32 sch;
  836. u32 alive;
  837. u32 rfkill;
  838. u32 ctkill;
  839. u32 wakeup;
  840. u32 rx;
  841. u32 rx_handlers[REPLY_MAX];
  842. u32 tx;
  843. u32 unhandled;
  844. };
  845. #ifdef CONFIG_IWLWIFI_DEBUGFS
  846. /* management statistics */
  847. enum iwl_mgmt_stats {
  848. MANAGEMENT_ASSOC_REQ = 0,
  849. MANAGEMENT_ASSOC_RESP,
  850. MANAGEMENT_REASSOC_REQ,
  851. MANAGEMENT_REASSOC_RESP,
  852. MANAGEMENT_PROBE_REQ,
  853. MANAGEMENT_PROBE_RESP,
  854. MANAGEMENT_BEACON,
  855. MANAGEMENT_ATIM,
  856. MANAGEMENT_DISASSOC,
  857. MANAGEMENT_AUTH,
  858. MANAGEMENT_DEAUTH,
  859. MANAGEMENT_ACTION,
  860. MANAGEMENT_MAX,
  861. };
  862. /* control statistics */
  863. enum iwl_ctrl_stats {
  864. CONTROL_BACK_REQ = 0,
  865. CONTROL_BACK,
  866. CONTROL_PSPOLL,
  867. CONTROL_RTS,
  868. CONTROL_CTS,
  869. CONTROL_ACK,
  870. CONTROL_CFEND,
  871. CONTROL_CFENDACK,
  872. CONTROL_MAX,
  873. };
  874. struct traffic_stats {
  875. u32 mgmt[MANAGEMENT_MAX];
  876. u32 ctrl[CONTROL_MAX];
  877. u32 data_cnt;
  878. u64 data_bytes;
  879. };
  880. #else
  881. struct traffic_stats {
  882. u64 data_bytes;
  883. };
  884. #endif
  885. /*
  886. * iwl_switch_rxon: "channel switch" structure
  887. *
  888. * @ switch_in_progress: channel switch in progress
  889. * @ channel: new channel
  890. */
  891. struct iwl_switch_rxon {
  892. bool switch_in_progress;
  893. __le16 channel;
  894. };
  895. /*
  896. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  897. * to perform continuous uCode event logging operation if enabled
  898. */
  899. #define UCODE_TRACE_PERIOD (100)
  900. /*
  901. * iwl_event_log: current uCode event log position
  902. *
  903. * @ucode_trace: enable/disable ucode continuous trace timer
  904. * @num_wraps: how many times the event buffer wraps
  905. * @next_entry: the entry just before the next one that uCode would fill
  906. * @non_wraps_count: counter for no wrap detected when dump ucode events
  907. * @wraps_once_count: counter for wrap once detected when dump ucode events
  908. * @wraps_more_count: counter for wrap more than once detected
  909. * when dump ucode events
  910. */
  911. struct iwl_event_log {
  912. bool ucode_trace;
  913. u32 num_wraps;
  914. u32 next_entry;
  915. int non_wraps_count;
  916. int wraps_once_count;
  917. int wraps_more_count;
  918. };
  919. /*
  920. * host interrupt timeout value
  921. * used with setting interrupt coalescing timer
  922. * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
  923. *
  924. * default interrupt coalescing timer is 64 x 32 = 2048 usecs
  925. * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
  926. */
  927. #define IWL_HOST_INT_TIMEOUT_MAX (0xFF)
  928. #define IWL_HOST_INT_TIMEOUT_DEF (0x40)
  929. #define IWL_HOST_INT_TIMEOUT_MIN (0x0)
  930. #define IWL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
  931. #define IWL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
  932. #define IWL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
  933. /*
  934. * This is the threshold value of plcp error rate per 100mSecs. It is
  935. * used to set and check for the validity of plcp_delta.
  936. */
  937. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  938. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  939. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  940. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  941. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  942. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  943. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  944. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  945. /* timer constants use to monitor and recover stuck tx queues in mSecs */
  946. #define IWL_DEF_MONITORING_PERIOD (1000)
  947. #define IWL_LONG_MONITORING_PERIOD (5000)
  948. #define IWL_ONE_HUNDRED_MSECS (100)
  949. #define IWL_MAX_MONITORING_PERIOD (60000)
  950. /* BT Antenna Coupling Threshold (dB) */
  951. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  952. enum iwl_reset {
  953. IWL_RF_RESET = 0,
  954. IWL_FW_RESET,
  955. IWL_MAX_FORCE_RESET,
  956. };
  957. struct iwl_force_reset {
  958. int reset_request_count;
  959. int reset_success_count;
  960. int reset_reject_count;
  961. unsigned long reset_duration;
  962. unsigned long last_force_reset_jiffies;
  963. };
  964. /* extend beacon time format bit shifting */
  965. /*
  966. * for _3945 devices
  967. * bits 31:24 - extended
  968. * bits 23:0 - interval
  969. */
  970. #define IWL3945_EXT_BEACON_TIME_POS 24
  971. /*
  972. * for _agn devices
  973. * bits 31:22 - extended
  974. * bits 21:0 - interval
  975. */
  976. #define IWLAGN_EXT_BEACON_TIME_POS 22
  977. enum iwl_rxon_context_id {
  978. IWL_RXON_CTX_BSS,
  979. NUM_IWL_RXON_CTX
  980. };
  981. struct iwl_rxon_context {
  982. struct ieee80211_vif *vif;
  983. enum iwl_rxon_context_id ctxid;
  984. /*
  985. * We declare this const so it can only be
  986. * changed via explicit cast within the
  987. * routines that actually update the physical
  988. * hardware.
  989. */
  990. const struct iwl_rxon_cmd active;
  991. struct iwl_rxon_cmd staging;
  992. struct iwl_rxon_time_cmd timing;
  993. struct iwl_qos_info qos_data;
  994. u8 bcast_sta_id, ap_sta_id;
  995. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  996. u8 qos_cmd;
  997. };
  998. struct iwl_priv {
  999. /* ieee device used by generic ieee processing code */
  1000. struct ieee80211_hw *hw;
  1001. struct ieee80211_channel *ieee_channels;
  1002. struct ieee80211_rate *ieee_rates;
  1003. struct iwl_cfg *cfg;
  1004. /* temporary frame storage list */
  1005. struct list_head free_frames;
  1006. int frames_count;
  1007. enum ieee80211_band band;
  1008. int alloc_rxb_page;
  1009. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  1010. struct iwl_rx_mem_buffer *rxb);
  1011. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  1012. /* spectrum measurement report caching */
  1013. struct iwl_spectrum_notification measure_report;
  1014. u8 measurement_status;
  1015. /* ucode beacon time */
  1016. u32 ucode_beacon_time;
  1017. int missed_beacon_threshold;
  1018. /* track IBSS manager (last beacon) status */
  1019. u32 ibss_manager;
  1020. /* storing the jiffies when the plcp error rate is received */
  1021. unsigned long plcp_jiffies;
  1022. /* force reset */
  1023. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  1024. /* we allocate array of iwl_channel_info for NIC's valid channels.
  1025. * Access via channel # using indirect index array */
  1026. struct iwl_channel_info *channel_info; /* channel info array */
  1027. u8 channel_count; /* # of channels */
  1028. /* thermal calibration */
  1029. s32 temperature; /* degrees Kelvin */
  1030. s32 last_temperature;
  1031. /* init calibration results */
  1032. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  1033. /* Scan related variables */
  1034. unsigned long scan_start;
  1035. unsigned long scan_start_tsf;
  1036. void *scan_cmd;
  1037. enum ieee80211_band scan_band;
  1038. struct cfg80211_scan_request *scan_request;
  1039. struct ieee80211_vif *scan_vif;
  1040. bool is_internal_short_scan;
  1041. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  1042. u8 mgmt_tx_ant;
  1043. /* spinlock */
  1044. spinlock_t lock; /* protect general shared data */
  1045. spinlock_t hcmd_lock; /* protect hcmd */
  1046. spinlock_t reg_lock; /* protect hw register access */
  1047. struct mutex mutex;
  1048. struct mutex sync_cmd_mutex; /* enable serialization of sync commands */
  1049. /* basic pci-network driver stuff */
  1050. struct pci_dev *pci_dev;
  1051. /* pci hardware address support */
  1052. void __iomem *hw_base;
  1053. u32 hw_rev;
  1054. u32 hw_wa_rev;
  1055. u8 rev_id;
  1056. /* microcode/device supports multiple contexts */
  1057. u8 valid_contexts;
  1058. /* command queue number */
  1059. u8 cmd_queue;
  1060. /* EEPROM MAC addresses */
  1061. struct mac_address addresses[2];
  1062. /* uCode images, save to reload in case of failure */
  1063. int fw_index; /* firmware we're trying to load */
  1064. u32 ucode_ver; /* version of ucode, copy of
  1065. iwl_ucode.ver */
  1066. struct fw_desc ucode_code; /* runtime inst */
  1067. struct fw_desc ucode_data; /* runtime data original */
  1068. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  1069. struct fw_desc ucode_init; /* initialization inst */
  1070. struct fw_desc ucode_init_data; /* initialization data */
  1071. struct fw_desc ucode_boot; /* bootstrap inst */
  1072. enum ucode_type ucode_type;
  1073. u8 ucode_write_complete; /* the image write is complete */
  1074. char firmware_name[25];
  1075. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  1076. struct iwl_switch_rxon switch_rxon;
  1077. /* 1st responses from initialize and runtime uCode images.
  1078. * _agn's initialize alive response contains some calibration data. */
  1079. struct iwl_init_alive_resp card_alive_init;
  1080. struct iwl_alive_resp card_alive;
  1081. unsigned long last_blink_time;
  1082. u8 last_blink_rate;
  1083. u8 allow_blinking;
  1084. u64 led_tpt;
  1085. u16 active_rate;
  1086. u8 start_calib;
  1087. struct iwl_sensitivity_data sensitivity_data;
  1088. struct iwl_chain_noise_data chain_noise_data;
  1089. bool enhance_sensitivity_table;
  1090. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  1091. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  1092. struct iwl_ht_config current_ht_config;
  1093. /* Rate scaling data */
  1094. u8 retry_rate;
  1095. wait_queue_head_t wait_command_queue;
  1096. int activity_timer_active;
  1097. /* Rx and Tx DMA processing queues */
  1098. struct iwl_rx_queue rxq;
  1099. struct iwl_tx_queue *txq;
  1100. unsigned long txq_ctx_active_msk;
  1101. struct iwl_dma_ptr kw; /* keep warm address */
  1102. struct iwl_dma_ptr scd_bc_tbls;
  1103. u32 scd_base_addr; /* scheduler sram base address */
  1104. unsigned long status;
  1105. /* counts mgmt, ctl, and data packets */
  1106. struct traffic_stats tx_stats;
  1107. struct traffic_stats rx_stats;
  1108. /* counts interrupts */
  1109. struct isr_statistics isr_stats;
  1110. struct iwl_power_mgr power_data;
  1111. struct iwl_tt_mgmt thermal_throttle;
  1112. /* context information */
  1113. u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
  1114. /* station table variables */
  1115. /* Note: if lock and sta_lock are needed, lock must be acquired first */
  1116. spinlock_t sta_lock;
  1117. int num_stations;
  1118. struct iwl_station_entry stations[IWL_STATION_COUNT];
  1119. struct iwl_wep_key wep_keys[WEP_KEYS_MAX]; /* protected by mutex */
  1120. u8 key_mapping_key;
  1121. unsigned long ucode_key_table;
  1122. /* queue refcounts */
  1123. #define IWL_MAX_HW_QUEUES 32
  1124. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  1125. /* for each AC */
  1126. atomic_t queue_stop_count[4];
  1127. /* Indication if ieee80211_ops->open has been called */
  1128. u8 is_open;
  1129. u8 mac80211_registered;
  1130. /* eeprom -- this is in the card's little endian byte order */
  1131. u8 *eeprom;
  1132. int nvm_device_type;
  1133. struct iwl_eeprom_calib_info *calib_info;
  1134. enum nl80211_iftype iw_mode;
  1135. struct sk_buff *ibss_beacon;
  1136. /* Last Rx'd beacon timestamp */
  1137. u64 timestamp;
  1138. union {
  1139. #if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
  1140. struct {
  1141. void *shared_virt;
  1142. dma_addr_t shared_phys;
  1143. struct delayed_work thermal_periodic;
  1144. struct delayed_work rfkill_poll;
  1145. struct iwl3945_notif_statistics statistics;
  1146. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1147. struct iwl3945_notif_statistics accum_statistics;
  1148. struct iwl3945_notif_statistics delta_statistics;
  1149. struct iwl3945_notif_statistics max_delta;
  1150. #endif
  1151. u32 sta_supp_rates;
  1152. int last_rx_rssi; /* From Rx packet statistics */
  1153. /* Rx'd packet timing information */
  1154. u32 last_beacon_time;
  1155. u64 last_tsf;
  1156. /*
  1157. * each calibration channel group in the
  1158. * EEPROM has a derived clip setting for
  1159. * each rate.
  1160. */
  1161. const struct iwl3945_clip_group clip_groups[5];
  1162. } _3945;
  1163. #endif
  1164. #if defined(CONFIG_IWLAGN) || defined(CONFIG_IWLAGN_MODULE)
  1165. struct {
  1166. /* INT ICT Table */
  1167. __le32 *ict_tbl;
  1168. void *ict_tbl_vir;
  1169. dma_addr_t ict_tbl_dma;
  1170. dma_addr_t aligned_ict_tbl_dma;
  1171. int ict_index;
  1172. u32 inta;
  1173. bool use_ict;
  1174. /*
  1175. * reporting the number of tids has AGG on. 0 means
  1176. * no AGGREGATION
  1177. */
  1178. u8 agg_tids_count;
  1179. struct iwl_rx_phy_res last_phy_res;
  1180. bool last_phy_res_valid;
  1181. struct completion firmware_loading_complete;
  1182. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1183. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1184. /*
  1185. * chain noise reset and gain commands are the
  1186. * two extra calibration commands follows the standard
  1187. * phy calibration commands
  1188. */
  1189. u8 phy_calib_chain_noise_reset_cmd;
  1190. u8 phy_calib_chain_noise_gain_cmd;
  1191. struct iwl_notif_statistics statistics;
  1192. struct iwl_bt_notif_statistics statistics_bt;
  1193. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1194. struct iwl_notif_statistics accum_statistics;
  1195. struct iwl_notif_statistics delta_statistics;
  1196. struct iwl_notif_statistics max_delta;
  1197. struct iwl_bt_notif_statistics accum_statistics_bt;
  1198. struct iwl_bt_notif_statistics delta_statistics_bt;
  1199. struct iwl_bt_notif_statistics max_delta_bt;
  1200. #endif
  1201. } _agn;
  1202. #endif
  1203. };
  1204. /* bt coex */
  1205. u8 bt_status;
  1206. u8 bt_traffic_load, notif_bt_traffic_load;
  1207. bool bt_ch_announce;
  1208. bool bt_sco_active;
  1209. bool bt_full_concurrent;
  1210. bool bt_ant_couple_ok;
  1211. __le32 kill_ack_mask;
  1212. __le32 kill_cts_mask;
  1213. __le16 bt_valid;
  1214. u16 bt_on_thresh;
  1215. u16 bt_duration;
  1216. u16 dynamic_frag_thresh;
  1217. u16 dynamic_agg_thresh;
  1218. u8 bt_ci_compliance;
  1219. struct work_struct bt_traffic_change_work;
  1220. struct iwl_hw_params hw_params;
  1221. u32 inta_mask;
  1222. struct workqueue_struct *workqueue;
  1223. struct work_struct restart;
  1224. struct work_struct scan_completed;
  1225. struct work_struct rx_replenish;
  1226. struct work_struct abort_scan;
  1227. struct work_struct beacon_update;
  1228. struct work_struct tt_work;
  1229. struct work_struct ct_enter;
  1230. struct work_struct ct_exit;
  1231. struct work_struct start_internal_scan;
  1232. struct work_struct tx_flush;
  1233. struct work_struct bt_full_concurrency;
  1234. struct work_struct bt_runtime_config;
  1235. struct tasklet_struct irq_tasklet;
  1236. struct delayed_work init_alive_start;
  1237. struct delayed_work alive_start;
  1238. struct delayed_work scan_check;
  1239. /* TX Power */
  1240. s8 tx_power_user_lmt;
  1241. s8 tx_power_device_lmt;
  1242. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  1243. #ifdef CONFIG_IWLWIFI_DEBUG
  1244. /* debugging info */
  1245. u32 debug_level; /* per device debugging will override global
  1246. iwl_debug_level if set */
  1247. #endif /* CONFIG_IWLWIFI_DEBUG */
  1248. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1249. /* debugfs */
  1250. u16 tx_traffic_idx;
  1251. u16 rx_traffic_idx;
  1252. u8 *tx_traffic;
  1253. u8 *rx_traffic;
  1254. struct dentry *debugfs_dir;
  1255. u32 dbgfs_sram_offset, dbgfs_sram_len;
  1256. bool disable_ht40;
  1257. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  1258. struct work_struct txpower_work;
  1259. u32 disable_sens_cal;
  1260. u32 disable_chain_noise_cal;
  1261. u32 disable_tx_power_cal;
  1262. struct work_struct run_time_calib_work;
  1263. struct timer_list statistics_periodic;
  1264. struct timer_list ucode_trace;
  1265. struct timer_list monitor_recover;
  1266. bool hw_ready;
  1267. struct iwl_event_log event_log;
  1268. }; /*iwl_priv */
  1269. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1270. {
  1271. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1272. }
  1273. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1274. {
  1275. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1276. }
  1277. #ifdef CONFIG_IWLWIFI_DEBUG
  1278. const char *iwl_get_tx_fail_reason(u32 status);
  1279. /*
  1280. * iwl_get_debug_level: Return active debug level for device
  1281. *
  1282. * Using sysfs it is possible to set per device debug level. This debug
  1283. * level will be used if set, otherwise the global debug level which can be
  1284. * set via module parameter is used.
  1285. */
  1286. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1287. {
  1288. if (priv->debug_level)
  1289. return priv->debug_level;
  1290. else
  1291. return iwl_debug_level;
  1292. }
  1293. #else
  1294. static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
  1295. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1296. {
  1297. return iwl_debug_level;
  1298. }
  1299. #endif
  1300. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  1301. int txq_id, int idx)
  1302. {
  1303. if (priv->txq[txq_id].txb[idx].skb)
  1304. return (struct ieee80211_hdr *)priv->txq[txq_id].
  1305. txb[idx].skb->data;
  1306. return NULL;
  1307. }
  1308. static inline struct iwl_rxon_context *
  1309. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  1310. {
  1311. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1312. return vif_priv->ctx;
  1313. }
  1314. #define for_each_context(priv, ctx) \
  1315. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  1316. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  1317. if (priv->valid_contexts & BIT(ctx->ctxid))
  1318. static inline int iwl_is_associated(struct iwl_priv *priv,
  1319. enum iwl_rxon_context_id ctxid)
  1320. {
  1321. return (priv->contexts[ctxid].active.filter_flags &
  1322. RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1323. }
  1324. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  1325. {
  1326. return iwl_is_associated(priv, IWL_RXON_CTX_BSS);
  1327. }
  1328. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  1329. {
  1330. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1331. }
  1332. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  1333. {
  1334. if (ch_info == NULL)
  1335. return 0;
  1336. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  1337. }
  1338. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  1339. {
  1340. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  1341. }
  1342. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  1343. {
  1344. return ch_info->band == IEEE80211_BAND_5GHZ;
  1345. }
  1346. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  1347. {
  1348. return ch_info->band == IEEE80211_BAND_2GHZ;
  1349. }
  1350. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  1351. {
  1352. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  1353. }
  1354. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  1355. {
  1356. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  1357. }
  1358. static inline void __iwl_free_pages(struct iwl_priv *priv, struct page *page)
  1359. {
  1360. __free_pages(page, priv->hw_params.rx_page_order);
  1361. priv->alloc_rxb_page--;
  1362. }
  1363. static inline void iwl_free_pages(struct iwl_priv *priv, unsigned long page)
  1364. {
  1365. free_pages(page, priv->hw_params.rx_page_order);
  1366. priv->alloc_rxb_page--;
  1367. }
  1368. #endif /* __iwl_dev_h__ */