bcm43xx.h 27 KB

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