iwl-dev.h 28 KB

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