iwl-dev.h 42 KB

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