rt2500usb.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2500usb
  19. Abstract: rt2500usb device specific routines.
  20. Supported chipsets: RT2570.
  21. */
  22. #include <linux/delay.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/usb.h>
  28. #include "rt2x00.h"
  29. #include "rt2x00usb.h"
  30. #include "rt2500usb.h"
  31. /*
  32. * Allow hardware encryption to be disabled.
  33. */
  34. static int modparam_nohwcrypt = 1;
  35. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  36. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  37. /*
  38. * Register access.
  39. * All access to the CSR registers will go through the methods
  40. * rt2500usb_register_read and rt2500usb_register_write.
  41. * BBP and RF register require indirect register access,
  42. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  43. * These indirect registers work with busy bits,
  44. * and we will try maximal REGISTER_BUSY_COUNT times to access
  45. * the register while taking a REGISTER_BUSY_DELAY us delay
  46. * between each attampt. When the busy bit is still set at that time,
  47. * the access attempt is considered to have failed,
  48. * and we will print an error.
  49. * If the csr_mutex is already held then the _lock variants must
  50. * be used instead.
  51. */
  52. static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
  53. const unsigned int offset,
  54. u16 *value)
  55. {
  56. __le16 reg;
  57. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  58. USB_VENDOR_REQUEST_IN, offset,
  59. &reg, sizeof(reg), REGISTER_TIMEOUT);
  60. *value = le16_to_cpu(reg);
  61. }
  62. static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
  63. const unsigned int offset,
  64. u16 *value)
  65. {
  66. __le16 reg;
  67. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
  68. USB_VENDOR_REQUEST_IN, offset,
  69. &reg, sizeof(reg), REGISTER_TIMEOUT);
  70. *value = le16_to_cpu(reg);
  71. }
  72. static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
  73. const unsigned int offset,
  74. void *value, const u16 length)
  75. {
  76. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  77. USB_VENDOR_REQUEST_IN, offset,
  78. value, length,
  79. REGISTER_TIMEOUT16(length));
  80. }
  81. static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
  82. const unsigned int offset,
  83. u16 value)
  84. {
  85. __le16 reg = cpu_to_le16(value);
  86. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  87. USB_VENDOR_REQUEST_OUT, offset,
  88. &reg, sizeof(reg), REGISTER_TIMEOUT);
  89. }
  90. static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
  91. const unsigned int offset,
  92. u16 value)
  93. {
  94. __le16 reg = cpu_to_le16(value);
  95. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
  96. USB_VENDOR_REQUEST_OUT, offset,
  97. &reg, sizeof(reg), REGISTER_TIMEOUT);
  98. }
  99. static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
  100. const unsigned int offset,
  101. void *value, const u16 length)
  102. {
  103. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  104. USB_VENDOR_REQUEST_OUT, offset,
  105. value, length,
  106. REGISTER_TIMEOUT16(length));
  107. }
  108. static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
  109. const unsigned int offset,
  110. struct rt2x00_field16 field,
  111. u16 *reg)
  112. {
  113. unsigned int i;
  114. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  115. rt2500usb_register_read_lock(rt2x00dev, offset, reg);
  116. if (!rt2x00_get_field16(*reg, field))
  117. return 1;
  118. udelay(REGISTER_BUSY_DELAY);
  119. }
  120. ERROR(rt2x00dev, "Indirect register access failed: "
  121. "offset=0x%.08x, value=0x%.08x\n", offset, *reg);
  122. *reg = ~0;
  123. return 0;
  124. }
  125. #define WAIT_FOR_BBP(__dev, __reg) \
  126. rt2500usb_regbusy_read((__dev), PHY_CSR8, PHY_CSR8_BUSY, (__reg))
  127. #define WAIT_FOR_RF(__dev, __reg) \
  128. rt2500usb_regbusy_read((__dev), PHY_CSR10, PHY_CSR10_RF_BUSY, (__reg))
  129. static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  130. const unsigned int word, const u8 value)
  131. {
  132. u16 reg;
  133. mutex_lock(&rt2x00dev->csr_mutex);
  134. /*
  135. * Wait until the BBP becomes available, afterwards we
  136. * can safely write the new data into the register.
  137. */
  138. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  139. reg = 0;
  140. rt2x00_set_field16(&reg, PHY_CSR7_DATA, value);
  141. rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
  142. rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 0);
  143. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
  144. }
  145. mutex_unlock(&rt2x00dev->csr_mutex);
  146. }
  147. static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  148. const unsigned int word, u8 *value)
  149. {
  150. u16 reg;
  151. mutex_lock(&rt2x00dev->csr_mutex);
  152. /*
  153. * Wait until the BBP becomes available, afterwards we
  154. * can safely write the read request into the register.
  155. * After the data has been written, we wait until hardware
  156. * returns the correct value, if at any time the register
  157. * doesn't become available in time, reg will be 0xffffffff
  158. * which means we return 0xff to the caller.
  159. */
  160. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  161. reg = 0;
  162. rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
  163. rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 1);
  164. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
  165. if (WAIT_FOR_BBP(rt2x00dev, &reg))
  166. rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, &reg);
  167. }
  168. *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
  169. mutex_unlock(&rt2x00dev->csr_mutex);
  170. }
  171. static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
  172. const unsigned int word, const u32 value)
  173. {
  174. u16 reg;
  175. if (!word)
  176. return;
  177. mutex_lock(&rt2x00dev->csr_mutex);
  178. /*
  179. * Wait until the RF becomes available, afterwards we
  180. * can safely write the new data into the register.
  181. */
  182. if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  183. reg = 0;
  184. rt2x00_set_field16(&reg, PHY_CSR9_RF_VALUE, value);
  185. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
  186. reg = 0;
  187. rt2x00_set_field16(&reg, PHY_CSR10_RF_VALUE, value >> 16);
  188. rt2x00_set_field16(&reg, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
  189. rt2x00_set_field16(&reg, PHY_CSR10_RF_IF_SELECT, 0);
  190. rt2x00_set_field16(&reg, PHY_CSR10_RF_BUSY, 1);
  191. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
  192. rt2x00_rf_write(rt2x00dev, word, value);
  193. }
  194. mutex_unlock(&rt2x00dev->csr_mutex);
  195. }
  196. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  197. static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
  198. const unsigned int offset,
  199. u32 *value)
  200. {
  201. rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
  202. }
  203. static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
  204. const unsigned int offset,
  205. u32 value)
  206. {
  207. rt2500usb_register_write(rt2x00dev, offset, value);
  208. }
  209. static const struct rt2x00debug rt2500usb_rt2x00debug = {
  210. .owner = THIS_MODULE,
  211. .csr = {
  212. .read = _rt2500usb_register_read,
  213. .write = _rt2500usb_register_write,
  214. .flags = RT2X00DEBUGFS_OFFSET,
  215. .word_base = CSR_REG_BASE,
  216. .word_size = sizeof(u16),
  217. .word_count = CSR_REG_SIZE / sizeof(u16),
  218. },
  219. .eeprom = {
  220. .read = rt2x00_eeprom_read,
  221. .write = rt2x00_eeprom_write,
  222. .word_base = EEPROM_BASE,
  223. .word_size = sizeof(u16),
  224. .word_count = EEPROM_SIZE / sizeof(u16),
  225. },
  226. .bbp = {
  227. .read = rt2500usb_bbp_read,
  228. .write = rt2500usb_bbp_write,
  229. .word_base = BBP_BASE,
  230. .word_size = sizeof(u8),
  231. .word_count = BBP_SIZE / sizeof(u8),
  232. },
  233. .rf = {
  234. .read = rt2x00_rf_read,
  235. .write = rt2500usb_rf_write,
  236. .word_base = RF_BASE,
  237. .word_size = sizeof(u32),
  238. .word_count = RF_SIZE / sizeof(u32),
  239. },
  240. };
  241. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  242. #ifdef CONFIG_RT2X00_LIB_LEDS
  243. static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
  244. enum led_brightness brightness)
  245. {
  246. struct rt2x00_led *led =
  247. container_of(led_cdev, struct rt2x00_led, led_dev);
  248. unsigned int enabled = brightness != LED_OFF;
  249. u16 reg;
  250. rt2500usb_register_read(led->rt2x00dev, MAC_CSR20, &reg);
  251. if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC)
  252. rt2x00_set_field16(&reg, MAC_CSR20_LINK, enabled);
  253. else if (led->type == LED_TYPE_ACTIVITY)
  254. rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, enabled);
  255. rt2500usb_register_write(led->rt2x00dev, MAC_CSR20, reg);
  256. }
  257. static int rt2500usb_blink_set(struct led_classdev *led_cdev,
  258. unsigned long *delay_on,
  259. unsigned long *delay_off)
  260. {
  261. struct rt2x00_led *led =
  262. container_of(led_cdev, struct rt2x00_led, led_dev);
  263. u16 reg;
  264. rt2500usb_register_read(led->rt2x00dev, MAC_CSR21, &reg);
  265. rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, *delay_on);
  266. rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, *delay_off);
  267. rt2500usb_register_write(led->rt2x00dev, MAC_CSR21, reg);
  268. return 0;
  269. }
  270. static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
  271. struct rt2x00_led *led,
  272. enum led_type type)
  273. {
  274. led->rt2x00dev = rt2x00dev;
  275. led->type = type;
  276. led->led_dev.brightness_set = rt2500usb_brightness_set;
  277. led->led_dev.blink_set = rt2500usb_blink_set;
  278. led->flags = LED_INITIALIZED;
  279. }
  280. #endif /* CONFIG_RT2X00_LIB_LEDS */
  281. /*
  282. * Configuration handlers.
  283. */
  284. /*
  285. * rt2500usb does not differentiate between shared and pairwise
  286. * keys, so we should use the same function for both key types.
  287. */
  288. static int rt2500usb_config_key(struct rt2x00_dev *rt2x00dev,
  289. struct rt2x00lib_crypto *crypto,
  290. struct ieee80211_key_conf *key)
  291. {
  292. int timeout;
  293. u32 mask;
  294. u16 reg;
  295. if (crypto->cmd == SET_KEY) {
  296. /*
  297. * Pairwise key will always be entry 0, but this
  298. * could collide with a shared key on the same
  299. * position...
  300. */
  301. mask = TXRX_CSR0_KEY_ID.bit_mask;
  302. rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  303. reg &= mask;
  304. if (reg && reg == mask)
  305. return -ENOSPC;
  306. reg = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
  307. key->hw_key_idx += reg ? ffz(reg) : 0;
  308. /*
  309. * The encryption key doesn't fit within the CSR cache,
  310. * this means we should allocate it seperately and use
  311. * rt2x00usb_vendor_request() to send the key to the hardware.
  312. */
  313. reg = KEY_ENTRY(key->hw_key_idx);
  314. timeout = REGISTER_TIMEOUT32(sizeof(crypto->key));
  315. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  316. USB_VENDOR_REQUEST_OUT, reg,
  317. crypto->key,
  318. sizeof(crypto->key),
  319. timeout);
  320. /*
  321. * The driver does not support the IV/EIV generation
  322. * in hardware. However it doesn't support the IV/EIV
  323. * inside the ieee80211 frame either, but requires it
  324. * to be provided seperately for the descriptor.
  325. * rt2x00lib will cut the IV/EIV data out of all frames
  326. * given to us by mac80211, but we must tell mac80211
  327. * to generate the IV/EIV data.
  328. */
  329. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  330. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  331. }
  332. /*
  333. * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
  334. * a particular key is valid.
  335. */
  336. rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  337. rt2x00_set_field16(&reg, TXRX_CSR0_ALGORITHM, crypto->cipher);
  338. rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
  339. mask = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
  340. if (crypto->cmd == SET_KEY)
  341. mask |= 1 << key->hw_key_idx;
  342. else if (crypto->cmd == DISABLE_KEY)
  343. mask &= ~(1 << key->hw_key_idx);
  344. rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, mask);
  345. rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  346. return 0;
  347. }
  348. static void rt2500usb_config_filter(struct rt2x00_dev *rt2x00dev,
  349. const unsigned int filter_flags)
  350. {
  351. u16 reg;
  352. /*
  353. * Start configuration steps.
  354. * Note that the version error will always be dropped
  355. * and broadcast frames will always be accepted since
  356. * there is no filter for it at this time.
  357. */
  358. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  359. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
  360. !(filter_flags & FIF_FCSFAIL));
  361. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
  362. !(filter_flags & FIF_PLCPFAIL));
  363. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
  364. !(filter_flags & FIF_CONTROL));
  365. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
  366. !(filter_flags & FIF_PROMISC_IN_BSS));
  367. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
  368. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  369. !rt2x00dev->intf_ap_count);
  370. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
  371. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
  372. !(filter_flags & FIF_ALLMULTI));
  373. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
  374. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  375. }
  376. static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
  377. struct rt2x00_intf *intf,
  378. struct rt2x00intf_conf *conf,
  379. const unsigned int flags)
  380. {
  381. unsigned int bcn_preload;
  382. u16 reg;
  383. if (flags & CONFIG_UPDATE_TYPE) {
  384. /*
  385. * Enable beacon config
  386. */
  387. bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20);
  388. rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
  389. rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
  390. rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
  391. 2 * (conf->type != NL80211_IFTYPE_STATION));
  392. rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
  393. /*
  394. * Enable synchronisation.
  395. */
  396. rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
  397. rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
  398. rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
  399. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  400. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
  401. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, conf->sync);
  402. rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
  403. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  404. }
  405. if (flags & CONFIG_UPDATE_MAC)
  406. rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
  407. (3 * sizeof(__le16)));
  408. if (flags & CONFIG_UPDATE_BSSID)
  409. rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
  410. (3 * sizeof(__le16)));
  411. }
  412. static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
  413. struct rt2x00lib_erp *erp)
  414. {
  415. u16 reg;
  416. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  417. rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, erp->ack_timeout);
  418. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  419. rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
  420. rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
  421. !!erp->short_preamble);
  422. rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
  423. rt2500usb_register_write(rt2x00dev, TXRX_CSR11, erp->basic_rates);
  424. rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
  425. rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
  426. rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
  427. }
  428. static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
  429. struct antenna_setup *ant)
  430. {
  431. u8 r2;
  432. u8 r14;
  433. u16 csr5;
  434. u16 csr6;
  435. /*
  436. * We should never come here because rt2x00lib is supposed
  437. * to catch this and send us the correct antenna explicitely.
  438. */
  439. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  440. ant->tx == ANTENNA_SW_DIVERSITY);
  441. rt2500usb_bbp_read(rt2x00dev, 2, &r2);
  442. rt2500usb_bbp_read(rt2x00dev, 14, &r14);
  443. rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
  444. rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
  445. /*
  446. * Configure the TX antenna.
  447. */
  448. switch (ant->tx) {
  449. case ANTENNA_HW_DIVERSITY:
  450. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
  451. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
  452. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
  453. break;
  454. case ANTENNA_A:
  455. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
  456. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
  457. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
  458. break;
  459. case ANTENNA_B:
  460. default:
  461. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
  462. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
  463. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
  464. break;
  465. }
  466. /*
  467. * Configure the RX antenna.
  468. */
  469. switch (ant->rx) {
  470. case ANTENNA_HW_DIVERSITY:
  471. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
  472. break;
  473. case ANTENNA_A:
  474. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
  475. break;
  476. case ANTENNA_B:
  477. default:
  478. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
  479. break;
  480. }
  481. /*
  482. * RT2525E and RT5222 need to flip TX I/Q
  483. */
  484. if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
  485. rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  486. rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
  487. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
  488. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
  489. /*
  490. * RT2525E does not need RX I/Q Flip.
  491. */
  492. if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
  493. rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
  494. } else {
  495. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
  496. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
  497. }
  498. rt2500usb_bbp_write(rt2x00dev, 2, r2);
  499. rt2500usb_bbp_write(rt2x00dev, 14, r14);
  500. rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
  501. rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
  502. }
  503. static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
  504. struct rf_channel *rf, const int txpower)
  505. {
  506. /*
  507. * Set TXpower.
  508. */
  509. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  510. /*
  511. * For RT2525E we should first set the channel to half band higher.
  512. */
  513. if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  514. static const u32 vals[] = {
  515. 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
  516. 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
  517. 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
  518. 0x00000902, 0x00000906
  519. };
  520. rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
  521. if (rf->rf4)
  522. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  523. }
  524. rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
  525. rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
  526. rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
  527. if (rf->rf4)
  528. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  529. }
  530. static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  531. const int txpower)
  532. {
  533. u32 rf3;
  534. rt2x00_rf_read(rt2x00dev, 3, &rf3);
  535. rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  536. rt2500usb_rf_write(rt2x00dev, 3, rf3);
  537. }
  538. static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
  539. struct rt2x00lib_conf *libconf)
  540. {
  541. u16 reg;
  542. rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
  543. rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
  544. libconf->conf->beacon_int * 4);
  545. rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
  546. }
  547. static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
  548. struct rt2x00lib_conf *libconf,
  549. const unsigned int flags)
  550. {
  551. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  552. rt2500usb_config_channel(rt2x00dev, &libconf->rf,
  553. libconf->conf->power_level);
  554. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  555. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  556. rt2500usb_config_txpower(rt2x00dev,
  557. libconf->conf->power_level);
  558. if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
  559. rt2500usb_config_duration(rt2x00dev, libconf);
  560. }
  561. /*
  562. * Link tuning
  563. */
  564. static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
  565. struct link_qual *qual)
  566. {
  567. u16 reg;
  568. /*
  569. * Update FCS error count from register.
  570. */
  571. rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
  572. qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
  573. /*
  574. * Update False CCA count from register.
  575. */
  576. rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
  577. qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
  578. }
  579. static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
  580. {
  581. u16 eeprom;
  582. u16 value;
  583. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
  584. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
  585. rt2500usb_bbp_write(rt2x00dev, 24, value);
  586. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
  587. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
  588. rt2500usb_bbp_write(rt2x00dev, 25, value);
  589. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
  590. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
  591. rt2500usb_bbp_write(rt2x00dev, 61, value);
  592. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
  593. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
  594. rt2500usb_bbp_write(rt2x00dev, 17, value);
  595. rt2x00dev->link.vgc_level = value;
  596. }
  597. /*
  598. * NOTE: This function is directly ported from legacy driver, but
  599. * despite it being declared it was never called. Although link tuning
  600. * sounds like a good idea, and usually works well for the other drivers,
  601. * it does _not_ work with rt2500usb. Enabling this function will result
  602. * in TX capabilities only until association kicks in. Immediately
  603. * after the successful association all TX frames will be kept in the
  604. * hardware queue and never transmitted.
  605. */
  606. #if 0
  607. static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
  608. {
  609. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  610. u16 bbp_thresh;
  611. u16 vgc_bound;
  612. u16 sens;
  613. u16 r24;
  614. u16 r25;
  615. u16 r61;
  616. u16 r17_sens;
  617. u8 r17;
  618. u8 up_bound;
  619. u8 low_bound;
  620. /*
  621. * Read current r17 value, as well as the sensitivity values
  622. * for the r17 register.
  623. */
  624. rt2500usb_bbp_read(rt2x00dev, 17, &r17);
  625. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
  626. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
  627. up_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
  628. low_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCLOWER);
  629. /*
  630. * If we are not associated, we should go straight to the
  631. * dynamic CCA tuning.
  632. */
  633. if (!rt2x00dev->intf_associated)
  634. goto dynamic_cca_tune;
  635. /*
  636. * Determine the BBP tuning threshold and correctly
  637. * set BBP 24, 25 and 61.
  638. */
  639. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
  640. bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
  641. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
  642. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
  643. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
  644. if ((rssi + bbp_thresh) > 0) {
  645. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
  646. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
  647. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
  648. } else {
  649. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
  650. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
  651. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
  652. }
  653. rt2500usb_bbp_write(rt2x00dev, 24, r24);
  654. rt2500usb_bbp_write(rt2x00dev, 25, r25);
  655. rt2500usb_bbp_write(rt2x00dev, 61, r61);
  656. /*
  657. * A too low RSSI will cause too much false CCA which will
  658. * then corrupt the R17 tuning. To remidy this the tuning should
  659. * be stopped (While making sure the R17 value will not exceed limits)
  660. */
  661. if (rssi >= -40) {
  662. if (r17 != 0x60)
  663. rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
  664. return;
  665. }
  666. /*
  667. * Special big-R17 for short distance
  668. */
  669. if (rssi >= -58) {
  670. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
  671. if (r17 != sens)
  672. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  673. return;
  674. }
  675. /*
  676. * Special mid-R17 for middle distance
  677. */
  678. if (rssi >= -74) {
  679. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
  680. if (r17 != sens)
  681. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  682. return;
  683. }
  684. /*
  685. * Leave short or middle distance condition, restore r17
  686. * to the dynamic tuning range.
  687. */
  688. low_bound = 0x32;
  689. if (rssi < -77)
  690. up_bound -= (-77 - rssi);
  691. if (up_bound < low_bound)
  692. up_bound = low_bound;
  693. if (r17 > up_bound) {
  694. rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
  695. rt2x00dev->link.vgc_level = up_bound;
  696. return;
  697. }
  698. dynamic_cca_tune:
  699. /*
  700. * R17 is inside the dynamic tuning range,
  701. * start tuning the link based on the false cca counter.
  702. */
  703. if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  704. rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
  705. rt2x00dev->link.vgc_level = r17;
  706. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  707. rt2500usb_bbp_write(rt2x00dev, 17, --r17);
  708. rt2x00dev->link.vgc_level = r17;
  709. }
  710. }
  711. #else
  712. #define rt2500usb_link_tuner NULL
  713. #endif
  714. /*
  715. * Initialization functions.
  716. */
  717. static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
  718. {
  719. u16 reg;
  720. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
  721. USB_MODE_TEST, REGISTER_TIMEOUT);
  722. rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
  723. 0x00f0, REGISTER_TIMEOUT);
  724. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  725. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
  726. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  727. rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
  728. rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
  729. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  730. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
  731. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
  732. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  733. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  734. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  735. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  736. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  737. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  738. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  739. rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
  740. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
  741. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
  742. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
  743. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
  744. rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
  745. rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
  746. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
  747. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
  748. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
  749. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
  750. rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
  751. rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  752. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
  753. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
  754. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
  755. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
  756. rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  757. rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  758. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
  759. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
  760. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
  761. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
  762. rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  763. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  764. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
  765. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, 0);
  766. rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
  767. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
  768. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  769. rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
  770. rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
  771. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  772. return -EBUSY;
  773. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  774. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  775. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  776. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
  777. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  778. if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
  779. rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
  780. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
  781. } else {
  782. reg = 0;
  783. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
  784. rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
  785. }
  786. rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
  787. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
  788. rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
  789. rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
  790. rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
  791. rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  792. rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
  793. rt2x00dev->rx->data_size);
  794. rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
  795. rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  796. rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
  797. rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0);
  798. rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  799. rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
  800. rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
  801. rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
  802. rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
  803. rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
  804. rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
  805. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  806. rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
  807. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  808. return 0;
  809. }
  810. static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  811. {
  812. unsigned int i;
  813. u8 value;
  814. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  815. rt2500usb_bbp_read(rt2x00dev, 0, &value);
  816. if ((value != 0xff) && (value != 0x00))
  817. return 0;
  818. udelay(REGISTER_BUSY_DELAY);
  819. }
  820. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  821. return -EACCES;
  822. }
  823. static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  824. {
  825. unsigned int i;
  826. u16 eeprom;
  827. u8 value;
  828. u8 reg_id;
  829. if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
  830. return -EACCES;
  831. rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
  832. rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
  833. rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
  834. rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
  835. rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
  836. rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
  837. rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
  838. rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
  839. rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
  840. rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
  841. rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
  842. rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
  843. rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
  844. rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
  845. rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
  846. rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
  847. rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
  848. rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
  849. rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
  850. rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
  851. rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
  852. rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
  853. rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
  854. rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
  855. rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
  856. rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
  857. rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
  858. rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
  859. rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
  860. rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
  861. rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
  862. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  863. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  864. if (eeprom != 0xffff && eeprom != 0x0000) {
  865. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  866. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  867. rt2500usb_bbp_write(rt2x00dev, reg_id, value);
  868. }
  869. }
  870. return 0;
  871. }
  872. /*
  873. * Device state switch handlers.
  874. */
  875. static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  876. enum dev_state state)
  877. {
  878. u16 reg;
  879. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  880. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
  881. (state == STATE_RADIO_RX_OFF) ||
  882. (state == STATE_RADIO_RX_OFF_LINK));
  883. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  884. }
  885. static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  886. {
  887. /*
  888. * Initialize all registers.
  889. */
  890. if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
  891. rt2500usb_init_bbp(rt2x00dev)))
  892. return -EIO;
  893. return 0;
  894. }
  895. static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  896. {
  897. rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
  898. rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
  899. /*
  900. * Disable synchronisation.
  901. */
  902. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  903. rt2x00usb_disable_radio(rt2x00dev);
  904. }
  905. static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
  906. enum dev_state state)
  907. {
  908. u16 reg;
  909. u16 reg2;
  910. unsigned int i;
  911. char put_to_sleep;
  912. char bbp_state;
  913. char rf_state;
  914. put_to_sleep = (state != STATE_AWAKE);
  915. reg = 0;
  916. rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
  917. rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
  918. rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
  919. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  920. rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
  921. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  922. /*
  923. * Device is not guaranteed to be in the requested state yet.
  924. * We must wait until the register indicates that the
  925. * device has entered the correct state.
  926. */
  927. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  928. rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
  929. bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
  930. rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
  931. if (bbp_state == state && rf_state == state)
  932. return 0;
  933. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  934. msleep(30);
  935. }
  936. return -EBUSY;
  937. }
  938. static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  939. enum dev_state state)
  940. {
  941. int retval = 0;
  942. switch (state) {
  943. case STATE_RADIO_ON:
  944. retval = rt2500usb_enable_radio(rt2x00dev);
  945. break;
  946. case STATE_RADIO_OFF:
  947. rt2500usb_disable_radio(rt2x00dev);
  948. break;
  949. case STATE_RADIO_RX_ON:
  950. case STATE_RADIO_RX_ON_LINK:
  951. case STATE_RADIO_RX_OFF:
  952. case STATE_RADIO_RX_OFF_LINK:
  953. rt2500usb_toggle_rx(rt2x00dev, state);
  954. break;
  955. case STATE_RADIO_IRQ_ON:
  956. case STATE_RADIO_IRQ_OFF:
  957. /* No support, but no error either */
  958. break;
  959. case STATE_DEEP_SLEEP:
  960. case STATE_SLEEP:
  961. case STATE_STANDBY:
  962. case STATE_AWAKE:
  963. retval = rt2500usb_set_state(rt2x00dev, state);
  964. break;
  965. default:
  966. retval = -ENOTSUPP;
  967. break;
  968. }
  969. if (unlikely(retval))
  970. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  971. state, retval);
  972. return retval;
  973. }
  974. /*
  975. * TX descriptor initialization
  976. */
  977. static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  978. struct sk_buff *skb,
  979. struct txentry_desc *txdesc)
  980. {
  981. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  982. __le32 *txd = skbdesc->desc;
  983. u32 word;
  984. /*
  985. * Start writing the descriptor words.
  986. */
  987. rt2x00_desc_read(txd, 1, &word);
  988. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  989. rt2x00_set_field32(&word, TXD_W1_AIFS, txdesc->aifs);
  990. rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
  991. rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
  992. rt2x00_desc_write(txd, 1, word);
  993. rt2x00_desc_read(txd, 2, &word);
  994. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  995. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  996. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  997. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  998. rt2x00_desc_write(txd, 2, word);
  999. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1000. _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
  1001. _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
  1002. }
  1003. rt2x00_desc_read(txd, 0, &word);
  1004. rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, txdesc->retry_limit);
  1005. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1006. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1007. rt2x00_set_field32(&word, TXD_W0_ACK,
  1008. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1009. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1010. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1011. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1012. test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags));
  1013. rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
  1014. test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
  1015. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1016. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
  1017. rt2x00_set_field32(&word, TXD_W0_CIPHER, txdesc->cipher);
  1018. rt2x00_set_field32(&word, TXD_W0_KEY_ID, txdesc->key_idx);
  1019. rt2x00_desc_write(txd, 0, word);
  1020. }
  1021. /*
  1022. * TX data initialization
  1023. */
  1024. static void rt2500usb_beacondone(struct urb *urb);
  1025. static void rt2500usb_write_beacon(struct queue_entry *entry)
  1026. {
  1027. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1028. struct usb_device *usb_dev = to_usb_device_intf(rt2x00dev->dev);
  1029. struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
  1030. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1031. int pipe = usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint);
  1032. int length;
  1033. u16 reg;
  1034. /*
  1035. * Add the descriptor in front of the skb.
  1036. */
  1037. skb_push(entry->skb, entry->queue->desc_size);
  1038. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  1039. skbdesc->desc = entry->skb->data;
  1040. /*
  1041. * Disable beaconing while we are reloading the beacon data,
  1042. * otherwise we might be sending out invalid data.
  1043. */
  1044. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  1045. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
  1046. rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
  1047. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
  1048. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  1049. /*
  1050. * USB devices cannot blindly pass the skb->len as the
  1051. * length of the data to usb_fill_bulk_urb. Pass the skb
  1052. * to the driver to determine what the length should be.
  1053. */
  1054. length = rt2x00dev->ops->lib->get_tx_data_len(entry);
  1055. usb_fill_bulk_urb(bcn_priv->urb, usb_dev, pipe,
  1056. entry->skb->data, length, rt2500usb_beacondone,
  1057. entry);
  1058. /*
  1059. * Second we need to create the guardian byte.
  1060. * We only need a single byte, so lets recycle
  1061. * the 'flags' field we are not using for beacons.
  1062. */
  1063. bcn_priv->guardian_data = 0;
  1064. usb_fill_bulk_urb(bcn_priv->guardian_urb, usb_dev, pipe,
  1065. &bcn_priv->guardian_data, 1, rt2500usb_beacondone,
  1066. entry);
  1067. /*
  1068. * Send out the guardian byte.
  1069. */
  1070. usb_submit_urb(bcn_priv->guardian_urb, GFP_ATOMIC);
  1071. }
  1072. static int rt2500usb_get_tx_data_len(struct queue_entry *entry)
  1073. {
  1074. int length;
  1075. /*
  1076. * The length _must_ be a multiple of 2,
  1077. * but it must _not_ be a multiple of the USB packet size.
  1078. */
  1079. length = roundup(entry->skb->len, 2);
  1080. length += (2 * !(length % entry->queue->usb_maxpacket));
  1081. return length;
  1082. }
  1083. static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1084. const enum data_queue_qid queue)
  1085. {
  1086. u16 reg;
  1087. if (queue != QID_BEACON) {
  1088. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  1089. return;
  1090. }
  1091. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  1092. if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
  1093. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
  1094. rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
  1095. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
  1096. /*
  1097. * Beacon generation will fail initially.
  1098. * To prevent this we need to register the TXRX_CSR19
  1099. * register several times.
  1100. */
  1101. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  1102. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  1103. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  1104. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  1105. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  1106. }
  1107. }
  1108. /*
  1109. * RX control handlers
  1110. */
  1111. static void rt2500usb_fill_rxdone(struct queue_entry *entry,
  1112. struct rxdone_entry_desc *rxdesc)
  1113. {
  1114. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1115. struct queue_entry_priv_usb *entry_priv = entry->priv_data;
  1116. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1117. __le32 *rxd =
  1118. (__le32 *)(entry->skb->data +
  1119. (entry_priv->urb->actual_length -
  1120. entry->queue->desc_size));
  1121. u32 word0;
  1122. u32 word1;
  1123. /*
  1124. * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
  1125. * frame data in rt2x00usb.
  1126. */
  1127. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1128. rxd = (__le32 *)skbdesc->desc;
  1129. /*
  1130. * It is now safe to read the descriptor on all architectures.
  1131. */
  1132. rt2x00_desc_read(rxd, 0, &word0);
  1133. rt2x00_desc_read(rxd, 1, &word1);
  1134. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1135. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1136. if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
  1137. rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC;
  1138. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1139. rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER);
  1140. if (rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR))
  1141. rxdesc->cipher_status = RX_CRYPTO_FAIL_KEY;
  1142. }
  1143. if (rxdesc->cipher != CIPHER_NONE) {
  1144. _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
  1145. _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
  1146. rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
  1147. /* ICV is located at the end of frame */
  1148. /*
  1149. * Hardware has stripped IV/EIV data from 802.11 frame during
  1150. * decryption. It has provided the data seperately but rt2x00lib
  1151. * should decide if it should be reinserted.
  1152. */
  1153. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1154. if (rxdesc->cipher != CIPHER_TKIP)
  1155. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1156. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1157. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1158. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1159. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1160. }
  1161. /*
  1162. * Obtain the status about this packet.
  1163. * When frame was received with an OFDM bitrate,
  1164. * the signal is the PLCP value. If it was received with
  1165. * a CCK bitrate the signal is the rate in 100kbit/s.
  1166. */
  1167. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1168. rxdesc->rssi =
  1169. rt2x00_get_field32(word1, RXD_W1_RSSI) - rt2x00dev->rssi_offset;
  1170. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1171. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1172. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1173. else
  1174. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1175. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1176. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1177. /*
  1178. * Adjust the skb memory window to the frame boundaries.
  1179. */
  1180. skb_trim(entry->skb, rxdesc->size);
  1181. }
  1182. /*
  1183. * Interrupt functions.
  1184. */
  1185. static void rt2500usb_beacondone(struct urb *urb)
  1186. {
  1187. struct queue_entry *entry = (struct queue_entry *)urb->context;
  1188. struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
  1189. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
  1190. return;
  1191. /*
  1192. * Check if this was the guardian beacon,
  1193. * if that was the case we need to send the real beacon now.
  1194. * Otherwise we should free the sk_buffer, the device
  1195. * should be doing the rest of the work now.
  1196. */
  1197. if (bcn_priv->guardian_urb == urb) {
  1198. usb_submit_urb(bcn_priv->urb, GFP_ATOMIC);
  1199. } else if (bcn_priv->urb == urb) {
  1200. dev_kfree_skb(entry->skb);
  1201. entry->skb = NULL;
  1202. }
  1203. }
  1204. /*
  1205. * Device probe functions.
  1206. */
  1207. static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1208. {
  1209. u16 word;
  1210. u8 *mac;
  1211. u8 bbp;
  1212. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1213. /*
  1214. * Start validation of the data that has been read.
  1215. */
  1216. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1217. if (!is_valid_ether_addr(mac)) {
  1218. random_ether_addr(mac);
  1219. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1220. }
  1221. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1222. if (word == 0xffff) {
  1223. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1224. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1225. ANTENNA_SW_DIVERSITY);
  1226. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1227. ANTENNA_SW_DIVERSITY);
  1228. rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
  1229. LED_MODE_DEFAULT);
  1230. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1231. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1232. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
  1233. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1234. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1235. }
  1236. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1237. if (word == 0xffff) {
  1238. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1239. rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
  1240. rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
  1241. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1242. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1243. }
  1244. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
  1245. if (word == 0xffff) {
  1246. rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
  1247. DEFAULT_RSSI_OFFSET);
  1248. rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
  1249. EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
  1250. }
  1251. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
  1252. if (word == 0xffff) {
  1253. rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
  1254. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
  1255. EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
  1256. }
  1257. /*
  1258. * Switch lower vgc bound to current BBP R17 value,
  1259. * lower the value a bit for better quality.
  1260. */
  1261. rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
  1262. bbp -= 6;
  1263. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
  1264. if (word == 0xffff) {
  1265. rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
  1266. rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
  1267. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
  1268. EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
  1269. } else {
  1270. rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
  1271. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
  1272. }
  1273. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
  1274. if (word == 0xffff) {
  1275. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
  1276. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
  1277. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
  1278. EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
  1279. }
  1280. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
  1281. if (word == 0xffff) {
  1282. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
  1283. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
  1284. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
  1285. EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
  1286. }
  1287. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
  1288. if (word == 0xffff) {
  1289. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
  1290. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
  1291. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
  1292. EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
  1293. }
  1294. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
  1295. if (word == 0xffff) {
  1296. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
  1297. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
  1298. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
  1299. EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
  1300. }
  1301. return 0;
  1302. }
  1303. static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1304. {
  1305. u16 reg;
  1306. u16 value;
  1307. u16 eeprom;
  1308. /*
  1309. * Read EEPROM word for configuration.
  1310. */
  1311. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1312. /*
  1313. * Identify RF chipset.
  1314. */
  1315. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1316. rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1317. rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
  1318. if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
  1319. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1320. return -ENODEV;
  1321. }
  1322. if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
  1323. !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
  1324. !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
  1325. !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
  1326. !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
  1327. !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1328. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1329. return -ENODEV;
  1330. }
  1331. /*
  1332. * Identify default antenna configuration.
  1333. */
  1334. rt2x00dev->default_ant.tx =
  1335. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1336. rt2x00dev->default_ant.rx =
  1337. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1338. /*
  1339. * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
  1340. * I am not 100% sure about this, but the legacy drivers do not
  1341. * indicate antenna swapping in software is required when
  1342. * diversity is enabled.
  1343. */
  1344. if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
  1345. rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
  1346. if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
  1347. rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
  1348. /*
  1349. * Store led mode, for correct led behaviour.
  1350. */
  1351. #ifdef CONFIG_RT2X00_LIB_LEDS
  1352. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
  1353. rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1354. if (value == LED_MODE_TXRX_ACTIVITY)
  1355. rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1356. LED_TYPE_ACTIVITY);
  1357. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1358. /*
  1359. * Check if the BBP tuning should be disabled.
  1360. */
  1361. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1362. if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
  1363. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1364. /*
  1365. * Read the RSSI <-> dBm offset information.
  1366. */
  1367. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
  1368. rt2x00dev->rssi_offset =
  1369. rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
  1370. return 0;
  1371. }
  1372. /*
  1373. * RF value list for RF2522
  1374. * Supports: 2.4 GHz
  1375. */
  1376. static const struct rf_channel rf_vals_bg_2522[] = {
  1377. { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
  1378. { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
  1379. { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
  1380. { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
  1381. { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
  1382. { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
  1383. { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
  1384. { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
  1385. { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
  1386. { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
  1387. { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
  1388. { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
  1389. { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
  1390. { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
  1391. };
  1392. /*
  1393. * RF value list for RF2523
  1394. * Supports: 2.4 GHz
  1395. */
  1396. static const struct rf_channel rf_vals_bg_2523[] = {
  1397. { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
  1398. { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
  1399. { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
  1400. { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
  1401. { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
  1402. { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
  1403. { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
  1404. { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
  1405. { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
  1406. { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
  1407. { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
  1408. { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
  1409. { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
  1410. { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
  1411. };
  1412. /*
  1413. * RF value list for RF2524
  1414. * Supports: 2.4 GHz
  1415. */
  1416. static const struct rf_channel rf_vals_bg_2524[] = {
  1417. { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
  1418. { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
  1419. { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
  1420. { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
  1421. { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
  1422. { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
  1423. { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
  1424. { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
  1425. { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
  1426. { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
  1427. { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
  1428. { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
  1429. { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
  1430. { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
  1431. };
  1432. /*
  1433. * RF value list for RF2525
  1434. * Supports: 2.4 GHz
  1435. */
  1436. static const struct rf_channel rf_vals_bg_2525[] = {
  1437. { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
  1438. { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
  1439. { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
  1440. { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
  1441. { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
  1442. { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
  1443. { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
  1444. { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
  1445. { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
  1446. { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
  1447. { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
  1448. { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
  1449. { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
  1450. { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
  1451. };
  1452. /*
  1453. * RF value list for RF2525e
  1454. * Supports: 2.4 GHz
  1455. */
  1456. static const struct rf_channel rf_vals_bg_2525e[] = {
  1457. { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
  1458. { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
  1459. { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
  1460. { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
  1461. { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
  1462. { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
  1463. { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
  1464. { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
  1465. { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
  1466. { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
  1467. { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
  1468. { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
  1469. { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
  1470. { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
  1471. };
  1472. /*
  1473. * RF value list for RF5222
  1474. * Supports: 2.4 GHz & 5.2 GHz
  1475. */
  1476. static const struct rf_channel rf_vals_5222[] = {
  1477. { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
  1478. { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
  1479. { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
  1480. { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
  1481. { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
  1482. { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
  1483. { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
  1484. { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
  1485. { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
  1486. { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
  1487. { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
  1488. { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
  1489. { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
  1490. { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
  1491. /* 802.11 UNI / HyperLan 2 */
  1492. { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
  1493. { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
  1494. { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
  1495. { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
  1496. { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
  1497. { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
  1498. { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
  1499. { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
  1500. /* 802.11 HyperLan 2 */
  1501. { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
  1502. { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
  1503. { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
  1504. { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
  1505. { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
  1506. { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
  1507. { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
  1508. { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
  1509. { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
  1510. { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
  1511. /* 802.11 UNII */
  1512. { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
  1513. { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
  1514. { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
  1515. { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
  1516. { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
  1517. };
  1518. static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1519. {
  1520. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1521. struct channel_info *info;
  1522. char *tx_power;
  1523. unsigned int i;
  1524. /*
  1525. * Initialize all hw fields.
  1526. */
  1527. rt2x00dev->hw->flags =
  1528. IEEE80211_HW_RX_INCLUDES_FCS |
  1529. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1530. IEEE80211_HW_SIGNAL_DBM;
  1531. rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
  1532. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1533. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1534. rt2x00_eeprom_addr(rt2x00dev,
  1535. EEPROM_MAC_ADDR_0));
  1536. /*
  1537. * Initialize hw_mode information.
  1538. */
  1539. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1540. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1541. if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
  1542. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
  1543. spec->channels = rf_vals_bg_2522;
  1544. } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
  1545. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
  1546. spec->channels = rf_vals_bg_2523;
  1547. } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
  1548. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
  1549. spec->channels = rf_vals_bg_2524;
  1550. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
  1551. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
  1552. spec->channels = rf_vals_bg_2525;
  1553. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  1554. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
  1555. spec->channels = rf_vals_bg_2525e;
  1556. } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1557. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1558. spec->num_channels = ARRAY_SIZE(rf_vals_5222);
  1559. spec->channels = rf_vals_5222;
  1560. }
  1561. /*
  1562. * Create channel information array
  1563. */
  1564. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  1565. if (!info)
  1566. return -ENOMEM;
  1567. spec->channels_info = info;
  1568. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
  1569. for (i = 0; i < 14; i++)
  1570. info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1571. if (spec->num_channels > 14) {
  1572. for (i = 14; i < spec->num_channels; i++)
  1573. info[i].tx_power1 = DEFAULT_TXPOWER;
  1574. }
  1575. return 0;
  1576. }
  1577. static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1578. {
  1579. int retval;
  1580. /*
  1581. * Allocate eeprom data.
  1582. */
  1583. retval = rt2500usb_validate_eeprom(rt2x00dev);
  1584. if (retval)
  1585. return retval;
  1586. retval = rt2500usb_init_eeprom(rt2x00dev);
  1587. if (retval)
  1588. return retval;
  1589. /*
  1590. * Initialize hw specifications.
  1591. */
  1592. retval = rt2500usb_probe_hw_mode(rt2x00dev);
  1593. if (retval)
  1594. return retval;
  1595. /*
  1596. * This device requires the atim queue
  1597. */
  1598. __set_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
  1599. __set_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags);
  1600. __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
  1601. if (!modparam_nohwcrypt) {
  1602. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  1603. __set_bit(CONFIG_CRYPTO_COPY_IV, &rt2x00dev->flags);
  1604. }
  1605. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1606. /*
  1607. * Set the rssi offset.
  1608. */
  1609. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1610. return 0;
  1611. }
  1612. static const struct ieee80211_ops rt2500usb_mac80211_ops = {
  1613. .tx = rt2x00mac_tx,
  1614. .start = rt2x00mac_start,
  1615. .stop = rt2x00mac_stop,
  1616. .add_interface = rt2x00mac_add_interface,
  1617. .remove_interface = rt2x00mac_remove_interface,
  1618. .config = rt2x00mac_config,
  1619. .config_interface = rt2x00mac_config_interface,
  1620. .configure_filter = rt2x00mac_configure_filter,
  1621. .set_key = rt2x00mac_set_key,
  1622. .get_stats = rt2x00mac_get_stats,
  1623. .bss_info_changed = rt2x00mac_bss_info_changed,
  1624. .conf_tx = rt2x00mac_conf_tx,
  1625. .get_tx_stats = rt2x00mac_get_tx_stats,
  1626. };
  1627. static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
  1628. .probe_hw = rt2500usb_probe_hw,
  1629. .initialize = rt2x00usb_initialize,
  1630. .uninitialize = rt2x00usb_uninitialize,
  1631. .clear_entry = rt2x00usb_clear_entry,
  1632. .set_device_state = rt2500usb_set_device_state,
  1633. .link_stats = rt2500usb_link_stats,
  1634. .reset_tuner = rt2500usb_reset_tuner,
  1635. .link_tuner = rt2500usb_link_tuner,
  1636. .write_tx_desc = rt2500usb_write_tx_desc,
  1637. .write_tx_data = rt2x00usb_write_tx_data,
  1638. .write_beacon = rt2500usb_write_beacon,
  1639. .get_tx_data_len = rt2500usb_get_tx_data_len,
  1640. .kick_tx_queue = rt2500usb_kick_tx_queue,
  1641. .fill_rxdone = rt2500usb_fill_rxdone,
  1642. .config_shared_key = rt2500usb_config_key,
  1643. .config_pairwise_key = rt2500usb_config_key,
  1644. .config_filter = rt2500usb_config_filter,
  1645. .config_intf = rt2500usb_config_intf,
  1646. .config_erp = rt2500usb_config_erp,
  1647. .config_ant = rt2500usb_config_ant,
  1648. .config = rt2500usb_config,
  1649. };
  1650. static const struct data_queue_desc rt2500usb_queue_rx = {
  1651. .entry_num = RX_ENTRIES,
  1652. .data_size = DATA_FRAME_SIZE,
  1653. .desc_size = RXD_DESC_SIZE,
  1654. .priv_size = sizeof(struct queue_entry_priv_usb),
  1655. };
  1656. static const struct data_queue_desc rt2500usb_queue_tx = {
  1657. .entry_num = TX_ENTRIES,
  1658. .data_size = DATA_FRAME_SIZE,
  1659. .desc_size = TXD_DESC_SIZE,
  1660. .priv_size = sizeof(struct queue_entry_priv_usb),
  1661. };
  1662. static const struct data_queue_desc rt2500usb_queue_bcn = {
  1663. .entry_num = BEACON_ENTRIES,
  1664. .data_size = MGMT_FRAME_SIZE,
  1665. .desc_size = TXD_DESC_SIZE,
  1666. .priv_size = sizeof(struct queue_entry_priv_usb_bcn),
  1667. };
  1668. static const struct data_queue_desc rt2500usb_queue_atim = {
  1669. .entry_num = ATIM_ENTRIES,
  1670. .data_size = DATA_FRAME_SIZE,
  1671. .desc_size = TXD_DESC_SIZE,
  1672. .priv_size = sizeof(struct queue_entry_priv_usb),
  1673. };
  1674. static const struct rt2x00_ops rt2500usb_ops = {
  1675. .name = KBUILD_MODNAME,
  1676. .max_sta_intf = 1,
  1677. .max_ap_intf = 1,
  1678. .eeprom_size = EEPROM_SIZE,
  1679. .rf_size = RF_SIZE,
  1680. .tx_queues = NUM_TX_QUEUES,
  1681. .rx = &rt2500usb_queue_rx,
  1682. .tx = &rt2500usb_queue_tx,
  1683. .bcn = &rt2500usb_queue_bcn,
  1684. .atim = &rt2500usb_queue_atim,
  1685. .lib = &rt2500usb_rt2x00_ops,
  1686. .hw = &rt2500usb_mac80211_ops,
  1687. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1688. .debugfs = &rt2500usb_rt2x00debug,
  1689. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1690. };
  1691. /*
  1692. * rt2500usb module information.
  1693. */
  1694. static struct usb_device_id rt2500usb_device_table[] = {
  1695. /* ASUS */
  1696. { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1697. { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
  1698. /* Belkin */
  1699. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
  1700. { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
  1701. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1702. /* Cisco Systems */
  1703. { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
  1704. { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
  1705. { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1706. /* Conceptronic */
  1707. { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
  1708. /* D-LINK */
  1709. { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
  1710. /* Gigabyte */
  1711. { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
  1712. { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
  1713. /* Hercules */
  1714. { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
  1715. /* Melco */
  1716. { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
  1717. { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
  1718. { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
  1719. { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
  1720. { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
  1721. /* MSI */
  1722. { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
  1723. { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
  1724. { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
  1725. /* Ralink */
  1726. { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1727. { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
  1728. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
  1729. { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1730. /* Siemens */
  1731. { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
  1732. /* SMC */
  1733. { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
  1734. /* Spairon */
  1735. { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
  1736. /* Trust */
  1737. { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1738. /* Zinwell */
  1739. { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
  1740. { 0, }
  1741. };
  1742. MODULE_AUTHOR(DRV_PROJECT);
  1743. MODULE_VERSION(DRV_VERSION);
  1744. MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
  1745. MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
  1746. MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
  1747. MODULE_LICENSE("GPL");
  1748. static struct usb_driver rt2500usb_driver = {
  1749. .name = KBUILD_MODNAME,
  1750. .id_table = rt2500usb_device_table,
  1751. .probe = rt2x00usb_probe,
  1752. .disconnect = rt2x00usb_disconnect,
  1753. .suspend = rt2x00usb_suspend,
  1754. .resume = rt2x00usb_resume,
  1755. };
  1756. static int __init rt2500usb_init(void)
  1757. {
  1758. return usb_register(&rt2500usb_driver);
  1759. }
  1760. static void __exit rt2500usb_exit(void)
  1761. {
  1762. usb_deregister(&rt2500usb_driver);
  1763. }
  1764. module_init(rt2500usb_init);
  1765. module_exit(rt2500usb_exit);