Xenomai  3.1
rt2x00.h
1 /* rt2x00.h
2  *
3  * Copyright (C) 2004 - 2005 rt2x00-2.0.0-b3 SourceForge Project
4  * <http://rt2x00.serialmonkey.com>
5  * 2006 rtnet adaption by Daniel Gregorek
6  * <dxg@gmx.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23 
24 /*
25  Module: rt2x00
26  Abstract: rt2x00 global information.
27  Supported chipsets: RT2560
28 */
29 
30 #ifndef RT2X00_H
31 #define RT2X00_H
32 
33 #include <linux/netdevice.h>
34 #include <linux/wireless.h>
35 
36 #include <rtnet_port.h>
37 #include <rtwlan.h>
38 
39 #define MAX_UNITS 2
40 
41 /*
42  * Module information.
43  */
44 #define DRV_NAME "rt2x00"
45 #define DRV_VERSION "0.1"
46 #define DRV_AUTHOR "Daniel Gregorek <dxg@gmx.de>"
47 //#define CONFIG_RT2X00_DEBUG
48 
49 /*
50  * Debug defines.
51  * The debug variable will be exported by the device specific module.
52  * For this reason this variable must be set to extern to make it accessible
53  * to the core module as well.
54  */
55 #ifdef CONFIG_RT2X00_DEBUG
56 extern int rt2x00_debug_level;
57 #define DEBUG_PRINTK(__message...) \
58  do { \
59  rtdm_printk(__message); \
60  } while (0)
61 #else /* CONFIG_RT2X00_DEBUG */
62 #define DEBUG_PRINTK(__message...) \
63  do { \
64  } while (0)
65 #endif /* CONFIG_RT2X00_DEBUG */
66 
67 /*
68  * Various debug levels.
69  * PANIC and ERROR indicates serious problems within the module,
70  * these should never be ignored and thus we will always print the message.
71  */
72 #define PANIC(__message, __args...) \
73  rtdm_printk(KERN_PANIC DRV_NAME "->%s: Panic - " __message, \
74  __FUNCTION__, ##__args);
75 #define ERROR(__message, __args...) \
76  rtdm_printk(KERN_ERR DRV_NAME "->%s: Error - " __message, \
77  __FUNCTION__, ##__args);
78 #define WARNING(__message, __args...) \
79  rtdm_printk(KERN_WARNING DRV_NAME "->%s: Warning - " __message, \
80  __FUNCTION__, ##__args);
81 #define NOTICE(__message, __args...) \
82  rtdm_printk(KERN_NOTICE DRV_NAME "->%s: Notice - " __message, \
83  __FUNCTION__, ##__args);
84 #define INFO(__message, __args...) \
85  rtdm_printk(KERN_INFO DRV_NAME "->%s: Info - " __message, \
86  __FUNCTION__, ##__args);
87 #define DEBUG(__message, __args...) \
88  DEBUG_PRINTK(KERN_DEBUG DRV_NAME "->%s: Debug - " __message, \
89  __FUNCTION__, ##__args);
90 
91 /*
92  * RT2x00 ring types.
93  */
94 
95 /*
96  * Ring names.
97  */
98 #define RING_RX 0x01 /* Ring used for receiving packets. */
99 #define RING_TX 0x02 /* Ring used for transmitting normal packets. */
100 
101 /*
102  * Ring sizes.
103  */
104 #define DATA_FRAME_SIZE 2432
105 #define MGMT_FRAME_SIZE 256
106 
107 /*
108  * RT2x00 xmit flags.
109  */
110 #define XMIT_IFS_SIFS 0x0001
111 #define XMIT_IFS_BACKOFF 0x0002
112 #define XMIT_IFS_NEW_BACKOFF 0x0004
113 #define XMIT_IFS_NONE 0x0008
114 #define XMIT_NEW_SEQUENCE 0x0010
115 #define XMIT_ACK 0x0020
116 #define XMIT_TIMESTAMP 0x0040
117 #define XMIT_RTS 0x0080
118 #define XMIT_OFDM 0x0100
119 #define XMIT_LONG_RETRY 0x0200
120 #define XMIT_MORE_FRAGS 0x0400
121 #define XMIT_SHORT_PREAMBLE 0x0800
122 #define XMIT_START 0x1000
123 
124 /*
125  * RT2x00 Statistics flags.
126  */
127 #define STATS_TX_RESULT 0x01
128 #define STATS_TX_RETRY_COUNT 0x02
129 #define STATS_RX_CRC 0x10
130 #define STATS_RX_PHYSICAL 0x20
131 #define STATS_RX_QUALITY 0x40
132 #define STATS_RX_DROP 0x80
133 
134 /*
135  * TX result flags.
136  */
137 #define TX_SUCCESS 0
138 #define TX_SUCCESS_RETRY 1
139 #define TX_FAIL_RETRY 2
140 #define TX_FAIL_INVALID 3
141 #define TX_FAIL_OTHER 4
142 
143 /*
144  * Channel type defines.
145  */
146 #define CHANNEL_OFDM 0x01
147 #define CHANNEL_UNII_LOW 0x02
148 #define CHANNEL_HIPERLAN2 0x04
149 #define CHANNEL_UNII_HIGH 0x08
150 
151 #define CHANNEL_OFDM_MIN 1
152 #define CHANNEL_OFDM_MAX 14
153 #define CHANNEL_UNII_LOW_MIN 36
154 #define CHANNEL_UNII_LOW_MAX 64
155 #define CHANNEL_HIPERLAN2_MIN 100
156 #define CHANNEL_HIPERLAN2_MAX 140
157 #define CHANNEL_UNII_HIGH_MIN 149
158 #define CHANNEL_UNII_HIGH_MAX 161
159 
160 /*
161  * Device 802.11abg capabilities.
162  */
163 static struct _rt2x00_capabilities {
164  u8 txpower[6];
165  u8 bitrate[12];
166 } __attribute__ ((packed)) capabilities = {
167  /*
168  * tx-power.
169  */
170  .txpower = {
171  3, 12, 25, 50, 75, 100,
172  },
173 
174  /*
175  * Bitrates
176  */
177  .bitrate = {
178  2, 4, 11, 22, /* CCK. */
179  12, 18, 24, 36, 48, 72, 96, 108, /* OFDM. */
180  },
181 };
182 
183 struct _rt2x00_config {
184  u8 config_flags;
185 #define CONFIG_DROP_BCAST 0x0001
186 #define CONFIG_DROP_MCAST 0x0002
187 #define CONFIG_AUTORESP 0x0004
188 
189  u8 antenna_tx;
190  u8 antenna_rx;
191 
192  u8 bssid[ETH_ALEN];
193  u8 short_retry;
194  u8 long_retry;
195 
196  u8 channel;
197  u8 bitrate; /* 0.5Mbit/sec */
198  u8 txpower; /* % */
199 
200  u8 bbpsens;
201 
202  /*
203  * LED status
204  */
205  u8 led_status;
206 
207  u16 __pad2; /* For alignment only. */
208 
209  /*
210  * Duration values in us.
211  */
212  u8 plcp;
213  u8 sifs;
214  u8 slot_time;
215 
216  /*
217  * Configuration values that have to be updated to device.
218  */
219  u16 update_flags;
220 #define UPDATE_ALL_CONFIG 0xffff
221 #define UPDATE_BSSID 0x0001
222 #define UPDATE_PACKET_FILTER 0x0002
223 #define UPDATE_CHANNEL 0x0004
224 #define UPDATE_BITRATE 0x0008
225 #define UPDATE_RETRY 0x0010
226 #define UPDATE_TXPOWER 0x0020
227 #define UPDATE_ANTENNA 0x0040
228 #define UPDATE_DURATION 0x0080
229 #define UPDATE_PREAMBLE 0x0100
230 #define UPDATE_AUTORESP 0x0200
231 #define UPDATE_LED_STATUS 0x0400
232 #define UPDATE_BBPSENS 0x0800
233 
234 } __attribute__((packed));
235 
236 struct _rt2x00_core {
237  /*
238  * RT2x00 device status flags (atomic read/write access).
239  */
240  unsigned long flags;
241 
242 #define DEVICE_ENABLED 0 /* Device has been opened. */
243 #define DEVICE_AWAKE 1 /* Device is not suspended. */
244 #define DEVICE_RADIO_ON 2 /* Device antenna is enabled. */
245 #define DEVICE_CONFIG_UPDATE 3 /* Device is updating configuration. */
246 
247  /*
248  * Device handler.
249  */
250  struct _rt2x00_dev_handler *handler;
251 
252  /*
253  * RTnet device we belong to.
254  */
255  struct rtnet_device *rtnet_dev;
256 
257  /*
258  * RTwlan stack structure.
259  */
260  struct rtwlan_device *rtwlan_dev;
261 
262  /*
263  * Device configuration.
264  */
265  struct _rt2x00_config config;
266 
267  void *priv;
268 
269 } __attribute__((packed));
270 
271 /*
272  * Device specific handlers.
273  */
274 struct _rt2x00_dev_handler {
275  /*
276  * Device specific module.
277  */
278  struct module *dev_module;
279 
280  /*
281  * Initialization handlers.
282  */
283  int (*dev_probe)(struct _rt2x00_core *core, void *priv);
284  int (*dev_remove)(struct _rt2x00_core *core);
285 
286  /*
287  * Radio control.
288  */
289  int (*dev_radio_on)(struct _rt2x00_core *core);
290  int (*dev_radio_off)(struct _rt2x00_core *core);
291 
292  /*
293  * Configuration handlers.
294  */
295  int (*dev_update_config)(struct _rt2x00_core *core, u16 update_flags);
296 
297  /*
298  * xmit handler.
299  */
300  int (*dev_xmit_packet)(struct _rt2x00_core *core, struct rtskb *rtskb,
301  u16 rate, u16 xmit_flags);
302 
303  /*
304  * Handler for direct access to register from core.
305  */
306  int (*dev_register_access)(struct _rt2x00_core *core, int request,
307  u32 address, u32 *value);
308 
309 } __attribute__((packed));
310 
311 static inline void *rt2x00_priv(const struct _rt2x00_core *core)
312 {
313  return core->priv;
314 }
315 
316 /*
317  * Duration calculations
318  * The rate variable passed is: 2 * real_rate (in Mb/s).
319  * Therefore length has to be multiplied with 8 to convert bytes to bits and mulltiply the length
320  * with 2 to compensate for the difference between real_rate and the rate variable.
321  */
322 #define ACK_SIZE 14
323 #define IEEE80211_HEADER 24
324 
325 static inline u16 get_duration(const unsigned int size, const u8 rate)
326 {
327  return ((size * 8 * 2) / rate);
328 }
329 
330 static inline u16 get_duration_res(const unsigned int size, const u8 rate)
331 {
332  return ((size * 8 * 2) % rate);
333 }
334 
335 static inline u16 get_preamble(const struct _rt2x00_config *config)
336 {
337  return 144;
338 }
339 
340 /*
341  * Register handlers.
342  * We store the position of a register field inside a field structure,
343  * This will simplify the process of setting and reading a certain field
344  * inside the register.
345  */
346 struct _rt2x00_field16 {
347  u16 bit_offset;
348  u16 bit_mask;
349 } __attribute__((packed));
350 
351 struct _rt2x00_field32 {
352  u32 bit_offset;
353  u32 bit_mask;
354 } __attribute__((packed));
355 
356 #define FIELD16(__offset, __mask) \
357  ((struct _rt2x00_field16){ (__offset), (__mask) })
358 #define FIELD32(__offset, __mask) \
359  ((struct _rt2x00_field32){ (__offset), (__mask) })
360 
361 static inline void rt2x00_set_field32(u32 *reg,
362  const struct _rt2x00_field32 field,
363  const u32 value)
364 {
365  *reg &= cpu_to_le32(~(field.bit_mask));
366  *reg |= cpu_to_le32((value << field.bit_offset) & field.bit_mask);
367 }
368 
369 static inline void rt2x00_set_field32_nb(u32 *reg,
370  const struct _rt2x00_field32 field,
371  const u32 value)
372 {
373  *reg &= ~(field.bit_mask);
374  *reg |= (value << field.bit_offset) & field.bit_mask;
375 }
376 
377 static inline u32 rt2x00_get_field32(const u32 reg,
378  const struct _rt2x00_field32 field)
379 {
380  return (le32_to_cpu(reg) & field.bit_mask) >> field.bit_offset;
381 }
382 
383 static inline u32 rt2x00_get_field32_nb(const u32 reg,
384  const struct _rt2x00_field32 field)
385 {
386  return (reg & field.bit_mask) >> field.bit_offset;
387 }
388 
389 static inline void rt2x00_set_field16(u16 *reg,
390  const struct _rt2x00_field16 field,
391  const u16 value)
392 {
393  *reg &= cpu_to_le16(~(field.bit_mask));
394  *reg |= cpu_to_le16((value << field.bit_offset) & field.bit_mask);
395 }
396 
397 static inline void rt2x00_set_field16_nb(u16 *reg,
398  const struct _rt2x00_field16 field,
399  const u16 value)
400 {
401  *reg &= ~(field.bit_mask);
402  *reg |= (value << field.bit_offset) & field.bit_mask;
403 }
404 
405 static inline u16 rt2x00_get_field16(const u16 reg,
406  const struct _rt2x00_field16 field)
407 {
408  return (le16_to_cpu(reg) & field.bit_mask) >> field.bit_offset;
409 }
410 
411 static inline u16 rt2x00_get_field16_nb(const u16 reg,
412  const struct _rt2x00_field16 field)
413 {
414  return (reg & field.bit_mask) >> field.bit_offset;
415 }
416 
417 /*
418  * rf register sructure for channel selection.
419  */
420 struct _rf_channel {
421  u32 rf1;
422  u32 rf2;
423  u32 rf3;
424  u32 rf4;
425 } __attribute__((packed));
426 
427 /*
428  * Chipset identification
429  * The chipset on the device is composed of a RT and RF chip.
430  * The chipset combination is important for determining device capabilities.
431  */
432 struct _rt2x00_chip {
433  u16 rt;
434  u16 rf;
435 } __attribute__((packed));
436 
437 /*
438  * Set chipset data.
439  * Some rf values for RT2400 devices are equal to rf values for RT2500 devices.
440  * To prevent problems, all rf values will be masked to clearly seperate each chipset.
441  */
442 static inline void set_chip(struct _rt2x00_chip *chipset, const u16 rt,
443  const u16 rf)
444 {
445  INFO("Chipset detected - rt: %04x, rf: %04x.\n", rt, rf);
446 
447  chipset->rt = rt;
448  chipset->rf = rf | (chipset->rt & 0xff00);
449 }
450 
451 static inline char rt2x00_rt(const struct _rt2x00_chip *chipset, const u16 chip)
452 {
453  return (chipset->rt == chip);
454 }
455 
456 static inline char rt2x00_rf(const struct _rt2x00_chip *chipset, const u16 chip)
457 {
458  return (chipset->rf == chip);
459 }
460 
461 static inline u16 rt2x00_get_rf(const struct _rt2x00_chip *chipset)
462 {
463  return chipset->rf;
464 }
465 
466 /*
467  * _data_ring
468  * Data rings are used by the device to send and receive packets.
469  * The data_addr is the base address of the data memory.
470  * Device specifice information is pointed to by the priv pointer.
471  * The index values may only be changed with the functions ring_index_inc()
472  * and ring_index_done_inc().
473  */
474 struct _data_ring {
475  /*
476  * Base address of packet ring.
477  */
478  dma_addr_t data_dma;
479  void *data_addr;
480 
481  /*
482  * Private device specific data.
483  */
484  void *priv;
485  struct _rt2x00_core *core;
486 
487  /*
488  * Current index values.
489  */
490  u8 index;
491  u8 index_done;
492 
493  /*
494  * Ring type set with RING_* define.
495  */
496  u8 ring_type;
497 
498  /*
499  * Number of entries in this ring.
500  */
501  u8 max_entries;
502 
503  /*
504  * Size of packet and descriptor in bytes.
505  */
506  u16 entry_size;
507  u16 desc_size;
508 
509  /*
510  * Total allocated memory size.
511  */
512  u32 mem_size;
513 } __attribute__((packed));
514 
515 /*
516  * Number of entries in a packet ring.
517  */
518 #define RX_ENTRIES 8
519 #define TX_ENTRIES 8
520 #define ATIM_ENTRIES 1
521 #define PRIO_ENTRIES 2
522 #define BEACON_ENTRIES 1
523 
524 /*
525  * Initialization and cleanup routines.
526  */
527 static inline void rt2x00_init_ring(struct _rt2x00_core *core,
528  struct _data_ring *ring, const u8 ring_type,
529  const u16 max_entries, const u16 entry_size,
530  const u16 desc_size)
531 {
532  ring->core = core;
533  ring->index = 0;
534  ring->index_done = 0;
535  ring->ring_type = ring_type;
536  ring->max_entries = max_entries;
537  ring->entry_size = entry_size;
538  ring->desc_size = desc_size;
539  ring->mem_size =
540  ring->max_entries * (ring->desc_size + ring->entry_size);
541 }
542 
543 static inline void rt2x00_deinit_ring(struct _data_ring *ring)
544 {
545  ring->core = NULL;
546  ring->index = 0;
547  ring->index_done = 0;
548  ring->ring_type = 0;
549  ring->max_entries = 0;
550  ring->entry_size = 0;
551  ring->desc_size = 0;
552  ring->mem_size = 0;
553 }
554 
555 /*
556  * Ring index manipulation functions.
557  */
558 static inline void rt2x00_ring_index_inc(struct _data_ring *ring)
559 {
560  ring->index = (++ring->index < ring->max_entries) ? ring->index : 0;
561 }
562 
563 static inline void rt2x00_ring_index_done_inc(struct _data_ring *ring)
564 {
565  ring->index_done =
566  (++ring->index_done < ring->max_entries) ? ring->index_done : 0;
567 }
568 
569 static inline void rt2x00_ring_clear_index(struct _data_ring *ring)
570 {
571  ring->index = 0;
572  ring->index_done = 0;
573 }
574 
575 static inline u8 rt2x00_ring_empty(struct _data_ring *ring)
576 {
577  return ring->index_done == ring->index;
578 }
579 
580 static inline u8 rt2x00_ring_free_entries(struct _data_ring *ring)
581 {
582  if (ring->index >= ring->index_done)
583  return ring->max_entries - (ring->index - ring->index_done);
584  else
585  return ring->index_done - ring->index;
586 }
587 
588 /*
589  * Return PLCP value matching the rate.
590  * PLCP values according to ieee802.11a-1999 p.14.
591  */
592 static inline u8 rt2x00_get_plcp(const u8 rate)
593 {
594  u8 counter = 0x00;
595  u8 plcp[12] = {
596  0x00, 0x01, 0x02, 0x03, /* CCK. */
597  0x0b, 0x0f, 0x0a, 0x0e, 0x09, 0x0d, 0x08, 0x0c, /* OFDM. */
598  };
599 
600  for (; counter < 12; counter++) {
601  if (capabilities.bitrate[counter] == rate)
602  return plcp[counter];
603  }
604 
605  return 0xff;
606 }
607 
608 #define OFDM_CHANNEL(__channel) \
609  ((__channel) >= CHANNEL_OFDM_MIN && (__channel) <= CHANNEL_OFDM_MAX)
610 #define UNII_LOW_CHANNEL(__channel) \
611  ((__channel) >= CHANNEL_UNII_LOW_MIN && \
612  (__channel) <= CHANNEL_UNII_LOW_MAX)
613 #define HIPERLAN2_CHANNEL(__channel) \
614  ((__channel) >= CHANNEL_HIPERLAN2_MIN && \
615  (__channel) <= CHANNEL_HIPERLAN2_MAX)
616 #define UNII_HIGH_CHANNEL(__channel) \
617  ((__channel) >= CHANNEL_UNII_HIGH_MIN && \
618  (__channel) <= CHANNEL_UNII_HIGH_MAX)
619 
620 /*
621  * Return the index value of the channel starting from the first channel of the range.
622  * Where range can be OFDM, UNII (low), HiperLAN2 or UNII (high).
623  */
624 static inline int rt2x00_get_channel_index(const u8 channel)
625 {
626  if (OFDM_CHANNEL(channel))
627  return (channel - 1);
628 
629  if (channel % 4)
630  return -EINVAL;
631 
632  if (UNII_LOW_CHANNEL(channel))
633  return ((channel - CHANNEL_UNII_LOW_MIN) / 4);
634  else if (HIPERLAN2_CHANNEL(channel))
635  return ((channel - CHANNEL_HIPERLAN2_MIN) / 4);
636  else if (UNII_HIGH_CHANNEL(channel))
637  return ((channel - CHANNEL_UNII_HIGH_MIN) / 4);
638  return -EINVAL;
639 }
640 
641 /*
642  * RT2x00 core module functions that can be used in the device specific modules.
643  */
644 extern struct rtnet_device *
645 rt2x00_core_probe(struct _rt2x00_dev_handler *handler, void *priv,
646  u32 sizeof_dev);
647 extern void rt2x00_core_remove(struct rtnet_device *rtnet_dev);
648 
649 #endif
static int __attribute__((cold))
Test if a mutex structure contains a valid autoinitializer.
Definition: mutex.c:177