iwl-dev.h 29 KB

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