iwl-dev.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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-rfkill.h"
  42. #include "iwl-4965-hw.h"
  43. #include "iwl-3945-hw.h"
  44. #include "iwl-3945-led.h"
  45. #include "iwl-led.h"
  46. #include "iwl-power.h"
  47. #include "iwl-agn-rs.h"
  48. /* configuration for the iwl4965 */
  49. extern struct iwl_cfg iwl4965_agn_cfg;
  50. extern struct iwl_cfg iwl5300_agn_cfg;
  51. extern struct iwl_cfg iwl5100_agn_cfg;
  52. extern struct iwl_cfg iwl5350_agn_cfg;
  53. extern struct iwl_cfg iwl5100_bg_cfg;
  54. extern struct iwl_cfg iwl5100_abg_cfg;
  55. extern struct iwl_cfg iwl5150_agn_cfg;
  56. /* CT-KILL constants */
  57. #define CT_KILL_THRESHOLD 110 /* in Celsius */
  58. /* Default noise level to report when noise measurement is not available.
  59. * This may be because we're:
  60. * 1) Not associated (4965, no beacon statistics being sent to driver)
  61. * 2) Scanning (noise measurement does not apply to associated channel)
  62. * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
  63. * Use default noise value of -127 ... this is below the range of measurable
  64. * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
  65. * Also, -127 works better than 0 when averaging frames with/without
  66. * noise info (e.g. averaging might be done in app); measured dBm values are
  67. * always negative ... using a negative value as the default keeps all
  68. * averages within an s8's (used in some apps) range of negative values. */
  69. #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
  70. /*
  71. * RTS threshold here is total size [2347] minus 4 FCS bytes
  72. * Per spec:
  73. * a value of 0 means RTS on all data/management packets
  74. * a value > max MSDU size means no RTS
  75. * else RTS for data/management frames where MPDU is larger
  76. * than RTS value.
  77. */
  78. #define DEFAULT_RTS_THRESHOLD 2347U
  79. #define MIN_RTS_THRESHOLD 0U
  80. #define MAX_RTS_THRESHOLD 2347U
  81. #define MAX_MSDU_SIZE 2304U
  82. #define MAX_MPDU_SIZE 2346U
  83. #define DEFAULT_BEACON_INTERVAL 100U
  84. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  85. #define DEFAULT_LONG_RETRY_LIMIT 4U
  86. struct iwl_rx_mem_buffer {
  87. dma_addr_t real_dma_addr;
  88. dma_addr_t aligned_dma_addr;
  89. struct sk_buff *skb;
  90. struct list_head list;
  91. };
  92. /*
  93. * Generic queue structure
  94. *
  95. * Contains common data for Rx and Tx queues
  96. */
  97. struct iwl_queue {
  98. int n_bd; /* number of BDs in this queue */
  99. int write_ptr; /* 1-st empty entry (index) host_w*/
  100. int read_ptr; /* last used entry (index) host_r*/
  101. dma_addr_t dma_addr; /* physical addr for BD's */
  102. int n_window; /* safe queue window */
  103. u32 id;
  104. int low_mark; /* low watermark, resume queue if free
  105. * space more than this */
  106. int high_mark; /* high watermark, stop queue if free
  107. * space less than this */
  108. } __attribute__ ((packed));
  109. /* One for each TFD */
  110. struct iwl_tx_info {
  111. struct sk_buff *skb[IWL_NUM_OF_TBS - 1];
  112. };
  113. /**
  114. * struct iwl_tx_queue - Tx Queue for DMA
  115. * @q: generic Rx/Tx queue descriptor
  116. * @bd: base of circular buffer of TFDs
  117. * @cmd: array of command/Tx buffers
  118. * @dma_addr_cmd: physical address of cmd/tx buffer array
  119. * @txb: array of per-TFD driver data
  120. * @need_update: indicates need to update read/write index
  121. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  122. *
  123. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  124. * descriptors) and required locking structures.
  125. */
  126. #define TFD_TX_CMD_SLOTS 256
  127. #define TFD_CMD_SLOTS 32
  128. struct iwl_tx_queue {
  129. struct iwl_queue q;
  130. struct iwl_tfd *tfds;
  131. struct iwl3945_tfd *tfds39;
  132. struct iwl_cmd *cmd[TFD_TX_CMD_SLOTS];
  133. struct iwl_tx_info *txb;
  134. u8 need_update;
  135. u8 sched_retry;
  136. u8 active;
  137. u8 swq_id;
  138. };
  139. #define IWL_NUM_SCAN_RATES (2)
  140. struct iwl4965_channel_tgd_info {
  141. u8 type;
  142. s8 max_power;
  143. };
  144. struct iwl4965_channel_tgh_info {
  145. s64 last_radar_time;
  146. };
  147. #define IWL4965_MAX_RATE (33)
  148. struct iwl3945_clip_group {
  149. /* maximum power level to prevent clipping for each rate, derived by
  150. * us from this band's saturation power in EEPROM */
  151. const s8 clip_powers[IWL_MAX_RATES];
  152. };
  153. /* current Tx power values to use, one for each rate for each channel.
  154. * requested power is limited by:
  155. * -- regulatory EEPROM limits for this channel
  156. * -- hardware capabilities (clip-powers)
  157. * -- spectrum management
  158. * -- user preference (e.g. iwconfig)
  159. * when requested power is set, base power index must also be set. */
  160. struct iwl3945_channel_power_info {
  161. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  162. s8 power_table_index; /* actual (compenst'd) index into gain table */
  163. s8 base_power_index; /* gain index for power at factory temp. */
  164. s8 requested_power; /* power (dBm) requested for this chnl/rate */
  165. };
  166. /* current scan Tx power values to use, one for each scan rate for each
  167. * channel. */
  168. struct iwl3945_scan_power_info {
  169. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  170. s8 power_table_index; /* actual (compenst'd) index into gain table */
  171. s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
  172. };
  173. /*
  174. * One for each channel, holds all channel setup data
  175. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  176. * with one another!
  177. */
  178. struct iwl_channel_info {
  179. struct iwl4965_channel_tgd_info tgd;
  180. struct iwl4965_channel_tgh_info tgh;
  181. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  182. struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for
  183. * FAT channel */
  184. u8 channel; /* channel number */
  185. u8 flags; /* flags copied from EEPROM */
  186. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  187. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  188. s8 min_power; /* always 0 */
  189. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  190. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  191. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  192. enum ieee80211_band band;
  193. /* FAT channel info */
  194. s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  195. s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */
  196. s8 fat_min_power; /* always 0 */
  197. s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */
  198. u8 fat_flags; /* flags copied from EEPROM */
  199. u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  200. /* Radio/DSP gain settings for each "normal" data Tx rate.
  201. * These include, in addition to RF and DSP gain, a few fields for
  202. * remembering/modifying gain settings (indexes). */
  203. struct iwl3945_channel_power_info power_info[IWL4965_MAX_RATE];
  204. /* Radio/DSP gain settings for each scan rate, for directed scans. */
  205. struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
  206. };
  207. #define IWL_TX_FIFO_AC0 0
  208. #define IWL_TX_FIFO_AC1 1
  209. #define IWL_TX_FIFO_AC2 2
  210. #define IWL_TX_FIFO_AC3 3
  211. #define IWL_TX_FIFO_HCCA_1 5
  212. #define IWL_TX_FIFO_HCCA_2 6
  213. #define IWL_TX_FIFO_NONE 7
  214. /* Minimum number of queues. MAX_NUM is defined in hw specific files */
  215. #define IWL_MIN_NUM_QUEUES 4
  216. /* Power management (not Tx power) structures */
  217. enum iwl_pwr_src {
  218. IWL_PWR_SRC_VMAIN,
  219. IWL_PWR_SRC_VAUX,
  220. };
  221. #define IEEE80211_DATA_LEN 2304
  222. #define IEEE80211_4ADDR_LEN 30
  223. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  224. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  225. struct iwl_frame {
  226. union {
  227. struct ieee80211_hdr frame;
  228. struct iwl_tx_beacon_cmd beacon;
  229. u8 raw[IEEE80211_FRAME_LEN];
  230. u8 cmd[360];
  231. } u;
  232. struct list_head list;
  233. };
  234. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  235. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  236. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  237. enum {
  238. /* CMD_SIZE_NORMAL = 0, */
  239. CMD_SIZE_HUGE = (1 << 0),
  240. /* CMD_SYNC = 0, */
  241. CMD_ASYNC = (1 << 1),
  242. /* CMD_NO_SKB = 0, */
  243. CMD_WANT_SKB = (1 << 2),
  244. };
  245. struct iwl_cmd;
  246. struct iwl_priv;
  247. struct iwl_cmd_meta {
  248. struct iwl_cmd_meta *source;
  249. union {
  250. struct sk_buff *skb;
  251. int (*callback)(struct iwl_priv *priv,
  252. struct iwl_cmd *cmd, struct sk_buff *skb);
  253. } __attribute__ ((packed)) u;
  254. /* The CMD_SIZE_HUGE flag bit indicates that the command
  255. * structure is stored at the end of the shared queue memory. */
  256. u32 flags;
  257. DECLARE_PCI_UNMAP_ADDR(mapping)
  258. DECLARE_PCI_UNMAP_LEN(len)
  259. } __attribute__ ((packed));
  260. #define IWL_CMD_MAX_PAYLOAD 320
  261. /**
  262. * struct iwl_cmd
  263. *
  264. * For allocation of the command and tx queues, this establishes the overall
  265. * size of the largest command we send to uCode, except for a scan command
  266. * (which is relatively huge; space is allocated separately).
  267. */
  268. struct iwl_cmd {
  269. struct iwl_cmd_meta meta; /* driver data */
  270. struct iwl_cmd_header hdr; /* uCode API */
  271. union {
  272. u32 flags;
  273. u8 val8;
  274. u16 val16;
  275. u32 val32;
  276. struct iwl_tx_cmd tx;
  277. u8 payload[IWL_CMD_MAX_PAYLOAD];
  278. } __attribute__ ((packed)) cmd;
  279. } __attribute__ ((packed));
  280. struct iwl_host_cmd {
  281. u8 id;
  282. u16 len;
  283. struct iwl_cmd_meta meta;
  284. const void *data;
  285. };
  286. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
  287. sizeof(struct iwl_cmd_meta))
  288. /*
  289. * RX related structures and functions
  290. */
  291. #define RX_FREE_BUFFERS 64
  292. #define RX_LOW_WATERMARK 8
  293. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  294. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  295. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  296. /**
  297. * struct iwl_rx_queue - Rx queue
  298. * @read: Shared index to newest available Rx buffer
  299. * @write: Shared index to oldest written Rx packet
  300. * @free_count: Number of pre-allocated buffers in rx_free
  301. * @rx_free: list of free SKBs for use
  302. * @rx_used: List of Rx buffers with no SKB
  303. * @need_update: flag to indicate we need to update read/write index
  304. *
  305. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  306. */
  307. struct iwl_rx_queue {
  308. __le32 *bd;
  309. dma_addr_t dma_addr;
  310. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  311. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  312. u32 read;
  313. u32 write;
  314. u32 free_count;
  315. struct list_head rx_free;
  316. struct list_head rx_used;
  317. int need_update;
  318. struct iwl_rb_status *rb_stts;
  319. dma_addr_t rb_stts_dma;
  320. spinlock_t lock;
  321. };
  322. #define IWL_SUPPORTED_RATES_IE_LEN 8
  323. #define MAX_TID_COUNT 9
  324. #define IWL_INVALID_RATE 0xFF
  325. #define IWL_INVALID_VALUE -1
  326. /**
  327. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  328. * @txq_id: Tx queue used for Tx attempt
  329. * @frame_count: # frames attempted by Tx command
  330. * @wait_for_ba: Expect block-ack before next Tx reply
  331. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  332. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  333. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  334. * @rate_n_flags: Rate at which Tx was attempted
  335. *
  336. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  337. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  338. * until block ack arrives.
  339. */
  340. struct iwl_ht_agg {
  341. u16 txq_id;
  342. u16 frame_count;
  343. u16 wait_for_ba;
  344. u16 start_idx;
  345. u64 bitmap;
  346. u32 rate_n_flags;
  347. #define IWL_AGG_OFF 0
  348. #define IWL_AGG_ON 1
  349. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  350. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  351. u8 state;
  352. };
  353. struct iwl_tid_data {
  354. u16 seq_number;
  355. u16 tfds_in_queue;
  356. struct iwl_ht_agg agg;
  357. };
  358. struct iwl_hw_key {
  359. enum ieee80211_key_alg alg;
  360. int keylen;
  361. u8 keyidx;
  362. u8 key[32];
  363. };
  364. union iwl_ht_rate_supp {
  365. u16 rates;
  366. struct {
  367. u8 siso_rate;
  368. u8 mimo_rate;
  369. };
  370. };
  371. #define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
  372. #define CFG_HT_MPDU_DENSITY_2USEC (0x5)
  373. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
  374. struct iwl_ht_info {
  375. /* self configuration data */
  376. u8 is_ht;
  377. u8 supported_chan_width;
  378. u8 sm_ps;
  379. u8 is_green_field;
  380. u8 sgf; /* HT_SHORT_GI_* short guard interval */
  381. u8 max_amsdu_size;
  382. u8 ampdu_factor;
  383. u8 mpdu_density;
  384. struct ieee80211_mcs_info mcs;
  385. /* BSS related data */
  386. u8 extension_chan_offset;
  387. u8 tx_chan_width;
  388. u8 ht_protection;
  389. u8 non_GF_STA_present;
  390. };
  391. union iwl_qos_capabity {
  392. struct {
  393. u8 edca_count:4; /* bit 0-3 */
  394. u8 q_ack:1; /* bit 4 */
  395. u8 queue_request:1; /* bit 5 */
  396. u8 txop_request:1; /* bit 6 */
  397. u8 reserved:1; /* bit 7 */
  398. } q_AP;
  399. struct {
  400. u8 acvo_APSD:1; /* bit 0 */
  401. u8 acvi_APSD:1; /* bit 1 */
  402. u8 ac_bk_APSD:1; /* bit 2 */
  403. u8 ac_be_APSD:1; /* bit 3 */
  404. u8 q_ack:1; /* bit 4 */
  405. u8 max_len:2; /* bit 5-6 */
  406. u8 more_data_ack:1; /* bit 7 */
  407. } q_STA;
  408. u8 val;
  409. };
  410. /* QoS structures */
  411. struct iwl_qos_info {
  412. int qos_active;
  413. union iwl_qos_capabity qos_cap;
  414. struct iwl_qosparam_cmd def_qos_parm;
  415. };
  416. #define STA_PS_STATUS_WAKE 0
  417. #define STA_PS_STATUS_SLEEP 1
  418. struct iwl3945_tid_data {
  419. u16 seq_number;
  420. };
  421. struct iwl3945_hw_key {
  422. enum ieee80211_key_alg alg;
  423. int keylen;
  424. u8 key[32];
  425. };
  426. struct iwl3945_station_entry {
  427. struct iwl3945_addsta_cmd sta;
  428. struct iwl3945_tid_data tid[MAX_TID_COUNT];
  429. u8 used;
  430. u8 ps_status;
  431. struct iwl3945_hw_key keyinfo;
  432. };
  433. struct iwl_station_entry {
  434. struct iwl_addsta_cmd sta;
  435. struct iwl_tid_data tid[MAX_TID_COUNT];
  436. u8 used;
  437. u8 ps_status;
  438. struct iwl_hw_key keyinfo;
  439. };
  440. /* one for each uCode image (inst/data, boot/init/runtime) */
  441. struct fw_desc {
  442. void *v_addr; /* access by driver */
  443. dma_addr_t p_addr; /* access by card's busmaster DMA */
  444. u32 len; /* bytes */
  445. };
  446. /* uCode file layout */
  447. struct iwl_ucode {
  448. __le32 ver; /* major/minor/API/serial */
  449. __le32 inst_size; /* bytes of runtime instructions */
  450. __le32 data_size; /* bytes of runtime data */
  451. __le32 init_size; /* bytes of initialization instructions */
  452. __le32 init_data_size; /* bytes of initialization data */
  453. __le32 boot_size; /* bytes of bootstrap instructions */
  454. u8 data[0]; /* data in same order as "size" elements */
  455. };
  456. struct iwl4965_ibss_seq {
  457. u8 mac[ETH_ALEN];
  458. u16 seq_num;
  459. u16 frag_num;
  460. unsigned long packet_time;
  461. struct list_head list;
  462. };
  463. struct iwl_sensitivity_ranges {
  464. u16 min_nrg_cck;
  465. u16 max_nrg_cck;
  466. u16 nrg_th_cck;
  467. u16 nrg_th_ofdm;
  468. u16 auto_corr_min_ofdm;
  469. u16 auto_corr_min_ofdm_mrc;
  470. u16 auto_corr_min_ofdm_x1;
  471. u16 auto_corr_min_ofdm_mrc_x1;
  472. u16 auto_corr_max_ofdm;
  473. u16 auto_corr_max_ofdm_mrc;
  474. u16 auto_corr_max_ofdm_x1;
  475. u16 auto_corr_max_ofdm_mrc_x1;
  476. u16 auto_corr_max_cck;
  477. u16 auto_corr_max_cck_mrc;
  478. u16 auto_corr_min_cck;
  479. u16 auto_corr_min_cck_mrc;
  480. };
  481. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  482. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  483. /**
  484. * struct iwl_hw_params
  485. * @max_txq_num: Max # Tx queues supported
  486. * @dma_chnl_num: Number of Tx DMA/FIFO channels
  487. * @scd_bc_tbls_size: size of scheduler byte count tables
  488. * @tx/rx_chains_num: Number of TX/RX chains
  489. * @valid_tx/rx_ant: usable antennas
  490. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  491. * @max_rxq_log: Log-base-2 of max_rxq_size
  492. * @rx_buf_size: Rx buffer size
  493. * @max_stations:
  494. * @bcast_sta_id:
  495. * @fat_channel: is 40MHz width possible in band 2.4
  496. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  497. * @sw_crypto: 0 for hw, 1 for sw
  498. * @max_xxx_size: for ucode uses
  499. * @ct_kill_threshold: temperature threshold
  500. * @calib_init_cfg: setup initial calibrations for the hw
  501. * @struct iwl_sensitivity_ranges: range of sensitivity values
  502. */
  503. struct iwl_hw_params {
  504. u8 max_txq_num;
  505. u8 dma_chnl_num;
  506. u16 scd_bc_tbls_size;
  507. u8 tx_chains_num;
  508. u8 rx_chains_num;
  509. u8 valid_tx_ant;
  510. u8 valid_rx_ant;
  511. u16 max_rxq_size;
  512. u16 max_rxq_log;
  513. u32 rx_buf_size;
  514. u32 max_pkt_size;
  515. u8 max_stations;
  516. u8 bcast_sta_id;
  517. u8 fat_channel;
  518. u8 sw_crypto;
  519. u32 max_inst_size;
  520. u32 max_data_size;
  521. u32 max_bsm_size;
  522. u32 ct_kill_threshold; /* value in hw-dependent units */
  523. u32 calib_init_cfg;
  524. const struct iwl_sensitivity_ranges *sens;
  525. };
  526. /******************************************************************************
  527. *
  528. * Functions implemented in core module which are forward declared here
  529. * for use by iwl-[4-5].c
  530. *
  531. * NOTE: The implementation of these functions are not hardware specific
  532. * which is why they are in the core module files.
  533. *
  534. * Naming convention --
  535. * iwl_ <-- Is part of iwlwifi
  536. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  537. * iwl4965_bg_ <-- Called from work queue context
  538. * iwl4965_mac_ <-- mac80211 callback
  539. *
  540. ****************************************************************************/
  541. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  542. extern int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
  543. extern const u8 iwl_bcast_addr[ETH_ALEN];
  544. extern int iwl_rxq_stop(struct iwl_priv *priv);
  545. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  546. extern int iwl_queue_space(const struct iwl_queue *q);
  547. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  548. {
  549. return q->write_ptr > q->read_ptr ?
  550. (i >= q->read_ptr && i < q->write_ptr) :
  551. !(i < q->read_ptr && i >= q->write_ptr);
  552. }
  553. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
  554. {
  555. /* This is for scan command, the big buffer at end of command array */
  556. if (is_huge)
  557. return q->n_window; /* must be power of 2 */
  558. /* Otherwise, use normal size buffers */
  559. return index & (q->n_window - 1);
  560. }
  561. struct iwl_dma_ptr {
  562. dma_addr_t dma;
  563. void *addr;
  564. size_t size;
  565. };
  566. #define HT_SHORT_GI_20MHZ (1 << 0)
  567. #define HT_SHORT_GI_40MHZ (1 << 1)
  568. #define IWL_CHANNEL_WIDTH_20MHZ 0
  569. #define IWL_CHANNEL_WIDTH_40MHZ 1
  570. #define IWL_OPERATION_MODE_AUTO 0
  571. #define IWL_OPERATION_MODE_HT_ONLY 1
  572. #define IWL_OPERATION_MODE_MIXED 2
  573. #define IWL_OPERATION_MODE_20MHZ 3
  574. #define IWL_TX_CRC_SIZE 4
  575. #define IWL_TX_DELIMITER_SIZE 4
  576. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  577. /* Sensitivity and chain noise calibration */
  578. #define INITIALIZATION_VALUE 0xFFFF
  579. #define CAL_NUM_OF_BEACONS 20
  580. #define MAXIMUM_ALLOWED_PATHLOSS 15
  581. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  582. #define MAX_FA_OFDM 50
  583. #define MIN_FA_OFDM 5
  584. #define MAX_FA_CCK 50
  585. #define MIN_FA_CCK 5
  586. #define AUTO_CORR_STEP_OFDM 1
  587. #define AUTO_CORR_STEP_CCK 3
  588. #define AUTO_CORR_MAX_TH_CCK 160
  589. #define NRG_DIFF 2
  590. #define NRG_STEP_CCK 2
  591. #define NRG_MARGIN 8
  592. #define MAX_NUMBER_CCK_NO_FA 100
  593. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  594. #define CHAIN_A 0
  595. #define CHAIN_B 1
  596. #define CHAIN_C 2
  597. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  598. #define ALL_BAND_FILTER 0xFF00
  599. #define IN_BAND_FILTER 0xFF
  600. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  601. #define NRG_NUM_PREV_STAT_L 20
  602. #define NUM_RX_CHAINS 3
  603. enum iwl4965_false_alarm_state {
  604. IWL_FA_TOO_MANY = 0,
  605. IWL_FA_TOO_FEW = 1,
  606. IWL_FA_GOOD_RANGE = 2,
  607. };
  608. enum iwl4965_chain_noise_state {
  609. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  610. IWL_CHAIN_NOISE_ACCUMULATE,
  611. IWL_CHAIN_NOISE_CALIBRATED,
  612. IWL_CHAIN_NOISE_DONE,
  613. };
  614. enum iwl4965_calib_enabled_state {
  615. IWL_CALIB_DISABLED = 0, /* must be 0 */
  616. IWL_CALIB_ENABLED = 1,
  617. };
  618. /*
  619. * enum iwl_calib
  620. * defines the order in which results of initial calibrations
  621. * should be sent to the runtime uCode
  622. */
  623. enum iwl_calib {
  624. IWL_CALIB_XTAL,
  625. IWL_CALIB_DC,
  626. IWL_CALIB_LO,
  627. IWL_CALIB_TX_IQ,
  628. IWL_CALIB_TX_IQ_PERD,
  629. IWL_CALIB_BASE_BAND,
  630. IWL_CALIB_MAX
  631. };
  632. /* Opaque calibration results */
  633. struct iwl_calib_result {
  634. void *buf;
  635. size_t buf_len;
  636. };
  637. enum ucode_type {
  638. UCODE_NONE = 0,
  639. UCODE_INIT,
  640. UCODE_RT
  641. };
  642. /* Sensitivity calib data */
  643. struct iwl_sensitivity_data {
  644. u32 auto_corr_ofdm;
  645. u32 auto_corr_ofdm_mrc;
  646. u32 auto_corr_ofdm_x1;
  647. u32 auto_corr_ofdm_mrc_x1;
  648. u32 auto_corr_cck;
  649. u32 auto_corr_cck_mrc;
  650. u32 last_bad_plcp_cnt_ofdm;
  651. u32 last_fa_cnt_ofdm;
  652. u32 last_bad_plcp_cnt_cck;
  653. u32 last_fa_cnt_cck;
  654. u32 nrg_curr_state;
  655. u32 nrg_prev_state;
  656. u32 nrg_value[10];
  657. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  658. u32 nrg_silence_ref;
  659. u32 nrg_energy_idx;
  660. u32 nrg_silence_idx;
  661. u32 nrg_th_cck;
  662. s32 nrg_auto_corr_silence_diff;
  663. u32 num_in_cck_no_fa;
  664. u32 nrg_th_ofdm;
  665. };
  666. /* Chain noise (differential Rx gain) calib data */
  667. struct iwl_chain_noise_data {
  668. u32 active_chains;
  669. u32 chain_noise_a;
  670. u32 chain_noise_b;
  671. u32 chain_noise_c;
  672. u32 chain_signal_a;
  673. u32 chain_signal_b;
  674. u32 chain_signal_c;
  675. u16 beacon_count;
  676. u8 disconn_array[NUM_RX_CHAINS];
  677. u8 delta_gain_code[NUM_RX_CHAINS];
  678. u8 radio_write;
  679. u8 state;
  680. };
  681. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  682. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  683. enum {
  684. MEASUREMENT_READY = (1 << 0),
  685. MEASUREMENT_ACTIVE = (1 << 1),
  686. };
  687. #define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
  688. struct iwl_priv {
  689. /* ieee device used by generic ieee processing code */
  690. struct ieee80211_hw *hw;
  691. struct ieee80211_channel *ieee_channels;
  692. struct ieee80211_rate *ieee_rates;
  693. struct iwl_cfg *cfg;
  694. /* temporary frame storage list */
  695. struct list_head free_frames;
  696. int frames_count;
  697. enum ieee80211_band band;
  698. int alloc_rxb_skb;
  699. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  700. struct iwl_rx_mem_buffer *rxb);
  701. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  702. #if defined(CONFIG_IWLAGN_SPECTRUM_MEASUREMENT) || defined(CONFIG_IWL3945_SPECTRUM_MEASUREMENT)
  703. /* spectrum measurement report caching */
  704. struct iwl_spectrum_notification measure_report;
  705. u8 measurement_status;
  706. #endif
  707. /* ucode beacon time */
  708. u32 ucode_beacon_time;
  709. /* we allocate array of iwl4965_channel_info for NIC's valid channels.
  710. * Access via channel # using indirect index array */
  711. struct iwl_channel_info *channel_info; /* channel info array */
  712. u8 channel_count; /* # of channels */
  713. /* each calibration channel group in the EEPROM has a derived
  714. * clip setting for each rate. 3945 only.*/
  715. const struct iwl3945_clip_group clip39_groups[5];
  716. /* thermal calibration */
  717. s32 temperature; /* degrees Kelvin */
  718. s32 last_temperature;
  719. /* init calibration results */
  720. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  721. /* Scan related variables */
  722. unsigned long last_scan_jiffies;
  723. unsigned long next_scan_jiffies;
  724. unsigned long scan_start;
  725. unsigned long scan_pass_start;
  726. unsigned long scan_start_tsf;
  727. struct iwl_scan_cmd *scan;
  728. int scan_bands;
  729. int one_direct_scan;
  730. u8 direct_ssid_len;
  731. u8 direct_ssid[IW_ESSID_MAX_SIZE];
  732. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  733. u8 mgmt_tx_ant;
  734. /* spinlock */
  735. spinlock_t lock; /* protect general shared data */
  736. spinlock_t hcmd_lock; /* protect hcmd */
  737. struct mutex mutex;
  738. /* basic pci-network driver stuff */
  739. struct pci_dev *pci_dev;
  740. /* pci hardware address support */
  741. void __iomem *hw_base;
  742. u32 hw_rev;
  743. u32 hw_wa_rev;
  744. u8 rev_id;
  745. /* uCode images, save to reload in case of failure */
  746. u32 ucode_ver; /* version of ucode, copy of
  747. iwl_ucode.ver */
  748. struct fw_desc ucode_code; /* runtime inst */
  749. struct fw_desc ucode_data; /* runtime data original */
  750. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  751. struct fw_desc ucode_init; /* initialization inst */
  752. struct fw_desc ucode_init_data; /* initialization data */
  753. struct fw_desc ucode_boot; /* bootstrap inst */
  754. enum ucode_type ucode_type;
  755. u8 ucode_write_complete; /* the image write is complete */
  756. struct iwl_rxon_time_cmd rxon_timing;
  757. /* We declare this const so it can only be
  758. * changed via explicit cast within the
  759. * routines that actually update the physical
  760. * hardware */
  761. const struct iwl_rxon_cmd active_rxon;
  762. struct iwl_rxon_cmd staging_rxon;
  763. int error_recovering;
  764. struct iwl_rxon_cmd recovery_rxon;
  765. /* 1st responses from initialize and runtime uCode images.
  766. * 4965's initialize alive response contains some calibration data. */
  767. struct iwl_init_alive_resp card_alive_init;
  768. struct iwl_alive_resp card_alive;
  769. #if defined(CONFIG_IWLWIFI_RFKILL) || defined(CONFIG_IWL3945_RFKILL)
  770. struct rfkill *rfkill;
  771. #endif
  772. #if defined(CONFIG_IWLWIFI_LEDS) || defined(CONFIG_IWL3945_LEDS)
  773. unsigned long last_blink_time;
  774. u8 last_blink_rate;
  775. u8 allow_blinking;
  776. u64 led_tpt;
  777. #endif
  778. #ifdef CONFIG_IWLWIFI_LEDS
  779. struct iwl_led led[IWL_LED_TRG_MAX];
  780. #endif
  781. #ifdef CONFIG_IWL3945_LEDS
  782. struct iwl3945_led led39[IWL_LED_TRG_MAX];
  783. unsigned int rxtxpackets;
  784. #endif
  785. u16 active_rate;
  786. u16 active_rate_basic;
  787. u8 assoc_station_added;
  788. u8 start_calib;
  789. struct iwl_sensitivity_data sensitivity_data;
  790. struct iwl_chain_noise_data chain_noise_data;
  791. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  792. struct iwl_ht_info current_ht_config;
  793. u8 last_phy_res[100];
  794. /* Rate scaling data */
  795. s8 data_retry_limit;
  796. u8 retry_rate;
  797. wait_queue_head_t wait_command_queue;
  798. int activity_timer_active;
  799. /* Rx and Tx DMA processing queues */
  800. struct iwl_rx_queue rxq;
  801. struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
  802. unsigned long txq_ctx_active_msk;
  803. struct iwl_dma_ptr kw; /* keep warm address */
  804. struct iwl_dma_ptr scd_bc_tbls;
  805. u32 scd_base_addr; /* scheduler sram base address */
  806. unsigned long status;
  807. int last_rx_rssi; /* From Rx packet statistics */
  808. int last_rx_noise; /* From beacon statistics */
  809. /* counts mgmt, ctl, and data packets */
  810. struct traffic_stats {
  811. u32 cnt;
  812. u64 bytes;
  813. } tx_stats[3], rx_stats[3];
  814. struct iwl_power_mgr power_data;
  815. struct iwl_notif_statistics statistics;
  816. unsigned long last_statistics_time;
  817. /* context information */
  818. u16 rates_mask;
  819. u32 power_mode;
  820. u32 antenna;
  821. u8 bssid[ETH_ALEN];
  822. u16 rts_threshold;
  823. u8 mac_addr[ETH_ALEN];
  824. /*station table variables */
  825. spinlock_t sta_lock;
  826. int num_stations;
  827. struct iwl_station_entry stations[IWL_STATION_COUNT];
  828. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  829. u8 default_wep_key;
  830. u8 key_mapping_key;
  831. unsigned long ucode_key_table;
  832. /* Indication if ieee80211_ops->open has been called */
  833. u8 is_open;
  834. u8 mac80211_registered;
  835. /* Rx'd packet timing information */
  836. u32 last_beacon_time;
  837. u64 last_tsf;
  838. /* eeprom */
  839. u8 *eeprom;
  840. struct iwl_eeprom_calib_info *calib_info;
  841. enum nl80211_iftype iw_mode;
  842. struct sk_buff *ibss_beacon;
  843. /* Last Rx'd beacon timestamp */
  844. u64 timestamp;
  845. u16 beacon_int;
  846. struct ieee80211_vif *vif;
  847. /*Added for 3945 */
  848. void *shared_virt;
  849. dma_addr_t shared_phys;
  850. /*End*/
  851. struct iwl_hw_params hw_params;
  852. /* Current association information needed to configure the
  853. * hardware */
  854. u16 assoc_id;
  855. u16 assoc_capability;
  856. struct iwl_qos_info qos_data;
  857. struct workqueue_struct *workqueue;
  858. struct work_struct up;
  859. struct work_struct restart;
  860. struct work_struct calibrated_work;
  861. struct work_struct scan_completed;
  862. struct work_struct rx_replenish;
  863. struct work_struct rf_kill;
  864. struct work_struct abort_scan;
  865. struct work_struct update_link_led;
  866. struct work_struct auth_work;
  867. struct work_struct report_work;
  868. struct work_struct request_scan;
  869. struct work_struct beacon_update;
  870. struct tasklet_struct irq_tasklet;
  871. struct delayed_work set_power_save;
  872. struct delayed_work init_alive_start;
  873. struct delayed_work alive_start;
  874. struct delayed_work scan_check;
  875. /*For 3945 only*/
  876. struct delayed_work thermal_periodic;
  877. /* TX Power */
  878. s8 tx_power_user_lmt;
  879. s8 tx_power_channel_lmt;
  880. #if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWL3945_DEBUG)
  881. /* debugging info */
  882. u32 debug_level;
  883. u32 framecnt_to_us;
  884. atomic_t restrict_refcnt;
  885. #ifdef CONFIG_IWLWIFI_DEBUGFS
  886. /* debugfs */
  887. struct iwl_debugfs *dbgfs;
  888. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  889. #endif /* CONFIG_IWLWIFI_DEBUG */
  890. struct work_struct txpower_work;
  891. u32 disable_sens_cal;
  892. u32 disable_chain_noise_cal;
  893. u32 disable_tx_power_cal;
  894. struct work_struct run_time_calib_work;
  895. struct timer_list statistics_periodic;
  896. /*For 3945*/
  897. #define IWL_DEFAULT_TX_POWER 0x0F
  898. s8 user_txpower_limit;
  899. s8 max_channel_txpower_limit;
  900. struct iwl3945_scan_cmd *scan39;
  901. /* We declare this const so it can only be
  902. * changed via explicit cast within the
  903. * routines that actually update the physical
  904. * hardware */
  905. const struct iwl3945_rxon_cmd active39_rxon;
  906. struct iwl3945_rxon_cmd staging39_rxon;
  907. struct iwl3945_rxon_cmd recovery39_rxon;
  908. struct iwl3945_power_mgr power_data_39;
  909. struct iwl3945_notif_statistics statistics_39;
  910. struct iwl3945_station_entry stations_39[IWL_STATION_COUNT];
  911. /* eeprom */
  912. struct iwl3945_eeprom eeprom39;
  913. u32 sta_supp_rates;
  914. u8 call_post_assoc_from_beacon;
  915. }; /*iwl_priv */
  916. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  917. {
  918. set_bit(txq_id, &priv->txq_ctx_active_msk);
  919. }
  920. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  921. {
  922. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  923. }
  924. #ifdef CONFIG_IWLWIFI_DEBUG
  925. const char *iwl_get_tx_fail_reason(u32 status);
  926. #else
  927. static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
  928. #endif
  929. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  930. int txq_id, int idx)
  931. {
  932. if (priv->txq[txq_id].txb[idx].skb[0])
  933. return (struct ieee80211_hdr *)priv->txq[txq_id].
  934. txb[idx].skb[0]->data;
  935. return NULL;
  936. }
  937. static inline int iwl_is_associated(struct iwl_priv *priv)
  938. {
  939. return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  940. }
  941. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  942. {
  943. if (ch_info == NULL)
  944. return 0;
  945. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  946. }
  947. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  948. {
  949. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  950. }
  951. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  952. {
  953. return ch_info->band == IEEE80211_BAND_5GHZ;
  954. }
  955. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  956. {
  957. return ch_info->band == IEEE80211_BAND_2GHZ;
  958. }
  959. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  960. {
  961. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  962. }
  963. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  964. {
  965. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  966. }
  967. #endif /* __iwl_dev_h__ */