bcm43xx.h 27 KB

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