iwl-dev.h 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  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. #define MAX_NUM_OF_TBS (20)
  106. /* One for each TFD */
  107. struct iwl_tx_info {
  108. struct sk_buff *skb[MAX_NUM_OF_TBS];
  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_frame *bd;
  126. struct iwl_cmd *cmd[TFD_TX_CMD_SLOTS];
  127. struct iwl_tx_info *txb;
  128. int need_update;
  129. int sched_retry;
  130. int active;
  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. } __attribute__ ((packed));
  224. #define IWL_CMD_MAX_PAYLOAD 320
  225. /**
  226. * struct iwl_cmd
  227. *
  228. * For allocation of the command and tx queues, this establishes the overall
  229. * size of the largest command we send to uCode, except for a scan command
  230. * (which is relatively huge; space is allocated separately).
  231. */
  232. struct iwl_cmd {
  233. struct iwl_cmd_meta meta; /* driver data */
  234. struct iwl_cmd_header hdr; /* uCode API */
  235. union {
  236. u32 flags;
  237. u8 val8;
  238. u16 val16;
  239. u32 val32;
  240. struct iwl_tx_cmd tx;
  241. u8 payload[IWL_CMD_MAX_PAYLOAD];
  242. } __attribute__ ((packed)) cmd;
  243. } __attribute__ ((packed));
  244. struct iwl_host_cmd {
  245. u8 id;
  246. u16 len;
  247. struct iwl_cmd_meta meta;
  248. const void *data;
  249. };
  250. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
  251. sizeof(struct iwl_cmd_meta))
  252. /*
  253. * RX related structures and functions
  254. */
  255. #define RX_FREE_BUFFERS 64
  256. #define RX_LOW_WATERMARK 8
  257. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  258. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  259. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  260. /**
  261. * struct iwl_rx_queue - Rx queue
  262. * @processed: Internal index to last handled Rx packet
  263. * @read: Shared index to newest available Rx buffer
  264. * @write: Shared index to oldest written Rx packet
  265. * @free_count: Number of pre-allocated buffers in rx_free
  266. * @rx_free: list of free SKBs for use
  267. * @rx_used: List of Rx buffers with no SKB
  268. * @need_update: flag to indicate we need to update read/write index
  269. *
  270. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  271. */
  272. struct iwl_rx_queue {
  273. __le32 *bd;
  274. dma_addr_t dma_addr;
  275. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  276. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  277. u32 processed;
  278. u32 read;
  279. u32 write;
  280. u32 free_count;
  281. struct list_head rx_free;
  282. struct list_head rx_used;
  283. int need_update;
  284. spinlock_t lock;
  285. };
  286. #define IWL_SUPPORTED_RATES_IE_LEN 8
  287. #define SCAN_INTERVAL 100
  288. #define MAX_A_CHANNELS 252
  289. #define MIN_A_CHANNELS 7
  290. #define MAX_B_CHANNELS 14
  291. #define MIN_B_CHANNELS 1
  292. #define MAX_TID_COUNT 9
  293. #define IWL_INVALID_RATE 0xFF
  294. #define IWL_INVALID_VALUE -1
  295. /**
  296. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  297. * @txq_id: Tx queue used for Tx attempt
  298. * @frame_count: # frames attempted by Tx command
  299. * @wait_for_ba: Expect block-ack before next Tx reply
  300. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  301. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  302. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  303. * @rate_n_flags: Rate at which Tx was attempted
  304. *
  305. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  306. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  307. * until block ack arrives.
  308. */
  309. struct iwl_ht_agg {
  310. u16 txq_id;
  311. u16 frame_count;
  312. u16 wait_for_ba;
  313. u16 start_idx;
  314. u64 bitmap;
  315. u32 rate_n_flags;
  316. #define IWL_AGG_OFF 0
  317. #define IWL_AGG_ON 1
  318. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  319. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  320. u8 state;
  321. };
  322. struct iwl_tid_data {
  323. u16 seq_number;
  324. u16 tfds_in_queue;
  325. struct iwl_ht_agg agg;
  326. };
  327. struct iwl_hw_key {
  328. enum ieee80211_key_alg alg;
  329. int keylen;
  330. u8 keyidx;
  331. u8 key[32];
  332. };
  333. union iwl4965_ht_rate_supp {
  334. u16 rates;
  335. struct {
  336. u8 siso_rate;
  337. u8 mimo_rate;
  338. };
  339. };
  340. #define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
  341. #define CFG_HT_MPDU_DENSITY_2USEC (0x5)
  342. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
  343. struct iwl_ht_info {
  344. /* self configuration data */
  345. u8 is_ht;
  346. u8 supported_chan_width;
  347. u8 sm_ps;
  348. u8 is_green_field;
  349. u8 sgf; /* HT_SHORT_GI_* short guard interval */
  350. u8 max_amsdu_size;
  351. u8 ampdu_factor;
  352. u8 mpdu_density;
  353. struct ieee80211_mcs_info mcs;
  354. /* BSS related data */
  355. u8 extension_chan_offset;
  356. u8 tx_chan_width;
  357. u8 ht_protection;
  358. u8 non_GF_STA_present;
  359. };
  360. union iwl_qos_capabity {
  361. struct {
  362. u8 edca_count:4; /* bit 0-3 */
  363. u8 q_ack:1; /* bit 4 */
  364. u8 queue_request:1; /* bit 5 */
  365. u8 txop_request:1; /* bit 6 */
  366. u8 reserved:1; /* bit 7 */
  367. } q_AP;
  368. struct {
  369. u8 acvo_APSD:1; /* bit 0 */
  370. u8 acvi_APSD:1; /* bit 1 */
  371. u8 ac_bk_APSD:1; /* bit 2 */
  372. u8 ac_be_APSD:1; /* bit 3 */
  373. u8 q_ack:1; /* bit 4 */
  374. u8 max_len:2; /* bit 5-6 */
  375. u8 more_data_ack:1; /* bit 7 */
  376. } q_STA;
  377. u8 val;
  378. };
  379. /* QoS structures */
  380. struct iwl_qos_info {
  381. int qos_enable;
  382. int qos_active;
  383. union iwl_qos_capabity qos_cap;
  384. struct iwl_qosparam_cmd def_qos_parm;
  385. };
  386. #define STA_PS_STATUS_WAKE 0
  387. #define STA_PS_STATUS_SLEEP 1
  388. struct iwl_station_entry {
  389. struct iwl_addsta_cmd sta;
  390. struct iwl_tid_data tid[MAX_TID_COUNT];
  391. u8 used;
  392. u8 ps_status;
  393. struct iwl_hw_key keyinfo;
  394. };
  395. /* one for each uCode image (inst/data, boot/init/runtime) */
  396. struct fw_desc {
  397. void *v_addr; /* access by driver */
  398. dma_addr_t p_addr; /* access by card's busmaster DMA */
  399. u32 len; /* bytes */
  400. };
  401. /* uCode file layout */
  402. struct iwl_ucode {
  403. __le32 ver; /* major/minor/subminor */
  404. __le32 inst_size; /* bytes of runtime instructions */
  405. __le32 data_size; /* bytes of runtime data */
  406. __le32 init_size; /* bytes of initialization instructions */
  407. __le32 init_data_size; /* bytes of initialization data */
  408. __le32 boot_size; /* bytes of bootstrap instructions */
  409. u8 data[0]; /* data in same order as "size" elements */
  410. };
  411. struct iwl4965_ibss_seq {
  412. u8 mac[ETH_ALEN];
  413. u16 seq_num;
  414. u16 frag_num;
  415. unsigned long packet_time;
  416. struct list_head list;
  417. };
  418. struct iwl_sensitivity_ranges {
  419. u16 min_nrg_cck;
  420. u16 max_nrg_cck;
  421. u16 nrg_th_cck;
  422. u16 nrg_th_ofdm;
  423. u16 auto_corr_min_ofdm;
  424. u16 auto_corr_min_ofdm_mrc;
  425. u16 auto_corr_min_ofdm_x1;
  426. u16 auto_corr_min_ofdm_mrc_x1;
  427. u16 auto_corr_max_ofdm;
  428. u16 auto_corr_max_ofdm_mrc;
  429. u16 auto_corr_max_ofdm_x1;
  430. u16 auto_corr_max_ofdm_mrc_x1;
  431. u16 auto_corr_max_cck;
  432. u16 auto_corr_max_cck_mrc;
  433. u16 auto_corr_min_cck;
  434. u16 auto_corr_min_cck_mrc;
  435. };
  436. #define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
  437. /**
  438. * struct iwl_hw_params
  439. * @max_txq_num: Max # Tx queues supported
  440. * @tx/rx_chains_num: Number of TX/RX chains
  441. * @valid_tx/rx_ant: usable antennas
  442. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  443. * @max_rxq_log: Log-base-2 of max_rxq_size
  444. * @rx_buf_size: Rx buffer size
  445. * @max_stations:
  446. * @bcast_sta_id:
  447. * @fat_channel: is 40MHz width possible in band 2.4
  448. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  449. * @sw_crypto: 0 for hw, 1 for sw
  450. * @max_xxx_size: for ucode uses
  451. * @ct_kill_threshold: temperature threshold
  452. * @calib_init_cfg: setup initial claibrations for the hw
  453. * @struct iwl_sensitivity_ranges: range of sensitivity values
  454. * @first_ampdu_q: first HW queue available for ampdu
  455. */
  456. struct iwl_hw_params {
  457. u16 max_txq_num;
  458. u8 tx_chains_num;
  459. u8 rx_chains_num;
  460. u8 valid_tx_ant;
  461. u8 valid_rx_ant;
  462. u16 max_rxq_size;
  463. u16 max_rxq_log;
  464. u32 rx_buf_size;
  465. u32 max_pkt_size;
  466. u8 max_stations;
  467. u8 bcast_sta_id;
  468. u8 fat_channel;
  469. u8 sw_crypto;
  470. u32 max_inst_size;
  471. u32 max_data_size;
  472. u32 max_bsm_size;
  473. u32 ct_kill_threshold; /* value in hw-dependent units */
  474. u32 calib_init_cfg;
  475. const struct iwl_sensitivity_ranges *sens;
  476. u8 first_ampdu_q;
  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. /* Opaque calibration results */
  596. struct iwl_calib_result {
  597. void *buf;
  598. size_t buf_len;
  599. };
  600. enum ucode_type {
  601. UCODE_NONE = 0,
  602. UCODE_INIT,
  603. UCODE_RT
  604. };
  605. /* Sensitivity calib data */
  606. struct iwl_sensitivity_data {
  607. u32 auto_corr_ofdm;
  608. u32 auto_corr_ofdm_mrc;
  609. u32 auto_corr_ofdm_x1;
  610. u32 auto_corr_ofdm_mrc_x1;
  611. u32 auto_corr_cck;
  612. u32 auto_corr_cck_mrc;
  613. u32 last_bad_plcp_cnt_ofdm;
  614. u32 last_fa_cnt_ofdm;
  615. u32 last_bad_plcp_cnt_cck;
  616. u32 last_fa_cnt_cck;
  617. u32 nrg_curr_state;
  618. u32 nrg_prev_state;
  619. u32 nrg_value[10];
  620. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  621. u32 nrg_silence_ref;
  622. u32 nrg_energy_idx;
  623. u32 nrg_silence_idx;
  624. u32 nrg_th_cck;
  625. s32 nrg_auto_corr_silence_diff;
  626. u32 num_in_cck_no_fa;
  627. u32 nrg_th_ofdm;
  628. };
  629. /* Chain noise (differential Rx gain) calib data */
  630. struct iwl_chain_noise_data {
  631. u32 active_chains;
  632. u32 chain_noise_a;
  633. u32 chain_noise_b;
  634. u32 chain_noise_c;
  635. u32 chain_signal_a;
  636. u32 chain_signal_b;
  637. u32 chain_signal_c;
  638. u16 beacon_count;
  639. u8 disconn_array[NUM_RX_CHAINS];
  640. u8 delta_gain_code[NUM_RX_CHAINS];
  641. u8 radio_write;
  642. u8 state;
  643. };
  644. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  645. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  646. enum {
  647. MEASUREMENT_READY = (1 << 0),
  648. MEASUREMENT_ACTIVE = (1 << 1),
  649. };
  650. #define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
  651. #define IWL_CALIB_MAX 4
  652. struct iwl_priv {
  653. /* ieee device used by generic ieee processing code */
  654. struct ieee80211_hw *hw;
  655. struct ieee80211_channel *ieee_channels;
  656. struct ieee80211_rate *ieee_rates;
  657. struct iwl_cfg *cfg;
  658. /* temporary frame storage list */
  659. struct list_head free_frames;
  660. int frames_count;
  661. enum ieee80211_band band;
  662. int alloc_rxb_skb;
  663. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  664. struct iwl_rx_mem_buffer *rxb);
  665. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  666. #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
  667. /* spectrum measurement report caching */
  668. struct iwl4965_spectrum_notification measure_report;
  669. u8 measurement_status;
  670. #endif
  671. /* ucode beacon time */
  672. u32 ucode_beacon_time;
  673. /* we allocate array of iwl4965_channel_info for NIC's valid channels.
  674. * Access via channel # using indirect index array */
  675. struct iwl_channel_info *channel_info; /* channel info array */
  676. u8 channel_count; /* # of channels */
  677. /* each calibration channel group in the EEPROM has a derived
  678. * clip setting for each rate. */
  679. const struct iwl4965_clip_group clip_groups[5];
  680. /* thermal calibration */
  681. s32 temperature; /* degrees Kelvin */
  682. s32 last_temperature;
  683. /* init calibration results */
  684. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  685. /* Scan related variables */
  686. unsigned long last_scan_jiffies;
  687. unsigned long next_scan_jiffies;
  688. unsigned long scan_start;
  689. unsigned long scan_pass_start;
  690. unsigned long scan_start_tsf;
  691. int scan_bands;
  692. int one_direct_scan;
  693. u8 direct_ssid_len;
  694. u8 direct_ssid[IW_ESSID_MAX_SIZE];
  695. struct iwl_scan_cmd *scan;
  696. u32 scan_tx_ant[IEEE80211_NUM_BANDS];
  697. /* spinlock */
  698. spinlock_t lock; /* protect general shared data */
  699. spinlock_t hcmd_lock; /* protect hcmd */
  700. struct mutex mutex;
  701. /* basic pci-network driver stuff */
  702. struct pci_dev *pci_dev;
  703. /* pci hardware address support */
  704. void __iomem *hw_base;
  705. u32 hw_rev;
  706. u32 hw_wa_rev;
  707. u8 rev_id;
  708. /* uCode images, save to reload in case of failure */
  709. struct fw_desc ucode_code; /* runtime inst */
  710. struct fw_desc ucode_data; /* runtime data original */
  711. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  712. struct fw_desc ucode_init; /* initialization inst */
  713. struct fw_desc ucode_init_data; /* initialization data */
  714. struct fw_desc ucode_boot; /* bootstrap inst */
  715. enum ucode_type ucode_type;
  716. u8 ucode_write_complete; /* the image write is complete */
  717. struct iwl_rxon_time_cmd rxon_timing;
  718. /* We declare this const so it can only be
  719. * changed via explicit cast within the
  720. * routines that actually update the physical
  721. * hardware */
  722. const struct iwl_rxon_cmd active_rxon;
  723. struct iwl_rxon_cmd staging_rxon;
  724. int error_recovering;
  725. struct iwl_rxon_cmd recovery_rxon;
  726. /* 1st responses from initialize and runtime uCode images.
  727. * 4965's initialize alive response contains some calibration data. */
  728. struct iwl_init_alive_resp card_alive_init;
  729. struct iwl_alive_resp card_alive;
  730. #ifdef CONFIG_IWLWIFI_RFKILL
  731. struct rfkill *rfkill;
  732. #endif
  733. #ifdef CONFIG_IWLWIFI_LEDS
  734. struct iwl_led led[IWL_LED_TRG_MAX];
  735. unsigned long last_blink_time;
  736. u8 last_blink_rate;
  737. u8 allow_blinking;
  738. u64 led_tpt;
  739. #endif
  740. u16 active_rate;
  741. u16 active_rate_basic;
  742. u8 assoc_station_added;
  743. u8 use_ant_b_for_management_frame; /* Tx antenna selection */
  744. u8 start_calib;
  745. struct iwl_sensitivity_data sensitivity_data;
  746. struct iwl_chain_noise_data chain_noise_data;
  747. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  748. struct iwl_ht_info current_ht_config;
  749. u8 last_phy_res[100];
  750. /* Rate scaling data */
  751. s8 data_retry_limit;
  752. u8 retry_rate;
  753. wait_queue_head_t wait_command_queue;
  754. int activity_timer_active;
  755. /* Rx and Tx DMA processing queues */
  756. struct iwl_rx_queue rxq;
  757. struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
  758. unsigned long txq_ctx_active_msk;
  759. struct iwl_kw kw; /* keep warm address */
  760. u32 scd_base_addr; /* scheduler sram base address */
  761. unsigned long status;
  762. int last_rx_rssi; /* From Rx packet statisitics */
  763. int last_rx_noise; /* From beacon statistics */
  764. /* counts mgmt, ctl, and data packets */
  765. struct traffic_stats {
  766. u32 cnt;
  767. u64 bytes;
  768. } tx_stats[3], rx_stats[3];
  769. struct iwl_power_mgr power_data;
  770. struct iwl_notif_statistics statistics;
  771. unsigned long last_statistics_time;
  772. /* context information */
  773. u8 essid[IW_ESSID_MAX_SIZE];
  774. u8 essid_len;
  775. u16 rates_mask;
  776. u32 power_mode;
  777. u32 antenna;
  778. u8 bssid[ETH_ALEN];
  779. u16 rts_threshold;
  780. u8 mac_addr[ETH_ALEN];
  781. /*station table variables */
  782. spinlock_t sta_lock;
  783. int num_stations;
  784. struct iwl_station_entry stations[IWL_STATION_COUNT];
  785. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  786. u8 default_wep_key;
  787. u8 key_mapping_key;
  788. unsigned long ucode_key_table;
  789. /* Indication if ieee80211_ops->open has been called */
  790. u8 is_open;
  791. u8 mac80211_registered;
  792. /* Rx'd packet timing information */
  793. u32 last_beacon_time;
  794. u64 last_tsf;
  795. /* eeprom */
  796. u8 *eeprom;
  797. struct iwl_eeprom_calib_info *calib_info;
  798. enum nl80211_iftype iw_mode;
  799. struct sk_buff *ibss_beacon;
  800. /* Last Rx'd beacon timestamp */
  801. u64 timestamp;
  802. u16 beacon_int;
  803. struct ieee80211_vif *vif;
  804. struct iwl_hw_params hw_params;
  805. /* driver/uCode shared Tx Byte Counts and Rx status */
  806. void *shared_virt;
  807. int rb_closed_offset;
  808. /* Physical Pointer to Tx Byte Counts and Rx status */
  809. dma_addr_t shared_phys;
  810. /* Current association information needed to configure the
  811. * hardware */
  812. u16 assoc_id;
  813. u16 assoc_capability;
  814. struct iwl_qos_info qos_data;
  815. struct workqueue_struct *workqueue;
  816. struct work_struct up;
  817. struct work_struct restart;
  818. struct work_struct calibrated_work;
  819. struct work_struct scan_completed;
  820. struct work_struct rx_replenish;
  821. struct work_struct rf_kill;
  822. struct work_struct abort_scan;
  823. struct work_struct update_link_led;
  824. struct work_struct auth_work;
  825. struct work_struct report_work;
  826. struct work_struct request_scan;
  827. struct work_struct beacon_update;
  828. struct work_struct set_monitor;
  829. struct tasklet_struct irq_tasklet;
  830. struct delayed_work set_power_save;
  831. struct delayed_work init_alive_start;
  832. struct delayed_work alive_start;
  833. struct delayed_work scan_check;
  834. /* TX Power */
  835. s8 tx_power_user_lmt;
  836. s8 tx_power_channel_lmt;
  837. #ifdef CONFIG_PM
  838. u32 pm_state[16];
  839. #endif
  840. #ifdef CONFIG_IWLWIFI_DEBUG
  841. /* debugging info */
  842. u32 debug_level;
  843. u32 framecnt_to_us;
  844. atomic_t restrict_refcnt;
  845. #ifdef CONFIG_IWLWIFI_DEBUGFS
  846. /* debugfs */
  847. struct iwl_debugfs *dbgfs;
  848. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  849. #endif /* CONFIG_IWLWIFI_DEBUG */
  850. struct work_struct txpower_work;
  851. u32 disable_sens_cal;
  852. u32 disable_chain_noise_cal;
  853. u32 disable_tx_power_cal;
  854. struct work_struct run_time_calib_work;
  855. struct timer_list statistics_periodic;
  856. }; /*iwl_priv */
  857. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  858. {
  859. set_bit(txq_id, &priv->txq_ctx_active_msk);
  860. }
  861. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  862. {
  863. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  864. }
  865. #ifdef CONFIG_IWLWIFI_DEBUG
  866. const char *iwl_get_tx_fail_reason(u32 status);
  867. #else
  868. static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
  869. #endif
  870. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  871. int txq_id, int idx)
  872. {
  873. if (priv->txq[txq_id].txb[idx].skb[0])
  874. return (struct ieee80211_hdr *)priv->txq[txq_id].
  875. txb[idx].skb[0]->data;
  876. return NULL;
  877. }
  878. static inline int iwl_is_associated(struct iwl_priv *priv)
  879. {
  880. return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  881. }
  882. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  883. {
  884. if (ch_info == NULL)
  885. return 0;
  886. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  887. }
  888. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  889. {
  890. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  891. }
  892. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  893. {
  894. return ch_info->band == IEEE80211_BAND_5GHZ;
  895. }
  896. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  897. {
  898. return ch_info->band == IEEE80211_BAND_2GHZ;
  899. }
  900. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  901. {
  902. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  903. }
  904. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  905. {
  906. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  907. }
  908. #ifdef CONFIG_IWLWIFI_DEBUG
  909. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  910. void *p, u32 len)
  911. {
  912. if (!(priv->debug_level & level))
  913. return;
  914. print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
  915. p, len, 1);
  916. }
  917. #else
  918. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  919. void *p, u32 len)
  920. {
  921. }
  922. #endif
  923. extern const struct iwl_channel_info *iwl_get_channel_info(
  924. const struct iwl_priv *priv, enum ieee80211_band band, u16 channel);
  925. /* Requires full declaration of iwl_priv before including */
  926. #endif /* __iwl_dev_h__ */