rt2800usb.c 101 KB

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