iwl-dev.h 45 KB

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