bcm43xx.h 28 KB

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