bcm43xx.h 27 KB

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