iwl-dev.h 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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_QUEUE(x) ((x >> 8) & 0xbf)
  201. #define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8)
  202. #define SEQ_TO_INDEX(x) ((u8)(x & 0xff))
  203. #define INDEX_TO_SEQ(x) ((u8)(x & 0xff))
  204. #define SEQ_HUGE_FRAME (0x4000)
  205. #define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000)
  206. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  207. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  208. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  209. enum {
  210. /* CMD_SIZE_NORMAL = 0, */
  211. CMD_SIZE_HUGE = (1 << 0),
  212. /* CMD_SYNC = 0, */
  213. CMD_ASYNC = (1 << 1),
  214. /* CMD_NO_SKB = 0, */
  215. CMD_WANT_SKB = (1 << 2),
  216. };
  217. struct iwl_cmd;
  218. struct iwl_priv;
  219. struct iwl_cmd_meta {
  220. struct iwl_cmd_meta *source;
  221. union {
  222. struct sk_buff *skb;
  223. int (*callback)(struct iwl_priv *priv,
  224. struct iwl_cmd *cmd, struct sk_buff *skb);
  225. } __attribute__ ((packed)) u;
  226. /* The CMD_SIZE_HUGE flag bit indicates that the command
  227. * structure is stored at the end of the shared queue memory. */
  228. u32 flags;
  229. } __attribute__ ((packed));
  230. #define IWL_CMD_MAX_PAYLOAD 320
  231. /**
  232. * struct iwl_cmd
  233. *
  234. * For allocation of the command and tx queues, this establishes the overall
  235. * size of the largest command we send to uCode, except for a scan command
  236. * (which is relatively huge; space is allocated separately).
  237. */
  238. struct iwl_cmd {
  239. struct iwl_cmd_meta meta; /* driver data */
  240. struct iwl_cmd_header hdr; /* uCode API */
  241. union {
  242. struct iwl_addsta_cmd addsta;
  243. struct iwl_led_cmd led;
  244. u32 flags;
  245. u8 val8;
  246. u16 val16;
  247. u32 val32;
  248. struct iwl4965_bt_cmd bt;
  249. struct iwl4965_rxon_time_cmd rxon_time;
  250. struct iwl_powertable_cmd powertable;
  251. struct iwl_qosparam_cmd qosparam;
  252. struct iwl_tx_cmd tx;
  253. struct iwl4965_rxon_assoc_cmd rxon_assoc;
  254. struct iwl_rem_sta_cmd rm_sta;
  255. u8 *indirect;
  256. u8 payload[IWL_CMD_MAX_PAYLOAD];
  257. } __attribute__ ((packed)) cmd;
  258. } __attribute__ ((packed));
  259. struct iwl_host_cmd {
  260. u8 id;
  261. u16 len;
  262. struct iwl_cmd_meta meta;
  263. const void *data;
  264. };
  265. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
  266. sizeof(struct iwl_cmd_meta))
  267. /*
  268. * RX related structures and functions
  269. */
  270. #define RX_FREE_BUFFERS 64
  271. #define RX_LOW_WATERMARK 8
  272. #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
  273. #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
  274. #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
  275. /**
  276. * struct iwl_rx_queue - Rx queue
  277. * @processed: Internal index to last handled Rx packet
  278. * @read: Shared index to newest available Rx buffer
  279. * @write: Shared index to oldest written Rx packet
  280. * @free_count: Number of pre-allocated buffers in rx_free
  281. * @rx_free: list of free SKBs for use
  282. * @rx_used: List of Rx buffers with no SKB
  283. * @need_update: flag to indicate we need to update read/write index
  284. *
  285. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  286. */
  287. struct iwl_rx_queue {
  288. __le32 *bd;
  289. dma_addr_t dma_addr;
  290. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  291. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  292. u32 processed;
  293. u32 read;
  294. u32 write;
  295. u32 free_count;
  296. struct list_head rx_free;
  297. struct list_head rx_used;
  298. int need_update;
  299. spinlock_t lock;
  300. };
  301. #define IWL_SUPPORTED_RATES_IE_LEN 8
  302. #define SCAN_INTERVAL 100
  303. #define MAX_A_CHANNELS 252
  304. #define MIN_A_CHANNELS 7
  305. #define MAX_B_CHANNELS 14
  306. #define MIN_B_CHANNELS 1
  307. #define MAX_TID_COUNT 9
  308. #define IWL_INVALID_RATE 0xFF
  309. #define IWL_INVALID_VALUE -1
  310. /**
  311. * struct iwl_ht_agg -- aggregation status while waiting for block-ack
  312. * @txq_id: Tx queue used for Tx attempt
  313. * @frame_count: # frames attempted by Tx command
  314. * @wait_for_ba: Expect block-ack before next Tx reply
  315. * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
  316. * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
  317. * @bitmap1: High order, one bit for each frame pending ACK in Tx window
  318. * @rate_n_flags: Rate at which Tx was attempted
  319. *
  320. * If REPLY_TX indicates that aggregation was attempted, driver must wait
  321. * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
  322. * until block ack arrives.
  323. */
  324. struct iwl_ht_agg {
  325. u16 txq_id;
  326. u16 frame_count;
  327. u16 wait_for_ba;
  328. u16 start_idx;
  329. u64 bitmap;
  330. u32 rate_n_flags;
  331. #define IWL_AGG_OFF 0
  332. #define IWL_AGG_ON 1
  333. #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
  334. #define IWL_EMPTYING_HW_QUEUE_DELBA 3
  335. u8 state;
  336. };
  337. struct iwl_tid_data {
  338. u16 seq_number;
  339. u16 tfds_in_queue;
  340. struct iwl_ht_agg agg;
  341. };
  342. struct iwl_hw_key {
  343. enum ieee80211_key_alg alg;
  344. int keylen;
  345. u8 keyidx;
  346. u8 key[32];
  347. };
  348. union iwl4965_ht_rate_supp {
  349. u16 rates;
  350. struct {
  351. u8 siso_rate;
  352. u8 mimo_rate;
  353. };
  354. };
  355. #define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
  356. #define CFG_HT_MPDU_DENSITY_2USEC (0x5)
  357. #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
  358. struct iwl_ht_info {
  359. /* self configuration data */
  360. u8 is_ht;
  361. u8 supported_chan_width;
  362. u8 is_green_field;
  363. u8 sgf; /* HT_SHORT_GI_* short guard interval */
  364. u8 max_amsdu_size;
  365. u8 ampdu_factor;
  366. u8 mpdu_density;
  367. u8 supp_mcs_set[16];
  368. /* BSS related data */
  369. u8 control_channel;
  370. u8 extension_chan_offset;
  371. u8 tx_chan_width;
  372. u8 ht_protection;
  373. u8 non_GF_STA_present;
  374. };
  375. union iwl_qos_capabity {
  376. struct {
  377. u8 edca_count:4; /* bit 0-3 */
  378. u8 q_ack:1; /* bit 4 */
  379. u8 queue_request:1; /* bit 5 */
  380. u8 txop_request:1; /* bit 6 */
  381. u8 reserved:1; /* bit 7 */
  382. } q_AP;
  383. struct {
  384. u8 acvo_APSD:1; /* bit 0 */
  385. u8 acvi_APSD:1; /* bit 1 */
  386. u8 ac_bk_APSD:1; /* bit 2 */
  387. u8 ac_be_APSD:1; /* bit 3 */
  388. u8 q_ack:1; /* bit 4 */
  389. u8 max_len:2; /* bit 5-6 */
  390. u8 more_data_ack:1; /* bit 7 */
  391. } q_STA;
  392. u8 val;
  393. };
  394. /* QoS structures */
  395. struct iwl_qos_info {
  396. int qos_enable;
  397. int qos_active;
  398. union iwl_qos_capabity qos_cap;
  399. struct iwl_qosparam_cmd def_qos_parm;
  400. };
  401. #define STA_PS_STATUS_WAKE 0
  402. #define STA_PS_STATUS_SLEEP 1
  403. struct iwl_station_entry {
  404. struct iwl_addsta_cmd sta;
  405. struct iwl_tid_data tid[MAX_TID_COUNT];
  406. u8 used;
  407. u8 ps_status;
  408. struct iwl_hw_key keyinfo;
  409. };
  410. /* one for each uCode image (inst/data, boot/init/runtime) */
  411. struct fw_desc {
  412. void *v_addr; /* access by driver */
  413. dma_addr_t p_addr; /* access by card's busmaster DMA */
  414. u32 len; /* bytes */
  415. };
  416. /* uCode file layout */
  417. struct iwl_ucode {
  418. __le32 ver; /* major/minor/subminor */
  419. __le32 inst_size; /* bytes of runtime instructions */
  420. __le32 data_size; /* bytes of runtime data */
  421. __le32 init_size; /* bytes of initialization instructions */
  422. __le32 init_data_size; /* bytes of initialization data */
  423. __le32 boot_size; /* bytes of bootstrap instructions */
  424. u8 data[0]; /* data in same order as "size" elements */
  425. };
  426. struct iwl4965_ibss_seq {
  427. u8 mac[ETH_ALEN];
  428. u16 seq_num;
  429. u16 frag_num;
  430. unsigned long packet_time;
  431. struct list_head list;
  432. };
  433. struct iwl_sensitivity_ranges {
  434. u16 min_nrg_cck;
  435. u16 max_nrg_cck;
  436. u16 nrg_th_cck;
  437. u16 nrg_th_ofdm;
  438. u16 auto_corr_min_ofdm;
  439. u16 auto_corr_min_ofdm_mrc;
  440. u16 auto_corr_min_ofdm_x1;
  441. u16 auto_corr_min_ofdm_mrc_x1;
  442. u16 auto_corr_max_ofdm;
  443. u16 auto_corr_max_ofdm_mrc;
  444. u16 auto_corr_max_ofdm_x1;
  445. u16 auto_corr_max_ofdm_mrc_x1;
  446. u16 auto_corr_max_cck;
  447. u16 auto_corr_max_cck_mrc;
  448. u16 auto_corr_min_cck;
  449. u16 auto_corr_min_cck_mrc;
  450. };
  451. #define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
  452. /**
  453. * struct iwl_hw_params
  454. * @max_txq_num: Max # Tx queues supported
  455. * @tx/rx_chains_num: Number of TX/RX chains
  456. * @valid_tx/rx_ant: usable antennas
  457. * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
  458. * @max_rxq_log: Log-base-2 of max_rxq_size
  459. * @rx_buf_size: Rx buffer size
  460. * @max_stations:
  461. * @bcast_sta_id:
  462. * @fat_channel: is 40MHz width possible in band 2.4
  463. * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
  464. * @sw_crypto: 0 for hw, 1 for sw
  465. * @max_xxx_size: for ucode uses
  466. * @ct_kill_threshold: temperature threshold
  467. * @struct iwl_sensitivity_ranges: range of sensitivity values
  468. * @first_ampdu_q: first HW queue available for ampdu
  469. */
  470. struct iwl_hw_params {
  471. u16 max_txq_num;
  472. u8 tx_chains_num;
  473. u8 rx_chains_num;
  474. u8 valid_tx_ant;
  475. u8 valid_rx_ant;
  476. u16 max_rxq_size;
  477. u16 max_rxq_log;
  478. u32 rx_buf_size;
  479. u32 max_pkt_size;
  480. u8 max_stations;
  481. u8 bcast_sta_id;
  482. u8 fat_channel;
  483. u8 sw_crypto;
  484. u32 max_inst_size;
  485. u32 max_data_size;
  486. u32 max_bsm_size;
  487. u32 ct_kill_threshold; /* value in hw-dependent units */
  488. const struct iwl_sensitivity_ranges *sens;
  489. u8 first_ampdu_q;
  490. };
  491. #define HT_SHORT_GI_20MHZ (1 << 0)
  492. #define HT_SHORT_GI_40MHZ (1 << 1)
  493. #define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
  494. x->u.rx_frame.stats.payload + \
  495. x->u.rx_frame.stats.phy_count))
  496. #define IWL_RX_END(x) ((struct iwl4965_rx_frame_end *)(\
  497. IWL_RX_HDR(x)->payload + \
  498. le16_to_cpu(IWL_RX_HDR(x)->len)))
  499. #define IWL_RX_STATS(x) (&x->u.rx_frame.stats)
  500. #define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload)
  501. /******************************************************************************
  502. *
  503. * Functions implemented in iwl-base.c which are forward declared here
  504. * for use by iwl-*.c
  505. *
  506. *****************************************************************************/
  507. struct iwl_addsta_cmd;
  508. extern int iwl_send_add_sta(struct iwl_priv *priv,
  509. struct iwl_addsta_cmd *sta, u8 flags);
  510. u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
  511. u8 flags, struct ieee80211_ht_info *ht_info);
  512. extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  513. struct ieee80211_hdr *hdr,
  514. const u8 *dest, int left);
  515. extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
  516. int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
  517. extern int iwl4965_set_power(struct iwl_priv *priv, void *cmd);
  518. extern const u8 iwl_bcast_addr[ETH_ALEN];
  519. /******************************************************************************
  520. *
  521. * Functions implemented in iwl-[34]*.c which are forward declared here
  522. * for use by iwl-base.c
  523. *
  524. * NOTE: The implementation of these functions are hardware specific
  525. * which is why they are in the hardware specific files (vs. iwl-base.c)
  526. *
  527. * Naming convention --
  528. * iwl4965_ <-- Its part of iwlwifi (should be changed to iwl4965_)
  529. * iwl4965_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW)
  530. * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
  531. * iwl4965_bg_ <-- Called from work queue context
  532. * iwl4965_mac_ <-- mac80211 callback
  533. *
  534. ****************************************************************************/
  535. extern int iwl_rxq_stop(struct iwl_priv *priv);
  536. extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
  537. extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
  538. struct iwl_frame *frame, u8 rate);
  539. extern void iwl4965_disable_events(struct iwl_priv *priv);
  540. extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel);
  541. extern int iwl_queue_space(const struct iwl_queue *q);
  542. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  543. {
  544. return q->write_ptr > q->read_ptr ?
  545. (i >= q->read_ptr && i < q->write_ptr) :
  546. !(i < q->read_ptr && i >= q->write_ptr);
  547. }
  548. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
  549. {
  550. /* This is for scan command, the big buffer at end of command array */
  551. if (is_huge)
  552. return q->n_window; /* must be power of 2 */
  553. /* Otherwise, use normal size buffers */
  554. return index & (q->n_window - 1);
  555. }
  556. struct iwl_priv;
  557. /*
  558. * Forward declare iwl-4965.c functions for iwl-base.c
  559. */
  560. extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv);
  561. int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
  562. u8 tid, int txq_id);
  563. /* Structures, enum, and defines specific to the 4965 */
  564. #define IWL_KW_SIZE 0x1000 /*4k */
  565. struct iwl_kw {
  566. dma_addr_t dma_addr;
  567. void *v_addr;
  568. size_t size;
  569. };
  570. #define IWL_CHANNEL_WIDTH_20MHZ 0
  571. #define IWL_CHANNEL_WIDTH_40MHZ 1
  572. #define IWL_MIMO_PS_STATIC 0
  573. #define IWL_MIMO_PS_NONE 3
  574. #define IWL_MIMO_PS_DYNAMIC 1
  575. #define IWL_MIMO_PS_INVALID 2
  576. #define IWL_OPERATION_MODE_AUTO 0
  577. #define IWL_OPERATION_MODE_HT_ONLY 1
  578. #define IWL_OPERATION_MODE_MIXED 2
  579. #define IWL_OPERATION_MODE_20MHZ 3
  580. #define IWL_TX_CRC_SIZE 4
  581. #define IWL_TX_DELIMITER_SIZE 4
  582. #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
  583. struct iwl4965_lq_mngr {
  584. spinlock_t lock;
  585. s32 max_window_size;
  586. s32 *expected_tpt;
  587. u8 *next_higher_rate;
  588. u8 *next_lower_rate;
  589. unsigned long stamp;
  590. unsigned long stamp_last;
  591. u32 flush_time;
  592. u32 tx_packets;
  593. };
  594. /* Sensitivity and chain noise calibration */
  595. #define INTERFERENCE_DATA_AVAILABLE __constant_cpu_to_le32(1)
  596. #define INITIALIZATION_VALUE 0xFFFF
  597. #define CAL_NUM_OF_BEACONS 20
  598. #define MAXIMUM_ALLOWED_PATHLOSS 15
  599. #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
  600. #define MAX_FA_OFDM 50
  601. #define MIN_FA_OFDM 5
  602. #define MAX_FA_CCK 50
  603. #define MIN_FA_CCK 5
  604. #define AUTO_CORR_STEP_OFDM 1
  605. #define AUTO_CORR_STEP_CCK 3
  606. #define AUTO_CORR_MAX_TH_CCK 160
  607. #define NRG_DIFF 2
  608. #define NRG_STEP_CCK 2
  609. #define NRG_MARGIN 8
  610. #define MAX_NUMBER_CCK_NO_FA 100
  611. #define AUTO_CORR_CCK_MIN_VAL_DEF (125)
  612. #define CHAIN_A 0
  613. #define CHAIN_B 1
  614. #define CHAIN_C 2
  615. #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
  616. #define ALL_BAND_FILTER 0xFF00
  617. #define IN_BAND_FILTER 0xFF
  618. #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
  619. #define NRG_NUM_PREV_STAT_L 20
  620. #define NUM_RX_CHAINS 3
  621. enum iwl4965_false_alarm_state {
  622. IWL_FA_TOO_MANY = 0,
  623. IWL_FA_TOO_FEW = 1,
  624. IWL_FA_GOOD_RANGE = 2,
  625. };
  626. enum iwl4965_chain_noise_state {
  627. IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
  628. IWL_CHAIN_NOISE_ACCUMULATE = 1,
  629. IWL_CHAIN_NOISE_CALIBRATED = 2,
  630. };
  631. enum iwl4965_calib_enabled_state {
  632. IWL_CALIB_DISABLED = 0, /* must be 0 */
  633. IWL_CALIB_ENABLED = 1,
  634. };
  635. struct statistics_general_data {
  636. u32 beacon_silence_rssi_a;
  637. u32 beacon_silence_rssi_b;
  638. u32 beacon_silence_rssi_c;
  639. u32 beacon_energy_a;
  640. u32 beacon_energy_b;
  641. u32 beacon_energy_c;
  642. };
  643. struct iwl_calib_results {
  644. void *tx_iq_res;
  645. void *tx_iq_perd_res;
  646. void *lo_res;
  647. u32 tx_iq_res_len;
  648. u32 tx_iq_perd_res_len;
  649. u32 lo_res_len;
  650. };
  651. enum ucode_type {
  652. UCODE_NONE = 0,
  653. UCODE_INIT,
  654. UCODE_RT
  655. };
  656. /* Sensitivity calib data */
  657. struct iwl_sensitivity_data {
  658. u32 auto_corr_ofdm;
  659. u32 auto_corr_ofdm_mrc;
  660. u32 auto_corr_ofdm_x1;
  661. u32 auto_corr_ofdm_mrc_x1;
  662. u32 auto_corr_cck;
  663. u32 auto_corr_cck_mrc;
  664. u32 last_bad_plcp_cnt_ofdm;
  665. u32 last_fa_cnt_ofdm;
  666. u32 last_bad_plcp_cnt_cck;
  667. u32 last_fa_cnt_cck;
  668. u32 nrg_curr_state;
  669. u32 nrg_prev_state;
  670. u32 nrg_value[10];
  671. u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
  672. u32 nrg_silence_ref;
  673. u32 nrg_energy_idx;
  674. u32 nrg_silence_idx;
  675. u32 nrg_th_cck;
  676. s32 nrg_auto_corr_silence_diff;
  677. u32 num_in_cck_no_fa;
  678. u32 nrg_th_ofdm;
  679. };
  680. /* Chain noise (differential Rx gain) calib data */
  681. struct iwl_chain_noise_data {
  682. u8 state;
  683. u16 beacon_count;
  684. u32 chain_noise_a;
  685. u32 chain_noise_b;
  686. u32 chain_noise_c;
  687. u32 chain_signal_a;
  688. u32 chain_signal_b;
  689. u32 chain_signal_c;
  690. u8 disconn_array[NUM_RX_CHAINS];
  691. u8 delta_gain_code[NUM_RX_CHAINS];
  692. u8 radio_write;
  693. };
  694. #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
  695. #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
  696. enum {
  697. MEASUREMENT_READY = (1 << 0),
  698. MEASUREMENT_ACTIVE = (1 << 1),
  699. };
  700. #define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
  701. struct iwl_priv {
  702. /* ieee device used by generic ieee processing code */
  703. struct ieee80211_hw *hw;
  704. struct ieee80211_channel *ieee_channels;
  705. struct ieee80211_rate *ieee_rates;
  706. struct iwl_cfg *cfg;
  707. /* temporary frame storage list */
  708. struct list_head free_frames;
  709. int frames_count;
  710. enum ieee80211_band band;
  711. int alloc_rxb_skb;
  712. bool add_radiotap;
  713. void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
  714. struct iwl_rx_mem_buffer *rxb);
  715. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  716. #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
  717. /* spectrum measurement report caching */
  718. struct iwl4965_spectrum_notification measure_report;
  719. u8 measurement_status;
  720. #endif
  721. /* ucode beacon time */
  722. u32 ucode_beacon_time;
  723. /* we allocate array of iwl4965_channel_info for NIC's valid channels.
  724. * Access via channel # using indirect index array */
  725. struct iwl_channel_info *channel_info; /* channel info array */
  726. u8 channel_count; /* # of channels */
  727. /* each calibration channel group in the EEPROM has a derived
  728. * clip setting for each rate. */
  729. const struct iwl4965_clip_group clip_groups[5];
  730. /* thermal calibration */
  731. s32 temperature; /* degrees Kelvin */
  732. s32 last_temperature;
  733. /* init calibration results */
  734. struct iwl_calib_results calib_results;
  735. /* Scan related variables */
  736. unsigned long last_scan_jiffies;
  737. unsigned long next_scan_jiffies;
  738. unsigned long scan_start;
  739. unsigned long scan_pass_start;
  740. unsigned long scan_start_tsf;
  741. int scan_bands;
  742. int one_direct_scan;
  743. u8 direct_ssid_len;
  744. u8 direct_ssid[IW_ESSID_MAX_SIZE];
  745. struct iwl_scan_cmd *scan;
  746. u32 scan_tx_ant[IEEE80211_NUM_BANDS];
  747. /* spinlock */
  748. spinlock_t lock; /* protect general shared data */
  749. spinlock_t hcmd_lock; /* protect hcmd */
  750. struct mutex mutex;
  751. /* basic pci-network driver stuff */
  752. struct pci_dev *pci_dev;
  753. /* pci hardware address support */
  754. void __iomem *hw_base;
  755. u32 hw_rev;
  756. u32 hw_wa_rev;
  757. u8 rev_id;
  758. /* uCode images, save to reload in case of failure */
  759. struct fw_desc ucode_code; /* runtime inst */
  760. struct fw_desc ucode_data; /* runtime data original */
  761. struct fw_desc ucode_data_backup; /* runtime data save/restore */
  762. struct fw_desc ucode_init; /* initialization inst */
  763. struct fw_desc ucode_init_data; /* initialization data */
  764. struct fw_desc ucode_boot; /* bootstrap inst */
  765. enum ucode_type ucode_type;
  766. u8 ucode_write_complete; /* the image write is complete */
  767. struct iwl4965_rxon_time_cmd rxon_timing;
  768. /* We declare this const so it can only be
  769. * changed via explicit cast within the
  770. * routines that actually update the physical
  771. * hardware */
  772. const struct iwl_rxon_cmd active_rxon;
  773. struct iwl_rxon_cmd staging_rxon;
  774. int error_recovering;
  775. struct iwl_rxon_cmd recovery_rxon;
  776. /* 1st responses from initialize and runtime uCode images.
  777. * 4965's initialize alive response contains some calibration data. */
  778. struct iwl_init_alive_resp card_alive_init;
  779. struct iwl_alive_resp card_alive;
  780. #ifdef CONFIG_IWLWIFI_RFKILL
  781. struct rfkill *rfkill;
  782. #endif
  783. #ifdef CONFIG_IWLWIFI_LEDS
  784. struct iwl_led led[IWL_LED_TRG_MAX];
  785. unsigned long last_blink_time;
  786. u8 last_blink_rate;
  787. u8 allow_blinking;
  788. u64 led_tpt;
  789. #endif
  790. u16 active_rate;
  791. u16 active_rate_basic;
  792. u8 assoc_station_added;
  793. u8 use_ant_b_for_management_frame; /* Tx antenna selection */
  794. u8 start_calib;
  795. struct iwl_sensitivity_data sensitivity_data;
  796. struct iwl_chain_noise_data chain_noise_data;
  797. __le16 sensitivity_tbl[HD_TABLE_SIZE];
  798. struct iwl_ht_info current_ht_config;
  799. u8 last_phy_res[100];
  800. /* Rate scaling data */
  801. struct iwl4965_lq_mngr lq_mngr;
  802. /* Rate scaling data */
  803. s8 data_retry_limit;
  804. u8 retry_rate;
  805. wait_queue_head_t wait_command_queue;
  806. int activity_timer_active;
  807. /* Rx and Tx DMA processing queues */
  808. struct iwl_rx_queue rxq;
  809. struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
  810. unsigned long txq_ctx_active_msk;
  811. struct iwl_kw kw; /* keep warm address */
  812. u32 scd_base_addr; /* scheduler sram base address */
  813. unsigned long status;
  814. int last_rx_rssi; /* From Rx packet statisitics */
  815. int last_rx_noise; /* From beacon statistics */
  816. /* counts mgmt, ctl, and data packets */
  817. struct traffic_stats {
  818. u32 cnt;
  819. u64 bytes;
  820. } tx_stats[3], rx_stats[3];
  821. struct iwl_power_mgr power_data;
  822. struct iwl_notif_statistics statistics;
  823. unsigned long last_statistics_time;
  824. /* context information */
  825. u8 essid[IW_ESSID_MAX_SIZE];
  826. u8 essid_len;
  827. u16 rates_mask;
  828. u32 power_mode;
  829. u32 antenna;
  830. u8 bssid[ETH_ALEN];
  831. u16 rts_threshold;
  832. u8 mac_addr[ETH_ALEN];
  833. /*station table variables */
  834. spinlock_t sta_lock;
  835. int num_stations;
  836. struct iwl_station_entry stations[IWL_STATION_COUNT];
  837. struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
  838. u8 default_wep_key;
  839. u8 key_mapping_key;
  840. unsigned long ucode_key_table;
  841. /* Indication if ieee80211_ops->open has been called */
  842. u8 is_open;
  843. u8 mac80211_registered;
  844. /* Rx'd packet timing information */
  845. u32 last_beacon_time;
  846. u64 last_tsf;
  847. /* eeprom */
  848. u8 *eeprom;
  849. struct iwl_eeprom_calib_info *calib_info;
  850. enum ieee80211_if_types iw_mode;
  851. struct sk_buff *ibss_beacon;
  852. /* Last Rx'd beacon timestamp */
  853. u64 timestamp;
  854. u16 beacon_int;
  855. struct ieee80211_vif *vif;
  856. struct iwl_hw_params hw_params;
  857. /* driver/uCode shared Tx Byte Counts and Rx status */
  858. void *shared_virt;
  859. int rb_closed_offset;
  860. /* Physical Pointer to Tx Byte Counts and Rx status */
  861. dma_addr_t shared_phys;
  862. /* Current association information needed to configure the
  863. * hardware */
  864. u16 assoc_id;
  865. u16 assoc_capability;
  866. u8 ps_mode;
  867. struct iwl_qos_info qos_data;
  868. struct workqueue_struct *workqueue;
  869. struct work_struct up;
  870. struct work_struct restart;
  871. struct work_struct calibrated_work;
  872. struct work_struct scan_completed;
  873. struct work_struct rx_replenish;
  874. struct work_struct rf_kill;
  875. struct work_struct abort_scan;
  876. struct work_struct update_link_led;
  877. struct work_struct auth_work;
  878. struct work_struct report_work;
  879. struct work_struct request_scan;
  880. struct work_struct beacon_update;
  881. struct work_struct set_monitor;
  882. struct tasklet_struct irq_tasklet;
  883. struct delayed_work init_alive_start;
  884. struct delayed_work alive_start;
  885. struct delayed_work scan_check;
  886. /* TX Power */
  887. s8 tx_power_user_lmt;
  888. s8 tx_power_channel_lmt;
  889. #ifdef CONFIG_PM
  890. u32 pm_state[16];
  891. #endif
  892. #ifdef CONFIG_IWLWIFI_DEBUG
  893. /* debugging info */
  894. u32 debug_level;
  895. u32 framecnt_to_us;
  896. atomic_t restrict_refcnt;
  897. #ifdef CONFIG_IWLWIFI_DEBUGFS
  898. /* debugfs */
  899. struct iwl_debugfs *dbgfs;
  900. #endif /* CONFIG_IWLWIFI_DEBUGFS */
  901. #endif /* CONFIG_IWLWIFI_DEBUG */
  902. struct work_struct txpower_work;
  903. u32 disable_sens_cal;
  904. u32 disable_chain_noise_cal;
  905. u32 disable_tx_power_cal;
  906. struct work_struct run_time_calib_work;
  907. struct timer_list statistics_periodic;
  908. }; /*iwl_priv */
  909. static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  910. {
  911. set_bit(txq_id, &priv->txq_ctx_active_msk);
  912. }
  913. static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  914. {
  915. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  916. }
  917. #ifdef CONFIG_IWLWIFI_DEBUG
  918. const char *iwl_get_tx_fail_reason(u32 status);
  919. #else
  920. static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
  921. #endif
  922. static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
  923. int txq_id, int idx)
  924. {
  925. if (priv->txq[txq_id].txb[idx].skb[0])
  926. return (struct ieee80211_hdr *)priv->txq[txq_id].
  927. txb[idx].skb[0]->data;
  928. return NULL;
  929. }
  930. static inline int iwl_is_associated(struct iwl_priv *priv)
  931. {
  932. return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
  933. }
  934. static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
  935. {
  936. if (ch_info == NULL)
  937. return 0;
  938. return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
  939. }
  940. static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
  941. {
  942. return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
  943. }
  944. static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
  945. {
  946. return ch_info->band == IEEE80211_BAND_5GHZ;
  947. }
  948. static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
  949. {
  950. return ch_info->band == IEEE80211_BAND_2GHZ;
  951. }
  952. static inline int is_channel_passive(const struct iwl_channel_info *ch)
  953. {
  954. return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
  955. }
  956. static inline int is_channel_ibss(const struct iwl_channel_info *ch)
  957. {
  958. return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
  959. }
  960. #ifdef CONFIG_IWLWIFI_DEBUG
  961. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  962. void *p, u32 len)
  963. {
  964. if (!(priv->debug_level & level))
  965. return;
  966. print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
  967. p, len, 1);
  968. }
  969. #else
  970. static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
  971. void *p, u32 len)
  972. {
  973. }
  974. #endif
  975. extern const struct iwl_channel_info *iwl_get_channel_info(
  976. const struct iwl_priv *priv, enum ieee80211_band band, u16 channel);
  977. /* Requires full declaration of iwl_priv before including */
  978. #endif /* __iwl_dev_h__ */