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