Add rt2x00-mac80211 snapshot (#1916)
[openwrt.git] / package / rt2x00 / src / rt2x00.h
1 /*
2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 /*
22 Module: rt2x00
23 Abstract: rt2x00 global information.
24 Supported chipsets: RT2460, RT2560, RT2570,
25 rt2561, rt2561s, rt2661, rt2571W & rt2671.
26 */
27
28 #ifndef RT2X00_H
29 #define RT2X00_H
30
31 #include <linux/bitops.h>
32 #include <linux/skbuff.h>
33 #include <linux/workqueue.h>
34
35 #include <net/mac80211.h>
36
37 #include "rt2x00lib.h"
38 #include "rt2x00debug.h"
39
40 /*
41 * Module information.
42 */
43 #ifndef DRV_NAME
44 #define DRV_NAME "rt2x00"
45 #endif /* DRV_NAME */
46 #define DRV_VERSION "2.0.1"
47 #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
48
49 /*
50 * Debug definitions.
51 * Debug output has to be enabled during compile time.
52 */
53 #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
54 printk(__kernlvl "%s -> %s: %s - " __msg, \
55 wiphy_name(rt2x00dev->hw->wiphy), \
56 __FUNCTION__, __lvl, ##__args)
57
58 #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
59 printk(__kernlvl "%s -> %s: %s - " __msg, \
60 DRV_NAME, __FUNCTION__, __lvl, ##__args)
61
62 #ifdef CONFIG_RT2X00_DEBUG
63 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
64 DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
65 #else /* CONFIG_RT2X00_DEBUG */
66 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
67 do { } while (0)
68 #endif /* CONFIG_RT2X00_DEBUG */
69
70 /*
71 * Various debug levels.
72 * The debug levels PANIC and ERROR both indicate serious problems,
73 * for this reason they should never be ignored.
74 * The special ERROR_PROBE message is for messages that are generated
75 * when the rt2x00_dev is not yet initialized.
76 */
77 #define PANIC(__dev, __msg, __args...) \
78 DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
79 #define ERROR(__dev, __msg, __args...) \
80 DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
81 #define ERROR_PROBE(__msg, __args...) \
82 DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
83 #define WARNING(__dev, __msg, __args...) \
84 DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
85 #define NOTICE(__dev, __msg, __args...) \
86 DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
87 #define INFO(__dev, __msg, __args...) \
88 DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
89 #define DEBUG(__dev, __msg, __args...) \
90 DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
91 #define EEPROM(__dev, __msg, __args...) \
92 DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
93
94 /*
95 * Ring sizes.
96 * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes.
97 * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings.
98 * MGMT_FRAME_SIZE is used for the BEACON ring.
99 */
100 #define DATA_FRAME_SIZE 2432
101 #define MGMT_FRAME_SIZE 256
102
103 /*
104 * Number of entries in a packet ring.
105 */
106 #define RX_ENTRIES 12
107 #define TX_ENTRIES 12
108 #define ATIM_ENTRIES 1
109 #define BEACON_ENTRIES 1
110
111 /*
112 * Standard timing and size defines.
113 */
114 #define ACK_SIZE 14
115 #define IEEE80211_HEADER 24
116 #define PLCP 48
117 #define BEACON 100
118 #define PREAMBLE 144
119 #define SHORT_PREAMBLE 72
120 #define SLOT_TIME 20
121 #define SHORT_SLOT_TIME 9
122 #define SIFS 10
123 #define PIFS ( SIFS + SLOT_TIME )
124 #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
125 #define DIFS ( PIFS + SLOT_TIME )
126 #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
127 #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
128
129 /*
130 * IEEE802.11 header defines
131 */
132 #define is_rts_frame(__fc) \
133 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
134 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS)) )
135 #define is_cts_frame(__fc) \
136 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
137 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS)) )
138 #define is_probe_resp(__fc) \
139 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) && \
140 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)) )
141
142 /*
143 * Interval defines
144 */
145 #define LINK_TUNE_INTERVAL ( 1 * HZ )
146 #define RFKILL_POLL_INTERVAL ( HZ / 4 )
147
148 /*
149 * TX result flags.
150 */
151 enum TX_STATUS {
152 TX_SUCCESS = 0,
153 TX_SUCCESS_RETRY = 1,
154 TX_FAIL_RETRY = 2,
155 TX_FAIL_INVALID = 3,
156 TX_FAIL_OTHER = 4,
157 };
158
159 /*
160 * Antenna values
161 */
162 enum antenna {
163 ANTENNA_DIVERSITY = 0,
164 ANTENNA_A = 1,
165 ANTENNA_B = 2,
166 };
167
168 /*
169 * Led mode values.
170 */
171 enum led_mode {
172 LED_MODE_DEFAULT = 0,
173 LED_MODE_TXRX_ACTIVITY = 1,
174 LED_MODE_SIGNAL_STRENGTH = 2,
175 LED_MODE_ASUS = 3,
176 LED_MODE_ALPHA = 4,
177 };
178
179 /*
180 * Device states
181 */
182 enum dev_state {
183 STATE_DEEP_SLEEP = 0,
184 STATE_SLEEP = 1,
185 STATE_STANDBY = 2,
186 STATE_AWAKE = 3,
187
188 /*
189 * Additional device states, these values are
190 * not strict since they are not directly passed
191 * into the device.
192 */
193 STATE_RADIO_ON,
194 STATE_RADIO_OFF,
195 STATE_RADIO_RX_ON,
196 STATE_RADIO_RX_OFF,
197 };
198
199 /*
200 * IFS backoff values
201 */
202 enum ifs {
203 IFS_BACKOFF = 0,
204 IFS_SIFS = 1,
205 IFS_NEW_BACKOFF = 2,
206 IFS_NONE = 3,
207 };
208
209 /*
210 * Cipher types for hardware encryption
211 */
212 enum cipher {
213 CIPHER_NONE = 0,
214 CIPHER_WEP64 = 1,
215 CIPHER_WEP128 = 2,
216 CIPHER_TKIP = 3,
217 CIPHER_AES = 4,
218 /*
219 * The following fields were added by rt61pci and rt73usb.
220 */
221 CIPHER_CKIP64 = 5,
222 CIPHER_CKIP128 = 6,
223 CIPHER_TKIP_NO_MIC = 7,
224 };
225
226 /*
227 * Register handlers.
228 * We store the position of a register field inside a field structure,
229 * This will simplify the process of setting and reading a certain field
230 * inside the register while making sure the process remains byte order safe.
231 */
232 struct rt2x00_field8 {
233 u8 bit_offset;
234 u8 bit_mask;
235 };
236
237 struct rt2x00_field16 {
238 u16 bit_offset;
239 u16 bit_mask;
240 };
241
242 struct rt2x00_field32 {
243 u32 bit_offset;
244 u32 bit_mask;
245 };
246
247 /*
248 * Power of two check from Linus Torvalds,
249 * this will check if the mask that has been
250 * given contains and contiguous set of bits.
251 */
252 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
253 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
254 #define is_valid_mask(x) is_power_of_two(1 + (x) + low_bit_mask(x))
255
256 #define FIELD8(__mask) \
257 ({ \
258 BUILD_BUG_ON(!(__mask) || \
259 !is_valid_mask(__mask) || \
260 (__mask) != (u8)(__mask)); \
261 (struct rt2x00_field8) { \
262 __ffs(__mask), (__mask) \
263 }; \
264 })
265
266 #define FIELD16(__mask) \
267 ({ \
268 BUILD_BUG_ON(!(__mask) || \
269 !is_valid_mask(__mask) || \
270 (__mask) != (u16)(__mask));\
271 (struct rt2x00_field16) { \
272 __ffs(__mask), (__mask) \
273 }; \
274 })
275
276 #define FIELD32(__mask) \
277 ({ \
278 BUILD_BUG_ON(!(__mask) || \
279 !is_valid_mask(__mask) || \
280 (__mask) != (u32)(__mask));\
281 (struct rt2x00_field32) { \
282 __ffs(__mask), (__mask) \
283 }; \
284 })
285
286 static inline void rt2x00_set_field32(u32 *reg,
287 const struct rt2x00_field32 field, const u32 value)
288 {
289 *reg &= ~(field.bit_mask);
290 *reg |= (value << field.bit_offset) & field.bit_mask;
291 }
292
293 static inline u32 rt2x00_get_field32(const u32 reg,
294 const struct rt2x00_field32 field)
295 {
296 return (reg & field.bit_mask) >> field.bit_offset;
297 }
298
299 static inline void rt2x00_set_field16(u16 *reg,
300 const struct rt2x00_field16 field, const u16 value)
301 {
302 *reg &= ~(field.bit_mask);
303 *reg |= (value << field.bit_offset) & field.bit_mask;
304 }
305
306 static inline u16 rt2x00_get_field16(const u16 reg,
307 const struct rt2x00_field16 field)
308 {
309 return (reg & field.bit_mask) >> field.bit_offset;
310 }
311
312 static inline void rt2x00_set_field8(u8 *reg,
313 const struct rt2x00_field8 field, const u8 value)
314 {
315 *reg &= ~(field.bit_mask);
316 *reg |= (value << field.bit_offset) & field.bit_mask;
317 }
318
319 static inline u8 rt2x00_get_field8(const u8 reg,
320 const struct rt2x00_field8 field)
321 {
322 return (reg & field.bit_mask) >> field.bit_offset;
323 }
324
325 /*
326 * Chipset identification
327 * The chipset on the device is composed of a RT and RF chip.
328 * The chipset combination is important for determining device capabilities.
329 */
330 struct rt2x00_chip {
331 u16 rt;
332 #define RT2460 0x0101
333 #define RT2560 0x0201
334 #define RT2570 0x1201
335 #define RT2561 0x0301
336 #define RT2561s 0x0302
337 #define RT2661 0x0401
338 #define RT2571 0x1300
339
340 u16 rf;
341 u32 rev;
342 };
343
344 /*
345 * data_desc
346 * Each data entry also contains a descriptor which is used by the
347 * device to determine what should be done with the packet and
348 * what the current status is.
349 * This structure is greatly simplified, but the descriptors
350 * are basically a list of little endian 32 bit values.
351 * Make the array by default 1 word big, this will allow us
352 * to use sizeof() correctly.
353 */
354 struct data_desc {
355 __le32 word[1];
356 };
357
358 /*
359 * data_entry_desc
360 * Summary of information that should be written into the
361 * descriptor for sending a TX frame.
362 */
363 struct data_entry_desc {
364 /*
365 * PLCP values.
366 */
367 u16 length_high;
368 u16 length_low;
369 u16 signal;
370 u16 service;
371
372 int queue;
373 int ifs;
374 };
375
376 /*
377 * data_entry
378 * The data ring is a list of data entries.
379 * Each entry holds a reference to the descriptor
380 * and the data buffer. For TX rings the reference to the
381 * sk_buff of the packet being transmitted is also stored here.
382 */
383 struct data_entry {
384 /*
385 * Status flags
386 */
387 unsigned long flags;
388 #define ENTRY_OWNER_NIC 1
389 #define ENTRY_TXDONE 2
390 #define ENTRY_TXD_RTS_FRAME 3
391 #define ENTRY_TXD_OFDM_RATE 4
392 #define ENTRY_TXD_MORE_FRAG 5
393 #define ENTRY_TXD_REQ_TIMESTAMP 6
394 #define ENTRY_TXD_REQ_ACK 7
395 #define ENTRY_TXD_NEW_SEQ 8
396
397 /*
398 * Ring we belong to.
399 */
400 struct data_ring *ring;
401
402 /*
403 * sk_buff for the packet which is being transmitted
404 * in this entry (Only used with TX related rings).
405 */
406 struct sk_buff *skb;
407
408 /*
409 * Store a ieee80211_tx_status structure in each
410 * ring entry, this will optimize the txdone
411 * handler.
412 */
413 struct ieee80211_tx_status tx_status;
414
415 /*
416 * private pointer specific to driver.
417 */
418 void *priv;
419
420 /*
421 * Data address for this entry.
422 */
423 void *data_addr;
424 dma_addr_t data_dma;
425 };
426
427 /*
428 * data_ring
429 * Data rings are used by the device to send and receive packets.
430 * The data_addr is the base address of the data memory.
431 * To determine at which point in the ring we are,
432 * have to use the rt2x00_ring_index_*() functions.
433 */
434 struct data_ring {
435 /*
436 * Pointer to main rt2x00dev structure where this
437 * ring belongs to.
438 */
439 struct rt2x00_dev *rt2x00dev;
440
441 /*
442 * Base address for the device specific data entries.
443 */
444 struct data_entry *entry;
445
446 /*
447 * TX queue statistic info.
448 */
449 struct ieee80211_tx_queue_stats_data stats;
450
451 /*
452 * TX Queue parameters.
453 */
454 struct ieee80211_tx_queue_params tx_params;
455
456 /*
457 * Base address for data ring.
458 */
459 dma_addr_t data_dma;
460 void *data_addr;
461
462 /*
463 * Index variables.
464 */
465 u16 index;
466 u16 index_done;
467
468 /*
469 * Size of packet and descriptor in bytes.
470 */
471 u16 data_size;
472 u16 desc_size;
473 };
474
475 /*
476 * Handlers to determine the address of the current device specific
477 * data entry, where either index or index_done points to.
478 */
479 static inline struct data_entry* rt2x00_get_data_entry(
480 struct data_ring *ring)
481 {
482 return &ring->entry[ring->index];
483 }
484
485 static inline struct data_entry* rt2x00_get_data_entry_done(
486 struct data_ring *ring)
487 {
488 return &ring->entry[ring->index_done];
489 }
490
491 /*
492 * Total ring memory
493 */
494 static inline int rt2x00_get_ring_size(struct data_ring *ring)
495 {
496 return ring->stats.limit * (ring->desc_size + ring->data_size);
497 }
498
499 /*
500 * Ring index manipulation functions.
501 */
502 static inline void rt2x00_ring_index_inc(struct data_ring *ring)
503 {
504 ring->index++;
505 if (ring->index >= ring->stats.limit)
506 ring->index = 0;
507 ring->stats.len++;
508 }
509
510 static inline void rt2x00_ring_index_done_inc(struct data_ring *ring)
511 {
512 ring->index_done++;
513 if (ring->index_done >= ring->stats.limit)
514 ring->index_done = 0;
515 ring->stats.len--;
516 ring->stats.count++;
517 }
518
519 static inline void rt2x00_ring_index_clear(struct data_ring *ring)
520 {
521 ring->index = 0;
522 ring->index_done = 0;
523 ring->stats.len = 0;
524 ring->stats.count = 0;
525 }
526
527 static inline int rt2x00_ring_empty(struct data_ring *ring)
528 {
529 return ring->stats.len == 0;
530 }
531
532 static inline int rt2x00_ring_full(struct data_ring *ring)
533 {
534 return ring->stats.len == ring->stats.limit;
535 }
536
537 static inline int rt2x00_ring_free(struct data_ring *ring)
538 {
539 if (ring->index_done >= ring->index)
540 return ring->index_done - ring->index;
541 return ring->stats.len - (ring->index - ring->index_done);
542 }
543
544 /*
545 * TX/RX Descriptor access functions.
546 */
547 static inline void rt2x00_desc_read(struct data_desc *desc,
548 const u8 word, u32 *value)
549 {
550 *value = le32_to_cpu(desc->word[word]);
551 }
552
553 static inline void rt2x00_desc_write(struct data_desc *desc,
554 const u8 word, const u32 value)
555 {
556 desc->word[word] = cpu_to_le32(value);
557 }
558
559 /*
560 * To optimize the quality of the link we need to store
561 * the quality of received frames and periodically
562 * optimize the link.
563 */
564 struct link {
565 /*
566 * Link tuner counter
567 * The number of times the link has been tuned
568 * since the radio has been switched on.
569 */
570 u32 count;
571
572 /*
573 * RSSI statistics.
574 */
575 u32 count_rssi;
576 u32 total_rssi;
577
578 /*
579 * Misc statistics.
580 */
581 u32 curr_noise;
582 u32 false_cca;
583
584 /*
585 * Work structure for scheduling periodic link tuning.
586 */
587 struct delayed_work work;
588 };
589
590 /*
591 * Interface structure
592 * Configuration details about the current interface.
593 */
594 struct interface {
595 /*
596 * Interface identification. The value is assigned
597 * to us by the 80211 stack, and is used to request
598 * new beacons.
599 */
600 int id;
601
602 /*
603 * Current working type (IEEE80211_IF_TYPE_*).
604 * This excludes the type IEEE80211_IF_TYPE_MNTR
605 * since that is counted seperately in the monitor_count
606 * field.
607 */
608 int type;
609
610 /*
611 * BBSID of the AP to associate with.
612 */
613 u8 bssid[ETH_ALEN];
614
615 /*
616 * Store the promisc mode for the current interface.
617 * monitor mode always forces promisc mode to be enabled,
618 * so we need to store the promisc mode seperately.
619 */
620 short promisc;
621
622 /*
623 * Monitor mode count, the number of interfaces
624 * in monitor mode that that have been added.
625 */
626 short monitor_count;
627 };
628
629 static inline int is_interface_present(struct interface *intf)
630 {
631 return !!intf->id;
632 }
633
634 static inline int is_monitor_present(struct interface *intf)
635 {
636 return !!intf->monitor_count;
637 }
638
639 /*
640 * rt2x00lib callback functions.
641 */
642 struct rt2x00lib_ops {
643 /*
644 * Interrupt handlers.
645 */
646 irq_handler_t irq_handler;
647
648 /*
649 * Device init handlers.
650 */
651 int (*init_hw)(struct rt2x00_dev *rt2x00dev);
652 char* (*get_fw_name)(struct rt2x00_dev *rt2x00dev);
653 int (*load_firmware)(struct rt2x00_dev *rt2x00dev, void *data,
654 const size_t len);
655
656 /*
657 * Device initialization/deinitialization handlers.
658 */
659 int (*initialize)(struct rt2x00_dev *rt2x00dev);
660 void (*uninitialize)(struct rt2x00_dev *rt2x00dev);
661
662 /*
663 * Radio control handlers.
664 */
665 int (*set_device_state)(struct rt2x00_dev *rt2x00dev,
666 enum dev_state state);
667 int (*rfkill_poll)(struct rt2x00_dev *rt2x00dev);
668 void (*link_tuner)(struct rt2x00_dev *rt2x00dev, int rssi);
669
670 /*
671 * TX control handlers
672 */
673 void (*write_tx_desc)(struct rt2x00_dev *rt2x00dev,
674 struct data_entry *entry, struct data_desc *txd,
675 struct data_entry_desc *desc,
676 struct ieee80211_hdr *ieee80211hdr, unsigned int length,
677 struct ieee80211_tx_control *control);
678 int (*write_tx_data)(struct rt2x00_dev *rt2x00dev,
679 struct data_ring *ring, struct sk_buff *skb,
680 struct ieee80211_tx_control *control);
681 void (*kick_tx_queue)(struct rt2x00_dev *rt2x00dev, int queue);
682
683 /*
684 * Configuration handlers.
685 */
686 void (*config_type)(struct rt2x00_dev *rt2x00dev, const int type);
687 void (*config_phymode)(struct rt2x00_dev *rt2x00dev, const int phy);
688 void (*config_channel)(struct rt2x00_dev *rt2x00dev, const int value,
689 const int channel, const int txpower);
690 void (*config_mac_addr)(struct rt2x00_dev *rt2x00dev, u8 *mac);
691 void (*config_bssid)(struct rt2x00_dev *rt2x00dev, u8 *bssid);
692 void (*config_promisc)(struct rt2x00_dev *rt2x00dev, const int promisc);
693 void (*config_txpower)(struct rt2x00_dev *rt2x00dev, const int txpower);
694 void (*config_antenna)(struct rt2x00_dev *rt2x00dev,
695 const int antenna_tx, const int antenna_rx);
696 void (*config_duration)(struct rt2x00_dev *rt2x00dev,
697 const int short_slot_time, const int beacon_int);
698 };
699
700 /*
701 * rt2x00 driver callback operation structure.
702 */
703 struct rt2x00_ops {
704 const char *name;
705 const unsigned int rxd_size;
706 const unsigned int txd_size;
707 const struct rt2x00lib_ops *lib;
708 const struct ieee80211_ops *hw;
709 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
710 const struct rt2x00debug *debugfs;
711 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
712 };
713
714 /*
715 * rt2x00 device structure.
716 */
717 struct rt2x00_dev {
718 /*
719 * Device structure.
720 * The structure stored in here depends on the
721 * system bus (PCI or USB).
722 * When accessing this variable, the rt2x00dev_{pci,usb}
723 * macro's should be used for correct typecasting.
724 */
725 void *dev;
726 struct device *device;
727 #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
728 #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
729
730 /*
731 * Callback functions.
732 */
733 const struct rt2x00_ops *ops;
734
735 /*
736 * IEEE80211 control structure.
737 */
738 struct ieee80211_hw *hw;
739 struct ieee80211_hw_mode *hwmodes;
740 unsigned int curr_hwmode;
741 #define HWMODE_B 0
742 #define HWMODE_G 1
743 #define HWMODE_A 2
744
745 /*
746 * rfkill structure for RF state switching support.
747 * This will only be compiled in when required.
748 */
749 #ifdef CONFIG_RT2X00_LIB_RFKILL
750 struct rfkill *rfkill;
751 struct delayed_work rfkill_work;
752 #endif /* CONFIG_RT2X00_LIB_RFKILL */
753
754 /*
755 * Device flags.
756 * In these flags the current status and some
757 * of the device capabilities are stored.
758 */
759 unsigned long flags;
760 #define DEVICE_ENABLED_RADIO 1
761 #define DEVICE_ENABLED_RADIO_HW 2
762 #define DEVICE_INITIALIZED 3
763 #define DEVICE_INITIALIZED_HW 4
764 #define FIRMWARE_REQUIRED 5
765 #define FIRMWARE_LOADED 6
766 #define FIRMWARE_FAILED 7
767 #define INTERFACE_ENABLED 8
768 #define INTERFACE_ENABLED_MONITOR 9
769 #define INTERFACE_ENABLED_PROMISC 10
770 #define DEVICE_SUPPORT_ATIM 11
771 #define DEVICE_SUPPORT_HW_BUTTON 12
772 #define CONFIG_FRAME_TYPE 13
773 #define CONFIG_RF_SEQUENCE 14
774 #define CONFIG_EXTERNAL_LNA 15
775 #define CONFIG_EXTERNAL_LNA_A 16
776 #define CONFIG_EXTERNAL_LNA_BG 17
777 #define CONFIG_DOUBLE_ANTENNA 18
778 #define CONFIG_DISABLE_LINK_TUNING 19
779
780 /*
781 * Chipset identification.
782 */
783 struct rt2x00_chip chip;
784
785 /*
786 * hw capability specifications.
787 */
788 struct hw_mode_spec spec;
789
790 /*
791 * Base address of device registers (PCI devices only).
792 */
793 void __iomem *csr_addr;
794
795 /*
796 * If enabled, the debugfs interface structures
797 * required for deregistration of debugfs.
798 */
799 const struct rt2x00debug_intf *debugfs_intf;
800
801 /*
802 * Queue for deferred work.
803 */
804 struct workqueue_struct *workqueue;
805
806 /*
807 * Interface configuration.
808 */
809 struct interface interface;
810
811 /*
812 * Link quality
813 */
814 struct link link;
815
816 /*
817 * EEPROM data.
818 */
819 __le16 *eeprom;
820
821 /*
822 * Active RF register values.
823 * These are stored here for easier working
824 * with the rf registers.
825 */
826 u32 rf1;
827 u32 rf2;
828 u32 rf3;
829 u32 rf4;
830
831 /*
832 * Current TX power value.
833 */
834 u16 tx_power;
835
836 /*
837 * LED register (for rt61pci & rt73usb).
838 */
839 u16 led_reg;
840
841 /*
842 * Led mode (LED_MODE_*)
843 */
844 u8 led_mode;
845
846 /*
847 * EEPROM bus width (PCI devices only).
848 */
849 u8 eeprom_width;
850
851 /*
852 * Frequency offset (for rt61pci & rt73usb).
853 */
854 u8 freq_offset;
855
856 /*
857 * Low level statistics which will have
858 * to be kept up to date while device is running.
859 */
860 struct ieee80211_low_level_stats low_level_stats;
861
862 /*
863 * RX configuration information.
864 */
865 struct ieee80211_rx_status rx_status;
866
867 /*
868 * Data ring arrays for RX, TX and Beacon.
869 * The Beacon array also contains the Atim ring
870 * if that is supported by the device.
871 */
872 struct data_ring *rx;
873 struct data_ring *tx;
874 struct data_ring *bcn;
875 };
876
877 static inline struct data_ring* rt2x00_get_ring(
878 struct rt2x00_dev *rt2x00dev, const unsigned int queue)
879 {
880 int atim = test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags);
881
882 /*
883 * Check if the rings have been allocated.
884 */
885 if (!rt2x00dev->tx || !rt2x00dev->bcn)
886 return NULL;
887
888 /*
889 * Check if we are requesting a reqular TX ring,
890 * or if we are requesting a Beacon or Atim ring.
891 * For Atim rings, we should check if it is supported.
892 */
893 if (queue < rt2x00dev->hw->queues)
894 return &rt2x00dev->tx[queue];
895 else if (queue == IEEE80211_TX_QUEUE_BEACON)
896 return &rt2x00dev->bcn[0];
897 else if (queue == IEEE80211_TX_QUEUE_AFTER_BEACON && atim)
898 return &rt2x00dev->bcn[1];
899
900 return NULL;
901 }
902
903 /*
904 * For-each loop for the ring array.
905 * Since the all rings are allocated as a single array,
906 * we can start at the rx pointer and move forward to the tx rings.
907 * The 1 + Atim check will assure that the address directly after
908 * the ring array is obtained and the for-each loop exits correctly.
909 */
910 #define ring_for_each(__dev, __entry) \
911 for ((__entry) = (__dev)->rx; \
912 (__entry) != &(__dev)->bcn[1 + \
913 test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags)]; \
914 (__entry)++)
915
916 #define txring_for_each(__dev, __entry) \
917 for ((__entry) = (__dev)->tx; (__entry) != (__dev)->bcn; (__entry)++)
918
919 /*
920 * EEPROM access.
921 * The EEPROM is being accessed by word index.
922 */
923 static inline void* rt2x00_eeprom_addr(const struct rt2x00_dev *rt2x00dev,
924 const u8 word)
925 {
926 return (void*)&rt2x00dev->eeprom[word];
927 }
928
929 static inline void rt2x00_eeprom_read(const struct rt2x00_dev *rt2x00dev,
930 const u8 word, u16 *data)
931 {
932 *data = le16_to_cpu(rt2x00dev->eeprom[word]);
933 }
934
935 static inline void rt2x00_eeprom_write(const struct rt2x00_dev *rt2x00dev,
936 const u8 word, u16 data)
937 {
938 rt2x00dev->eeprom[word] = cpu_to_le16(data);
939 }
940
941 /*
942 * Link tuning handlers
943 */
944 static inline void rt2x00_start_link_tune(struct rt2x00_dev *rt2x00dev)
945 {
946 rt2x00dev->link.count = 0;
947 rt2x00dev->link.count_rssi = 0;
948 rt2x00dev->link.total_rssi = 0;
949 rt2x00dev->link.curr_noise = 0;
950
951 queue_delayed_work(rt2x00dev->workqueue,
952 &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
953 }
954
955 static inline void rt2x00_stop_link_tune(struct rt2x00_dev *rt2x00dev)
956 {
957 if (work_pending(&rt2x00dev->link.work.work))
958 cancel_rearming_delayed_workqueue(
959 rt2x00dev->workqueue, &rt2x00dev->link.work);
960 }
961
962 static inline void rt2x00_update_link_rssi(struct link *link, u32 rssi)
963 {
964 link->count_rssi++;
965 link->total_rssi += rssi;
966 }
967
968 static inline u32 rt2x00_get_link_rssi(struct link *link)
969 {
970 u32 average = 0;
971
972 if (link->count_rssi && link->total_rssi)
973 average = link->total_rssi / link->count_rssi;
974
975 link->count_rssi = 0;
976 link->total_rssi = 0;
977
978 return average;
979 }
980
981 /*
982 * Chipset handlers
983 */
984 static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
985 const u16 rt, const u16 rf, const u32 rev)
986 {
987 INFO(rt2x00dev,
988 "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
989 rt, rf, rev);
990
991 rt2x00dev->chip.rt = rt;
992 rt2x00dev->chip.rf = rf;
993 rt2x00dev->chip.rev = rev;
994 }
995
996 static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
997 {
998 return (chipset->rt == chip);
999 }
1000
1001 static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
1002 {
1003 return (chipset->rf == chip);
1004 }
1005
1006 static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
1007 {
1008 return chipset->rev;
1009 }
1010
1011 /*
1012 * Device specific rate value.
1013 * We will have to create the device specific rate value
1014 * passed to the ieee80211 kernel. We need to make it a consist of
1015 * multiple fields because we want to store more then 1 device specific
1016 * values inside the value.
1017 * 1 - rate, stored as 100 kbit/s.
1018 * 2 - preamble, short_preamble enabled flag.
1019 * 3 - MASK_RATE, which rates are enabled in this mode, this mask
1020 * corresponds with the TX register format for the current device.
1021 * 4 - plcp, 802.11b rates are device specific,
1022 * 802.11g rates are set according to the ieee802.11a-1999 p.14.
1023 * The bit to enable preamble is set in a seperate define.
1024 */
1025 #define DEV_RATE FIELD32(0x000007ff)
1026 #define DEV_PREAMBLE FIELD32(0x00000800)
1027 #define DEV_RATEMASK FIELD32(0x00fff000)
1028 #define DEV_PLCP FIELD32(0xff000000)
1029
1030 /*
1031 * Bitmask for MASK_RATE
1032 */
1033 #define DEV_RATE_1MB 0x00000001
1034 #define DEV_RATE_2MB 0x00000002
1035 #define DEV_RATE_5_5MB 0x00000004
1036 #define DEV_RATE_11MB 0x00000008
1037 #define DEV_RATE_6MB 0x00000010
1038 #define DEV_RATE_9MB 0x00000020
1039 #define DEV_RATE_12MB 0x00000040
1040 #define DEV_RATE_18MB 0x00000080
1041 #define DEV_RATE_24MB 0x00000100
1042 #define DEV_RATE_36MB 0x00000200
1043 #define DEV_RATE_48MB 0x00000400
1044 #define DEV_RATE_54MB 0x00000800
1045
1046 /*
1047 * Bitmask groups of bitrates
1048 */
1049 #define DEV_BASIC_RATE \
1050 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB | \
1051 DEV_RATE_6MB | DEV_RATE_12MB | DEV_RATE_24MB )
1052
1053 #define DEV_CCK_RATE \
1054 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB )
1055
1056 #define DEV_OFDM_RATE \
1057 ( DEV_RATE_6MB | DEV_RATE_9MB | DEV_RATE_12MB | DEV_RATE_18MB | \
1058 DEV_RATE_24MB | DEV_RATE_36MB | DEV_RATE_48MB | DEV_RATE_54MB )
1059
1060 /*
1061 * Macro's to set and get specific fields from the device specific val and val2
1062 * fields inside the ieee80211_rate entry.
1063 */
1064 #define DEVICE_SET_RATE_FIELD(__value, __mask) \
1065 (int)( ((__value) << DEV_##__mask.bit_offset) & DEV_##__mask.bit_mask )
1066
1067 #define DEVICE_GET_RATE_FIELD(__value, __mask) \
1068 (int)( ((__value) & DEV_##__mask.bit_mask) >> DEV_##__mask.bit_offset )
1069
1070 /*
1071 * Duration calculations
1072 * The rate variable passed is: 100kbs.
1073 * To convert from bytes to bits we multiply size with 8,
1074 * then the size is multiplied with 10 to make the
1075 * real rate -> rate argument correction.
1076 */
1077 static inline u16 get_duration(const unsigned int size, const u8 rate)
1078 {
1079 return ((size * 8 * 10) / rate);
1080 }
1081
1082 static inline u16 get_duration_res(const unsigned int size, const u8 rate)
1083 {
1084 return ((size * 8 * 10) % rate);
1085 }
1086
1087 #endif /* RT2X00_H */
This page took 0.092529 seconds and 5 git commands to generate.