bcm43xx_main.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. Broadcom BCM43xx wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
  4. Stefano Brivio <st3@riseup.net>
  5. Michael Buesch <mbuesch@freenet.de>
  6. Danny van Dyk <kugelfang@gentoo.org>
  7. Andreas Jaggi <andreas.jaggi@waterwave.ch>
  8. Some parts of the code in this file are derived from the ipw2200
  9. driver Copyright(c) 2003 - 2004 Intel Corporation.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  21. Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef BCM43xx_MAIN_H_
  24. #define BCM43xx_MAIN_H_
  25. #include "bcm43xx.h"
  26. #ifdef CONFIG_BCM947XX
  27. #define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
  28. static inline void e_aton(char *str, char *dest)
  29. {
  30. int i = 0;
  31. u16 *d = (u16 *) dest;
  32. for (;;) {
  33. dest[i++] = (char) simple_strtoul(str, NULL, 16);
  34. str += 2;
  35. if (!*str++ || i == 6)
  36. break;
  37. }
  38. for (i = 0; i < 3; i++)
  39. d[i] = cpu_to_be16(d[i]);
  40. }
  41. #endif
  42. #define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
  43. #define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
  44. /* Magic helper macro to pad structures. Ignore those above. It's magic. */
  45. #define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
  46. /* Lightweight function to convert a frequency (in Mhz) to a channel number. */
  47. static inline
  48. u8 bcm43xx_freq_to_channel_a(int freq)
  49. {
  50. return ((freq - 5000) / 5);
  51. }
  52. static inline
  53. u8 bcm43xx_freq_to_channel_bg(int freq)
  54. {
  55. u8 channel;
  56. if (freq == 2484)
  57. channel = 14;
  58. else
  59. channel = (freq - 2407) / 5;
  60. return channel;
  61. }
  62. static inline
  63. u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
  64. int freq)
  65. {
  66. if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
  67. return bcm43xx_freq_to_channel_a(freq);
  68. return bcm43xx_freq_to_channel_bg(freq);
  69. }
  70. /* Lightweight function to convert a channel number to a frequency (in Mhz). */
  71. static inline
  72. int bcm43xx_channel_to_freq_a(u8 channel)
  73. {
  74. return (5000 + (5 * channel));
  75. }
  76. static inline
  77. int bcm43xx_channel_to_freq_bg(u8 channel)
  78. {
  79. int freq;
  80. if (channel == 14)
  81. freq = 2484;
  82. else
  83. freq = 2407 + (5 * channel);
  84. return freq;
  85. }
  86. static inline
  87. int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
  88. u8 channel)
  89. {
  90. if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
  91. return bcm43xx_channel_to_freq_a(channel);
  92. return bcm43xx_channel_to_freq_bg(channel);
  93. }
  94. /* Lightweight function to check if a channel number is valid.
  95. * Note that this does _NOT_ check for geographical restrictions!
  96. */
  97. static inline
  98. int bcm43xx_is_valid_channel_a(u8 channel)
  99. {
  100. return (channel <= 200);
  101. }
  102. static inline
  103. int bcm43xx_is_valid_channel_bg(u8 channel)
  104. {
  105. return (channel >= 1 && channel <= 14);
  106. }
  107. static inline
  108. int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
  109. u8 channel)
  110. {
  111. if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
  112. return bcm43xx_is_valid_channel_a(channel);
  113. return bcm43xx_is_valid_channel_bg(channel);
  114. }
  115. void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
  116. void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
  117. void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
  118. int iw_mode);
  119. u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
  120. u16 routing, u16 offset);
  121. u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
  122. u16 routing, u16 offset);
  123. void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
  124. u16 routing, u16 offset,
  125. u32 value);
  126. void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
  127. u16 routing, u16 offset,
  128. u16 value);
  129. void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
  130. int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
  131. void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
  132. void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
  133. void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
  134. void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
  135. int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
  136. int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
  137. #endif /* BCM43xx_MAIN_H_ */