rt2800usb.c 101 KB

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