iwl-dev.h 31 KB

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