iwl-dev.h 44 KB

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