bcm43xx.h 25 KB

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