iwl-dev.h 39 KB

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