iwl-dev.h 29 KB

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