iwl-dev.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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. };
  236. #define DEF_CMD_PAYLOAD_SIZE 320
  237. /**
  238. * struct iwl_device_cmd
  239. *
  240. * For allocation of the command and tx queues, this establishes the overall
  241. * size of the largest command we send to uCode, except for commands that
  242. * aren't fully copied and use other TFD space.
  243. */
  244. struct iwl_device_cmd {
  245. struct iwl_cmd_header hdr; /* uCode API */
  246. union {
  247. u32 flags;
  248. u8 val8;
  249. u16 val16;
  250. u32 val32;
  251. struct iwl_tx_cmd tx;
  252. struct iwl6000_channel_switch_cmd chswitch;
  253. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  254. } __packed cmd;
  255. } __packed;
  256. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  257. #define IWL_MAX_CMD_TFDS 2
  258. enum iwl_hcmd_dataflag {
  259. IWL_HCMD_DFL_NOCOPY = BIT(0),
  260. };
  261. struct iwl_host_cmd {
  262. const void *data[IWL_MAX_CMD_TFDS];
  263. unsigned long reply_page;
  264. void (*callback)(struct iwl_priv *priv,
  265. struct iwl_device_cmd *cmd,
  266. struct iwl_rx_packet *pkt);
  267. u32 flags;
  268. u16 len[IWL_MAX_CMD_TFDS];
  269. u8 dataflags[IWL_MAX_CMD_TFDS];
  270. u8 id;
  271. };
  272. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  273. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  274. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  275. /**
  276. * struct iwl_rx_queue - Rx queue
  277. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  278. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  279. * @read: Shared index to newest available Rx buffer
  280. * @write: Shared index to oldest written Rx packet
  281. * @free_count: Number of pre-allocated buffers in rx_free
  282. * @rx_free: list of free SKBs for use
  283. * @rx_used: List of Rx buffers with no SKB
  284. * @need_update: flag to indicate we need to update read/write index
  285. * @rb_stts: driver's pointer to receive buffer status
  286. * @rb_stts_dma: bus address of receive buffer status
  287. *
  288. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  289. */
  290. struct iwl_rx_queue {
  291. __le32 *bd;
  292. dma_addr_t bd_dma;
  293. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  294. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  295. u32 read;
  296. u32 write;
  297. u32 free_count;
  298. u32 write_actual;
  299. struct list_head rx_free;
  300. struct list_head rx_used;
  301. int need_update;
  302. struct iwl_rb_status *rb_stts;
  303. dma_addr_t rb_stts_dma;
  304. spinlock_t lock;
  305. };
  306. #define IWL_SUPPORTED_RATES_IE_LEN 8
  307. #define MAX_TID_COUNT 9
  308. #define IWL_INVALID_RATE 0xFF
  309. #define IWL_INVALID_VALUE -1
  310. /**
  311. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  312. * @txq_id: Tx queue used for Tx attempt
  313. * @frame_count: # frames attempted by Tx command
  314. * @wait_for_ba: Expect block-ack before next Tx reply
  315. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  316. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  317. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  318. * @rate_n_flags: Rate at which Tx was attempted
  319. *
  320. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  321. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  322. * until block ack arrives.
  323. */
  324. struct iwl_ht_agg {
  325. u16 txq_id;
  326. u16 frame_count;
  327. u16 wait_for_ba;
  328. u16 start_idx;
  329. u64 bitmap;
  330. u32 rate_n_flags;
  331. #define IWL_AGG_OFF 0
  332. #define IWL_AGG_ON 1
  333. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  334. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  335. u8 state;
  336. u8 tx_fifo;
  337. };
  338. struct iwl_tid_data {
  339. u16 seq_number; /* agn only */
  340. u16 tfds_in_queue;
  341. struct iwl_ht_agg agg;
  342. };
  343. struct iwl_hw_key {
  344. u32 cipher;
  345. int keylen;
  346. u8 keyidx;
  347. u8 key[32];
  348. };
  349. union iwl_ht_rate_supp {
  350. u16 rates;
  351. struct {
  352. u8 siso_rate;
  353. u8 mimo_rate;
  354. };
  355. };
  356. #define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
  357. #define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
  358. #define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
  359. #define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
  360. #define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
  361. #define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
  362. #define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
  363. /*
  364. * Maximal MPDU density for TX aggregation
  365. * 4 - 2us density
  366. * 5 - 4us density
  367. * 6 - 8us density
  368. * 7 - 16us density
  369. */
  370. #define CFG_HT_MPDU_DENSITY_2USEC (0x4)
  371. #define CFG_HT_MPDU_DENSITY_4USEC (0x5)
  372. #define CFG_HT_MPDU_DENSITY_8USEC (0x6)
  373. #define CFG_HT_MPDU_DENSITY_16USEC (0x7)
  374. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
  375. #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
  376. #define CFG_HT_MPDU_DENSITY_MIN (0x1)
  377. struct iwl_ht_config {
  378. bool single_chain_sufficient;
  379. enum ieee80211_smps_mode smps; /* current smps mode */
  380. };
  381. /* QoS structures */
  382. struct iwl_qos_info {
  383. int qos_active;
  384. struct iwl_qosparam_cmd def_qos_parm;
  385. };
  386. /*
  387. * Structure should be accessed with sta_lock held. When station addition
  388. * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
  389. * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
  390. * held.
  391. */
  392. struct iwl_station_entry {
  393. struct iwl_addsta_cmd sta;
  394. struct iwl_tid_data tid[MAX_TID_COUNT];
  395. u8 used, ctxid;
  396. struct iwl_hw_key keyinfo;
  397. struct iwl_link_quality_cmd *lq;
  398. };
  399. struct iwl_station_priv_common {
  400. struct iwl_rxon_context *ctx;
  401. u8 sta_id;
  402. };
  403. /*
  404. * iwl_station_priv: Driver's private station information
  405. *
  406. * When mac80211 creates a station it reserves some space (hw->sta_data_size)
  407. * in the structure for use by driver. This structure is places in that
  408. * space.
  409. */
  410. struct iwl_station_priv {
  411. struct iwl_station_priv_common common;
  412. struct iwl_lq_sta lq_sta;
  413. atomic_t pending_frames;
  414. bool client;
  415. bool asleep;
  416. u8 max_agg_bufsize;
  417. };
  418. /**
  419. * struct iwl_vif_priv - driver's private per-interface information
  420. *
  421. * When mac80211 allocates a virtual interface, it can allocate
  422. * space for us to put data into.
  423. */
  424. struct iwl_vif_priv {
  425. struct iwl_rxon_context *ctx;
  426. u8 ibss_bssid_sta_id;
  427. };
  428. /* one for each uCode image (inst/data, boot/init/runtime) */
  429. struct fw_desc {
  430. void *v_addr; /* access by driver */
  431. dma_addr_t p_addr; /* access by card's busmaster DMA */
  432. u32 len; /* bytes */
  433. };
  434. struct fw_img {
  435. struct fw_desc code, data;
  436. };
  437. /* v1/v2 uCode file layout */
  438. struct iwl_ucode_header {
  439. __le32 ver; /* major/minor/API/serial */
  440. union {
  441. struct {
  442. __le32 inst_size; /* bytes of runtime code */
  443. __le32 data_size; /* bytes of runtime data */
  444. __le32 init_size; /* bytes of init code */
  445. __le32 init_data_size; /* bytes of init data */
  446. __le32 boot_size; /* bytes of bootstrap code */
  447. u8 data[0]; /* in same order as sizes */
  448. } v1;
  449. struct {
  450. __le32 build; /* build number */
  451. __le32 inst_size; /* bytes of runtime code */
  452. __le32 data_size; /* bytes of runtime data */
  453. __le32 init_size; /* bytes of init code */
  454. __le32 init_data_size; /* bytes of init data */
  455. __le32 boot_size; /* bytes of bootstrap code */
  456. u8 data[0]; /* in same order as sizes */
  457. } v2;
  458. } u;
  459. };
  460. /*
  461. * new TLV uCode file layout
  462. *
  463. * The new TLV file format contains TLVs, that each specify
  464. * some piece of data. To facilitate "groups", for example
  465. * different instruction image with different capabilities,
  466. * bundled with the same init image, an alternative mechanism
  467. * is provided:
  468. * When the alternative field is 0, that means that the item
  469. * is always valid. When it is non-zero, then it is only
  470. * valid in conjunction with items of the same alternative,
  471. * in which case the driver (user) selects one alternative
  472. * to use.
  473. */
  474. enum iwl_ucode_tlv_type {
  475. IWL_UCODE_TLV_INVALID = 0, /* unused */
  476. IWL_UCODE_TLV_INST = 1,
  477. IWL_UCODE_TLV_DATA = 2,
  478. IWL_UCODE_TLV_INIT = 3,
  479. IWL_UCODE_TLV_INIT_DATA = 4,
  480. IWL_UCODE_TLV_BOOT = 5,
  481. IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
  482. IWL_UCODE_TLV_PAN = 7,
  483. IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
  484. IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
  485. IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
  486. IWL_UCODE_TLV_INIT_EVTLOG_PTR = 11,
  487. IWL_UCODE_TLV_INIT_EVTLOG_SIZE = 12,
  488. IWL_UCODE_TLV_INIT_ERRLOG_PTR = 13,
  489. IWL_UCODE_TLV_ENHANCE_SENS_TBL = 14,
  490. IWL_UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
  491. /* 16 and 17 reserved for future use */
  492. IWL_UCODE_TLV_FLAGS = 18,
  493. };
  494. /**
  495. * enum iwl_ucode_tlv_flag - ucode API flags
  496. * @IWL_UCODE_TLV_FLAGS_PAN: This is PAN capable microcode; this previously
  497. * was a separate TLV but moved here to save space.
  498. * @IWL_UCODE_TLV_FLAGS_NEWSCAN: new uCode scan behaviour on hidden SSID,
  499. * treats good CRC threshold as a boolean
  500. * @IWL_UCODE_TLV_FLAGS_MFP: This uCode image supports MFP (802.11w).
  501. */
  502. enum iwl_ucode_tlv_flag {
  503. IWL_UCODE_TLV_FLAGS_PAN = BIT(0),
  504. IWL_UCODE_TLV_FLAGS_NEWSCAN = BIT(1),
  505. IWL_UCODE_TLV_FLAGS_MFP = BIT(2),
  506. };
  507. struct iwl_ucode_tlv {
  508. __le16 type; /* see above */
  509. __le16 alternative; /* see comment */
  510. __le32 length; /* not including type/length fields */
  511. u8 data[0];
  512. } __packed;
  513. #define IWL_TLV_UCODE_MAGIC 0x0a4c5749
  514. struct iwl_tlv_ucode_header {
  515. /*
  516. * The TLV style ucode header is distinguished from
  517. * the v1/v2 style header by first four bytes being
  518. * zero, as such is an invalid combination of
  519. * major/minor/API/serial versions.
  520. */
  521. __le32 zero;
  522. __le32 magic;
  523. u8 human_readable[64];
  524. __le32 ver; /* major/minor/API/serial */
  525. __le32 build;
  526. __le64 alternatives; /* bitmask of valid alternatives */
  527. /*
  528. * The data contained herein has a TLV layout,
  529. * see above for the TLV header and types.
  530. * Note that each TLV is padded to a length
  531. * that is a multiple of 4 for alignment.
  532. */
  533. u8 data[0];
  534. };
  535. struct iwl_sensitivity_ranges {
  536. u16 min_nrg_cck;
  537. u16 max_nrg_cck;
  538. u16 nrg_th_cck;
  539. u16 nrg_th_ofdm;
  540. u16 auto_corr_min_ofdm;
  541. u16 auto_corr_min_ofdm_mrc;
  542. u16 auto_corr_min_ofdm_x1;
  543. u16 auto_corr_min_ofdm_mrc_x1;
  544. u16 auto_corr_max_ofdm;
  545. u16 auto_corr_max_ofdm_mrc;
  546. u16 auto_corr_max_ofdm_x1;
  547. u16 auto_corr_max_ofdm_mrc_x1;
  548. u16 auto_corr_max_cck;
  549. u16 auto_corr_max_cck_mrc;
  550. u16 auto_corr_min_cck;
  551. u16 auto_corr_min_cck_mrc;
  552. u16 barker_corr_th_min;
  553. u16 barker_corr_th_min_mrc;
  554. u16 nrg_th_cca;
  555. };
  556. #define KELVIN_TO_CELSIUS(x) ((x)-273)
  557. #define CELSIUS_TO_KELVIN(x) ((x)+273)
  558. /**
  559. * struct iwl_hw_params
  560. * @max_txq_num: Max # Tx queues supported
  561. * @dma_chnl_num: Number of Tx DMA/FIFO channels
  562. * @scd_bc_tbls_size: size of scheduler byte count tables
  563. * @tfd_size: TFD size
  564. * @tx/rx_chains_num: Number of TX/RX chains
  565. * @valid_tx/rx_ant: usable antennas
  566. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  567. * @max_rxq_log: Log-base-2 of max_rxq_size
  568. * @rx_page_order: Rx buffer page order
  569. * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
  570. * @max_stations:
  571. * @ht40_channel: is 40MHz width possible in band 2.4
  572. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  573. * @sw_crypto: 0 for hw, 1 for sw
  574. * @max_xxx_size: for ucode uses
  575. * @ct_kill_threshold: temperature threshold
  576. * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
  577. * @calib_init_cfg: setup initial calibrations for the hw
  578. * @calib_rt_cfg: setup runtime calibrations for the hw
  579. * @struct iwl_sensitivity_ranges: range of sensitivity values
  580. */
  581. struct iwl_hw_params {
  582. u8 max_txq_num;
  583. u8 dma_chnl_num;
  584. u16 scd_bc_tbls_size;
  585. u32 tfd_size;
  586. u8 tx_chains_num;
  587. u8 rx_chains_num;
  588. u8 valid_tx_ant;
  589. u8 valid_rx_ant;
  590. u16 max_rxq_size;
  591. u16 max_rxq_log;
  592. u32 rx_page_order;
  593. u8 max_stations;
  594. u8 ht40_channel;
  595. u8 max_beacon_itrvl; /* in 1024 ms */
  596. u32 max_inst_size;
  597. u32 max_data_size;
  598. u32 ct_kill_threshold; /* value in hw-dependent units */
  599. u32 ct_kill_exit_threshold; /* value in hw-dependent units */
  600. /* for 1000, 6000 series and up */
  601. u16 beacon_time_tsf_bits;
  602. u32 calib_init_cfg;
  603. u32 calib_rt_cfg;
  604. const struct iwl_sensitivity_ranges *sens;
  605. };
  606. /******************************************************************************
  607. *
  608. * Functions implemented in core module which are forward declared here
  609. * for use by iwl-[4-5].c
  610. *
  611. * NOTE: The implementation of these functions are not hardware specific
  612. * which is why they are in the core module files.
  613. *
  614. * Naming convention --
  615. * iwl_ <-- Is part of iwlwifi
  616. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  617. *
  618. ****************************************************************************/
  619. extern void iwl_update_chain_flags(struct iwl_priv *priv);
  620. extern const u8 iwl_bcast_addr[ETH_ALEN];
  621. extern int iwl_rxq_stop(struct iwl_priv *priv);
  622. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  623. extern int iwl_queue_space(const struct iwl_queue *q);
  624. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  625. {
  626. return q->write_ptr >= q->read_ptr ?
  627. (i >= q->read_ptr && i < q->write_ptr) :
  628. !(i < q->read_ptr && i >= q->write_ptr);
  629. }
  630. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
  631. {
  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. * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
  872. * to perform continuous uCode event logging operation if enabled
  873. */
  874. #define UCODE_TRACE_PERIOD (100)
  875. /*
  876. * iwl_event_log: current uCode event log position
  877. *
  878. * @ucode_trace: enable/disable ucode continuous trace timer
  879. * @num_wraps: how many times the event buffer wraps
  880. * @next_entry: the entry just before the next one that uCode would fill
  881. * @non_wraps_count: counter for no wrap detected when dump ucode events
  882. * @wraps_once_count: counter for wrap once detected when dump ucode events
  883. * @wraps_more_count: counter for wrap more than once detected
  884. * when dump ucode events
  885. */
  886. struct iwl_event_log {
  887. bool ucode_trace;
  888. u32 num_wraps;
  889. u32 next_entry;
  890. int non_wraps_count;
  891. int wraps_once_count;
  892. int wraps_more_count;
  893. };
  894. /*
  895. * host interrupt timeout value
  896. * used with setting interrupt coalescing timer
  897. * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
  898. *
  899. * default interrupt coalescing timer is 64 x 32 = 2048 usecs
  900. * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
  901. */
  902. #define IWL_HOST_INT_TIMEOUT_MAX (0xFF)
  903. #define IWL_HOST_INT_TIMEOUT_DEF (0x40)
  904. #define IWL_HOST_INT_TIMEOUT_MIN (0x0)
  905. #define IWL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
  906. #define IWL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
  907. #define IWL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
  908. /*
  909. * This is the threshold value of plcp error rate per 100mSecs. It is
  910. * used to set and check for the validity of plcp_delta.
  911. */
  912. #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (1)
  913. #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50)
  914. #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100)
  915. #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200)
  916. #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255)
  917. #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE (0)
  918. #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
  919. #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
  920. /* TX queue watchdog timeouts in mSecs */
  921. #define IWL_DEF_WD_TIMEOUT (2000)
  922. #define IWL_LONG_WD_TIMEOUT (10000)
  923. #define IWL_MAX_WD_TIMEOUT (120000)
  924. /* BT Antenna Coupling Threshold (dB) */
  925. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  926. /* Firmware reload counter and Timestamp */
  927. #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */
  928. #define IWL_MAX_CONTINUE_RELOAD_CNT 4
  929. enum iwl_reset {
  930. IWL_RF_RESET = 0,
  931. IWL_FW_RESET,
  932. IWL_MAX_FORCE_RESET,
  933. };
  934. struct iwl_force_reset {
  935. int reset_request_count;
  936. int reset_success_count;
  937. int reset_reject_count;
  938. unsigned long reset_duration;
  939. unsigned long last_force_reset_jiffies;
  940. };
  941. /* extend beacon time format bit shifting */
  942. /*
  943. * for _agn devices
  944. * bits 31:22 - extended
  945. * bits 21:0 - interval
  946. */
  947. #define IWLAGN_EXT_BEACON_TIME_POS 22
  948. /**
  949. * struct iwl_notification_wait - notification wait entry
  950. * @list: list head for global list
  951. * @fn: function called with the notification
  952. * @cmd: command ID
  953. *
  954. * This structure is not used directly, to wait for a
  955. * notification declare it on the stack, and call
  956. * iwlagn_init_notification_wait() with appropriate
  957. * parameters. Then do whatever will cause the ucode
  958. * to notify the driver, and to wait for that then
  959. * call iwlagn_wait_notification().
  960. *
  961. * Each notification is one-shot. If at some point we
  962. * need to support multi-shot notifications (which
  963. * can't be allocated on the stack) we need to modify
  964. * the code for them.
  965. */
  966. struct iwl_notification_wait {
  967. struct list_head list;
  968. void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
  969. void *data);
  970. void *fn_data;
  971. u8 cmd;
  972. bool triggered, aborted;
  973. };
  974. enum iwl_rxon_context_id {
  975. IWL_RXON_CTX_BSS,
  976. IWL_RXON_CTX_PAN,
  977. NUM_IWL_RXON_CTX
  978. };
  979. struct iwl_rxon_context {
  980. struct ieee80211_vif *vif;
  981. const u8 *ac_to_fifo;
  982. const u8 *ac_to_queue;
  983. u8 mcast_queue;
  984. /*
  985. * We could use the vif to indicate active, but we
  986. * also need it to be active during disabling when
  987. * we already removed the vif for type setting.
  988. */
  989. bool always_active, is_active;
  990. bool ht_need_multiple_chains;
  991. enum iwl_rxon_context_id ctxid;
  992. u32 interface_modes, exclusive_interface_modes;
  993. u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
  994. /*
  995. * We declare this const so it can only be
  996. * changed via explicit cast within the
  997. * routines that actually update the physical
  998. * hardware.
  999. */
  1000. const struct iwl_rxon_cmd active;
  1001. struct iwl_rxon_cmd staging;
  1002. struct iwl_rxon_time_cmd timing;
  1003. struct iwl_qos_info qos_data;
  1004. u8 bcast_sta_id, ap_sta_id;
  1005. u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
  1006. u8 qos_cmd;
  1007. u8 wep_key_cmd;
  1008. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  1009. u8 key_mapping_keys;
  1010. __le32 station_flags;
  1011. struct {
  1012. bool non_gf_sta_present;
  1013. u8 protection;
  1014. bool enabled, is_40mhz;
  1015. u8 extension_chan_offset;
  1016. } ht;
  1017. bool last_tx_rejected;
  1018. };
  1019. enum iwl_scan_type {
  1020. IWL_SCAN_NORMAL,
  1021. IWL_SCAN_RADIO_RESET,
  1022. IWL_SCAN_OFFCH_TX,
  1023. };
  1024. enum iwlagn_ucode_type {
  1025. IWL_UCODE_NONE,
  1026. IWL_UCODE_REGULAR,
  1027. IWL_UCODE_INIT,
  1028. IWL_UCODE_WOWLAN,
  1029. };
  1030. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  1031. struct iwl_testmode_trace {
  1032. u32 buff_size;
  1033. u32 total_size;
  1034. u32 num_chunks;
  1035. u8 *cpu_addr;
  1036. u8 *trace_addr;
  1037. dma_addr_t dma_addr;
  1038. bool trace_enabled;
  1039. };
  1040. #endif
  1041. struct iwl_bus;
  1042. /**
  1043. * struct iwl_bus_ops - bus specific operations
  1044. * @get_pm_support: must returns true if the bus can go to sleep
  1045. * @apm_config: will be called during the config of the APM configuration
  1046. * @set_drv_data: set the priv pointer to the bus layer
  1047. * @get_dev: returns the device struct
  1048. * @get_irq: returns the irq number
  1049. * @get_hw_id: prints the hw_id in the provided buffer
  1050. * @write8: write a byte to register at offset ofs
  1051. * @write32: write a dword to register at offset ofs
  1052. * @wread32: read a dword at register at offset ofs
  1053. */
  1054. struct iwl_bus_ops {
  1055. bool (*get_pm_support)(struct iwl_bus *bus);
  1056. void (*apm_config)(struct iwl_bus *bus);
  1057. void (*set_drv_data)(struct iwl_bus *bus, void *priv);
  1058. struct device *(*get_dev)(const struct iwl_bus *bus);
  1059. unsigned int (*get_irq)(const struct iwl_bus *bus);
  1060. void (*get_hw_id)(struct iwl_bus *bus, char buf[], int buf_len);
  1061. void (*write8)(struct iwl_bus *bus, u32 ofs, u8 val);
  1062. void (*write32)(struct iwl_bus *bus, u32 ofs, u32 val);
  1063. u32 (*read32)(struct iwl_bus *bus, u32 ofs);
  1064. };
  1065. struct iwl_bus {
  1066. /* pointer to bus specific struct */
  1067. void *bus_specific;
  1068. /* Common data to all buses */
  1069. struct iwl_priv *priv; /* driver's context */
  1070. struct device *dev;
  1071. struct iwl_bus_ops *ops;
  1072. unsigned int irq;
  1073. };
  1074. struct iwl_trans;
  1075. /**
  1076. * struct iwl_trans_ops - transport specific operations
  1077. * @rx_init: inits the rx memory, allocate it if needed
  1078. * @rx_free: frees the rx memory
  1079. * @tx_init:inits the tx memory, allocate if needed
  1080. * @tx_free: frees the tx memory
  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. void (*tx_free)(struct iwl_priv *priv);
  1087. };
  1088. struct iwl_trans {
  1089. const struct iwl_trans_ops *ops;
  1090. };
  1091. struct iwl_priv {
  1092. /* ieee device used by generic ieee processing code */
  1093. struct ieee80211_hw *hw;
  1094. struct ieee80211_channel *ieee_channels;
  1095. struct ieee80211_rate *ieee_rates;
  1096. struct iwl_cfg *cfg;
  1097. enum ieee80211_band band;
  1098. void (*pre_rx_handler)(struct iwl_priv *priv,
  1099. struct iwl_rx_mem_buffer *rxb);
  1100. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  1101. struct iwl_rx_mem_buffer *rxb);
  1102. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  1103. /* spectrum measurement report caching */
  1104. struct iwl_spectrum_notification measure_report;
  1105. u8 measurement_status;
  1106. /* ucode beacon time */
  1107. u32 ucode_beacon_time;
  1108. int missed_beacon_threshold;
  1109. /* track IBSS manager (last beacon) status */
  1110. u32 ibss_manager;
  1111. /* jiffies when last recovery from statistics was performed */
  1112. unsigned long rx_statistics_jiffies;
  1113. /* force reset */
  1114. struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
  1115. /* firmware reload counter and timestamp */
  1116. unsigned long reload_jiffies;
  1117. int reload_count;
  1118. /* we allocate array of iwl_channel_info for NIC's valid channels.
  1119. * Access via channel # using indirect index array */
  1120. struct iwl_channel_info *channel_info; /* channel info array */
  1121. u8 channel_count; /* # of channels */
  1122. /* thermal calibration */
  1123. s32 temperature; /* degrees Kelvin */
  1124. s32 last_temperature;
  1125. /* init calibration results */
  1126. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  1127. /* Scan related variables */
  1128. unsigned long scan_start;
  1129. unsigned long scan_start_tsf;
  1130. void *scan_cmd;
  1131. enum ieee80211_band scan_band;
  1132. struct cfg80211_scan_request *scan_request;
  1133. struct ieee80211_vif *scan_vif;
  1134. enum iwl_scan_type scan_type;
  1135. u8 scan_tx_ant[IEEE80211_NUM_BANDS];
  1136. u8 mgmt_tx_ant;
  1137. /* spinlock */
  1138. spinlock_t lock; /* protect general shared data */
  1139. spinlock_t hcmd_lock; /* protect hcmd */
  1140. spinlock_t reg_lock; /* protect hw register access */
  1141. struct mutex mutex;
  1142. struct iwl_bus bus; /* bus specific data */
  1143. struct iwl_trans trans;
  1144. /* microcode/device supports multiple contexts */
  1145. u8 valid_contexts;
  1146. /* command queue number */
  1147. u8 cmd_queue;
  1148. /* max number of station keys */
  1149. u8 sta_key_max_num;
  1150. bool new_scan_threshold_behaviour;
  1151. /* EEPROM MAC addresses */
  1152. struct mac_address addresses[2];
  1153. /* uCode images, save to reload in case of failure */
  1154. int fw_index; /* firmware we're trying to load */
  1155. u32 ucode_ver; /* version of ucode, copy of
  1156. iwl_ucode.ver */
  1157. struct fw_img ucode_rt;
  1158. struct fw_img ucode_init;
  1159. enum iwlagn_ucode_type ucode_type;
  1160. u8 ucode_write_complete; /* the image write is complete */
  1161. char firmware_name[25];
  1162. struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
  1163. __le16 switch_channel;
  1164. struct {
  1165. u32 error_event_table;
  1166. u32 log_event_table;
  1167. } device_pointers;
  1168. u16 active_rate;
  1169. u8 start_calib;
  1170. struct iwl_sensitivity_data sensitivity_data;
  1171. struct iwl_chain_noise_data chain_noise_data;
  1172. bool enhance_sensitivity_table;
  1173. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  1174. __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
  1175. struct iwl_ht_config current_ht_config;
  1176. /* Rate scaling data */
  1177. u8 retry_rate;
  1178. wait_queue_head_t wait_command_queue;
  1179. int activity_timer_active;
  1180. /* Rx and Tx DMA processing queues */
  1181. struct iwl_rx_queue rxq;
  1182. struct iwl_tx_queue *txq;
  1183. unsigned long txq_ctx_active_msk;
  1184. struct iwl_dma_ptr kw; /* keep warm address */
  1185. struct iwl_dma_ptr scd_bc_tbls;
  1186. u32 scd_base_addr; /* scheduler sram base address */
  1187. unsigned long status;
  1188. /* counts mgmt, ctl, and data packets */
  1189. struct traffic_stats tx_stats;
  1190. struct traffic_stats rx_stats;
  1191. /* counts interrupts */
  1192. struct isr_statistics isr_stats;
  1193. struct iwl_power_mgr power_data;
  1194. struct iwl_tt_mgmt thermal_throttle;
  1195. /* station table variables */
  1196. /* Note: if lock and sta_lock are needed, lock must be acquired first */
  1197. spinlock_t sta_lock;
  1198. int num_stations;
  1199. struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
  1200. unsigned long ucode_key_table;
  1201. /* queue refcounts */
  1202. #define IWL_MAX_HW_QUEUES 32
  1203. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  1204. /* for each AC */
  1205. atomic_t queue_stop_count[4];
  1206. /* Indication if ieee80211_ops->open has been called */
  1207. u8 is_open;
  1208. u8 mac80211_registered;
  1209. /* eeprom -- this is in the card's little endian byte order */
  1210. u8 *eeprom;
  1211. int nvm_device_type;
  1212. struct iwl_eeprom_calib_info *calib_info;
  1213. enum nl80211_iftype iw_mode;
  1214. /* Last Rx'd beacon timestamp */
  1215. u64 timestamp;
  1216. struct {
  1217. __le32 flag;
  1218. struct statistics_general_common common;
  1219. struct statistics_rx_non_phy rx_non_phy;
  1220. struct statistics_rx_phy rx_ofdm;
  1221. struct statistics_rx_ht_phy rx_ofdm_ht;
  1222. struct statistics_rx_phy rx_cck;
  1223. struct statistics_tx tx;
  1224. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1225. struct statistics_bt_activity bt_activity;
  1226. __le32 num_bt_kills, accum_num_bt_kills;
  1227. #endif
  1228. } statistics;
  1229. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1230. struct {
  1231. struct statistics_general_common common;
  1232. struct statistics_rx_non_phy rx_non_phy;
  1233. struct statistics_rx_phy rx_ofdm;
  1234. struct statistics_rx_ht_phy rx_ofdm_ht;
  1235. struct statistics_rx_phy rx_cck;
  1236. struct statistics_tx tx;
  1237. struct statistics_bt_activity bt_activity;
  1238. } accum_stats, delta_stats, max_delta_stats;
  1239. #endif
  1240. struct {
  1241. /* INT ICT Table */
  1242. __le32 *ict_tbl;
  1243. void *ict_tbl_vir;
  1244. dma_addr_t ict_tbl_dma;
  1245. dma_addr_t aligned_ict_tbl_dma;
  1246. int ict_index;
  1247. u32 inta;
  1248. bool use_ict;
  1249. /*
  1250. * reporting the number of tids has AGG on. 0 means
  1251. * no AGGREGATION
  1252. */
  1253. u8 agg_tids_count;
  1254. struct iwl_rx_phy_res last_phy_res;
  1255. bool last_phy_res_valid;
  1256. struct completion firmware_loading_complete;
  1257. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1258. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1259. /*
  1260. * chain noise reset and gain commands are the
  1261. * two extra calibration commands follows the standard
  1262. * phy calibration commands
  1263. */
  1264. u8 phy_calib_chain_noise_reset_cmd;
  1265. u8 phy_calib_chain_noise_gain_cmd;
  1266. /* counts reply_tx error */
  1267. struct reply_tx_error_statistics reply_tx_stats;
  1268. struct reply_agg_tx_error_statistics reply_agg_tx_stats;
  1269. /* notification wait support */
  1270. struct list_head notif_waits;
  1271. spinlock_t notif_wait_lock;
  1272. wait_queue_head_t notif_waitq;
  1273. /* remain-on-channel offload support */
  1274. struct ieee80211_channel *hw_roc_channel;
  1275. struct delayed_work hw_roc_work;
  1276. enum nl80211_channel_type hw_roc_chantype;
  1277. int hw_roc_duration;
  1278. bool hw_roc_setup;
  1279. struct sk_buff *offchan_tx_skb;
  1280. int offchan_tx_timeout;
  1281. struct ieee80211_channel *offchan_tx_chan;
  1282. } _agn;
  1283. /* bt coex */
  1284. u8 bt_enable_flag;
  1285. u8 bt_status;
  1286. u8 bt_traffic_load, last_bt_traffic_load;
  1287. bool bt_ch_announce;
  1288. bool bt_full_concurrent;
  1289. bool bt_ant_couple_ok;
  1290. __le32 kill_ack_mask;
  1291. __le32 kill_cts_mask;
  1292. __le16 bt_valid;
  1293. u16 bt_on_thresh;
  1294. u16 bt_duration;
  1295. u16 dynamic_frag_thresh;
  1296. u8 bt_ci_compliance;
  1297. struct work_struct bt_traffic_change_work;
  1298. struct iwl_hw_params hw_params;
  1299. u32 inta_mask;
  1300. struct workqueue_struct *workqueue;
  1301. struct work_struct restart;
  1302. struct work_struct scan_completed;
  1303. struct work_struct rx_replenish;
  1304. struct work_struct abort_scan;
  1305. struct work_struct beacon_update;
  1306. struct iwl_rxon_context *beacon_ctx;
  1307. struct sk_buff *beacon_skb;
  1308. void *beacon_cmd;
  1309. struct work_struct tt_work;
  1310. struct work_struct ct_enter;
  1311. struct work_struct ct_exit;
  1312. struct work_struct start_internal_scan;
  1313. struct work_struct tx_flush;
  1314. struct work_struct bt_full_concurrency;
  1315. struct work_struct bt_runtime_config;
  1316. struct tasklet_struct irq_tasklet;
  1317. struct delayed_work scan_check;
  1318. /* TX Power */
  1319. s8 tx_power_user_lmt;
  1320. s8 tx_power_device_lmt;
  1321. s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
  1322. s8 tx_power_next;
  1323. #ifdef CONFIG_IWLWIFI_DEBUG
  1324. /* debugging info */
  1325. u32 debug_level; /* per device debugging will override global
  1326. iwl_debug_level if set */
  1327. #endif /* CONFIG_IWLWIFI_DEBUG */
  1328. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1329. /* debugfs */
  1330. u16 tx_traffic_idx;
  1331. u16 rx_traffic_idx;
  1332. u8 *tx_traffic;
  1333. u8 *rx_traffic;
  1334. struct dentry *debugfs_dir;
  1335. u32 dbgfs_sram_offset, dbgfs_sram_len;
  1336. bool disable_ht40;
  1337. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  1338. struct work_struct txpower_work;
  1339. u32 disable_sens_cal;
  1340. u32 disable_chain_noise_cal;
  1341. struct work_struct run_time_calib_work;
  1342. struct timer_list statistics_periodic;
  1343. struct timer_list ucode_trace;
  1344. struct timer_list watchdog;
  1345. struct iwl_event_log event_log;
  1346. struct led_classdev led;
  1347. unsigned long blink_on, blink_off;
  1348. bool led_registered;
  1349. #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
  1350. struct iwl_testmode_trace testmode_trace;
  1351. #endif
  1352. u32 dbg_fixed_rate;
  1353. }; /*iwl_priv */
  1354. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1355. {
  1356. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1357. }
  1358. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1359. {
  1360. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1361. }
  1362. #ifdef CONFIG_IWLWIFI_DEBUG
  1363. /*
  1364. * iwl_get_debug_level: Return active debug level for device
  1365. *
  1366. * Using sysfs it is possible to set per device debug level. This debug
  1367. * level will be used if set, otherwise the global debug level which can be
  1368. * set via module parameter is used.
  1369. */
  1370. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1371. {
  1372. if (priv->debug_level)
  1373. return priv->debug_level;
  1374. else
  1375. return iwl_debug_level;
  1376. }
  1377. #else
  1378. static inline u32 iwl_get_debug_level(struct iwl_priv *priv)
  1379. {
  1380. return iwl_debug_level;
  1381. }
  1382. #endif
  1383. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  1384. int txq_id, int idx)
  1385. {
  1386. if (priv->txq[txq_id].txb[idx].skb)
  1387. return (struct ieee80211_hdr *)priv->txq[txq_id].
  1388. txb[idx].skb->data;
  1389. return NULL;
  1390. }
  1391. static inline struct iwl_rxon_context *
  1392. iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
  1393. {
  1394. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1395. return vif_priv->ctx;
  1396. }
  1397. #define for_each_context(priv, ctx) \
  1398. for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
  1399. ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
  1400. if (priv->valid_contexts & BIT(ctx->ctxid))
  1401. static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
  1402. {
  1403. return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  1404. }
  1405. static inline int iwl_is_associated(struct iwl_priv *priv,
  1406. enum iwl_rxon_context_id ctxid)
  1407. {
  1408. return iwl_is_associated_ctx(&priv->contexts[ctxid]);
  1409. }
  1410. static inline int iwl_is_any_associated(struct iwl_priv *priv)
  1411. {
  1412. struct iwl_rxon_context *ctx;
  1413. for_each_context(priv, ctx)
  1414. if (iwl_is_associated_ctx(ctx))
  1415. return true;
  1416. return false;
  1417. }
  1418. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  1419. {
  1420. if (ch_info == NULL)
  1421. return 0;
  1422. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  1423. }
  1424. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  1425. {
  1426. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  1427. }
  1428. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  1429. {
  1430. return ch_info->band == IEEE80211_BAND_5GHZ;
  1431. }
  1432. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  1433. {
  1434. return ch_info->band == IEEE80211_BAND_2GHZ;
  1435. }
  1436. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  1437. {
  1438. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  1439. }
  1440. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  1441. {
  1442. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  1443. }
  1444. static inline void __iwl_free_pages(struct iwl_priv *priv, struct page *page)
  1445. {
  1446. __free_pages(page, priv->hw_params.rx_page_order);
  1447. }
  1448. static inline void iwl_free_pages(struct iwl_priv *priv, unsigned long page)
  1449. {
  1450. free_pages(page, priv->hw_params.rx_page_order);
  1451. }
  1452. #endif /* __iwl_dev_h__ */