33 #include <linux/netdevice.h> 34 #include <linux/wireless.h> 36 #include <rtnet_port.h> 44 #define DRV_NAME "rt2x00" 45 #define DRV_VERSION "0.1" 46 #define DRV_AUTHOR "Daniel Gregorek <dxg@gmx.de>" 55 #ifdef CONFIG_RT2X00_DEBUG 56 extern int rt2x00_debug_level;
57 #define DEBUG_PRINTK(__message...) do{ rtdm_printk(__message); }while(0) 59 #define DEBUG_PRINTK(__message...) do{ }while(0) 67 #define PANIC(__message,__args...) rtdm_printk(KERN_PANIC DRV_NAME "->%s: Panic - " __message,__FUNCTION__,##__args); 68 #define ERROR(__message,__args...) rtdm_printk(KERN_ERR DRV_NAME "->%s: Error - " __message,__FUNCTION__,##__args); 69 #define WARNING(__message,__args...) rtdm_printk(KERN_WARNING DRV_NAME "->%s: Warning - " __message,__FUNCTION__,##__args); 70 #define NOTICE(__message,__args...) rtdm_printk(KERN_NOTICE DRV_NAME "->%s: Notice - " __message,__FUNCTION__,##__args); 71 #define INFO(__message,__args...) rtdm_printk(KERN_INFO DRV_NAME "->%s: Info - " __message,__FUNCTION__,##__args); 72 #define DEBUG(__message,__args...) DEBUG_PRINTK(KERN_DEBUG DRV_NAME "->%s: Debug - " __message,__FUNCTION__,##__args); 87 #define DATA_FRAME_SIZE 2432 88 #define MGMT_FRAME_SIZE 256 93 #define XMIT_IFS_SIFS 0x0001 94 #define XMIT_IFS_BACKOFF 0x0002 95 #define XMIT_IFS_NEW_BACKOFF 0x0004 96 #define XMIT_IFS_NONE 0x0008 97 #define XMIT_NEW_SEQUENCE 0x0010 98 #define XMIT_ACK 0x0020 99 #define XMIT_TIMESTAMP 0x0040 100 #define XMIT_RTS 0x0080 101 #define XMIT_OFDM 0x0100 102 #define XMIT_LONG_RETRY 0x0200 103 #define XMIT_MORE_FRAGS 0x0400 104 #define XMIT_SHORT_PREAMBLE 0x0800 105 #define XMIT_START 0x1000 110 #define STATS_TX_RESULT 0x01 111 #define STATS_TX_RETRY_COUNT 0x02 112 #define STATS_RX_CRC 0x10 113 #define STATS_RX_PHYSICAL 0x20 114 #define STATS_RX_QUALITY 0x40 115 #define STATS_RX_DROP 0x80 121 #define TX_SUCCESS_RETRY 1 122 #define TX_FAIL_RETRY 2 123 #define TX_FAIL_INVALID 3 124 #define TX_FAIL_OTHER 4 129 #define CHANNEL_OFDM 0x01 130 #define CHANNEL_UNII_LOW 0x02 131 #define CHANNEL_HIPERLAN2 0x04 132 #define CHANNEL_UNII_HIGH 0x08 134 #define CHANNEL_OFDM_MIN 1 135 #define CHANNEL_OFDM_MAX 14 136 #define CHANNEL_UNII_LOW_MIN 36 137 #define CHANNEL_UNII_LOW_MAX 64 138 #define CHANNEL_HIPERLAN2_MIN 100 139 #define CHANNEL_HIPERLAN2_MAX 140 140 #define CHANNEL_UNII_HIGH_MIN 149 141 #define CHANNEL_UNII_HIGH_MAX 161 146 static struct _rt2x00_capabilities{
149 } __attribute__ ((packed)) capabilities = {
154 3, 12, 25, 50, 75, 100,
162 12, 18, 24, 36, 48, 72, 96, 108,
166 struct _rt2x00_config{
169 #define CONFIG_DROP_BCAST 0x0001 170 #define CONFIG_DROP_MCAST 0x0002 171 #define CONFIG_AUTORESP 0x0004 204 #define UPDATE_ALL_CONFIG 0xffff 205 #define UPDATE_BSSID 0x0001 206 #define UPDATE_PACKET_FILTER 0x0002 207 #define UPDATE_CHANNEL 0x0004 208 #define UPDATE_BITRATE 0x0008 209 #define UPDATE_RETRY 0x0010 210 #define UPDATE_TXPOWER 0x0020 211 #define UPDATE_ANTENNA 0x0040 212 #define UPDATE_DURATION 0x0080 213 #define UPDATE_PREAMBLE 0x0100 214 #define UPDATE_AUTORESP 0x0200 215 #define UPDATE_LED_STATUS 0x0400 216 #define UPDATE_BBPSENS 0x0800 218 } __attribute__ ((packed));
220 struct _rt2x00_core {
227 #define DEVICE_ENABLED 0 228 #define DEVICE_AWAKE 1 229 #define DEVICE_RADIO_ON 2 230 #define DEVICE_CONFIG_UPDATE 3 235 struct _rt2x00_dev_handler *handler;
240 struct rtnet_device *rtnet_dev;
245 struct rtwlan_device *rtwlan_dev;
250 struct _rt2x00_config config;
254 } __attribute__ ((packed));
259 struct _rt2x00_dev_handler {
264 struct module *dev_module;
269 int (*dev_probe)(
struct _rt2x00_core *core,
void *priv);
270 int (*dev_remove)(
struct _rt2x00_core *core);
275 int (*dev_radio_on)(
struct _rt2x00_core *core);
276 int (*dev_radio_off)(
struct _rt2x00_core *core);
281 int (*dev_update_config)(
struct _rt2x00_core *core, u16 update_flags);
286 int (*dev_xmit_packet)(
struct _rt2x00_core *core,
struct rtskb *rtskb, u16 rate, u16 xmit_flags);
291 int (*dev_register_access)(
struct _rt2x00_core * core,
int request, u32 address, u32 * value);
293 } __attribute__ ((packed));
295 static inline void * rt2x00_priv(
const struct _rt2x00_core *core) {
307 #define IEEE80211_HEADER 24 310 get_duration(
const unsigned int size,
const u8 rate) {
312 return ((size * 8 * 2) / rate);
316 get_duration_res(
const unsigned int size,
const u8 rate) {
318 return ((size * 8 * 2) % rate);
322 get_preamble(
const struct _rt2x00_config *config) {
334 struct _rt2x00_field16{
337 } __attribute__ ((packed));
339 struct _rt2x00_field32{
342 } __attribute__ ((packed));
344 #define FIELD16(__offset, __mask) ( (struct _rt2x00_field16) { (__offset), (__mask) } ) 345 #define FIELD32(__offset, __mask) ( (struct _rt2x00_field32) { (__offset), (__mask) } ) 348 rt2x00_set_field32(u32 *reg,
const struct _rt2x00_field32 field,
const u32 value) {
350 *reg &= cpu_to_le32(~(field.bit_mask));
351 *reg |= cpu_to_le32((value << field.bit_offset) & field.bit_mask);
355 rt2x00_set_field32_nb(u32 *reg,
const struct _rt2x00_field32 field,
const u32 value) {
357 *reg &= ~(field.bit_mask);
358 *reg |= (value << field.bit_offset) & field.bit_mask;
362 rt2x00_get_field32(
const u32 reg,
const struct _rt2x00_field32 field) {
364 return (le32_to_cpu(reg) & field.bit_mask) >> field.bit_offset;
368 rt2x00_get_field32_nb(
const u32 reg,
const struct _rt2x00_field32 field) {
370 return (reg & field.bit_mask) >> field.bit_offset;
374 rt2x00_set_field16(u16 *reg,
const struct _rt2x00_field16 field,
const u16 value) {
376 *reg &= cpu_to_le16(~(field.bit_mask));
377 *reg |= cpu_to_le16((value << field.bit_offset) & field.bit_mask);
381 rt2x00_set_field16_nb(u16 *reg,
const struct _rt2x00_field16 field,
const u16 value) {
383 *reg &= ~(field.bit_mask);
384 *reg |= (value << field.bit_offset) & field.bit_mask;
388 rt2x00_get_field16(
const u16 reg,
const struct _rt2x00_field16 field) {
390 return (le16_to_cpu(reg) & field.bit_mask) >> field.bit_offset;
394 rt2x00_get_field16_nb(
const u16 reg,
const struct _rt2x00_field16 field) {
396 return (reg & field.bit_mask) >> field.bit_offset;
407 }__attribute__ ((packed));
417 } __attribute__ ((packed));
425 set_chip(
struct _rt2x00_chip *chipset,
const u16 rt,
const u16 rf) {
427 INFO(
"Chipset detected - rt: %04x, rf: %04x.\n", rt, rf);
430 chipset->rf = rf | (chipset->rt & 0xff00);
434 rt2x00_rt(
const struct _rt2x00_chip *chipset,
const u16 chip) {
436 return (chipset->rt == chip);
440 rt2x00_rf(
const struct _rt2x00_chip *chipset,
const u16 chip) {
442 return (chipset->rf == chip);
446 rt2x00_get_rf(
const struct _rt2x00_chip *chipset) {
471 struct _rt2x00_core *core;
499 } __attribute__ ((packed));
506 #define ATIM_ENTRIES 1 507 #define PRIO_ENTRIES 2 508 #define BEACON_ENTRIES 1 513 static inline void rt2x00_init_ring(
514 struct _rt2x00_core *core,
515 struct _data_ring *ring,
517 const u16 max_entries,
518 const u16 entry_size,
519 const u16 desc_size) {
523 ring->index_done = 0;
524 ring->ring_type = ring_type;
525 ring->max_entries = max_entries;
526 ring->entry_size = entry_size;
527 ring->desc_size = desc_size;
528 ring->mem_size = ring->max_entries * (ring->desc_size + ring->entry_size);
531 static inline void rt2x00_deinit_ring(
struct _data_ring *ring) {
535 ring->index_done = 0;
537 ring->max_entries = 0;
538 ring->entry_size = 0;
546 static inline void rt2x00_ring_index_inc(
struct _data_ring *ring) {
548 ring->index = (++ring->index < ring->max_entries) ? ring->index : 0;
551 static inline void rt2x00_ring_index_done_inc(
struct _data_ring *ring) {
553 ring->index_done = (++ring->index_done < ring->max_entries) ? ring->index_done : 0;
556 static inline void rt2x00_ring_clear_index(
struct _data_ring *ring) {
559 ring->index_done = 0;
562 static inline u8 rt2x00_ring_empty(
struct _data_ring *ring) {
564 return ring->index_done == ring->index;
567 static inline u8 rt2x00_ring_free_entries(
struct _data_ring *ring) {
569 if(ring->index >= ring->index_done)
570 return ring->max_entries - (ring->index - ring->index_done);
572 return ring->index_done - ring->index;
579 static inline u8 rt2x00_get_plcp(
const u8 rate) {
583 0x00, 0x01, 0x02, 0x03,
584 0x0b, 0x0f, 0x0a, 0x0e, 0x09, 0x0d, 0x08, 0x0c,
587 for(; counter < 12; counter++){
588 if(capabilities.bitrate[counter] == rate)
589 return plcp[counter];
595 #define OFDM_CHANNEL(__channel) ( (__channel) >= CHANNEL_OFDM_MIN && (__channel) <= CHANNEL_OFDM_MAX ) 596 #define UNII_LOW_CHANNEL(__channel) ( (__channel) >= CHANNEL_UNII_LOW_MIN && (__channel) <= CHANNEL_UNII_LOW_MAX ) 597 #define HIPERLAN2_CHANNEL(__channel) ( (__channel) >= CHANNEL_HIPERLAN2_MIN && (__channel) <= CHANNEL_HIPERLAN2_MAX ) 598 #define UNII_HIGH_CHANNEL(__channel) ( (__channel) >= CHANNEL_UNII_HIGH_MIN && (__channel) <= CHANNEL_UNII_HIGH_MAX ) 604 static inline int rt2x00_get_channel_index(
const u8 channel) {
606 if(OFDM_CHANNEL(channel))
607 return (channel - 1);
612 if(UNII_LOW_CHANNEL(channel))
613 return ((channel - CHANNEL_UNII_LOW_MIN) / 4);
614 else if(HIPERLAN2_CHANNEL(channel))
615 return ((channel - CHANNEL_HIPERLAN2_MIN) / 4);
616 else if(UNII_HIGH_CHANNEL(channel))
617 return ((channel - CHANNEL_UNII_HIGH_MIN) / 4);
625 extern struct rtnet_device * rt2x00_core_probe(
struct _rt2x00_dev_handler * handler,
void *priv, u32 sizeof_dev);
626 extern void rt2x00_core_remove(
struct rtnet_device *rtnet_dev);