bcm43xx.h 28 KB

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