iwl-dev.h 37 KB

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