iwl-dev.h 28 KB

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