rt2500usb.c 59 KB

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