bcm43xx.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. #ifndef BCM43xx_H_
  2. #define BCM43xx_H_
  3. #include <linux/version.h>
  4. #include <linux/kernel.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/stringify.h>
  8. #include <linux/pci.h>
  9. #include <net/ieee80211.h>
  10. #include <net/ieee80211softmac.h>
  11. #include <asm/atomic.h>
  12. #include <asm/io.h>
  13. #include "bcm43xx_debugfs.h"
  14. #include "bcm43xx_leds.h"
  15. #include "bcm43xx_sysfs.h"
  16. #define PFX KBUILD_MODNAME ": "
  17. #define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
  18. #define BCM43xx_IRQWAIT_MAX_RETRIES 50
  19. #define BCM43xx_IO_SIZE 8192
  20. /* Active Core PCI Configuration Register. */
  21. #define BCM43xx_PCICFG_ACTIVE_CORE 0x80
  22. /* SPROM control register. */
  23. #define BCM43xx_PCICFG_SPROMCTL 0x88
  24. /* Interrupt Control PCI Configuration Register. (Only on PCI cores with rev >= 6) */
  25. #define BCM43xx_PCICFG_ICR 0x94
  26. /* MMIO offsets */
  27. #define BCM43xx_MMIO_DMA1_REASON 0x20
  28. #define BCM43xx_MMIO_DMA1_IRQ_MASK 0x24
  29. #define BCM43xx_MMIO_DMA2_REASON 0x28
  30. #define BCM43xx_MMIO_DMA2_IRQ_MASK 0x2C
  31. #define BCM43xx_MMIO_DMA3_REASON 0x30
  32. #define BCM43xx_MMIO_DMA3_IRQ_MASK 0x34
  33. #define BCM43xx_MMIO_DMA4_REASON 0x38
  34. #define BCM43xx_MMIO_DMA4_IRQ_MASK 0x3C
  35. #define BCM43xx_MMIO_STATUS_BITFIELD 0x120
  36. #define BCM43xx_MMIO_STATUS2_BITFIELD 0x124
  37. #define BCM43xx_MMIO_GEN_IRQ_REASON 0x128
  38. #define BCM43xx_MMIO_GEN_IRQ_MASK 0x12C
  39. #define BCM43xx_MMIO_RAM_CONTROL 0x130
  40. #define BCM43xx_MMIO_RAM_DATA 0x134
  41. #define BCM43xx_MMIO_PS_STATUS 0x140
  42. #define BCM43xx_MMIO_RADIO_HWENABLED_HI 0x158
  43. #define BCM43xx_MMIO_SHM_CONTROL 0x160
  44. #define BCM43xx_MMIO_SHM_DATA 0x164
  45. #define BCM43xx_MMIO_SHM_DATA_UNALIGNED 0x166
  46. #define BCM43xx_MMIO_XMITSTAT_0 0x170
  47. #define BCM43xx_MMIO_XMITSTAT_1 0x174
  48. #define BCM43xx_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
  49. #define BCM43xx_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
  50. #define BCM43xx_MMIO_DMA1_BASE 0x200
  51. #define BCM43xx_MMIO_DMA2_BASE 0x220
  52. #define BCM43xx_MMIO_DMA3_BASE 0x240
  53. #define BCM43xx_MMIO_DMA4_BASE 0x260
  54. #define BCM43xx_MMIO_PIO1_BASE 0x300
  55. #define BCM43xx_MMIO_PIO2_BASE 0x310
  56. #define BCM43xx_MMIO_PIO3_BASE 0x320
  57. #define BCM43xx_MMIO_PIO4_BASE 0x330
  58. #define BCM43xx_MMIO_PHY_VER 0x3E0
  59. #define BCM43xx_MMIO_PHY_RADIO 0x3E2
  60. #define BCM43xx_MMIO_ANTENNA 0x3E8
  61. #define BCM43xx_MMIO_CHANNEL 0x3F0
  62. #define BCM43xx_MMIO_CHANNEL_EXT 0x3F4
  63. #define BCM43xx_MMIO_RADIO_CONTROL 0x3F6
  64. #define BCM43xx_MMIO_RADIO_DATA_HIGH 0x3F8
  65. #define BCM43xx_MMIO_RADIO_DATA_LOW 0x3FA
  66. #define BCM43xx_MMIO_PHY_CONTROL 0x3FC
  67. #define BCM43xx_MMIO_PHY_DATA 0x3FE
  68. #define BCM43xx_MMIO_MACFILTER_CONTROL 0x420
  69. #define BCM43xx_MMIO_MACFILTER_DATA 0x422
  70. #define BCM43xx_MMIO_RADIO_HWENABLED_LO 0x49A
  71. #define BCM43xx_MMIO_GPIO_CONTROL 0x49C
  72. #define BCM43xx_MMIO_GPIO_MASK 0x49E
  73. #define BCM43xx_MMIO_TSF_0 0x632 /* core rev < 3 only */
  74. #define BCM43xx_MMIO_TSF_1 0x634 /* core rev < 3 only */
  75. #define BCM43xx_MMIO_TSF_2 0x636 /* core rev < 3 only */
  76. #define BCM43xx_MMIO_TSF_3 0x638 /* core rev < 3 only */
  77. #define BCM43xx_MMIO_POWERUP_DELAY 0x6A8
  78. /* SPROM offsets. */
  79. #define BCM43xx_SPROM_BASE 0x1000
  80. #define BCM43xx_SPROM_BOARDFLAGS2 0x1c
  81. #define BCM43xx_SPROM_IL0MACADDR 0x24
  82. #define BCM43xx_SPROM_ET0MACADDR 0x27
  83. #define BCM43xx_SPROM_ET1MACADDR 0x2a
  84. #define BCM43xx_SPROM_ETHPHY 0x2d
  85. #define BCM43xx_SPROM_BOARDREV 0x2e
  86. #define BCM43xx_SPROM_PA0B0 0x2f
  87. #define BCM43xx_SPROM_PA0B1 0x30
  88. #define BCM43xx_SPROM_PA0B2 0x31
  89. #define BCM43xx_SPROM_WL0GPIO0 0x32
  90. #define BCM43xx_SPROM_WL0GPIO2 0x33
  91. #define BCM43xx_SPROM_MAXPWR 0x34
  92. #define BCM43xx_SPROM_PA1B0 0x35
  93. #define BCM43xx_SPROM_PA1B1 0x36
  94. #define BCM43xx_SPROM_PA1B2 0x37
  95. #define BCM43xx_SPROM_IDL_TSSI_TGT 0x38
  96. #define BCM43xx_SPROM_BOARDFLAGS 0x39
  97. #define BCM43xx_SPROM_ANTENNA_GAIN 0x3a
  98. #define BCM43xx_SPROM_VERSION 0x3f
  99. /* BCM43xx_SPROM_BOARDFLAGS values */
  100. #define BCM43xx_BFL_BTCOEXIST 0x0001 /* implements Bluetooth coexistance */
  101. #define BCM43xx_BFL_PACTRL 0x0002 /* GPIO 9 controlling the PA */
  102. #define BCM43xx_BFL_AIRLINEMODE 0x0004 /* implements GPIO 13 radio disable indication */
  103. #define BCM43xx_BFL_RSSI 0x0008 /* software calculates nrssi slope. */
  104. #define BCM43xx_BFL_ENETSPI 0x0010 /* has ephy roboswitch spi */
  105. #define BCM43xx_BFL_XTAL_NOSLOW 0x0020 /* no slow clock available */
  106. #define BCM43xx_BFL_CCKHIPWR 0x0040 /* can do high power CCK transmission */
  107. #define BCM43xx_BFL_ENETADM 0x0080 /* has ADMtek switch */
  108. #define BCM43xx_BFL_ENETVLAN 0x0100 /* can do vlan */
  109. #define BCM43xx_BFL_AFTERBURNER 0x0200 /* supports Afterburner mode */
  110. #define BCM43xx_BFL_NOPCI 0x0400 /* leaves PCI floating */
  111. #define BCM43xx_BFL_FEM 0x0800 /* supports the Front End Module */
  112. /* GPIO register offset, in both ChipCommon and PCI core. */
  113. #define BCM43xx_GPIO_CONTROL 0x6c
  114. /* SHM Routing */
  115. #define BCM43xx_SHM_SHARED 0x0001
  116. #define BCM43xx_SHM_WIRELESS 0x0002
  117. #define BCM43xx_SHM_PCM 0x0003
  118. #define BCM43xx_SHM_HWMAC 0x0004
  119. #define BCM43xx_SHM_UCODE 0x0300
  120. /* MacFilter offsets. */
  121. #define BCM43xx_MACFILTER_SELF 0x0000
  122. #define BCM43xx_MACFILTER_ASSOC 0x0003
  123. /* Chipcommon registers. */
  124. #define BCM43xx_CHIPCOMMON_CAPABILITIES 0x04
  125. #define BCM43xx_CHIPCOMMON_PLLONDELAY 0xB0
  126. #define BCM43xx_CHIPCOMMON_FREFSELDELAY 0xB4
  127. #define BCM43xx_CHIPCOMMON_SLOWCLKCTL 0xB8
  128. #define BCM43xx_CHIPCOMMON_SYSCLKCTL 0xC0
  129. /* PCI core specific registers. */
  130. #define BCM43xx_PCICORE_BCAST_ADDR 0x50
  131. #define BCM43xx_PCICORE_BCAST_DATA 0x54
  132. #define BCM43xx_PCICORE_SBTOPCI2 0x108
  133. /* SBTOPCI2 values. */
  134. #define BCM43xx_SBTOPCI2_PREFETCH 0x4
  135. #define BCM43xx_SBTOPCI2_BURST 0x8
  136. /* Chipcommon capabilities. */
  137. #define BCM43xx_CAPABILITIES_PCTL 0x00040000
  138. #define BCM43xx_CAPABILITIES_PLLMASK 0x00030000
  139. #define BCM43xx_CAPABILITIES_PLLSHIFT 16
  140. #define BCM43xx_CAPABILITIES_FLASHMASK 0x00000700
  141. #define BCM43xx_CAPABILITIES_FLASHSHIFT 8
  142. #define BCM43xx_CAPABILITIES_EXTBUSPRESENT 0x00000040
  143. #define BCM43xx_CAPABILITIES_UARTGPIO 0x00000020
  144. #define BCM43xx_CAPABILITIES_UARTCLOCKMASK 0x00000018
  145. #define BCM43xx_CAPABILITIES_UARTCLOCKSHIFT 3
  146. #define BCM43xx_CAPABILITIES_MIPSBIGENDIAN 0x00000004
  147. #define BCM43xx_CAPABILITIES_NRUARTSMASK 0x00000003
  148. /* PowerControl */
  149. #define BCM43xx_PCTL_IN 0xB0
  150. #define BCM43xx_PCTL_OUT 0xB4
  151. #define BCM43xx_PCTL_OUTENABLE 0xB8
  152. #define BCM43xx_PCTL_XTAL_POWERUP 0x40
  153. #define BCM43xx_PCTL_PLL_POWERDOWN 0x80
  154. /* PowerControl Clock Modes */
  155. #define BCM43xx_PCTL_CLK_FAST 0x00
  156. #define BCM43xx_PCTL_CLK_SLOW 0x01
  157. #define BCM43xx_PCTL_CLK_DYNAMIC 0x02
  158. #define BCM43xx_PCTL_FORCE_SLOW 0x0800
  159. #define BCM43xx_PCTL_FORCE_PLL 0x1000
  160. #define BCM43xx_PCTL_DYN_XTAL 0x2000
  161. /* COREIDs */
  162. #define BCM43xx_COREID_CHIPCOMMON 0x800
  163. #define BCM43xx_COREID_ILINE20 0x801
  164. #define BCM43xx_COREID_SDRAM 0x803
  165. #define BCM43xx_COREID_PCI 0x804
  166. #define BCM43xx_COREID_MIPS 0x805
  167. #define BCM43xx_COREID_ETHERNET 0x806
  168. #define BCM43xx_COREID_V90 0x807
  169. #define BCM43xx_COREID_USB11_HOSTDEV 0x80a
  170. #define BCM43xx_COREID_IPSEC 0x80b
  171. #define BCM43xx_COREID_PCMCIA 0x80d
  172. #define BCM43xx_COREID_EXT_IF 0x80f
  173. #define BCM43xx_COREID_80211 0x812
  174. #define BCM43xx_COREID_MIPS_3302 0x816
  175. #define BCM43xx_COREID_USB11_HOST 0x817
  176. #define BCM43xx_COREID_USB11_DEV 0x818
  177. #define BCM43xx_COREID_USB20_HOST 0x819
  178. #define BCM43xx_COREID_USB20_DEV 0x81a
  179. #define BCM43xx_COREID_SDIO_HOST 0x81b
  180. /* Core Information Registers */
  181. #define BCM43xx_CIR_BASE 0xf00
  182. #define BCM43xx_CIR_SBTPSFLAG (BCM43xx_CIR_BASE + 0x18)
  183. #define BCM43xx_CIR_SBIMSTATE (BCM43xx_CIR_BASE + 0x90)
  184. #define BCM43xx_CIR_SBINTVEC (BCM43xx_CIR_BASE + 0x94)
  185. #define BCM43xx_CIR_SBTMSTATELOW (BCM43xx_CIR_BASE + 0x98)
  186. #define BCM43xx_CIR_SBTMSTATEHIGH (BCM43xx_CIR_BASE + 0x9c)
  187. #define BCM43xx_CIR_SBIMCONFIGLOW (BCM43xx_CIR_BASE + 0xa8)
  188. #define BCM43xx_CIR_SB_ID_HI (BCM43xx_CIR_BASE + 0xfc)
  189. /* Mask to get the Backplane Flag Number from SBTPSFLAG. */
  190. #define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
  191. /* SBIMCONFIGLOW values/masks. */
  192. #define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK 0x00000007
  193. #define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT 0
  194. #define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK 0x00000070
  195. #define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT 4
  196. #define BCM43xx_SBIMCONFIGLOW_CONNID_MASK 0x00ff0000
  197. #define BCM43xx_SBIMCONFIGLOW_CONNID_SHIFT 16
  198. /* sbtmstatelow state flags */
  199. #define BCM43xx_SBTMSTATELOW_RESET 0x01
  200. #define BCM43xx_SBTMSTATELOW_REJECT 0x02
  201. #define BCM43xx_SBTMSTATELOW_CLOCK 0x10000
  202. #define BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK 0x20000
  203. /* sbtmstatehigh state flags */
  204. #define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
  205. #define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
  206. /* sbimstate flags */
  207. #define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
  208. #define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
  209. /* PHYVersioning */
  210. #define BCM43xx_PHYTYPE_A 0x00
  211. #define BCM43xx_PHYTYPE_B 0x01
  212. #define BCM43xx_PHYTYPE_G 0x02
  213. /* PHYRegisters */
  214. #define BCM43xx_PHY_ILT_A_CTRL 0x0072
  215. #define BCM43xx_PHY_ILT_A_DATA1 0x0073
  216. #define BCM43xx_PHY_ILT_A_DATA2 0x0074
  217. #define BCM43xx_PHY_G_LO_CONTROL 0x0810
  218. #define BCM43xx_PHY_ILT_G_CTRL 0x0472
  219. #define BCM43xx_PHY_ILT_G_DATA1 0x0473
  220. #define BCM43xx_PHY_ILT_G_DATA2 0x0474
  221. #define BCM43xx_PHY_A_PCTL 0x007B
  222. #define BCM43xx_PHY_G_PCTL 0x0029
  223. #define BCM43xx_PHY_A_CRS 0x0029
  224. #define BCM43xx_PHY_RADIO_BITFIELD 0x0401
  225. #define BCM43xx_PHY_G_CRS 0x0429
  226. #define BCM43xx_PHY_NRSSILT_CTRL 0x0803
  227. #define BCM43xx_PHY_NRSSILT_DATA 0x0804
  228. /* RadioRegisters */
  229. #define BCM43xx_RADIOCTL_ID 0x01
  230. /* StatusBitField */
  231. #define BCM43xx_SBF_MAC_ENABLED 0x00000001
  232. #define BCM43xx_SBF_2 0x00000002 /*FIXME: fix name*/
  233. #define BCM43xx_SBF_CORE_READY 0x00000004
  234. #define BCM43xx_SBF_400 0x00000400 /*FIXME: fix name*/
  235. #define BCM43xx_SBF_4000 0x00004000 /*FIXME: fix name*/
  236. #define BCM43xx_SBF_8000 0x00008000 /*FIXME: fix name*/
  237. #define BCM43xx_SBF_XFER_REG_BYTESWAP 0x00010000
  238. #define BCM43xx_SBF_MODE_NOTADHOC 0x00020000
  239. #define BCM43xx_SBF_MODE_AP 0x00040000
  240. #define BCM43xx_SBF_RADIOREG_LOCK 0x00080000
  241. #define BCM43xx_SBF_MODE_MONITOR 0x00400000
  242. #define BCM43xx_SBF_MODE_PROMISC 0x01000000
  243. #define BCM43xx_SBF_PS1 0x02000000
  244. #define BCM43xx_SBF_PS2 0x04000000
  245. #define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
  246. #define BCM43xx_SBF_TIME_UPDATE 0x10000000
  247. #define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/
  248. /* MicrocodeFlagsBitfield (addr + lo-word values?)*/
  249. #define BCM43xx_UCODEFLAGS_OFFSET 0x005E
  250. #define BCM43xx_UCODEFLAG_AUTODIV 0x0001
  251. #define BCM43xx_UCODEFLAG_UNKBGPHY 0x0002
  252. #define BCM43xx_UCODEFLAG_UNKBPHY 0x0004
  253. #define BCM43xx_UCODEFLAG_UNKGPHY 0x0020
  254. #define BCM43xx_UCODEFLAG_UNKPACTRL 0x0040
  255. #define BCM43xx_UCODEFLAG_JAPAN 0x0080
  256. /* Generic-Interrupt reasons. */
  257. #define BCM43xx_IRQ_READY (1 << 0)
  258. #define BCM43xx_IRQ_BEACON (1 << 1)
  259. #define BCM43xx_IRQ_PS (1 << 2)
  260. #define BCM43xx_IRQ_REG124 (1 << 5)
  261. #define BCM43xx_IRQ_PMQ (1 << 6)
  262. #define BCM43xx_IRQ_PIO_WORKAROUND (1 << 8)
  263. #define BCM43xx_IRQ_XMIT_ERROR (1 << 11)
  264. #define BCM43xx_IRQ_RX (1 << 15)
  265. #define BCM43xx_IRQ_SCAN (1 << 16)
  266. #define BCM43xx_IRQ_NOISE (1 << 18)
  267. #define BCM43xx_IRQ_XMIT_STATUS (1 << 29)
  268. #define BCM43xx_IRQ_ALL 0xffffffff
  269. #define BCM43xx_IRQ_INITIAL (BCM43xx_IRQ_PS | \
  270. BCM43xx_IRQ_REG124 | \
  271. BCM43xx_IRQ_PMQ | \
  272. BCM43xx_IRQ_XMIT_ERROR | \
  273. BCM43xx_IRQ_RX | \
  274. BCM43xx_IRQ_SCAN | \
  275. BCM43xx_IRQ_NOISE | \
  276. BCM43xx_IRQ_XMIT_STATUS)
  277. /* Initial default iw_mode */
  278. #define BCM43xx_INITIAL_IWMODE IW_MODE_INFRA
  279. /* Bus type PCI. */
  280. #define BCM43xx_BUSTYPE_PCI 0
  281. /* Bus type Silicone Backplane Bus. */
  282. #define BCM43xx_BUSTYPE_SB 1
  283. /* Bus type PCMCIA. */
  284. #define BCM43xx_BUSTYPE_PCMCIA 2
  285. /* Threshold values. */
  286. #define BCM43xx_MIN_RTS_THRESHOLD 1U
  287. #define BCM43xx_MAX_RTS_THRESHOLD 2304U
  288. #define BCM43xx_DEFAULT_RTS_THRESHOLD BCM43xx_MAX_RTS_THRESHOLD
  289. #define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
  290. #define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
  291. /* Max size of a security key */
  292. #define BCM43xx_SEC_KEYSIZE 16
  293. /* Security algorithms. */
  294. enum {
  295. BCM43xx_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
  296. BCM43xx_SEC_ALGO_WEP,
  297. BCM43xx_SEC_ALGO_UNKNOWN,
  298. BCM43xx_SEC_ALGO_AES,
  299. BCM43xx_SEC_ALGO_WEP104,
  300. BCM43xx_SEC_ALGO_TKIP,
  301. };
  302. #ifdef assert
  303. # undef assert
  304. #endif
  305. #ifdef CONFIG_BCM43XX_DEBUG
  306. #define assert(expr) \
  307. do { \
  308. if (unlikely(!(expr))) { \
  309. printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
  310. #expr, __FILE__, __LINE__, __FUNCTION__); \
  311. } \
  312. } while (0)
  313. #else
  314. #define assert(expr) do { /* nothing */ } while (0)
  315. #endif
  316. /* rate limited printk(). */
  317. #ifdef printkl
  318. # undef printkl
  319. #endif
  320. #define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
  321. /* rate limited printk() for debugging */
  322. #ifdef dprintkl
  323. # undef dprintkl
  324. #endif
  325. #ifdef CONFIG_BCM43XX_DEBUG
  326. # define dprintkl printkl
  327. #else
  328. # define dprintkl(f, x...) do { /* nothing */ } while (0)
  329. #endif
  330. /* Helper macro for if branches.
  331. * An if branch marked with this macro is only taken in DEBUG mode.
  332. * Example:
  333. * if (DEBUG_ONLY(foo == bar)) {
  334. * do something
  335. * }
  336. * In DEBUG mode, the branch will be taken if (foo == bar).
  337. * In non-DEBUG mode, the branch will never be taken.
  338. */
  339. #ifdef DEBUG_ONLY
  340. # undef DEBUG_ONLY
  341. #endif
  342. #ifdef CONFIG_BCM43XX_DEBUG
  343. # define DEBUG_ONLY(x) (x)
  344. #else
  345. # define DEBUG_ONLY(x) 0
  346. #endif
  347. /* debugging printk() */
  348. #ifdef dprintk
  349. # undef dprintk
  350. #endif
  351. #ifdef CONFIG_BCM43XX_DEBUG
  352. # define dprintk(f, x...) do { printk(f ,##x); } while (0)
  353. #else
  354. # define dprintk(f, x...) do { /* nothing */ } while (0)
  355. #endif
  356. struct net_device;
  357. struct pci_dev;
  358. struct bcm43xx_dmaring;
  359. struct bcm43xx_pioqueue;
  360. struct bcm43xx_initval {
  361. u16 offset;
  362. u16 size;
  363. u32 value;
  364. } __attribute__((__packed__));
  365. /* Values for bcm430x_sprominfo.locale */
  366. enum {
  367. BCM43xx_LOCALE_WORLD = 0,
  368. BCM43xx_LOCALE_THAILAND,
  369. BCM43xx_LOCALE_ISRAEL,
  370. BCM43xx_LOCALE_JORDAN,
  371. BCM43xx_LOCALE_CHINA,
  372. BCM43xx_LOCALE_JAPAN,
  373. BCM43xx_LOCALE_USA_CANADA_ANZ,
  374. BCM43xx_LOCALE_EUROPE,
  375. BCM43xx_LOCALE_USA_LOW,
  376. BCM43xx_LOCALE_JAPAN_HIGH,
  377. BCM43xx_LOCALE_ALL,
  378. BCM43xx_LOCALE_NONE,
  379. };
  380. #define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
  381. struct bcm43xx_sprominfo {
  382. u16 boardflags2;
  383. u8 il0macaddr[6];
  384. u8 et0macaddr[6];
  385. u8 et1macaddr[6];
  386. u8 et0phyaddr:5;
  387. u8 et1phyaddr:5;
  388. u8 et0mdcport:1;
  389. u8 et1mdcport:1;
  390. u8 boardrev;
  391. u8 locale:4;
  392. u8 antennas_aphy:2;
  393. u8 antennas_bgphy:2;
  394. u16 pa0b0;
  395. u16 pa0b1;
  396. u16 pa0b2;
  397. u8 wl0gpio0;
  398. u8 wl0gpio1;
  399. u8 wl0gpio2;
  400. u8 wl0gpio3;
  401. u8 maxpower_aphy;
  402. u8 maxpower_bgphy;
  403. u16 pa1b0;
  404. u16 pa1b1;
  405. u16 pa1b2;
  406. u8 idle_tssi_tgt_aphy;
  407. u8 idle_tssi_tgt_bgphy;
  408. u16 boardflags;
  409. u16 antennagain_aphy;
  410. u16 antennagain_bgphy;
  411. };
  412. /* Value pair to measure the LocalOscillator. */
  413. struct bcm43xx_lopair {
  414. s8 low;
  415. s8 high;
  416. u8 used:1;
  417. };
  418. #define BCM43xx_LO_COUNT (14*4)
  419. struct bcm43xx_phyinfo {
  420. /* Hardware Data */
  421. u8 version;
  422. u8 type;
  423. u8 rev;
  424. u16 antenna_diversity;
  425. u16 savedpctlreg;
  426. u16 minlowsig[2];
  427. u16 minlowsigpos[2];
  428. u8 connected:1,
  429. calibrated:1,
  430. is_locked:1, /* used in bcm43xx_phy_{un}lock() */
  431. dyn_tssi_tbl:1; /* used in bcm43xx_phy_init_tssi2dbm_table() */
  432. /* LO Measurement Data.
  433. * Use bcm43xx_get_lopair() to get a value.
  434. */
  435. struct bcm43xx_lopair *_lo_pairs;
  436. /* TSSI to dBm table in use */
  437. const s8 *tssi2dbm;
  438. /* idle TSSI value */
  439. s8 idle_tssi;
  440. /* PHY lock for core.rev < 3
  441. * This lock is only used by bcm43xx_phy_{un}lock()
  442. */
  443. spinlock_t lock;
  444. };
  445. struct bcm43xx_radioinfo {
  446. u16 manufact;
  447. u16 version;
  448. u8 revision;
  449. /* 0: baseband attenuation,
  450. * 1: radio attenuation,
  451. * 2: tx_CTL1
  452. * 3: tx_CTL2
  453. */
  454. u16 txpower[4];
  455. /* Desired TX power in dBm Q5.2 */
  456. u16 txpower_desired;
  457. /* Current Interference Mitigation mode */
  458. int interfmode;
  459. /* Stack of saved values from the Interference Mitigation code */
  460. u16 interfstack[20];
  461. /* Saved values from the NRSSI Slope calculation */
  462. s16 nrssi[2];
  463. s32 nrssislope;
  464. /* In memory nrssi lookup table. */
  465. s8 nrssi_lt[64];
  466. /* current channel */
  467. u8 channel;
  468. u8 initial_channel;
  469. u16 lofcal;
  470. u16 initval;
  471. u8 enabled:1;
  472. /* ACI (adjacent channel interference) flags. */
  473. u8 aci_enable:1,
  474. aci_wlan_automatic:1,
  475. aci_hw_rssi:1;
  476. };
  477. /* Data structures for DMA transmission, per 80211 core. */
  478. struct bcm43xx_dma {
  479. struct bcm43xx_dmaring *tx_ring0;
  480. struct bcm43xx_dmaring *tx_ring1;
  481. struct bcm43xx_dmaring *tx_ring2;
  482. struct bcm43xx_dmaring *tx_ring3;
  483. struct bcm43xx_dmaring *rx_ring0;
  484. struct bcm43xx_dmaring *rx_ring1; /* only available on core.rev < 5 */
  485. };
  486. /* Data structures for PIO transmission, per 80211 core. */
  487. struct bcm43xx_pio {
  488. struct bcm43xx_pioqueue *queue0;
  489. struct bcm43xx_pioqueue *queue1;
  490. struct bcm43xx_pioqueue *queue2;
  491. struct bcm43xx_pioqueue *queue3;
  492. };
  493. #define BCM43xx_MAX_80211_CORES 2
  494. #define BCM43xx_COREFLAG_AVAILABLE (1 << 0)
  495. #define BCM43xx_COREFLAG_ENABLED (1 << 1)
  496. #define BCM43xx_COREFLAG_INITIALIZED (1 << 2)
  497. #ifdef CONFIG_BCM947XX
  498. #define core_offset(bcm) (bcm)->current_core_offset
  499. #else
  500. #define core_offset(bcm) 0
  501. #endif
  502. struct bcm43xx_coreinfo {
  503. /** Driver internal flags. See BCM43xx_COREFLAG_* */
  504. u32 flags;
  505. /** core_id ID number */
  506. u16 id;
  507. /** core_rev revision number */
  508. u8 rev;
  509. /** Index number for _switch_core() */
  510. u8 index;
  511. /* Pointer to the PHYinfo, which belongs to this core (if 80211 core) */
  512. struct bcm43xx_phyinfo *phy;
  513. /* Pointer to the RadioInfo, which belongs to this core (if 80211 core) */
  514. struct bcm43xx_radioinfo *radio;
  515. /* Pointer to the DMA rings, which belong to this core (if 80211 core) */
  516. struct bcm43xx_dma *dma;
  517. /* Pointer to the PIO queues, which belong to this core (if 80211 core) */
  518. struct bcm43xx_pio *pio;
  519. };
  520. /* Context information for a noise calculation (Link Quality). */
  521. struct bcm43xx_noise_calculation {
  522. struct bcm43xx_coreinfo *core_at_start;
  523. u8 channel_at_start;
  524. u8 calculation_running:1;
  525. u8 nr_samples;
  526. s8 samples[8][4];
  527. };
  528. struct bcm43xx_stats {
  529. u8 link_quality;
  530. /* Store the last TX/RX times here for updating the leds. */
  531. unsigned long last_tx;
  532. unsigned long last_rx;
  533. };
  534. struct bcm43xx_key {
  535. u8 enabled:1;
  536. u8 algorithm;
  537. };
  538. struct bcm43xx_private {
  539. struct bcm43xx_sysfs sysfs;
  540. struct ieee80211_device *ieee;
  541. struct ieee80211softmac_device *softmac;
  542. struct net_device *net_dev;
  543. struct pci_dev *pci_dev;
  544. unsigned int irq;
  545. void __iomem *mmio_addr;
  546. unsigned int mmio_len;
  547. /* Do not use the lock directly. Use the bcm43xx_lock* helper
  548. * functions, to be MMIO-safe. */
  549. spinlock_t _lock;
  550. /* Driver status flags. */
  551. u32 initialized:1, /* init_board() succeed */
  552. was_initialized:1, /* for PCI suspend/resume. */
  553. shutting_down:1, /* free_board() in progress */
  554. __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
  555. bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
  556. reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
  557. powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
  558. short_preamble:1, /* TRUE, if short preamble is enabled. */
  559. firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
  560. struct bcm43xx_stats stats;
  561. /* Bus type we are connected to.
  562. * This is currently always BCM43xx_BUSTYPE_PCI
  563. */
  564. u8 bustype;
  565. u16 board_vendor;
  566. u16 board_type;
  567. u16 board_revision;
  568. u16 chip_id;
  569. u8 chip_rev;
  570. struct bcm43xx_sprominfo sprom;
  571. #define BCM43xx_NR_LEDS 4
  572. struct bcm43xx_led leds[BCM43xx_NR_LEDS];
  573. /* The currently active core. NULL if not initialized, yet. */
  574. struct bcm43xx_coreinfo *current_core;
  575. #ifdef CONFIG_BCM947XX
  576. /** current core memory offset */
  577. u32 current_core_offset;
  578. #endif
  579. struct bcm43xx_coreinfo *active_80211_core;
  580. /* coreinfo structs for all possible cores follow.
  581. * Note that a core might not exist.
  582. * So check the coreinfo flags before using it.
  583. */
  584. struct bcm43xx_coreinfo core_chipcommon;
  585. struct bcm43xx_coreinfo core_pci;
  586. struct bcm43xx_coreinfo core_v90;
  587. struct bcm43xx_coreinfo core_pcmcia;
  588. struct bcm43xx_coreinfo core_ethernet;
  589. struct bcm43xx_coreinfo core_80211[ BCM43xx_MAX_80211_CORES ];
  590. /* Info about the PHY for each 80211 core. */
  591. struct bcm43xx_phyinfo phy[ BCM43xx_MAX_80211_CORES ];
  592. /* Info about the Radio for each 80211 core. */
  593. struct bcm43xx_radioinfo radio[ BCM43xx_MAX_80211_CORES ];
  594. /* DMA */
  595. struct bcm43xx_dma dma[ BCM43xx_MAX_80211_CORES ];
  596. /* PIO */
  597. struct bcm43xx_pio pio[ BCM43xx_MAX_80211_CORES ];
  598. u32 chipcommon_capabilities;
  599. /* Reason code of the last interrupt. */
  600. u32 irq_reason;
  601. u32 dma_reason[4];
  602. /* saved irq enable/disable state bitfield. */
  603. u32 irq_savedstate;
  604. /* Link Quality calculation context. */
  605. struct bcm43xx_noise_calculation noisecalc;
  606. /* Threshold values. */
  607. //TODO: The RTS thr has to be _used_. Currently, it is only set via WX.
  608. u32 rts_threshold;
  609. /* Interrupt Service Routine tasklet (bottom-half) */
  610. struct tasklet_struct isr_tasklet;
  611. /* Periodic tasks */
  612. struct timer_list periodic_tasks;
  613. unsigned int periodic_state;
  614. struct work_struct restart_work;
  615. /* Informational stuff. */
  616. char nick[IW_ESSID_MAX_SIZE + 1];
  617. /* encryption/decryption */
  618. u16 security_offset;
  619. struct bcm43xx_key key[54];
  620. u8 default_key_idx;
  621. /* Firmware. */
  622. const struct firmware *ucode;
  623. const struct firmware *pcm;
  624. const struct firmware *initvals0;
  625. const struct firmware *initvals1;
  626. /* Debugging stuff follows. */
  627. #ifdef CONFIG_BCM43XX_DEBUG
  628. struct bcm43xx_dfsentry *dfsentry;
  629. #endif
  630. };
  631. /* bcm43xx_(un)lock() protect struct bcm43xx_private.
  632. * Note that _NO_ MMIO writes are allowed. If you want to
  633. * write to the device through MMIO in the critical section, use
  634. * the *_mmio lock functions.
  635. * MMIO read-access is allowed, though.
  636. */
  637. #define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags)
  638. #define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags)
  639. /* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO.
  640. * MMIO write-access to the device is allowed.
  641. * All MMIO writes are flushed on unlock, so it is guaranteed to not
  642. * interfere with other threads writing MMIO registers.
  643. */
  644. #define bcm43xx_lock_mmio(bcm, flags) bcm43xx_lock(bcm, flags)
  645. #define bcm43xx_unlock_mmio(bcm, flags) do { mmiowb(); bcm43xx_unlock(bcm, flags); } while (0)
  646. static inline
  647. struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
  648. {
  649. return ieee80211softmac_priv(dev);
  650. }
  651. /* Helper function, which returns a boolean.
  652. * TRUE, if PIO is used; FALSE, if DMA is used.
  653. */
  654. #if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
  655. static inline
  656. int bcm43xx_using_pio(struct bcm43xx_private *bcm)
  657. {
  658. return bcm->__using_pio;
  659. }
  660. #elif defined(CONFIG_BCM43XX_DMA)
  661. static inline
  662. int bcm43xx_using_pio(struct bcm43xx_private *bcm)
  663. {
  664. return 0;
  665. }
  666. #elif defined(CONFIG_BCM43XX_PIO)
  667. static inline
  668. int bcm43xx_using_pio(struct bcm43xx_private *bcm)
  669. {
  670. return 1;
  671. }
  672. #else
  673. # error "Using neither DMA nor PIO? Confused..."
  674. #endif
  675. static inline
  676. int bcm43xx_num_80211_cores(struct bcm43xx_private *bcm)
  677. {
  678. int i, cnt = 0;
  679. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  680. if (bcm->core_80211[i].flags & BCM43xx_COREFLAG_AVAILABLE)
  681. cnt++;
  682. }
  683. return cnt;
  684. }
  685. /* Are we running in init_board() context? */
  686. static inline
  687. int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
  688. {
  689. if (bcm->initialized)
  690. return 0;
  691. if (bcm->shutting_down)
  692. return 0;
  693. return 1;
  694. }
  695. static inline
  696. struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
  697. u16 radio_attenuation,
  698. u16 baseband_attenuation)
  699. {
  700. return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
  701. }
  702. static inline
  703. u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
  704. {
  705. return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
  706. }
  707. static inline
  708. void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
  709. {
  710. iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
  711. }
  712. static inline
  713. u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
  714. {
  715. return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
  716. }
  717. static inline
  718. void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
  719. {
  720. iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
  721. }
  722. static inline
  723. int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
  724. {
  725. return pci_read_config_word(bcm->pci_dev, offset, value);
  726. }
  727. static inline
  728. int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
  729. {
  730. return pci_read_config_dword(bcm->pci_dev, offset, value);
  731. }
  732. static inline
  733. int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
  734. {
  735. return pci_write_config_word(bcm->pci_dev, offset, value);
  736. }
  737. static inline
  738. int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
  739. {
  740. return pci_write_config_dword(bcm->pci_dev, offset, value);
  741. }
  742. /** Limit a value between two limits */
  743. #ifdef limit_value
  744. # undef limit_value
  745. #endif
  746. #define limit_value(value, min, max) \
  747. ({ \
  748. typeof(value) __value = (value); \
  749. typeof(value) __min = (min); \
  750. typeof(value) __max = (max); \
  751. if (__value < __min) \
  752. __value = __min; \
  753. else if (__value > __max) \
  754. __value = __max; \
  755. __value; \
  756. })
  757. /** Helpers to print MAC addresses. */
  758. #define BCM43xx_MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
  759. #define BCM43xx_MACARG(x) ((u8*)(x))[0], ((u8*)(x))[1], \
  760. ((u8*)(x))[2], ((u8*)(x))[3], \
  761. ((u8*)(x))[4], ((u8*)(x))[5]
  762. #endif /* BCM43xx_H_ */