iwl-dev.h 31 KB

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