iwl-dev.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 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 <linux/wait.h>
  36. #include <linux/leds.h>
  37. #include <net/ieee80211_radiotap.h>
  38. #include "iwl-eeprom.h"
  39. #include "iwl-csr.h"
  40. #include "iwl-prph.h"
  41. #include "iwl-fh.h"
  42. #include "iwl-debug.h"
  43. #include "iwl-4965-hw.h"
  44. #include "iwl-3945-hw.h"
  45. #include "iwl-agn-hw.h"
  46. #include "iwl-led.h"
  47. #include "iwl-power.h"
  48. #include "iwl-agn-rs.h"
  49. #include "iwl-agn-tt.h"
  50. struct iwl_tx_queue;
  51. /* CT-KILL constants */
  52. #define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
  53. #define CT_KILL_THRESHOLD 114 /* in Celsius */
  54. #define CT_KILL_EXIT_THRESHOLD 95 /* 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 page_dma;
  85. struct page *page;
  86. struct list_head list;
  87. };
  88. #define rxb_addr(r) page_address(r->page)
  89. /* defined below */
  90. struct iwl_device_cmd;
  91. struct iwl_cmd_meta {
  92. /* only for SYNC commands, iff the reply skb is wanted */
  93. struct iwl_host_cmd *source;
  94. /*
  95. * only for ASYNC commands
  96. * (which is somewhat stupid -- look at iwl-sta.c for instance
  97. * which duplicates a bunch of code because the callback isn't
  98. * invoked for SYNC commands, if it were and its result passed
  99. * through it would be simpler...)
  100. */
  101. void (*callback)(struct iwl_priv *priv,
  102. struct iwl_device_cmd *cmd,
  103. struct iwl_rx_packet *pkt);
  104. /* The CMD_SIZE_HUGE flag bit indicates that the command
  105. * structure is stored at the end of the shared queue memory. */
  106. u32 flags;
  107. DEFINE_DMA_UNMAP_ADDR(mapping);
  108. DEFINE_DMA_UNMAP_LEN(len);
  109. };
  110. /*
  111. * Generic queue structure
  112. *
  113. * Contains common data for Rx and Tx queues
  114. */
  115. struct iwl_queue {
  116. int n_bd; /* number of BDs in this queue */
  117. int write_ptr; /* 1-st empty entry (index) host_w*/
  118. int read_ptr; /* last used entry (index) host_r*/
  119. /* use for monitoring and recovering the stuck queue */
  120. dma_addr_t dma_addr; /* physical addr for BD's */
  121. int n_window; /* safe queue window */
  122. u32 id;
  123. int low_mark; /* low watermark, resume queue if free
  124. * space more than this */
  125. int high_mark; /* high watermark, stop queue if free
  126. * space less than this */
  127. };
  128. /* One for each TFD */
  129. struct iwl_tx_info {
  130. struct sk_buff *skb;
  131. struct iwl_rxon_context *ctx;
  132. };
  133. /**
  134. * struct iwl_tx_queue - Tx Queue for DMA
  135. * @q: generic Rx/Tx queue descriptor
  136. * @bd: base of circular buffer of TFDs
  137. * @cmd: array of command/TX buffer pointers
  138. * @meta: array of meta data for each command/tx buffer
  139. * @dma_addr_cmd: physical address of cmd/tx buffer array
  140. * @txb: array of per-TFD driver data
  141. * @time_stamp: time (in jiffies) of last read_ptr change
  142. * @need_update: indicates need to update read/write index
  143. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  144. *
  145. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  146. * descriptors) and required locking structures.
  147. */
  148. #define TFD_TX_CMD_SLOTS 256
  149. #define TFD_CMD_SLOTS 32
  150. struct iwl_tx_queue {
  151. struct iwl_queue q;
  152. void *tfds;
  153. struct iwl_device_cmd **cmd;
  154. struct iwl_cmd_meta *meta;
  155. struct iwl_tx_info *txb;
  156. unsigned long time_stamp;
  157. u8 need_update;
  158. u8 sched_retry;
  159. u8 active;
  160. u8 swq_id;
  161. };
  162. #define IWL_NUM_SCAN_RATES (2)
  163. struct iwl4965_channel_tgd_info {
  164. u8 type;
  165. s8 max_power;
  166. };
  167. struct iwl4965_channel_tgh_info {
  168. s64 last_radar_time;
  169. };
  170. #define IWL4965_MAX_RATE (33)
  171. struct iwl3945_clip_group {
  172. /* maximum power level to prevent clipping for each rate, derived by
  173. * us from this band's saturation power in EEPROM */
  174. const s8 clip_powers[IWL_MAX_RATES];
  175. };
  176. /* current Tx power values to use, one for each rate for each channel.
  177. * requested power is limited by:
  178. * -- regulatory EEPROM limits for this channel
  179. * -- hardware capabilities (clip-powers)
  180. * -- spectrum management
  181. * -- user preference (e.g. iwconfig)
  182. * when requested power is set, base power index must also be set. */
  183. struct iwl3945_channel_power_info {
  184. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  185. s8 power_table_index; /* actual (compenst'd) index into gain table */
  186. s8 base_power_index; /* gain index for power at factory temp. */
  187. s8 requested_power; /* power (dBm) requested for this chnl/rate */
  188. };
  189. /* current scan Tx power values to use, one for each scan rate for each
  190. * channel. */
  191. struct iwl3945_scan_power_info {
  192. struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */
  193. s8 power_table_index; /* actual (compenst'd) index into gain table */
  194. s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
  195. };
  196. /*
  197. * One for each channel, holds all channel setup data
  198. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  199. * with one another!
  200. */
  201. struct iwl_channel_info {
  202. struct iwl4965_channel_tgd_info tgd;
  203. struct iwl4965_channel_tgh_info tgh;
  204. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  205. struct iwl_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
  206. * HT40 channel */
  207. u8 channel; /* channel number */
  208. u8 flags; /* flags copied from EEPROM */
  209. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  210. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  211. s8 min_power; /* always 0 */
  212. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  213. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  214. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  215. enum ieee80211_band band;
  216. /* HT40 channel info */
  217. s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  218. u8 ht40_flags; /* flags copied from EEPROM */
  219. u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  220. /* Radio/DSP gain settings for each "normal" data Tx rate.
  221. * These include, in addition to RF and DSP gain, a few fields for
  222. * remembering/modifying gain settings (indexes). */
  223. struct iwl3945_channel_power_info power_info[IWL4965_MAX_RATE];
  224. /* Radio/DSP gain settings for each scan rate, for directed scans. */
  225. struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
  226. };
  227. #define IWL_TX_FIFO_BK 0 /* shared */
  228. #define IWL_TX_FIFO_BE 1
  229. #define IWL_TX_FIFO_VI 2 /* shared */
  230. #define IWL_TX_FIFO_VO 3
  231. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  232. #define IWL_TX_FIFO_BE_IPAN 4
  233. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  234. #define IWL_TX_FIFO_VO_IPAN 5
  235. #define IWL_TX_FIFO_UNUSED -1
  236. /* Minimum number of queues. MAX_NUM is defined in hw specific files.
  237. * Set the minimum to accommodate the 4 standard TX queues, 1 command
  238. * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
  239. #define IWL_MIN_NUM_QUEUES 10
  240. /*
  241. * Command queue depends on iPAN support.
  242. */
  243. #define IWL_DEFAULT_CMD_QUEUE_NUM 4
  244. #define IWL_IPAN_CMD_QUEUE_NUM 9
  245. /*
  246. * This queue number is required for proper operation
  247. * because the ucode will stop/start the scheduler as
  248. * required.
  249. */
  250. #define IWL_IPAN_MCAST_QUEUE 8
  251. #define IEEE80211_DATA_LEN 2304
  252. #define IEEE80211_4ADDR_LEN 30
  253. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  254. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  255. struct iwl_frame {
  256. union {
  257. struct ieee80211_hdr frame;
  258. struct iwl_tx_beacon_cmd beacon;
  259. u8 raw[IEEE80211_FRAME_LEN];
  260. u8 cmd[360];
  261. } u;
  262. struct list_head list;
  263. };
  264. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  265. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  266. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  267. enum {
  268. CMD_SYNC = 0,
  269. CMD_SIZE_NORMAL = 0,
  270. CMD_NO_SKB = 0,
  271. CMD_SIZE_HUGE = (1 << 0),
  272. CMD_ASYNC = (1 << 1),
  273. CMD_WANT_SKB = (1 << 2),
  274. };
  275. #define DEF_CMD_PAYLOAD_SIZE 320
  276. /**
  277. * struct iwl_device_cmd
  278. *
  279. * For allocation of the command and tx queues, this establishes the overall
  280. * size of the largest command we send to uCode, except for a scan command
  281. * (which is relatively huge; space is allocated separately).
  282. */
  283. struct iwl_device_cmd {
  284. struct iwl_cmd_header hdr; /* uCode API */
  285. union {
  286. u32 flags;
  287. u8 val8;
  288. u16 val16;
  289. u32 val32;
  290. struct iwl_tx_cmd tx;
  291. struct iwl6000_channel_switch_cmd chswitch;
  292. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  293. } __packed cmd;
  294. } __packed;
  295. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  296. struct iwl_host_cmd {
  297. const void *data;
  298. unsigned long reply_page;
  299. void (*callback)(struct iwl_priv *priv,
  300. struct iwl_device_cmd *cmd,
  301. struct iwl_rx_packet *pkt);
  302. u32 flags;
  303. u16 len;
  304. u8 id;
  305. };
  306. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  307. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  308. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  309. /**
  310. * struct iwl_rx_queue - Rx queue
  311. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  312. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  313. * @read: Shared index to newest available Rx buffer
  314. * @write: Shared index to oldest written Rx packet
  315. * @free_count: Number of pre-allocated buffers in rx_free
  316. * @rx_free: list of free SKBs for use
  317. * @rx_used: List of Rx buffers with no SKB
  318. * @need_update: flag to indicate we need to update read/write index
  319. * @rb_stts: driver's pointer to receive buffer status
  320. * @rb_stts_dma: bus address of receive buffer status
  321. *
  322. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  323. */
  324. struct iwl_rx_queue {
  325. __le32 *bd;
  326. dma_addr_t bd_dma;
  327. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  328. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  329. u32 read;
  330. u32 write;
  331. u32 free_count;
  332. u32 write_actual;
  333. struct list_head rx_free;
  334. struct list_head rx_used;
  335. int need_update;
  336. struct iwl_rb_status *rb_stts;
  337. dma_addr_t rb_stts_dma;
  338. spinlock_t lock;
  339. };
  340. #define IWL_SUPPORTED_RATES_IE_LEN 8
  341. #define MAX_TID_COUNT 9
  342. #define IWL_INVALID_RATE 0xFF
  343. #define IWL_INVALID_VALUE -1
  344. /**
  345. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  346. * @txq_id: Tx queue used for Tx attempt
  347. * @frame_count: # frames attempted by Tx command
  348. * @wait_for_ba: Expect block-ack before next Tx reply
  349. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  350. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  351. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  352. * @rate_n_flags: Rate at which Tx was attempted
  353. *
  354. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  355. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  356. * until block ack arrives.
  357. */
  358. struct iwl_ht_agg {
  359. u16 txq_id;
  360. u16 frame_count;
  361. u16 wait_for_ba;
  362. u16 start_idx;
  363. u64 bitmap;
  364. u32 rate_n_flags;
  365. #define IWL_AGG_OFF 0
  366. #define IWL_AGG_ON 1
  367. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  368. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  369. u8 state;
  370. };
  371. struct iwl_tid_data {
  372. u16 seq_number; /* agn only */
  373. u16 tfds_in_queue;
  374. struct iwl_ht_agg agg;
  375. };
  376. struct iwl_hw_key {
  377. u32 cipher;
  378. int keylen;
  379. u8 keyidx;
  380. u8 key[32];
  381. };
  382. union iwl_ht_rate_supp {
  383. u16 rates;
  384. struct {
  385. u8 siso_rate;
  386. u8 mimo_rate;
  387. };
  388. };
  389. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  390. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  391. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  392. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  393. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  394. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  395. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  396. /*
  397. * Maximal MPDU density for TX aggregation
  398. * 4 - 2us density
  399. * 5 - 4us density
  400. * 6 - 8us density
  401. * 7 - 16us density
  402. */
  403. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  404. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  405. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  406. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  407. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  408. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  409. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  410. struct iwl_ht_config {
  411. bool single_chain_sufficient;
  412. enum ieee80211_smps_mode smps; /* current smps mode */
  413. };
  414. /* QoS structures */
  415. struct iwl_qos_info {
  416. int qos_active;
  417. struct iwl_qosparam_cmd def_qos_parm;
  418. };
  419. /*
  420. * Structure should be accessed with sta_lock held. When station addition
  421. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  422. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  423. * held.
  424. */
  425. struct iwl_station_entry {
  426. struct iwl_addsta_cmd sta;
  427. struct iwl_tid_data tid[MAX_TID_COUNT];
  428. u8 used, ctxid;
  429. struct iwl_hw_key keyinfo;
  430. struct iwl_link_quality_cmd *lq;
  431. };
  432. struct iwl_station_priv_common {
  433. struct iwl_rxon_context *ctx;
  434. u8 sta_id;
  435. };
  436. /*
  437. * iwl_station_priv: Driver's private station information
  438. *
  439. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  440. * in the structure for use by driver. This structure is places in that
  441. * space.
  442. *
  443. * The common struct MUST be first because it is shared between
  444. * 3945 and agn!
  445. */
  446. struct iwl_station_priv {
  447. struct iwl_station_priv_common common;
  448. struct iwl_lq_sta lq_sta;
  449. atomic_t pending_frames;
  450. bool client;
  451. bool asleep;
  452. u8 max_agg_bufsize;
  453. };
  454. /**
  455. * struct iwl_vif_priv - driver's private per-interface information
  456. *
  457. * When mac80211 allocates a virtual interface, it can allocate
  458. * space for us to put data into.
  459. */
  460. struct iwl_vif_priv {
  461. struct iwl_rxon_context *ctx;
  462. u8 ibss_bssid_sta_id;
  463. };
  464. /* one for each uCode image (inst/data, boot/init/runtime) */
  465. struct fw_desc {
  466. void *v_addr; /* access by driver */
  467. dma_addr_t p_addr; /* access by card's busmaster DMA */
  468. u32 len; /* bytes */
  469. };
  470. /* v1/v2 uCode file layout */
  471. struct iwl_ucode_header {
  472. __le32 ver; /* major/minor/API/serial */
  473. union {
  474. struct {
  475. __le32 inst_size; /* bytes of runtime code */
  476. __le32 data_size; /* bytes of runtime data */
  477. __le32 init_size; /* bytes of init code */
  478. __le32 init_data_size; /* bytes of init data */
  479. __le32 boot_size; /* bytes of bootstrap code */
  480. u8 data[0]; /* in same order as sizes */
  481. } v1;
  482. struct {
  483. __le32 build; /* build number */
  484. __le32 inst_size; /* bytes of runtime code */
  485. __le32 data_size; /* bytes of runtime data */
  486. __le32 init_size; /* bytes of init code */
  487. __le32 init_data_size; /* bytes of init data */
  488. __le32 boot_size; /* bytes of bootstrap code */
  489. u8 data[0]; /* in same order as sizes */
  490. } v2;
  491. } u;
  492. };
  493. /*
  494. * new TLV uCode file layout
  495. *
  496. * The new TLV file format contains TLVs, that each specify
  497. * some piece of data. To facilitate "groups", for example
  498. * different instruction image with different capabilities,
  499. * bundled with the same init image, an alternative mechanism
  500. * is provided:
  501. * When the alternative field is 0, that means that the item
  502. * is always valid. When it is non-zero, then it is only
  503. * valid in conjunction with items of the same alternative,
  504. * in which case the driver (user) selects one alternative
  505. * to use.
  506. */
  507. enum iwl_ucode_tlv_type {
  508. IWL_UCODE_TLV_INVALID = 0, /* unused */
  509. IWL_UCODE_TLV_INST = 1,
  510. IWL_UCODE_TLV_DATA = 2,
  511. IWL_UCODE_TLV_INIT = 3,
  512. IWL_UCODE_TLV_INIT_DATA = 4,
  513. IWL_UCODE_TLV_BOOT = 5,
  514. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  515. IWL_UCODE_TLV_PAN = 7,
  516. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  517. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  518. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  519. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  520. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  521. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  522. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  523. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  524. };
  525. struct iwl_ucode_tlv {
  526. __le16 type; /* see above */
  527. __le16 alternative; /* see comment */
  528. __le32 length; /* not including type/length fields */
  529. u8 data[0];
  530. } __packed;
  531. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  532. struct iwl_tlv_ucode_header {
  533. /*
  534. * The TLV style ucode header is distinguished from
  535. * the v1/v2 style header by first four bytes being
  536. * zero, as such is an invalid combination of
  537. * major/minor/API/serial versions.
  538. */
  539. __le32 zero;
  540. __le32 magic;
  541. u8 human_readable[64];
  542. __le32 ver; /* major/minor/API/serial */
  543. __le32 build;
  544. __le64 alternatives; /* bitmask of valid alternatives */
  545. /*
  546. * The data contained herein has a TLV layout,
  547. * see above for the TLV header and types.
  548. * Note that each TLV is padded to a length
  549. * that is a multiple of 4 for alignment.
  550. */
  551. u8 data[0];
  552. };
  553. struct iwl4965_ibss_seq {
  554. u8 mac[ETH_ALEN];
  555. u16 seq_num;
  556. u16 frag_num;
  557. unsigned long packet_time;
  558. struct list_head list;
  559. };
  560. struct iwl_sensitivity_ranges {
  561. u16 min_nrg_cck;
  562. u16 max_nrg_cck;
  563. u16 nrg_th_cck;
  564. u16 nrg_th_ofdm;
  565. u16 auto_corr_min_ofdm;
  566. u16 auto_corr_min_ofdm_mrc;
  567. u16 auto_corr_min_ofdm_x1;
  568. u16 auto_corr_min_ofdm_mrc_x1;
  569. u16 auto_corr_max_ofdm;
  570. u16 auto_corr_max_ofdm_mrc;
  571. u16 auto_corr_max_ofdm_x1;
  572. u16 auto_corr_max_ofdm_mrc_x1;
  573. u16 auto_corr_max_cck;
  574. u16 auto_corr_max_cck_mrc;
  575. u16 auto_corr_min_cck;
  576. u16 auto_corr_min_cck_mrc;
  577. u16 barker_corr_th_min;
  578. u16 barker_corr_th_min_mrc;
  579. u16 nrg_th_cca;
  580. };
  581. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  582. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  583. /**
  584. * struct iwl_hw_params
  585. * @max_txq_num: Max # Tx queues supported
  586. * @dma_chnl_num: Number of Tx DMA/FIFO channels
  587. * @scd_bc_tbls_size: size of scheduler byte count tables
  588. * @tfd_size: TFD size
  589. * @tx/rx_chains_num: Number of TX/RX chains
  590. * @valid_tx/rx_ant: usable antennas
  591. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  592. * @max_rxq_log: Log-base-2 of max_rxq_size
  593. * @rx_page_order: Rx buffer page order
  594. * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
  595. * @max_stations:
  596. * @ht40_channel: is 40MHz width possible in band 2.4
  597. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  598. * @sw_crypto: 0 for hw, 1 for sw
  599. * @max_xxx_size: for ucode uses
  600. * @ct_kill_threshold: temperature threshold
  601. * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
  602. * @calib_init_cfg: setup initial calibrations for the hw
  603. * @calib_rt_cfg: setup runtime calibrations for the hw
  604. * @struct iwl_sensitivity_ranges: range of sensitivity values
  605. */
  606. struct iwl_hw_params {
  607. u8 max_txq_num;
  608. u8 dma_chnl_num;
  609. u16 scd_bc_tbls_size;
  610. u32 tfd_size;
  611. u8 tx_chains_num;
  612. u8 rx_chains_num;
  613. u8 valid_tx_ant;
  614. u8 valid_rx_ant;
  615. u16 max_rxq_size;
  616. u16 max_rxq_log;
  617. u32 rx_page_order;
  618. u32 rx_wrt_ptr_reg;
  619. u8 max_stations;
  620. u8 ht40_channel;
  621. u8 max_beacon_itrvl; /* in 1024 ms */
  622. u32 max_inst_size;
  623. u32 max_data_size;
  624. u32 max_bsm_size;
  625. u32 ct_kill_threshold; /* value in hw-dependent units */
  626. u32 ct_kill_exit_threshold; /* value in hw-dependent units */
  627. /* for 1000, 6000 series and up */
  628. u16 beacon_time_tsf_bits;
  629. u32 calib_init_cfg;
  630. u32 calib_rt_cfg;
  631. const struct iwl_sensitivity_ranges *sens;
  632. };
  633. /******************************************************************************
  634. *
  635. * Functions implemented in core module which are forward declared here
  636. * for use by iwl-[4-5].c
  637. *
  638. * NOTE: The implementation of these functions are not hardware specific
  639. * which is why they are in the core module files.
  640. *
  641. * Naming convention --
  642. * iwl_ <-- Is part of iwlwifi
  643. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  644. * iwl4965_bg_ <-- Called from work queue context
  645. * iwl4965_mac_ <-- mac80211 callback
  646. *
  647. ****************************************************************************/
  648. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  649. extern const u8 iwl_bcast_addr[ETH_ALEN];
  650. extern int iwl_rxq_stop(struct iwl_priv *priv);
  651. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  652. extern int iwl_queue_space(const struct iwl_queue *q);
  653. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  654. {
  655. return q->write_ptr >= q->read_ptr ?
  656. (i >= q->read_ptr && i < q->write_ptr) :
  657. !(i < q->read_ptr && i >= q->write_ptr);
  658. }
  659. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
  660. {
  661. /*
  662. * This is for init calibration result and scan command which
  663. * required buffer > TFD_MAX_PAYLOAD_SIZE,
  664. * the big buffer at end of command array
  665. */
  666. if (is_huge)
  667. return q->n_window; /* must be power of 2 */
  668. /* Otherwise, use normal size buffers */
  669. return index & (q->n_window - 1);
  670. }
  671. struct iwl_dma_ptr {
  672. dma_addr_t dma;
  673. void *addr;
  674. size_t size;
  675. };
  676. #define IWL_OPERATION_MODE_AUTO 0
  677. #define IWL_OPERATION_MODE_HT_ONLY 1
  678. #define IWL_OPERATION_MODE_MIXED 2
  679. #define IWL_OPERATION_MODE_20MHZ 3
  680. #define IWL_TX_CRC_SIZE 4
  681. #define IWL_TX_DELIMITER_SIZE 4
  682. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  683. /* Sensitivity and chain noise calibration */
  684. #define INITIALIZATION_VALUE 0xFFFF
  685. #define IWL4965_CAL_NUM_BEACONS 20
  686. #define IWL_CAL_NUM_BEACONS 16
  687. #define MAXIMUM_ALLOWED_PATHLOSS 15
  688. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  689. #define MAX_FA_OFDM 50
  690. #define MIN_FA_OFDM 5
  691. #define MAX_FA_CCK 50
  692. #define MIN_FA_CCK 5
  693. #define AUTO_CORR_STEP_OFDM 1
  694. #define AUTO_CORR_STEP_CCK 3
  695. #define AUTO_CORR_MAX_TH_CCK 160
  696. #define NRG_DIFF 2
  697. #define NRG_STEP_CCK 2
  698. #define NRG_MARGIN 8
  699. #define MAX_NUMBER_CCK_NO_FA 100
  700. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  701. #define CHAIN_A 0
  702. #define CHAIN_B 1
  703. #define CHAIN_C 2
  704. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  705. #define ALL_BAND_FILTER 0xFF00
  706. #define IN_BAND_FILTER 0xFF
  707. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  708. #define NRG_NUM_PREV_STAT_L 20
  709. #define NUM_RX_CHAINS 3
  710. enum iwl4965_false_alarm_state {
  711. IWL_FA_TOO_MANY = 0,
  712. IWL_FA_TOO_FEW = 1,
  713. IWL_FA_GOOD_RANGE = 2,
  714. };
  715. enum iwl4965_chain_noise_state {
  716. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  717. IWL_CHAIN_NOISE_ACCUMULATE,
  718. IWL_CHAIN_NOISE_CALIBRATED,
  719. IWL_CHAIN_NOISE_DONE,
  720. };
  721. enum iwl4965_calib_enabled_state {
  722. IWL_CALIB_DISABLED = 0, /* must be 0 */
  723. IWL_CALIB_ENABLED = 1,
  724. };
  725. /*
  726. * enum iwl_calib
  727. * defines the order in which results of initial calibrations
  728. * should be sent to the runtime uCode
  729. */
  730. enum iwl_calib {
  731. IWL_CALIB_XTAL,
  732. IWL_CALIB_DC,
  733. IWL_CALIB_LO,
  734. IWL_CALIB_TX_IQ,
  735. IWL_CALIB_TX_IQ_PERD,
  736. IWL_CALIB_BASE_BAND,
  737. IWL_CALIB_TEMP_OFFSET,
  738. IWL_CALIB_MAX
  739. };
  740. /* Opaque calibration results */
  741. struct iwl_calib_result {
  742. void *buf;
  743. size_t buf_len;
  744. };
  745. enum ucode_type {
  746. UCODE_NONE = 0,
  747. UCODE_INIT,
  748. UCODE_RT
  749. };
  750. /* Sensitivity calib data */
  751. struct iwl_sensitivity_data {
  752. u32 auto_corr_ofdm;
  753. u32 auto_corr_ofdm_mrc;
  754. u32 auto_corr_ofdm_x1;
  755. u32 auto_corr_ofdm_mrc_x1;
  756. u32 auto_corr_cck;
  757. u32 auto_corr_cck_mrc;
  758. u32 last_bad_plcp_cnt_ofdm;
  759. u32 last_fa_cnt_ofdm;
  760. u32 last_bad_plcp_cnt_cck;
  761. u32 last_fa_cnt_cck;
  762. u32 nrg_curr_state;
  763. u32 nrg_prev_state;
  764. u32 nrg_value[10];
  765. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  766. u32 nrg_silence_ref;
  767. u32 nrg_energy_idx;
  768. u32 nrg_silence_idx;
  769. u32 nrg_th_cck;
  770. s32 nrg_auto_corr_silence_diff;
  771. u32 num_in_cck_no_fa;
  772. u32 nrg_th_ofdm;
  773. u16 barker_corr_th_min;
  774. u16 barker_corr_th_min_mrc;
  775. u16 nrg_th_cca;
  776. };
  777. /* Chain noise (differential Rx gain) calib data */
  778. struct iwl_chain_noise_data {
  779. u32 active_chains;
  780. u32 chain_noise_a;
  781. u32 chain_noise_b;
  782. u32 chain_noise_c;
  783. u32 chain_signal_a;
  784. u32 chain_signal_b;
  785. u32 chain_signal_c;
  786. u16 beacon_count;
  787. u8 disconn_array[NUM_RX_CHAINS];
  788. u8 delta_gain_code[NUM_RX_CHAINS];
  789. u8 radio_write;
  790. u8 state;
  791. };
  792. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  793. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  794. #define IWL_TRAFFIC_ENTRIES (256)
  795. #define IWL_TRAFFIC_ENTRY_SIZE (64)
  796. enum {
  797. MEASUREMENT_READY = (1 << 0),
  798. MEASUREMENT_ACTIVE = (1 << 1),
  799. };
  800. enum iwl_nvm_type {
  801. NVM_DEVICE_TYPE_EEPROM = 0,
  802. NVM_DEVICE_TYPE_OTP,
  803. };
  804. /*
  805. * Two types of OTP memory access modes
  806. * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
  807. * based on physical memory addressing
  808. * IWL_OTP_ACCESS_RELATIVE - relative address mode,
  809. * based on logical memory addressing
  810. */
  811. enum iwl_access_mode {
  812. IWL_OTP_ACCESS_ABSOLUTE,
  813. IWL_OTP_ACCESS_RELATIVE,
  814. };
  815. /**
  816. * enum iwl_pa_type - Power Amplifier type
  817. * @IWL_PA_SYSTEM: based on uCode configuration
  818. * @IWL_PA_INTERNAL: use Internal only
  819. */
  820. enum iwl_pa_type {
  821. IWL_PA_SYSTEM = 0,
  822. IWL_PA_INTERNAL = 1,
  823. };
  824. /* interrupt statistics */
  825. struct isr_statistics {
  826. u32 hw;
  827. u32 sw;
  828. u32 err_code;
  829. u32 sch;
  830. u32 alive;
  831. u32 rfkill;
  832. u32 ctkill;
  833. u32 wakeup;
  834. u32 rx;
  835. u32 rx_handlers[REPLY_MAX];
  836. u32 tx;
  837. u32 unhandled;
  838. };
  839. /* reply_tx_statistics (for _agn devices) */
  840. struct reply_tx_error_statistics {
  841. u32 pp_delay;
  842. u32 pp_few_bytes;
  843. u32 pp_bt_prio;
  844. u32 pp_quiet_period;
  845. u32 pp_calc_ttak;
  846. u32 int_crossed_retry;
  847. u32 short_limit;
  848. u32 long_limit;
  849. u32 fifo_underrun;
  850. u32 drain_flow;
  851. u32 rfkill_flush;
  852. u32 life_expire;
  853. u32 dest_ps;
  854. u32 host_abort;
  855. u32 bt_retry;
  856. u32 sta_invalid;
  857. u32 frag_drop;
  858. u32 tid_disable;
  859. u32 fifo_flush;
  860. u32 insuff_cf_poll;
  861. u32 fail_hw_drop;
  862. u32 sta_color_mismatch;
  863. u32 unknown;
  864. };
  865. /* reply_agg_tx_statistics (for _agn devices) */
  866. struct reply_agg_tx_error_statistics {
  867. u32 underrun;
  868. u32 bt_prio;
  869. u32 few_bytes;
  870. u32 abort;
  871. u32 last_sent_ttl;
  872. u32 last_sent_try;
  873. u32 last_sent_bt_kill;
  874. u32 scd_query;
  875. u32 bad_crc32;
  876. u32 response;
  877. u32 dump_tx;
  878. u32 delay_tx;
  879. u32 unknown;
  880. };
  881. /* management statistics */
  882. enum iwl_mgmt_stats {
  883. MANAGEMENT_ASSOC_REQ = 0,
  884. MANAGEMENT_ASSOC_RESP,
  885. MANAGEMENT_REASSOC_REQ,
  886. MANAGEMENT_REASSOC_RESP,
  887. MANAGEMENT_PROBE_REQ,
  888. MANAGEMENT_PROBE_RESP,
  889. MANAGEMENT_BEACON,
  890. MANAGEMENT_ATIM,
  891. MANAGEMENT_DISASSOC,
  892. MANAGEMENT_AUTH,
  893. MANAGEMENT_DEAUTH,
  894. MANAGEMENT_ACTION,
  895. MANAGEMENT_MAX,
  896. };
  897. /* control statistics */
  898. enum iwl_ctrl_stats {
  899. CONTROL_BACK_REQ = 0,
  900. CONTROL_BACK,
  901. CONTROL_PSPOLL,
  902. CONTROL_RTS,
  903. CONTROL_CTS,
  904. CONTROL_ACK,
  905. CONTROL_CFEND,
  906. CONTROL_CFENDACK,
  907. CONTROL_MAX,
  908. };
  909. struct traffic_stats {
  910. #ifdef CONFIG_IWLWIFI_DEBUGFS
  911. u32 mgmt[MANAGEMENT_MAX];
  912. u32 ctrl[CONTROL_MAX];
  913. u32 data_cnt;
  914. u64 data_bytes;
  915. #endif
  916. };
  917. /*
  918. * iwl_switch_rxon: "channel switch" structure
  919. *
  920. * @ switch_in_progress: channel switch in progress
  921. * @ channel: new channel
  922. */
  923. struct iwl_switch_rxon {
  924. bool switch_in_progress;
  925. __le16 channel;
  926. };
  927. /*
  928. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  929. * to perform continuous uCode event logging operation if enabled
  930. */
  931. #define UCODE_TRACE_PERIOD (100)
  932. /*
  933. * iwl_event_log: current uCode event log position
  934. *
  935. * @ucode_trace: enable/disable ucode continuous trace timer
  936. * @num_wraps: how many times the event buffer wraps
  937. * @next_entry: the entry just before the next one that uCode would fill
  938. * @non_wraps_count: counter for no wrap detected when dump ucode events
  939. * @wraps_once_count: counter for wrap once detected when dump ucode events
  940. * @wraps_more_count: counter for wrap more than once detected
  941. * when dump ucode events
  942. */
  943. struct iwl_event_log {
  944. bool ucode_trace;
  945. u32 num_wraps;
  946. u32 next_entry;
  947. int non_wraps_count;
  948. int wraps_once_count;
  949. int wraps_more_count;
  950. };
  951. /*
  952. * host interrupt timeout value
  953. * used with setting interrupt coalescing timer
  954. * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
  955. *
  956. * default interrupt coalescing timer is 64 x 32 = 2048 usecs
  957. * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
  958. */
  959. #define IWL_HOST_INT_TIMEOUT_MAX (0xFF)
  960. #define IWL_HOST_INT_TIMEOUT_DEF (0x40)
  961. #define IWL_HOST_INT_TIMEOUT_MIN (0x0)
  962. #define IWL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
  963. #define IWL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
  964. #define IWL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
  965. /*
  966. * This is the threshold value of plcp error rate per 100mSecs. It is
  967. * used to set and check for the validity of plcp_delta.
  968. */
  969. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  970. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  971. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  972. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  973. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  974. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  975. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  976. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  977. /* TX queue watchdog timeouts in mSecs */
  978. #define IWL_DEF_WD_TIMEOUT (2000)
  979. #define IWL_LONG_WD_TIMEOUT (10000)
  980. #define IWL_MAX_WD_TIMEOUT (120000)
  981. /* BT Antenna Coupling Threshold (dB) */
  982. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  983. enum iwl_reset {
  984. IWL_RF_RESET = 0,
  985. IWL_FW_RESET,
  986. IWL_MAX_FORCE_RESET,
  987. };
  988. struct iwl_force_reset {
  989. int reset_request_count;
  990. int reset_success_count;
  991. int reset_reject_count;
  992. unsigned long reset_duration;
  993. unsigned long last_force_reset_jiffies;
  994. };
  995. /* extend beacon time format bit shifting */
  996. /*
  997. * for _3945 devices
  998. * bits 31:24 - extended
  999. * bits 23:0 - interval
  1000. */
  1001. #define IWL3945_EXT_BEACON_TIME_POS 24
  1002. /*
  1003. * for _agn devices
  1004. * bits 31:22 - extended
  1005. * bits 21:0 - interval
  1006. */
  1007. #define IWLAGN_EXT_BEACON_TIME_POS 22
  1008. /**
  1009. * struct iwl_notification_wait - notification wait entry
  1010. * @list: list head for global list
  1011. * @fn: function called with the notification
  1012. * @cmd: command ID
  1013. *
  1014. * This structure is not used directly, to wait for a
  1015. * notification declare it on the stack, and call
  1016. * iwlagn_init_notification_wait() with appropriate
  1017. * parameters. Then do whatever will cause the ucode
  1018. * to notify the driver, and to wait for that then
  1019. * call iwlagn_wait_notification().
  1020. *
  1021. * Each notification is one-shot. If at some point we
  1022. * need to support multi-shot notifications (which
  1023. * can't be allocated on the stack) we need to modify
  1024. * the code for them.
  1025. */
  1026. struct iwl_notification_wait {
  1027. struct list_head list;
  1028. void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt);
  1029. u8 cmd;
  1030. bool triggered;
  1031. };
  1032. enum iwl_rxon_context_id {
  1033. IWL_RXON_CTX_BSS,
  1034. IWL_RXON_CTX_PAN,
  1035. NUM_IWL_RXON_CTX
  1036. };
  1037. struct iwl_rxon_context {
  1038. struct ieee80211_vif *vif;
  1039. const u8 *ac_to_fifo;
  1040. const u8 *ac_to_queue;
  1041. u8 mcast_queue;
  1042. /*
  1043. * We could use the vif to indicate active, but we
  1044. * also need it to be active during disabling when
  1045. * we already removed the vif for type setting.
  1046. */
  1047. bool always_active, is_active;
  1048. bool ht_need_multiple_chains;
  1049. enum iwl_rxon_context_id ctxid;
  1050. u32 interface_modes, exclusive_interface_modes;
  1051. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  1052. /*
  1053. * We declare this const so it can only be
  1054. * changed via explicit cast within the
  1055. * routines that actually update the physical
  1056. * hardware.
  1057. */
  1058. const struct iwl_rxon_cmd active;
  1059. struct iwl_rxon_cmd staging;
  1060. struct iwl_rxon_time_cmd timing;
  1061. struct iwl_qos_info qos_data;
  1062. u8 bcast_sta_id, ap_sta_id;
  1063. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  1064. u8 qos_cmd;
  1065. u8 wep_key_cmd;
  1066. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  1067. u8 key_mapping_keys;
  1068. __le32 station_flags;
  1069. struct {
  1070. bool non_gf_sta_present;
  1071. u8 protection;
  1072. bool enabled, is_40mhz;
  1073. u8 extension_chan_offset;
  1074. } ht;
  1075. };
  1076. struct iwl_priv {
  1077. /* ieee device used by generic ieee processing code */
  1078. struct ieee80211_hw *hw;
  1079. struct ieee80211_channel *ieee_channels;
  1080. struct ieee80211_rate *ieee_rates;
  1081. struct iwl_cfg *cfg;
  1082. /* temporary frame storage list */
  1083. struct list_head free_frames;
  1084. int frames_count;
  1085. enum ieee80211_band band;
  1086. int alloc_rxb_page;
  1087. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  1088. struct iwl_rx_mem_buffer *rxb);
  1089. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  1090. /* spectrum measurement report caching */
  1091. struct iwl_spectrum_notification measure_report;
  1092. u8 measurement_status;
  1093. /* ucode beacon time */
  1094. u32 ucode_beacon_time;
  1095. int missed_beacon_threshold;
  1096. /* track IBSS manager (last beacon) status */
  1097. u32 ibss_manager;
  1098. /* storing the jiffies when the plcp error rate is received */
  1099. unsigned long plcp_jiffies;
  1100. /* force reset */
  1101. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  1102. /* we allocate array of iwl_channel_info for NIC's valid channels.
  1103. * Access via channel # using indirect index array */
  1104. struct iwl_channel_info *channel_info; /* channel info array */
  1105. u8 channel_count; /* # of channels */
  1106. /* thermal calibration */
  1107. s32 temperature; /* degrees Kelvin */
  1108. s32 last_temperature;
  1109. /* init calibration results */
  1110. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  1111. /* Scan related variables */
  1112. unsigned long scan_start;
  1113. unsigned long scan_start_tsf;
  1114. void *scan_cmd;
  1115. enum ieee80211_band scan_band;
  1116. struct cfg80211_scan_request *scan_request;
  1117. struct ieee80211_vif *scan_vif;
  1118. bool is_internal_short_scan;
  1119. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  1120. u8 mgmt_tx_ant;
  1121. /* spinlock */
  1122. spinlock_t lock; /* protect general shared data */
  1123. spinlock_t hcmd_lock; /* protect hcmd */
  1124. spinlock_t reg_lock; /* protect hw register access */
  1125. struct mutex mutex;
  1126. struct mutex sync_cmd_mutex; /* enable serialization of sync commands */
  1127. /* basic pci-network driver stuff */
  1128. struct pci_dev *pci_dev;
  1129. /* pci hardware address support */
  1130. void __iomem *hw_base;
  1131. u32 hw_rev;
  1132. u32 hw_wa_rev;
  1133. u8 rev_id;
  1134. /* microcode/device supports multiple contexts */
  1135. u8 valid_contexts;
  1136. /* command queue number */
  1137. u8 cmd_queue;
  1138. /* max number of station keys */
  1139. u8 sta_key_max_num;
  1140. /* EEPROM MAC addresses */
  1141. struct mac_address addresses[2];
  1142. /* uCode images, save to reload in case of failure */
  1143. int fw_index; /* firmware we're trying to load */
  1144. u32 ucode_ver; /* version of ucode, copy of
  1145. iwl_ucode.ver */
  1146. struct fw_desc ucode_code; /* runtime inst */
  1147. struct fw_desc ucode_data; /* runtime data original */
  1148. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  1149. struct fw_desc ucode_init; /* initialization inst */
  1150. struct fw_desc ucode_init_data; /* initialization data */
  1151. struct fw_desc ucode_boot; /* bootstrap inst */
  1152. enum ucode_type ucode_type;
  1153. u8 ucode_write_complete; /* the image write is complete */
  1154. char firmware_name[25];
  1155. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  1156. struct iwl_switch_rxon switch_rxon;
  1157. /* 1st responses from initialize and runtime uCode images.
  1158. * _agn's initialize alive response contains some calibration data. */
  1159. struct iwl_init_alive_resp card_alive_init;
  1160. struct iwl_alive_resp card_alive;
  1161. u16 active_rate;
  1162. u8 start_calib;
  1163. struct iwl_sensitivity_data sensitivity_data;
  1164. struct iwl_chain_noise_data chain_noise_data;
  1165. bool enhance_sensitivity_table;
  1166. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  1167. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  1168. struct iwl_ht_config current_ht_config;
  1169. /* Rate scaling data */
  1170. u8 retry_rate;
  1171. wait_queue_head_t wait_command_queue;
  1172. int activity_timer_active;
  1173. /* Rx and Tx DMA processing queues */
  1174. struct iwl_rx_queue rxq;
  1175. struct iwl_tx_queue *txq;
  1176. unsigned long txq_ctx_active_msk;
  1177. struct iwl_dma_ptr kw; /* keep warm address */
  1178. struct iwl_dma_ptr scd_bc_tbls;
  1179. u32 scd_base_addr; /* scheduler sram base address */
  1180. unsigned long status;
  1181. /* counts mgmt, ctl, and data packets */
  1182. struct traffic_stats tx_stats;
  1183. struct traffic_stats rx_stats;
  1184. /* counts interrupts */
  1185. struct isr_statistics isr_stats;
  1186. struct iwl_power_mgr power_data;
  1187. struct iwl_tt_mgmt thermal_throttle;
  1188. /* context information */
  1189. u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
  1190. /* station table variables */
  1191. /* Note: if lock and sta_lock are needed, lock must be acquired first */
  1192. spinlock_t sta_lock;
  1193. int num_stations;
  1194. struct iwl_station_entry stations[IWL_STATION_COUNT];
  1195. unsigned long ucode_key_table;
  1196. /* queue refcounts */
  1197. #define IWL_MAX_HW_QUEUES 32
  1198. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  1199. /* for each AC */
  1200. atomic_t queue_stop_count[4];
  1201. /* Indication if ieee80211_ops->open has been called */
  1202. u8 is_open;
  1203. u8 mac80211_registered;
  1204. /* eeprom -- this is in the card's little endian byte order */
  1205. u8 *eeprom;
  1206. int nvm_device_type;
  1207. struct iwl_eeprom_calib_info *calib_info;
  1208. enum nl80211_iftype iw_mode;
  1209. /* Last Rx'd beacon timestamp */
  1210. u64 timestamp;
  1211. union {
  1212. #if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
  1213. struct {
  1214. void *shared_virt;
  1215. dma_addr_t shared_phys;
  1216. struct delayed_work thermal_periodic;
  1217. struct delayed_work rfkill_poll;
  1218. struct iwl3945_notif_statistics statistics;
  1219. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1220. struct iwl3945_notif_statistics accum_statistics;
  1221. struct iwl3945_notif_statistics delta_statistics;
  1222. struct iwl3945_notif_statistics max_delta;
  1223. #endif
  1224. u32 sta_supp_rates;
  1225. int last_rx_rssi; /* From Rx packet statistics */
  1226. /* Rx'd packet timing information */
  1227. u32 last_beacon_time;
  1228. u64 last_tsf;
  1229. /*
  1230. * each calibration channel group in the
  1231. * EEPROM has a derived clip setting for
  1232. * each rate.
  1233. */
  1234. const struct iwl3945_clip_group clip_groups[5];
  1235. } _3945;
  1236. #endif
  1237. #if defined(CONFIG_IWLAGN) || defined(CONFIG_IWLAGN_MODULE)
  1238. struct {
  1239. /* INT ICT Table */
  1240. __le32 *ict_tbl;
  1241. void *ict_tbl_vir;
  1242. dma_addr_t ict_tbl_dma;
  1243. dma_addr_t aligned_ict_tbl_dma;
  1244. int ict_index;
  1245. u32 inta;
  1246. bool use_ict;
  1247. /*
  1248. * reporting the number of tids has AGG on. 0 means
  1249. * no AGGREGATION
  1250. */
  1251. u8 agg_tids_count;
  1252. struct iwl_rx_phy_res last_phy_res;
  1253. bool last_phy_res_valid;
  1254. struct completion firmware_loading_complete;
  1255. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1256. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1257. /*
  1258. * chain noise reset and gain commands are the
  1259. * two extra calibration commands follows the standard
  1260. * phy calibration commands
  1261. */
  1262. u8 phy_calib_chain_noise_reset_cmd;
  1263. u8 phy_calib_chain_noise_gain_cmd;
  1264. struct iwl_notif_statistics statistics;
  1265. struct iwl_bt_notif_statistics statistics_bt;
  1266. /* counts reply_tx error */
  1267. struct reply_tx_error_statistics reply_tx_stats;
  1268. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  1269. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1270. struct iwl_notif_statistics accum_statistics;
  1271. struct iwl_notif_statistics delta_statistics;
  1272. struct iwl_notif_statistics max_delta;
  1273. struct iwl_bt_notif_statistics accum_statistics_bt;
  1274. struct iwl_bt_notif_statistics delta_statistics_bt;
  1275. struct iwl_bt_notif_statistics max_delta_bt;
  1276. #endif
  1277. /* notification wait support */
  1278. struct list_head notif_waits;
  1279. spinlock_t notif_wait_lock;
  1280. wait_queue_head_t notif_waitq;
  1281. /* remain-on-channel offload support */
  1282. struct ieee80211_channel *hw_roc_channel;
  1283. struct delayed_work hw_roc_work;
  1284. enum nl80211_channel_type hw_roc_chantype;
  1285. int hw_roc_duration;
  1286. } _agn;
  1287. #endif
  1288. };
  1289. /* bt coex */
  1290. u8 bt_enable_flag;
  1291. u8 bt_status;
  1292. u8 bt_traffic_load, last_bt_traffic_load;
  1293. bool bt_ch_announce;
  1294. bool bt_full_concurrent;
  1295. bool bt_ant_couple_ok;
  1296. __le32 kill_ack_mask;
  1297. __le32 kill_cts_mask;
  1298. __le16 bt_valid;
  1299. u16 bt_on_thresh;
  1300. u16 bt_duration;
  1301. u16 dynamic_frag_thresh;
  1302. u8 bt_ci_compliance;
  1303. struct work_struct bt_traffic_change_work;
  1304. struct iwl_hw_params hw_params;
  1305. u32 inta_mask;
  1306. struct workqueue_struct *workqueue;
  1307. struct work_struct restart;
  1308. struct work_struct scan_completed;
  1309. struct work_struct rx_replenish;
  1310. struct work_struct abort_scan;
  1311. struct work_struct beacon_update;
  1312. struct iwl_rxon_context *beacon_ctx;
  1313. struct sk_buff *beacon_skb;
  1314. struct work_struct tt_work;
  1315. struct work_struct ct_enter;
  1316. struct work_struct ct_exit;
  1317. struct work_struct start_internal_scan;
  1318. struct work_struct tx_flush;
  1319. struct work_struct bt_full_concurrency;
  1320. struct work_struct bt_runtime_config;
  1321. struct tasklet_struct irq_tasklet;
  1322. struct delayed_work init_alive_start;
  1323. struct delayed_work alive_start;
  1324. struct delayed_work scan_check;
  1325. /* TX Power */
  1326. s8 tx_power_user_lmt;
  1327. s8 tx_power_device_lmt;
  1328. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  1329. s8 tx_power_next;
  1330. #ifdef CONFIG_IWLWIFI_DEBUG
  1331. /* debugging info */
  1332. u32 debug_level; /* per device debugging will override global
  1333. iwl_debug_level if set */
  1334. #endif /* CONFIG_IWLWIFI_DEBUG */
  1335. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1336. /* debugfs */
  1337. u16 tx_traffic_idx;
  1338. u16 rx_traffic_idx;
  1339. u8 *tx_traffic;
  1340. u8 *rx_traffic;
  1341. struct dentry *debugfs_dir;
  1342. u32 dbgfs_sram_offset, dbgfs_sram_len;
  1343. bool disable_ht40;
  1344. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  1345. struct work_struct txpower_work;
  1346. u32 disable_sens_cal;
  1347. u32 disable_chain_noise_cal;
  1348. u32 disable_tx_power_cal;
  1349. struct work_struct run_time_calib_work;
  1350. struct timer_list statistics_periodic;
  1351. struct timer_list ucode_trace;
  1352. struct timer_list watchdog;
  1353. bool hw_ready;
  1354. struct iwl_event_log event_log;
  1355. struct led_classdev led;
  1356. unsigned long blink_on, blink_off;
  1357. bool led_registered;
  1358. }; /*iwl_priv */
  1359. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1360. {
  1361. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1362. }
  1363. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1364. {
  1365. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1366. }
  1367. #ifdef CONFIG_IWLWIFI_DEBUG
  1368. /*
  1369. * iwl_get_debug_level: Return active debug level for device
  1370. *
  1371. * Using sysfs it is possible to set per device debug level. This debug
  1372. * level will be used if set, otherwise the global debug level which can be
  1373. * set via module parameter is used.
  1374. */
  1375. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1376. {
  1377. if (priv->debug_level)
  1378. return priv->debug_level;
  1379. else
  1380. return iwl_debug_level;
  1381. }
  1382. #else
  1383. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1384. {
  1385. return iwl_debug_level;
  1386. }
  1387. #endif
  1388. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  1389. int txq_id, int idx)
  1390. {
  1391. if (priv->txq[txq_id].txb[idx].skb)
  1392. return (struct ieee80211_hdr *)priv->txq[txq_id].
  1393. txb[idx].skb->data;
  1394. return NULL;
  1395. }
  1396. static inline struct iwl_rxon_context *
  1397. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  1398. {
  1399. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1400. return vif_priv->ctx;
  1401. }
  1402. #define for_each_context(priv, ctx) \
  1403. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  1404. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  1405. if (priv->valid_contexts & BIT(ctx->ctxid))
  1406. static inline int iwl_is_associated(struct iwl_priv *priv,
  1407. enum iwl_rxon_context_id ctxid)
  1408. {
  1409. return (priv->contexts[ctxid].active.filter_flags &
  1410. RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1411. }
  1412. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  1413. {
  1414. return iwl_is_associated(priv, IWL_RXON_CTX_BSS);
  1415. }
  1416. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  1417. {
  1418. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1419. }
  1420. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  1421. {
  1422. if (ch_info == NULL)
  1423. return 0;
  1424. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  1425. }
  1426. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  1427. {
  1428. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  1429. }
  1430. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  1431. {
  1432. return ch_info->band == IEEE80211_BAND_5GHZ;
  1433. }
  1434. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  1435. {
  1436. return ch_info->band == IEEE80211_BAND_2GHZ;
  1437. }
  1438. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  1439. {
  1440. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  1441. }
  1442. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  1443. {
  1444. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  1445. }
  1446. static inline void __iwl_free_pages(struct iwl_priv *priv, struct page *page)
  1447. {
  1448. __free_pages(page, priv->hw_params.rx_page_order);
  1449. priv->alloc_rxb_page--;
  1450. }
  1451. static inline void iwl_free_pages(struct iwl_priv *priv, unsigned long page)
  1452. {
  1453. free_pages(page, priv->hw_params.rx_page_order);
  1454. priv->alloc_rxb_page--;
  1455. }
  1456. #endif /* __iwl_dev_h__ */