iwl-dev.h 42 KB

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