iwl-dev.h 39 KB

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