1 /******************************************************************************
3 * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
33 #include <linux/pci.h> /* for struct pci_device_id */
34 #include <linux/kernel.h>
35 #include <net/ieee80211_radiotap.h>
39 /* Hardware specific file defines the PCI IDs table for that hardware module */
40 extern struct pci_device_id iwl_hw_card_ids[];
44 #define DRV_NAME "iwl3945"
45 #include "iwl-3945-hw.h"
47 #define DRV_NAME "iwl4965"
48 #include "iwl-4965-hw.h"
54 * Driver implementation data structures, constants, inline
57 * NOTE: DO NOT PUT HARDWARE/UCODE SPECIFIC DECLARATIONS HERE
59 * Hardware specific declarations go into iwl-*hw.h
63 #include "iwl-debug.h"
65 /* Default noise level to report when noise measurement is not available.
66 * This may be because we're:
67 * 1) Not associated (4965, no beacon statistics being sent to driver)
68 * 2) Scanning (noise measurement does not apply to associated channel)
69 * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
70 * Use default noise value of -127 ... this is below the range of measurable
71 * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
72 * Also, -127 works better than 0 when averaging frames with/without
73 * noise info (e.g. averaging might be done in app); measured dBm values are
74 * always negative ... using a negative value as the default keeps all
75 * averages within an s8's (used in some apps) range of negative values. */
76 #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
78 /* Module parameters accessible from iwl-*.c */
79 extern int iwl_param_hwcrypto;
80 extern int iwl_param_queues_num;
83 IWL_ANTENNA_DIVERSITY,
89 * RTS threshold here is total size [2347] minus 4 FCS bytes
91 * a value of 0 means RTS on all data/management packets
92 * a value > max MSDU size means no RTS
93 * else RTS for data/management frames where MPDU is larger
96 #define DEFAULT_RTS_THRESHOLD 2347U
97 #define MIN_RTS_THRESHOLD 0U
98 #define MAX_RTS_THRESHOLD 2347U
99 #define MAX_MSDU_SIZE 2304U
100 #define MAX_MPDU_SIZE 2346U
101 #define DEFAULT_BEACON_INTERVAL 100U
102 #define DEFAULT_SHORT_RETRY_LIMIT 7U
103 #define DEFAULT_LONG_RETRY_LIMIT 4U
105 struct iwl_rx_mem_buffer {
108 struct list_head list;
111 struct iwl_rt_rx_hdr {
112 struct ieee80211_radiotap_header rt_hdr;
113 __le64 rt_tsf; /* TSF */
114 u8 rt_flags; /* radiotap packet flags */
115 u8 rt_rate; /* rate in 500kb/s */
116 __le16 rt_channelMHz; /* channel in MHz */
117 __le16 rt_chbitmask; /* channel bitfield */
118 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
120 u8 rt_antenna; /* antenna number */
121 u8 payload[0]; /* payload... */
122 } __attribute__ ((packed));
124 struct iwl_rt_tx_hdr {
125 struct ieee80211_radiotap_header rt_hdr;
126 u8 rt_rate; /* rate in 500kb/s */
127 __le16 rt_channel; /* channel in mHz */
128 __le16 rt_chbitmask; /* channel bitfield */
129 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
130 u8 rt_antenna; /* antenna number */
131 u8 payload[0]; /* payload... */
132 } __attribute__ ((packed));
135 * Generic queue structure
137 * Contains common data for Rx and Tx queues
140 int n_bd; /* number of BDs in this queue */
141 int write_ptr; /* 1-st empty entry (index) host_w*/
142 int read_ptr; /* last used entry (index) host_r*/
143 dma_addr_t dma_addr; /* physical addr for BD's */
144 int n_window; /* safe queue window */
146 int low_mark; /* low watermark, resume queue if free
147 * space more than this */
148 int high_mark; /* high watermark, stop queue if free
149 * space less than this */
150 } __attribute__ ((packed));
152 #define MAX_NUM_OF_TBS (20)
155 struct ieee80211_tx_status status;
156 struct sk_buff *skb[MAX_NUM_OF_TBS];
160 * struct iwl_tx_queue - Tx Queue for DMA
161 * @need_update: need to update read/write index
162 * @shed_retry: queue is HT AGG enabled
164 * Queue consists of circular buffer of BD's and required locking structures.
166 struct iwl_tx_queue {
168 struct iwl_tfd_frame *bd;
170 dma_addr_t dma_addr_cmd;
171 struct iwl_tx_info *txb;
177 #include "iwl-channel.h"
180 #include "iwl-3945-rs.h"
182 #include "iwl-4965-rs.h"
185 #define IWL_TX_FIFO_AC0 0
186 #define IWL_TX_FIFO_AC1 1
187 #define IWL_TX_FIFO_AC2 2
188 #define IWL_TX_FIFO_AC3 3
189 #define IWL_TX_FIFO_HCCA_1 5
190 #define IWL_TX_FIFO_HCCA_2 6
191 #define IWL_TX_FIFO_NONE 7
193 /* Minimum number of queues. MAX_NUM is defined in hw specific files */
194 #define IWL_MIN_NUM_QUEUES 4
196 /* Power management (not Tx power) structures */
198 struct iwl_power_vec_entry {
199 struct iwl_powertable_cmd cmd;
202 #define IWL_POWER_RANGE_0 (0)
203 #define IWL_POWER_RANGE_1 (1)
205 #define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */
206 #define IWL_POWER_INDEX_3 0x03
207 #define IWL_POWER_INDEX_5 0x05
208 #define IWL_POWER_AC 0x06
209 #define IWL_POWER_BATTERY 0x07
210 #define IWL_POWER_LIMIT 0x07
211 #define IWL_POWER_MASK 0x0F
212 #define IWL_POWER_ENABLED 0x10
213 #define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK)
215 struct iwl_power_mgr {
217 struct iwl_power_vec_entry pwr_range_0[IWL_POWER_AC];
218 struct iwl_power_vec_entry pwr_range_1[IWL_POWER_AC];
223 #define IEEE80211_DATA_LEN 2304
224 #define IEEE80211_4ADDR_LEN 30
225 #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
226 #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
230 struct ieee80211_hdr frame;
231 struct iwl_tx_beacon_cmd beacon;
232 u8 raw[IEEE80211_FRAME_LEN];
235 struct list_head list;
238 #define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf)
239 #define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8)
240 #define SEQ_TO_INDEX(x) (x & 0xff)
241 #define INDEX_TO_SEQ(x) (x & 0xff)
242 #define SEQ_HUGE_FRAME (0x4000)
243 #define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000)
244 #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
245 #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
246 #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
249 /* CMD_SIZE_NORMAL = 0, */
250 CMD_SIZE_HUGE = (1 << 0),
252 CMD_ASYNC = (1 << 1),
253 /* CMD_NO_SKB = 0, */
254 CMD_WANT_SKB = (1 << 2),
260 struct iwl_cmd_meta {
261 struct iwl_cmd_meta *source;
264 int (*callback)(struct iwl_priv *priv,
265 struct iwl_cmd *cmd, struct sk_buff *skb);
266 } __attribute__ ((packed)) u;
268 /* The CMD_SIZE_HUGE flag bit indicates that the command
269 * structure is stored at the end of the shared queue memory. */
272 } __attribute__ ((packed));
275 struct iwl_cmd_meta meta;
276 struct iwl_cmd_header hdr;
278 struct iwl_addsta_cmd addsta;
279 struct iwl_led_cmd led;
284 struct iwl_bt_cmd bt;
285 struct iwl_rxon_time_cmd rxon_time;
286 struct iwl_powertable_cmd powertable;
287 struct iwl_qosparam_cmd qosparam;
288 struct iwl_tx_cmd tx;
289 struct iwl_tx_beacon_cmd tx_beacon;
290 struct iwl_rxon_assoc_cmd rxon_assoc;
293 } __attribute__ ((packed)) cmd;
294 } __attribute__ ((packed));
296 struct iwl_host_cmd {
299 struct iwl_cmd_meta meta;
303 #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
304 sizeof(struct iwl_cmd_meta))
307 * RX related structures and functions
309 #define RX_FREE_BUFFERS 64
310 #define RX_LOW_WATERMARK 8
312 #define SUP_RATE_11A_MAX_NUM_CHANNELS 8
313 #define SUP_RATE_11B_MAX_NUM_CHANNELS 4
314 #define SUP_RATE_11G_MAX_NUM_CHANNELS 12
317 * struct iwl_rx_queue - Rx queue
318 * @processed: Internal index to last handled Rx packet
319 * @read: Shared index to newest available Rx buffer
320 * @write: Shared index to oldest written Rx packet
321 * @free_count: Number of pre-allocated buffers in rx_free
322 * @rx_free: list of free SKBs for use
323 * @rx_used: List of Rx buffers with no SKB
324 * @need_update: flag to indicate we need to update read/write index
326 * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
328 struct iwl_rx_queue {
331 struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
332 struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
337 struct list_head rx_free;
338 struct list_head rx_used;
343 #define IWL_SUPPORTED_RATES_IE_LEN 8
345 #define SCAN_INTERVAL 100
347 #define MAX_A_CHANNELS 252
348 #define MIN_A_CHANNELS 7
350 #define MAX_B_CHANNELS 14
351 #define MIN_B_CHANNELS 1
353 #define STATUS_HCMD_ACTIVE 0 /* host command in progress */
354 #define STATUS_INT_ENABLED 1
355 #define STATUS_RF_KILL_HW 2
356 #define STATUS_RF_KILL_SW 3
357 #define STATUS_INIT 4
358 #define STATUS_ALIVE 5
359 #define STATUS_READY 6
360 #define STATUS_TEMPERATURE 7
361 #define STATUS_GEO_CONFIGURED 8
362 #define STATUS_EXIT_PENDING 9
363 #define STATUS_IN_SUSPEND 10
364 #define STATUS_STATISTICS 11
365 #define STATUS_SCANNING 12
366 #define STATUS_SCAN_ABORTING 13
367 #define STATUS_SCAN_HW 14
368 #define STATUS_POWER_PMI 15
369 #define STATUS_FW_ERROR 16
371 #define MAX_TID_COUNT 9
373 #define IWL_INVALID_RATE 0xFF
374 #define IWL_INVALID_VALUE -1
377 #ifdef CONFIG_IWLWIFI_HT
378 #ifdef CONFIG_IWLWIFI_HT_AGG
388 #endif /* CONFIG_IWLWIFI_HT_AGG */
389 #endif /* CONFIG_IWLWIFI_HT */
392 struct iwl_tid_data {
395 #ifdef CONFIG_IWLWIFI_HT
396 #ifdef CONFIG_IWLWIFI_HT_AGG
397 struct iwl_ht_agg agg;
398 #endif /* CONFIG_IWLWIFI_HT_AGG */
399 #endif /* CONFIG_IWLWIFI_HT */
404 enum ieee80211_key_alg alg;
409 union iwl_ht_rate_supp {
417 #ifdef CONFIG_IWLWIFI_HT
418 #define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
419 #define HT_IE_MAX_AMSDU_SIZE_4K (0)
420 #define CFG_HT_MPDU_DENSITY_2USEC (0x5)
421 #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
432 u8 supported_chan_width;
433 u8 extension_chan_offset;
440 #endif /*CONFIG_IWLWIFI_HT */
442 #ifdef CONFIG_IWLWIFI_QOS
444 union iwl_qos_capabity {
446 u8 edca_count:4; /* bit 0-3 */
447 u8 q_ack:1; /* bit 4 */
448 u8 queue_request:1; /* bit 5 */
449 u8 txop_request:1; /* bit 6 */
450 u8 reserved:1; /* bit 7 */
453 u8 acvo_APSD:1; /* bit 0 */
454 u8 acvi_APSD:1; /* bit 1 */
455 u8 ac_bk_APSD:1; /* bit 2 */
456 u8 ac_be_APSD:1; /* bit 3 */
457 u8 q_ack:1; /* bit 4 */
458 u8 max_len:2; /* bit 5-6 */
459 u8 more_data_ack:1; /* bit 7 */
465 struct iwl_qos_info {
468 union iwl_qos_capabity qos_cap;
469 struct iwl_qosparam_cmd def_qos_parm;
471 #endif /*CONFIG_IWLWIFI_QOS */
473 #define STA_PS_STATUS_WAKE 0
474 #define STA_PS_STATUS_SLEEP 1
476 struct iwl_station_entry {
477 struct iwl_addsta_cmd sta;
478 struct iwl_tid_data tid[MAX_TID_COUNT];
490 struct iwl_hw_key keyinfo;
493 /* one for each uCode image (inst/data, boot/init/runtime) */
495 void *v_addr; /* access by driver */
496 dma_addr_t p_addr; /* access by card's busmaster DMA */
500 /* uCode file layout */
502 __le32 ver; /* major/minor/subminor */
503 __le32 inst_size; /* bytes of runtime instructions */
504 __le32 data_size; /* bytes of runtime data */
505 __le32 init_size; /* bytes of initialization instructions */
506 __le32 init_data_size; /* bytes of initialization data */
507 __le32 boot_size; /* bytes of bootstrap instructions */
508 u8 data[0]; /* data in same order as "size" elements */
511 #define IWL_IBSS_MAC_HASH_SIZE 32
513 struct iwl_ibss_seq {
517 unsigned long packet_time;
518 struct list_head list;
521 struct iwl_driver_hw_info {
531 dma_addr_t shared_phys;
535 #define STA_FLG_RTS_MIMO_PROT_MSK __constant_cpu_to_le32(1 << 17)
536 #define STA_FLG_AGG_MPDU_8US_MSK __constant_cpu_to_le32(1 << 18)
537 #define STA_FLG_MAX_AGG_SIZE_POS (19)
538 #define STA_FLG_MAX_AGG_SIZE_MSK __constant_cpu_to_le32(3 << 19)
539 #define STA_FLG_FAT_EN_MSK __constant_cpu_to_le32(1 << 21)
540 #define STA_FLG_MIMO_DIS_MSK __constant_cpu_to_le32(1 << 22)
541 #define STA_FLG_AGG_MPDU_DENSITY_POS (23)
542 #define STA_FLG_AGG_MPDU_DENSITY_MSK __constant_cpu_to_le32(7 << 23)
543 #define HT_SHORT_GI_20MHZ_ONLY (1 << 0)
544 #define HT_SHORT_GI_40MHZ_ONLY (1 << 1)
547 #include "iwl-priv.h"
549 /* Requires full declaration of iwl_priv before including */
552 #define IWL_RX_HDR(x) ((struct iwl_rx_frame_hdr *)(\
553 x->u.rx_frame.stats.payload + \
554 x->u.rx_frame.stats.phy_count))
555 #define IWL_RX_END(x) ((struct iwl_rx_frame_end *)(\
556 IWL_RX_HDR(x)->payload + \
557 le16_to_cpu(IWL_RX_HDR(x)->len)))
558 #define IWL_RX_STATS(x) (&x->u.rx_frame.stats)
559 #define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload)
562 /******************************************************************************
564 * Functions implemented in iwl-base.c which are forward declared here
567 *****************************************************************************/
568 struct iwl_addsta_cmd;
569 extern int iwl_send_add_station(struct iwl_priv *priv,
570 struct iwl_addsta_cmd *sta, u8 flags);
571 extern u8 iwl_add_station(struct iwl_priv *priv, const u8 *bssid,
572 int is_ap, u8 flags);
573 extern int iwl_is_network_packet(struct iwl_priv *priv,
574 struct ieee80211_hdr *header);
575 extern int iwl_power_init_handle(struct iwl_priv *priv);
576 extern int iwl_eeprom_init(struct iwl_priv *priv);
577 #ifdef CONFIG_IWLWIFI_DEBUG
578 extern void iwl_report_frame(struct iwl_priv *priv,
579 struct iwl_rx_packet *pkt,
580 struct ieee80211_hdr *header, int group100);
582 static inline void iwl_report_frame(struct iwl_priv *priv,
583 struct iwl_rx_packet *pkt,
584 struct ieee80211_hdr *header,
587 extern void iwl_handle_data_packet_monitor(struct iwl_priv *priv,
588 struct iwl_rx_mem_buffer *rxb,
589 void *data, short len,
590 struct ieee80211_rx_status *stats,
592 extern int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr
594 extern int iwl_rx_queue_alloc(struct iwl_priv *priv);
595 extern void iwl_rx_queue_reset(struct iwl_priv *priv,
596 struct iwl_rx_queue *rxq);
597 extern int iwl_calc_db_from_ratio(int sig_ratio);
598 extern int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm);
599 extern int iwl_tx_queue_init(struct iwl_priv *priv,
600 struct iwl_tx_queue *txq, int count, u32 id);
601 extern void iwl_rx_replenish(void *data);
602 extern void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq);
603 extern int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len,
605 extern int __must_check iwl_send_cmd(struct iwl_priv *priv,
606 struct iwl_host_cmd *cmd);
607 extern unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
608 struct ieee80211_hdr *hdr,
609 const u8 *dest, int left);
610 extern int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv,
611 struct iwl_rx_queue *q);
612 extern int iwl_send_statistics_request(struct iwl_priv *priv);
613 extern void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
615 struct ieee80211_rx_status *stats);
617 extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr);
620 extern const u8 BROADCAST_ADDR[ETH_ALEN];
623 * Currently used by iwl-3945-rs... look at restructuring so that it doesn't
624 * call this... todo... fix that.
626 extern u8 iwl_sync_station(struct iwl_priv *priv, int sta_id,
627 u16 tx_rate, u8 flags);
629 static inline int iwl_is_associated(struct iwl_priv *priv)
631 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
634 /******************************************************************************
636 * Functions implemented in iwl-[34]*.c which are forward declared here
637 * for use by iwl-base.c
639 * NOTE: The implementation of these functions are hardware specific
640 * which is why they are in the hardware specific files (vs. iwl-base.c)
642 * Naming convention --
643 * iwl_ <-- Its part of iwlwifi (should be changed to iwl_)
644 * iwl_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW)
645 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
646 * iwl_bg_ <-- Called from work queue context
647 * iwl_mac_ <-- mac80211 callback
649 ****************************************************************************/
650 extern void iwl_hw_rx_handler_setup(struct iwl_priv *priv);
651 extern void iwl_hw_setup_deferred_work(struct iwl_priv *priv);
652 extern void iwl_hw_cancel_deferred_work(struct iwl_priv *priv);
653 extern int iwl_hw_rxq_stop(struct iwl_priv *priv);
654 extern int iwl_hw_set_hw_setting(struct iwl_priv *priv);
655 extern int iwl_hw_nic_init(struct iwl_priv *priv);
656 extern int iwl_hw_nic_stop_master(struct iwl_priv *priv);
657 extern void iwl_hw_txq_ctx_free(struct iwl_priv *priv);
658 extern void iwl_hw_txq_ctx_stop(struct iwl_priv *priv);
659 extern int iwl_hw_nic_reset(struct iwl_priv *priv);
660 extern int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *tfd,
661 dma_addr_t addr, u16 len);
662 extern int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq);
663 extern int iwl_hw_get_temperature(struct iwl_priv *priv);
664 extern int iwl_hw_tx_queue_init(struct iwl_priv *priv,
665 struct iwl_tx_queue *txq);
666 extern unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
667 struct iwl_frame *frame, u8 rate);
668 extern int iwl_hw_get_rx_read(struct iwl_priv *priv);
669 extern void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv,
671 struct ieee80211_tx_control *ctrl,
672 struct ieee80211_hdr *hdr,
673 int sta_id, int tx_id);
674 extern int iwl_hw_reg_send_txpower(struct iwl_priv *priv);
675 extern int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power);
676 extern void iwl_hw_rx_statistics(struct iwl_priv *priv,
677 struct iwl_rx_mem_buffer *rxb);
678 extern void iwl_disable_events(struct iwl_priv *priv);
679 extern int iwl4965_get_temperature(const struct iwl_priv *priv);
682 * iwl_hw_find_station - Find station id for a given BSSID
683 * @bssid: MAC address of station ID to find
685 * NOTE: This should not be hardware specific but the code has
686 * not yet been merged into a single common layer for managing the
689 extern u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *bssid);
691 extern int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel);
693 extern int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);