iwl-dev.h 29 KB

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