iwl-dev.h 45 KB

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