ath5k.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  1. /*
  2. * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _ATH5K_H
  18. #define _ATH5K_H
  19. /* TODO: Clean up channel debugging (doesn't work anyway) and start
  20. * working on reg. control code using all available eeprom information
  21. * (rev. engineering needed) */
  22. #define CHAN_DEBUG 0
  23. #include <linux/io.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/types.h>
  26. #include <linux/average.h>
  27. #include <linux/leds.h>
  28. #include <net/mac80211.h>
  29. /* RX/TX descriptor hw structs
  30. * TODO: Driver part should only see sw structs */
  31. #include "desc.h"
  32. /* EEPROM structs/offsets
  33. * TODO: Make a more generic struct (eg. add more stuff to ath5k_capabilities)
  34. * and clean up common bits, then introduce set/get functions in eeprom.c */
  35. #include "eeprom.h"
  36. #include "debug.h"
  37. #include "../ath.h"
  38. #include "ani.h"
  39. /* PCI IDs */
  40. #define PCI_DEVICE_ID_ATHEROS_AR5210 0x0007 /* AR5210 */
  41. #define PCI_DEVICE_ID_ATHEROS_AR5311 0x0011 /* AR5311 */
  42. #define PCI_DEVICE_ID_ATHEROS_AR5211 0x0012 /* AR5211 */
  43. #define PCI_DEVICE_ID_ATHEROS_AR5212 0x0013 /* AR5212 */
  44. #define PCI_DEVICE_ID_3COM_3CRDAG675 0x0013 /* 3CRDAG675 (Atheros AR5212) */
  45. #define PCI_DEVICE_ID_3COM_2_3CRPAG175 0x0013 /* 3CRPAG175 (Atheros AR5212) */
  46. #define PCI_DEVICE_ID_ATHEROS_AR5210_AP 0x0207 /* AR5210 (Early) */
  47. #define PCI_DEVICE_ID_ATHEROS_AR5212_IBM 0x1014 /* AR5212 (IBM MiniPCI) */
  48. #define PCI_DEVICE_ID_ATHEROS_AR5210_DEFAULT 0x1107 /* AR5210 (no eeprom) */
  49. #define PCI_DEVICE_ID_ATHEROS_AR5212_DEFAULT 0x1113 /* AR5212 (no eeprom) */
  50. #define PCI_DEVICE_ID_ATHEROS_AR5211_DEFAULT 0x1112 /* AR5211 (no eeprom) */
  51. #define PCI_DEVICE_ID_ATHEROS_AR5212_FPGA 0xf013 /* AR5212 (emulation board) */
  52. #define PCI_DEVICE_ID_ATHEROS_AR5211_LEGACY 0xff12 /* AR5211 (emulation board) */
  53. #define PCI_DEVICE_ID_ATHEROS_AR5211_FPGA11B 0xf11b /* AR5211 (emulation board) */
  54. #define PCI_DEVICE_ID_ATHEROS_AR5312_REV2 0x0052 /* AR5312 WMAC (AP31) */
  55. #define PCI_DEVICE_ID_ATHEROS_AR5312_REV7 0x0057 /* AR5312 WMAC (AP30-040) */
  56. #define PCI_DEVICE_ID_ATHEROS_AR5312_REV8 0x0058 /* AR5312 WMAC (AP43-030) */
  57. #define PCI_DEVICE_ID_ATHEROS_AR5212_0014 0x0014 /* AR5212 compatible */
  58. #define PCI_DEVICE_ID_ATHEROS_AR5212_0015 0x0015 /* AR5212 compatible */
  59. #define PCI_DEVICE_ID_ATHEROS_AR5212_0016 0x0016 /* AR5212 compatible */
  60. #define PCI_DEVICE_ID_ATHEROS_AR5212_0017 0x0017 /* AR5212 compatible */
  61. #define PCI_DEVICE_ID_ATHEROS_AR5212_0018 0x0018 /* AR5212 compatible */
  62. #define PCI_DEVICE_ID_ATHEROS_AR5212_0019 0x0019 /* AR5212 compatible */
  63. #define PCI_DEVICE_ID_ATHEROS_AR2413 0x001a /* AR2413 (Griffin-lite) */
  64. #define PCI_DEVICE_ID_ATHEROS_AR5413 0x001b /* AR5413 (Eagle) */
  65. #define PCI_DEVICE_ID_ATHEROS_AR5424 0x001c /* AR5424 (Condor PCI-E) */
  66. #define PCI_DEVICE_ID_ATHEROS_AR5416 0x0023 /* AR5416 */
  67. #define PCI_DEVICE_ID_ATHEROS_AR5418 0x0024 /* AR5418 */
  68. /****************************\
  69. GENERIC DRIVER DEFINITIONS
  70. \****************************/
  71. #define ATH5K_PRINTF(fmt, ...) \
  72. pr_warn("%s: " fmt, __func__, ##__VA_ARGS__)
  73. void __printf(3, 4)
  74. _ath5k_printk(const struct ath5k_hw *ah, const char *level,
  75. const char *fmt, ...);
  76. #define ATH5K_PRINTK(_sc, _level, _fmt, ...) \
  77. _ath5k_printk(_sc, _level, _fmt, ##__VA_ARGS__)
  78. #define ATH5K_PRINTK_LIMIT(_sc, _level, _fmt, ...) \
  79. do { \
  80. if (net_ratelimit()) \
  81. ATH5K_PRINTK(_sc, _level, _fmt, ##__VA_ARGS__); \
  82. } while (0)
  83. #define ATH5K_INFO(_sc, _fmt, ...) \
  84. ATH5K_PRINTK(_sc, KERN_INFO, _fmt, ##__VA_ARGS__)
  85. #define ATH5K_WARN(_sc, _fmt, ...) \
  86. ATH5K_PRINTK_LIMIT(_sc, KERN_WARNING, _fmt, ##__VA_ARGS__)
  87. #define ATH5K_ERR(_sc, _fmt, ...) \
  88. ATH5K_PRINTK_LIMIT(_sc, KERN_ERR, _fmt, ##__VA_ARGS__)
  89. /*
  90. * AR5K REGISTER ACCESS
  91. */
  92. /* Some macros to read/write fields */
  93. /* First shift, then mask */
  94. #define AR5K_REG_SM(_val, _flags) \
  95. (((_val) << _flags##_S) & (_flags))
  96. /* First mask, then shift */
  97. #define AR5K_REG_MS(_val, _flags) \
  98. (((_val) & (_flags)) >> _flags##_S)
  99. /* Some registers can hold multiple values of interest. For this
  100. * reason when we want to write to these registers we must first
  101. * retrieve the values which we do not want to clear (lets call this
  102. * old_data) and then set the register with this and our new_value:
  103. * ( old_data | new_value) */
  104. #define AR5K_REG_WRITE_BITS(ah, _reg, _flags, _val) \
  105. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, _reg) & ~(_flags)) | \
  106. (((_val) << _flags##_S) & (_flags)), _reg)
  107. #define AR5K_REG_MASKED_BITS(ah, _reg, _flags, _mask) \
  108. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, _reg) & \
  109. (_mask)) | (_flags), _reg)
  110. #define AR5K_REG_ENABLE_BITS(ah, _reg, _flags) \
  111. ath5k_hw_reg_write(ah, ath5k_hw_reg_read(ah, _reg) | (_flags), _reg)
  112. #define AR5K_REG_DISABLE_BITS(ah, _reg, _flags) \
  113. ath5k_hw_reg_write(ah, ath5k_hw_reg_read(ah, _reg) & ~(_flags), _reg)
  114. /* Access QCU registers per queue */
  115. #define AR5K_REG_READ_Q(ah, _reg, _queue) \
  116. (ath5k_hw_reg_read(ah, _reg) & (1 << _queue)) \
  117. #define AR5K_REG_WRITE_Q(ah, _reg, _queue) \
  118. ath5k_hw_reg_write(ah, (1 << _queue), _reg)
  119. #define AR5K_Q_ENABLE_BITS(_reg, _queue) do { \
  120. _reg |= 1 << _queue; \
  121. } while (0)
  122. #define AR5K_Q_DISABLE_BITS(_reg, _queue) do { \
  123. _reg &= ~(1 << _queue); \
  124. } while (0)
  125. /* Used while writing initvals */
  126. #define AR5K_REG_WAIT(_i) do { \
  127. if (_i % 64) \
  128. udelay(1); \
  129. } while (0)
  130. /*
  131. * Some tunable values (these should be changeable by the user)
  132. * TODO: Make use of them and add more options OR use debug/configfs
  133. */
  134. #define AR5K_TUNE_DMA_BEACON_RESP 2
  135. #define AR5K_TUNE_SW_BEACON_RESP 10
  136. #define AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF 0
  137. #define AR5K_TUNE_MIN_TX_FIFO_THRES 1
  138. #define AR5K_TUNE_MAX_TX_FIFO_THRES ((IEEE80211_MAX_FRAME_LEN / 64) + 1)
  139. #define AR5K_TUNE_REGISTER_TIMEOUT 20000
  140. /* Register for RSSI threshold has a mask of 0xff, so 255 seems to
  141. * be the max value. */
  142. #define AR5K_TUNE_RSSI_THRES 129
  143. /* This must be set when setting the RSSI threshold otherwise it can
  144. * prevent a reset. If AR5K_RSSI_THR is read after writing to it
  145. * the BMISS_THRES will be seen as 0, seems hardware doesn't keep
  146. * track of it. Max value depends on hardware. For AR5210 this is just 7.
  147. * For AR5211+ this seems to be up to 255. */
  148. #define AR5K_TUNE_BMISS_THRES 7
  149. #define AR5K_TUNE_REGISTER_DWELL_TIME 20000
  150. #define AR5K_TUNE_BEACON_INTERVAL 100
  151. #define AR5K_TUNE_AIFS 2
  152. #define AR5K_TUNE_AIFS_11B 2
  153. #define AR5K_TUNE_AIFS_XR 0
  154. #define AR5K_TUNE_CWMIN 15
  155. #define AR5K_TUNE_CWMIN_11B 31
  156. #define AR5K_TUNE_CWMIN_XR 3
  157. #define AR5K_TUNE_CWMAX 1023
  158. #define AR5K_TUNE_CWMAX_11B 1023
  159. #define AR5K_TUNE_CWMAX_XR 7
  160. #define AR5K_TUNE_NOISE_FLOOR -72
  161. #define AR5K_TUNE_CCA_MAX_GOOD_VALUE -95
  162. #define AR5K_TUNE_MAX_TXPOWER 63
  163. #define AR5K_TUNE_DEFAULT_TXPOWER 25
  164. #define AR5K_TUNE_TPC_TXPOWER false
  165. #define ATH5K_TUNE_CALIBRATION_INTERVAL_FULL 60000 /* 60 sec */
  166. #define ATH5K_TUNE_CALIBRATION_INTERVAL_SHORT 10000 /* 10 sec */
  167. #define ATH5K_TUNE_CALIBRATION_INTERVAL_ANI 1000 /* 1 sec */
  168. #define ATH5K_TX_COMPLETE_POLL_INT 3000 /* 3 sec */
  169. #define AR5K_INIT_CARR_SENSE_EN 1
  170. /*Swap RX/TX Descriptor for big endian archs*/
  171. #if defined(__BIG_ENDIAN)
  172. #define AR5K_INIT_CFG ( \
  173. AR5K_CFG_SWTD | AR5K_CFG_SWRD \
  174. )
  175. #else
  176. #define AR5K_INIT_CFG 0x00000000
  177. #endif
  178. /* Initial values */
  179. #define AR5K_INIT_CYCRSSI_THR1 2
  180. /* Tx retry limit defaults from standard */
  181. #define AR5K_INIT_RETRY_SHORT 7
  182. #define AR5K_INIT_RETRY_LONG 4
  183. /* Slot time */
  184. #define AR5K_INIT_SLOT_TIME_TURBO 6
  185. #define AR5K_INIT_SLOT_TIME_DEFAULT 9
  186. #define AR5K_INIT_SLOT_TIME_HALF_RATE 13
  187. #define AR5K_INIT_SLOT_TIME_QUARTER_RATE 21
  188. #define AR5K_INIT_SLOT_TIME_B 20
  189. #define AR5K_SLOT_TIME_MAX 0xffff
  190. /* SIFS */
  191. #define AR5K_INIT_SIFS_TURBO 6
  192. #define AR5K_INIT_SIFS_DEFAULT_BG 10
  193. #define AR5K_INIT_SIFS_DEFAULT_A 16
  194. #define AR5K_INIT_SIFS_HALF_RATE 32
  195. #define AR5K_INIT_SIFS_QUARTER_RATE 64
  196. /* Used to calculate tx time for non 5/10/40MHz
  197. * operation */
  198. /* It's preamble time + signal time (16 + 4) */
  199. #define AR5K_INIT_OFDM_PREAMPLE_TIME 20
  200. /* Preamble time for 40MHz (turbo) operation (min ?) */
  201. #define AR5K_INIT_OFDM_PREAMBLE_TIME_MIN 14
  202. #define AR5K_INIT_OFDM_SYMBOL_TIME 4
  203. #define AR5K_INIT_OFDM_PLCP_BITS 22
  204. /* Rx latency for 5 and 10MHz operation (max ?) */
  205. #define AR5K_INIT_RX_LAT_MAX 63
  206. /* Tx latencies from initvals (5212 only but no problem
  207. * because we only tweak them on 5212) */
  208. #define AR5K_INIT_TX_LAT_A 54
  209. #define AR5K_INIT_TX_LAT_BG 384
  210. /* Tx latency for 40MHz (turbo) operation (min ?) */
  211. #define AR5K_INIT_TX_LAT_MIN 32
  212. /* Default Tx/Rx latencies (same for 5211)*/
  213. #define AR5K_INIT_TX_LATENCY_5210 54
  214. #define AR5K_INIT_RX_LATENCY_5210 29
  215. /* Tx frame to Tx data start delay */
  216. #define AR5K_INIT_TXF2TXD_START_DEFAULT 14
  217. #define AR5K_INIT_TXF2TXD_START_DELAY_10MHZ 12
  218. #define AR5K_INIT_TXF2TXD_START_DELAY_5MHZ 13
  219. /* We need to increase PHY switch and agc settling time
  220. * on turbo mode */
  221. #define AR5K_SWITCH_SETTLING 5760
  222. #define AR5K_SWITCH_SETTLING_TURBO 7168
  223. #define AR5K_AGC_SETTLING 28
  224. /* 38 on 5210 but shouldn't matter */
  225. #define AR5K_AGC_SETTLING_TURBO 37
  226. /*****************************\
  227. * GENERIC CHIPSET DEFINITIONS *
  228. \*****************************/
  229. /**
  230. * enum ath5k_version - MAC Chips
  231. * @AR5K_AR5210: AR5210 (Crete)
  232. * @AR5K_AR5211: AR5211 (Oahu/Maui)
  233. * @AR5K_AR5212: AR5212 (Venice) and newer
  234. */
  235. enum ath5k_version {
  236. AR5K_AR5210 = 0,
  237. AR5K_AR5211 = 1,
  238. AR5K_AR5212 = 2,
  239. };
  240. /**
  241. * enum ath5k_radio - PHY Chips
  242. * @AR5K_RF5110: RF5110 (Fez)
  243. * @AR5K_RF5111: RF5111 (Sombrero)
  244. * @AR5K_RF5112: RF2112/5112(A) (Derby/Derby2)
  245. * @AR5K_RF2413: RF2413/2414 (Griffin/Griffin-Lite)
  246. * @AR5K_RF5413: RF5413/5414/5424 (Eagle/Condor)
  247. * @AR5K_RF2316: RF2315/2316 (Cobra SoC)
  248. * @AR5K_RF2317: RF2317 (Spider SoC)
  249. * @AR5K_RF2425: RF2425/2417 (Swan/Nalla)
  250. */
  251. enum ath5k_radio {
  252. AR5K_RF5110 = 0,
  253. AR5K_RF5111 = 1,
  254. AR5K_RF5112 = 2,
  255. AR5K_RF2413 = 3,
  256. AR5K_RF5413 = 4,
  257. AR5K_RF2316 = 5,
  258. AR5K_RF2317 = 6,
  259. AR5K_RF2425 = 7,
  260. };
  261. /*
  262. * Common silicon revision/version values
  263. */
  264. #define AR5K_SREV_UNKNOWN 0xffff
  265. #define AR5K_SREV_AR5210 0x00 /* Crete */
  266. #define AR5K_SREV_AR5311 0x10 /* Maui 1 */
  267. #define AR5K_SREV_AR5311A 0x20 /* Maui 2 */
  268. #define AR5K_SREV_AR5311B 0x30 /* Spirit */
  269. #define AR5K_SREV_AR5211 0x40 /* Oahu */
  270. #define AR5K_SREV_AR5212 0x50 /* Venice */
  271. #define AR5K_SREV_AR5312_R2 0x52 /* AP31 */
  272. #define AR5K_SREV_AR5212_V4 0x54 /* ??? */
  273. #define AR5K_SREV_AR5213 0x55 /* ??? */
  274. #define AR5K_SREV_AR5312_R7 0x57 /* AP30 */
  275. #define AR5K_SREV_AR2313_R8 0x58 /* AP43 */
  276. #define AR5K_SREV_AR5213A 0x59 /* Hainan */
  277. #define AR5K_SREV_AR2413 0x78 /* Griffin lite */
  278. #define AR5K_SREV_AR2414 0x70 /* Griffin */
  279. #define AR5K_SREV_AR2315_R6 0x86 /* AP51-Light */
  280. #define AR5K_SREV_AR2315_R7 0x87 /* AP51-Full */
  281. #define AR5K_SREV_AR5424 0x90 /* Condor */
  282. #define AR5K_SREV_AR2317_R1 0x90 /* AP61-Light */
  283. #define AR5K_SREV_AR2317_R2 0x91 /* AP61-Full */
  284. #define AR5K_SREV_AR5413 0xa4 /* Eagle lite */
  285. #define AR5K_SREV_AR5414 0xa0 /* Eagle */
  286. #define AR5K_SREV_AR2415 0xb0 /* Talon */
  287. #define AR5K_SREV_AR5416 0xc0 /* PCI-E */
  288. #define AR5K_SREV_AR5418 0xca /* PCI-E */
  289. #define AR5K_SREV_AR2425 0xe0 /* Swan */
  290. #define AR5K_SREV_AR2417 0xf0 /* Nala */
  291. #define AR5K_SREV_RAD_5110 0x00
  292. #define AR5K_SREV_RAD_5111 0x10
  293. #define AR5K_SREV_RAD_5111A 0x15
  294. #define AR5K_SREV_RAD_2111 0x20
  295. #define AR5K_SREV_RAD_5112 0x30
  296. #define AR5K_SREV_RAD_5112A 0x35
  297. #define AR5K_SREV_RAD_5112B 0x36
  298. #define AR5K_SREV_RAD_2112 0x40
  299. #define AR5K_SREV_RAD_2112A 0x45
  300. #define AR5K_SREV_RAD_2112B 0x46
  301. #define AR5K_SREV_RAD_2413 0x50
  302. #define AR5K_SREV_RAD_5413 0x60
  303. #define AR5K_SREV_RAD_2316 0x70 /* Cobra SoC */
  304. #define AR5K_SREV_RAD_2317 0x80
  305. #define AR5K_SREV_RAD_5424 0xa0 /* Mostly same as 5413 */
  306. #define AR5K_SREV_RAD_2425 0xa2
  307. #define AR5K_SREV_RAD_5133 0xc0
  308. #define AR5K_SREV_PHY_5211 0x30
  309. #define AR5K_SREV_PHY_5212 0x41
  310. #define AR5K_SREV_PHY_5212A 0x42
  311. #define AR5K_SREV_PHY_5212B 0x43
  312. #define AR5K_SREV_PHY_2413 0x45
  313. #define AR5K_SREV_PHY_5413 0x61
  314. #define AR5K_SREV_PHY_2425 0x70
  315. /* TODO add support to mac80211 for vendor-specific rates and modes */
  316. /**
  317. * DOC: Atheros XR
  318. *
  319. * Some of this information is based on Documentation from:
  320. *
  321. * http://madwifi-project.org/wiki/ChipsetFeatures/SuperAG
  322. *
  323. * Atheros' eXtended Range - range enhancing extension is a modulation scheme
  324. * that is supposed to double the link distance between an Atheros XR-enabled
  325. * client device with an Atheros XR-enabled access point. This is achieved
  326. * by increasing the receiver sensitivity up to, -105dBm, which is about 20dB
  327. * above what the 802.11 specifications demand. In addition, new (proprietary)
  328. * data rates are introduced: 3, 2, 1, 0.5 and 0.25 MBit/s.
  329. *
  330. * Please note that can you either use XR or TURBO but you cannot use both,
  331. * they are exclusive.
  332. *
  333. * Also note that we do not plan to support XR mode at least for now. You can
  334. * get a mode similar to XR by using 5MHz bwmode.
  335. */
  336. /**
  337. * DOC: Atheros SuperAG
  338. *
  339. * In addition to XR we have another modulation scheme called TURBO mode
  340. * that is supposed to provide a throughput transmission speed up to 40Mbit/s
  341. * -60Mbit/s at a 108Mbit/s signaling rate achieved through the bonding of two
  342. * 54Mbit/s 802.11g channels. To use this feature both ends must support it.
  343. * There is also a distinction between "static" and "dynamic" turbo modes:
  344. *
  345. * - Static: is the dumb version: devices set to this mode stick to it until
  346. * the mode is turned off.
  347. *
  348. * - Dynamic: is the intelligent version, the network decides itself if it
  349. * is ok to use turbo. As soon as traffic is detected on adjacent channels
  350. * (which would get used in turbo mode), or when a non-turbo station joins
  351. * the network, turbo mode won't be used until the situation changes again.
  352. * Dynamic mode is achieved by Atheros' Adaptive Radio (AR) feature which
  353. * monitors the used radio band in order to decide whether turbo mode may
  354. * be used or not.
  355. *
  356. * This article claims Super G sticks to bonding of channels 5 and 6 for
  357. * USA:
  358. *
  359. * http://www.pcworld.com/article/id,113428-page,1/article.html
  360. *
  361. * The channel bonding seems to be driver specific though.
  362. *
  363. * In addition to TURBO modes we also have the following features for even
  364. * greater speed-up:
  365. *
  366. * - Bursting: allows multiple frames to be sent at once, rather than pausing
  367. * after each frame. Bursting is a standards-compliant feature that can be
  368. * used with any Access Point.
  369. *
  370. * - Fast frames: increases the amount of information that can be sent per
  371. * frame, also resulting in a reduction of transmission overhead. It is a
  372. * proprietary feature that needs to be supported by the Access Point.
  373. *
  374. * - Compression: data frames are compressed in real time using a Lempel Ziv
  375. * algorithm. This is done transparently. Once this feature is enabled,
  376. * compression and decompression takes place inside the chipset, without
  377. * putting additional load on the host CPU.
  378. *
  379. * As with XR we also don't plan to support SuperAG features for now. You can
  380. * get a mode similar to TURBO by using 40MHz bwmode.
  381. */
  382. /**
  383. * enum ath5k_driver_mode - PHY operation mode
  384. * @AR5K_MODE_11A: 802.11a
  385. * @AR5K_MODE_11B: 802.11b
  386. * @AR5K_MODE_11G: 801.11g
  387. * @AR5K_MODE_MAX: Used for boundary checks
  388. *
  389. * Do not change the order here, we use these as
  390. * array indices and it also maps EEPROM structures.
  391. */
  392. enum ath5k_driver_mode {
  393. AR5K_MODE_11A = 0,
  394. AR5K_MODE_11B = 1,
  395. AR5K_MODE_11G = 2,
  396. AR5K_MODE_MAX = 3
  397. };
  398. /**
  399. * enum ath5k_ant_mode - Antenna operation mode
  400. * @AR5K_ANTMODE_DEFAULT: Default antenna setup
  401. * @AR5K_ANTMODE_FIXED_A: Only antenna A is present
  402. * @AR5K_ANTMODE_FIXED_B: Only antenna B is present
  403. * @AR5K_ANTMODE_SINGLE_AP: STA locked on a single ap
  404. * @AR5K_ANTMODE_SECTOR_AP: AP with tx antenna set on tx desc
  405. * @AR5K_ANTMODE_SECTOR_STA: STA with tx antenna set on tx desc
  406. * @AR5K_ANTMODE_DEBUG: Debug mode -A -> Rx, B-> Tx-
  407. * @AR5K_ANTMODE_MAX: Used for boundary checks
  408. *
  409. * For more infos on antenna control check out phy.c
  410. */
  411. enum ath5k_ant_mode {
  412. AR5K_ANTMODE_DEFAULT = 0,
  413. AR5K_ANTMODE_FIXED_A = 1,
  414. AR5K_ANTMODE_FIXED_B = 2,
  415. AR5K_ANTMODE_SINGLE_AP = 3,
  416. AR5K_ANTMODE_SECTOR_AP = 4,
  417. AR5K_ANTMODE_SECTOR_STA = 5,
  418. AR5K_ANTMODE_DEBUG = 6,
  419. AR5K_ANTMODE_MAX,
  420. };
  421. /**
  422. * enum ath5k_bw_mode - Bandwidth operation mode
  423. * @AR5K_BWMODE_DEFAULT: 20MHz, default operation
  424. * @AR5K_BWMODE_5MHZ: Quarter rate
  425. * @AR5K_BWMODE_10MHZ: Half rate
  426. * @AR5K_BWMODE_40MHZ: Turbo
  427. */
  428. enum ath5k_bw_mode {
  429. AR5K_BWMODE_DEFAULT = 0,
  430. AR5K_BWMODE_5MHZ = 1,
  431. AR5K_BWMODE_10MHZ = 2,
  432. AR5K_BWMODE_40MHZ = 3
  433. };
  434. /****************\
  435. TX DEFINITIONS
  436. \****************/
  437. /**
  438. * struct ath5k_tx_status - TX Status descriptor
  439. * @ts_seqnum: Sequence number
  440. * @ts_tstamp: Timestamp
  441. * @ts_status: Status code
  442. * @ts_final_idx: Final transmission series index
  443. * @ts_final_retry: Final retry count
  444. * @ts_rssi: RSSI for received ACK
  445. * @ts_shortretry: Short retry count
  446. * @ts_virtcol: Virtual collision count
  447. * @ts_antenna: Antenna used
  448. *
  449. * TX status descriptor gets filled by the hw
  450. * on each transmission attempt.
  451. */
  452. struct ath5k_tx_status {
  453. u16 ts_seqnum;
  454. u16 ts_tstamp;
  455. u8 ts_status;
  456. u8 ts_final_idx;
  457. u8 ts_final_retry;
  458. s8 ts_rssi;
  459. u8 ts_shortretry;
  460. u8 ts_virtcol;
  461. u8 ts_antenna;
  462. };
  463. #define AR5K_TXSTAT_ALTRATE 0x80
  464. #define AR5K_TXERR_XRETRY 0x01
  465. #define AR5K_TXERR_FILT 0x02
  466. #define AR5K_TXERR_FIFO 0x04
  467. /**
  468. * enum ath5k_tx_queue - Queue types used to classify tx queues.
  469. * @AR5K_TX_QUEUE_INACTIVE: q is unused -- see ath5k_hw_release_tx_queue
  470. * @AR5K_TX_QUEUE_DATA: A normal data queue
  471. * @AR5K_TX_QUEUE_BEACON: The beacon queue
  472. * @AR5K_TX_QUEUE_CAB: The after-beacon queue
  473. * @AR5K_TX_QUEUE_UAPSD: Unscheduled Automatic Power Save Delivery queue
  474. */
  475. enum ath5k_tx_queue {
  476. AR5K_TX_QUEUE_INACTIVE = 0,
  477. AR5K_TX_QUEUE_DATA,
  478. AR5K_TX_QUEUE_BEACON,
  479. AR5K_TX_QUEUE_CAB,
  480. AR5K_TX_QUEUE_UAPSD,
  481. };
  482. #define AR5K_NUM_TX_QUEUES 10
  483. #define AR5K_NUM_TX_QUEUES_NOQCU 2
  484. /**
  485. * enum ath5k_tx_queue_subtype - Queue sub-types to classify normal data queues
  486. * @AR5K_WME_AC_BK: Background traffic
  487. * @AR5K_WME_AC_BE: Best-effort (normal) traffic
  488. * @AR5K_WME_AC_VI: Video traffic
  489. * @AR5K_WME_AC_VO: Voice traffic
  490. *
  491. * These are the 4 Access Categories as defined in
  492. * WME spec. 0 is the lowest priority and 4 is the
  493. * highest. Normal data that hasn't been classified
  494. * goes to the Best Effort AC.
  495. */
  496. enum ath5k_tx_queue_subtype {
  497. AR5K_WME_AC_BK = 0,
  498. AR5K_WME_AC_BE,
  499. AR5K_WME_AC_VI,
  500. AR5K_WME_AC_VO,
  501. };
  502. /**
  503. * enum ath5k_tx_queue_id - Queue ID numbers as returned by the hw functions
  504. * @AR5K_TX_QUEUE_ID_NOQCU_DATA: Data queue on AR5210 (no QCU available)
  505. * @AR5K_TX_QUEUE_ID_NOQCU_BEACON: Beacon queue on AR5210 (no QCU available)
  506. * @AR5K_TX_QUEUE_ID_DATA_MIN: Data queue min index
  507. * @AR5K_TX_QUEUE_ID_DATA_MAX: Data queue max index
  508. * @AR5K_TX_QUEUE_ID_CAB: Content after beacon queue
  509. * @AR5K_TX_QUEUE_ID_BEACON: Beacon queue
  510. * @AR5K_TX_QUEUE_ID_UAPSD: Urgent Automatic Power Save Delivery,
  511. *
  512. * Each number represents a hw queue. If hw does not support hw queues
  513. * (eg 5210) all data goes in one queue.
  514. */
  515. enum ath5k_tx_queue_id {
  516. AR5K_TX_QUEUE_ID_NOQCU_DATA = 0,
  517. AR5K_TX_QUEUE_ID_NOQCU_BEACON = 1,
  518. AR5K_TX_QUEUE_ID_DATA_MIN = 0,
  519. AR5K_TX_QUEUE_ID_DATA_MAX = 3,
  520. AR5K_TX_QUEUE_ID_UAPSD = 7,
  521. AR5K_TX_QUEUE_ID_CAB = 8,
  522. AR5K_TX_QUEUE_ID_BEACON = 9,
  523. };
  524. /*
  525. * Flags to set hw queue's parameters...
  526. */
  527. #define AR5K_TXQ_FLAG_TXOKINT_ENABLE 0x0001 /* Enable TXOK interrupt */
  528. #define AR5K_TXQ_FLAG_TXERRINT_ENABLE 0x0002 /* Enable TXERR interrupt */
  529. #define AR5K_TXQ_FLAG_TXEOLINT_ENABLE 0x0004 /* Enable TXEOL interrupt -not used- */
  530. #define AR5K_TXQ_FLAG_TXDESCINT_ENABLE 0x0008 /* Enable TXDESC interrupt -not used- */
  531. #define AR5K_TXQ_FLAG_TXURNINT_ENABLE 0x0010 /* Enable TXURN interrupt */
  532. #define AR5K_TXQ_FLAG_CBRORNINT_ENABLE 0x0020 /* Enable CBRORN interrupt */
  533. #define AR5K_TXQ_FLAG_CBRURNINT_ENABLE 0x0040 /* Enable CBRURN interrupt */
  534. #define AR5K_TXQ_FLAG_QTRIGINT_ENABLE 0x0080 /* Enable QTRIG interrupt */
  535. #define AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE 0x0100 /* Enable TXNOFRM interrupt */
  536. #define AR5K_TXQ_FLAG_BACKOFF_DISABLE 0x0200 /* Disable random post-backoff */
  537. #define AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE 0x0300 /* Enable ready time expiry policy (?)*/
  538. #define AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE 0x0800 /* Enable backoff while bursting */
  539. #define AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS 0x1000 /* Disable backoff while bursting */
  540. #define AR5K_TXQ_FLAG_COMPRESSION_ENABLE 0x2000 /* Enable hw compression -not implemented-*/
  541. /**
  542. * struct ath5k_txq - Transmit queue state
  543. * @qnum: Hardware q number
  544. * @link: Link ptr in last TX desc
  545. * @q: Transmit queue (&struct list_head)
  546. * @lock: Lock on q and link
  547. * @setup: Is the queue configured
  548. * @txq_len:Number of queued buffers
  549. * @txq_max: Max allowed num of queued buffers
  550. * @txq_poll_mark: Used to check if queue got stuck
  551. * @txq_stuck: Queue stuck counter
  552. *
  553. * One of these exists for each hardware transmit queue.
  554. * Packets sent to us from above are assigned to queues based
  555. * on their priority. Not all devices support a complete set
  556. * of hardware transmit queues. For those devices the array
  557. * sc_ac2q will map multiple priorities to fewer hardware queues
  558. * (typically all to one hardware queue).
  559. */
  560. struct ath5k_txq {
  561. unsigned int qnum;
  562. u32 *link;
  563. struct list_head q;
  564. spinlock_t lock;
  565. bool setup;
  566. int txq_len;
  567. int txq_max;
  568. bool txq_poll_mark;
  569. unsigned int txq_stuck;
  570. };
  571. /**
  572. * struct ath5k_txq_info - A struct to hold TX queue's parameters
  573. * @tqi_type: One of enum ath5k_tx_queue
  574. * @tqi_subtype: One of enum ath5k_tx_queue_subtype
  575. * @tqi_flags: TX queue flags (see above)
  576. * @tqi_aifs: Arbitrated Inter-frame Space
  577. * @tqi_cw_min: Minimum Contention Window
  578. * @tqi_cw_max: Maximum Contention Window
  579. * @tqi_cbr_period: Constant bit rate period
  580. * @tqi_ready_time: Time queue waits after an event when RDYTIME is enabled
  581. */
  582. struct ath5k_txq_info {
  583. enum ath5k_tx_queue tqi_type;
  584. enum ath5k_tx_queue_subtype tqi_subtype;
  585. u16 tqi_flags;
  586. u8 tqi_aifs;
  587. u16 tqi_cw_min;
  588. u16 tqi_cw_max;
  589. u32 tqi_cbr_period;
  590. u32 tqi_cbr_overflow_limit;
  591. u32 tqi_burst_time;
  592. u32 tqi_ready_time;
  593. };
  594. /**
  595. * enum ath5k_pkt_type - Transmit packet types
  596. * @AR5K_PKT_TYPE_NORMAL: Normal data
  597. * @AR5K_PKT_TYPE_ATIM: ATIM
  598. * @AR5K_PKT_TYPE_PSPOLL: PS-Poll
  599. * @AR5K_PKT_TYPE_BEACON: Beacon
  600. * @AR5K_PKT_TYPE_PROBE_RESP: Probe response
  601. * @AR5K_PKT_TYPE_PIFS: PIFS
  602. * Used on tx control descriptor
  603. */
  604. enum ath5k_pkt_type {
  605. AR5K_PKT_TYPE_NORMAL = 0,
  606. AR5K_PKT_TYPE_ATIM = 1,
  607. AR5K_PKT_TYPE_PSPOLL = 2,
  608. AR5K_PKT_TYPE_BEACON = 3,
  609. AR5K_PKT_TYPE_PROBE_RESP = 4,
  610. AR5K_PKT_TYPE_PIFS = 5,
  611. };
  612. /*
  613. * TX power and TPC settings
  614. */
  615. #define AR5K_TXPOWER_OFDM(_r, _v) ( \
  616. ((0 & 1) << ((_v) + 6)) | \
  617. (((ah->ah_txpower.txp_rates_power_table[(_r)]) & 0x3f) << (_v)) \
  618. )
  619. #define AR5K_TXPOWER_CCK(_r, _v) ( \
  620. (ah->ah_txpower.txp_rates_power_table[(_r)] & 0x3f) << (_v) \
  621. )
  622. /****************\
  623. RX DEFINITIONS
  624. \****************/
  625. /**
  626. * struct ath5k_rx_status - RX Status descriptor
  627. * @rs_datalen: Data length
  628. * @rs_tstamp: Timestamp
  629. * @rs_status: Status code
  630. * @rs_phyerr: PHY error mask
  631. * @rs_rssi: RSSI in 0.5dbm units
  632. * @rs_keyix: Index to the key used for decrypting
  633. * @rs_rate: Rate used to decode the frame
  634. * @rs_antenna: Antenna used to receive the frame
  635. * @rs_more: Indicates this is a frame fragment (Fast frames)
  636. */
  637. struct ath5k_rx_status {
  638. u16 rs_datalen;
  639. u16 rs_tstamp;
  640. u8 rs_status;
  641. u8 rs_phyerr;
  642. s8 rs_rssi;
  643. u8 rs_keyix;
  644. u8 rs_rate;
  645. u8 rs_antenna;
  646. u8 rs_more;
  647. };
  648. #define AR5K_RXERR_CRC 0x01
  649. #define AR5K_RXERR_PHY 0x02
  650. #define AR5K_RXERR_FIFO 0x04
  651. #define AR5K_RXERR_DECRYPT 0x08
  652. #define AR5K_RXERR_MIC 0x10
  653. #define AR5K_RXKEYIX_INVALID ((u8) -1)
  654. #define AR5K_TXKEYIX_INVALID ((u32) -1)
  655. /**************************\
  656. BEACON TIMERS DEFINITIONS
  657. \**************************/
  658. #define AR5K_BEACON_PERIOD 0x0000ffff
  659. #define AR5K_BEACON_ENA 0x00800000 /*enable beacon xmit*/
  660. #define AR5K_BEACON_RESET_TSF 0x01000000 /*force a TSF reset*/
  661. /*
  662. * TSF to TU conversion:
  663. *
  664. * TSF is a 64bit value in usec (microseconds).
  665. * TU is a 32bit value and defined by IEEE802.11 (page 6) as "A measurement of
  666. * time equal to 1024 usec", so it's roughly milliseconds (usec / 1024).
  667. */
  668. #define TSF_TO_TU(_tsf) (u32)((_tsf) >> 10)
  669. /*******************************\
  670. GAIN OPTIMIZATION DEFINITIONS
  671. \*******************************/
  672. /**
  673. * enum ath5k_rfgain - RF Gain optimization engine state
  674. * @AR5K_RFGAIN_INACTIVE: Engine disabled
  675. * @AR5K_RFGAIN_ACTIVE: Probe active
  676. * @AR5K_RFGAIN_READ_REQUESTED: Probe requested
  677. * @AR5K_RFGAIN_NEED_CHANGE: Gain_F needs change
  678. */
  679. enum ath5k_rfgain {
  680. AR5K_RFGAIN_INACTIVE = 0,
  681. AR5K_RFGAIN_ACTIVE,
  682. AR5K_RFGAIN_READ_REQUESTED,
  683. AR5K_RFGAIN_NEED_CHANGE,
  684. };
  685. /**
  686. * struct ath5k_gain - RF Gain optimization engine state data
  687. * @g_step_idx: Current step index
  688. * @g_current: Current gain
  689. * @g_target: Target gain
  690. * @g_low: Low gain boundary
  691. * @g_high: High gain boundary
  692. * @g_f_corr: Gain_F correction
  693. * @g_state: One of enum ath5k_rfgain
  694. */
  695. struct ath5k_gain {
  696. u8 g_step_idx;
  697. u8 g_current;
  698. u8 g_target;
  699. u8 g_low;
  700. u8 g_high;
  701. u8 g_f_corr;
  702. u8 g_state;
  703. };
  704. /********************\
  705. COMMON DEFINITIONS
  706. \********************/
  707. #define AR5K_SLOT_TIME_9 396
  708. #define AR5K_SLOT_TIME_20 880
  709. #define AR5K_SLOT_TIME_MAX 0xffff
  710. /**
  711. * struct ath5k_athchan_2ghz - 2GHz to 5GHZ map for RF5111
  712. * @a2_flags: Channel flags (internal)
  713. * @a2_athchan: HW channel number (internal)
  714. *
  715. * This structure is used to map 2GHz channels to
  716. * 5GHz Atheros channels on 2111 frequency converter
  717. * that comes together with RF5111
  718. * TODO: Clean up
  719. */
  720. struct ath5k_athchan_2ghz {
  721. u32 a2_flags;
  722. u16 a2_athchan;
  723. };
  724. /**
  725. * enum ath5k_dmasize - DMA size definitions (2^(n+2))
  726. * @AR5K_DMASIZE_4B: 4Bytes
  727. * @AR5K_DMASIZE_8B: 8Bytes
  728. * @AR5K_DMASIZE_16B: 16Bytes
  729. * @AR5K_DMASIZE_32B: 32Bytes
  730. * @AR5K_DMASIZE_64B: 64Bytes (Default)
  731. * @AR5K_DMASIZE_128B: 128Bytes
  732. * @AR5K_DMASIZE_256B: 256Bytes
  733. * @AR5K_DMASIZE_512B: 512Bytes
  734. *
  735. * These are used to set DMA burst size on hw
  736. *
  737. * Note: Some platforms can't handle more than 4Bytes
  738. * be careful on embedded boards.
  739. */
  740. enum ath5k_dmasize {
  741. AR5K_DMASIZE_4B = 0,
  742. AR5K_DMASIZE_8B,
  743. AR5K_DMASIZE_16B,
  744. AR5K_DMASIZE_32B,
  745. AR5K_DMASIZE_64B,
  746. AR5K_DMASIZE_128B,
  747. AR5K_DMASIZE_256B,
  748. AR5K_DMASIZE_512B
  749. };
  750. /******************\
  751. RATE DEFINITIONS
  752. \******************/
  753. /**
  754. * DOC: Rate codes
  755. *
  756. * Seems the ar5xxx hardware supports up to 32 rates, indexed by 1-32.
  757. *
  758. * The rate code is used to get the RX rate or set the TX rate on the
  759. * hardware descriptors. It is also used for internal modulation control
  760. * and settings.
  761. *
  762. * This is the hardware rate map we are aware of (html unfriendly):
  763. *
  764. * Rate code Rate (Kbps)
  765. * --------- -----------
  766. * 0x01 3000 (XR)
  767. * 0x02 1000 (XR)
  768. * 0x03 250 (XR)
  769. * 0x04 - 05 -Reserved-
  770. * 0x06 2000 (XR)
  771. * 0x07 500 (XR)
  772. * 0x08 48000 (OFDM)
  773. * 0x09 24000 (OFDM)
  774. * 0x0A 12000 (OFDM)
  775. * 0x0B 6000 (OFDM)
  776. * 0x0C 54000 (OFDM)
  777. * 0x0D 36000 (OFDM)
  778. * 0x0E 18000 (OFDM)
  779. * 0x0F 9000 (OFDM)
  780. * 0x10 - 17 -Reserved-
  781. * 0x18 11000L (CCK)
  782. * 0x19 5500L (CCK)
  783. * 0x1A 2000L (CCK)
  784. * 0x1B 1000L (CCK)
  785. * 0x1C 11000S (CCK)
  786. * 0x1D 5500S (CCK)
  787. * 0x1E 2000S (CCK)
  788. * 0x1F -Reserved-
  789. *
  790. * "S" indicates CCK rates with short preamble and "L" with long preamble.
  791. *
  792. * AR5211 has different rate codes for CCK (802.11B) rates. It only uses the
  793. * lowest 4 bits, so they are the same as above with a 0xF mask.
  794. * (0xB, 0xA, 0x9 and 0x8 for 1M, 2M, 5.5M and 11M).
  795. * We handle this in ath5k_setup_bands().
  796. */
  797. #define AR5K_MAX_RATES 32
  798. /* B */
  799. #define ATH5K_RATE_CODE_1M 0x1B
  800. #define ATH5K_RATE_CODE_2M 0x1A
  801. #define ATH5K_RATE_CODE_5_5M 0x19
  802. #define ATH5K_RATE_CODE_11M 0x18
  803. /* A and G */
  804. #define ATH5K_RATE_CODE_6M 0x0B
  805. #define ATH5K_RATE_CODE_9M 0x0F
  806. #define ATH5K_RATE_CODE_12M 0x0A
  807. #define ATH5K_RATE_CODE_18M 0x0E
  808. #define ATH5K_RATE_CODE_24M 0x09
  809. #define ATH5K_RATE_CODE_36M 0x0D
  810. #define ATH5K_RATE_CODE_48M 0x08
  811. #define ATH5K_RATE_CODE_54M 0x0C
  812. /* Adding this flag to rate_code on B rates
  813. * enables short preamble */
  814. #define AR5K_SET_SHORT_PREAMBLE 0x04
  815. /*
  816. * Crypto definitions
  817. */
  818. #define AR5K_KEYCACHE_SIZE 8
  819. extern bool ath5k_modparam_nohwcrypt;
  820. /***********************\
  821. HW RELATED DEFINITIONS
  822. \***********************/
  823. /*
  824. * Misc definitions
  825. */
  826. #define AR5K_RSSI_EP_MULTIPLIER (1 << 7)
  827. #define AR5K_ASSERT_ENTRY(_e, _s) do { \
  828. if (_e >= _s) \
  829. return false; \
  830. } while (0)
  831. /*
  832. * Hardware interrupt abstraction
  833. */
  834. /**
  835. * enum ath5k_int - Hardware interrupt masks helpers
  836. * @AR5K_INT_RXOK: Frame successfully received
  837. * @AR5K_INT_RXDESC: Request RX descriptor/Read RX descriptor
  838. * @AR5K_INT_RXERR: Frame reception failed
  839. * @AR5K_INT_RXNOFRM: No frame received within a specified time period
  840. * @AR5K_INT_RXEOL: Reached "End Of List", means we need more RX descriptors
  841. * @AR5K_INT_RXORN: Indicates we got RX FIFO overrun. Note that Rx overrun is
  842. * not always fatal, on some chips we can continue operation
  843. * without resetting the card, that's why %AR5K_INT_FATAL is not
  844. * common for all chips.
  845. * @AR5K_INT_RX_ALL: Mask to identify all RX related interrupts
  846. *
  847. * @AR5K_INT_TXOK: Frame transmission success
  848. * @AR5K_INT_TXDESC: Request TX descriptor/Read TX status descriptor
  849. * @AR5K_INT_TXERR: Frame transmission failure
  850. * @AR5K_INT_TXEOL: Received End Of List for VEOL (Virtual End Of List). The
  851. * Queue Control Unit (QCU) signals an EOL interrupt only if a
  852. * descriptor's LinkPtr is NULL. For more details, refer to:
  853. * "http://www.freepatentsonline.com/20030225739.html"
  854. * @AR5K_INT_TXNOFRM: No frame was transmitted within a specified time period
  855. * @AR5K_INT_TXURN: Indicates we got TX FIFO underrun. In such case we should
  856. * increase the TX trigger threshold.
  857. * @AR5K_INT_TX_ALL: Mask to identify all TX related interrupts
  858. *
  859. * @AR5K_INT_MIB: Indicates the either Management Information Base counters or
  860. * one of the PHY error counters reached the maximum value and
  861. * should be read and cleared.
  862. * @AR5K_INT_SWI: Software triggered interrupt.
  863. * @AR5K_INT_RXPHY: RX PHY Error
  864. * @AR5K_INT_RXKCM: RX Key cache miss
  865. * @AR5K_INT_SWBA: SoftWare Beacon Alert - indicates its time to send a
  866. * beacon that must be handled in software. The alternative is if
  867. * you have VEOL support, in that case you let the hardware deal
  868. * with things.
  869. * @AR5K_INT_BRSSI: Beacon received with an RSSI value below our threshold
  870. * @AR5K_INT_BMISS: If in STA mode this indicates we have stopped seeing
  871. * beacons from the AP have associated with, we should probably
  872. * try to reassociate. When in IBSS mode this might mean we have
  873. * not received any beacons from any local stations. Note that
  874. * every station in an IBSS schedules to send beacons at the
  875. * Target Beacon Transmission Time (TBTT) with a random backoff.
  876. * @AR5K_INT_BNR: Beacon queue got triggered (DMA beacon alert) while empty.
  877. * @AR5K_INT_TIM: Beacon with local station's TIM bit set
  878. * @AR5K_INT_DTIM: Beacon with DTIM bit and zero DTIM count received
  879. * @AR5K_INT_DTIM_SYNC: DTIM sync lost
  880. * @AR5K_INT_GPIO: GPIO interrupt is used for RF Kill switches connected to
  881. * our GPIO pins.
  882. * @AR5K_INT_BCN_TIMEOUT: Beacon timeout, we waited after TBTT but got noting
  883. * @AR5K_INT_CAB_TIMEOUT: We waited for CAB traffic after the beacon but got
  884. * nothing or an incomplete CAB frame sequence.
  885. * @AR5K_INT_QCBRORN: A queue got it's CBR counter expired
  886. * @AR5K_INT_QCBRURN: A queue got triggered wile empty
  887. * @AR5K_INT_QTRIG: A queue got triggered
  888. *
  889. * @AR5K_INT_FATAL: Fatal errors were encountered, typically caused by bus/DMA
  890. * errors. Indicates we need to reset the card.
  891. * @AR5K_INT_GLOBAL: Used to clear and set the IER
  892. * @AR5K_INT_NOCARD: Signals the card has been removed
  893. * @AR5K_INT_COMMON: Common interrupts shared among MACs with the same
  894. * bit value
  895. *
  896. * These are mapped to take advantage of some common bits
  897. * between the MACs, to be able to set intr properties
  898. * easier. Some of them are not used yet inside hw.c. Most map
  899. * to the respective hw interrupt value as they are common among different
  900. * MACs.
  901. */
  902. enum ath5k_int {
  903. AR5K_INT_RXOK = 0x00000001,
  904. AR5K_INT_RXDESC = 0x00000002,
  905. AR5K_INT_RXERR = 0x00000004,
  906. AR5K_INT_RXNOFRM = 0x00000008,
  907. AR5K_INT_RXEOL = 0x00000010,
  908. AR5K_INT_RXORN = 0x00000020,
  909. AR5K_INT_TXOK = 0x00000040,
  910. AR5K_INT_TXDESC = 0x00000080,
  911. AR5K_INT_TXERR = 0x00000100,
  912. AR5K_INT_TXNOFRM = 0x00000200,
  913. AR5K_INT_TXEOL = 0x00000400,
  914. AR5K_INT_TXURN = 0x00000800,
  915. AR5K_INT_MIB = 0x00001000,
  916. AR5K_INT_SWI = 0x00002000,
  917. AR5K_INT_RXPHY = 0x00004000,
  918. AR5K_INT_RXKCM = 0x00008000,
  919. AR5K_INT_SWBA = 0x00010000,
  920. AR5K_INT_BRSSI = 0x00020000,
  921. AR5K_INT_BMISS = 0x00040000,
  922. AR5K_INT_FATAL = 0x00080000, /* Non common */
  923. AR5K_INT_BNR = 0x00100000, /* Non common */
  924. AR5K_INT_TIM = 0x00200000, /* Non common */
  925. AR5K_INT_DTIM = 0x00400000, /* Non common */
  926. AR5K_INT_DTIM_SYNC = 0x00800000, /* Non common */
  927. AR5K_INT_GPIO = 0x01000000,
  928. AR5K_INT_BCN_TIMEOUT = 0x02000000, /* Non common */
  929. AR5K_INT_CAB_TIMEOUT = 0x04000000, /* Non common */
  930. AR5K_INT_QCBRORN = 0x08000000, /* Non common */
  931. AR5K_INT_QCBRURN = 0x10000000, /* Non common */
  932. AR5K_INT_QTRIG = 0x20000000, /* Non common */
  933. AR5K_INT_GLOBAL = 0x80000000,
  934. AR5K_INT_TX_ALL = AR5K_INT_TXOK
  935. | AR5K_INT_TXDESC
  936. | AR5K_INT_TXERR
  937. | AR5K_INT_TXNOFRM
  938. | AR5K_INT_TXEOL
  939. | AR5K_INT_TXURN,
  940. AR5K_INT_RX_ALL = AR5K_INT_RXOK
  941. | AR5K_INT_RXDESC
  942. | AR5K_INT_RXERR
  943. | AR5K_INT_RXNOFRM
  944. | AR5K_INT_RXEOL
  945. | AR5K_INT_RXORN,
  946. AR5K_INT_COMMON = AR5K_INT_RXOK
  947. | AR5K_INT_RXDESC
  948. | AR5K_INT_RXERR
  949. | AR5K_INT_RXNOFRM
  950. | AR5K_INT_RXEOL
  951. | AR5K_INT_RXORN
  952. | AR5K_INT_TXOK
  953. | AR5K_INT_TXDESC
  954. | AR5K_INT_TXERR
  955. | AR5K_INT_TXNOFRM
  956. | AR5K_INT_TXEOL
  957. | AR5K_INT_TXURN
  958. | AR5K_INT_MIB
  959. | AR5K_INT_SWI
  960. | AR5K_INT_RXPHY
  961. | AR5K_INT_RXKCM
  962. | AR5K_INT_SWBA
  963. | AR5K_INT_BRSSI
  964. | AR5K_INT_BMISS
  965. | AR5K_INT_GPIO
  966. | AR5K_INT_GLOBAL,
  967. AR5K_INT_NOCARD = 0xffffffff
  968. };
  969. /**
  970. * enum ath5k_calibration_mask - Mask which calibration is active at the moment
  971. * @AR5K_CALIBRATION_FULL: Full calibration (AGC + SHORT)
  972. * @AR5K_CALIBRATION_SHORT: Short calibration (NF + I/Q)
  973. * @AR5K_CALIBRATION_NF: Noise Floor calibration
  974. * @AR5K_CALIBRATION_ANI: Adaptive Noise Immunity
  975. */
  976. enum ath5k_calibration_mask {
  977. AR5K_CALIBRATION_FULL = 0x01,
  978. AR5K_CALIBRATION_SHORT = 0x02,
  979. AR5K_CALIBRATION_NF = 0x04,
  980. AR5K_CALIBRATION_ANI = 0x08,
  981. };
  982. /**
  983. * enum ath5k_power_mode - Power management modes
  984. * @AR5K_PM_UNDEFINED: Undefined
  985. * @AR5K_PM_AUTO: Allow card to sleep if possible
  986. * @AR5K_PM_AWAKE: Force card to wake up
  987. * @AR5K_PM_FULL_SLEEP: Force card to full sleep (DANGEROUS)
  988. * @AR5K_PM_NETWORK_SLEEP: Allow to sleep for a specified duration
  989. *
  990. * Currently only PM_AWAKE is used, FULL_SLEEP and NETWORK_SLEEP/AUTO
  991. * are also known to have problems on some cards. This is not a big
  992. * problem though because we can have almost the same effect as
  993. * FULL_SLEEP by putting card on warm reset (it's almost powered down).
  994. */
  995. enum ath5k_power_mode {
  996. AR5K_PM_UNDEFINED = 0,
  997. AR5K_PM_AUTO,
  998. AR5K_PM_AWAKE,
  999. AR5K_PM_FULL_SLEEP,
  1000. AR5K_PM_NETWORK_SLEEP,
  1001. };
  1002. /*
  1003. * These match net80211 definitions (not used in
  1004. * mac80211).
  1005. * TODO: Clean this up
  1006. */
  1007. #define AR5K_LED_INIT 0 /*IEEE80211_S_INIT*/
  1008. #define AR5K_LED_SCAN 1 /*IEEE80211_S_SCAN*/
  1009. #define AR5K_LED_AUTH 2 /*IEEE80211_S_AUTH*/
  1010. #define AR5K_LED_ASSOC 3 /*IEEE80211_S_ASSOC*/
  1011. #define AR5K_LED_RUN 4 /*IEEE80211_S_RUN*/
  1012. /* GPIO-controlled software LED */
  1013. #define AR5K_SOFTLED_PIN 0
  1014. #define AR5K_SOFTLED_ON 0
  1015. #define AR5K_SOFTLED_OFF 1
  1016. /* XXX: we *may* move cap_range stuff to struct wiphy */
  1017. struct ath5k_capabilities {
  1018. /*
  1019. * Supported PHY modes
  1020. * (ie. AR5K_MODE_11A, AR5K_MODE_11B, ...)
  1021. */
  1022. DECLARE_BITMAP(cap_mode, AR5K_MODE_MAX);
  1023. /*
  1024. * Frequency range (without regulation restrictions)
  1025. */
  1026. struct {
  1027. u16 range_2ghz_min;
  1028. u16 range_2ghz_max;
  1029. u16 range_5ghz_min;
  1030. u16 range_5ghz_max;
  1031. } cap_range;
  1032. /*
  1033. * Values stored in the EEPROM (some of them...)
  1034. */
  1035. struct ath5k_eeprom_info cap_eeprom;
  1036. /*
  1037. * Queue information
  1038. */
  1039. struct {
  1040. u8 q_tx_num;
  1041. } cap_queues;
  1042. bool cap_has_phyerr_counters;
  1043. bool cap_has_mrr_support;
  1044. bool cap_needs_2GHz_ovr;
  1045. };
  1046. /* size of noise floor history (keep it a power of two) */
  1047. #define ATH5K_NF_CAL_HIST_MAX 8
  1048. struct ath5k_nfcal_hist {
  1049. s16 index; /* current index into nfval */
  1050. s16 nfval[ATH5K_NF_CAL_HIST_MAX]; /* last few noise floors */
  1051. };
  1052. #define ATH5K_LED_MAX_NAME_LEN 31
  1053. /*
  1054. * State for LED triggers
  1055. */
  1056. struct ath5k_led {
  1057. char name[ATH5K_LED_MAX_NAME_LEN + 1]; /* name of the LED in sysfs */
  1058. struct ath5k_hw *ah; /* driver state */
  1059. struct led_classdev led_dev; /* led classdev */
  1060. };
  1061. /* Rfkill */
  1062. struct ath5k_rfkill {
  1063. /* GPIO PIN for rfkill */
  1064. u16 gpio;
  1065. /* polarity of rfkill GPIO PIN */
  1066. bool polarity;
  1067. /* RFKILL toggle tasklet */
  1068. struct tasklet_struct toggleq;
  1069. };
  1070. /* statistics */
  1071. struct ath5k_statistics {
  1072. /* antenna use */
  1073. unsigned int antenna_rx[5]; /* frames count per antenna RX */
  1074. unsigned int antenna_tx[5]; /* frames count per antenna TX */
  1075. /* frame errors */
  1076. unsigned int rx_all_count; /* all RX frames, including errors */
  1077. unsigned int tx_all_count; /* all TX frames, including errors */
  1078. unsigned int rx_bytes_count; /* all RX bytes, including errored pkts
  1079. * and the MAC headers for each packet
  1080. */
  1081. unsigned int tx_bytes_count; /* all TX bytes, including errored pkts
  1082. * and the MAC headers and padding for
  1083. * each packet.
  1084. */
  1085. unsigned int rxerr_crc;
  1086. unsigned int rxerr_phy;
  1087. unsigned int rxerr_phy_code[32];
  1088. unsigned int rxerr_fifo;
  1089. unsigned int rxerr_decrypt;
  1090. unsigned int rxerr_mic;
  1091. unsigned int rxerr_proc;
  1092. unsigned int rxerr_jumbo;
  1093. unsigned int txerr_retry;
  1094. unsigned int txerr_fifo;
  1095. unsigned int txerr_filt;
  1096. /* MIB counters */
  1097. unsigned int ack_fail;
  1098. unsigned int rts_fail;
  1099. unsigned int rts_ok;
  1100. unsigned int fcs_error;
  1101. unsigned int beacons;
  1102. unsigned int mib_intr;
  1103. unsigned int rxorn_intr;
  1104. unsigned int rxeol_intr;
  1105. };
  1106. /*
  1107. * Misc defines
  1108. */
  1109. #define AR5K_MAX_GPIO 10
  1110. #define AR5K_MAX_RF_BANKS 8
  1111. #if CHAN_DEBUG
  1112. #define ATH_CHAN_MAX (26 + 26 + 26 + 200 + 200)
  1113. #else
  1114. #define ATH_CHAN_MAX (14 + 14 + 14 + 252 + 20)
  1115. #endif
  1116. #define ATH_RXBUF 40 /* number of RX buffers */
  1117. #define ATH_TXBUF 200 /* number of TX buffers */
  1118. #define ATH_BCBUF 4 /* number of beacon buffers */
  1119. #define ATH5K_TXQ_LEN_MAX (ATH_TXBUF / 4) /* bufs per queue */
  1120. #define ATH5K_TXQ_LEN_LOW (ATH5K_TXQ_LEN_MAX / 2) /* low mark */
  1121. /* Driver state associated with an instance of a device */
  1122. struct ath5k_hw {
  1123. struct ath_common common;
  1124. struct pci_dev *pdev;
  1125. struct device *dev; /* for dma mapping */
  1126. int irq;
  1127. u16 devid;
  1128. void __iomem *iobase; /* address of the device */
  1129. struct mutex lock; /* dev-level lock */
  1130. struct ieee80211_hw *hw; /* IEEE 802.11 common */
  1131. struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
  1132. struct ieee80211_channel channels[ATH_CHAN_MAX];
  1133. struct ieee80211_rate rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
  1134. s8 rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
  1135. enum nl80211_iftype opmode;
  1136. #ifdef CONFIG_ATH5K_DEBUG
  1137. struct ath5k_dbg_info debug; /* debug info */
  1138. #endif /* CONFIG_ATH5K_DEBUG */
  1139. struct ath5k_buf *bufptr; /* allocated buffer ptr */
  1140. struct ath5k_desc *desc; /* TX/RX descriptors */
  1141. dma_addr_t desc_daddr; /* DMA (physical) address */
  1142. size_t desc_len; /* size of TX/RX descriptors */
  1143. DECLARE_BITMAP(status, 4);
  1144. #define ATH_STAT_INVALID 0 /* disable hardware accesses */
  1145. #define ATH_STAT_PROMISC 1
  1146. #define ATH_STAT_LEDSOFT 2 /* enable LED gpio status */
  1147. #define ATH_STAT_STARTED 3 /* opened & irqs enabled */
  1148. unsigned int filter_flags; /* HW flags, AR5K_RX_FILTER_* */
  1149. struct ieee80211_channel *curchan; /* current h/w channel */
  1150. u16 nvifs;
  1151. enum ath5k_int imask; /* interrupt mask copy */
  1152. spinlock_t irqlock;
  1153. bool rx_pending; /* rx tasklet pending */
  1154. bool tx_pending; /* tx tasklet pending */
  1155. u8 bssidmask[ETH_ALEN];
  1156. unsigned int led_pin, /* GPIO pin for driving LED */
  1157. led_on; /* pin setting for LED on */
  1158. struct work_struct reset_work; /* deferred chip reset */
  1159. struct work_struct calib_work; /* deferred phy calibration */
  1160. struct list_head rxbuf; /* receive buffer */
  1161. spinlock_t rxbuflock;
  1162. u32 *rxlink; /* link ptr in last RX desc */
  1163. struct tasklet_struct rxtq; /* rx intr tasklet */
  1164. struct ath5k_led rx_led; /* rx led */
  1165. struct list_head txbuf; /* transmit buffer */
  1166. spinlock_t txbuflock;
  1167. unsigned int txbuf_len; /* buf count in txbuf list */
  1168. struct ath5k_txq txqs[AR5K_NUM_TX_QUEUES]; /* tx queues */
  1169. struct tasklet_struct txtq; /* tx intr tasklet */
  1170. struct ath5k_led tx_led; /* tx led */
  1171. struct ath5k_rfkill rf_kill;
  1172. spinlock_t block; /* protects beacon */
  1173. struct tasklet_struct beacontq; /* beacon intr tasklet */
  1174. struct list_head bcbuf; /* beacon buffer */
  1175. struct ieee80211_vif *bslot[ATH_BCBUF];
  1176. u16 num_ap_vifs;
  1177. u16 num_adhoc_vifs;
  1178. u16 num_mesh_vifs;
  1179. unsigned int bhalq, /* SW q for outgoing beacons */
  1180. bmisscount, /* missed beacon transmits */
  1181. bintval, /* beacon interval in TU */
  1182. bsent;
  1183. unsigned int nexttbtt; /* next beacon time in TU */
  1184. struct ath5k_txq *cabq; /* content after beacon */
  1185. int power_level; /* Requested tx power in dBm */
  1186. bool assoc; /* associate state */
  1187. bool enable_beacon; /* true if beacons are on */
  1188. struct ath5k_statistics stats;
  1189. struct ath5k_ani_state ani_state;
  1190. struct tasklet_struct ani_tasklet; /* ANI calibration */
  1191. struct delayed_work tx_complete_work;
  1192. struct survey_info survey; /* collected survey info */
  1193. enum ath5k_int ah_imr;
  1194. struct ieee80211_channel *ah_current_channel;
  1195. bool ah_iq_cal_needed;
  1196. bool ah_single_chip;
  1197. enum ath5k_version ah_version;
  1198. enum ath5k_radio ah_radio;
  1199. u32 ah_mac_srev;
  1200. u16 ah_mac_version;
  1201. u16 ah_phy_revision;
  1202. u16 ah_radio_5ghz_revision;
  1203. u16 ah_radio_2ghz_revision;
  1204. #define ah_modes ah_capabilities.cap_mode
  1205. #define ah_ee_version ah_capabilities.cap_eeprom.ee_version
  1206. u8 ah_retry_long;
  1207. u8 ah_retry_short;
  1208. u32 ah_use_32khz_clock;
  1209. u8 ah_coverage_class;
  1210. bool ah_ack_bitrate_high;
  1211. u8 ah_bwmode;
  1212. bool ah_short_slot;
  1213. /* Antenna Control */
  1214. u32 ah_ant_ctl[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX];
  1215. u8 ah_ant_mode;
  1216. u8 ah_tx_ant;
  1217. u8 ah_def_ant;
  1218. struct ath5k_capabilities ah_capabilities;
  1219. struct ath5k_txq_info ah_txq[AR5K_NUM_TX_QUEUES];
  1220. u32 ah_txq_status;
  1221. u32 ah_txq_imr_txok;
  1222. u32 ah_txq_imr_txerr;
  1223. u32 ah_txq_imr_txurn;
  1224. u32 ah_txq_imr_txdesc;
  1225. u32 ah_txq_imr_txeol;
  1226. u32 ah_txq_imr_cbrorn;
  1227. u32 ah_txq_imr_cbrurn;
  1228. u32 ah_txq_imr_qtrig;
  1229. u32 ah_txq_imr_nofrm;
  1230. u32 ah_txq_isr_txok_all;
  1231. u32 ah_txq_isr_txurn;
  1232. u32 ah_txq_isr_qcborn;
  1233. u32 ah_txq_isr_qcburn;
  1234. u32 ah_txq_isr_qtrig;
  1235. u32 *ah_rf_banks;
  1236. size_t ah_rf_banks_size;
  1237. size_t ah_rf_regs_count;
  1238. struct ath5k_gain ah_gain;
  1239. u8 ah_offset[AR5K_MAX_RF_BANKS];
  1240. struct {
  1241. /* Temporary tables used for interpolation */
  1242. u8 tmpL[AR5K_EEPROM_N_PD_GAINS]
  1243. [AR5K_EEPROM_POWER_TABLE_SIZE];
  1244. u8 tmpR[AR5K_EEPROM_N_PD_GAINS]
  1245. [AR5K_EEPROM_POWER_TABLE_SIZE];
  1246. u8 txp_pd_table[AR5K_EEPROM_POWER_TABLE_SIZE * 2];
  1247. u16 txp_rates_power_table[AR5K_MAX_RATES];
  1248. u8 txp_min_idx;
  1249. bool txp_tpc;
  1250. /* Values in 0.25dB units */
  1251. s16 txp_min_pwr;
  1252. s16 txp_max_pwr;
  1253. s16 txp_cur_pwr;
  1254. /* Values in 0.5dB units */
  1255. s16 txp_offset;
  1256. s16 txp_ofdm;
  1257. s16 txp_cck_ofdm_gainf_delta;
  1258. /* Value in dB units */
  1259. s16 txp_cck_ofdm_pwr_delta;
  1260. bool txp_setup;
  1261. } ah_txpower;
  1262. struct ath5k_nfcal_hist ah_nfcal_hist;
  1263. /* average beacon RSSI in our BSS (used by ANI) */
  1264. struct ewma ah_beacon_rssi_avg;
  1265. /* noise floor from last periodic calibration */
  1266. s32 ah_noise_floor;
  1267. /* Calibration timestamp */
  1268. unsigned long ah_cal_next_full;
  1269. unsigned long ah_cal_next_short;
  1270. unsigned long ah_cal_next_ani;
  1271. /* Calibration mask */
  1272. u8 ah_cal_mask;
  1273. /*
  1274. * Function pointers
  1275. */
  1276. int (*ah_setup_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
  1277. unsigned int, unsigned int, int, enum ath5k_pkt_type,
  1278. unsigned int, unsigned int, unsigned int, unsigned int,
  1279. unsigned int, unsigned int, unsigned int, unsigned int);
  1280. int (*ah_proc_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
  1281. struct ath5k_tx_status *);
  1282. int (*ah_proc_rx_desc)(struct ath5k_hw *, struct ath5k_desc *,
  1283. struct ath5k_rx_status *);
  1284. };
  1285. struct ath_bus_ops {
  1286. enum ath_bus_type ath_bus_type;
  1287. void (*read_cachesize)(struct ath_common *common, int *csz);
  1288. bool (*eeprom_read)(struct ath_common *common, u32 off, u16 *data);
  1289. int (*eeprom_read_mac)(struct ath5k_hw *ah, u8 *mac);
  1290. };
  1291. /*
  1292. * Prototypes
  1293. */
  1294. extern const struct ieee80211_ops ath5k_hw_ops;
  1295. /* Initialization and detach functions */
  1296. int ath5k_hw_init(struct ath5k_hw *ah);
  1297. void ath5k_hw_deinit(struct ath5k_hw *ah);
  1298. int ath5k_sysfs_register(struct ath5k_hw *ah);
  1299. void ath5k_sysfs_unregister(struct ath5k_hw *ah);
  1300. /*Chip id helper functions */
  1301. int ath5k_hw_read_srev(struct ath5k_hw *ah);
  1302. /* LED functions */
  1303. int ath5k_init_leds(struct ath5k_hw *ah);
  1304. void ath5k_led_enable(struct ath5k_hw *ah);
  1305. void ath5k_led_off(struct ath5k_hw *ah);
  1306. void ath5k_unregister_leds(struct ath5k_hw *ah);
  1307. /* Reset Functions */
  1308. int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, struct ieee80211_channel *channel);
  1309. int ath5k_hw_on_hold(struct ath5k_hw *ah);
  1310. int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
  1311. struct ieee80211_channel *channel, bool fast, bool skip_pcu);
  1312. int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
  1313. bool is_set);
  1314. /* Power management functions */
  1315. /* Clock rate related functions */
  1316. unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec);
  1317. unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock);
  1318. void ath5k_hw_set_clockrate(struct ath5k_hw *ah);
  1319. /* DMA Related Functions */
  1320. void ath5k_hw_start_rx_dma(struct ath5k_hw *ah);
  1321. u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah);
  1322. int ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr);
  1323. int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue);
  1324. int ath5k_hw_stop_beacon_queue(struct ath5k_hw *ah, unsigned int queue);
  1325. u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue);
  1326. int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue,
  1327. u32 phys_addr);
  1328. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase);
  1329. /* Interrupt handling */
  1330. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah);
  1331. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask);
  1332. enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask);
  1333. void ath5k_hw_update_mib_counters(struct ath5k_hw *ah);
  1334. /* Init/Stop functions */
  1335. void ath5k_hw_dma_init(struct ath5k_hw *ah);
  1336. int ath5k_hw_dma_stop(struct ath5k_hw *ah);
  1337. /* EEPROM access functions */
  1338. int ath5k_eeprom_init(struct ath5k_hw *ah);
  1339. void ath5k_eeprom_detach(struct ath5k_hw *ah);
  1340. /* Protocol Control Unit Functions */
  1341. /* Helpers */
  1342. int ath5k_hw_get_frame_duration(struct ath5k_hw *ah,
  1343. int len, struct ieee80211_rate *rate, bool shortpre);
  1344. unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah);
  1345. unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah);
  1346. int ath5k_hw_set_opmode(struct ath5k_hw *ah, enum nl80211_iftype opmode);
  1347. void ath5k_hw_set_coverage_class(struct ath5k_hw *ah, u8 coverage_class);
  1348. /* RX filter control*/
  1349. int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac);
  1350. void ath5k_hw_set_bssid(struct ath5k_hw *ah);
  1351. void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask);
  1352. void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1);
  1353. u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah);
  1354. void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter);
  1355. /* Receive (DRU) start/stop functions */
  1356. void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah);
  1357. void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah);
  1358. /* Beacon control functions */
  1359. u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah);
  1360. void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64);
  1361. void ath5k_hw_reset_tsf(struct ath5k_hw *ah);
  1362. void ath5k_hw_init_beacon_timers(struct ath5k_hw *ah, u32 next_beacon,
  1363. u32 interval);
  1364. bool ath5k_hw_check_beacon_timers(struct ath5k_hw *ah, int intval);
  1365. /* Init function */
  1366. void ath5k_hw_pcu_init(struct ath5k_hw *ah, enum nl80211_iftype op_mode);
  1367. /* Queue Control Unit, DFS Control Unit Functions */
  1368. int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
  1369. struct ath5k_txq_info *queue_info);
  1370. int ath5k_hw_set_tx_queueprops(struct ath5k_hw *ah, int queue,
  1371. const struct ath5k_txq_info *queue_info);
  1372. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah,
  1373. enum ath5k_tx_queue queue_type,
  1374. struct ath5k_txq_info *queue_info);
  1375. void ath5k_hw_set_tx_retry_limits(struct ath5k_hw *ah,
  1376. unsigned int queue);
  1377. u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue);
  1378. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue);
  1379. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue);
  1380. int ath5k_hw_set_ifs_intervals(struct ath5k_hw *ah, unsigned int slot_time);
  1381. /* Init function */
  1382. int ath5k_hw_init_queues(struct ath5k_hw *ah);
  1383. /* Hardware Descriptor Functions */
  1384. int ath5k_hw_init_desc_functions(struct ath5k_hw *ah);
  1385. int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  1386. u32 size, unsigned int flags);
  1387. int ath5k_hw_setup_mrr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  1388. unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2,
  1389. u_int tx_tries2, unsigned int tx_rate3, u_int tx_tries3);
  1390. /* GPIO Functions */
  1391. void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state);
  1392. int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio);
  1393. int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio);
  1394. u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio);
  1395. int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val);
  1396. void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
  1397. u32 interrupt_level);
  1398. /* RFkill Functions */
  1399. void ath5k_rfkill_hw_start(struct ath5k_hw *ah);
  1400. void ath5k_rfkill_hw_stop(struct ath5k_hw *ah);
  1401. /* Misc functions TODO: Cleanup */
  1402. int ath5k_hw_set_capabilities(struct ath5k_hw *ah);
  1403. int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid, u16 assoc_id);
  1404. int ath5k_hw_disable_pspoll(struct ath5k_hw *ah);
  1405. /* Initial register settings functions */
  1406. int ath5k_hw_write_initvals(struct ath5k_hw *ah, u8 mode, bool change_channel);
  1407. /* PHY functions */
  1408. /* Misc PHY functions */
  1409. u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, enum ieee80211_band band);
  1410. int ath5k_hw_phy_disable(struct ath5k_hw *ah);
  1411. /* Gain_F optimization */
  1412. enum ath5k_rfgain ath5k_hw_gainf_calibrate(struct ath5k_hw *ah);
  1413. int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah);
  1414. /* PHY/RF channel functions */
  1415. bool ath5k_channel_ok(struct ath5k_hw *ah, struct ieee80211_channel *channel);
  1416. /* PHY calibration */
  1417. void ath5k_hw_init_nfcal_hist(struct ath5k_hw *ah);
  1418. int ath5k_hw_phy_calibrate(struct ath5k_hw *ah,
  1419. struct ieee80211_channel *channel);
  1420. void ath5k_hw_update_noise_floor(struct ath5k_hw *ah);
  1421. /* Spur mitigation */
  1422. bool ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
  1423. struct ieee80211_channel *channel);
  1424. /* Antenna control */
  1425. void ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode);
  1426. void ath5k_hw_set_antenna_switch(struct ath5k_hw *ah, u8 ee_mode);
  1427. /* TX power setup */
  1428. int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower);
  1429. /* Init function */
  1430. int ath5k_hw_phy_init(struct ath5k_hw *ah, struct ieee80211_channel *channel,
  1431. u8 mode, bool fast);
  1432. /*
  1433. * Functions used internally
  1434. */
  1435. static inline struct ath_common *ath5k_hw_common(struct ath5k_hw *ah)
  1436. {
  1437. return &ah->common;
  1438. }
  1439. static inline struct ath_regulatory *ath5k_hw_regulatory(struct ath5k_hw *ah)
  1440. {
  1441. return &(ath5k_hw_common(ah)->regulatory);
  1442. }
  1443. #ifdef CONFIG_ATHEROS_AR231X
  1444. #define AR5K_AR2315_PCI_BASE ((void __iomem *)0xb0100000)
  1445. static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
  1446. {
  1447. /* On AR2315 and AR2317 the PCI clock domain registers
  1448. * are outside of the WMAC register space */
  1449. if (unlikely((reg >= 0x4000) && (reg < 0x5000) &&
  1450. (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
  1451. return AR5K_AR2315_PCI_BASE + reg;
  1452. return ah->iobase + reg;
  1453. }
  1454. static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
  1455. {
  1456. return ioread32(ath5k_ahb_reg(ah, reg));
  1457. }
  1458. static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
  1459. {
  1460. iowrite32(val, ath5k_ahb_reg(ah, reg));
  1461. }
  1462. #else
  1463. static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
  1464. {
  1465. return ioread32(ah->iobase + reg);
  1466. }
  1467. static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
  1468. {
  1469. iowrite32(val, ah->iobase + reg);
  1470. }
  1471. #endif
  1472. static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
  1473. {
  1474. return ath5k_hw_common(ah)->bus_ops->ath_bus_type;
  1475. }
  1476. static inline void ath5k_read_cachesize(struct ath_common *common, int *csz)
  1477. {
  1478. common->bus_ops->read_cachesize(common, csz);
  1479. }
  1480. static inline bool ath5k_hw_nvram_read(struct ath5k_hw *ah, u32 off, u16 *data)
  1481. {
  1482. struct ath_common *common = ath5k_hw_common(ah);
  1483. return common->bus_ops->eeprom_read(common, off, data);
  1484. }
  1485. static inline u32 ath5k_hw_bitswap(u32 val, unsigned int bits)
  1486. {
  1487. u32 retval = 0, bit, i;
  1488. for (i = 0; i < bits; i++) {
  1489. bit = (val >> i) & 1;
  1490. retval = (retval << 1) | bit;
  1491. }
  1492. return retval;
  1493. }
  1494. #endif