iwl-dev.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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. * James P. Ketrenos <ipw2100-admin@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 <net/ieee80211_radiotap.h>
  36. #define DRV_NAME "iwlagn"
  37. #include "iwl-rfkill.h"
  38. #include "iwl-eeprom.h"
  39. #include "iwl-4965-hw.h"
  40. #include "iwl-csr.h"
  41. #include "iwl-prph.h"
  42. #include "iwl-debug.h"
  43. #include "iwl-led.h"
  44. #include "iwl-power.h"
  45. #include "iwl-agn-rs.h"
  46. /* configuration for the iwl4965 */
  47. extern struct iwl_cfg iwl4965_agn_cfg;
  48. extern struct iwl_cfg iwl5300_agn_cfg;
  49. extern struct iwl_cfg iwl5100_agn_cfg;
  50. extern struct iwl_cfg iwl5350_agn_cfg;
  51. extern struct iwl_cfg iwl5100_bg_cfg;
  52. extern struct iwl_cfg iwl5100_abg_cfg;
  53. /* CT-KILL constants */
  54. #define CT_KILL_THRESHOLD 110 /* in Celsius */
  55. /* Default noise level to report when noise measurement is not available.
  56. * This may be because we're:
  57. * 1) Not associated (4965, no beacon statistics being sent to driver)
  58. * 2) Scanning (noise measurement does not apply to associated channel)
  59. * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
  60. * Use default noise value of -127 ... this is below the range of measurable
  61. * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
  62. * Also, -127 works better than 0 when averaging frames with/without
  63. * noise info (e.g. averaging might be done in app); measured dBm values are
  64. * always negative ... using a negative value as the default keeps all
  65. * averages within an s8's (used in some apps) range of negative values. */
  66. #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
  67. /*
  68. * RTS threshold here is total size [2347] minus 4 FCS bytes
  69. * Per spec:
  70. * a value of 0 means RTS on all data/management packets
  71. * a value > max MSDU size means no RTS
  72. * else RTS for data/management frames where MPDU is larger
  73. * than RTS value.
  74. */
  75. #define DEFAULT_RTS_THRESHOLD 2347U
  76. #define MIN_RTS_THRESHOLD 0U
  77. #define MAX_RTS_THRESHOLD 2347U
  78. #define MAX_MSDU_SIZE 2304U
  79. #define MAX_MPDU_SIZE 2346U
  80. #define DEFAULT_BEACON_INTERVAL 100U
  81. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  82. #define DEFAULT_LONG_RETRY_LIMIT 4U
  83. struct iwl_rx_mem_buffer {
  84. dma_addr_t dma_addr;
  85. struct sk_buff *skb;
  86. struct list_head list;
  87. };
  88. /*
  89. * Generic queue structure
  90. *
  91. * Contains common data for Rx and Tx queues
  92. */
  93. struct iwl_queue {
  94. int n_bd; /* number of BDs in this queue */
  95. int write_ptr; /* 1-st empty entry (index) host_w*/
  96. int read_ptr; /* last used entry (index) host_r*/
  97. dma_addr_t dma_addr; /* physical addr for BD's */
  98. int n_window; /* safe queue window */
  99. u32 id;
  100. int low_mark; /* low watermark, resume queue if free
  101. * space more than this */
  102. int high_mark; /* high watermark, stop queue if free
  103. * space less than this */
  104. } __attribute__ ((packed));
  105. #define MAX_NUM_OF_TBS (20)
  106. /* One for each TFD */
  107. struct iwl_tx_info {
  108. struct sk_buff *skb[MAX_NUM_OF_TBS];
  109. };
  110. /**
  111. * struct iwl_tx_queue - Tx Queue for DMA
  112. * @q: generic Rx/Tx queue descriptor
  113. * @bd: base of circular buffer of TFDs
  114. * @cmd: array of command/Tx buffers
  115. * @dma_addr_cmd: physical address of cmd/tx buffer array
  116. * @txb: array of per-TFD driver data
  117. * @need_update: indicates need to update read/write index
  118. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  119. *
  120. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  121. * descriptors) and required locking structures.
  122. */
  123. struct iwl_tx_queue {
  124. struct iwl_queue q;
  125. struct iwl_tfd_frame *bd;
  126. struct iwl_cmd *cmd[TFD_TX_CMD_SLOTS];
  127. struct iwl_tx_info *txb;
  128. int need_update;
  129. int sched_retry;
  130. int active;
  131. };
  132. #define IWL_NUM_SCAN_RATES (2)
  133. struct iwl4965_channel_tgd_info {
  134. u8 type;
  135. s8 max_power;
  136. };
  137. struct iwl4965_channel_tgh_info {
  138. s64 last_radar_time;
  139. };
  140. /*
  141. * One for each channel, holds all channel setup data
  142. * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
  143. * with one another!
  144. */
  145. struct iwl_channel_info {
  146. struct iwl4965_channel_tgd_info tgd;
  147. struct iwl4965_channel_tgh_info tgh;
  148. struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
  149. struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for
  150. * FAT channel */
  151. u8 channel; /* channel number */
  152. u8 flags; /* flags copied from EEPROM */
  153. s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  154. s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
  155. s8 min_power; /* always 0 */
  156. s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
  157. u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
  158. u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
  159. enum ieee80211_band band;
  160. /* FAT channel info */
  161. s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
  162. s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */
  163. s8 fat_min_power; /* always 0 */
  164. s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */
  165. u8 fat_flags; /* flags copied from EEPROM */
  166. u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */
  167. };
  168. struct iwl4965_clip_group {
  169. /* maximum power level to prevent clipping for each rate, derived by
  170. * us from this band's saturation power in EEPROM */
  171. const s8 clip_powers[IWL_MAX_RATES];
  172. };
  173. #define IWL_TX_FIFO_AC0 0
  174. #define IWL_TX_FIFO_AC1 1
  175. #define IWL_TX_FIFO_AC2 2
  176. #define IWL_TX_FIFO_AC3 3
  177. #define IWL_TX_FIFO_HCCA_1 5
  178. #define IWL_TX_FIFO_HCCA_2 6
  179. #define IWL_TX_FIFO_NONE 7
  180. /* Minimum number of queues. MAX_NUM is defined in hw specific files */
  181. #define IWL_MIN_NUM_QUEUES 4
  182. /* Power management (not Tx power) structures */
  183. enum iwl_pwr_src {
  184. IWL_PWR_SRC_VMAIN,
  185. IWL_PWR_SRC_VAUX,
  186. };
  187. #define IEEE80211_DATA_LEN 2304
  188. #define IEEE80211_4ADDR_LEN 30
  189. #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
  190. #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
  191. struct iwl_frame {
  192. union {
  193. struct ieee80211_hdr frame;
  194. struct iwl_tx_beacon_cmd beacon;
  195. u8 raw[IEEE80211_FRAME_LEN];
  196. u8 cmd[360];
  197. } u;
  198. struct list_head list;
  199. };
  200. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  201. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  202. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  203. enum {
  204. /* CMD_SIZE_NORMAL = 0, */
  205. CMD_SIZE_HUGE = (1 << 0),
  206. /* CMD_SYNC = 0, */
  207. CMD_ASYNC = (1 << 1),
  208. /* CMD_NO_SKB = 0, */
  209. CMD_WANT_SKB = (1 << 2),
  210. };
  211. struct iwl_cmd;
  212. struct iwl_priv;
  213. struct iwl_cmd_meta {
  214. struct iwl_cmd_meta *source;
  215. union {
  216. struct sk_buff *skb;
  217. int (*callback)(struct iwl_priv *priv,
  218. struct iwl_cmd *cmd, struct sk_buff *skb);
  219. } __attribute__ ((packed)) u;
  220. /* The CMD_SIZE_HUGE flag bit indicates that the command
  221. * structure is stored at the end of the shared queue memory. */
  222. u32 flags;
  223. } __attribute__ ((packed));
  224. #define IWL_CMD_MAX_PAYLOAD 320
  225. /**
  226. * struct iwl_cmd
  227. *
  228. * For allocation of the command and tx queues, this establishes the overall
  229. * size of the largest command we send to uCode, except for a scan command
  230. * (which is relatively huge; space is allocated separately).
  231. */
  232. struct iwl_cmd {
  233. struct iwl_cmd_meta meta; /* driver data */
  234. struct iwl_cmd_header hdr; /* uCode API */
  235. union {
  236. struct iwl_addsta_cmd addsta;
  237. struct iwl_led_cmd led;
  238. u32 flags;
  239. u8 val8;
  240. u16 val16;
  241. u32 val32;
  242. struct iwl4965_bt_cmd bt;
  243. struct iwl4965_rxon_time_cmd rxon_time;
  244. struct iwl_powertable_cmd powertable;
  245. struct iwl_qosparam_cmd qosparam;
  246. struct iwl_tx_cmd tx;
  247. struct iwl4965_rxon_assoc_cmd rxon_assoc;
  248. struct iwl_rem_sta_cmd rm_sta;
  249. u8 *indirect;
  250. u8 payload[IWL_CMD_MAX_PAYLOAD];
  251. } __attribute__ ((packed)) cmd;
  252. } __attribute__ ((packed));
  253. struct iwl_host_cmd {
  254. u8 id;
  255. u16 len;
  256. struct iwl_cmd_meta meta;
  257. const void *data;
  258. };
  259. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
  260. sizeof(struct iwl_cmd_meta))
  261. /*
  262. * RX related structures and functions
  263. */
  264. #define RX_FREE_BUFFERS 64
  265. #define RX_LOW_WATERMARK 8
  266. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  267. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  268. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  269. /**
  270. * struct iwl_rx_queue - Rx queue
  271. * @processed: Internal index to last handled Rx packet
  272. * @read: Shared index to newest available Rx buffer
  273. * @write: Shared index to oldest written Rx packet
  274. * @free_count: Number of pre-allocated buffers in rx_free
  275. * @rx_free: list of free SKBs for use
  276. * @rx_used: List of Rx buffers with no SKB
  277. * @need_update: flag to indicate we need to update read/write index
  278. *
  279. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  280. */
  281. struct iwl_rx_queue {
  282. __le32 *bd;
  283. dma_addr_t dma_addr;
  284. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  285. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  286. u32 processed;
  287. u32 read;
  288. u32 write;
  289. u32 free_count;
  290. struct list_head rx_free;
  291. struct list_head rx_used;
  292. int need_update;
  293. spinlock_t lock;
  294. };
  295. #define IWL_SUPPORTED_RATES_IE_LEN 8
  296. #define SCAN_INTERVAL 100
  297. #define MAX_A_CHANNELS 252
  298. #define MIN_A_CHANNELS 7
  299. #define MAX_B_CHANNELS 14
  300. #define MIN_B_CHANNELS 1
  301. #define MAX_TID_COUNT 9
  302. #define IWL_INVALID_RATE 0xFF
  303. #define IWL_INVALID_VALUE -1
  304. /**
  305. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  306. * @txq_id: Tx queue used for Tx attempt
  307. * @frame_count: # frames attempted by Tx command
  308. * @wait_for_ba: Expect block-ack before next Tx reply
  309. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  310. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  311. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  312. * @rate_n_flags: Rate at which Tx was attempted
  313. *
  314. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  315. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  316. * until block ack arrives.
  317. */
  318. struct iwl_ht_agg {
  319. u16 txq_id;
  320. u16 frame_count;
  321. u16 wait_for_ba;
  322. u16 start_idx;
  323. u64 bitmap;
  324. u32 rate_n_flags;
  325. #define IWL_AGG_OFF 0
  326. #define IWL_AGG_ON 1
  327. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  328. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  329. u8 state;
  330. };
  331. struct iwl_tid_data {
  332. u16 seq_number;
  333. u16 tfds_in_queue;
  334. struct iwl_ht_agg agg;
  335. };
  336. struct iwl_hw_key {
  337. enum ieee80211_key_alg alg;
  338. int keylen;
  339. u8 keyidx;
  340. u8 key[32];
  341. };
  342. union iwl4965_ht_rate_supp {
  343. u16 rates;
  344. struct {
  345. u8 siso_rate;
  346. u8 mimo_rate;
  347. };
  348. };
  349. #define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
  350. #define CFG_HT_MPDU_DENSITY_2USEC (0x5)
  351. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
  352. struct iwl_ht_info {
  353. /* self configuration data */
  354. u8 is_ht;
  355. u8 supported_chan_width;
  356. u8 sm_ps;
  357. u8 is_green_field;
  358. u8 sgf; /* HT_SHORT_GI_* short guard interval */
  359. u8 max_amsdu_size;
  360. u8 ampdu_factor;
  361. u8 mpdu_density;
  362. u8 supp_mcs_set[16];
  363. /* BSS related data */
  364. u8 control_channel;
  365. u8 extension_chan_offset;
  366. u8 tx_chan_width;
  367. u8 ht_protection;
  368. u8 non_GF_STA_present;
  369. };
  370. union iwl_qos_capabity {
  371. struct {
  372. u8 edca_count:4; /* bit 0-3 */
  373. u8 q_ack:1; /* bit 4 */
  374. u8 queue_request:1; /* bit 5 */
  375. u8 txop_request:1; /* bit 6 */
  376. u8 reserved:1; /* bit 7 */
  377. } q_AP;
  378. struct {
  379. u8 acvo_APSD:1; /* bit 0 */
  380. u8 acvi_APSD:1; /* bit 1 */
  381. u8 ac_bk_APSD:1; /* bit 2 */
  382. u8 ac_be_APSD:1; /* bit 3 */
  383. u8 q_ack:1; /* bit 4 */
  384. u8 max_len:2; /* bit 5-6 */
  385. u8 more_data_ack:1; /* bit 7 */
  386. } q_STA;
  387. u8 val;
  388. };
  389. /* QoS structures */
  390. struct iwl_qos_info {
  391. int qos_enable;
  392. int qos_active;
  393. union iwl_qos_capabity qos_cap;
  394. struct iwl_qosparam_cmd def_qos_parm;
  395. };
  396. #define STA_PS_STATUS_WAKE 0
  397. #define STA_PS_STATUS_SLEEP 1
  398. struct iwl_station_entry {
  399. struct iwl_addsta_cmd sta;
  400. struct iwl_tid_data tid[MAX_TID_COUNT];
  401. u8 used;
  402. u8 ps_status;
  403. struct iwl_hw_key keyinfo;
  404. };
  405. /* one for each uCode image (inst/data, boot/init/runtime) */
  406. struct fw_desc {
  407. void *v_addr; /* access by driver */
  408. dma_addr_t p_addr; /* access by card's busmaster DMA */
  409. u32 len; /* bytes */
  410. };
  411. /* uCode file layout */
  412. struct iwl_ucode {
  413. __le32 ver; /* major/minor/subminor */
  414. __le32 inst_size; /* bytes of runtime instructions */
  415. __le32 data_size; /* bytes of runtime data */
  416. __le32 init_size; /* bytes of initialization instructions */
  417. __le32 init_data_size; /* bytes of initialization data */
  418. __le32 boot_size; /* bytes of bootstrap instructions */
  419. u8 data[0]; /* data in same order as "size" elements */
  420. };
  421. struct iwl4965_ibss_seq {
  422. u8 mac[ETH_ALEN];
  423. u16 seq_num;
  424. u16 frag_num;
  425. unsigned long packet_time;
  426. struct list_head list;
  427. };
  428. struct iwl_sensitivity_ranges {
  429. u16 min_nrg_cck;
  430. u16 max_nrg_cck;
  431. u16 nrg_th_cck;
  432. u16 nrg_th_ofdm;
  433. u16 auto_corr_min_ofdm;
  434. u16 auto_corr_min_ofdm_mrc;
  435. u16 auto_corr_min_ofdm_x1;
  436. u16 auto_corr_min_ofdm_mrc_x1;
  437. u16 auto_corr_max_ofdm;
  438. u16 auto_corr_max_ofdm_mrc;
  439. u16 auto_corr_max_ofdm_x1;
  440. u16 auto_corr_max_ofdm_mrc_x1;
  441. u16 auto_corr_max_cck;
  442. u16 auto_corr_max_cck_mrc;
  443. u16 auto_corr_min_cck;
  444. u16 auto_corr_min_cck_mrc;
  445. };
  446. #define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
  447. /**
  448. * struct iwl_hw_params
  449. * @max_txq_num: Max # Tx queues supported
  450. * @tx/rx_chains_num: Number of TX/RX chains
  451. * @valid_tx/rx_ant: usable antennas
  452. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  453. * @max_rxq_log: Log-base-2 of max_rxq_size
  454. * @rx_buf_size: Rx buffer size
  455. * @max_stations:
  456. * @bcast_sta_id:
  457. * @fat_channel: is 40MHz width possible in band 2.4
  458. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  459. * @sw_crypto: 0 for hw, 1 for sw
  460. * @max_xxx_size: for ucode uses
  461. * @ct_kill_threshold: temperature threshold
  462. * @struct iwl_sensitivity_ranges: range of sensitivity values
  463. * @first_ampdu_q: first HW queue available for ampdu
  464. */
  465. struct iwl_hw_params {
  466. u16 max_txq_num;
  467. u8 tx_chains_num;
  468. u8 rx_chains_num;
  469. u8 valid_tx_ant;
  470. u8 valid_rx_ant;
  471. u16 max_rxq_size;
  472. u16 max_rxq_log;
  473. u32 rx_buf_size;
  474. u32 max_pkt_size;
  475. u8 max_stations;
  476. u8 bcast_sta_id;
  477. u8 fat_channel;
  478. u8 sw_crypto;
  479. u32 max_inst_size;
  480. u32 max_data_size;
  481. u32 max_bsm_size;
  482. u32 ct_kill_threshold; /* value in hw-dependent units */
  483. const struct iwl_sensitivity_ranges *sens;
  484. u8 first_ampdu_q;
  485. };
  486. #define HT_SHORT_GI_20MHZ (1 << 0)
  487. #define HT_SHORT_GI_40MHZ (1 << 1)
  488. #define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
  489. x->u.rx_frame.stats.payload + \
  490. x->u.rx_frame.stats.phy_count))
  491. #define IWL_RX_END(x) ((struct iwl4965_rx_frame_end *)(\
  492. IWL_RX_HDR(x)->payload + \
  493. le16_to_cpu(IWL_RX_HDR(x)->len)))
  494. #define IWL_RX_STATS(x) (&x->u.rx_frame.stats)
  495. #define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload)
  496. /******************************************************************************
  497. *
  498. * Functions implemented in core module which are forward declared here
  499. * for use by iwl-[4-5].c
  500. *
  501. * NOTE: The implementation of these functions are not hardware specific
  502. * which is why they are in the core module files.
  503. *
  504. * Naming convention --
  505. * iwl_ <-- Is part of iwlwifi
  506. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  507. * iwl4965_bg_ <-- Called from work queue context
  508. * iwl4965_mac_ <-- mac80211 callback
  509. *
  510. ****************************************************************************/
  511. struct iwl_addsta_cmd;
  512. extern int iwl_send_add_sta(struct iwl_priv *priv,
  513. struct iwl_addsta_cmd *sta, u8 flags);
  514. extern u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr,
  515. int is_ap, u8 flags, struct ieee80211_ht_info *ht_info);
  516. extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
  517. extern int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
  518. extern const u8 iwl_bcast_addr[ETH_ALEN];
  519. extern int iwl_rxq_stop(struct iwl_priv *priv);
  520. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  521. extern int iwl_queue_space(const struct iwl_queue *q);
  522. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  523. {
  524. return q->write_ptr > q->read_ptr ?
  525. (i >= q->read_ptr && i < q->write_ptr) :
  526. !(i < q->read_ptr && i >= q->write_ptr);
  527. }
  528. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
  529. {
  530. /* This is for scan command, the big buffer at end of command array */
  531. if (is_huge)
  532. return q->n_window; /* must be power of 2 */
  533. /* Otherwise, use normal size buffers */
  534. return index & (q->n_window - 1);
  535. }
  536. struct iwl_priv;
  537. /* Structures, enum, and defines specific to the 4965 */
  538. #define IWL_KW_SIZE 0x1000 /*4k */
  539. struct iwl_kw {
  540. dma_addr_t dma_addr;
  541. void *v_addr;
  542. size_t size;
  543. };
  544. #define IWL_CHANNEL_WIDTH_20MHZ 0
  545. #define IWL_CHANNEL_WIDTH_40MHZ 1
  546. #define IWL_OPERATION_MODE_AUTO 0
  547. #define IWL_OPERATION_MODE_HT_ONLY 1
  548. #define IWL_OPERATION_MODE_MIXED 2
  549. #define IWL_OPERATION_MODE_20MHZ 3
  550. #define IWL_TX_CRC_SIZE 4
  551. #define IWL_TX_DELIMITER_SIZE 4
  552. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  553. /* Sensitivity and chain noise calibration */
  554. #define INTERFERENCE_DATA_AVAILABLE __constant_cpu_to_le32(1)
  555. #define INITIALIZATION_VALUE 0xFFFF
  556. #define CAL_NUM_OF_BEACONS 20
  557. #define MAXIMUM_ALLOWED_PATHLOSS 15
  558. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  559. #define MAX_FA_OFDM 50
  560. #define MIN_FA_OFDM 5
  561. #define MAX_FA_CCK 50
  562. #define MIN_FA_CCK 5
  563. #define AUTO_CORR_STEP_OFDM 1
  564. #define AUTO_CORR_STEP_CCK 3
  565. #define AUTO_CORR_MAX_TH_CCK 160
  566. #define NRG_DIFF 2
  567. #define NRG_STEP_CCK 2
  568. #define NRG_MARGIN 8
  569. #define MAX_NUMBER_CCK_NO_FA 100
  570. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  571. #define CHAIN_A 0
  572. #define CHAIN_B 1
  573. #define CHAIN_C 2
  574. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  575. #define ALL_BAND_FILTER 0xFF00
  576. #define IN_BAND_FILTER 0xFF
  577. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  578. #define NRG_NUM_PREV_STAT_L 20
  579. #define NUM_RX_CHAINS 3
  580. enum iwl4965_false_alarm_state {
  581. IWL_FA_TOO_MANY = 0,
  582. IWL_FA_TOO_FEW = 1,
  583. IWL_FA_GOOD_RANGE = 2,
  584. };
  585. enum iwl4965_chain_noise_state {
  586. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  587. IWL_CHAIN_NOISE_ACCUMULATE,
  588. IWL_CHAIN_NOISE_CALIBRATED,
  589. IWL_CHAIN_NOISE_DONE,
  590. };
  591. enum iwl4965_calib_enabled_state {
  592. IWL_CALIB_DISABLED = 0, /* must be 0 */
  593. IWL_CALIB_ENABLED = 1,
  594. };
  595. struct statistics_general_data {
  596. u32 beacon_silence_rssi_a;
  597. u32 beacon_silence_rssi_b;
  598. u32 beacon_silence_rssi_c;
  599. u32 beacon_energy_a;
  600. u32 beacon_energy_b;
  601. u32 beacon_energy_c;
  602. };
  603. /* Opaque calibration results */
  604. struct iwl_calib_result {
  605. void *buf;
  606. size_t buf_len;
  607. };
  608. enum ucode_type {
  609. UCODE_NONE = 0,
  610. UCODE_INIT,
  611. UCODE_RT
  612. };
  613. /* Sensitivity calib data */
  614. struct iwl_sensitivity_data {
  615. u32 auto_corr_ofdm;
  616. u32 auto_corr_ofdm_mrc;
  617. u32 auto_corr_ofdm_x1;
  618. u32 auto_corr_ofdm_mrc_x1;
  619. u32 auto_corr_cck;
  620. u32 auto_corr_cck_mrc;
  621. u32 last_bad_plcp_cnt_ofdm;
  622. u32 last_fa_cnt_ofdm;
  623. u32 last_bad_plcp_cnt_cck;
  624. u32 last_fa_cnt_cck;
  625. u32 nrg_curr_state;
  626. u32 nrg_prev_state;
  627. u32 nrg_value[10];
  628. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  629. u32 nrg_silence_ref;
  630. u32 nrg_energy_idx;
  631. u32 nrg_silence_idx;
  632. u32 nrg_th_cck;
  633. s32 nrg_auto_corr_silence_diff;
  634. u32 num_in_cck_no_fa;
  635. u32 nrg_th_ofdm;
  636. };
  637. /* Chain noise (differential Rx gain) calib data */
  638. struct iwl_chain_noise_data {
  639. u32 active_chains;
  640. u32 chain_noise_a;
  641. u32 chain_noise_b;
  642. u32 chain_noise_c;
  643. u32 chain_signal_a;
  644. u32 chain_signal_b;
  645. u32 chain_signal_c;
  646. u16 beacon_count;
  647. u8 disconn_array[NUM_RX_CHAINS];
  648. u8 delta_gain_code[NUM_RX_CHAINS];
  649. u8 radio_write;
  650. u8 state;
  651. };
  652. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  653. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  654. enum {
  655. MEASUREMENT_READY = (1 << 0),
  656. MEASUREMENT_ACTIVE = (1 << 1),
  657. };
  658. #define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
  659. #define IWL_CALIB_MAX 3
  660. struct iwl_priv {
  661. /* ieee device used by generic ieee processing code */
  662. struct ieee80211_hw *hw;
  663. struct ieee80211_channel *ieee_channels;
  664. struct ieee80211_rate *ieee_rates;
  665. struct iwl_cfg *cfg;
  666. /* temporary frame storage list */
  667. struct list_head free_frames;
  668. int frames_count;
  669. enum ieee80211_band band;
  670. int alloc_rxb_skb;
  671. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  672. struct iwl_rx_mem_buffer *rxb);
  673. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  674. #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
  675. /* spectrum measurement report caching */
  676. struct iwl4965_spectrum_notification measure_report;
  677. u8 measurement_status;
  678. #endif
  679. /* ucode beacon time */
  680. u32 ucode_beacon_time;
  681. /* we allocate array of iwl4965_channel_info for NIC's valid channels.
  682. * Access via channel # using indirect index array */
  683. struct iwl_channel_info *channel_info; /* channel info array */
  684. u8 channel_count; /* # of channels */
  685. /* each calibration channel group in the EEPROM has a derived
  686. * clip setting for each rate. */
  687. const struct iwl4965_clip_group clip_groups[5];
  688. /* thermal calibration */
  689. s32 temperature; /* degrees Kelvin */
  690. s32 last_temperature;
  691. /* init calibration results */
  692. struct iwl_calib_result calib_results[IWL_CALIB_MAX];
  693. /* Scan related variables */
  694. unsigned long last_scan_jiffies;
  695. unsigned long next_scan_jiffies;
  696. unsigned long scan_start;
  697. unsigned long scan_pass_start;
  698. unsigned long scan_start_tsf;
  699. int scan_bands;
  700. int one_direct_scan;
  701. u8 direct_ssid_len;
  702. u8 direct_ssid[IW_ESSID_MAX_SIZE];
  703. struct iwl_scan_cmd *scan;
  704. u32 scan_tx_ant[IEEE80211_NUM_BANDS];
  705. /* spinlock */
  706. spinlock_t lock; /* protect general shared data */
  707. spinlock_t hcmd_lock; /* protect hcmd */
  708. struct mutex mutex;
  709. /* basic pci-network driver stuff */
  710. struct pci_dev *pci_dev;
  711. /* pci hardware address support */
  712. void __iomem *hw_base;
  713. u32 hw_rev;
  714. u32 hw_wa_rev;
  715. u8 rev_id;
  716. /* uCode images, save to reload in case of failure */
  717. struct fw_desc ucode_code; /* runtime inst */
  718. struct fw_desc ucode_data; /* runtime data original */
  719. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  720. struct fw_desc ucode_init; /* initialization inst */
  721. struct fw_desc ucode_init_data; /* initialization data */
  722. struct fw_desc ucode_boot; /* bootstrap inst */
  723. enum ucode_type ucode_type;
  724. u8 ucode_write_complete; /* the image write is complete */
  725. struct iwl4965_rxon_time_cmd rxon_timing;
  726. /* We declare this const so it can only be
  727. * changed via explicit cast within the
  728. * routines that actually update the physical
  729. * hardware */
  730. const struct iwl_rxon_cmd active_rxon;
  731. struct iwl_rxon_cmd staging_rxon;
  732. int error_recovering;
  733. struct iwl_rxon_cmd recovery_rxon;
  734. /* 1st responses from initialize and runtime uCode images.
  735. * 4965's initialize alive response contains some calibration data. */
  736. struct iwl_init_alive_resp card_alive_init;
  737. struct iwl_alive_resp card_alive;
  738. #ifdef CONFIG_IWLWIFI_RFKILL
  739. struct rfkill *rfkill;
  740. #endif
  741. #ifdef CONFIG_IWLWIFI_LEDS
  742. struct iwl_led led[IWL_LED_TRG_MAX];
  743. unsigned long last_blink_time;
  744. u8 last_blink_rate;
  745. u8 allow_blinking;
  746. u64 led_tpt;
  747. #endif
  748. u16 active_rate;
  749. u16 active_rate_basic;
  750. u8 assoc_station_added;
  751. u8 use_ant_b_for_management_frame; /* Tx antenna selection */
  752. u8 start_calib;
  753. struct iwl_sensitivity_data sensitivity_data;
  754. struct iwl_chain_noise_data chain_noise_data;
  755. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  756. struct iwl_ht_info current_ht_config;
  757. u8 last_phy_res[100];
  758. /* Rate scaling data */
  759. s8 data_retry_limit;
  760. u8 retry_rate;
  761. wait_queue_head_t wait_command_queue;
  762. int activity_timer_active;
  763. /* Rx and Tx DMA processing queues */
  764. struct iwl_rx_queue rxq;
  765. struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
  766. unsigned long txq_ctx_active_msk;
  767. struct iwl_kw kw; /* keep warm address */
  768. u32 scd_base_addr; /* scheduler sram base address */
  769. unsigned long status;
  770. int last_rx_rssi; /* From Rx packet statisitics */
  771. int last_rx_noise; /* From beacon statistics */
  772. /* counts mgmt, ctl, and data packets */
  773. struct traffic_stats {
  774. u32 cnt;
  775. u64 bytes;
  776. } tx_stats[3], rx_stats[3];
  777. struct iwl_power_mgr power_data;
  778. struct iwl_notif_statistics statistics;
  779. unsigned long last_statistics_time;
  780. /* context information */
  781. u8 essid[IW_ESSID_MAX_SIZE];
  782. u8 essid_len;
  783. u16 rates_mask;
  784. u32 power_mode;
  785. u32 antenna;
  786. u8 bssid[ETH_ALEN];
  787. u16 rts_threshold;
  788. u8 mac_addr[ETH_ALEN];
  789. /*station table variables */
  790. spinlock_t sta_lock;
  791. int num_stations;
  792. struct iwl_station_entry stations[IWL_STATION_COUNT];
  793. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  794. u8 default_wep_key;
  795. u8 key_mapping_key;
  796. unsigned long ucode_key_table;
  797. /* Indication if ieee80211_ops->open has been called */
  798. u8 is_open;
  799. u8 mac80211_registered;
  800. /* Rx'd packet timing information */
  801. u32 last_beacon_time;
  802. u64 last_tsf;
  803. /* eeprom */
  804. u8 *eeprom;
  805. struct iwl_eeprom_calib_info *calib_info;
  806. enum nl80211_iftype iw_mode;
  807. struct sk_buff *ibss_beacon;
  808. /* Last Rx'd beacon timestamp */
  809. u64 timestamp;
  810. u16 beacon_int;
  811. struct ieee80211_vif *vif;
  812. struct iwl_hw_params hw_params;
  813. /* driver/uCode shared Tx Byte Counts and Rx status */
  814. void *shared_virt;
  815. int rb_closed_offset;
  816. /* Physical Pointer to Tx Byte Counts and Rx status */
  817. dma_addr_t shared_phys;
  818. /* Current association information needed to configure the
  819. * hardware */
  820. u16 assoc_id;
  821. u16 assoc_capability;
  822. struct iwl_qos_info qos_data;
  823. struct workqueue_struct *workqueue;
  824. struct work_struct up;
  825. struct work_struct restart;
  826. struct work_struct calibrated_work;
  827. struct work_struct scan_completed;
  828. struct work_struct rx_replenish;
  829. struct work_struct rf_kill;
  830. struct work_struct abort_scan;
  831. struct work_struct update_link_led;
  832. struct work_struct auth_work;
  833. struct work_struct report_work;
  834. struct work_struct request_scan;
  835. struct work_struct beacon_update;
  836. struct work_struct set_monitor;
  837. struct tasklet_struct irq_tasklet;
  838. struct delayed_work set_power_save;
  839. struct delayed_work init_alive_start;
  840. struct delayed_work alive_start;
  841. struct delayed_work scan_check;
  842. /* TX Power */
  843. s8 tx_power_user_lmt;
  844. s8 tx_power_channel_lmt;
  845. #ifdef CONFIG_PM
  846. u32 pm_state[16];
  847. #endif
  848. #ifdef CONFIG_IWLWIFI_DEBUG
  849. /* debugging info */
  850. u32 debug_level;
  851. u32 framecnt_to_us;
  852. atomic_t restrict_refcnt;
  853. #ifdef CONFIG_IWLWIFI_DEBUGFS
  854. /* debugfs */
  855. struct iwl_debugfs *dbgfs;
  856. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  857. #endif /* CONFIG_IWLWIFI_DEBUG */
  858. struct work_struct txpower_work;
  859. u32 disable_sens_cal;
  860. u32 disable_chain_noise_cal;
  861. u32 disable_tx_power_cal;
  862. struct work_struct run_time_calib_work;
  863. struct timer_list statistics_periodic;
  864. }; /*iwl_priv */
  865. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  866. {
  867. set_bit(txq_id, &priv->txq_ctx_active_msk);
  868. }
  869. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  870. {
  871. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  872. }
  873. #ifdef CONFIG_IWLWIFI_DEBUG
  874. const char *iwl_get_tx_fail_reason(u32 status);
  875. #else
  876. static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
  877. #endif
  878. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  879. int txq_id, int idx)
  880. {
  881. if (priv->txq[txq_id].txb[idx].skb[0])
  882. return (struct ieee80211_hdr *)priv->txq[txq_id].
  883. txb[idx].skb[0]->data;
  884. return NULL;
  885. }
  886. static inline int iwl_is_associated(struct iwl_priv *priv)
  887. {
  888. return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  889. }
  890. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  891. {
  892. if (ch_info == NULL)
  893. return 0;
  894. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  895. }
  896. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  897. {
  898. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  899. }
  900. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  901. {
  902. return ch_info->band == IEEE80211_BAND_5GHZ;
  903. }
  904. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  905. {
  906. return ch_info->band == IEEE80211_BAND_2GHZ;
  907. }
  908. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  909. {
  910. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  911. }
  912. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  913. {
  914. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  915. }
  916. #ifdef CONFIG_IWLWIFI_DEBUG
  917. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  918. void *p, u32 len)
  919. {
  920. if (!(priv->debug_level & level))
  921. return;
  922. print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
  923. p, len, 1);
  924. }
  925. #else
  926. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  927. void *p, u32 len)
  928. {
  929. }
  930. #endif
  931. extern const struct iwl_channel_info *iwl_get_channel_info(
  932. const struct iwl_priv *priv, enum ieee80211_band band, u16 channel);
  933. /* Requires full declaration of iwl_priv before including */
  934. #endif /* __iwl_dev_h__ */