rt2800usb.c 102 KB

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