iwl-dev.h 39 KB

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