b43legacy.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. #ifndef B43legacy_H_
  2. #define B43legacy_H_
  3. #include <linux/hw_random.h>
  4. #include <linux/kernel.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/stringify.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/pci.h>
  10. #include <asm/atomic.h>
  11. #include <linux/io.h>
  12. #include <linux/ssb/ssb.h>
  13. #include <linux/ssb/ssb_driver_chipcommon.h>
  14. #include <linux/wireless.h>
  15. #include <net/mac80211.h>
  16. #include "debugfs.h"
  17. #include "leds.h"
  18. #include "rfkill.h"
  19. #include "phy.h"
  20. #define B43legacy_IRQWAIT_MAX_RETRIES 100
  21. #define B43legacy_RX_MAX_SSI 60 /* best guess at max ssi */
  22. /* MMIO offsets */
  23. #define B43legacy_MMIO_DMA0_REASON 0x20
  24. #define B43legacy_MMIO_DMA0_IRQ_MASK 0x24
  25. #define B43legacy_MMIO_DMA1_REASON 0x28
  26. #define B43legacy_MMIO_DMA1_IRQ_MASK 0x2C
  27. #define B43legacy_MMIO_DMA2_REASON 0x30
  28. #define B43legacy_MMIO_DMA2_IRQ_MASK 0x34
  29. #define B43legacy_MMIO_DMA3_REASON 0x38
  30. #define B43legacy_MMIO_DMA3_IRQ_MASK 0x3C
  31. #define B43legacy_MMIO_DMA4_REASON 0x40
  32. #define B43legacy_MMIO_DMA4_IRQ_MASK 0x44
  33. #define B43legacy_MMIO_DMA5_REASON 0x48
  34. #define B43legacy_MMIO_DMA5_IRQ_MASK 0x4C
  35. #define B43legacy_MMIO_MACCTL 0x120
  36. #define B43legacy_MMIO_STATUS_BITFIELD 0x120
  37. #define B43legacy_MMIO_STATUS2_BITFIELD 0x124
  38. #define B43legacy_MMIO_GEN_IRQ_REASON 0x128
  39. #define B43legacy_MMIO_GEN_IRQ_MASK 0x12C
  40. #define B43legacy_MMIO_RAM_CONTROL 0x130
  41. #define B43legacy_MMIO_RAM_DATA 0x134
  42. #define B43legacy_MMIO_PS_STATUS 0x140
  43. #define B43legacy_MMIO_RADIO_HWENABLED_HI 0x158
  44. #define B43legacy_MMIO_SHM_CONTROL 0x160
  45. #define B43legacy_MMIO_SHM_DATA 0x164
  46. #define B43legacy_MMIO_SHM_DATA_UNALIGNED 0x166
  47. #define B43legacy_MMIO_XMITSTAT_0 0x170
  48. #define B43legacy_MMIO_XMITSTAT_1 0x174
  49. #define B43legacy_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
  50. #define B43legacy_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
  51. /* 32-bit DMA */
  52. #define B43legacy_MMIO_DMA32_BASE0 0x200
  53. #define B43legacy_MMIO_DMA32_BASE1 0x220
  54. #define B43legacy_MMIO_DMA32_BASE2 0x240
  55. #define B43legacy_MMIO_DMA32_BASE3 0x260
  56. #define B43legacy_MMIO_DMA32_BASE4 0x280
  57. #define B43legacy_MMIO_DMA32_BASE5 0x2A0
  58. /* 64-bit DMA */
  59. #define B43legacy_MMIO_DMA64_BASE0 0x200
  60. #define B43legacy_MMIO_DMA64_BASE1 0x240
  61. #define B43legacy_MMIO_DMA64_BASE2 0x280
  62. #define B43legacy_MMIO_DMA64_BASE3 0x2C0
  63. #define B43legacy_MMIO_DMA64_BASE4 0x300
  64. #define B43legacy_MMIO_DMA64_BASE5 0x340
  65. /* PIO */
  66. #define B43legacy_MMIO_PIO1_BASE 0x300
  67. #define B43legacy_MMIO_PIO2_BASE 0x310
  68. #define B43legacy_MMIO_PIO3_BASE 0x320
  69. #define B43legacy_MMIO_PIO4_BASE 0x330
  70. #define B43legacy_MMIO_PHY_VER 0x3E0
  71. #define B43legacy_MMIO_PHY_RADIO 0x3E2
  72. #define B43legacy_MMIO_PHY0 0x3E6
  73. #define B43legacy_MMIO_ANTENNA 0x3E8
  74. #define B43legacy_MMIO_CHANNEL 0x3F0
  75. #define B43legacy_MMIO_CHANNEL_EXT 0x3F4
  76. #define B43legacy_MMIO_RADIO_CONTROL 0x3F6
  77. #define B43legacy_MMIO_RADIO_DATA_HIGH 0x3F8
  78. #define B43legacy_MMIO_RADIO_DATA_LOW 0x3FA
  79. #define B43legacy_MMIO_PHY_CONTROL 0x3FC
  80. #define B43legacy_MMIO_PHY_DATA 0x3FE
  81. #define B43legacy_MMIO_MACFILTER_CONTROL 0x420
  82. #define B43legacy_MMIO_MACFILTER_DATA 0x422
  83. #define B43legacy_MMIO_RCMTA_COUNT 0x43C /* Receive Match Transmitter Addr */
  84. #define B43legacy_MMIO_RADIO_HWENABLED_LO 0x49A
  85. #define B43legacy_MMIO_GPIO_CONTROL 0x49C
  86. #define B43legacy_MMIO_GPIO_MASK 0x49E
  87. #define B43legacy_MMIO_TSF_0 0x632 /* core rev < 3 only */
  88. #define B43legacy_MMIO_TSF_1 0x634 /* core rev < 3 only */
  89. #define B43legacy_MMIO_TSF_2 0x636 /* core rev < 3 only */
  90. #define B43legacy_MMIO_TSF_3 0x638 /* core rev < 3 only */
  91. #define B43legacy_MMIO_RNG 0x65A
  92. #define B43legacy_MMIO_POWERUP_DELAY 0x6A8
  93. /* SPROM boardflags_lo values */
  94. #define B43legacy_BFL_PACTRL 0x0002
  95. #define B43legacy_BFL_RSSI 0x0008
  96. #define B43legacy_BFL_EXTLNA 0x1000
  97. /* GPIO register offset, in both ChipCommon and PCI core. */
  98. #define B43legacy_GPIO_CONTROL 0x6c
  99. /* SHM Routing */
  100. #define B43legacy_SHM_SHARED 0x0001
  101. #define B43legacy_SHM_WIRELESS 0x0002
  102. #define B43legacy_SHM_HW 0x0004
  103. #define B43legacy_SHM_UCODE 0x0300
  104. /* SHM Routing modifiers */
  105. #define B43legacy_SHM_AUTOINC_R 0x0200 /* Read Auto-increment */
  106. #define B43legacy_SHM_AUTOINC_W 0x0100 /* Write Auto-increment */
  107. #define B43legacy_SHM_AUTOINC_RW (B43legacy_SHM_AUTOINC_R | \
  108. B43legacy_SHM_AUTOINC_W)
  109. /* Misc SHM_SHARED offsets */
  110. #define B43legacy_SHM_SH_WLCOREREV 0x0016 /* 802.11 core revision */
  111. #define B43legacy_SHM_SH_HOSTFLO 0x005E /* Hostflags ucode opts (low) */
  112. #define B43legacy_SHM_SH_HOSTFHI 0x0060 /* Hostflags ucode opts (high) */
  113. /* SHM_SHARED crypto engine */
  114. #define B43legacy_SHM_SH_KEYIDXBLOCK 0x05D4 /* Key index/algorithm block */
  115. /* SHM_SHARED beacon variables */
  116. #define B43legacy_SHM_SH_BEACPHYCTL 0x0054 /* Beacon PHY TX control word */
  117. /* SHM_SHARED ACK/CTS control */
  118. #define B43legacy_SHM_SH_ACKCTSPHYCTL 0x0022 /* ACK/CTS PHY control word */
  119. /* SHM_SHARED probe response variables */
  120. #define B43legacy_SHM_SH_PRPHYCTL 0x0188 /* Probe Resp PHY TX control */
  121. #define B43legacy_SHM_SH_PRMAXTIME 0x0074 /* Probe Response max time */
  122. /* SHM_SHARED rate tables */
  123. /* SHM_SHARED microcode soft registers */
  124. #define B43legacy_SHM_SH_UCODEREV 0x0000 /* Microcode revision */
  125. #define B43legacy_SHM_SH_UCODEPATCH 0x0002 /* Microcode patchlevel */
  126. #define B43legacy_SHM_SH_UCODEDATE 0x0004 /* Microcode date */
  127. #define B43legacy_SHM_SH_UCODETIME 0x0006 /* Microcode time */
  128. #define B43legacy_UCODEFLAGS_OFFSET 0x005E
  129. /* Hardware Radio Enable masks */
  130. #define B43legacy_MMIO_RADIO_HWENABLED_HI_MASK (1 << 16)
  131. #define B43legacy_MMIO_RADIO_HWENABLED_LO_MASK (1 << 4)
  132. /* HostFlags. See b43legacy_hf_read/write() */
  133. #define B43legacy_HF_SYMW 0x00000002 /* G-PHY SYM workaround */
  134. #define B43legacy_HF_GDCW 0x00000020 /* G-PHY DV cancel filter */
  135. #define B43legacy_HF_OFDMPABOOST 0x00000040 /* Enable PA boost OFDM */
  136. #define B43legacy_HF_EDCF 0x00000100 /* on if WME/MAC suspended */
  137. /* MacFilter offsets. */
  138. #define B43legacy_MACFILTER_SELF 0x0000
  139. #define B43legacy_MACFILTER_BSSID 0x0003
  140. #define B43legacy_MACFILTER_MAC 0x0010
  141. /* PHYVersioning */
  142. #define B43legacy_PHYTYPE_B 0x01
  143. #define B43legacy_PHYTYPE_G 0x02
  144. /* PHYRegisters */
  145. #define B43legacy_PHY_G_LO_CONTROL 0x0810
  146. #define B43legacy_PHY_ILT_G_CTRL 0x0472
  147. #define B43legacy_PHY_ILT_G_DATA1 0x0473
  148. #define B43legacy_PHY_ILT_G_DATA2 0x0474
  149. #define B43legacy_PHY_G_PCTL 0x0029
  150. #define B43legacy_PHY_RADIO_BITFIELD 0x0401
  151. #define B43legacy_PHY_G_CRS 0x0429
  152. #define B43legacy_PHY_NRSSILT_CTRL 0x0803
  153. #define B43legacy_PHY_NRSSILT_DATA 0x0804
  154. /* RadioRegisters */
  155. #define B43legacy_RADIOCTL_ID 0x01
  156. /* MAC Control bitfield */
  157. #define B43legacy_MACCTL_IHR_ENABLED 0x00000400 /* IHR Region Enabled */
  158. #define B43legacy_MACCTL_INFRA 0x00020000 /* Infrastructure mode */
  159. #define B43legacy_MACCTL_AP 0x00040000 /* AccessPoint mode */
  160. #define B43legacy_MACCTL_BEACPROMISC 0x00100000 /* Beacon Promiscuous */
  161. #define B43legacy_MACCTL_KEEP_BADPLCP 0x00200000 /* Keep bad PLCP frames */
  162. #define B43legacy_MACCTL_KEEP_CTL 0x00400000 /* Keep control frames */
  163. #define B43legacy_MACCTL_KEEP_BAD 0x00800000 /* Keep bad frames (FCS) */
  164. #define B43legacy_MACCTL_PROMISC 0x01000000 /* Promiscuous mode */
  165. #define B43legacy_MACCTL_GMODE 0x80000000 /* G Mode */
  166. /* StatusBitField */
  167. #define B43legacy_SBF_MAC_ENABLED 0x00000001
  168. #define B43legacy_SBF_CORE_READY 0x00000004
  169. #define B43legacy_SBF_400 0x00000400 /*FIXME: fix name*/
  170. #define B43legacy_SBF_XFER_REG_BYTESWAP 0x00010000
  171. #define B43legacy_SBF_MODE_NOTADHOC 0x00020000
  172. #define B43legacy_SBF_MODE_AP 0x00040000
  173. #define B43legacy_SBF_RADIOREG_LOCK 0x00080000
  174. #define B43legacy_SBF_MODE_MONITOR 0x00400000
  175. #define B43legacy_SBF_MODE_PROMISC 0x01000000
  176. #define B43legacy_SBF_PS1 0x02000000
  177. #define B43legacy_SBF_PS2 0x04000000
  178. #define B43legacy_SBF_NO_SSID_BCAST 0x08000000
  179. #define B43legacy_SBF_TIME_UPDATE 0x10000000
  180. /* 802.11 core specific TM State Low flags */
  181. #define B43legacy_TMSLOW_GMODE 0x20000000 /* G Mode Enable */
  182. #define B43legacy_TMSLOW_PLLREFSEL 0x00200000 /* PLL Freq Ref Select */
  183. #define B43legacy_TMSLOW_MACPHYCLKEN 0x00100000 /* MAC PHY Clock Ctrl Enbl */
  184. #define B43legacy_TMSLOW_PHYRESET 0x00080000 /* PHY Reset */
  185. #define B43legacy_TMSLOW_PHYCLKEN 0x00040000 /* PHY Clock Enable */
  186. /* 802.11 core specific TM State High flags */
  187. #define B43legacy_TMSHIGH_FCLOCK 0x00040000 /* Fast Clock Available */
  188. #define B43legacy_TMSHIGH_GPHY 0x00010000 /* G-PHY avail (rev >= 5) */
  189. #define B43legacy_UCODEFLAG_AUTODIV 0x0001
  190. /* Generic-Interrupt reasons. */
  191. #define B43legacy_IRQ_MAC_SUSPENDED 0x00000001
  192. #define B43legacy_IRQ_BEACON 0x00000002
  193. #define B43legacy_IRQ_TBTT_INDI 0x00000004 /* Target Beacon Transmit Time */
  194. #define B43legacy_IRQ_BEACON_TX_OK 0x00000008
  195. #define B43legacy_IRQ_BEACON_CANCEL 0x00000010
  196. #define B43legacy_IRQ_ATIM_END 0x00000020
  197. #define B43legacy_IRQ_PMQ 0x00000040
  198. #define B43legacy_IRQ_PIO_WORKAROUND 0x00000100
  199. #define B43legacy_IRQ_MAC_TXERR 0x00000200
  200. #define B43legacy_IRQ_PHY_TXERR 0x00000800
  201. #define B43legacy_IRQ_PMEVENT 0x00001000
  202. #define B43legacy_IRQ_TIMER0 0x00002000
  203. #define B43legacy_IRQ_TIMER1 0x00004000
  204. #define B43legacy_IRQ_DMA 0x00008000
  205. #define B43legacy_IRQ_TXFIFO_FLUSH_OK 0x00010000
  206. #define B43legacy_IRQ_CCA_MEASURE_OK 0x00020000
  207. #define B43legacy_IRQ_NOISESAMPLE_OK 0x00040000
  208. #define B43legacy_IRQ_UCODE_DEBUG 0x08000000
  209. #define B43legacy_IRQ_RFKILL 0x10000000
  210. #define B43legacy_IRQ_TX_OK 0x20000000
  211. #define B43legacy_IRQ_PHY_G_CHANGED 0x40000000
  212. #define B43legacy_IRQ_TIMEOUT 0x80000000
  213. #define B43legacy_IRQ_ALL 0xFFFFFFFF
  214. #define B43legacy_IRQ_MASKTEMPLATE (B43legacy_IRQ_MAC_SUSPENDED | \
  215. B43legacy_IRQ_BEACON | \
  216. B43legacy_IRQ_TBTT_INDI | \
  217. B43legacy_IRQ_ATIM_END | \
  218. B43legacy_IRQ_PMQ | \
  219. B43legacy_IRQ_MAC_TXERR | \
  220. B43legacy_IRQ_PHY_TXERR | \
  221. B43legacy_IRQ_DMA | \
  222. B43legacy_IRQ_TXFIFO_FLUSH_OK | \
  223. B43legacy_IRQ_NOISESAMPLE_OK | \
  224. B43legacy_IRQ_UCODE_DEBUG | \
  225. B43legacy_IRQ_RFKILL | \
  226. B43legacy_IRQ_TX_OK)
  227. /* Device specific rate values.
  228. * The actual values defined here are (rate_in_mbps * 2).
  229. * Some code depends on this. Don't change it. */
  230. #define B43legacy_CCK_RATE_1MB 2
  231. #define B43legacy_CCK_RATE_2MB 4
  232. #define B43legacy_CCK_RATE_5MB 11
  233. #define B43legacy_CCK_RATE_11MB 22
  234. #define B43legacy_OFDM_RATE_6MB 12
  235. #define B43legacy_OFDM_RATE_9MB 18
  236. #define B43legacy_OFDM_RATE_12MB 24
  237. #define B43legacy_OFDM_RATE_18MB 36
  238. #define B43legacy_OFDM_RATE_24MB 48
  239. #define B43legacy_OFDM_RATE_36MB 72
  240. #define B43legacy_OFDM_RATE_48MB 96
  241. #define B43legacy_OFDM_RATE_54MB 108
  242. /* Convert a b43legacy rate value to a rate in 100kbps */
  243. #define B43legacy_RATE_TO_100KBPS(rate) (((rate) * 10) / 2)
  244. #define B43legacy_DEFAULT_SHORT_RETRY_LIMIT 7
  245. #define B43legacy_DEFAULT_LONG_RETRY_LIMIT 4
  246. #define B43legacy_PHY_TX_BADNESS_LIMIT 1000
  247. /* Max size of a security key */
  248. #define B43legacy_SEC_KEYSIZE 16
  249. /* Security algorithms. */
  250. enum {
  251. B43legacy_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
  252. B43legacy_SEC_ALGO_WEP40,
  253. B43legacy_SEC_ALGO_TKIP,
  254. B43legacy_SEC_ALGO_AES,
  255. B43legacy_SEC_ALGO_WEP104,
  256. B43legacy_SEC_ALGO_AES_LEGACY,
  257. };
  258. /* Core Information Registers */
  259. #define B43legacy_CIR_BASE 0xf00
  260. #define B43legacy_CIR_SBTPSFLAG (B43legacy_CIR_BASE + 0x18)
  261. #define B43legacy_CIR_SBIMSTATE (B43legacy_CIR_BASE + 0x90)
  262. #define B43legacy_CIR_SBINTVEC (B43legacy_CIR_BASE + 0x94)
  263. #define B43legacy_CIR_SBTMSTATELOW (B43legacy_CIR_BASE + 0x98)
  264. #define B43legacy_CIR_SBTMSTATEHIGH (B43legacy_CIR_BASE + 0x9c)
  265. #define B43legacy_CIR_SBIMCONFIGLOW (B43legacy_CIR_BASE + 0xa8)
  266. #define B43legacy_CIR_SB_ID_HI (B43legacy_CIR_BASE + 0xfc)
  267. /* sbtmstatehigh state flags */
  268. #define B43legacy_SBTMSTATEHIGH_SERROR 0x00000001
  269. #define B43legacy_SBTMSTATEHIGH_BUSY 0x00000004
  270. #define B43legacy_SBTMSTATEHIGH_TIMEOUT 0x00000020
  271. #define B43legacy_SBTMSTATEHIGH_G_PHY_AVAIL 0x00010000
  272. #define B43legacy_SBTMSTATEHIGH_COREFLAGS 0x1FFF0000
  273. #define B43legacy_SBTMSTATEHIGH_DMA64BIT 0x10000000
  274. #define B43legacy_SBTMSTATEHIGH_GATEDCLK 0x20000000
  275. #define B43legacy_SBTMSTATEHIGH_BISTFAILED 0x40000000
  276. #define B43legacy_SBTMSTATEHIGH_BISTCOMPLETE 0x80000000
  277. /* sbimstate flags */
  278. #define B43legacy_SBIMSTATE_IB_ERROR 0x20000
  279. #define B43legacy_SBIMSTATE_TIMEOUT 0x40000
  280. #define PFX KBUILD_MODNAME ": "
  281. #ifdef assert
  282. # undef assert
  283. #endif
  284. #ifdef CONFIG_B43LEGACY_DEBUG
  285. # define B43legacy_WARN_ON(expr) \
  286. do { \
  287. if (unlikely((expr))) { \
  288. printk(KERN_INFO PFX "Test (%s) failed at:" \
  289. " %s:%d:%s()\n", \
  290. #expr, __FILE__, \
  291. __LINE__, __FUNCTION__); \
  292. } \
  293. } while (0)
  294. # define B43legacy_BUG_ON(expr) \
  295. do { \
  296. if (unlikely((expr))) { \
  297. printk(KERN_INFO PFX "Test (%s) failed\n", \
  298. #expr); \
  299. BUG_ON(expr); \
  300. } \
  301. } while (0)
  302. # define B43legacy_DEBUG 1
  303. #else
  304. # define B43legacy_WARN_ON(x) do { /* nothing */ } while (0)
  305. # define B43legacy_BUG_ON(x) do { /* nothing */ } while (0)
  306. # define B43legacy_DEBUG 0
  307. #endif
  308. struct net_device;
  309. struct pci_dev;
  310. struct b43legacy_dmaring;
  311. struct b43legacy_pioqueue;
  312. /* The firmware file header */
  313. #define B43legacy_FW_TYPE_UCODE 'u'
  314. #define B43legacy_FW_TYPE_PCM 'p'
  315. #define B43legacy_FW_TYPE_IV 'i'
  316. struct b43legacy_fw_header {
  317. /* File type */
  318. u8 type;
  319. /* File format version */
  320. u8 ver;
  321. u8 __padding[2];
  322. /* Size of the data. For ucode and PCM this is in bytes.
  323. * For IV this is number-of-ivs. */
  324. __be32 size;
  325. } __attribute__((__packed__));
  326. /* Initial Value file format */
  327. #define B43legacy_IV_OFFSET_MASK 0x7FFF
  328. #define B43legacy_IV_32BIT 0x8000
  329. struct b43legacy_iv {
  330. __be16 offset_size;
  331. union {
  332. __be16 d16;
  333. __be32 d32;
  334. } data __attribute__((__packed__));
  335. } __attribute__((__packed__));
  336. #define B43legacy_PHYMODE(phytype) (1 << (phytype))
  337. #define B43legacy_PHYMODE_B B43legacy_PHYMODE \
  338. ((B43legacy_PHYTYPE_B))
  339. #define B43legacy_PHYMODE_G B43legacy_PHYMODE \
  340. ((B43legacy_PHYTYPE_G))
  341. /* Value pair to measure the LocalOscillator. */
  342. struct b43legacy_lopair {
  343. s8 low;
  344. s8 high;
  345. u8 used:1;
  346. };
  347. #define B43legacy_LO_COUNT (14*4)
  348. struct b43legacy_phy {
  349. /* Possible PHYMODEs on this PHY */
  350. u8 possible_phymodes;
  351. /* GMODE bit enabled in MACCTL? */
  352. bool gmode;
  353. /* Possible ieee80211 subsystem hwmodes for this PHY.
  354. * Which mode is selected, depends on thr GMODE enabled bit */
  355. #define B43legacy_MAX_PHYHWMODES 2
  356. struct ieee80211_hw_mode hwmodes[B43legacy_MAX_PHYHWMODES];
  357. /* Analog Type */
  358. u8 analog;
  359. /* B43legacy_PHYTYPE_ */
  360. u8 type;
  361. /* PHY revision number. */
  362. u8 rev;
  363. u16 antenna_diversity;
  364. u16 savedpctlreg;
  365. /* Radio versioning */
  366. u16 radio_manuf; /* Radio manufacturer */
  367. u16 radio_ver; /* Radio version */
  368. u8 calibrated:1;
  369. u8 radio_rev; /* Radio revision */
  370. bool locked; /* Only used in b43legacy_phy_{un}lock() */
  371. bool dyn_tssi_tbl; /* tssi2dbm is kmalloc()ed. */
  372. /* ACI (adjacent channel interference) flags. */
  373. bool aci_enable;
  374. bool aci_wlan_automatic;
  375. bool aci_hw_rssi;
  376. /* Radio switched on/off */
  377. bool radio_on;
  378. struct {
  379. /* Values saved when turning the radio off.
  380. * They are needed when turning it on again. */
  381. bool valid;
  382. u16 rfover;
  383. u16 rfoverval;
  384. } radio_off_context;
  385. u16 minlowsig[2];
  386. u16 minlowsigpos[2];
  387. /* LO Measurement Data.
  388. * Use b43legacy_get_lopair() to get a value.
  389. */
  390. struct b43legacy_lopair *_lo_pairs;
  391. /* TSSI to dBm table in use */
  392. const s8 *tssi2dbm;
  393. /* idle TSSI value */
  394. s8 idle_tssi;
  395. /* Target idle TSSI */
  396. int tgt_idle_tssi;
  397. /* Current idle TSSI */
  398. int cur_idle_tssi;
  399. /* LocalOscillator control values. */
  400. struct b43legacy_txpower_lo_control *lo_control;
  401. /* Values from b43legacy_calc_loopback_gain() */
  402. s16 max_lb_gain; /* Maximum Loopback gain in hdB */
  403. s16 trsw_rx_gain; /* TRSW RX gain in hdB */
  404. s16 lna_lod_gain; /* LNA lod */
  405. s16 lna_gain; /* LNA */
  406. s16 pga_gain; /* PGA */
  407. /* PHY lock for core.rev < 3
  408. * This lock is only used by b43legacy_phy_{un}lock()
  409. */
  410. spinlock_t lock;
  411. /* Desired TX power level (in dBm). This is set by the user and
  412. * adjusted in b43legacy_phy_xmitpower(). */
  413. u8 power_level;
  414. /* Values from b43legacy_calc_loopback_gain() */
  415. u16 loopback_gain[2];
  416. /* TX Power control values. */
  417. /* B/G PHY */
  418. struct {
  419. /* Current Radio Attenuation for TXpower recalculation. */
  420. u16 rfatt;
  421. /* Current Baseband Attenuation for TXpower recalculation. */
  422. u16 bbatt;
  423. /* Current TXpower control value for TXpower recalculation. */
  424. u16 txctl1;
  425. u16 txctl2;
  426. };
  427. /* A PHY */
  428. struct {
  429. u16 txpwr_offset;
  430. };
  431. #ifdef CONFIG_B43LEGACY_DEBUG
  432. bool manual_txpower_control; /* Manual TX-power control enabled? */
  433. #endif
  434. /* Current Interference Mitigation mode */
  435. int interfmode;
  436. /* Stack of saved values from the Interference Mitigation code.
  437. * Each value in the stack is layed out as follows:
  438. * bit 0-11: offset
  439. * bit 12-15: register ID
  440. * bit 16-32: value
  441. * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
  442. */
  443. #define B43legacy_INTERFSTACK_SIZE 26
  444. u32 interfstack[B43legacy_INTERFSTACK_SIZE];
  445. /* Saved values from the NRSSI Slope calculation */
  446. s16 nrssi[2];
  447. s32 nrssislope;
  448. /* In memory nrssi lookup table. */
  449. s8 nrssi_lt[64];
  450. /* current channel */
  451. u8 channel;
  452. u16 lofcal;
  453. u16 initval;
  454. /* PHY TX errors counter. */
  455. atomic_t txerr_cnt;
  456. };
  457. /* Data structures for DMA transmission, per 80211 core. */
  458. struct b43legacy_dma {
  459. struct b43legacy_dmaring *tx_ring0;
  460. struct b43legacy_dmaring *tx_ring1;
  461. struct b43legacy_dmaring *tx_ring2;
  462. struct b43legacy_dmaring *tx_ring3;
  463. struct b43legacy_dmaring *tx_ring4;
  464. struct b43legacy_dmaring *tx_ring5;
  465. struct b43legacy_dmaring *rx_ring0;
  466. struct b43legacy_dmaring *rx_ring3; /* only on core.rev < 5 */
  467. };
  468. /* Data structures for PIO transmission, per 80211 core. */
  469. struct b43legacy_pio {
  470. struct b43legacy_pioqueue *queue0;
  471. struct b43legacy_pioqueue *queue1;
  472. struct b43legacy_pioqueue *queue2;
  473. struct b43legacy_pioqueue *queue3;
  474. };
  475. /* Context information for a noise calculation (Link Quality). */
  476. struct b43legacy_noise_calculation {
  477. u8 channel_at_start;
  478. bool calculation_running;
  479. u8 nr_samples;
  480. s8 samples[8][4];
  481. };
  482. struct b43legacy_stats {
  483. u8 link_noise;
  484. /* Store the last TX/RX times here for updating the leds. */
  485. unsigned long last_tx;
  486. unsigned long last_rx;
  487. };
  488. struct b43legacy_key {
  489. void *keyconf;
  490. bool enabled;
  491. u8 algorithm;
  492. };
  493. struct b43legacy_wldev;
  494. /* Data structure for the WLAN parts (802.11 cores) of the b43legacy chip. */
  495. struct b43legacy_wl {
  496. /* Pointer to the active wireless device on this chip */
  497. struct b43legacy_wldev *current_dev;
  498. /* Pointer to the ieee80211 hardware data structure */
  499. struct ieee80211_hw *hw;
  500. spinlock_t irq_lock; /* locks IRQ */
  501. struct mutex mutex; /* locks wireless core state */
  502. spinlock_t leds_lock; /* lock for leds */
  503. /* We can only have one operating interface (802.11 core)
  504. * at a time. General information about this interface follows.
  505. */
  506. /* Opaque ID of the operating interface from the ieee80211
  507. * subsystem. Do not modify.
  508. */
  509. int if_id;
  510. /* MAC address (can be NULL). */
  511. u8 mac_addr[ETH_ALEN];
  512. /* Current BSSID (can be NULL). */
  513. u8 bssid[ETH_ALEN];
  514. /* Interface type. (IEEE80211_IF_TYPE_XXX) */
  515. int if_type;
  516. /* Is the card operating in AP, STA or IBSS mode? */
  517. bool operating;
  518. /* filter flags */
  519. unsigned int filter_flags;
  520. /* Stats about the wireless interface */
  521. struct ieee80211_low_level_stats ieee_stats;
  522. struct hwrng rng;
  523. u8 rng_initialized;
  524. char rng_name[30 + 1];
  525. /* The RF-kill button */
  526. struct b43legacy_rfkill rfkill;
  527. /* List of all wireless devices on this chip */
  528. struct list_head devlist;
  529. u8 nr_devs;
  530. bool radiotap_enabled;
  531. };
  532. /* Pointers to the firmware data and meta information about it. */
  533. struct b43legacy_firmware {
  534. /* Microcode */
  535. const struct firmware *ucode;
  536. /* PCM code */
  537. const struct firmware *pcm;
  538. /* Initial MMIO values for the firmware */
  539. const struct firmware *initvals;
  540. /* Initial MMIO values for the firmware, band-specific */
  541. const struct firmware *initvals_band;
  542. /* Firmware revision */
  543. u16 rev;
  544. /* Firmware patchlevel */
  545. u16 patch;
  546. };
  547. /* Device (802.11 core) initialization status. */
  548. enum {
  549. B43legacy_STAT_UNINIT = 0, /* Uninitialized. */
  550. B43legacy_STAT_INITIALIZED = 1, /* Initialized, not yet started. */
  551. B43legacy_STAT_STARTED = 2, /* Up and running. */
  552. };
  553. #define b43legacy_status(wldev) atomic_read(&(wldev)->__init_status)
  554. #define b43legacy_set_status(wldev, stat) do { \
  555. atomic_set(&(wldev)->__init_status, (stat)); \
  556. smp_wmb(); \
  557. } while (0)
  558. /* *** --- HOW LOCKING WORKS IN B43legacy --- ***
  559. *
  560. * You should always acquire both, wl->mutex and wl->irq_lock unless:
  561. * - You don't need to acquire wl->irq_lock, if the interface is stopped.
  562. * - You don't need to acquire wl->mutex in the IRQ handler, IRQ tasklet
  563. * and packet TX path (and _ONLY_ there.)
  564. */
  565. /* Data structure for one wireless device (802.11 core) */
  566. struct b43legacy_wldev {
  567. struct ssb_device *dev;
  568. struct b43legacy_wl *wl;
  569. /* The device initialization status.
  570. * Use b43legacy_status() to query. */
  571. atomic_t __init_status;
  572. /* Saved init status for handling suspend. */
  573. int suspend_init_status;
  574. bool __using_pio; /* Using pio rather than dma. */
  575. bool bad_frames_preempt;/* Use "Bad Frames Preemption". */
  576. bool reg124_set_0x4; /* Variable to keep track of IRQ. */
  577. bool short_preamble; /* TRUE if using short preamble. */
  578. bool short_slot; /* TRUE if using short slot timing. */
  579. bool radio_hw_enable; /* State of radio hardware enable bit. */
  580. /* PHY/Radio device. */
  581. struct b43legacy_phy phy;
  582. union {
  583. /* DMA engines. */
  584. struct b43legacy_dma dma;
  585. /* PIO engines. */
  586. struct b43legacy_pio pio;
  587. };
  588. /* Various statistics about the physical device. */
  589. struct b43legacy_stats stats;
  590. /* The device LEDs. */
  591. struct b43legacy_led led_tx;
  592. struct b43legacy_led led_rx;
  593. struct b43legacy_led led_assoc;
  594. struct b43legacy_led led_radio;
  595. /* Reason code of the last interrupt. */
  596. u32 irq_reason;
  597. u32 dma_reason[6];
  598. /* saved irq enable/disable state bitfield. */
  599. u32 irq_savedstate;
  600. /* Link Quality calculation context. */
  601. struct b43legacy_noise_calculation noisecalc;
  602. /* if > 0 MAC is suspended. if == 0 MAC is enabled. */
  603. int mac_suspended;
  604. /* Interrupt Service Routine tasklet (bottom-half) */
  605. struct tasklet_struct isr_tasklet;
  606. /* Periodic tasks */
  607. struct delayed_work periodic_work;
  608. unsigned int periodic_state;
  609. struct work_struct restart_work;
  610. /* encryption/decryption */
  611. u16 ktp; /* Key table pointer */
  612. u8 max_nr_keys;
  613. struct b43legacy_key key[58];
  614. /* Cached beacon template while uploading the template. */
  615. struct sk_buff *cached_beacon;
  616. /* Firmware data */
  617. struct b43legacy_firmware fw;
  618. /* Devicelist in struct b43legacy_wl (all 802.11 cores) */
  619. struct list_head list;
  620. /* Debugging stuff follows. */
  621. #ifdef CONFIG_B43LEGACY_DEBUG
  622. struct b43legacy_dfsentry *dfsentry;
  623. #endif
  624. };
  625. static inline
  626. struct b43legacy_wl *hw_to_b43legacy_wl(struct ieee80211_hw *hw)
  627. {
  628. return hw->priv;
  629. }
  630. /* Helper function, which returns a boolean.
  631. * TRUE, if PIO is used; FALSE, if DMA is used.
  632. */
  633. #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
  634. static inline
  635. int b43legacy_using_pio(struct b43legacy_wldev *dev)
  636. {
  637. return dev->__using_pio;
  638. }
  639. #elif defined(CONFIG_B43LEGACY_DMA)
  640. static inline
  641. int b43legacy_using_pio(struct b43legacy_wldev *dev)
  642. {
  643. return 0;
  644. }
  645. #elif defined(CONFIG_B43LEGACY_PIO)
  646. static inline
  647. int b43legacy_using_pio(struct b43legacy_wldev *dev)
  648. {
  649. return 1;
  650. }
  651. #else
  652. # error "Using neither DMA nor PIO? Confused..."
  653. #endif
  654. static inline
  655. struct b43legacy_wldev *dev_to_b43legacy_wldev(struct device *dev)
  656. {
  657. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  658. return ssb_get_drvdata(ssb_dev);
  659. }
  660. /* Is the device operating in a specified mode (IEEE80211_IF_TYPE_XXX). */
  661. static inline
  662. int b43legacy_is_mode(struct b43legacy_wl *wl, int type)
  663. {
  664. return (wl->operating &&
  665. wl->if_type == type);
  666. }
  667. static inline
  668. bool is_bcm_board_vendor(struct b43legacy_wldev *dev)
  669. {
  670. return (dev->dev->bus->boardinfo.vendor == PCI_VENDOR_ID_BROADCOM);
  671. }
  672. static inline
  673. u16 b43legacy_read16(struct b43legacy_wldev *dev, u16 offset)
  674. {
  675. return ssb_read16(dev->dev, offset);
  676. }
  677. static inline
  678. void b43legacy_write16(struct b43legacy_wldev *dev, u16 offset, u16 value)
  679. {
  680. ssb_write16(dev->dev, offset, value);
  681. }
  682. static inline
  683. u32 b43legacy_read32(struct b43legacy_wldev *dev, u16 offset)
  684. {
  685. return ssb_read32(dev->dev, offset);
  686. }
  687. static inline
  688. void b43legacy_write32(struct b43legacy_wldev *dev, u16 offset, u32 value)
  689. {
  690. ssb_write32(dev->dev, offset, value);
  691. }
  692. static inline
  693. struct b43legacy_lopair *b43legacy_get_lopair(struct b43legacy_phy *phy,
  694. u16 radio_attenuation,
  695. u16 baseband_attenuation)
  696. {
  697. return phy->_lo_pairs + (radio_attenuation
  698. + 14 * (baseband_attenuation / 2));
  699. }
  700. /* Message printing */
  701. void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...)
  702. __attribute__((format(printf, 2, 3)));
  703. void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...)
  704. __attribute__((format(printf, 2, 3)));
  705. void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...)
  706. __attribute__((format(printf, 2, 3)));
  707. #if B43legacy_DEBUG
  708. void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...)
  709. __attribute__((format(printf, 2, 3)));
  710. #else /* DEBUG */
  711. # define b43legacydbg(wl, fmt...) do { /* nothing */ } while (0)
  712. #endif /* DEBUG */
  713. /** Limit a value between two limits */
  714. #ifdef limit_value
  715. # undef limit_value
  716. #endif
  717. #define limit_value(value, min, max) \
  718. ({ \
  719. typeof(value) __value = (value); \
  720. typeof(value) __min = (min); \
  721. typeof(value) __max = (max); \
  722. if (__value < __min) \
  723. __value = __min; \
  724. else if (__value > __max) \
  725. __value = __max; \
  726. __value; \
  727. })
  728. /* Macros for printing a value in Q5.2 format */
  729. #define Q52_FMT "%u.%u"
  730. #define Q52_ARG(q52) ((q52) / 4), (((q52) & 3) * 100 / 4)
  731. #endif /* B43legacy_H_ */