zd_chip.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /* ZD1211 USB-WLAN driver for Linux
  2. *
  3. * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
  4. * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _ZD_CHIP_H
  20. #define _ZD_CHIP_H
  21. #include <net/mac80211.h>
  22. #include "zd_rf.h"
  23. #include "zd_usb.h"
  24. /* Header for the Media Access Controller (MAC) and the Baseband Processor
  25. * (BBP). It appears that the ZD1211 wraps the old ZD1205 with USB glue and
  26. * adds a processor for handling the USB protocol.
  27. */
  28. /* Address space */
  29. enum {
  30. /* CONTROL REGISTERS */
  31. CR_START = 0x9000,
  32. /* FIRMWARE */
  33. FW_START = 0xee00,
  34. /* EEPROM */
  35. E2P_START = 0xf800,
  36. E2P_LEN = 0x800,
  37. /* EEPROM layout */
  38. E2P_LOAD_CODE_LEN = 0xe, /* base 0xf800 */
  39. E2P_LOAD_VECT_LEN = 0x9, /* base 0xf80e */
  40. /* E2P_DATA indexes into this */
  41. E2P_DATA_LEN = 0x7e, /* base 0xf817 */
  42. E2P_BOOT_CODE_LEN = 0x760, /* base 0xf895 */
  43. E2P_INTR_VECT_LEN = 0xb, /* base 0xfff5 */
  44. /* Some precomputed offsets into the EEPROM */
  45. E2P_DATA_OFFSET = E2P_LOAD_CODE_LEN + E2P_LOAD_VECT_LEN,
  46. E2P_BOOT_CODE_OFFSET = E2P_DATA_OFFSET + E2P_DATA_LEN,
  47. };
  48. #define CTL_REG(offset) ((zd_addr_t)(CR_START + (offset)))
  49. #define E2P_DATA(offset) ((zd_addr_t)(E2P_START + E2P_DATA_OFFSET + (offset)))
  50. #define FWRAW_DATA(offset) ((zd_addr_t)(FW_START + (offset)))
  51. /* 8-bit hardware registers */
  52. #define ZD_CR0 CTL_REG(0x0000)
  53. #define ZD_CR1 CTL_REG(0x0004)
  54. #define ZD_CR2 CTL_REG(0x0008)
  55. #define ZD_CR3 CTL_REG(0x000C)
  56. #define ZD_CR5 CTL_REG(0x0010)
  57. /* bit 5: if set short preamble used
  58. * bit 6: filter band - Japan channel 14 on, else off
  59. */
  60. #define ZD_CR6 CTL_REG(0x0014)
  61. #define ZD_CR7 CTL_REG(0x0018)
  62. #define ZD_CR8 CTL_REG(0x001C)
  63. #define ZD_CR4 CTL_REG(0x0020)
  64. #define ZD_CR9 CTL_REG(0x0024)
  65. /* bit 2: antenna switch (together with ZD_CR10) */
  66. #define ZD_CR10 CTL_REG(0x0028)
  67. /* bit 1: antenna switch (together with ZD_CR9)
  68. * RF2959 controls with ZD_CR11 radion on and off
  69. */
  70. #define ZD_CR11 CTL_REG(0x002C)
  71. /* bit 6: TX power control for OFDM
  72. * RF2959 controls with ZD_CR10 radio on and off
  73. */
  74. #define ZD_CR12 CTL_REG(0x0030)
  75. #define ZD_CR13 CTL_REG(0x0034)
  76. #define ZD_CR14 CTL_REG(0x0038)
  77. #define ZD_CR15 CTL_REG(0x003C)
  78. #define ZD_CR16 CTL_REG(0x0040)
  79. #define ZD_CR17 CTL_REG(0x0044)
  80. #define ZD_CR18 CTL_REG(0x0048)
  81. #define ZD_CR19 CTL_REG(0x004C)
  82. #define ZD_CR20 CTL_REG(0x0050)
  83. #define ZD_CR21 CTL_REG(0x0054)
  84. #define ZD_CR22 CTL_REG(0x0058)
  85. #define ZD_CR23 CTL_REG(0x005C)
  86. #define ZD_CR24 CTL_REG(0x0060) /* CCA threshold */
  87. #define ZD_CR25 CTL_REG(0x0064)
  88. #define ZD_CR26 CTL_REG(0x0068)
  89. #define ZD_CR27 CTL_REG(0x006C)
  90. #define ZD_CR28 CTL_REG(0x0070)
  91. #define ZD_CR29 CTL_REG(0x0074)
  92. #define ZD_CR30 CTL_REG(0x0078)
  93. #define ZD_CR31 CTL_REG(0x007C) /* TX power control for RF in
  94. * CCK mode
  95. */
  96. #define ZD_CR32 CTL_REG(0x0080)
  97. #define ZD_CR33 CTL_REG(0x0084)
  98. #define ZD_CR34 CTL_REG(0x0088)
  99. #define ZD_CR35 CTL_REG(0x008C)
  100. #define ZD_CR36 CTL_REG(0x0090)
  101. #define ZD_CR37 CTL_REG(0x0094)
  102. #define ZD_CR38 CTL_REG(0x0098)
  103. #define ZD_CR39 CTL_REG(0x009C)
  104. #define ZD_CR40 CTL_REG(0x00A0)
  105. #define ZD_CR41 CTL_REG(0x00A4)
  106. #define ZD_CR42 CTL_REG(0x00A8)
  107. #define ZD_CR43 CTL_REG(0x00AC)
  108. #define ZD_CR44 CTL_REG(0x00B0)
  109. #define ZD_CR45 CTL_REG(0x00B4)
  110. #define ZD_CR46 CTL_REG(0x00B8)
  111. #define ZD_CR47 CTL_REG(0x00BC) /* CCK baseband gain
  112. * (patch value might be in EEPROM)
  113. */
  114. #define ZD_CR48 CTL_REG(0x00C0)
  115. #define ZD_CR49 CTL_REG(0x00C4)
  116. #define ZD_CR50 CTL_REG(0x00C8)
  117. #define ZD_CR51 CTL_REG(0x00CC) /* TX power control for RF in
  118. * 6-36M modes
  119. */
  120. #define ZD_CR52 CTL_REG(0x00D0) /* TX power control for RF in
  121. * 48M mode
  122. */
  123. #define ZD_CR53 CTL_REG(0x00D4) /* TX power control for RF in
  124. * 54M mode
  125. */
  126. #define ZD_CR54 CTL_REG(0x00D8)
  127. #define ZD_CR55 CTL_REG(0x00DC)
  128. #define ZD_CR56 CTL_REG(0x00E0)
  129. #define ZD_CR57 CTL_REG(0x00E4)
  130. #define ZD_CR58 CTL_REG(0x00E8)
  131. #define ZD_CR59 CTL_REG(0x00EC)
  132. #define ZD_CR60 CTL_REG(0x00F0)
  133. #define ZD_CR61 CTL_REG(0x00F4)
  134. #define ZD_CR62 CTL_REG(0x00F8)
  135. #define ZD_CR63 CTL_REG(0x00FC)
  136. #define ZD_CR64 CTL_REG(0x0100)
  137. #define ZD_CR65 CTL_REG(0x0104) /* OFDM 54M calibration */
  138. #define ZD_CR66 CTL_REG(0x0108) /* OFDM 48M calibration */
  139. #define ZD_CR67 CTL_REG(0x010C) /* OFDM 36M calibration */
  140. #define ZD_CR68 CTL_REG(0x0110) /* CCK calibration */
  141. #define ZD_CR69 CTL_REG(0x0114)
  142. #define ZD_CR70 CTL_REG(0x0118)
  143. #define ZD_CR71 CTL_REG(0x011C)
  144. #define ZD_CR72 CTL_REG(0x0120)
  145. #define ZD_CR73 CTL_REG(0x0124)
  146. #define ZD_CR74 CTL_REG(0x0128)
  147. #define ZD_CR75 CTL_REG(0x012C)
  148. #define ZD_CR76 CTL_REG(0x0130)
  149. #define ZD_CR77 CTL_REG(0x0134)
  150. #define ZD_CR78 CTL_REG(0x0138)
  151. #define ZD_CR79 CTL_REG(0x013C)
  152. #define ZD_CR80 CTL_REG(0x0140)
  153. #define ZD_CR81 CTL_REG(0x0144)
  154. #define ZD_CR82 CTL_REG(0x0148)
  155. #define ZD_CR83 CTL_REG(0x014C)
  156. #define ZD_CR84 CTL_REG(0x0150)
  157. #define ZD_CR85 CTL_REG(0x0154)
  158. #define ZD_CR86 CTL_REG(0x0158)
  159. #define ZD_CR87 CTL_REG(0x015C)
  160. #define ZD_CR88 CTL_REG(0x0160)
  161. #define ZD_CR89 CTL_REG(0x0164)
  162. #define ZD_CR90 CTL_REG(0x0168)
  163. #define ZD_CR91 CTL_REG(0x016C)
  164. #define ZD_CR92 CTL_REG(0x0170)
  165. #define ZD_CR93 CTL_REG(0x0174)
  166. #define ZD_CR94 CTL_REG(0x0178)
  167. #define ZD_CR95 CTL_REG(0x017C)
  168. #define ZD_CR96 CTL_REG(0x0180)
  169. #define ZD_CR97 CTL_REG(0x0184)
  170. #define ZD_CR98 CTL_REG(0x0188)
  171. #define ZD_CR99 CTL_REG(0x018C)
  172. #define ZD_CR100 CTL_REG(0x0190)
  173. #define ZD_CR101 CTL_REG(0x0194)
  174. #define ZD_CR102 CTL_REG(0x0198)
  175. #define ZD_CR103 CTL_REG(0x019C)
  176. #define ZD_CR104 CTL_REG(0x01A0)
  177. #define ZD_CR105 CTL_REG(0x01A4)
  178. #define ZD_CR106 CTL_REG(0x01A8)
  179. #define ZD_CR107 CTL_REG(0x01AC)
  180. #define ZD_CR108 CTL_REG(0x01B0)
  181. #define ZD_CR109 CTL_REG(0x01B4)
  182. #define ZD_CR110 CTL_REG(0x01B8)
  183. #define ZD_CR111 CTL_REG(0x01BC)
  184. #define ZD_CR112 CTL_REG(0x01C0)
  185. #define ZD_CR113 CTL_REG(0x01C4)
  186. #define ZD_CR114 CTL_REG(0x01C8)
  187. #define ZD_CR115 CTL_REG(0x01CC)
  188. #define ZD_CR116 CTL_REG(0x01D0)
  189. #define ZD_CR117 CTL_REG(0x01D4)
  190. #define ZD_CR118 CTL_REG(0x01D8)
  191. #define ZD_CR119 CTL_REG(0x01DC)
  192. #define ZD_CR120 CTL_REG(0x01E0)
  193. #define ZD_CR121 CTL_REG(0x01E4)
  194. #define ZD_CR122 CTL_REG(0x01E8)
  195. #define ZD_CR123 CTL_REG(0x01EC)
  196. #define ZD_CR124 CTL_REG(0x01F0)
  197. #define ZD_CR125 CTL_REG(0x01F4)
  198. #define ZD_CR126 CTL_REG(0x01F8)
  199. #define ZD_CR127 CTL_REG(0x01FC)
  200. #define ZD_CR128 CTL_REG(0x0200)
  201. #define ZD_CR129 CTL_REG(0x0204)
  202. #define ZD_CR130 CTL_REG(0x0208)
  203. #define ZD_CR131 CTL_REG(0x020C)
  204. #define ZD_CR132 CTL_REG(0x0210)
  205. #define ZD_CR133 CTL_REG(0x0214)
  206. #define ZD_CR134 CTL_REG(0x0218)
  207. #define ZD_CR135 CTL_REG(0x021C)
  208. #define ZD_CR136 CTL_REG(0x0220)
  209. #define ZD_CR137 CTL_REG(0x0224)
  210. #define ZD_CR138 CTL_REG(0x0228)
  211. #define ZD_CR139 CTL_REG(0x022C)
  212. #define ZD_CR140 CTL_REG(0x0230)
  213. #define ZD_CR141 CTL_REG(0x0234)
  214. #define ZD_CR142 CTL_REG(0x0238)
  215. #define ZD_CR143 CTL_REG(0x023C)
  216. #define ZD_CR144 CTL_REG(0x0240)
  217. #define ZD_CR145 CTL_REG(0x0244)
  218. #define ZD_CR146 CTL_REG(0x0248)
  219. #define ZD_CR147 CTL_REG(0x024C)
  220. #define ZD_CR148 CTL_REG(0x0250)
  221. #define ZD_CR149 CTL_REG(0x0254)
  222. #define ZD_CR150 CTL_REG(0x0258)
  223. #define ZD_CR151 CTL_REG(0x025C)
  224. #define ZD_CR152 CTL_REG(0x0260)
  225. #define ZD_CR153 CTL_REG(0x0264)
  226. #define ZD_CR154 CTL_REG(0x0268)
  227. #define ZD_CR155 CTL_REG(0x026C)
  228. #define ZD_CR156 CTL_REG(0x0270)
  229. #define ZD_CR157 CTL_REG(0x0274)
  230. #define ZD_CR158 CTL_REG(0x0278)
  231. #define ZD_CR159 CTL_REG(0x027C)
  232. #define ZD_CR160 CTL_REG(0x0280)
  233. #define ZD_CR161 CTL_REG(0x0284)
  234. #define ZD_CR162 CTL_REG(0x0288)
  235. #define ZD_CR163 CTL_REG(0x028C)
  236. #define ZD_CR164 CTL_REG(0x0290)
  237. #define ZD_CR165 CTL_REG(0x0294)
  238. #define ZD_CR166 CTL_REG(0x0298)
  239. #define ZD_CR167 CTL_REG(0x029C)
  240. #define ZD_CR168 CTL_REG(0x02A0)
  241. #define ZD_CR169 CTL_REG(0x02A4)
  242. #define ZD_CR170 CTL_REG(0x02A8)
  243. #define ZD_CR171 CTL_REG(0x02AC)
  244. #define ZD_CR172 CTL_REG(0x02B0)
  245. #define ZD_CR173 CTL_REG(0x02B4)
  246. #define ZD_CR174 CTL_REG(0x02B8)
  247. #define ZD_CR175 CTL_REG(0x02BC)
  248. #define ZD_CR176 CTL_REG(0x02C0)
  249. #define ZD_CR177 CTL_REG(0x02C4)
  250. #define ZD_CR178 CTL_REG(0x02C8)
  251. #define ZD_CR179 CTL_REG(0x02CC)
  252. #define ZD_CR180 CTL_REG(0x02D0)
  253. #define ZD_CR181 CTL_REG(0x02D4)
  254. #define ZD_CR182 CTL_REG(0x02D8)
  255. #define ZD_CR183 CTL_REG(0x02DC)
  256. #define ZD_CR184 CTL_REG(0x02E0)
  257. #define ZD_CR185 CTL_REG(0x02E4)
  258. #define ZD_CR186 CTL_REG(0x02E8)
  259. #define ZD_CR187 CTL_REG(0x02EC)
  260. #define ZD_CR188 CTL_REG(0x02F0)
  261. #define ZD_CR189 CTL_REG(0x02F4)
  262. #define ZD_CR190 CTL_REG(0x02F8)
  263. #define ZD_CR191 CTL_REG(0x02FC)
  264. #define ZD_CR192 CTL_REG(0x0300)
  265. #define ZD_CR193 CTL_REG(0x0304)
  266. #define ZD_CR194 CTL_REG(0x0308)
  267. #define ZD_CR195 CTL_REG(0x030C)
  268. #define ZD_CR196 CTL_REG(0x0310)
  269. #define ZD_CR197 CTL_REG(0x0314)
  270. #define ZD_CR198 CTL_REG(0x0318)
  271. #define ZD_CR199 CTL_REG(0x031C)
  272. #define ZD_CR200 CTL_REG(0x0320)
  273. #define ZD_CR201 CTL_REG(0x0324)
  274. #define ZD_CR202 CTL_REG(0x0328)
  275. #define ZD_CR203 CTL_REG(0x032C) /* I2C bus template value & flash
  276. * control
  277. */
  278. #define ZD_CR204 CTL_REG(0x0330)
  279. #define ZD_CR205 CTL_REG(0x0334)
  280. #define ZD_CR206 CTL_REG(0x0338)
  281. #define ZD_CR207 CTL_REG(0x033C)
  282. #define ZD_CR208 CTL_REG(0x0340)
  283. #define ZD_CR209 CTL_REG(0x0344)
  284. #define ZD_CR210 CTL_REG(0x0348)
  285. #define ZD_CR211 CTL_REG(0x034C)
  286. #define ZD_CR212 CTL_REG(0x0350)
  287. #define ZD_CR213 CTL_REG(0x0354)
  288. #define ZD_CR214 CTL_REG(0x0358)
  289. #define ZD_CR215 CTL_REG(0x035C)
  290. #define ZD_CR216 CTL_REG(0x0360)
  291. #define ZD_CR217 CTL_REG(0x0364)
  292. #define ZD_CR218 CTL_REG(0x0368)
  293. #define ZD_CR219 CTL_REG(0x036C)
  294. #define ZD_CR220 CTL_REG(0x0370)
  295. #define ZD_CR221 CTL_REG(0x0374)
  296. #define ZD_CR222 CTL_REG(0x0378)
  297. #define ZD_CR223 CTL_REG(0x037C)
  298. #define ZD_CR224 CTL_REG(0x0380)
  299. #define ZD_CR225 CTL_REG(0x0384)
  300. #define ZD_CR226 CTL_REG(0x0388)
  301. #define ZD_CR227 CTL_REG(0x038C)
  302. #define ZD_CR228 CTL_REG(0x0390)
  303. #define ZD_CR229 CTL_REG(0x0394)
  304. #define ZD_CR230 CTL_REG(0x0398)
  305. #define ZD_CR231 CTL_REG(0x039C)
  306. #define ZD_CR232 CTL_REG(0x03A0)
  307. #define ZD_CR233 CTL_REG(0x03A4)
  308. #define ZD_CR234 CTL_REG(0x03A8)
  309. #define ZD_CR235 CTL_REG(0x03AC)
  310. #define ZD_CR236 CTL_REG(0x03B0)
  311. #define ZD_CR240 CTL_REG(0x03C0)
  312. /* bit 7: host-controlled RF register writes
  313. * ZD_CR241-ZD_CR245: for hardware controlled writing of RF bits, not needed for
  314. * USB
  315. */
  316. #define ZD_CR241 CTL_REG(0x03C4)
  317. #define ZD_CR242 CTL_REG(0x03C8)
  318. #define ZD_CR243 CTL_REG(0x03CC)
  319. #define ZD_CR244 CTL_REG(0x03D0)
  320. #define ZD_CR245 CTL_REG(0x03D4)
  321. #define ZD_CR251 CTL_REG(0x03EC) /* only used for activation and
  322. * deactivation of Airoha RFs AL2230
  323. * and AL7230B
  324. */
  325. #define ZD_CR252 CTL_REG(0x03F0)
  326. #define ZD_CR253 CTL_REG(0x03F4)
  327. #define ZD_CR254 CTL_REG(0x03F8)
  328. #define ZD_CR255 CTL_REG(0x03FC)
  329. #define CR_MAX_PHY_REG 255
  330. /* Taken from the ZYDAS driver, not all of them are relevant for the ZD1211
  331. * driver.
  332. */
  333. #define CR_RF_IF_CLK CTL_REG(0x0400)
  334. #define CR_RF_IF_DATA CTL_REG(0x0404)
  335. #define CR_PE1_PE2 CTL_REG(0x0408)
  336. #define CR_PE2_DLY CTL_REG(0x040C)
  337. #define CR_LE1 CTL_REG(0x0410)
  338. #define CR_LE2 CTL_REG(0x0414)
  339. /* Seems to enable/disable GPI (General Purpose IO?) */
  340. #define CR_GPI_EN CTL_REG(0x0418)
  341. #define CR_RADIO_PD CTL_REG(0x042C)
  342. #define CR_RF2948_PD CTL_REG(0x042C)
  343. #define CR_ENABLE_PS_MANUAL_AGC CTL_REG(0x043C)
  344. #define CR_CONFIG_PHILIPS CTL_REG(0x0440)
  345. #define CR_SA2400_SER_AP CTL_REG(0x0444)
  346. #define CR_I2C_WRITE CTL_REG(0x0444)
  347. #define CR_SA2400_SER_RP CTL_REG(0x0448)
  348. #define CR_RADIO_PE CTL_REG(0x0458)
  349. #define CR_RST_BUS_MASTER CTL_REG(0x045C)
  350. #define CR_RFCFG CTL_REG(0x0464)
  351. #define CR_HSTSCHG CTL_REG(0x046C)
  352. #define CR_PHY_ON CTL_REG(0x0474)
  353. #define CR_RX_DELAY CTL_REG(0x0478)
  354. #define CR_RX_PE_DELAY CTL_REG(0x047C)
  355. #define CR_GPIO_1 CTL_REG(0x0490)
  356. #define CR_GPIO_2 CTL_REG(0x0494)
  357. #define CR_EncryBufMux CTL_REG(0x04A8)
  358. #define CR_PS_CTRL CTL_REG(0x0500)
  359. #define CR_ADDA_PWR_DWN CTL_REG(0x0504)
  360. #define CR_ADDA_MBIAS_WARMTIME CTL_REG(0x0508)
  361. #define CR_MAC_PS_STATE CTL_REG(0x050C)
  362. #define CR_INTERRUPT CTL_REG(0x0510)
  363. #define INT_TX_COMPLETE (1 << 0)
  364. #define INT_RX_COMPLETE (1 << 1)
  365. #define INT_RETRY_FAIL (1 << 2)
  366. #define INT_WAKEUP (1 << 3)
  367. #define INT_DTIM_NOTIFY (1 << 5)
  368. #define INT_CFG_NEXT_BCN (1 << 6)
  369. #define INT_BUS_ABORT (1 << 7)
  370. #define INT_TX_FIFO_READY (1 << 8)
  371. #define INT_UART (1 << 9)
  372. #define INT_TX_COMPLETE_EN (1 << 16)
  373. #define INT_RX_COMPLETE_EN (1 << 17)
  374. #define INT_RETRY_FAIL_EN (1 << 18)
  375. #define INT_WAKEUP_EN (1 << 19)
  376. #define INT_DTIM_NOTIFY_EN (1 << 21)
  377. #define INT_CFG_NEXT_BCN_EN (1 << 22)
  378. #define INT_BUS_ABORT_EN (1 << 23)
  379. #define INT_TX_FIFO_READY_EN (1 << 24)
  380. #define INT_UART_EN (1 << 25)
  381. #define CR_TSF_LOW_PART CTL_REG(0x0514)
  382. #define CR_TSF_HIGH_PART CTL_REG(0x0518)
  383. /* Following three values are in time units (1024us)
  384. * Following condition must be met:
  385. * atim < tbtt < bcn
  386. */
  387. #define CR_ATIM_WND_PERIOD CTL_REG(0x051C)
  388. #define CR_BCN_INTERVAL CTL_REG(0x0520)
  389. #define CR_PRE_TBTT CTL_REG(0x0524)
  390. /* in units of TU(1024us) */
  391. /* for UART support */
  392. #define CR_UART_RBR_THR_DLL CTL_REG(0x0540)
  393. #define CR_UART_DLM_IER CTL_REG(0x0544)
  394. #define CR_UART_IIR_FCR CTL_REG(0x0548)
  395. #define CR_UART_LCR CTL_REG(0x054c)
  396. #define CR_UART_MCR CTL_REG(0x0550)
  397. #define CR_UART_LSR CTL_REG(0x0554)
  398. #define CR_UART_MSR CTL_REG(0x0558)
  399. #define CR_UART_ECR CTL_REG(0x055c)
  400. #define CR_UART_STATUS CTL_REG(0x0560)
  401. #define CR_PCI_TX_ADDR_P1 CTL_REG(0x0600)
  402. #define CR_PCI_TX_AddR_P2 CTL_REG(0x0604)
  403. #define CR_PCI_RX_AddR_P1 CTL_REG(0x0608)
  404. #define CR_PCI_RX_AddR_P2 CTL_REG(0x060C)
  405. /* must be overwritten if custom MAC address will be used */
  406. #define CR_MAC_ADDR_P1 CTL_REG(0x0610)
  407. #define CR_MAC_ADDR_P2 CTL_REG(0x0614)
  408. #define CR_BSSID_P1 CTL_REG(0x0618)
  409. #define CR_BSSID_P2 CTL_REG(0x061C)
  410. #define CR_BCN_PLCP_CFG CTL_REG(0x0620)
  411. /* Group hash table for filtering incoming packets.
  412. *
  413. * The group hash table is 64 bit large and split over two parts. The first
  414. * part is the lower part. The upper 6 bits of the last byte of the target
  415. * address are used as index. Packets are received if the hash table bit is
  416. * set. This is used for multicast handling, but for broadcasts (address
  417. * ff:ff:ff:ff:ff:ff) the highest bit in the second table must also be set.
  418. */
  419. #define CR_GROUP_HASH_P1 CTL_REG(0x0624)
  420. #define CR_GROUP_HASH_P2 CTL_REG(0x0628)
  421. #define CR_RX_TIMEOUT CTL_REG(0x062C)
  422. /* Basic rates supported by the BSS. When producing ACK or CTS messages, the
  423. * device will use a rate in this table that is less than or equal to the rate
  424. * of the incoming frame which prompted the response. */
  425. #define CR_BASIC_RATE_TBL CTL_REG(0x0630)
  426. #define CR_RATE_1M (1 << 0) /* 802.11b */
  427. #define CR_RATE_2M (1 << 1) /* 802.11b */
  428. #define CR_RATE_5_5M (1 << 2) /* 802.11b */
  429. #define CR_RATE_11M (1 << 3) /* 802.11b */
  430. #define CR_RATE_6M (1 << 8) /* 802.11g */
  431. #define CR_RATE_9M (1 << 9) /* 802.11g */
  432. #define CR_RATE_12M (1 << 10) /* 802.11g */
  433. #define CR_RATE_18M (1 << 11) /* 802.11g */
  434. #define CR_RATE_24M (1 << 12) /* 802.11g */
  435. #define CR_RATE_36M (1 << 13) /* 802.11g */
  436. #define CR_RATE_48M (1 << 14) /* 802.11g */
  437. #define CR_RATE_54M (1 << 15) /* 802.11g */
  438. #define CR_RATES_80211G 0xff00
  439. #define CR_RATES_80211B 0x000f
  440. /* Mandatory rates required in the BSS. When producing ACK or CTS messages, if
  441. * the device could not find an appropriate rate in CR_BASIC_RATE_TBL, it will
  442. * look for a rate in this table that is less than or equal to the rate of
  443. * the incoming frame. */
  444. #define CR_MANDATORY_RATE_TBL CTL_REG(0x0634)
  445. #define CR_RTS_CTS_RATE CTL_REG(0x0638)
  446. /* These are all bit indexes in CR_RTS_CTS_RATE, so remember to shift. */
  447. #define RTSCTS_SH_RTS_RATE 0
  448. #define RTSCTS_SH_EXP_CTS_RATE 4
  449. #define RTSCTS_SH_RTS_MOD_TYPE 8
  450. #define RTSCTS_SH_RTS_PMB_TYPE 9
  451. #define RTSCTS_SH_CTS_RATE 16
  452. #define RTSCTS_SH_CTS_MOD_TYPE 24
  453. #define RTSCTS_SH_CTS_PMB_TYPE 25
  454. #define CR_WEP_PROTECT CTL_REG(0x063C)
  455. #define CR_RX_THRESHOLD CTL_REG(0x0640)
  456. /* register for controlling the LEDS */
  457. #define CR_LED CTL_REG(0x0644)
  458. /* masks for controlling LEDs */
  459. #define LED1 (1 << 8)
  460. #define LED2 (1 << 9)
  461. #define LED_SW (1 << 10)
  462. /* Seems to indicate that the configuration is over.
  463. */
  464. #define CR_AFTER_PNP CTL_REG(0x0648)
  465. #define CR_ACK_TIME_80211 CTL_REG(0x0658)
  466. #define CR_RX_OFFSET CTL_REG(0x065c)
  467. #define CR_BCN_LENGTH CTL_REG(0x0664)
  468. #define CR_PHY_DELAY CTL_REG(0x066C)
  469. #define CR_BCN_FIFO CTL_REG(0x0670)
  470. #define CR_SNIFFER_ON CTL_REG(0x0674)
  471. #define CR_ENCRYPTION_TYPE CTL_REG(0x0678)
  472. #define NO_WEP 0
  473. #define WEP64 1
  474. #define WEP128 5
  475. #define WEP256 6
  476. #define ENC_SNIFFER 8
  477. #define CR_ZD1211_RETRY_MAX CTL_REG(0x067C)
  478. #define CR_REG1 CTL_REG(0x0680)
  479. /* Setting the bit UNLOCK_PHY_REGS disallows the write access to physical
  480. * registers, so one could argue it is a LOCK bit. But calling it
  481. * LOCK_PHY_REGS makes it confusing.
  482. */
  483. #define UNLOCK_PHY_REGS (1 << 7)
  484. #define CR_DEVICE_STATE CTL_REG(0x0684)
  485. #define CR_UNDERRUN_CNT CTL_REG(0x0688)
  486. #define CR_RX_FILTER CTL_REG(0x068c)
  487. #define RX_FILTER_ASSOC_REQUEST (1 << 0)
  488. #define RX_FILTER_ASSOC_RESPONSE (1 << 1)
  489. #define RX_FILTER_REASSOC_REQUEST (1 << 2)
  490. #define RX_FILTER_REASSOC_RESPONSE (1 << 3)
  491. #define RX_FILTER_PROBE_REQUEST (1 << 4)
  492. #define RX_FILTER_PROBE_RESPONSE (1 << 5)
  493. /* bits 6 and 7 reserved */
  494. #define RX_FILTER_BEACON (1 << 8)
  495. #define RX_FILTER_ATIM (1 << 9)
  496. #define RX_FILTER_DISASSOC (1 << 10)
  497. #define RX_FILTER_AUTH (1 << 11)
  498. #define RX_FILTER_DEAUTH (1 << 12)
  499. #define RX_FILTER_PSPOLL (1 << 26)
  500. #define RX_FILTER_RTS (1 << 27)
  501. #define RX_FILTER_CTS (1 << 28)
  502. #define RX_FILTER_ACK (1 << 29)
  503. #define RX_FILTER_CFEND (1 << 30)
  504. #define RX_FILTER_CFACK (1 << 31)
  505. /* Enable bits for all frames you are interested in. */
  506. #define STA_RX_FILTER (RX_FILTER_ASSOC_REQUEST | RX_FILTER_ASSOC_RESPONSE | \
  507. RX_FILTER_REASSOC_REQUEST | RX_FILTER_REASSOC_RESPONSE | \
  508. RX_FILTER_PROBE_REQUEST | RX_FILTER_PROBE_RESPONSE | \
  509. (0x3 << 6) /* vendor driver sets these reserved bits */ | \
  510. RX_FILTER_BEACON | RX_FILTER_ATIM | RX_FILTER_DISASSOC | \
  511. RX_FILTER_AUTH | RX_FILTER_DEAUTH | \
  512. (0x7 << 13) /* vendor driver sets these reserved bits */ | \
  513. RX_FILTER_PSPOLL | RX_FILTER_ACK) /* 0x2400ffff */
  514. #define RX_FILTER_CTRL (RX_FILTER_RTS | RX_FILTER_CTS | \
  515. RX_FILTER_CFEND | RX_FILTER_CFACK)
  516. #define BCN_MODE_AP 0x1000000
  517. #define BCN_MODE_IBSS 0x2000000
  518. /* Monitor mode sets filter to 0xfffff */
  519. #define CR_ACK_TIMEOUT_EXT CTL_REG(0x0690)
  520. #define CR_BCN_FIFO_SEMAPHORE CTL_REG(0x0694)
  521. #define CR_IFS_VALUE CTL_REG(0x0698)
  522. #define IFS_VALUE_DIFS_SH 0
  523. #define IFS_VALUE_EIFS_SH 12
  524. #define IFS_VALUE_SIFS_SH 24
  525. #define IFS_VALUE_DEFAULT (( 50 << IFS_VALUE_DIFS_SH) | \
  526. (1148 << IFS_VALUE_EIFS_SH) | \
  527. ( 10 << IFS_VALUE_SIFS_SH))
  528. #define CR_RX_TIME_OUT CTL_REG(0x069C)
  529. #define CR_TOTAL_RX_FRM CTL_REG(0x06A0)
  530. #define CR_CRC32_CNT CTL_REG(0x06A4)
  531. #define CR_CRC16_CNT CTL_REG(0x06A8)
  532. #define CR_DECRYPTION_ERR_UNI CTL_REG(0x06AC)
  533. #define CR_RX_FIFO_OVERRUN CTL_REG(0x06B0)
  534. #define CR_DECRYPTION_ERR_MUL CTL_REG(0x06BC)
  535. #define CR_NAV_CNT CTL_REG(0x06C4)
  536. #define CR_NAV_CCA CTL_REG(0x06C8)
  537. #define CR_RETRY_CNT CTL_REG(0x06CC)
  538. #define CR_READ_TCB_ADDR CTL_REG(0x06E8)
  539. #define CR_READ_RFD_ADDR CTL_REG(0x06EC)
  540. #define CR_CWMIN_CWMAX CTL_REG(0x06F0)
  541. #define CR_TOTAL_TX_FRM CTL_REG(0x06F4)
  542. /* CAM: Continuous Access Mode (power management) */
  543. #define CR_CAM_MODE CTL_REG(0x0700)
  544. #define MODE_IBSS 0x0
  545. #define MODE_AP 0x1
  546. #define MODE_STA 0x2
  547. #define MODE_AP_WDS 0x3
  548. #define CR_CAM_ROLL_TB_LOW CTL_REG(0x0704)
  549. #define CR_CAM_ROLL_TB_HIGH CTL_REG(0x0708)
  550. #define CR_CAM_ADDRESS CTL_REG(0x070C)
  551. #define CR_CAM_DATA CTL_REG(0x0710)
  552. #define CR_ROMDIR CTL_REG(0x0714)
  553. #define CR_DECRY_ERR_FLG_LOW CTL_REG(0x0714)
  554. #define CR_DECRY_ERR_FLG_HIGH CTL_REG(0x0718)
  555. #define CR_WEPKEY0 CTL_REG(0x0720)
  556. #define CR_WEPKEY1 CTL_REG(0x0724)
  557. #define CR_WEPKEY2 CTL_REG(0x0728)
  558. #define CR_WEPKEY3 CTL_REG(0x072C)
  559. #define CR_WEPKEY4 CTL_REG(0x0730)
  560. #define CR_WEPKEY5 CTL_REG(0x0734)
  561. #define CR_WEPKEY6 CTL_REG(0x0738)
  562. #define CR_WEPKEY7 CTL_REG(0x073C)
  563. #define CR_WEPKEY8 CTL_REG(0x0740)
  564. #define CR_WEPKEY9 CTL_REG(0x0744)
  565. #define CR_WEPKEY10 CTL_REG(0x0748)
  566. #define CR_WEPKEY11 CTL_REG(0x074C)
  567. #define CR_WEPKEY12 CTL_REG(0x0750)
  568. #define CR_WEPKEY13 CTL_REG(0x0754)
  569. #define CR_WEPKEY14 CTL_REG(0x0758)
  570. #define CR_WEPKEY15 CTL_REG(0x075c)
  571. #define CR_TKIP_MODE CTL_REG(0x0760)
  572. #define CR_EEPROM_PROTECT0 CTL_REG(0x0758)
  573. #define CR_EEPROM_PROTECT1 CTL_REG(0x075C)
  574. #define CR_DBG_FIFO_RD CTL_REG(0x0800)
  575. #define CR_DBG_SELECT CTL_REG(0x0804)
  576. #define CR_FIFO_Length CTL_REG(0x0808)
  577. #define CR_RSSI_MGC CTL_REG(0x0810)
  578. #define CR_PON CTL_REG(0x0818)
  579. #define CR_RX_ON CTL_REG(0x081C)
  580. #define CR_TX_ON CTL_REG(0x0820)
  581. #define CR_CHIP_EN CTL_REG(0x0824)
  582. #define CR_LO_SW CTL_REG(0x0828)
  583. #define CR_TXRX_SW CTL_REG(0x082C)
  584. #define CR_S_MD CTL_REG(0x0830)
  585. #define CR_USB_DEBUG_PORT CTL_REG(0x0888)
  586. #define CR_ZD1211B_CWIN_MAX_MIN_AC0 CTL_REG(0x0b00)
  587. #define CR_ZD1211B_CWIN_MAX_MIN_AC1 CTL_REG(0x0b04)
  588. #define CR_ZD1211B_CWIN_MAX_MIN_AC2 CTL_REG(0x0b08)
  589. #define CR_ZD1211B_CWIN_MAX_MIN_AC3 CTL_REG(0x0b0c)
  590. #define CR_ZD1211B_AIFS_CTL1 CTL_REG(0x0b10)
  591. #define CR_ZD1211B_AIFS_CTL2 CTL_REG(0x0b14)
  592. #define CR_ZD1211B_TXOP CTL_REG(0x0b20)
  593. #define CR_ZD1211B_RETRY_MAX CTL_REG(0x0b28)
  594. /* Value for CR_ZD1211_RETRY_MAX & CR_ZD1211B_RETRY_MAX. Vendor driver uses 2,
  595. * we use 0. The first rate is tried (count+2), then all next rates are tried
  596. * twice, until 1 Mbits is tried. */
  597. #define ZD1211_RETRY_COUNT 0
  598. #define ZD1211B_RETRY_COUNT \
  599. (ZD1211_RETRY_COUNT << 0)| \
  600. (ZD1211_RETRY_COUNT << 8)| \
  601. (ZD1211_RETRY_COUNT << 16)| \
  602. (ZD1211_RETRY_COUNT << 24)
  603. /* Used to detect PLL lock */
  604. #define UW2453_INTR_REG ((zd_addr_t)0x85c1)
  605. #define CWIN_SIZE 0x007f043f
  606. #define HWINT_ENABLED \
  607. (INT_TX_COMPLETE_EN| \
  608. INT_RX_COMPLETE_EN| \
  609. INT_RETRY_FAIL_EN| \
  610. INT_WAKEUP_EN| \
  611. INT_CFG_NEXT_BCN_EN)
  612. #define HWINT_DISABLED 0
  613. #define E2P_PWR_INT_GUARD 8
  614. #define E2P_CHANNEL_COUNT 14
  615. /* If you compare this addresses with the ZYDAS orignal driver, please notify
  616. * that we use word mapping for the EEPROM.
  617. */
  618. /*
  619. * Upper 16 bit contains the regulatory domain.
  620. */
  621. #define E2P_SUBID E2P_DATA(0x00)
  622. #define E2P_POD E2P_DATA(0x02)
  623. #define E2P_MAC_ADDR_P1 E2P_DATA(0x04)
  624. #define E2P_MAC_ADDR_P2 E2P_DATA(0x06)
  625. #define E2P_PWR_CAL_VALUE1 E2P_DATA(0x08)
  626. #define E2P_PWR_CAL_VALUE2 E2P_DATA(0x0a)
  627. #define E2P_PWR_CAL_VALUE3 E2P_DATA(0x0c)
  628. #define E2P_PWR_CAL_VALUE4 E2P_DATA(0x0e)
  629. #define E2P_PWR_INT_VALUE1 E2P_DATA(0x10)
  630. #define E2P_PWR_INT_VALUE2 E2P_DATA(0x12)
  631. #define E2P_PWR_INT_VALUE3 E2P_DATA(0x14)
  632. #define E2P_PWR_INT_VALUE4 E2P_DATA(0x16)
  633. /* Contains a bit for each allowed channel. It gives for Europe (ETSI 0x30)
  634. * also only 11 channels. */
  635. #define E2P_ALLOWED_CHANNEL E2P_DATA(0x18)
  636. #define E2P_DEVICE_VER E2P_DATA(0x20)
  637. #define E2P_PHY_REG E2P_DATA(0x25)
  638. #define E2P_36M_CAL_VALUE1 E2P_DATA(0x28)
  639. #define E2P_36M_CAL_VALUE2 E2P_DATA(0x2a)
  640. #define E2P_36M_CAL_VALUE3 E2P_DATA(0x2c)
  641. #define E2P_36M_CAL_VALUE4 E2P_DATA(0x2e)
  642. #define E2P_11A_INT_VALUE1 E2P_DATA(0x30)
  643. #define E2P_11A_INT_VALUE2 E2P_DATA(0x32)
  644. #define E2P_11A_INT_VALUE3 E2P_DATA(0x34)
  645. #define E2P_11A_INT_VALUE4 E2P_DATA(0x36)
  646. #define E2P_48M_CAL_VALUE1 E2P_DATA(0x38)
  647. #define E2P_48M_CAL_VALUE2 E2P_DATA(0x3a)
  648. #define E2P_48M_CAL_VALUE3 E2P_DATA(0x3c)
  649. #define E2P_48M_CAL_VALUE4 E2P_DATA(0x3e)
  650. #define E2P_48M_INT_VALUE1 E2P_DATA(0x40)
  651. #define E2P_48M_INT_VALUE2 E2P_DATA(0x42)
  652. #define E2P_48M_INT_VALUE3 E2P_DATA(0x44)
  653. #define E2P_48M_INT_VALUE4 E2P_DATA(0x46)
  654. #define E2P_54M_CAL_VALUE1 E2P_DATA(0x48) /* ??? */
  655. #define E2P_54M_CAL_VALUE2 E2P_DATA(0x4a)
  656. #define E2P_54M_CAL_VALUE3 E2P_DATA(0x4c)
  657. #define E2P_54M_CAL_VALUE4 E2P_DATA(0x4e)
  658. #define E2P_54M_INT_VALUE1 E2P_DATA(0x50)
  659. #define E2P_54M_INT_VALUE2 E2P_DATA(0x52)
  660. #define E2P_54M_INT_VALUE3 E2P_DATA(0x54)
  661. #define E2P_54M_INT_VALUE4 E2P_DATA(0x56)
  662. /* This word contains the base address of the FW_REG_ registers below */
  663. #define FWRAW_REGS_ADDR FWRAW_DATA(0x1d)
  664. /* All 16 bit values, offset from the address in FWRAW_REGS_ADDR */
  665. enum {
  666. FW_REG_FIRMWARE_VER = 0,
  667. /* non-zero if USB high speed connection */
  668. FW_REG_USB_SPEED = 1,
  669. FW_REG_FIX_TX_RATE = 2,
  670. /* Seems to be able to control LEDs over the firmware */
  671. FW_REG_LED_LINK_STATUS = 3,
  672. FW_REG_SOFT_RESET = 4,
  673. FW_REG_FLASH_CHK = 5,
  674. };
  675. /* Values for FW_LINK_STATUS */
  676. #define FW_LINK_OFF 0x0
  677. #define FW_LINK_TX 0x1
  678. /* 0x2 - link led on? */
  679. enum {
  680. /* indices for ofdm_cal_values */
  681. OFDM_36M_INDEX = 0,
  682. OFDM_48M_INDEX = 1,
  683. OFDM_54M_INDEX = 2,
  684. };
  685. struct zd_chip {
  686. struct zd_usb usb;
  687. struct zd_rf rf;
  688. struct mutex mutex;
  689. /* Base address of FW_REG_ registers */
  690. zd_addr_t fw_regs_base;
  691. /* EepSetPoint in the vendor driver */
  692. u8 pwr_cal_values[E2P_CHANNEL_COUNT];
  693. /* integration values in the vendor driver */
  694. u8 pwr_int_values[E2P_CHANNEL_COUNT];
  695. /* SetPointOFDM in the vendor driver */
  696. u8 ofdm_cal_values[3][E2P_CHANNEL_COUNT];
  697. u16 link_led;
  698. unsigned int pa_type:4,
  699. patch_cck_gain:1, patch_cr157:1, patch_6m_band_edge:1,
  700. new_phy_layout:1, al2230s_bit:1,
  701. supports_tx_led:1;
  702. };
  703. static inline struct zd_chip *zd_usb_to_chip(struct zd_usb *usb)
  704. {
  705. return container_of(usb, struct zd_chip, usb);
  706. }
  707. static inline struct zd_chip *zd_rf_to_chip(struct zd_rf *rf)
  708. {
  709. return container_of(rf, struct zd_chip, rf);
  710. }
  711. #define zd_chip_dev(chip) (&(chip)->usb.intf->dev)
  712. void zd_chip_init(struct zd_chip *chip,
  713. struct ieee80211_hw *hw,
  714. struct usb_interface *intf);
  715. void zd_chip_clear(struct zd_chip *chip);
  716. int zd_chip_read_mac_addr_fw(struct zd_chip *chip, u8 *addr);
  717. int zd_chip_init_hw(struct zd_chip *chip);
  718. int zd_chip_reset(struct zd_chip *chip);
  719. static inline int zd_chip_is_zd1211b(struct zd_chip *chip)
  720. {
  721. return chip->usb.is_zd1211b;
  722. }
  723. static inline int zd_ioread16v_locked(struct zd_chip *chip, u16 *values,
  724. const zd_addr_t *addresses,
  725. unsigned int count)
  726. {
  727. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  728. return zd_usb_ioread16v(&chip->usb, values, addresses, count);
  729. }
  730. static inline int zd_ioread16_locked(struct zd_chip *chip, u16 *value,
  731. const zd_addr_t addr)
  732. {
  733. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  734. return zd_usb_ioread16(&chip->usb, value, addr);
  735. }
  736. int zd_ioread32v_locked(struct zd_chip *chip, u32 *values,
  737. const zd_addr_t *addresses, unsigned int count);
  738. static inline int zd_ioread32_locked(struct zd_chip *chip, u32 *value,
  739. const zd_addr_t addr)
  740. {
  741. return zd_ioread32v_locked(chip, value, &addr, 1);
  742. }
  743. static inline int zd_iowrite16_locked(struct zd_chip *chip, u16 value,
  744. zd_addr_t addr)
  745. {
  746. struct zd_ioreq16 ioreq;
  747. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  748. ioreq.addr = addr;
  749. ioreq.value = value;
  750. return zd_usb_iowrite16v(&chip->usb, &ioreq, 1);
  751. }
  752. int zd_iowrite16a_locked(struct zd_chip *chip,
  753. const struct zd_ioreq16 *ioreqs, unsigned int count);
  754. int _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
  755. unsigned int count);
  756. static inline int zd_iowrite32_locked(struct zd_chip *chip, u32 value,
  757. zd_addr_t addr)
  758. {
  759. struct zd_ioreq32 ioreq;
  760. ioreq.addr = addr;
  761. ioreq.value = value;
  762. return _zd_iowrite32v_locked(chip, &ioreq, 1);
  763. }
  764. int zd_iowrite32a_locked(struct zd_chip *chip,
  765. const struct zd_ioreq32 *ioreqs, unsigned int count);
  766. static inline int zd_rfwrite_locked(struct zd_chip *chip, u32 value, u8 bits)
  767. {
  768. ZD_ASSERT(mutex_is_locked(&chip->mutex));
  769. return zd_usb_rfwrite(&chip->usb, value, bits);
  770. }
  771. int zd_rfwrite_cr_locked(struct zd_chip *chip, u32 value);
  772. int zd_rfwritev_locked(struct zd_chip *chip,
  773. const u32* values, unsigned int count, u8 bits);
  774. int zd_rfwritev_cr_locked(struct zd_chip *chip,
  775. const u32* values, unsigned int count);
  776. /* Locking functions for reading and writing registers.
  777. * The different parameters are intentional.
  778. */
  779. int zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value);
  780. int zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value);
  781. int zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value);
  782. int zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value);
  783. int zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses,
  784. u32 *values, unsigned int count);
  785. int zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
  786. unsigned int count);
  787. int zd_chip_set_channel(struct zd_chip *chip, u8 channel);
  788. static inline u8 _zd_chip_get_channel(struct zd_chip *chip)
  789. {
  790. return chip->rf.channel;
  791. }
  792. u8 zd_chip_get_channel(struct zd_chip *chip);
  793. int zd_read_regdomain(struct zd_chip *chip, u8 *regdomain);
  794. int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr);
  795. int zd_write_bssid(struct zd_chip *chip, const u8 *bssid);
  796. int zd_chip_switch_radio_on(struct zd_chip *chip);
  797. int zd_chip_switch_radio_off(struct zd_chip *chip);
  798. int zd_chip_enable_int(struct zd_chip *chip);
  799. void zd_chip_disable_int(struct zd_chip *chip);
  800. int zd_chip_enable_rxtx(struct zd_chip *chip);
  801. void zd_chip_disable_rxtx(struct zd_chip *chip);
  802. int zd_chip_enable_hwint(struct zd_chip *chip);
  803. int zd_chip_disable_hwint(struct zd_chip *chip);
  804. int zd_chip_generic_patch_6m_band(struct zd_chip *chip, int channel);
  805. int zd_chip_set_rts_cts_rate_locked(struct zd_chip *chip, int preamble);
  806. static inline int zd_get_encryption_type(struct zd_chip *chip, u32 *type)
  807. {
  808. return zd_ioread32(chip, CR_ENCRYPTION_TYPE, type);
  809. }
  810. static inline int zd_set_encryption_type(struct zd_chip *chip, u32 type)
  811. {
  812. return zd_iowrite32(chip, CR_ENCRYPTION_TYPE, type);
  813. }
  814. static inline int zd_chip_get_basic_rates(struct zd_chip *chip, u16 *cr_rates)
  815. {
  816. return zd_ioread16(chip, CR_BASIC_RATE_TBL, cr_rates);
  817. }
  818. int zd_chip_set_basic_rates(struct zd_chip *chip, u16 cr_rates);
  819. int zd_chip_lock_phy_regs(struct zd_chip *chip);
  820. int zd_chip_unlock_phy_regs(struct zd_chip *chip);
  821. enum led_status {
  822. ZD_LED_OFF = 0,
  823. ZD_LED_SCANNING = 1,
  824. ZD_LED_ASSOCIATED = 2,
  825. };
  826. int zd_chip_control_leds(struct zd_chip *chip, enum led_status status);
  827. int zd_set_beacon_interval(struct zd_chip *chip, u16 interval, u8 dtim_period,
  828. int type);
  829. static inline int zd_get_beacon_interval(struct zd_chip *chip, u32 *interval)
  830. {
  831. return zd_ioread32(chip, CR_BCN_INTERVAL, interval);
  832. }
  833. struct rx_status;
  834. u8 zd_rx_rate(const void *rx_frame, const struct rx_status *status);
  835. struct zd_mc_hash {
  836. u32 low;
  837. u32 high;
  838. };
  839. static inline void zd_mc_clear(struct zd_mc_hash *hash)
  840. {
  841. hash->low = 0;
  842. /* The interfaces must always received broadcasts.
  843. * The hash of the broadcast address ff:ff:ff:ff:ff:ff is 63.
  844. */
  845. hash->high = 0x80000000;
  846. }
  847. static inline void zd_mc_add_all(struct zd_mc_hash *hash)
  848. {
  849. hash->low = hash->high = 0xffffffff;
  850. }
  851. static inline void zd_mc_add_addr(struct zd_mc_hash *hash, u8 *addr)
  852. {
  853. unsigned int i = addr[5] >> 2;
  854. if (i < 32) {
  855. hash->low |= 1 << i;
  856. } else {
  857. hash->high |= 1 << (i-32);
  858. }
  859. }
  860. int zd_chip_set_multicast_hash(struct zd_chip *chip,
  861. struct zd_mc_hash *hash);
  862. u64 zd_chip_get_tsf(struct zd_chip *chip);
  863. #endif /* _ZD_CHIP_H */