iwl-dev.h 27 KB

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