rt2800usb.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  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 "rt2800usb.h"
  32. /*
  33. * Allow hardware encryption to be disabled.
  34. */
  35. static int modparam_nohwcrypt = 1;
  36. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  37. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  38. /*
  39. * Register access.
  40. * All access to the CSR registers will go through the methods
  41. * rt2800_register_read and rt2800_register_write.
  42. * BBP and RF register require indirect register access,
  43. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  44. * These indirect registers work with busy bits,
  45. * and we will try maximal REGISTER_BUSY_COUNT times to access
  46. * the register while taking a REGISTER_BUSY_DELAY us delay
  47. * between each attampt. When the busy bit is still set at that time,
  48. * the access attempt is considered to have failed,
  49. * and we will print an error.
  50. * The _lock versions must be used if you already hold the csr_mutex
  51. */
  52. #define WAIT_FOR_BBP(__dev, __reg) \
  53. rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
  54. #define WAIT_FOR_RFCSR(__dev, __reg) \
  55. rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
  56. #define WAIT_FOR_RF(__dev, __reg) \
  57. rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
  58. #define WAIT_FOR_MCU(__dev, __reg) \
  59. rt2x00usb_regbusy_read((__dev), H2M_MAILBOX_CSR, \
  60. H2M_MAILBOX_CSR_OWNER, (__reg))
  61. static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  62. const unsigned int word, const u8 value)
  63. {
  64. u32 reg;
  65. mutex_lock(&rt2x00dev->csr_mutex);
  66. /*
  67. * Wait until the BBP becomes available, afterwards we
  68. * can safely write the new data into the register.
  69. */
  70. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  71. reg = 0;
  72. rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
  73. rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  74. rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  75. rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
  76. rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  77. }
  78. mutex_unlock(&rt2x00dev->csr_mutex);
  79. }
  80. static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  81. const unsigned int word, u8 *value)
  82. {
  83. u32 reg;
  84. mutex_lock(&rt2x00dev->csr_mutex);
  85. /*
  86. * Wait until the BBP becomes available, afterwards we
  87. * can safely write the read request into the register.
  88. * After the data has been written, we wait until hardware
  89. * returns the correct value, if at any time the register
  90. * doesn't become available in time, reg will be 0xffffffff
  91. * which means we return 0xff to the caller.
  92. */
  93. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  94. reg = 0;
  95. rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  96. rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  97. rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
  98. rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  99. WAIT_FOR_BBP(rt2x00dev, &reg);
  100. }
  101. *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
  102. mutex_unlock(&rt2x00dev->csr_mutex);
  103. }
  104. static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
  105. const unsigned int word, const u8 value)
  106. {
  107. u32 reg;
  108. mutex_lock(&rt2x00dev->csr_mutex);
  109. /*
  110. * Wait until the RFCSR becomes available, afterwards we
  111. * can safely write the new data into the register.
  112. */
  113. if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  114. reg = 0;
  115. rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
  116. rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  117. rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
  118. rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  119. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  120. }
  121. mutex_unlock(&rt2x00dev->csr_mutex);
  122. }
  123. static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
  124. const unsigned int word, u8 *value)
  125. {
  126. u32 reg;
  127. mutex_lock(&rt2x00dev->csr_mutex);
  128. /*
  129. * Wait until the RFCSR becomes available, afterwards we
  130. * can safely write the read request into the register.
  131. * After the data has been written, we wait until hardware
  132. * returns the correct value, if at any time the register
  133. * doesn't become available in time, reg will be 0xffffffff
  134. * which means we return 0xff to the caller.
  135. */
  136. if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  137. reg = 0;
  138. rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  139. rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
  140. rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  141. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  142. WAIT_FOR_RFCSR(rt2x00dev, &reg);
  143. }
  144. *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
  145. mutex_unlock(&rt2x00dev->csr_mutex);
  146. }
  147. static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
  148. const unsigned int word, const u32 value)
  149. {
  150. u32 reg;
  151. mutex_lock(&rt2x00dev->csr_mutex);
  152. /*
  153. * Wait until the RF becomes available, afterwards we
  154. * can safely write the new data into the register.
  155. */
  156. if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  157. reg = 0;
  158. rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
  159. rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
  160. rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
  161. rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
  162. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
  163. rt2x00_rf_write(rt2x00dev, word, value);
  164. }
  165. mutex_unlock(&rt2x00dev->csr_mutex);
  166. }
  167. static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
  168. const u8 command, const u8 token,
  169. const u8 arg0, const u8 arg1)
  170. {
  171. u32 reg;
  172. mutex_lock(&rt2x00dev->csr_mutex);
  173. /*
  174. * Wait until the MCU becomes available, afterwards we
  175. * can safely write the new data into the register.
  176. */
  177. if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
  178. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  179. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  180. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  181. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  182. rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
  183. reg = 0;
  184. rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  185. rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
  186. }
  187. mutex_unlock(&rt2x00dev->csr_mutex);
  188. }
  189. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  190. static const struct rt2x00debug rt2800usb_rt2x00debug = {
  191. .owner = THIS_MODULE,
  192. .csr = {
  193. .read = rt2800_register_read,
  194. .write = rt2800_register_write,
  195. .flags = RT2X00DEBUGFS_OFFSET,
  196. .word_base = CSR_REG_BASE,
  197. .word_size = sizeof(u32),
  198. .word_count = CSR_REG_SIZE / sizeof(u32),
  199. },
  200. .eeprom = {
  201. .read = rt2x00_eeprom_read,
  202. .write = rt2x00_eeprom_write,
  203. .word_base = EEPROM_BASE,
  204. .word_size = sizeof(u16),
  205. .word_count = EEPROM_SIZE / sizeof(u16),
  206. },
  207. .bbp = {
  208. .read = rt2800usb_bbp_read,
  209. .write = rt2800usb_bbp_write,
  210. .word_base = BBP_BASE,
  211. .word_size = sizeof(u8),
  212. .word_count = BBP_SIZE / sizeof(u8),
  213. },
  214. .rf = {
  215. .read = rt2x00_rf_read,
  216. .write = rt2800usb_rf_write,
  217. .word_base = RF_BASE,
  218. .word_size = sizeof(u32),
  219. .word_count = RF_SIZE / sizeof(u32),
  220. },
  221. };
  222. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  223. static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  224. {
  225. u32 reg;
  226. rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
  227. return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
  228. }
  229. #ifdef CONFIG_RT2X00_LIB_LEDS
  230. static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
  231. enum led_brightness brightness)
  232. {
  233. struct rt2x00_led *led =
  234. container_of(led_cdev, struct rt2x00_led, led_dev);
  235. unsigned int enabled = brightness != LED_OFF;
  236. unsigned int bg_mode =
  237. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  238. unsigned int polarity =
  239. rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  240. EEPROM_FREQ_LED_POLARITY);
  241. unsigned int ledmode =
  242. rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  243. EEPROM_FREQ_LED_MODE);
  244. if (led->type == LED_TYPE_RADIO) {
  245. rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  246. enabled ? 0x20 : 0);
  247. } else if (led->type == LED_TYPE_ASSOC) {
  248. rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  249. enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
  250. } else if (led->type == LED_TYPE_QUALITY) {
  251. /*
  252. * The brightness is divided into 6 levels (0 - 5),
  253. * The specs tell us the following levels:
  254. * 0, 1 ,3, 7, 15, 31
  255. * to determine the level in a simple way we can simply
  256. * work with bitshifting:
  257. * (1 << level) - 1
  258. */
  259. rt2800usb_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  260. (1 << brightness / (LED_FULL / 6)) - 1,
  261. polarity);
  262. }
  263. }
  264. static int rt2800usb_blink_set(struct led_classdev *led_cdev,
  265. unsigned long *delay_on,
  266. unsigned long *delay_off)
  267. {
  268. struct rt2x00_led *led =
  269. container_of(led_cdev, struct rt2x00_led, led_dev);
  270. u32 reg;
  271. rt2800_register_read(led->rt2x00dev, LED_CFG, &reg);
  272. rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
  273. rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
  274. rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
  275. rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
  276. rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
  277. rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
  278. rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
  279. rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
  280. return 0;
  281. }
  282. static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
  283. struct rt2x00_led *led,
  284. enum led_type type)
  285. {
  286. led->rt2x00dev = rt2x00dev;
  287. led->type = type;
  288. led->led_dev.brightness_set = rt2800usb_brightness_set;
  289. led->led_dev.blink_set = rt2800usb_blink_set;
  290. led->flags = LED_INITIALIZED;
  291. }
  292. #endif /* CONFIG_RT2X00_LIB_LEDS */
  293. /*
  294. * Configuration handlers.
  295. */
  296. static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
  297. struct rt2x00lib_crypto *crypto,
  298. struct ieee80211_key_conf *key)
  299. {
  300. struct mac_wcid_entry wcid_entry;
  301. struct mac_iveiv_entry iveiv_entry;
  302. u32 offset;
  303. u32 reg;
  304. offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
  305. rt2800_register_read(rt2x00dev, offset, &reg);
  306. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
  307. !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
  308. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
  309. (crypto->cmd == SET_KEY) * crypto->cipher);
  310. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
  311. (crypto->cmd == SET_KEY) * crypto->bssidx);
  312. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
  313. rt2800_register_write(rt2x00dev, offset, reg);
  314. offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
  315. memset(&iveiv_entry, 0, sizeof(iveiv_entry));
  316. if ((crypto->cipher == CIPHER_TKIP) ||
  317. (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
  318. (crypto->cipher == CIPHER_AES))
  319. iveiv_entry.iv[3] |= 0x20;
  320. iveiv_entry.iv[3] |= key->keyidx << 6;
  321. rt2800_register_multiwrite(rt2x00dev, offset,
  322. &iveiv_entry, sizeof(iveiv_entry));
  323. offset = MAC_WCID_ENTRY(key->hw_key_idx);
  324. memset(&wcid_entry, 0, sizeof(wcid_entry));
  325. if (crypto->cmd == SET_KEY)
  326. memcpy(&wcid_entry, crypto->address, ETH_ALEN);
  327. rt2800_register_multiwrite(rt2x00dev, offset,
  328. &wcid_entry, sizeof(wcid_entry));
  329. }
  330. static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  331. struct rt2x00lib_crypto *crypto,
  332. struct ieee80211_key_conf *key)
  333. {
  334. struct hw_key_entry key_entry;
  335. struct rt2x00_field32 field;
  336. u32 offset;
  337. u32 reg;
  338. if (crypto->cmd == SET_KEY) {
  339. key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
  340. memcpy(key_entry.key, crypto->key,
  341. sizeof(key_entry.key));
  342. memcpy(key_entry.tx_mic, crypto->tx_mic,
  343. sizeof(key_entry.tx_mic));
  344. memcpy(key_entry.rx_mic, crypto->rx_mic,
  345. sizeof(key_entry.rx_mic));
  346. offset = SHARED_KEY_ENTRY(key->hw_key_idx);
  347. rt2800_register_multiwrite(rt2x00dev, offset,
  348. &key_entry, sizeof(key_entry));
  349. }
  350. /*
  351. * The cipher types are stored over multiple registers
  352. * starting with SHARED_KEY_MODE_BASE each word will have
  353. * 32 bits and contains the cipher types for 2 bssidx each.
  354. * Using the correct defines correctly will cause overhead,
  355. * so just calculate the correct offset.
  356. */
  357. field.bit_offset = 4 * (key->hw_key_idx % 8);
  358. field.bit_mask = 0x7 << field.bit_offset;
  359. offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
  360. rt2800_register_read(rt2x00dev, offset, &reg);
  361. rt2x00_set_field32(&reg, field,
  362. (crypto->cmd == SET_KEY) * crypto->cipher);
  363. rt2800_register_write(rt2x00dev, offset, reg);
  364. /*
  365. * Update WCID information
  366. */
  367. rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  368. return 0;
  369. }
  370. static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  371. struct rt2x00lib_crypto *crypto,
  372. struct ieee80211_key_conf *key)
  373. {
  374. struct hw_key_entry key_entry;
  375. u32 offset;
  376. if (crypto->cmd == SET_KEY) {
  377. /*
  378. * 1 pairwise key is possible per AID, this means that the AID
  379. * equals our hw_key_idx. Make sure the WCID starts _after_ the
  380. * last possible shared key entry.
  381. */
  382. if (crypto->aid > (256 - 32))
  383. return -ENOSPC;
  384. key->hw_key_idx = 32 + crypto->aid;
  385. memcpy(key_entry.key, crypto->key,
  386. sizeof(key_entry.key));
  387. memcpy(key_entry.tx_mic, crypto->tx_mic,
  388. sizeof(key_entry.tx_mic));
  389. memcpy(key_entry.rx_mic, crypto->rx_mic,
  390. sizeof(key_entry.rx_mic));
  391. offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  392. rt2800_register_multiwrite(rt2x00dev, offset,
  393. &key_entry, sizeof(key_entry));
  394. }
  395. /*
  396. * Update WCID information
  397. */
  398. rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  399. return 0;
  400. }
  401. static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
  402. const unsigned int filter_flags)
  403. {
  404. u32 reg;
  405. /*
  406. * Start configuration steps.
  407. * Note that the version error will always be dropped
  408. * and broadcast frames will always be accepted since
  409. * there is no filter for it at this time.
  410. */
  411. rt2800_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
  412. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
  413. !(filter_flags & FIF_FCSFAIL));
  414. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
  415. !(filter_flags & FIF_PLCPFAIL));
  416. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
  417. !(filter_flags & FIF_PROMISC_IN_BSS));
  418. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
  419. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
  420. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
  421. !(filter_flags & FIF_ALLMULTI));
  422. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
  423. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
  424. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
  425. !(filter_flags & FIF_CONTROL));
  426. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
  427. !(filter_flags & FIF_CONTROL));
  428. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
  429. !(filter_flags & FIF_CONTROL));
  430. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
  431. !(filter_flags & FIF_CONTROL));
  432. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
  433. !(filter_flags & FIF_CONTROL));
  434. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
  435. !(filter_flags & FIF_PSPOLL));
  436. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
  437. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
  438. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
  439. !(filter_flags & FIF_CONTROL));
  440. rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
  441. }
  442. static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
  443. struct rt2x00_intf *intf,
  444. struct rt2x00intf_conf *conf,
  445. const unsigned int flags)
  446. {
  447. unsigned int beacon_base;
  448. u32 reg;
  449. if (flags & CONFIG_UPDATE_TYPE) {
  450. /*
  451. * Clear current synchronisation setup.
  452. * For the Beacon base registers we only need to clear
  453. * the first byte since that byte contains the VALID and OWNER
  454. * bits which (when set to 0) will invalidate the entire beacon.
  455. */
  456. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  457. rt2800_register_write(rt2x00dev, beacon_base, 0);
  458. /*
  459. * Enable synchronisation.
  460. */
  461. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  462. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  463. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
  464. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  465. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  466. }
  467. if (flags & CONFIG_UPDATE_MAC) {
  468. reg = le32_to_cpu(conf->mac[1]);
  469. rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
  470. conf->mac[1] = cpu_to_le32(reg);
  471. rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
  472. conf->mac, sizeof(conf->mac));
  473. }
  474. if (flags & CONFIG_UPDATE_BSSID) {
  475. reg = le32_to_cpu(conf->bssid[1]);
  476. rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
  477. rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
  478. conf->bssid[1] = cpu_to_le32(reg);
  479. rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
  480. conf->bssid, sizeof(conf->bssid));
  481. }
  482. }
  483. static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
  484. struct rt2x00lib_erp *erp)
  485. {
  486. u32 reg;
  487. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  488. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
  489. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  490. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  491. rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
  492. !!erp->short_preamble);
  493. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
  494. !!erp->short_preamble);
  495. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  496. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  497. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
  498. erp->cts_protection ? 2 : 0);
  499. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  500. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
  501. erp->basic_rates);
  502. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  503. rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
  504. rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
  505. rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
  506. rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
  507. rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
  508. rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
  509. rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
  510. rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
  511. rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
  512. rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
  513. rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
  514. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  515. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
  516. erp->beacon_int * 16);
  517. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  518. }
  519. static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
  520. struct antenna_setup *ant)
  521. {
  522. u8 r1;
  523. u8 r3;
  524. rt2800usb_bbp_read(rt2x00dev, 1, &r1);
  525. rt2800usb_bbp_read(rt2x00dev, 3, &r3);
  526. /*
  527. * Configure the TX antenna.
  528. */
  529. switch ((int)ant->tx) {
  530. case 1:
  531. rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
  532. break;
  533. case 2:
  534. rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
  535. break;
  536. case 3:
  537. /* Do nothing */
  538. break;
  539. }
  540. /*
  541. * Configure the RX antenna.
  542. */
  543. switch ((int)ant->rx) {
  544. case 1:
  545. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
  546. break;
  547. case 2:
  548. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
  549. break;
  550. case 3:
  551. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
  552. break;
  553. }
  554. rt2800usb_bbp_write(rt2x00dev, 3, r3);
  555. rt2800usb_bbp_write(rt2x00dev, 1, r1);
  556. }
  557. static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  558. struct rt2x00lib_conf *libconf)
  559. {
  560. u16 eeprom;
  561. short lna_gain;
  562. if (libconf->rf.channel <= 14) {
  563. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  564. lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
  565. } else if (libconf->rf.channel <= 64) {
  566. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  567. lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
  568. } else if (libconf->rf.channel <= 128) {
  569. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
  570. lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
  571. } else {
  572. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
  573. lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
  574. }
  575. rt2x00dev->lna_gain = lna_gain;
  576. }
  577. static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
  578. struct ieee80211_conf *conf,
  579. struct rf_channel *rf,
  580. struct channel_info *info)
  581. {
  582. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  583. if (rt2x00dev->default_ant.tx == 1)
  584. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
  585. if (rt2x00dev->default_ant.rx == 1) {
  586. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
  587. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  588. } else if (rt2x00dev->default_ant.rx == 2)
  589. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  590. if (rf->channel > 14) {
  591. /*
  592. * When TX power is below 0, we should increase it by 7 to
  593. * make it a positive value (Minumum value is -7).
  594. * However this means that values between 0 and 7 have
  595. * double meaning, and we should set a 7DBm boost flag.
  596. */
  597. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
  598. (info->tx_power1 >= 0));
  599. if (info->tx_power1 < 0)
  600. info->tx_power1 += 7;
  601. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
  602. TXPOWER_A_TO_DEV(info->tx_power1));
  603. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
  604. (info->tx_power2 >= 0));
  605. if (info->tx_power2 < 0)
  606. info->tx_power2 += 7;
  607. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
  608. TXPOWER_A_TO_DEV(info->tx_power2));
  609. } else {
  610. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
  611. TXPOWER_G_TO_DEV(info->tx_power1));
  612. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
  613. TXPOWER_G_TO_DEV(info->tx_power2));
  614. }
  615. rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
  616. rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  617. rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  618. rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  619. rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  620. udelay(200);
  621. rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  622. rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  623. rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  624. rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  625. udelay(200);
  626. rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  627. rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  628. rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  629. rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  630. }
  631. static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
  632. struct ieee80211_conf *conf,
  633. struct rf_channel *rf,
  634. struct channel_info *info)
  635. {
  636. u8 rfcsr;
  637. rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
  638. rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
  639. rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
  640. rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
  641. rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
  642. rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
  643. rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
  644. TXPOWER_G_TO_DEV(info->tx_power1));
  645. rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
  646. rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
  647. rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
  648. rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
  649. rt2800usb_rfcsr_write(rt2x00dev, 24,
  650. rt2x00dev->calibration[conf_is_ht40(conf)]);
  651. rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
  652. rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  653. rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
  654. }
  655. static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
  656. struct ieee80211_conf *conf,
  657. struct rf_channel *rf,
  658. struct channel_info *info)
  659. {
  660. u32 reg;
  661. unsigned int tx_pin;
  662. u8 bbp;
  663. if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  664. rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
  665. else
  666. rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
  667. /*
  668. * Change BBP settings
  669. */
  670. rt2800usb_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  671. rt2800usb_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  672. rt2800usb_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  673. rt2800usb_bbp_write(rt2x00dev, 86, 0);
  674. if (rf->channel <= 14) {
  675. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  676. rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
  677. rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
  678. } else {
  679. rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
  680. rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
  681. }
  682. } else {
  683. rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
  684. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
  685. rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
  686. else
  687. rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
  688. }
  689. rt2800_register_read(rt2x00dev, TX_BAND_CFG, &reg);
  690. rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
  691. rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
  692. rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
  693. rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
  694. tx_pin = 0;
  695. /* Turn on unused PA or LNA when not using 1T or 1R */
  696. if (rt2x00dev->default_ant.tx != 1) {
  697. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
  698. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
  699. }
  700. /* Turn on unused PA or LNA when not using 1T or 1R */
  701. if (rt2x00dev->default_ant.rx != 1) {
  702. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
  703. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
  704. }
  705. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
  706. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
  707. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
  708. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
  709. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
  710. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
  711. rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  712. rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  713. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
  714. rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  715. rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
  716. rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
  717. rt2800usb_bbp_write(rt2x00dev, 3, bbp);
  718. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  719. if (conf_is_ht40(conf)) {
  720. rt2800usb_bbp_write(rt2x00dev, 69, 0x1a);
  721. rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  722. rt2800usb_bbp_write(rt2x00dev, 73, 0x16);
  723. } else {
  724. rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
  725. rt2800usb_bbp_write(rt2x00dev, 70, 0x08);
  726. rt2800usb_bbp_write(rt2x00dev, 73, 0x11);
  727. }
  728. }
  729. msleep(1);
  730. }
  731. static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  732. const int txpower)
  733. {
  734. u32 reg;
  735. u32 value = TXPOWER_G_TO_DEV(txpower);
  736. u8 r1;
  737. rt2800usb_bbp_read(rt2x00dev, 1, &r1);
  738. rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
  739. rt2800usb_bbp_write(rt2x00dev, 1, r1);
  740. rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
  741. rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
  742. rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
  743. rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
  744. rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
  745. rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
  746. rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
  747. rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
  748. rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
  749. rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
  750. rt2800_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
  751. rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
  752. rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
  753. rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
  754. rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
  755. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
  756. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
  757. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
  758. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
  759. rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
  760. rt2800_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
  761. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
  762. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
  763. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
  764. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
  765. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
  766. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
  767. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
  768. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
  769. rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
  770. rt2800_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
  771. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
  772. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
  773. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
  774. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
  775. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
  776. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
  777. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
  778. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
  779. rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
  780. rt2800_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
  781. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
  782. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
  783. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
  784. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
  785. rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
  786. }
  787. static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  788. struct rt2x00lib_conf *libconf)
  789. {
  790. u32 reg;
  791. rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
  792. rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
  793. libconf->conf->short_frame_max_tx_count);
  794. rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
  795. libconf->conf->long_frame_max_tx_count);
  796. rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
  797. rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
  798. rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
  799. rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
  800. rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
  801. }
  802. static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
  803. struct rt2x00lib_conf *libconf)
  804. {
  805. enum dev_state state =
  806. (libconf->conf->flags & IEEE80211_CONF_PS) ?
  807. STATE_SLEEP : STATE_AWAKE;
  808. u32 reg;
  809. if (state == STATE_SLEEP) {
  810. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
  811. rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  812. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
  813. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
  814. libconf->conf->listen_interval - 1);
  815. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
  816. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  817. rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  818. } else {
  819. rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  820. rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  821. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
  822. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
  823. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
  824. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  825. }
  826. }
  827. static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
  828. struct rt2x00lib_conf *libconf,
  829. const unsigned int flags)
  830. {
  831. /* Always recalculate LNA gain before changing configuration */
  832. rt2800usb_config_lna_gain(rt2x00dev, libconf);
  833. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  834. rt2800usb_config_channel(rt2x00dev, libconf->conf,
  835. &libconf->rf, &libconf->channel);
  836. if (flags & IEEE80211_CONF_CHANGE_POWER)
  837. rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  838. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  839. rt2800usb_config_retry_limit(rt2x00dev, libconf);
  840. if (flags & IEEE80211_CONF_CHANGE_PS)
  841. rt2800usb_config_ps(rt2x00dev, libconf);
  842. }
  843. /*
  844. * Link tuning
  845. */
  846. static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
  847. struct link_qual *qual)
  848. {
  849. u32 reg;
  850. /*
  851. * Update FCS error count from register.
  852. */
  853. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  854. qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
  855. }
  856. static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
  857. {
  858. if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  859. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
  860. return 0x1c + (2 * rt2x00dev->lna_gain);
  861. else
  862. return 0x2e + rt2x00dev->lna_gain;
  863. }
  864. if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  865. return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
  866. else
  867. return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
  868. }
  869. static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  870. struct link_qual *qual, u8 vgc_level)
  871. {
  872. if (qual->vgc_level != vgc_level) {
  873. rt2800usb_bbp_write(rt2x00dev, 66, vgc_level);
  874. qual->vgc_level = vgc_level;
  875. qual->vgc_level_reg = vgc_level;
  876. }
  877. }
  878. static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  879. struct link_qual *qual)
  880. {
  881. rt2800usb_set_vgc(rt2x00dev, qual,
  882. rt2800usb_get_default_vgc(rt2x00dev));
  883. }
  884. static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  885. struct link_qual *qual, const u32 count)
  886. {
  887. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
  888. return;
  889. /*
  890. * When RSSI is better then -80 increase VGC level with 0x10
  891. */
  892. rt2800usb_set_vgc(rt2x00dev, qual,
  893. rt2800usb_get_default_vgc(rt2x00dev) +
  894. ((qual->rssi > -80) * 0x10));
  895. }
  896. /*
  897. * Firmware functions
  898. */
  899. static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  900. {
  901. return FIRMWARE_RT2870;
  902. }
  903. static bool rt2800usb_check_crc(const u8 *data, const size_t len)
  904. {
  905. u16 fw_crc;
  906. u16 crc;
  907. /*
  908. * The last 2 bytes in the firmware array are the crc checksum itself,
  909. * this means that we should never pass those 2 bytes to the crc
  910. * algorithm.
  911. */
  912. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  913. /*
  914. * Use the crc ccitt algorithm.
  915. * This will return the same value as the legacy driver which
  916. * used bit ordering reversion on the both the firmware bytes
  917. * before input input as well as on the final output.
  918. * Obviously using crc ccitt directly is much more efficient.
  919. */
  920. crc = crc_ccitt(~0, data, len - 2);
  921. /*
  922. * There is a small difference between the crc-itu-t + bitrev and
  923. * the crc-ccitt crc calculation. In the latter method the 2 bytes
  924. * will be swapped, use swab16 to convert the crc to the correct
  925. * value.
  926. */
  927. crc = swab16(crc);
  928. return fw_crc == crc;
  929. }
  930. static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  931. const u8 *data, const size_t len)
  932. {
  933. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  934. size_t offset = 0;
  935. /*
  936. * Firmware files:
  937. * There are 2 variations of the rt2870 firmware.
  938. * a) size: 4kb
  939. * b) size: 8kb
  940. * Note that (b) contains 2 seperate firmware blobs of 4k
  941. * within the file. The first blob is the same firmware as (a),
  942. * but the second blob is for the additional chipsets.
  943. */
  944. if (len != 4096 && len != 8192)
  945. return FW_BAD_LENGTH;
  946. /*
  947. * Check if we need the upper 4kb firmware data or not.
  948. */
  949. if ((len == 4096) &&
  950. (chipset != 0x2860) &&
  951. (chipset != 0x2872) &&
  952. (chipset != 0x3070))
  953. return FW_BAD_VERSION;
  954. /*
  955. * 8kb firmware files must be checked as if it were
  956. * 2 seperate firmware files.
  957. */
  958. while (offset < len) {
  959. if (!rt2800usb_check_crc(data + offset, 4096))
  960. return FW_BAD_CRC;
  961. offset += 4096;
  962. }
  963. return FW_OK;
  964. }
  965. static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  966. const u8 *data, const size_t len)
  967. {
  968. unsigned int i;
  969. int status;
  970. u32 reg;
  971. u32 offset;
  972. u32 length;
  973. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  974. /*
  975. * Check which section of the firmware we need.
  976. */
  977. if ((chipset == 0x2860) ||
  978. (chipset == 0x2872) ||
  979. (chipset == 0x3070)) {
  980. offset = 0;
  981. length = 4096;
  982. } else {
  983. offset = 4096;
  984. length = 4096;
  985. }
  986. /*
  987. * Wait for stable hardware.
  988. */
  989. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  990. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  991. if (reg && reg != ~0)
  992. break;
  993. msleep(1);
  994. }
  995. if (i == REGISTER_BUSY_COUNT) {
  996. ERROR(rt2x00dev, "Unstable hardware.\n");
  997. return -EBUSY;
  998. }
  999. /*
  1000. * Write firmware to device.
  1001. */
  1002. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1003. USB_VENDOR_REQUEST_OUT,
  1004. FIRMWARE_IMAGE_BASE,
  1005. data + offset, length,
  1006. REGISTER_TIMEOUT32(length));
  1007. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  1008. rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  1009. /*
  1010. * Send firmware request to device to load firmware,
  1011. * we need to specify a long timeout time.
  1012. */
  1013. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  1014. 0, USB_MODE_FIRMWARE,
  1015. REGISTER_TIMEOUT_FIRMWARE);
  1016. if (status < 0) {
  1017. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  1018. return status;
  1019. }
  1020. msleep(10);
  1021. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1022. /*
  1023. * Send signal to firmware during boot time.
  1024. */
  1025. rt2800usb_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  1026. if ((chipset == 0x3070) ||
  1027. (chipset == 0x3071) ||
  1028. (chipset == 0x3572)) {
  1029. udelay(200);
  1030. rt2800usb_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
  1031. udelay(10);
  1032. }
  1033. /*
  1034. * Wait for device to stabilize.
  1035. */
  1036. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1037. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1038. if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  1039. break;
  1040. msleep(1);
  1041. }
  1042. if (i == REGISTER_BUSY_COUNT) {
  1043. ERROR(rt2x00dev, "PBF system register not ready.\n");
  1044. return -EBUSY;
  1045. }
  1046. /*
  1047. * Initialize firmware.
  1048. */
  1049. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1050. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1051. msleep(1);
  1052. return 0;
  1053. }
  1054. /*
  1055. * Initialization functions.
  1056. */
  1057. static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
  1058. {
  1059. u32 reg;
  1060. unsigned int i;
  1061. /*
  1062. * Wait untill BBP and RF are ready.
  1063. */
  1064. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1065. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1066. if (reg && reg != ~0)
  1067. break;
  1068. msleep(1);
  1069. }
  1070. if (i == REGISTER_BUSY_COUNT) {
  1071. ERROR(rt2x00dev, "Unstable hardware.\n");
  1072. return -EBUSY;
  1073. }
  1074. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1075. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
  1076. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1077. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  1078. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  1079. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1080. rt2800_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
  1081. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  1082. USB_MODE_RESET, REGISTER_TIMEOUT);
  1083. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1084. rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  1085. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  1086. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  1087. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  1088. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  1089. rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
  1090. rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  1091. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  1092. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  1093. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  1094. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  1095. rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
  1096. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  1097. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  1098. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1099. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1100. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
  1101. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  1102. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  1103. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  1104. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1105. rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  1106. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1107. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1108. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  1109. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  1110. rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  1111. } else {
  1112. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  1113. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  1114. }
  1115. rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  1116. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  1117. rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  1118. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  1119. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  1120. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  1121. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  1122. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  1123. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  1124. rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
  1125. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  1126. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  1127. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  1128. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  1129. rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  1130. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  1131. if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
  1132. rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
  1133. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  1134. else
  1135. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  1136. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  1137. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  1138. rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  1139. rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  1140. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  1141. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  1142. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  1143. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  1144. rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  1145. rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  1146. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  1147. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  1148. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
  1149. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  1150. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
  1151. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1152. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1153. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1154. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1155. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1156. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1157. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  1158. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  1159. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
  1160. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  1161. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
  1162. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1163. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1164. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1165. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1166. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1167. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1168. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  1169. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  1170. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  1171. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  1172. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
  1173. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1174. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1175. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1176. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1177. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1178. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1179. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  1180. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  1181. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  1182. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  1183. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
  1184. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1185. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1186. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1187. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1188. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1189. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1190. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  1191. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  1192. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  1193. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  1194. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
  1195. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1196. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1197. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1198. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1199. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1200. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1201. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  1202. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  1203. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  1204. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  1205. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
  1206. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1207. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1208. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1209. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1210. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1211. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1212. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  1213. rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  1214. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1215. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1216. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  1217. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1218. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  1219. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  1220. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  1221. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  1222. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  1223. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  1224. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1225. rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
  1226. rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
  1227. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  1228. rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  1229. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  1230. IEEE80211_MAX_RTS_THRESHOLD);
  1231. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  1232. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  1233. rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  1234. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  1235. /*
  1236. * ASIC will keep garbage value after boot, clear encryption keys.
  1237. */
  1238. for (i = 0; i < 4; i++)
  1239. rt2800_register_write(rt2x00dev,
  1240. SHARED_KEY_MODE_ENTRY(i), 0);
  1241. for (i = 0; i < 256; i++) {
  1242. u32 wcid[2] = { 0xffffffff, 0x00ffffff };
  1243. rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
  1244. wcid, sizeof(wcid));
  1245. rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
  1246. rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  1247. }
  1248. /*
  1249. * Clear all beacons
  1250. * For the Beacon base registers we only need to clear
  1251. * the first byte since that byte contains the VALID and OWNER
  1252. * bits which (when set to 0) will invalidate the entire beacon.
  1253. */
  1254. rt2800_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1255. rt2800_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1256. rt2800_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1257. rt2800_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1258. rt2800_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
  1259. rt2800_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
  1260. rt2800_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
  1261. rt2800_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
  1262. rt2800_register_read(rt2x00dev, USB_CYC_CFG, &reg);
  1263. rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
  1264. rt2800_register_write(rt2x00dev, USB_CYC_CFG, reg);
  1265. rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  1266. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  1267. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  1268. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  1269. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  1270. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  1271. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  1272. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  1273. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  1274. rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  1275. rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  1276. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  1277. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  1278. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  1279. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  1280. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  1281. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  1282. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  1283. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  1284. rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  1285. rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  1286. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  1287. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  1288. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
  1289. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  1290. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  1291. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  1292. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  1293. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  1294. rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  1295. rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  1296. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  1297. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  1298. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  1299. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  1300. rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  1301. /*
  1302. * We must clear the error counters.
  1303. * These registers are cleared on read,
  1304. * so we may pass a useless variable to store the value.
  1305. */
  1306. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  1307. rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  1308. rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  1309. rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  1310. rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  1311. rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  1312. return 0;
  1313. }
  1314. static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  1315. {
  1316. unsigned int i;
  1317. u32 reg;
  1318. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1319. rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  1320. if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  1321. return 0;
  1322. udelay(REGISTER_BUSY_DELAY);
  1323. }
  1324. ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
  1325. return -EACCES;
  1326. }
  1327. static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1328. {
  1329. unsigned int i;
  1330. u8 value;
  1331. /*
  1332. * BBP was enabled after firmware was loaded,
  1333. * but we need to reactivate it now.
  1334. */
  1335. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1336. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1337. msleep(1);
  1338. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1339. rt2800usb_bbp_read(rt2x00dev, 0, &value);
  1340. if ((value != 0xff) && (value != 0x00))
  1341. return 0;
  1342. udelay(REGISTER_BUSY_DELAY);
  1343. }
  1344. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1345. return -EACCES;
  1346. }
  1347. static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1348. {
  1349. unsigned int i;
  1350. u16 eeprom;
  1351. u8 reg_id;
  1352. u8 value;
  1353. if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
  1354. rt2800usb_wait_bbp_ready(rt2x00dev)))
  1355. return -EACCES;
  1356. rt2800usb_bbp_write(rt2x00dev, 65, 0x2c);
  1357. rt2800usb_bbp_write(rt2x00dev, 66, 0x38);
  1358. rt2800usb_bbp_write(rt2x00dev, 69, 0x12);
  1359. rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  1360. rt2800usb_bbp_write(rt2x00dev, 73, 0x10);
  1361. rt2800usb_bbp_write(rt2x00dev, 81, 0x37);
  1362. rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
  1363. rt2800usb_bbp_write(rt2x00dev, 83, 0x6a);
  1364. rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
  1365. rt2800usb_bbp_write(rt2x00dev, 86, 0x00);
  1366. rt2800usb_bbp_write(rt2x00dev, 91, 0x04);
  1367. rt2800usb_bbp_write(rt2x00dev, 92, 0x00);
  1368. rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
  1369. rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
  1370. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  1371. rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
  1372. rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
  1373. }
  1374. if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
  1375. rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
  1376. }
  1377. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1378. rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  1379. rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
  1380. rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
  1381. }
  1382. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1383. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1384. if (eeprom != 0xffff && eeprom != 0x0000) {
  1385. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1386. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1387. rt2800usb_bbp_write(rt2x00dev, reg_id, value);
  1388. }
  1389. }
  1390. return 0;
  1391. }
  1392. static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
  1393. bool bw40, u8 rfcsr24, u8 filter_target)
  1394. {
  1395. unsigned int i;
  1396. u8 bbp;
  1397. u8 rfcsr;
  1398. u8 passband;
  1399. u8 stopband;
  1400. u8 overtuned = 0;
  1401. rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1402. rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  1403. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  1404. rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  1405. rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1406. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  1407. rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
  1408. /*
  1409. * Set power & frequency of passband test tone
  1410. */
  1411. rt2800usb_bbp_write(rt2x00dev, 24, 0);
  1412. for (i = 0; i < 100; i++) {
  1413. rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
  1414. msleep(1);
  1415. rt2800usb_bbp_read(rt2x00dev, 55, &passband);
  1416. if (passband)
  1417. break;
  1418. }
  1419. /*
  1420. * Set power & frequency of stopband test tone
  1421. */
  1422. rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
  1423. for (i = 0; i < 100; i++) {
  1424. rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
  1425. msleep(1);
  1426. rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
  1427. if ((passband - stopband) <= filter_target) {
  1428. rfcsr24++;
  1429. overtuned += ((passband - stopband) == filter_target);
  1430. } else
  1431. break;
  1432. rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1433. }
  1434. rfcsr24 -= !!overtuned;
  1435. rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1436. return rfcsr24;
  1437. }
  1438. static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  1439. {
  1440. u8 rfcsr;
  1441. u8 bbp;
  1442. if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  1443. return 0;
  1444. /*
  1445. * Init RF calibration.
  1446. */
  1447. rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
  1448. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  1449. rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
  1450. msleep(1);
  1451. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  1452. rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
  1453. rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
  1454. rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
  1455. rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
  1456. rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
  1457. rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
  1458. rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
  1459. rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
  1460. rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
  1461. rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
  1462. rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
  1463. rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
  1464. rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
  1465. rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
  1466. rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
  1467. rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
  1468. rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
  1469. rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
  1470. rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
  1471. rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
  1472. rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
  1473. /*
  1474. * Set RX Filter calibration for 20MHz and 40MHz
  1475. */
  1476. rt2x00dev->calibration[0] =
  1477. rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
  1478. rt2x00dev->calibration[1] =
  1479. rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
  1480. /*
  1481. * Set back to initial state
  1482. */
  1483. rt2800usb_bbp_write(rt2x00dev, 24, 0);
  1484. rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1485. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  1486. rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
  1487. /*
  1488. * set BBP back to BW20
  1489. */
  1490. rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  1491. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  1492. rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  1493. return 0;
  1494. }
  1495. /*
  1496. * Device state switch handlers.
  1497. */
  1498. static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1499. enum dev_state state)
  1500. {
  1501. u32 reg;
  1502. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1503. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  1504. (state == STATE_RADIO_RX_ON) ||
  1505. (state == STATE_RADIO_RX_ON_LINK));
  1506. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1507. }
  1508. static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  1509. {
  1510. unsigned int i;
  1511. u32 reg;
  1512. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1513. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1514. if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  1515. !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  1516. return 0;
  1517. msleep(1);
  1518. }
  1519. ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
  1520. return -EACCES;
  1521. }
  1522. static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1523. {
  1524. u32 reg;
  1525. u16 word;
  1526. /*
  1527. * Initialize all registers.
  1528. */
  1529. if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
  1530. rt2800usb_init_registers(rt2x00dev) ||
  1531. rt2800usb_init_bbp(rt2x00dev) ||
  1532. rt2800usb_init_rfcsr(rt2x00dev)))
  1533. return -EIO;
  1534. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1535. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1536. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1537. udelay(50);
  1538. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1539. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  1540. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  1541. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  1542. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1543. rt2800_register_read(rt2x00dev, USB_DMA_CFG, &reg);
  1544. rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
  1545. /* Don't use bulk in aggregation when working with USB 1.1 */
  1546. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
  1547. (rt2x00dev->rx->usb_maxpacket == 512));
  1548. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
  1549. /*
  1550. * Total room for RX frames in kilobytes, PBF might still exceed
  1551. * this limit so reduce the number to prevent errors.
  1552. */
  1553. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
  1554. ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
  1555. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
  1556. rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
  1557. rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
  1558. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1559. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1560. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  1561. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1562. /*
  1563. * Initialize LED control
  1564. */
  1565. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  1566. rt2800usb_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  1567. word & 0xff, (word >> 8) & 0xff);
  1568. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  1569. rt2800usb_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  1570. word & 0xff, (word >> 8) & 0xff);
  1571. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  1572. rt2800usb_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  1573. word & 0xff, (word >> 8) & 0xff);
  1574. return 0;
  1575. }
  1576. static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1577. {
  1578. u32 reg;
  1579. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1580. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1581. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1582. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1583. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  1584. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  1585. rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
  1586. /* Wait for DMA, ignore error */
  1587. rt2800usb_wait_wpdma_ready(rt2x00dev);
  1588. rt2x00usb_disable_radio(rt2x00dev);
  1589. }
  1590. static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
  1591. enum dev_state state)
  1592. {
  1593. if (state == STATE_AWAKE)
  1594. rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  1595. else
  1596. rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  1597. return 0;
  1598. }
  1599. static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1600. enum dev_state state)
  1601. {
  1602. int retval = 0;
  1603. switch (state) {
  1604. case STATE_RADIO_ON:
  1605. /*
  1606. * Before the radio can be enabled, the device first has
  1607. * to be woken up. After that it needs a bit of time
  1608. * to be fully awake and then the radio can be enabled.
  1609. */
  1610. rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
  1611. msleep(1);
  1612. retval = rt2800usb_enable_radio(rt2x00dev);
  1613. break;
  1614. case STATE_RADIO_OFF:
  1615. /*
  1616. * After the radio has been disabled, the device should
  1617. * be put to sleep for powersaving.
  1618. */
  1619. rt2800usb_disable_radio(rt2x00dev);
  1620. rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
  1621. break;
  1622. case STATE_RADIO_RX_ON:
  1623. case STATE_RADIO_RX_ON_LINK:
  1624. case STATE_RADIO_RX_OFF:
  1625. case STATE_RADIO_RX_OFF_LINK:
  1626. rt2800usb_toggle_rx(rt2x00dev, state);
  1627. break;
  1628. case STATE_RADIO_IRQ_ON:
  1629. case STATE_RADIO_IRQ_OFF:
  1630. /* No support, but no error either */
  1631. break;
  1632. case STATE_DEEP_SLEEP:
  1633. case STATE_SLEEP:
  1634. case STATE_STANDBY:
  1635. case STATE_AWAKE:
  1636. retval = rt2800usb_set_state(rt2x00dev, state);
  1637. break;
  1638. default:
  1639. retval = -ENOTSUPP;
  1640. break;
  1641. }
  1642. if (unlikely(retval))
  1643. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1644. state, retval);
  1645. return retval;
  1646. }
  1647. /*
  1648. * TX descriptor initialization
  1649. */
  1650. static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1651. struct sk_buff *skb,
  1652. struct txentry_desc *txdesc)
  1653. {
  1654. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1655. __le32 *txi = skbdesc->desc;
  1656. __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
  1657. u32 word;
  1658. /*
  1659. * Initialize TX Info descriptor
  1660. */
  1661. rt2x00_desc_read(txwi, 0, &word);
  1662. rt2x00_set_field32(&word, TXWI_W0_FRAG,
  1663. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1664. rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
  1665. rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  1666. rt2x00_set_field32(&word, TXWI_W0_TS,
  1667. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1668. rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  1669. test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  1670. rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
  1671. rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
  1672. rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
  1673. rt2x00_set_field32(&word, TXWI_W0_BW,
  1674. test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  1675. rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  1676. test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  1677. rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
  1678. rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  1679. rt2x00_desc_write(txwi, 0, word);
  1680. rt2x00_desc_read(txwi, 1, &word);
  1681. rt2x00_set_field32(&word, TXWI_W1_ACK,
  1682. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1683. rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  1684. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1685. rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
  1686. rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  1687. test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  1688. txdesc->key_idx : 0xff);
  1689. rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
  1690. skb->len - txdesc->l2pad);
  1691. rt2x00_set_field32(&word, TXWI_W1_PACKETID,
  1692. skbdesc->entry->queue->qid + 1);
  1693. rt2x00_desc_write(txwi, 1, word);
  1694. /*
  1695. * Always write 0 to IV/EIV fields, hardware will insert the IV
  1696. * from the IVEIV register when TXINFO_W0_WIV is set to 0.
  1697. * When TXINFO_W0_WIV is set to 1 it will use the IV data
  1698. * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  1699. * crypto entry in the registers should be used to encrypt the frame.
  1700. */
  1701. _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
  1702. _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
  1703. /*
  1704. * Initialize TX descriptor
  1705. */
  1706. rt2x00_desc_read(txi, 0, &word);
  1707. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
  1708. skb->len + TXWI_DESC_SIZE);
  1709. rt2x00_set_field32(&word, TXINFO_W0_WIV,
  1710. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  1711. rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
  1712. rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
  1713. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
  1714. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
  1715. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1716. rt2x00_desc_write(txi, 0, word);
  1717. }
  1718. /*
  1719. * TX data initialization
  1720. */
  1721. static void rt2800usb_write_beacon(struct queue_entry *entry)
  1722. {
  1723. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1724. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1725. unsigned int beacon_base;
  1726. u32 reg;
  1727. /*
  1728. * Add the descriptor in front of the skb.
  1729. */
  1730. skb_push(entry->skb, entry->queue->desc_size);
  1731. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  1732. skbdesc->desc = entry->skb->data;
  1733. /*
  1734. * Disable beaconing while we are reloading the beacon data,
  1735. * otherwise we might be sending out invalid data.
  1736. */
  1737. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1738. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1739. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1740. /*
  1741. * Write entire beacon with descriptor to register.
  1742. */
  1743. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1744. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1745. USB_VENDOR_REQUEST_OUT, beacon_base,
  1746. entry->skb->data, entry->skb->len,
  1747. REGISTER_TIMEOUT32(entry->skb->len));
  1748. /*
  1749. * Clean up the beacon skb.
  1750. */
  1751. dev_kfree_skb(entry->skb);
  1752. entry->skb = NULL;
  1753. }
  1754. static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
  1755. {
  1756. int length;
  1757. /*
  1758. * The length _must_ include 4 bytes padding,
  1759. * it should always be multiple of 4,
  1760. * but it must _not_ be a multiple of the USB packet size.
  1761. */
  1762. length = roundup(entry->skb->len + 4, 4);
  1763. length += (4 * !(length % entry->queue->usb_maxpacket));
  1764. return length;
  1765. }
  1766. static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1767. const enum data_queue_qid queue)
  1768. {
  1769. u32 reg;
  1770. if (queue != QID_BEACON) {
  1771. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  1772. return;
  1773. }
  1774. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1775. if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  1776. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  1777. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  1778. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  1779. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1780. }
  1781. }
  1782. /*
  1783. * RX control handlers
  1784. */
  1785. static void rt2800usb_fill_rxdone(struct queue_entry *entry,
  1786. struct rxdone_entry_desc *rxdesc)
  1787. {
  1788. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1789. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1790. __le32 *rxd = (__le32 *)entry->skb->data;
  1791. __le32 *rxwi;
  1792. u32 rxd0;
  1793. u32 rxwi0;
  1794. u32 rxwi1;
  1795. u32 rxwi2;
  1796. u32 rxwi3;
  1797. /*
  1798. * Copy descriptor to the skbdesc->desc buffer, making it safe from
  1799. * moving of frame data in rt2x00usb.
  1800. */
  1801. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1802. rxd = (__le32 *)skbdesc->desc;
  1803. rxwi = &rxd[RXD_DESC_SIZE / sizeof(__le32)];
  1804. /*
  1805. * It is now safe to read the descriptor on all architectures.
  1806. */
  1807. rt2x00_desc_read(rxd, 0, &rxd0);
  1808. rt2x00_desc_read(rxwi, 0, &rxwi0);
  1809. rt2x00_desc_read(rxwi, 1, &rxwi1);
  1810. rt2x00_desc_read(rxwi, 2, &rxwi2);
  1811. rt2x00_desc_read(rxwi, 3, &rxwi3);
  1812. if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
  1813. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1814. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1815. rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
  1816. rxdesc->cipher_status =
  1817. rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
  1818. }
  1819. if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
  1820. /*
  1821. * Hardware has stripped IV/EIV data from 802.11 frame during
  1822. * decryption. Unfortunately the descriptor doesn't contain
  1823. * any fields with the EIV/IV data either, so they can't
  1824. * be restored by rt2x00lib.
  1825. */
  1826. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1827. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1828. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1829. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1830. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1831. }
  1832. if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
  1833. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1834. if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD)) {
  1835. rxdesc->dev_flags |= RXDONE_L2PAD;
  1836. skbdesc->flags |= SKBDESC_L2_PADDED;
  1837. }
  1838. if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
  1839. rxdesc->flags |= RX_FLAG_SHORT_GI;
  1840. if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
  1841. rxdesc->flags |= RX_FLAG_40MHZ;
  1842. /*
  1843. * Detect RX rate, always use MCS as signal type.
  1844. */
  1845. rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  1846. rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
  1847. rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
  1848. /*
  1849. * Mask of 0x8 bit to remove the short preamble flag.
  1850. */
  1851. if (rxdesc->rate_mode == RATE_MODE_CCK)
  1852. rxdesc->signal &= ~0x8;
  1853. rxdesc->rssi =
  1854. (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
  1855. rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
  1856. rxdesc->noise =
  1857. (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
  1858. rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
  1859. rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  1860. /*
  1861. * Remove RXWI descriptor from start of buffer.
  1862. */
  1863. skb_pull(entry->skb, skbdesc->desc_len);
  1864. skb_trim(entry->skb, rxdesc->size);
  1865. }
  1866. /*
  1867. * Device probe functions.
  1868. */
  1869. static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1870. {
  1871. u16 word;
  1872. u8 *mac;
  1873. u8 default_lna_gain;
  1874. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1875. /*
  1876. * Start validation of the data that has been read.
  1877. */
  1878. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1879. if (!is_valid_ether_addr(mac)) {
  1880. random_ether_addr(mac);
  1881. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1882. }
  1883. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1884. if (word == 0xffff) {
  1885. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1886. rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
  1887. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
  1888. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1889. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1890. } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
  1891. /*
  1892. * There is a max of 2 RX streams for RT2870 series
  1893. */
  1894. if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
  1895. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1896. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1897. }
  1898. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1899. if (word == 0xffff) {
  1900. rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
  1901. rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
  1902. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1903. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1904. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1905. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
  1906. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
  1907. rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
  1908. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
  1909. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
  1910. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1911. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1912. }
  1913. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1914. if ((word & 0x00ff) == 0x00ff) {
  1915. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1916. rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  1917. LED_MODE_TXRX_ACTIVITY);
  1918. rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  1919. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1920. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
  1921. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
  1922. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
  1923. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1924. }
  1925. /*
  1926. * During the LNA validation we are going to use
  1927. * lna0 as correct value. Note that EEPROM_LNA
  1928. * is never validated.
  1929. */
  1930. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  1931. default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  1932. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  1933. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  1934. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  1935. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  1936. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  1937. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  1938. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  1939. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  1940. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  1941. if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  1942. rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  1943. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  1944. default_lna_gain);
  1945. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  1946. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  1947. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  1948. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  1949. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  1950. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  1951. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  1952. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  1953. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  1954. rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  1955. if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  1956. rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  1957. rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  1958. default_lna_gain);
  1959. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  1960. return 0;
  1961. }
  1962. static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1963. {
  1964. u32 reg;
  1965. u16 value;
  1966. u16 eeprom;
  1967. /*
  1968. * Read EEPROM word for configuration.
  1969. */
  1970. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1971. /*
  1972. * Identify RF chipset.
  1973. */
  1974. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1975. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1976. rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
  1977. /*
  1978. * The check for rt2860 is not a typo, some rt2870 hardware
  1979. * identifies itself as rt2860 in the CSR register.
  1980. */
  1981. if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
  1982. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
  1983. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
  1984. !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
  1985. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1986. return -ENODEV;
  1987. }
  1988. if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
  1989. !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
  1990. !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
  1991. !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
  1992. !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
  1993. !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  1994. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1995. return -ENODEV;
  1996. }
  1997. /*
  1998. * Identify default antenna configuration.
  1999. */
  2000. rt2x00dev->default_ant.tx =
  2001. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
  2002. rt2x00dev->default_ant.rx =
  2003. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
  2004. /*
  2005. * Read frequency offset and RF programming sequence.
  2006. */
  2007. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  2008. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  2009. /*
  2010. * Read external LNA informations.
  2011. */
  2012. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  2013. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  2014. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  2015. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  2016. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  2017. /*
  2018. * Detect if this device has an hardware controlled radio.
  2019. */
  2020. if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
  2021. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  2022. /*
  2023. * Store led settings, for correct led behaviour.
  2024. */
  2025. #ifdef CONFIG_RT2X00_LIB_LEDS
  2026. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  2027. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  2028. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  2029. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
  2030. &rt2x00dev->led_mcu_reg);
  2031. #endif /* CONFIG_RT2X00_LIB_LEDS */
  2032. return 0;
  2033. }
  2034. /*
  2035. * RF value list for rt2870
  2036. * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  2037. */
  2038. static const struct rf_channel rf_vals[] = {
  2039. { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  2040. { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  2041. { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  2042. { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  2043. { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  2044. { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  2045. { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  2046. { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  2047. { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  2048. { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  2049. { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  2050. { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  2051. { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  2052. { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  2053. /* 802.11 UNI / HyperLan 2 */
  2054. { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  2055. { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  2056. { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  2057. { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  2058. { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  2059. { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  2060. { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  2061. { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  2062. { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  2063. { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  2064. { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  2065. { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  2066. /* 802.11 HyperLan 2 */
  2067. { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  2068. { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  2069. { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
  2070. { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
  2071. { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  2072. { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  2073. { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  2074. { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  2075. { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  2076. { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  2077. { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  2078. { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  2079. { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  2080. { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  2081. { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  2082. { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  2083. /* 802.11 UNII */
  2084. { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  2085. { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  2086. { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  2087. { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  2088. { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  2089. { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  2090. { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  2091. { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
  2092. { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
  2093. { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
  2094. { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
  2095. /* 802.11 Japan */
  2096. { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  2097. { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  2098. { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  2099. { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  2100. { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  2101. { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  2102. { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  2103. };
  2104. /*
  2105. * RF value list for rt3070
  2106. * Supports: 2.4 GHz
  2107. */
  2108. static const struct rf_channel rf_vals_3070[] = {
  2109. {1, 241, 2, 2 },
  2110. {2, 241, 2, 7 },
  2111. {3, 242, 2, 2 },
  2112. {4, 242, 2, 7 },
  2113. {5, 243, 2, 2 },
  2114. {6, 243, 2, 7 },
  2115. {7, 244, 2, 2 },
  2116. {8, 244, 2, 7 },
  2117. {9, 245, 2, 2 },
  2118. {10, 245, 2, 7 },
  2119. {11, 246, 2, 2 },
  2120. {12, 246, 2, 7 },
  2121. {13, 247, 2, 2 },
  2122. {14, 248, 2, 4 },
  2123. };
  2124. static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  2125. {
  2126. struct hw_mode_spec *spec = &rt2x00dev->spec;
  2127. struct channel_info *info;
  2128. char *tx_power1;
  2129. char *tx_power2;
  2130. unsigned int i;
  2131. u16 eeprom;
  2132. /*
  2133. * Initialize all hw fields.
  2134. */
  2135. rt2x00dev->hw->flags =
  2136. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  2137. IEEE80211_HW_SIGNAL_DBM |
  2138. IEEE80211_HW_SUPPORTS_PS |
  2139. IEEE80211_HW_PS_NULLFUNC_STACK;
  2140. rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
  2141. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  2142. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  2143. rt2x00_eeprom_addr(rt2x00dev,
  2144. EEPROM_MAC_ADDR_0));
  2145. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2146. /*
  2147. * Initialize HT information.
  2148. */
  2149. spec->ht.ht_supported = true;
  2150. spec->ht.cap =
  2151. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  2152. IEEE80211_HT_CAP_GRN_FLD |
  2153. IEEE80211_HT_CAP_SGI_20 |
  2154. IEEE80211_HT_CAP_SGI_40 |
  2155. IEEE80211_HT_CAP_TX_STBC |
  2156. IEEE80211_HT_CAP_RX_STBC |
  2157. IEEE80211_HT_CAP_PSMP_SUPPORT;
  2158. spec->ht.ampdu_factor = 3;
  2159. spec->ht.ampdu_density = 4;
  2160. spec->ht.mcs.tx_params =
  2161. IEEE80211_HT_MCS_TX_DEFINED |
  2162. IEEE80211_HT_MCS_TX_RX_DIFF |
  2163. ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
  2164. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  2165. switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  2166. case 3:
  2167. spec->ht.mcs.rx_mask[2] = 0xff;
  2168. case 2:
  2169. spec->ht.mcs.rx_mask[1] = 0xff;
  2170. case 1:
  2171. spec->ht.mcs.rx_mask[0] = 0xff;
  2172. spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  2173. break;
  2174. }
  2175. /*
  2176. * Initialize hw_mode information.
  2177. */
  2178. spec->supported_bands = SUPPORT_BAND_2GHZ;
  2179. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  2180. if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
  2181. rt2x00_rf(&rt2x00dev->chip, RF2720)) {
  2182. spec->num_channels = 14;
  2183. spec->channels = rf_vals;
  2184. } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
  2185. rt2x00_rf(&rt2x00dev->chip, RF2750)) {
  2186. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  2187. spec->num_channels = ARRAY_SIZE(rf_vals);
  2188. spec->channels = rf_vals;
  2189. } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
  2190. rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2191. spec->num_channels = ARRAY_SIZE(rf_vals_3070);
  2192. spec->channels = rf_vals_3070;
  2193. }
  2194. /*
  2195. * Create channel information array
  2196. */
  2197. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  2198. if (!info)
  2199. return -ENOMEM;
  2200. spec->channels_info = info;
  2201. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  2202. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  2203. for (i = 0; i < 14; i++) {
  2204. info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
  2205. info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
  2206. }
  2207. if (spec->num_channels > 14) {
  2208. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  2209. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  2210. for (i = 14; i < spec->num_channels; i++) {
  2211. info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
  2212. info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
  2213. }
  2214. }
  2215. return 0;
  2216. }
  2217. static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  2218. {
  2219. int retval;
  2220. /*
  2221. * Allocate eeprom data.
  2222. */
  2223. retval = rt2800usb_validate_eeprom(rt2x00dev);
  2224. if (retval)
  2225. return retval;
  2226. retval = rt2800usb_init_eeprom(rt2x00dev);
  2227. if (retval)
  2228. return retval;
  2229. /*
  2230. * Initialize hw specifications.
  2231. */
  2232. retval = rt2800usb_probe_hw_mode(rt2x00dev);
  2233. if (retval)
  2234. return retval;
  2235. /*
  2236. * This device has multiple filters for control frames
  2237. * and has a separate filter for PS Poll frames.
  2238. */
  2239. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  2240. __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
  2241. /*
  2242. * This device requires firmware.
  2243. */
  2244. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2245. __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
  2246. if (!modparam_nohwcrypt)
  2247. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  2248. /*
  2249. * Set the rssi offset.
  2250. */
  2251. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2252. return 0;
  2253. }
  2254. /*
  2255. * IEEE80211 stack callback functions.
  2256. */
  2257. static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
  2258. u32 *iv32, u16 *iv16)
  2259. {
  2260. struct rt2x00_dev *rt2x00dev = hw->priv;
  2261. struct mac_iveiv_entry iveiv_entry;
  2262. u32 offset;
  2263. offset = MAC_IVEIV_ENTRY(hw_key_idx);
  2264. rt2800_register_multiread(rt2x00dev, offset,
  2265. &iveiv_entry, sizeof(iveiv_entry));
  2266. memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
  2267. memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
  2268. }
  2269. static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2270. {
  2271. struct rt2x00_dev *rt2x00dev = hw->priv;
  2272. u32 reg;
  2273. bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  2274. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  2275. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  2276. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  2277. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  2278. rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  2279. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  2280. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  2281. rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  2282. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  2283. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  2284. rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  2285. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  2286. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  2287. rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  2288. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  2289. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  2290. rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  2291. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  2292. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  2293. rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  2294. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  2295. return 0;
  2296. }
  2297. static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  2298. const struct ieee80211_tx_queue_params *params)
  2299. {
  2300. struct rt2x00_dev *rt2x00dev = hw->priv;
  2301. struct data_queue *queue;
  2302. struct rt2x00_field32 field;
  2303. int retval;
  2304. u32 reg;
  2305. u32 offset;
  2306. /*
  2307. * First pass the configuration through rt2x00lib, that will
  2308. * update the queue settings and validate the input. After that
  2309. * we are free to update the registers based on the value
  2310. * in the queue parameter.
  2311. */
  2312. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  2313. if (retval)
  2314. return retval;
  2315. /*
  2316. * We only need to perform additional register initialization
  2317. * for WMM queues/
  2318. */
  2319. if (queue_idx >= 4)
  2320. return 0;
  2321. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  2322. /* Update WMM TXOP register */
  2323. offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  2324. field.bit_offset = (queue_idx & 1) * 16;
  2325. field.bit_mask = 0xffff << field.bit_offset;
  2326. rt2800_register_read(rt2x00dev, offset, &reg);
  2327. rt2x00_set_field32(&reg, field, queue->txop);
  2328. rt2800_register_write(rt2x00dev, offset, reg);
  2329. /* Update WMM registers */
  2330. field.bit_offset = queue_idx * 4;
  2331. field.bit_mask = 0xf << field.bit_offset;
  2332. rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  2333. rt2x00_set_field32(&reg, field, queue->aifs);
  2334. rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  2335. rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  2336. rt2x00_set_field32(&reg, field, queue->cw_min);
  2337. rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  2338. rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  2339. rt2x00_set_field32(&reg, field, queue->cw_max);
  2340. rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  2341. /* Update EDCA registers */
  2342. offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  2343. rt2800_register_read(rt2x00dev, offset, &reg);
  2344. rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  2345. rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  2346. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  2347. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  2348. rt2800_register_write(rt2x00dev, offset, reg);
  2349. return 0;
  2350. }
  2351. static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
  2352. {
  2353. struct rt2x00_dev *rt2x00dev = hw->priv;
  2354. u64 tsf;
  2355. u32 reg;
  2356. rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  2357. tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  2358. rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  2359. tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  2360. return tsf;
  2361. }
  2362. static const struct ieee80211_ops rt2800usb_mac80211_ops = {
  2363. .tx = rt2x00mac_tx,
  2364. .start = rt2x00mac_start,
  2365. .stop = rt2x00mac_stop,
  2366. .add_interface = rt2x00mac_add_interface,
  2367. .remove_interface = rt2x00mac_remove_interface,
  2368. .config = rt2x00mac_config,
  2369. .configure_filter = rt2x00mac_configure_filter,
  2370. .set_tim = rt2x00mac_set_tim,
  2371. .set_key = rt2x00mac_set_key,
  2372. .get_stats = rt2x00mac_get_stats,
  2373. .get_tkip_seq = rt2800usb_get_tkip_seq,
  2374. .set_rts_threshold = rt2800usb_set_rts_threshold,
  2375. .bss_info_changed = rt2x00mac_bss_info_changed,
  2376. .conf_tx = rt2800usb_conf_tx,
  2377. .get_tx_stats = rt2x00mac_get_tx_stats,
  2378. .get_tsf = rt2800usb_get_tsf,
  2379. .rfkill_poll = rt2x00mac_rfkill_poll,
  2380. };
  2381. static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
  2382. .probe_hw = rt2800usb_probe_hw,
  2383. .get_firmware_name = rt2800usb_get_firmware_name,
  2384. .check_firmware = rt2800usb_check_firmware,
  2385. .load_firmware = rt2800usb_load_firmware,
  2386. .initialize = rt2x00usb_initialize,
  2387. .uninitialize = rt2x00usb_uninitialize,
  2388. .clear_entry = rt2x00usb_clear_entry,
  2389. .set_device_state = rt2800usb_set_device_state,
  2390. .rfkill_poll = rt2800usb_rfkill_poll,
  2391. .link_stats = rt2800usb_link_stats,
  2392. .reset_tuner = rt2800usb_reset_tuner,
  2393. .link_tuner = rt2800usb_link_tuner,
  2394. .write_tx_desc = rt2800usb_write_tx_desc,
  2395. .write_tx_data = rt2x00usb_write_tx_data,
  2396. .write_beacon = rt2800usb_write_beacon,
  2397. .get_tx_data_len = rt2800usb_get_tx_data_len,
  2398. .kick_tx_queue = rt2800usb_kick_tx_queue,
  2399. .kill_tx_queue = rt2x00usb_kill_tx_queue,
  2400. .fill_rxdone = rt2800usb_fill_rxdone,
  2401. .config_shared_key = rt2800usb_config_shared_key,
  2402. .config_pairwise_key = rt2800usb_config_pairwise_key,
  2403. .config_filter = rt2800usb_config_filter,
  2404. .config_intf = rt2800usb_config_intf,
  2405. .config_erp = rt2800usb_config_erp,
  2406. .config_ant = rt2800usb_config_ant,
  2407. .config = rt2800usb_config,
  2408. };
  2409. static const struct data_queue_desc rt2800usb_queue_rx = {
  2410. .entry_num = RX_ENTRIES,
  2411. .data_size = AGGREGATION_SIZE,
  2412. .desc_size = RXD_DESC_SIZE + RXWI_DESC_SIZE,
  2413. .priv_size = sizeof(struct queue_entry_priv_usb),
  2414. };
  2415. static const struct data_queue_desc rt2800usb_queue_tx = {
  2416. .entry_num = TX_ENTRIES,
  2417. .data_size = AGGREGATION_SIZE,
  2418. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2419. .priv_size = sizeof(struct queue_entry_priv_usb),
  2420. };
  2421. static const struct data_queue_desc rt2800usb_queue_bcn = {
  2422. .entry_num = 8 * BEACON_ENTRIES,
  2423. .data_size = MGMT_FRAME_SIZE,
  2424. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2425. .priv_size = sizeof(struct queue_entry_priv_usb),
  2426. };
  2427. static const struct rt2x00_ops rt2800usb_ops = {
  2428. .name = KBUILD_MODNAME,
  2429. .max_sta_intf = 1,
  2430. .max_ap_intf = 8,
  2431. .eeprom_size = EEPROM_SIZE,
  2432. .rf_size = RF_SIZE,
  2433. .tx_queues = NUM_TX_QUEUES,
  2434. .rx = &rt2800usb_queue_rx,
  2435. .tx = &rt2800usb_queue_tx,
  2436. .bcn = &rt2800usb_queue_bcn,
  2437. .lib = &rt2800usb_rt2x00_ops,
  2438. .hw = &rt2800usb_mac80211_ops,
  2439. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2440. .debugfs = &rt2800usb_rt2x00debug,
  2441. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2442. };
  2443. /*
  2444. * rt2800usb module information.
  2445. */
  2446. static struct usb_device_id rt2800usb_device_table[] = {
  2447. /* Abocom */
  2448. { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2449. { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2450. { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2451. { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2452. { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2453. { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2454. /* AirTies */
  2455. { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
  2456. /* Amigo */
  2457. { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2458. { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
  2459. /* Amit */
  2460. { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2461. /* ASUS */
  2462. { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
  2463. { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
  2464. { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
  2465. { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
  2466. { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
  2467. /* AzureWave */
  2468. { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
  2469. { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
  2470. { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
  2471. { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
  2472. /* Belkin */
  2473. { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
  2474. { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2475. { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2476. { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2477. /* Buffalo */
  2478. { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
  2479. { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2480. /* Conceptronic */
  2481. { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2482. { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
  2483. { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
  2484. { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2485. { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2486. { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
  2487. { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
  2488. { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2489. { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
  2490. { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
  2491. /* Corega */
  2492. { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2493. { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2494. { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2495. { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2496. { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
  2497. /* D-Link */
  2498. { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2499. { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2500. { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2501. { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2502. { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2503. { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2504. { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2505. { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
  2506. /* Edimax */
  2507. { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
  2508. { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
  2509. { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
  2510. /* Encore */
  2511. { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
  2512. /* EnGenius */
  2513. { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
  2514. { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
  2515. { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
  2516. { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
  2517. { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
  2518. { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
  2519. /* Gemtek */
  2520. { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
  2521. /* Gigabyte */
  2522. { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2523. { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2524. { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2525. /* Hawking */
  2526. { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
  2527. { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
  2528. { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
  2529. { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2530. /* I-O DATA */
  2531. { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
  2532. /* LevelOne */
  2533. { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
  2534. { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
  2535. /* Linksys */
  2536. { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2537. { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2538. { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
  2539. /* Logitec */
  2540. { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
  2541. { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
  2542. { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
  2543. /* Motorola */
  2544. { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2545. { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
  2546. /* Ovislink */
  2547. { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2548. /* Pegatron */
  2549. { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
  2550. { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2551. { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2552. /* Philips */
  2553. { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2554. /* Planex */
  2555. { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2556. { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
  2557. { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2558. /* Qcom */
  2559. { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
  2560. /* Quanta */
  2561. { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
  2562. /* Ralink */
  2563. { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
  2564. { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
  2565. { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2566. { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2567. { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2568. { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2569. { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2570. { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2571. { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
  2572. /* Samsung */
  2573. { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
  2574. /* Siemens */
  2575. { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
  2576. /* Sitecom */
  2577. { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
  2578. { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2579. { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2580. { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2581. { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
  2582. { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2583. { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2584. { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2585. { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2586. { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2587. { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
  2588. { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
  2589. /* SMC */
  2590. { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2591. { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
  2592. { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2593. { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2594. { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2595. { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2596. { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2597. { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2598. { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2599. /* Sparklan */
  2600. { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
  2601. /* Sweex */
  2602. { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
  2603. { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
  2604. { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
  2605. /* U-Media*/
  2606. { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2607. /* ZCOM */
  2608. { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
  2609. { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
  2610. /* Zinwell */
  2611. { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
  2612. { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
  2613. { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
  2614. { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
  2615. /* Zyxel */
  2616. { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
  2617. { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2618. { 0, }
  2619. };
  2620. MODULE_AUTHOR(DRV_PROJECT);
  2621. MODULE_VERSION(DRV_VERSION);
  2622. MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
  2623. MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
  2624. MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
  2625. MODULE_FIRMWARE(FIRMWARE_RT2870);
  2626. MODULE_LICENSE("GPL");
  2627. static struct usb_driver rt2800usb_driver = {
  2628. .name = KBUILD_MODNAME,
  2629. .id_table = rt2800usb_device_table,
  2630. .probe = rt2x00usb_probe,
  2631. .disconnect = rt2x00usb_disconnect,
  2632. .suspend = rt2x00usb_suspend,
  2633. .resume = rt2x00usb_resume,
  2634. };
  2635. static int __init rt2800usb_init(void)
  2636. {
  2637. return usb_register(&rt2800usb_driver);
  2638. }
  2639. static void __exit rt2800usb_exit(void)
  2640. {
  2641. usb_deregister(&rt2800usb_driver);
  2642. }
  2643. module_init(rt2800usb_init);
  2644. module_exit(rt2800usb_exit);