iwl-dev.h 29 KB

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