rt2800usb.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  1. /*
  2. Copyright (C) 2004 - 2009 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: rt2800usb
  19. Abstract: rt2800usb device specific routines.
  20. Supported chipsets: RT2800U.
  21. */
  22. #include <linux/crc-ccitt.h>
  23. #include <linux/delay.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/usb.h>
  29. #include "rt2x00.h"
  30. #include "rt2x00usb.h"
  31. #include "rt2800lib.h"
  32. #include "rt2800.h"
  33. #include "rt2800usb.h"
  34. /*
  35. * Allow hardware encryption to be disabled.
  36. */
  37. static int modparam_nohwcrypt = 1;
  38. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  39. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  40. /*
  41. * Firmware functions
  42. */
  43. static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  44. {
  45. return FIRMWARE_RT2870;
  46. }
  47. static bool rt2800usb_check_crc(const u8 *data, const size_t len)
  48. {
  49. u16 fw_crc;
  50. u16 crc;
  51. /*
  52. * The last 2 bytes in the firmware array are the crc checksum itself,
  53. * this means that we should never pass those 2 bytes to the crc
  54. * algorithm.
  55. */
  56. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  57. /*
  58. * Use the crc ccitt algorithm.
  59. * This will return the same value as the legacy driver which
  60. * used bit ordering reversion on the both the firmware bytes
  61. * before input input as well as on the final output.
  62. * Obviously using crc ccitt directly is much more efficient.
  63. */
  64. crc = crc_ccitt(~0, data, len - 2);
  65. /*
  66. * There is a small difference between the crc-itu-t + bitrev and
  67. * the crc-ccitt crc calculation. In the latter method the 2 bytes
  68. * will be swapped, use swab16 to convert the crc to the correct
  69. * value.
  70. */
  71. crc = swab16(crc);
  72. return fw_crc == crc;
  73. }
  74. static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  75. const u8 *data, const size_t len)
  76. {
  77. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  78. size_t offset = 0;
  79. /*
  80. * Firmware files:
  81. * There are 2 variations of the rt2870 firmware.
  82. * a) size: 4kb
  83. * b) size: 8kb
  84. * Note that (b) contains 2 seperate firmware blobs of 4k
  85. * within the file. The first blob is the same firmware as (a),
  86. * but the second blob is for the additional chipsets.
  87. */
  88. if (len != 4096 && len != 8192)
  89. return FW_BAD_LENGTH;
  90. /*
  91. * Check if we need the upper 4kb firmware data or not.
  92. */
  93. if ((len == 4096) &&
  94. (chipset != 0x2860) &&
  95. (chipset != 0x2872) &&
  96. (chipset != 0x3070))
  97. return FW_BAD_VERSION;
  98. /*
  99. * 8kb firmware files must be checked as if it were
  100. * 2 seperate firmware files.
  101. */
  102. while (offset < len) {
  103. if (!rt2800usb_check_crc(data + offset, 4096))
  104. return FW_BAD_CRC;
  105. offset += 4096;
  106. }
  107. return FW_OK;
  108. }
  109. static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  110. const u8 *data, const size_t len)
  111. {
  112. unsigned int i;
  113. int status;
  114. u32 reg;
  115. u32 offset;
  116. u32 length;
  117. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  118. /*
  119. * Check which section of the firmware we need.
  120. */
  121. if ((chipset == 0x2860) ||
  122. (chipset == 0x2872) ||
  123. (chipset == 0x3070)) {
  124. offset = 0;
  125. length = 4096;
  126. } else {
  127. offset = 4096;
  128. length = 4096;
  129. }
  130. /*
  131. * Wait for stable hardware.
  132. */
  133. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  134. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  135. if (reg && reg != ~0)
  136. break;
  137. msleep(1);
  138. }
  139. if (i == REGISTER_BUSY_COUNT) {
  140. ERROR(rt2x00dev, "Unstable hardware.\n");
  141. return -EBUSY;
  142. }
  143. /*
  144. * Write firmware to device.
  145. */
  146. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  147. USB_VENDOR_REQUEST_OUT,
  148. FIRMWARE_IMAGE_BASE,
  149. data + offset, length,
  150. REGISTER_TIMEOUT32(length));
  151. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  152. rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  153. /*
  154. * Send firmware request to device to load firmware,
  155. * we need to specify a long timeout time.
  156. */
  157. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  158. 0, USB_MODE_FIRMWARE,
  159. REGISTER_TIMEOUT_FIRMWARE);
  160. if (status < 0) {
  161. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  162. return status;
  163. }
  164. msleep(10);
  165. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  166. /*
  167. * Send signal to firmware during boot time.
  168. */
  169. rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  170. if ((chipset == 0x3070) ||
  171. (chipset == 0x3071) ||
  172. (chipset == 0x3572)) {
  173. udelay(200);
  174. rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
  175. udelay(10);
  176. }
  177. /*
  178. * Wait for device to stabilize.
  179. */
  180. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  181. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  182. if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  183. break;
  184. msleep(1);
  185. }
  186. if (i == REGISTER_BUSY_COUNT) {
  187. ERROR(rt2x00dev, "PBF system register not ready.\n");
  188. return -EBUSY;
  189. }
  190. /*
  191. * Initialize firmware.
  192. */
  193. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  194. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  195. msleep(1);
  196. return 0;
  197. }
  198. /*
  199. * Initialization functions.
  200. */
  201. static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
  202. {
  203. u32 reg;
  204. unsigned int i;
  205. if (rt2x00_intf_is_usb(rt2x00dev)) {
  206. /*
  207. * Wait untill BBP and RF are ready.
  208. */
  209. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  210. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  211. if (reg && reg != ~0)
  212. break;
  213. msleep(1);
  214. }
  215. if (i == REGISTER_BUSY_COUNT) {
  216. ERROR(rt2x00dev, "Unstable hardware.\n");
  217. return -EBUSY;
  218. }
  219. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  220. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL,
  221. reg & ~0x00002000);
  222. }
  223. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  224. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  225. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  226. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  227. if (rt2x00_intf_is_usb(rt2x00dev)) {
  228. rt2800_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
  229. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  230. USB_MODE_RESET, REGISTER_TIMEOUT);
  231. }
  232. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  233. rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  234. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  235. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  236. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  237. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  238. rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
  239. rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  240. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  241. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  242. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  243. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  244. rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
  245. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  246. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  247. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  248. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  249. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
  250. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  251. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  252. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  253. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  254. rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  255. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  256. if (rt2x00_intf_is_usb(rt2x00dev) &&
  257. rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  258. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  259. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  260. rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  261. } else {
  262. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  263. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  264. }
  265. rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  266. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  267. rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  268. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  269. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  270. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  271. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  272. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  273. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  274. rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
  275. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  276. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  277. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  278. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  279. rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  280. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  281. if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
  282. rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
  283. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  284. else
  285. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  286. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  287. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  288. rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  289. rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  290. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  291. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  292. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  293. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  294. rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  295. rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  296. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  297. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  298. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
  299. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  300. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
  301. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  302. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  303. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  304. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  305. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  306. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  307. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  308. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  309. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
  310. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  311. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
  312. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  313. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  314. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  315. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  316. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  317. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  318. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  319. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  320. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  321. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  322. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
  323. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  324. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  325. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  326. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  327. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  328. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  329. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  330. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  331. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  332. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  333. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
  334. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  335. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  336. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  337. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  338. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  339. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  340. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  341. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  342. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  343. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  344. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
  345. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  346. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  347. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  348. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  349. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  350. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  351. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  352. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  353. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  354. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  355. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
  356. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  357. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  358. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  359. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  360. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  361. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  362. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  363. if (rt2x00_intf_is_usb(rt2x00dev)) {
  364. rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  365. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  366. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  367. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  368. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  369. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  370. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  371. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  372. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  373. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  374. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  375. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  376. }
  377. rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
  378. rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
  379. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  380. rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  381. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  382. IEEE80211_MAX_RTS_THRESHOLD);
  383. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  384. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  385. rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  386. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  387. /*
  388. * ASIC will keep garbage value after boot, clear encryption keys.
  389. */
  390. for (i = 0; i < 4; i++)
  391. rt2800_register_write(rt2x00dev,
  392. SHARED_KEY_MODE_ENTRY(i), 0);
  393. for (i = 0; i < 256; i++) {
  394. u32 wcid[2] = { 0xffffffff, 0x00ffffff };
  395. rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
  396. wcid, sizeof(wcid));
  397. rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
  398. rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  399. }
  400. /*
  401. * Clear all beacons
  402. * For the Beacon base registers we only need to clear
  403. * the first byte since that byte contains the VALID and OWNER
  404. * bits which (when set to 0) will invalidate the entire beacon.
  405. */
  406. rt2800_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  407. rt2800_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  408. rt2800_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  409. rt2800_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  410. rt2800_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
  411. rt2800_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
  412. rt2800_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
  413. rt2800_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
  414. if (rt2x00_intf_is_usb(rt2x00dev)) {
  415. rt2800_register_read(rt2x00dev, USB_CYC_CFG, &reg);
  416. rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
  417. rt2800_register_write(rt2x00dev, USB_CYC_CFG, reg);
  418. }
  419. rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  420. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  421. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  422. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  423. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  424. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  425. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  426. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  427. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  428. rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  429. rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  430. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  431. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  432. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  433. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  434. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  435. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  436. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  437. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  438. rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  439. rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  440. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  441. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  442. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
  443. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  444. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  445. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  446. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  447. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  448. rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  449. rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  450. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  451. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  452. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  453. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  454. rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  455. /*
  456. * We must clear the error counters.
  457. * These registers are cleared on read,
  458. * so we may pass a useless variable to store the value.
  459. */
  460. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  461. rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  462. rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  463. rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  464. rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  465. rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  466. return 0;
  467. }
  468. static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  469. {
  470. unsigned int i;
  471. u32 reg;
  472. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  473. rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  474. if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  475. return 0;
  476. udelay(REGISTER_BUSY_DELAY);
  477. }
  478. ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
  479. return -EACCES;
  480. }
  481. static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  482. {
  483. unsigned int i;
  484. u8 value;
  485. /*
  486. * BBP was enabled after firmware was loaded,
  487. * but we need to reactivate it now.
  488. */
  489. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  490. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  491. msleep(1);
  492. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  493. rt2800_bbp_read(rt2x00dev, 0, &value);
  494. if ((value != 0xff) && (value != 0x00))
  495. return 0;
  496. udelay(REGISTER_BUSY_DELAY);
  497. }
  498. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  499. return -EACCES;
  500. }
  501. static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  502. {
  503. unsigned int i;
  504. u16 eeprom;
  505. u8 reg_id;
  506. u8 value;
  507. if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
  508. rt2800usb_wait_bbp_ready(rt2x00dev)))
  509. return -EACCES;
  510. rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  511. rt2800_bbp_write(rt2x00dev, 66, 0x38);
  512. rt2800_bbp_write(rt2x00dev, 69, 0x12);
  513. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  514. rt2800_bbp_write(rt2x00dev, 73, 0x10);
  515. rt2800_bbp_write(rt2x00dev, 81, 0x37);
  516. rt2800_bbp_write(rt2x00dev, 82, 0x62);
  517. rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  518. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  519. rt2800_bbp_write(rt2x00dev, 86, 0x00);
  520. rt2800_bbp_write(rt2x00dev, 91, 0x04);
  521. rt2800_bbp_write(rt2x00dev, 92, 0x00);
  522. rt2800_bbp_write(rt2x00dev, 103, 0x00);
  523. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  524. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  525. rt2800_bbp_write(rt2x00dev, 69, 0x16);
  526. rt2800_bbp_write(rt2x00dev, 73, 0x12);
  527. }
  528. if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION)
  529. rt2800_bbp_write(rt2x00dev, 84, 0x19);
  530. if (rt2x00_intf_is_usb(rt2x00dev) &&
  531. rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  532. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  533. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  534. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  535. }
  536. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  537. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  538. if (eeprom != 0xffff && eeprom != 0x0000) {
  539. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  540. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  541. rt2800_bbp_write(rt2x00dev, reg_id, value);
  542. }
  543. }
  544. return 0;
  545. }
  546. static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
  547. bool bw40, u8 rfcsr24, u8 filter_target)
  548. {
  549. unsigned int i;
  550. u8 bbp;
  551. u8 rfcsr;
  552. u8 passband;
  553. u8 stopband;
  554. u8 overtuned = 0;
  555. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  556. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  557. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  558. rt2800_bbp_write(rt2x00dev, 4, bbp);
  559. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  560. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  561. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  562. /*
  563. * Set power & frequency of passband test tone
  564. */
  565. rt2800_bbp_write(rt2x00dev, 24, 0);
  566. for (i = 0; i < 100; i++) {
  567. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  568. msleep(1);
  569. rt2800_bbp_read(rt2x00dev, 55, &passband);
  570. if (passband)
  571. break;
  572. }
  573. /*
  574. * Set power & frequency of stopband test tone
  575. */
  576. rt2800_bbp_write(rt2x00dev, 24, 0x06);
  577. for (i = 0; i < 100; i++) {
  578. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  579. msleep(1);
  580. rt2800_bbp_read(rt2x00dev, 55, &stopband);
  581. if ((passband - stopband) <= filter_target) {
  582. rfcsr24++;
  583. overtuned += ((passband - stopband) == filter_target);
  584. } else
  585. break;
  586. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  587. }
  588. rfcsr24 -= !!overtuned;
  589. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  590. return rfcsr24;
  591. }
  592. static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  593. {
  594. u8 rfcsr;
  595. u8 bbp;
  596. if (rt2x00_intf_is_usb(rt2x00dev) &&
  597. rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  598. return 0;
  599. /*
  600. * Init RF calibration.
  601. */
  602. rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  603. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  604. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  605. msleep(1);
  606. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  607. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  608. if (rt2x00_intf_is_usb(rt2x00dev)) {
  609. rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  610. rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
  611. rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
  612. rt2800_rfcsr_write(rt2x00dev, 7, 0x70);
  613. rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
  614. rt2800_rfcsr_write(rt2x00dev, 10, 0x71);
  615. rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  616. rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
  617. rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  618. rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
  619. rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
  620. rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
  621. rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
  622. rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  623. rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
  624. rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
  625. rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
  626. rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  627. rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  628. rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
  629. }
  630. /*
  631. * Set RX Filter calibration for 20MHz and 40MHz
  632. */
  633. rt2x00dev->calibration[0] =
  634. rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
  635. rt2x00dev->calibration[1] =
  636. rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
  637. /*
  638. * Set back to initial state
  639. */
  640. rt2800_bbp_write(rt2x00dev, 24, 0);
  641. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  642. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  643. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  644. /*
  645. * set BBP back to BW20
  646. */
  647. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  648. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  649. rt2800_bbp_write(rt2x00dev, 4, bbp);
  650. return 0;
  651. }
  652. /*
  653. * Device state switch handlers.
  654. */
  655. static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  656. enum dev_state state)
  657. {
  658. u32 reg;
  659. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  660. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  661. (state == STATE_RADIO_RX_ON) ||
  662. (state == STATE_RADIO_RX_ON_LINK));
  663. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  664. }
  665. static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  666. {
  667. unsigned int i;
  668. u32 reg;
  669. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  670. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  671. if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  672. !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  673. return 0;
  674. msleep(1);
  675. }
  676. ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
  677. return -EACCES;
  678. }
  679. static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  680. {
  681. u32 reg;
  682. u16 word;
  683. /*
  684. * Initialize all registers.
  685. */
  686. if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
  687. rt2800usb_init_registers(rt2x00dev) ||
  688. rt2800usb_init_bbp(rt2x00dev) ||
  689. rt2800usb_init_rfcsr(rt2x00dev)))
  690. return -EIO;
  691. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  692. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  693. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  694. udelay(50);
  695. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  696. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  697. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  698. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  699. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  700. rt2800_register_read(rt2x00dev, USB_DMA_CFG, &reg);
  701. rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
  702. /* Don't use bulk in aggregation when working with USB 1.1 */
  703. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
  704. (rt2x00dev->rx->usb_maxpacket == 512));
  705. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
  706. /*
  707. * Total room for RX frames in kilobytes, PBF might still exceed
  708. * this limit so reduce the number to prevent errors.
  709. */
  710. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
  711. ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
  712. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
  713. rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
  714. rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
  715. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  716. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  717. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  718. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  719. /*
  720. * Initialize LED control
  721. */
  722. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  723. rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  724. word & 0xff, (word >> 8) & 0xff);
  725. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  726. rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  727. word & 0xff, (word >> 8) & 0xff);
  728. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  729. rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  730. word & 0xff, (word >> 8) & 0xff);
  731. return 0;
  732. }
  733. static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  734. {
  735. u32 reg;
  736. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  737. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  738. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  739. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  740. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  741. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  742. rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
  743. /* Wait for DMA, ignore error */
  744. rt2800usb_wait_wpdma_ready(rt2x00dev);
  745. rt2x00usb_disable_radio(rt2x00dev);
  746. }
  747. static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
  748. enum dev_state state)
  749. {
  750. if (state == STATE_AWAKE)
  751. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  752. else
  753. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  754. return 0;
  755. }
  756. static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  757. enum dev_state state)
  758. {
  759. int retval = 0;
  760. switch (state) {
  761. case STATE_RADIO_ON:
  762. /*
  763. * Before the radio can be enabled, the device first has
  764. * to be woken up. After that it needs a bit of time
  765. * to be fully awake and then the radio can be enabled.
  766. */
  767. rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
  768. msleep(1);
  769. retval = rt2800usb_enable_radio(rt2x00dev);
  770. break;
  771. case STATE_RADIO_OFF:
  772. /*
  773. * After the radio has been disabled, the device should
  774. * be put to sleep for powersaving.
  775. */
  776. rt2800usb_disable_radio(rt2x00dev);
  777. rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
  778. break;
  779. case STATE_RADIO_RX_ON:
  780. case STATE_RADIO_RX_ON_LINK:
  781. case STATE_RADIO_RX_OFF:
  782. case STATE_RADIO_RX_OFF_LINK:
  783. rt2800usb_toggle_rx(rt2x00dev, state);
  784. break;
  785. case STATE_RADIO_IRQ_ON:
  786. case STATE_RADIO_IRQ_OFF:
  787. /* No support, but no error either */
  788. break;
  789. case STATE_DEEP_SLEEP:
  790. case STATE_SLEEP:
  791. case STATE_STANDBY:
  792. case STATE_AWAKE:
  793. retval = rt2800usb_set_state(rt2x00dev, state);
  794. break;
  795. default:
  796. retval = -ENOTSUPP;
  797. break;
  798. }
  799. if (unlikely(retval))
  800. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  801. state, retval);
  802. return retval;
  803. }
  804. /*
  805. * TX descriptor initialization
  806. */
  807. static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  808. struct sk_buff *skb,
  809. struct txentry_desc *txdesc)
  810. {
  811. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  812. __le32 *txi = skbdesc->desc;
  813. __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
  814. u32 word;
  815. /*
  816. * Initialize TX Info descriptor
  817. */
  818. rt2x00_desc_read(txwi, 0, &word);
  819. rt2x00_set_field32(&word, TXWI_W0_FRAG,
  820. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  821. rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
  822. rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  823. rt2x00_set_field32(&word, TXWI_W0_TS,
  824. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  825. rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  826. test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  827. rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
  828. rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
  829. rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
  830. rt2x00_set_field32(&word, TXWI_W0_BW,
  831. test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  832. rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  833. test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  834. rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
  835. rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  836. rt2x00_desc_write(txwi, 0, word);
  837. rt2x00_desc_read(txwi, 1, &word);
  838. rt2x00_set_field32(&word, TXWI_W1_ACK,
  839. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  840. rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  841. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  842. rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
  843. rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  844. test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  845. txdesc->key_idx : 0xff);
  846. rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
  847. skb->len - txdesc->l2pad);
  848. rt2x00_set_field32(&word, TXWI_W1_PACKETID,
  849. skbdesc->entry->queue->qid + 1);
  850. rt2x00_desc_write(txwi, 1, word);
  851. /*
  852. * Always write 0 to IV/EIV fields, hardware will insert the IV
  853. * from the IVEIV register when TXINFO_W0_WIV is set to 0.
  854. * When TXINFO_W0_WIV is set to 1 it will use the IV data
  855. * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  856. * crypto entry in the registers should be used to encrypt the frame.
  857. */
  858. _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
  859. _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
  860. /*
  861. * Initialize TX descriptor
  862. */
  863. rt2x00_desc_read(txi, 0, &word);
  864. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
  865. skb->len + TXWI_DESC_SIZE);
  866. rt2x00_set_field32(&word, TXINFO_W0_WIV,
  867. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  868. rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
  869. rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
  870. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
  871. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
  872. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  873. rt2x00_desc_write(txi, 0, word);
  874. }
  875. /*
  876. * TX data initialization
  877. */
  878. static void rt2800usb_write_beacon(struct queue_entry *entry)
  879. {
  880. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  881. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  882. unsigned int beacon_base;
  883. u32 reg;
  884. /*
  885. * Add the descriptor in front of the skb.
  886. */
  887. skb_push(entry->skb, entry->queue->desc_size);
  888. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  889. skbdesc->desc = entry->skb->data;
  890. /*
  891. * Disable beaconing while we are reloading the beacon data,
  892. * otherwise we might be sending out invalid data.
  893. */
  894. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  895. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  896. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  897. /*
  898. * Write entire beacon with descriptor to register.
  899. */
  900. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  901. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  902. USB_VENDOR_REQUEST_OUT, beacon_base,
  903. entry->skb->data, entry->skb->len,
  904. REGISTER_TIMEOUT32(entry->skb->len));
  905. /*
  906. * Clean up the beacon skb.
  907. */
  908. dev_kfree_skb(entry->skb);
  909. entry->skb = NULL;
  910. }
  911. static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
  912. {
  913. int length;
  914. /*
  915. * The length _must_ include 4 bytes padding,
  916. * it should always be multiple of 4,
  917. * but it must _not_ be a multiple of the USB packet size.
  918. */
  919. length = roundup(entry->skb->len + 4, 4);
  920. length += (4 * !(length % entry->queue->usb_maxpacket));
  921. return length;
  922. }
  923. static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  924. const enum data_queue_qid queue)
  925. {
  926. u32 reg;
  927. if (queue != QID_BEACON) {
  928. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  929. return;
  930. }
  931. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  932. if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  933. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  934. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  935. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  936. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  937. }
  938. }
  939. /*
  940. * RX control handlers
  941. */
  942. static void rt2800usb_fill_rxdone(struct queue_entry *entry,
  943. struct rxdone_entry_desc *rxdesc)
  944. {
  945. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  946. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  947. __le32 *rxd = (__le32 *)entry->skb->data;
  948. __le32 *rxwi;
  949. u32 rxd0;
  950. u32 rxwi0;
  951. u32 rxwi1;
  952. u32 rxwi2;
  953. u32 rxwi3;
  954. /*
  955. * Copy descriptor to the skbdesc->desc buffer, making it safe from
  956. * moving of frame data in rt2x00usb.
  957. */
  958. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  959. rxd = (__le32 *)skbdesc->desc;
  960. rxwi = &rxd[RXINFO_DESC_SIZE / sizeof(__le32)];
  961. /*
  962. * It is now safe to read the descriptor on all architectures.
  963. */
  964. rt2x00_desc_read(rxd, 0, &rxd0);
  965. rt2x00_desc_read(rxwi, 0, &rxwi0);
  966. rt2x00_desc_read(rxwi, 1, &rxwi1);
  967. rt2x00_desc_read(rxwi, 2, &rxwi2);
  968. rt2x00_desc_read(rxwi, 3, &rxwi3);
  969. if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
  970. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  971. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  972. rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
  973. rxdesc->cipher_status =
  974. rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
  975. }
  976. if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
  977. /*
  978. * Hardware has stripped IV/EIV data from 802.11 frame during
  979. * decryption. Unfortunately the descriptor doesn't contain
  980. * any fields with the EIV/IV data either, so they can't
  981. * be restored by rt2x00lib.
  982. */
  983. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  984. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  985. rxdesc->flags |= RX_FLAG_DECRYPTED;
  986. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  987. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  988. }
  989. if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
  990. rxdesc->dev_flags |= RXDONE_MY_BSS;
  991. if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD)) {
  992. rxdesc->dev_flags |= RXDONE_L2PAD;
  993. skbdesc->flags |= SKBDESC_L2_PADDED;
  994. }
  995. if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
  996. rxdesc->flags |= RX_FLAG_SHORT_GI;
  997. if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
  998. rxdesc->flags |= RX_FLAG_40MHZ;
  999. /*
  1000. * Detect RX rate, always use MCS as signal type.
  1001. */
  1002. rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  1003. rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
  1004. rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
  1005. /*
  1006. * Mask of 0x8 bit to remove the short preamble flag.
  1007. */
  1008. if (rxdesc->rate_mode == RATE_MODE_CCK)
  1009. rxdesc->signal &= ~0x8;
  1010. rxdesc->rssi =
  1011. (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
  1012. rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
  1013. rxdesc->noise =
  1014. (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
  1015. rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
  1016. rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  1017. /*
  1018. * Remove RXWI descriptor from start of buffer.
  1019. */
  1020. skb_pull(entry->skb, skbdesc->desc_len);
  1021. skb_trim(entry->skb, rxdesc->size);
  1022. }
  1023. /*
  1024. * Device probe functions.
  1025. */
  1026. static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1027. {
  1028. u16 word;
  1029. u8 *mac;
  1030. u8 default_lna_gain;
  1031. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1032. /*
  1033. * Start validation of the data that has been read.
  1034. */
  1035. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1036. if (!is_valid_ether_addr(mac)) {
  1037. random_ether_addr(mac);
  1038. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1039. }
  1040. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1041. if (word == 0xffff) {
  1042. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1043. rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
  1044. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
  1045. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1046. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1047. } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
  1048. /*
  1049. * There is a max of 2 RX streams for RT2870 series
  1050. */
  1051. if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
  1052. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1053. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1054. }
  1055. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1056. if (word == 0xffff) {
  1057. rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
  1058. rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
  1059. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1060. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1061. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1062. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
  1063. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
  1064. rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
  1065. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
  1066. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
  1067. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1068. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1069. }
  1070. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1071. if ((word & 0x00ff) == 0x00ff) {
  1072. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1073. rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  1074. LED_MODE_TXRX_ACTIVITY);
  1075. rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  1076. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1077. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
  1078. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
  1079. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
  1080. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1081. }
  1082. /*
  1083. * During the LNA validation we are going to use
  1084. * lna0 as correct value. Note that EEPROM_LNA
  1085. * is never validated.
  1086. */
  1087. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  1088. default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  1089. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  1090. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  1091. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  1092. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  1093. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  1094. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  1095. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  1096. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  1097. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  1098. if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  1099. rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  1100. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  1101. default_lna_gain);
  1102. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  1103. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  1104. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  1105. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  1106. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  1107. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  1108. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  1109. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  1110. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  1111. rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  1112. if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  1113. rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  1114. rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  1115. default_lna_gain);
  1116. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  1117. return 0;
  1118. }
  1119. static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1120. {
  1121. u32 reg;
  1122. u16 value;
  1123. u16 eeprom;
  1124. /*
  1125. * Read EEPROM word for configuration.
  1126. */
  1127. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1128. /*
  1129. * Identify RF chipset.
  1130. */
  1131. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1132. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1133. rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
  1134. /*
  1135. * The check for rt2860 is not a typo, some rt2870 hardware
  1136. * identifies itself as rt2860 in the CSR register.
  1137. */
  1138. if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
  1139. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
  1140. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
  1141. !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
  1142. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1143. return -ENODEV;
  1144. }
  1145. if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
  1146. !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
  1147. !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
  1148. !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
  1149. !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
  1150. !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  1151. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1152. return -ENODEV;
  1153. }
  1154. /*
  1155. * Identify default antenna configuration.
  1156. */
  1157. rt2x00dev->default_ant.tx =
  1158. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
  1159. rt2x00dev->default_ant.rx =
  1160. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
  1161. /*
  1162. * Read frequency offset and RF programming sequence.
  1163. */
  1164. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1165. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1166. /*
  1167. * Read external LNA informations.
  1168. */
  1169. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1170. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  1171. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1172. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  1173. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1174. /*
  1175. * Detect if this device has an hardware controlled radio.
  1176. */
  1177. if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
  1178. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1179. /*
  1180. * Store led settings, for correct led behaviour.
  1181. */
  1182. #ifdef CONFIG_RT2X00_LIB_LEDS
  1183. rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1184. rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1185. rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  1186. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
  1187. &rt2x00dev->led_mcu_reg);
  1188. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1189. return 0;
  1190. }
  1191. /*
  1192. * RF value list for rt2870
  1193. * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  1194. */
  1195. static const struct rf_channel rf_vals[] = {
  1196. { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  1197. { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  1198. { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  1199. { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  1200. { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  1201. { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  1202. { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  1203. { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  1204. { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  1205. { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  1206. { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  1207. { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  1208. { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  1209. { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  1210. /* 802.11 UNI / HyperLan 2 */
  1211. { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  1212. { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  1213. { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  1214. { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  1215. { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  1216. { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  1217. { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  1218. { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  1219. { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  1220. { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  1221. { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  1222. { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  1223. /* 802.11 HyperLan 2 */
  1224. { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  1225. { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  1226. { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
  1227. { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
  1228. { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  1229. { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  1230. { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  1231. { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  1232. { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  1233. { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  1234. { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  1235. { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  1236. { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  1237. { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  1238. { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  1239. { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  1240. /* 802.11 UNII */
  1241. { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  1242. { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  1243. { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  1244. { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  1245. { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  1246. { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  1247. { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  1248. { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
  1249. { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
  1250. { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
  1251. { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
  1252. /* 802.11 Japan */
  1253. { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  1254. { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  1255. { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  1256. { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  1257. { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  1258. { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  1259. { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  1260. };
  1261. /*
  1262. * RF value list for rt3070
  1263. * Supports: 2.4 GHz
  1264. */
  1265. static const struct rf_channel rf_vals_3070[] = {
  1266. {1, 241, 2, 2 },
  1267. {2, 241, 2, 7 },
  1268. {3, 242, 2, 2 },
  1269. {4, 242, 2, 7 },
  1270. {5, 243, 2, 2 },
  1271. {6, 243, 2, 7 },
  1272. {7, 244, 2, 2 },
  1273. {8, 244, 2, 7 },
  1274. {9, 245, 2, 2 },
  1275. {10, 245, 2, 7 },
  1276. {11, 246, 2, 2 },
  1277. {12, 246, 2, 7 },
  1278. {13, 247, 2, 2 },
  1279. {14, 248, 2, 4 },
  1280. };
  1281. static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1282. {
  1283. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1284. struct channel_info *info;
  1285. char *tx_power1;
  1286. char *tx_power2;
  1287. unsigned int i;
  1288. u16 eeprom;
  1289. /*
  1290. * Initialize all hw fields.
  1291. */
  1292. rt2x00dev->hw->flags =
  1293. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1294. IEEE80211_HW_SIGNAL_DBM |
  1295. IEEE80211_HW_SUPPORTS_PS |
  1296. IEEE80211_HW_PS_NULLFUNC_STACK;
  1297. rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
  1298. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1299. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1300. rt2x00_eeprom_addr(rt2x00dev,
  1301. EEPROM_MAC_ADDR_0));
  1302. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1303. /*
  1304. * Initialize HT information.
  1305. */
  1306. spec->ht.ht_supported = true;
  1307. spec->ht.cap =
  1308. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  1309. IEEE80211_HT_CAP_GRN_FLD |
  1310. IEEE80211_HT_CAP_SGI_20 |
  1311. IEEE80211_HT_CAP_SGI_40 |
  1312. IEEE80211_HT_CAP_TX_STBC |
  1313. IEEE80211_HT_CAP_RX_STBC |
  1314. IEEE80211_HT_CAP_PSMP_SUPPORT;
  1315. spec->ht.ampdu_factor = 3;
  1316. spec->ht.ampdu_density = 4;
  1317. spec->ht.mcs.tx_params =
  1318. IEEE80211_HT_MCS_TX_DEFINED |
  1319. IEEE80211_HT_MCS_TX_RX_DIFF |
  1320. ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
  1321. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  1322. switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  1323. case 3:
  1324. spec->ht.mcs.rx_mask[2] = 0xff;
  1325. case 2:
  1326. spec->ht.mcs.rx_mask[1] = 0xff;
  1327. case 1:
  1328. spec->ht.mcs.rx_mask[0] = 0xff;
  1329. spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  1330. break;
  1331. }
  1332. /*
  1333. * Initialize hw_mode information.
  1334. */
  1335. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1336. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1337. if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
  1338. rt2x00_rf(&rt2x00dev->chip, RF2720)) {
  1339. spec->num_channels = 14;
  1340. spec->channels = rf_vals;
  1341. } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
  1342. rt2x00_rf(&rt2x00dev->chip, RF2750)) {
  1343. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1344. spec->num_channels = ARRAY_SIZE(rf_vals);
  1345. spec->channels = rf_vals;
  1346. } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
  1347. rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  1348. spec->num_channels = ARRAY_SIZE(rf_vals_3070);
  1349. spec->channels = rf_vals_3070;
  1350. }
  1351. /*
  1352. * Create channel information array
  1353. */
  1354. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  1355. if (!info)
  1356. return -ENOMEM;
  1357. spec->channels_info = info;
  1358. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  1359. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  1360. for (i = 0; i < 14; i++) {
  1361. info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
  1362. info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
  1363. }
  1364. if (spec->num_channels > 14) {
  1365. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  1366. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  1367. for (i = 14; i < spec->num_channels; i++) {
  1368. info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
  1369. info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. static const struct rt2800_ops rt2800usb_rt2800_ops = {
  1375. .register_read = rt2x00usb_register_read,
  1376. .register_write = rt2x00usb_register_write,
  1377. .register_write_lock = rt2x00usb_register_write_lock,
  1378. .register_multiread = rt2x00usb_register_multiread,
  1379. .register_multiwrite = rt2x00usb_register_multiwrite,
  1380. .regbusy_read = rt2x00usb_regbusy_read,
  1381. };
  1382. static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1383. {
  1384. int retval;
  1385. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  1386. rt2x00dev->priv = (void *)&rt2800usb_rt2800_ops;
  1387. /*
  1388. * Allocate eeprom data.
  1389. */
  1390. retval = rt2800usb_validate_eeprom(rt2x00dev);
  1391. if (retval)
  1392. return retval;
  1393. retval = rt2800usb_init_eeprom(rt2x00dev);
  1394. if (retval)
  1395. return retval;
  1396. /*
  1397. * Initialize hw specifications.
  1398. */
  1399. retval = rt2800usb_probe_hw_mode(rt2x00dev);
  1400. if (retval)
  1401. return retval;
  1402. /*
  1403. * This device has multiple filters for control frames
  1404. * and has a separate filter for PS Poll frames.
  1405. */
  1406. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  1407. __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
  1408. /*
  1409. * This device requires firmware.
  1410. */
  1411. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  1412. __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
  1413. if (!modparam_nohwcrypt)
  1414. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  1415. /*
  1416. * Set the rssi offset.
  1417. */
  1418. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1419. return 0;
  1420. }
  1421. /*
  1422. * IEEE80211 stack callback functions.
  1423. */
  1424. static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
  1425. u32 *iv32, u16 *iv16)
  1426. {
  1427. struct rt2x00_dev *rt2x00dev = hw->priv;
  1428. struct mac_iveiv_entry iveiv_entry;
  1429. u32 offset;
  1430. offset = MAC_IVEIV_ENTRY(hw_key_idx);
  1431. rt2800_register_multiread(rt2x00dev, offset,
  1432. &iveiv_entry, sizeof(iveiv_entry));
  1433. memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
  1434. memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
  1435. }
  1436. static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  1437. {
  1438. struct rt2x00_dev *rt2x00dev = hw->priv;
  1439. u32 reg;
  1440. bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  1441. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  1442. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  1443. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  1444. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  1445. rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  1446. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  1447. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  1448. rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  1449. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  1450. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  1451. rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  1452. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  1453. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  1454. rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  1455. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  1456. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  1457. rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  1458. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  1459. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  1460. rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  1461. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  1462. return 0;
  1463. }
  1464. static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  1465. const struct ieee80211_tx_queue_params *params)
  1466. {
  1467. struct rt2x00_dev *rt2x00dev = hw->priv;
  1468. struct data_queue *queue;
  1469. struct rt2x00_field32 field;
  1470. int retval;
  1471. u32 reg;
  1472. u32 offset;
  1473. /*
  1474. * First pass the configuration through rt2x00lib, that will
  1475. * update the queue settings and validate the input. After that
  1476. * we are free to update the registers based on the value
  1477. * in the queue parameter.
  1478. */
  1479. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  1480. if (retval)
  1481. return retval;
  1482. /*
  1483. * We only need to perform additional register initialization
  1484. * for WMM queues/
  1485. */
  1486. if (queue_idx >= 4)
  1487. return 0;
  1488. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  1489. /* Update WMM TXOP register */
  1490. offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  1491. field.bit_offset = (queue_idx & 1) * 16;
  1492. field.bit_mask = 0xffff << field.bit_offset;
  1493. rt2800_register_read(rt2x00dev, offset, &reg);
  1494. rt2x00_set_field32(&reg, field, queue->txop);
  1495. rt2800_register_write(rt2x00dev, offset, reg);
  1496. /* Update WMM registers */
  1497. field.bit_offset = queue_idx * 4;
  1498. field.bit_mask = 0xf << field.bit_offset;
  1499. rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  1500. rt2x00_set_field32(&reg, field, queue->aifs);
  1501. rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  1502. rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  1503. rt2x00_set_field32(&reg, field, queue->cw_min);
  1504. rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  1505. rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  1506. rt2x00_set_field32(&reg, field, queue->cw_max);
  1507. rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  1508. /* Update EDCA registers */
  1509. offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  1510. rt2800_register_read(rt2x00dev, offset, &reg);
  1511. rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  1512. rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  1513. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  1514. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  1515. rt2800_register_write(rt2x00dev, offset, reg);
  1516. return 0;
  1517. }
  1518. static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
  1519. {
  1520. struct rt2x00_dev *rt2x00dev = hw->priv;
  1521. u64 tsf;
  1522. u32 reg;
  1523. rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  1524. tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  1525. rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  1526. tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  1527. return tsf;
  1528. }
  1529. static const struct ieee80211_ops rt2800usb_mac80211_ops = {
  1530. .tx = rt2x00mac_tx,
  1531. .start = rt2x00mac_start,
  1532. .stop = rt2x00mac_stop,
  1533. .add_interface = rt2x00mac_add_interface,
  1534. .remove_interface = rt2x00mac_remove_interface,
  1535. .config = rt2x00mac_config,
  1536. .configure_filter = rt2x00mac_configure_filter,
  1537. .set_tim = rt2x00mac_set_tim,
  1538. .set_key = rt2x00mac_set_key,
  1539. .get_stats = rt2x00mac_get_stats,
  1540. .get_tkip_seq = rt2800usb_get_tkip_seq,
  1541. .set_rts_threshold = rt2800usb_set_rts_threshold,
  1542. .bss_info_changed = rt2x00mac_bss_info_changed,
  1543. .conf_tx = rt2800usb_conf_tx,
  1544. .get_tx_stats = rt2x00mac_get_tx_stats,
  1545. .get_tsf = rt2800usb_get_tsf,
  1546. .rfkill_poll = rt2x00mac_rfkill_poll,
  1547. };
  1548. static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
  1549. .probe_hw = rt2800usb_probe_hw,
  1550. .get_firmware_name = rt2800usb_get_firmware_name,
  1551. .check_firmware = rt2800usb_check_firmware,
  1552. .load_firmware = rt2800usb_load_firmware,
  1553. .initialize = rt2x00usb_initialize,
  1554. .uninitialize = rt2x00usb_uninitialize,
  1555. .clear_entry = rt2x00usb_clear_entry,
  1556. .set_device_state = rt2800usb_set_device_state,
  1557. .rfkill_poll = rt2800_rfkill_poll,
  1558. .link_stats = rt2800_link_stats,
  1559. .reset_tuner = rt2800_reset_tuner,
  1560. .link_tuner = rt2800_link_tuner,
  1561. .write_tx_desc = rt2800usb_write_tx_desc,
  1562. .write_tx_data = rt2x00usb_write_tx_data,
  1563. .write_beacon = rt2800usb_write_beacon,
  1564. .get_tx_data_len = rt2800usb_get_tx_data_len,
  1565. .kick_tx_queue = rt2800usb_kick_tx_queue,
  1566. .kill_tx_queue = rt2x00usb_kill_tx_queue,
  1567. .fill_rxdone = rt2800usb_fill_rxdone,
  1568. .config_shared_key = rt2800_config_shared_key,
  1569. .config_pairwise_key = rt2800_config_pairwise_key,
  1570. .config_filter = rt2800_config_filter,
  1571. .config_intf = rt2800_config_intf,
  1572. .config_erp = rt2800_config_erp,
  1573. .config_ant = rt2800_config_ant,
  1574. .config = rt2800_config,
  1575. };
  1576. static const struct data_queue_desc rt2800usb_queue_rx = {
  1577. .entry_num = RX_ENTRIES,
  1578. .data_size = AGGREGATION_SIZE,
  1579. .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE,
  1580. .priv_size = sizeof(struct queue_entry_priv_usb),
  1581. };
  1582. static const struct data_queue_desc rt2800usb_queue_tx = {
  1583. .entry_num = TX_ENTRIES,
  1584. .data_size = AGGREGATION_SIZE,
  1585. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  1586. .priv_size = sizeof(struct queue_entry_priv_usb),
  1587. };
  1588. static const struct data_queue_desc rt2800usb_queue_bcn = {
  1589. .entry_num = 8 * BEACON_ENTRIES,
  1590. .data_size = MGMT_FRAME_SIZE,
  1591. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  1592. .priv_size = sizeof(struct queue_entry_priv_usb),
  1593. };
  1594. static const struct rt2x00_ops rt2800usb_ops = {
  1595. .name = KBUILD_MODNAME,
  1596. .max_sta_intf = 1,
  1597. .max_ap_intf = 8,
  1598. .eeprom_size = EEPROM_SIZE,
  1599. .rf_size = RF_SIZE,
  1600. .tx_queues = NUM_TX_QUEUES,
  1601. .rx = &rt2800usb_queue_rx,
  1602. .tx = &rt2800usb_queue_tx,
  1603. .bcn = &rt2800usb_queue_bcn,
  1604. .lib = &rt2800usb_rt2x00_ops,
  1605. .hw = &rt2800usb_mac80211_ops,
  1606. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1607. .debugfs = &rt2800_rt2x00debug,
  1608. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1609. };
  1610. /*
  1611. * rt2800usb module information.
  1612. */
  1613. static struct usb_device_id rt2800usb_device_table[] = {
  1614. /* Abocom */
  1615. { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  1616. { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  1617. { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  1618. { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  1619. { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  1620. { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  1621. /* AirTies */
  1622. { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
  1623. /* Amigo */
  1624. { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  1625. { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
  1626. /* Amit */
  1627. { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  1628. /* ASUS */
  1629. { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
  1630. { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
  1631. { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
  1632. { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
  1633. { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
  1634. /* AzureWave */
  1635. { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
  1636. { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
  1637. { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
  1638. { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
  1639. /* Belkin */
  1640. { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
  1641. { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1642. { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1643. { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
  1644. /* Buffalo */
  1645. { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
  1646. { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
  1647. /* Conceptronic */
  1648. { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
  1649. { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
  1650. { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
  1651. { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  1652. { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  1653. { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
  1654. { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
  1655. { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
  1656. { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
  1657. { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
  1658. /* Corega */
  1659. { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
  1660. { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1661. { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  1662. { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  1663. { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
  1664. /* D-Link */
  1665. { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  1666. { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
  1667. { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
  1668. { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
  1669. { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
  1670. { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
  1671. { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  1672. { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
  1673. /* Edimax */
  1674. { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
  1675. { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
  1676. { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
  1677. /* Encore */
  1678. { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
  1679. /* EnGenius */
  1680. { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
  1681. { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
  1682. { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
  1683. { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
  1684. { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
  1685. { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
  1686. /* Gemtek */
  1687. { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
  1688. /* Gigabyte */
  1689. { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
  1690. { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1691. { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
  1692. /* Hawking */
  1693. { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
  1694. { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
  1695. { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
  1696. { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
  1697. /* I-O DATA */
  1698. { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
  1699. /* LevelOne */
  1700. { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
  1701. { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
  1702. /* Linksys */
  1703. { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
  1704. { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
  1705. { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
  1706. /* Logitec */
  1707. { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
  1708. { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
  1709. { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
  1710. /* Motorola */
  1711. { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  1712. { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
  1713. /* Ovislink */
  1714. { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  1715. /* Pegatron */
  1716. { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
  1717. { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1718. { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
  1719. /* Philips */
  1720. { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
  1721. /* Planex */
  1722. { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
  1723. { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
  1724. { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
  1725. /* Qcom */
  1726. { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
  1727. /* Quanta */
  1728. { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
  1729. /* Ralink */
  1730. { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
  1731. { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
  1732. { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
  1733. { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  1734. { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  1735. { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  1736. { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  1737. { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  1738. { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
  1739. /* Samsung */
  1740. { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
  1741. /* Siemens */
  1742. { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
  1743. /* Sitecom */
  1744. { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
  1745. { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
  1746. { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1747. { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
  1748. { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
  1749. { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
  1750. { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  1751. { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
  1752. { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
  1753. { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  1754. { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
  1755. { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
  1756. /* SMC */
  1757. { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
  1758. { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
  1759. { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
  1760. { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
  1761. { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
  1762. { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
  1763. { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
  1764. { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
  1765. { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
  1766. /* Sparklan */
  1767. { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
  1768. /* Sweex */
  1769. { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
  1770. { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
  1771. { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
  1772. /* U-Media*/
  1773. { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
  1774. /* ZCOM */
  1775. { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
  1776. { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
  1777. /* Zinwell */
  1778. { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
  1779. { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
  1780. { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
  1781. { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
  1782. /* Zyxel */
  1783. { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
  1784. { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
  1785. { 0, }
  1786. };
  1787. MODULE_AUTHOR(DRV_PROJECT);
  1788. MODULE_VERSION(DRV_VERSION);
  1789. MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
  1790. MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
  1791. MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
  1792. MODULE_FIRMWARE(FIRMWARE_RT2870);
  1793. MODULE_LICENSE("GPL");
  1794. static struct usb_driver rt2800usb_driver = {
  1795. .name = KBUILD_MODNAME,
  1796. .id_table = rt2800usb_device_table,
  1797. .probe = rt2x00usb_probe,
  1798. .disconnect = rt2x00usb_disconnect,
  1799. .suspend = rt2x00usb_suspend,
  1800. .resume = rt2x00usb_resume,
  1801. };
  1802. static int __init rt2800usb_init(void)
  1803. {
  1804. return usb_register(&rt2800usb_driver);
  1805. }
  1806. static void __exit rt2800usb_exit(void)
  1807. {
  1808. usb_deregister(&rt2800usb_driver);
  1809. }
  1810. module_init(rt2800usb_init);
  1811. module_exit(rt2800usb_exit);