iwl-dev.h 45 KB

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