rt2800usb.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119
  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_rev(&rt2x00dev->chip) == RT3070_VERSION)
  893. return 0x1c + (2 * rt2x00dev->lna_gain);
  894. else
  895. return 0x2e + rt2x00dev->lna_gain;
  896. }
  897. if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  898. return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
  899. else
  900. return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
  901. }
  902. static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  903. struct link_qual *qual, u8 vgc_level)
  904. {
  905. if (qual->vgc_level != vgc_level) {
  906. rt2800_bbp_write(rt2x00dev, 66, vgc_level);
  907. qual->vgc_level = vgc_level;
  908. qual->vgc_level_reg = vgc_level;
  909. }
  910. }
  911. static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  912. struct link_qual *qual)
  913. {
  914. rt2800usb_set_vgc(rt2x00dev, qual,
  915. rt2800usb_get_default_vgc(rt2x00dev));
  916. }
  917. static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  918. struct link_qual *qual, const u32 count)
  919. {
  920. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
  921. return;
  922. /*
  923. * When RSSI is better then -80 increase VGC level with 0x10
  924. */
  925. rt2800usb_set_vgc(rt2x00dev, qual,
  926. rt2800usb_get_default_vgc(rt2x00dev) +
  927. ((qual->rssi > -80) * 0x10));
  928. }
  929. /*
  930. * Firmware functions
  931. */
  932. static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  933. {
  934. return FIRMWARE_RT2870;
  935. }
  936. static bool rt2800usb_check_crc(const u8 *data, const size_t len)
  937. {
  938. u16 fw_crc;
  939. u16 crc;
  940. /*
  941. * The last 2 bytes in the firmware array are the crc checksum itself,
  942. * this means that we should never pass those 2 bytes to the crc
  943. * algorithm.
  944. */
  945. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  946. /*
  947. * Use the crc ccitt algorithm.
  948. * This will return the same value as the legacy driver which
  949. * used bit ordering reversion on the both the firmware bytes
  950. * before input input as well as on the final output.
  951. * Obviously using crc ccitt directly is much more efficient.
  952. */
  953. crc = crc_ccitt(~0, data, len - 2);
  954. /*
  955. * There is a small difference between the crc-itu-t + bitrev and
  956. * the crc-ccitt crc calculation. In the latter method the 2 bytes
  957. * will be swapped, use swab16 to convert the crc to the correct
  958. * value.
  959. */
  960. crc = swab16(crc);
  961. return fw_crc == crc;
  962. }
  963. static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  964. const u8 *data, const size_t len)
  965. {
  966. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  967. size_t offset = 0;
  968. /*
  969. * Firmware files:
  970. * There are 2 variations of the rt2870 firmware.
  971. * a) size: 4kb
  972. * b) size: 8kb
  973. * Note that (b) contains 2 seperate firmware blobs of 4k
  974. * within the file. The first blob is the same firmware as (a),
  975. * but the second blob is for the additional chipsets.
  976. */
  977. if (len != 4096 && len != 8192)
  978. return FW_BAD_LENGTH;
  979. /*
  980. * Check if we need the upper 4kb firmware data or not.
  981. */
  982. if ((len == 4096) &&
  983. (chipset != 0x2860) &&
  984. (chipset != 0x2872) &&
  985. (chipset != 0x3070))
  986. return FW_BAD_VERSION;
  987. /*
  988. * 8kb firmware files must be checked as if it were
  989. * 2 seperate firmware files.
  990. */
  991. while (offset < len) {
  992. if (!rt2800usb_check_crc(data + offset, 4096))
  993. return FW_BAD_CRC;
  994. offset += 4096;
  995. }
  996. return FW_OK;
  997. }
  998. static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  999. const u8 *data, const size_t len)
  1000. {
  1001. unsigned int i;
  1002. int status;
  1003. u32 reg;
  1004. u32 offset;
  1005. u32 length;
  1006. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  1007. /*
  1008. * Check which section of the firmware we need.
  1009. */
  1010. if ((chipset == 0x2860) ||
  1011. (chipset == 0x2872) ||
  1012. (chipset == 0x3070)) {
  1013. offset = 0;
  1014. length = 4096;
  1015. } else {
  1016. offset = 4096;
  1017. length = 4096;
  1018. }
  1019. /*
  1020. * Wait for stable hardware.
  1021. */
  1022. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1023. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1024. if (reg && reg != ~0)
  1025. break;
  1026. msleep(1);
  1027. }
  1028. if (i == REGISTER_BUSY_COUNT) {
  1029. ERROR(rt2x00dev, "Unstable hardware.\n");
  1030. return -EBUSY;
  1031. }
  1032. /*
  1033. * Write firmware to device.
  1034. */
  1035. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1036. USB_VENDOR_REQUEST_OUT,
  1037. FIRMWARE_IMAGE_BASE,
  1038. data + offset, length,
  1039. REGISTER_TIMEOUT32(length));
  1040. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  1041. rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  1042. /*
  1043. * Send firmware request to device to load firmware,
  1044. * we need to specify a long timeout time.
  1045. */
  1046. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  1047. 0, USB_MODE_FIRMWARE,
  1048. REGISTER_TIMEOUT_FIRMWARE);
  1049. if (status < 0) {
  1050. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  1051. return status;
  1052. }
  1053. msleep(10);
  1054. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1055. /*
  1056. * Send signal to firmware during boot time.
  1057. */
  1058. rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  1059. if ((chipset == 0x3070) ||
  1060. (chipset == 0x3071) ||
  1061. (chipset == 0x3572)) {
  1062. udelay(200);
  1063. rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
  1064. udelay(10);
  1065. }
  1066. /*
  1067. * Wait for device to stabilize.
  1068. */
  1069. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1070. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1071. if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  1072. break;
  1073. msleep(1);
  1074. }
  1075. if (i == REGISTER_BUSY_COUNT) {
  1076. ERROR(rt2x00dev, "PBF system register not ready.\n");
  1077. return -EBUSY;
  1078. }
  1079. /*
  1080. * Initialize firmware.
  1081. */
  1082. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1083. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1084. msleep(1);
  1085. return 0;
  1086. }
  1087. /*
  1088. * Initialization functions.
  1089. */
  1090. static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
  1091. {
  1092. u32 reg;
  1093. unsigned int i;
  1094. /*
  1095. * Wait untill BBP and RF are ready.
  1096. */
  1097. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1098. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1099. if (reg && reg != ~0)
  1100. break;
  1101. msleep(1);
  1102. }
  1103. if (i == REGISTER_BUSY_COUNT) {
  1104. ERROR(rt2x00dev, "Unstable hardware.\n");
  1105. return -EBUSY;
  1106. }
  1107. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1108. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
  1109. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1110. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  1111. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  1112. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1113. rt2800_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
  1114. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  1115. USB_MODE_RESET, REGISTER_TIMEOUT);
  1116. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1117. rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  1118. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  1119. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  1120. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  1121. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  1122. rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
  1123. rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  1124. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  1125. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  1126. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  1127. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  1128. rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
  1129. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  1130. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  1131. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1132. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1133. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
  1134. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  1135. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  1136. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  1137. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1138. rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  1139. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1140. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1141. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  1142. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  1143. rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  1144. } else {
  1145. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  1146. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  1147. }
  1148. rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  1149. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  1150. rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  1151. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  1152. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  1153. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  1154. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  1155. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  1156. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  1157. rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
  1158. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  1159. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  1160. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  1161. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  1162. rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  1163. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  1164. if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
  1165. rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
  1166. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  1167. else
  1168. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  1169. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  1170. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  1171. rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  1172. rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  1173. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  1174. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  1175. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  1176. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  1177. rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  1178. rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  1179. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  1180. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  1181. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
  1182. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  1183. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
  1184. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1185. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1186. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1187. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1188. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1189. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1190. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  1191. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  1192. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
  1193. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  1194. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
  1195. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1196. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1197. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1198. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1199. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1200. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1201. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  1202. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  1203. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  1204. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  1205. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
  1206. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1207. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1208. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1209. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1210. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1211. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1212. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  1213. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  1214. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  1215. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  1216. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
  1217. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1218. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1219. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1220. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1221. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1222. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1223. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  1224. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  1225. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  1226. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  1227. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
  1228. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1229. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1230. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1231. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1232. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1233. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1234. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  1235. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  1236. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  1237. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  1238. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
  1239. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1240. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1241. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1242. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1243. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1244. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1245. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  1246. rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  1247. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1248. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1249. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  1250. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1251. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  1252. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  1253. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  1254. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  1255. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  1256. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  1257. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1258. rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
  1259. rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
  1260. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  1261. rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  1262. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  1263. IEEE80211_MAX_RTS_THRESHOLD);
  1264. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  1265. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  1266. rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  1267. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  1268. /*
  1269. * ASIC will keep garbage value after boot, clear encryption keys.
  1270. */
  1271. for (i = 0; i < 4; i++)
  1272. rt2800_register_write(rt2x00dev,
  1273. SHARED_KEY_MODE_ENTRY(i), 0);
  1274. for (i = 0; i < 256; i++) {
  1275. u32 wcid[2] = { 0xffffffff, 0x00ffffff };
  1276. rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
  1277. wcid, sizeof(wcid));
  1278. rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
  1279. rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  1280. }
  1281. /*
  1282. * Clear all beacons
  1283. * For the Beacon base registers we only need to clear
  1284. * the first byte since that byte contains the VALID and OWNER
  1285. * bits which (when set to 0) will invalidate the entire beacon.
  1286. */
  1287. rt2800_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1288. rt2800_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1289. rt2800_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1290. rt2800_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1291. rt2800_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
  1292. rt2800_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
  1293. rt2800_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
  1294. rt2800_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
  1295. rt2800_register_read(rt2x00dev, USB_CYC_CFG, &reg);
  1296. rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
  1297. rt2800_register_write(rt2x00dev, USB_CYC_CFG, reg);
  1298. rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  1299. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  1300. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  1301. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  1302. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  1303. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  1304. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  1305. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  1306. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  1307. rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  1308. rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  1309. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  1310. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  1311. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  1312. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  1313. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  1314. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  1315. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  1316. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  1317. rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  1318. rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  1319. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  1320. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  1321. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
  1322. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  1323. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  1324. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  1325. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  1326. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  1327. rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  1328. rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  1329. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  1330. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  1331. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  1332. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  1333. rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  1334. /*
  1335. * We must clear the error counters.
  1336. * These registers are cleared on read,
  1337. * so we may pass a useless variable to store the value.
  1338. */
  1339. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  1340. rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  1341. rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  1342. rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  1343. rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  1344. rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  1345. return 0;
  1346. }
  1347. static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  1348. {
  1349. unsigned int i;
  1350. u32 reg;
  1351. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1352. rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  1353. if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  1354. return 0;
  1355. udelay(REGISTER_BUSY_DELAY);
  1356. }
  1357. ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
  1358. return -EACCES;
  1359. }
  1360. static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1361. {
  1362. unsigned int i;
  1363. u8 value;
  1364. /*
  1365. * BBP was enabled after firmware was loaded,
  1366. * but we need to reactivate it now.
  1367. */
  1368. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1369. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1370. msleep(1);
  1371. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1372. rt2800_bbp_read(rt2x00dev, 0, &value);
  1373. if ((value != 0xff) && (value != 0x00))
  1374. return 0;
  1375. udelay(REGISTER_BUSY_DELAY);
  1376. }
  1377. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1378. return -EACCES;
  1379. }
  1380. static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1381. {
  1382. unsigned int i;
  1383. u16 eeprom;
  1384. u8 reg_id;
  1385. u8 value;
  1386. if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
  1387. rt2800usb_wait_bbp_ready(rt2x00dev)))
  1388. return -EACCES;
  1389. rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  1390. rt2800_bbp_write(rt2x00dev, 66, 0x38);
  1391. rt2800_bbp_write(rt2x00dev, 69, 0x12);
  1392. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  1393. rt2800_bbp_write(rt2x00dev, 73, 0x10);
  1394. rt2800_bbp_write(rt2x00dev, 81, 0x37);
  1395. rt2800_bbp_write(rt2x00dev, 82, 0x62);
  1396. rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  1397. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  1398. rt2800_bbp_write(rt2x00dev, 86, 0x00);
  1399. rt2800_bbp_write(rt2x00dev, 91, 0x04);
  1400. rt2800_bbp_write(rt2x00dev, 92, 0x00);
  1401. rt2800_bbp_write(rt2x00dev, 103, 0x00);
  1402. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  1403. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  1404. rt2800_bbp_write(rt2x00dev, 69, 0x16);
  1405. rt2800_bbp_write(rt2x00dev, 73, 0x12);
  1406. }
  1407. if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
  1408. rt2800_bbp_write(rt2x00dev, 84, 0x19);
  1409. }
  1410. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1411. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  1412. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  1413. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  1414. }
  1415. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1416. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1417. if (eeprom != 0xffff && eeprom != 0x0000) {
  1418. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1419. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1420. rt2800_bbp_write(rt2x00dev, reg_id, value);
  1421. }
  1422. }
  1423. return 0;
  1424. }
  1425. static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
  1426. bool bw40, u8 rfcsr24, u8 filter_target)
  1427. {
  1428. unsigned int i;
  1429. u8 bbp;
  1430. u8 rfcsr;
  1431. u8 passband;
  1432. u8 stopband;
  1433. u8 overtuned = 0;
  1434. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1435. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  1436. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  1437. rt2800_bbp_write(rt2x00dev, 4, bbp);
  1438. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1439. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  1440. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  1441. /*
  1442. * Set power & frequency of passband test tone
  1443. */
  1444. rt2800_bbp_write(rt2x00dev, 24, 0);
  1445. for (i = 0; i < 100; i++) {
  1446. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  1447. msleep(1);
  1448. rt2800_bbp_read(rt2x00dev, 55, &passband);
  1449. if (passband)
  1450. break;
  1451. }
  1452. /*
  1453. * Set power & frequency of stopband test tone
  1454. */
  1455. rt2800_bbp_write(rt2x00dev, 24, 0x06);
  1456. for (i = 0; i < 100; i++) {
  1457. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  1458. msleep(1);
  1459. rt2800_bbp_read(rt2x00dev, 55, &stopband);
  1460. if ((passband - stopband) <= filter_target) {
  1461. rfcsr24++;
  1462. overtuned += ((passband - stopband) == filter_target);
  1463. } else
  1464. break;
  1465. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1466. }
  1467. rfcsr24 -= !!overtuned;
  1468. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1469. return rfcsr24;
  1470. }
  1471. static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  1472. {
  1473. u8 rfcsr;
  1474. u8 bbp;
  1475. if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  1476. return 0;
  1477. /*
  1478. * Init RF calibration.
  1479. */
  1480. rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  1481. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  1482. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  1483. msleep(1);
  1484. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  1485. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  1486. rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  1487. rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
  1488. rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
  1489. rt2800_rfcsr_write(rt2x00dev, 7, 0x70);
  1490. rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
  1491. rt2800_rfcsr_write(rt2x00dev, 10, 0x71);
  1492. rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  1493. rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
  1494. rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  1495. rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
  1496. rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
  1497. rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
  1498. rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
  1499. rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  1500. rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
  1501. rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
  1502. rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
  1503. rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  1504. rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  1505. rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
  1506. /*
  1507. * Set RX Filter calibration for 20MHz and 40MHz
  1508. */
  1509. rt2x00dev->calibration[0] =
  1510. rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
  1511. rt2x00dev->calibration[1] =
  1512. rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
  1513. /*
  1514. * Set back to initial state
  1515. */
  1516. rt2800_bbp_write(rt2x00dev, 24, 0);
  1517. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1518. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  1519. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  1520. /*
  1521. * set BBP back to BW20
  1522. */
  1523. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  1524. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  1525. rt2800_bbp_write(rt2x00dev, 4, bbp);
  1526. return 0;
  1527. }
  1528. /*
  1529. * Device state switch handlers.
  1530. */
  1531. static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1532. enum dev_state state)
  1533. {
  1534. u32 reg;
  1535. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1536. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  1537. (state == STATE_RADIO_RX_ON) ||
  1538. (state == STATE_RADIO_RX_ON_LINK));
  1539. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1540. }
  1541. static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  1542. {
  1543. unsigned int i;
  1544. u32 reg;
  1545. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1546. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1547. if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  1548. !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  1549. return 0;
  1550. msleep(1);
  1551. }
  1552. ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
  1553. return -EACCES;
  1554. }
  1555. static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1556. {
  1557. u32 reg;
  1558. u16 word;
  1559. /*
  1560. * Initialize all registers.
  1561. */
  1562. if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
  1563. rt2800usb_init_registers(rt2x00dev) ||
  1564. rt2800usb_init_bbp(rt2x00dev) ||
  1565. rt2800usb_init_rfcsr(rt2x00dev)))
  1566. return -EIO;
  1567. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1568. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1569. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1570. udelay(50);
  1571. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1572. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  1573. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  1574. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  1575. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1576. rt2800_register_read(rt2x00dev, USB_DMA_CFG, &reg);
  1577. rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
  1578. /* Don't use bulk in aggregation when working with USB 1.1 */
  1579. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
  1580. (rt2x00dev->rx->usb_maxpacket == 512));
  1581. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
  1582. /*
  1583. * Total room for RX frames in kilobytes, PBF might still exceed
  1584. * this limit so reduce the number to prevent errors.
  1585. */
  1586. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
  1587. ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
  1588. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
  1589. rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
  1590. rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
  1591. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1592. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1593. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  1594. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1595. /*
  1596. * Initialize LED control
  1597. */
  1598. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  1599. rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  1600. word & 0xff, (word >> 8) & 0xff);
  1601. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  1602. rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  1603. word & 0xff, (word >> 8) & 0xff);
  1604. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  1605. rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  1606. word & 0xff, (word >> 8) & 0xff);
  1607. return 0;
  1608. }
  1609. static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1610. {
  1611. u32 reg;
  1612. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1613. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1614. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1615. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1616. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  1617. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  1618. rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
  1619. /* Wait for DMA, ignore error */
  1620. rt2800usb_wait_wpdma_ready(rt2x00dev);
  1621. rt2x00usb_disable_radio(rt2x00dev);
  1622. }
  1623. static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
  1624. enum dev_state state)
  1625. {
  1626. if (state == STATE_AWAKE)
  1627. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  1628. else
  1629. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  1630. return 0;
  1631. }
  1632. static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1633. enum dev_state state)
  1634. {
  1635. int retval = 0;
  1636. switch (state) {
  1637. case STATE_RADIO_ON:
  1638. /*
  1639. * Before the radio can be enabled, the device first has
  1640. * to be woken up. After that it needs a bit of time
  1641. * to be fully awake and then the radio can be enabled.
  1642. */
  1643. rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
  1644. msleep(1);
  1645. retval = rt2800usb_enable_radio(rt2x00dev);
  1646. break;
  1647. case STATE_RADIO_OFF:
  1648. /*
  1649. * After the radio has been disabled, the device should
  1650. * be put to sleep for powersaving.
  1651. */
  1652. rt2800usb_disable_radio(rt2x00dev);
  1653. rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
  1654. break;
  1655. case STATE_RADIO_RX_ON:
  1656. case STATE_RADIO_RX_ON_LINK:
  1657. case STATE_RADIO_RX_OFF:
  1658. case STATE_RADIO_RX_OFF_LINK:
  1659. rt2800usb_toggle_rx(rt2x00dev, state);
  1660. break;
  1661. case STATE_RADIO_IRQ_ON:
  1662. case STATE_RADIO_IRQ_OFF:
  1663. /* No support, but no error either */
  1664. break;
  1665. case STATE_DEEP_SLEEP:
  1666. case STATE_SLEEP:
  1667. case STATE_STANDBY:
  1668. case STATE_AWAKE:
  1669. retval = rt2800usb_set_state(rt2x00dev, state);
  1670. break;
  1671. default:
  1672. retval = -ENOTSUPP;
  1673. break;
  1674. }
  1675. if (unlikely(retval))
  1676. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1677. state, retval);
  1678. return retval;
  1679. }
  1680. /*
  1681. * TX descriptor initialization
  1682. */
  1683. static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1684. struct sk_buff *skb,
  1685. struct txentry_desc *txdesc)
  1686. {
  1687. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1688. __le32 *txi = skbdesc->desc;
  1689. __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
  1690. u32 word;
  1691. /*
  1692. * Initialize TX Info descriptor
  1693. */
  1694. rt2x00_desc_read(txwi, 0, &word);
  1695. rt2x00_set_field32(&word, TXWI_W0_FRAG,
  1696. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1697. rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
  1698. rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  1699. rt2x00_set_field32(&word, TXWI_W0_TS,
  1700. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1701. rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  1702. test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  1703. rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
  1704. rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
  1705. rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
  1706. rt2x00_set_field32(&word, TXWI_W0_BW,
  1707. test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  1708. rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  1709. test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  1710. rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
  1711. rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  1712. rt2x00_desc_write(txwi, 0, word);
  1713. rt2x00_desc_read(txwi, 1, &word);
  1714. rt2x00_set_field32(&word, TXWI_W1_ACK,
  1715. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1716. rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  1717. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1718. rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
  1719. rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  1720. test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  1721. txdesc->key_idx : 0xff);
  1722. rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
  1723. skb->len - txdesc->l2pad);
  1724. rt2x00_set_field32(&word, TXWI_W1_PACKETID,
  1725. skbdesc->entry->queue->qid + 1);
  1726. rt2x00_desc_write(txwi, 1, word);
  1727. /*
  1728. * Always write 0 to IV/EIV fields, hardware will insert the IV
  1729. * from the IVEIV register when TXINFO_W0_WIV is set to 0.
  1730. * When TXINFO_W0_WIV is set to 1 it will use the IV data
  1731. * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  1732. * crypto entry in the registers should be used to encrypt the frame.
  1733. */
  1734. _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
  1735. _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
  1736. /*
  1737. * Initialize TX descriptor
  1738. */
  1739. rt2x00_desc_read(txi, 0, &word);
  1740. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
  1741. skb->len + TXWI_DESC_SIZE);
  1742. rt2x00_set_field32(&word, TXINFO_W0_WIV,
  1743. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  1744. rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
  1745. rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
  1746. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
  1747. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
  1748. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1749. rt2x00_desc_write(txi, 0, word);
  1750. }
  1751. /*
  1752. * TX data initialization
  1753. */
  1754. static void rt2800usb_write_beacon(struct queue_entry *entry)
  1755. {
  1756. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1757. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1758. unsigned int beacon_base;
  1759. u32 reg;
  1760. /*
  1761. * Add the descriptor in front of the skb.
  1762. */
  1763. skb_push(entry->skb, entry->queue->desc_size);
  1764. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  1765. skbdesc->desc = entry->skb->data;
  1766. /*
  1767. * Disable beaconing while we are reloading the beacon data,
  1768. * otherwise we might be sending out invalid data.
  1769. */
  1770. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1771. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1772. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1773. /*
  1774. * Write entire beacon with descriptor to register.
  1775. */
  1776. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1777. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1778. USB_VENDOR_REQUEST_OUT, beacon_base,
  1779. entry->skb->data, entry->skb->len,
  1780. REGISTER_TIMEOUT32(entry->skb->len));
  1781. /*
  1782. * Clean up the beacon skb.
  1783. */
  1784. dev_kfree_skb(entry->skb);
  1785. entry->skb = NULL;
  1786. }
  1787. static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
  1788. {
  1789. int length;
  1790. /*
  1791. * The length _must_ include 4 bytes padding,
  1792. * it should always be multiple of 4,
  1793. * but it must _not_ be a multiple of the USB packet size.
  1794. */
  1795. length = roundup(entry->skb->len + 4, 4);
  1796. length += (4 * !(length % entry->queue->usb_maxpacket));
  1797. return length;
  1798. }
  1799. static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1800. const enum data_queue_qid queue)
  1801. {
  1802. u32 reg;
  1803. if (queue != QID_BEACON) {
  1804. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  1805. return;
  1806. }
  1807. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1808. if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  1809. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  1810. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  1811. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  1812. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1813. }
  1814. }
  1815. /*
  1816. * RX control handlers
  1817. */
  1818. static void rt2800usb_fill_rxdone(struct queue_entry *entry,
  1819. struct rxdone_entry_desc *rxdesc)
  1820. {
  1821. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1822. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1823. __le32 *rxd = (__le32 *)entry->skb->data;
  1824. __le32 *rxwi;
  1825. u32 rxd0;
  1826. u32 rxwi0;
  1827. u32 rxwi1;
  1828. u32 rxwi2;
  1829. u32 rxwi3;
  1830. /*
  1831. * Copy descriptor to the skbdesc->desc buffer, making it safe from
  1832. * moving of frame data in rt2x00usb.
  1833. */
  1834. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1835. rxd = (__le32 *)skbdesc->desc;
  1836. rxwi = &rxd[RXINFO_DESC_SIZE / sizeof(__le32)];
  1837. /*
  1838. * It is now safe to read the descriptor on all architectures.
  1839. */
  1840. rt2x00_desc_read(rxd, 0, &rxd0);
  1841. rt2x00_desc_read(rxwi, 0, &rxwi0);
  1842. rt2x00_desc_read(rxwi, 1, &rxwi1);
  1843. rt2x00_desc_read(rxwi, 2, &rxwi2);
  1844. rt2x00_desc_read(rxwi, 3, &rxwi3);
  1845. if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
  1846. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1847. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1848. rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
  1849. rxdesc->cipher_status =
  1850. rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
  1851. }
  1852. if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
  1853. /*
  1854. * Hardware has stripped IV/EIV data from 802.11 frame during
  1855. * decryption. Unfortunately the descriptor doesn't contain
  1856. * any fields with the EIV/IV data either, so they can't
  1857. * be restored by rt2x00lib.
  1858. */
  1859. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1860. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1861. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1862. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1863. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1864. }
  1865. if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
  1866. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1867. if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD)) {
  1868. rxdesc->dev_flags |= RXDONE_L2PAD;
  1869. skbdesc->flags |= SKBDESC_L2_PADDED;
  1870. }
  1871. if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
  1872. rxdesc->flags |= RX_FLAG_SHORT_GI;
  1873. if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
  1874. rxdesc->flags |= RX_FLAG_40MHZ;
  1875. /*
  1876. * Detect RX rate, always use MCS as signal type.
  1877. */
  1878. rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  1879. rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
  1880. rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
  1881. /*
  1882. * Mask of 0x8 bit to remove the short preamble flag.
  1883. */
  1884. if (rxdesc->rate_mode == RATE_MODE_CCK)
  1885. rxdesc->signal &= ~0x8;
  1886. rxdesc->rssi =
  1887. (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
  1888. rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
  1889. rxdesc->noise =
  1890. (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
  1891. rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
  1892. rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  1893. /*
  1894. * Remove RXWI descriptor from start of buffer.
  1895. */
  1896. skb_pull(entry->skb, skbdesc->desc_len);
  1897. skb_trim(entry->skb, rxdesc->size);
  1898. }
  1899. /*
  1900. * Device probe functions.
  1901. */
  1902. static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1903. {
  1904. u16 word;
  1905. u8 *mac;
  1906. u8 default_lna_gain;
  1907. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1908. /*
  1909. * Start validation of the data that has been read.
  1910. */
  1911. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1912. if (!is_valid_ether_addr(mac)) {
  1913. random_ether_addr(mac);
  1914. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1915. }
  1916. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1917. if (word == 0xffff) {
  1918. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1919. rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
  1920. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
  1921. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1922. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1923. } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
  1924. /*
  1925. * There is a max of 2 RX streams for RT2870 series
  1926. */
  1927. if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
  1928. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1929. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1930. }
  1931. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1932. if (word == 0xffff) {
  1933. rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
  1934. rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
  1935. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1936. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1937. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1938. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
  1939. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
  1940. rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
  1941. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
  1942. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
  1943. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1944. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1945. }
  1946. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1947. if ((word & 0x00ff) == 0x00ff) {
  1948. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1949. rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  1950. LED_MODE_TXRX_ACTIVITY);
  1951. rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  1952. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1953. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
  1954. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
  1955. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
  1956. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1957. }
  1958. /*
  1959. * During the LNA validation we are going to use
  1960. * lna0 as correct value. Note that EEPROM_LNA
  1961. * is never validated.
  1962. */
  1963. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  1964. default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  1965. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  1966. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  1967. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  1968. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  1969. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  1970. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  1971. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  1972. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  1973. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  1974. if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  1975. rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  1976. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  1977. default_lna_gain);
  1978. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  1979. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  1980. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  1981. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  1982. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  1983. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  1984. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  1985. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  1986. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  1987. rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  1988. if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  1989. rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  1990. rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  1991. default_lna_gain);
  1992. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  1993. return 0;
  1994. }
  1995. static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1996. {
  1997. u32 reg;
  1998. u16 value;
  1999. u16 eeprom;
  2000. /*
  2001. * Read EEPROM word for configuration.
  2002. */
  2003. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2004. /*
  2005. * Identify RF chipset.
  2006. */
  2007. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  2008. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  2009. rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
  2010. /*
  2011. * The check for rt2860 is not a typo, some rt2870 hardware
  2012. * identifies itself as rt2860 in the CSR register.
  2013. */
  2014. if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
  2015. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
  2016. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
  2017. !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
  2018. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  2019. return -ENODEV;
  2020. }
  2021. if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
  2022. !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
  2023. !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
  2024. !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
  2025. !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
  2026. !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2027. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  2028. return -ENODEV;
  2029. }
  2030. /*
  2031. * Identify default antenna configuration.
  2032. */
  2033. rt2x00dev->default_ant.tx =
  2034. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
  2035. rt2x00dev->default_ant.rx =
  2036. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
  2037. /*
  2038. * Read frequency offset and RF programming sequence.
  2039. */
  2040. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  2041. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  2042. /*
  2043. * Read external LNA informations.
  2044. */
  2045. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  2046. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  2047. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  2048. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  2049. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  2050. /*
  2051. * Detect if this device has an hardware controlled radio.
  2052. */
  2053. if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
  2054. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  2055. /*
  2056. * Store led settings, for correct led behaviour.
  2057. */
  2058. #ifdef CONFIG_RT2X00_LIB_LEDS
  2059. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  2060. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  2061. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  2062. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
  2063. &rt2x00dev->led_mcu_reg);
  2064. #endif /* CONFIG_RT2X00_LIB_LEDS */
  2065. return 0;
  2066. }
  2067. /*
  2068. * RF value list for rt2870
  2069. * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  2070. */
  2071. static const struct rf_channel rf_vals[] = {
  2072. { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  2073. { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  2074. { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  2075. { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  2076. { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  2077. { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  2078. { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  2079. { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  2080. { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  2081. { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  2082. { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  2083. { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  2084. { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  2085. { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  2086. /* 802.11 UNI / HyperLan 2 */
  2087. { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  2088. { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  2089. { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  2090. { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  2091. { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  2092. { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  2093. { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  2094. { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  2095. { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  2096. { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  2097. { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  2098. { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  2099. /* 802.11 HyperLan 2 */
  2100. { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  2101. { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  2102. { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
  2103. { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
  2104. { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  2105. { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  2106. { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  2107. { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  2108. { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  2109. { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  2110. { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  2111. { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  2112. { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  2113. { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  2114. { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  2115. { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  2116. /* 802.11 UNII */
  2117. { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  2118. { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  2119. { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  2120. { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  2121. { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  2122. { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  2123. { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  2124. { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
  2125. { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
  2126. { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
  2127. { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
  2128. /* 802.11 Japan */
  2129. { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  2130. { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  2131. { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  2132. { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  2133. { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  2134. { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  2135. { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  2136. };
  2137. /*
  2138. * RF value list for rt3070
  2139. * Supports: 2.4 GHz
  2140. */
  2141. static const struct rf_channel rf_vals_3070[] = {
  2142. {1, 241, 2, 2 },
  2143. {2, 241, 2, 7 },
  2144. {3, 242, 2, 2 },
  2145. {4, 242, 2, 7 },
  2146. {5, 243, 2, 2 },
  2147. {6, 243, 2, 7 },
  2148. {7, 244, 2, 2 },
  2149. {8, 244, 2, 7 },
  2150. {9, 245, 2, 2 },
  2151. {10, 245, 2, 7 },
  2152. {11, 246, 2, 2 },
  2153. {12, 246, 2, 7 },
  2154. {13, 247, 2, 2 },
  2155. {14, 248, 2, 4 },
  2156. };
  2157. static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  2158. {
  2159. struct hw_mode_spec *spec = &rt2x00dev->spec;
  2160. struct channel_info *info;
  2161. char *tx_power1;
  2162. char *tx_power2;
  2163. unsigned int i;
  2164. u16 eeprom;
  2165. /*
  2166. * Initialize all hw fields.
  2167. */
  2168. rt2x00dev->hw->flags =
  2169. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  2170. IEEE80211_HW_SIGNAL_DBM |
  2171. IEEE80211_HW_SUPPORTS_PS |
  2172. IEEE80211_HW_PS_NULLFUNC_STACK;
  2173. rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
  2174. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  2175. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  2176. rt2x00_eeprom_addr(rt2x00dev,
  2177. EEPROM_MAC_ADDR_0));
  2178. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2179. /*
  2180. * Initialize HT information.
  2181. */
  2182. spec->ht.ht_supported = true;
  2183. spec->ht.cap =
  2184. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  2185. IEEE80211_HT_CAP_GRN_FLD |
  2186. IEEE80211_HT_CAP_SGI_20 |
  2187. IEEE80211_HT_CAP_SGI_40 |
  2188. IEEE80211_HT_CAP_TX_STBC |
  2189. IEEE80211_HT_CAP_RX_STBC |
  2190. IEEE80211_HT_CAP_PSMP_SUPPORT;
  2191. spec->ht.ampdu_factor = 3;
  2192. spec->ht.ampdu_density = 4;
  2193. spec->ht.mcs.tx_params =
  2194. IEEE80211_HT_MCS_TX_DEFINED |
  2195. IEEE80211_HT_MCS_TX_RX_DIFF |
  2196. ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
  2197. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  2198. switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  2199. case 3:
  2200. spec->ht.mcs.rx_mask[2] = 0xff;
  2201. case 2:
  2202. spec->ht.mcs.rx_mask[1] = 0xff;
  2203. case 1:
  2204. spec->ht.mcs.rx_mask[0] = 0xff;
  2205. spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  2206. break;
  2207. }
  2208. /*
  2209. * Initialize hw_mode information.
  2210. */
  2211. spec->supported_bands = SUPPORT_BAND_2GHZ;
  2212. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  2213. if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
  2214. rt2x00_rf(&rt2x00dev->chip, RF2720)) {
  2215. spec->num_channels = 14;
  2216. spec->channels = rf_vals;
  2217. } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
  2218. rt2x00_rf(&rt2x00dev->chip, RF2750)) {
  2219. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  2220. spec->num_channels = ARRAY_SIZE(rf_vals);
  2221. spec->channels = rf_vals;
  2222. } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
  2223. rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2224. spec->num_channels = ARRAY_SIZE(rf_vals_3070);
  2225. spec->channels = rf_vals_3070;
  2226. }
  2227. /*
  2228. * Create channel information array
  2229. */
  2230. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  2231. if (!info)
  2232. return -ENOMEM;
  2233. spec->channels_info = info;
  2234. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  2235. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  2236. for (i = 0; i < 14; i++) {
  2237. info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
  2238. info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
  2239. }
  2240. if (spec->num_channels > 14) {
  2241. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  2242. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  2243. for (i = 14; i < spec->num_channels; i++) {
  2244. info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
  2245. info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
  2246. }
  2247. }
  2248. return 0;
  2249. }
  2250. static const struct rt2800_ops rt2800usb_rt2800_ops = {
  2251. .register_read = rt2x00usb_register_read,
  2252. .register_write = rt2x00usb_register_write,
  2253. .register_write_lock = rt2x00usb_register_write_lock,
  2254. .register_multiread = rt2x00usb_register_multiread,
  2255. .register_multiwrite = rt2x00usb_register_multiwrite,
  2256. .regbusy_read = rt2x00usb_regbusy_read,
  2257. };
  2258. static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  2259. {
  2260. int retval;
  2261. rt2x00dev->priv = (void *)&rt2800usb_rt2800_ops;
  2262. /*
  2263. * Allocate eeprom data.
  2264. */
  2265. retval = rt2800usb_validate_eeprom(rt2x00dev);
  2266. if (retval)
  2267. return retval;
  2268. retval = rt2800usb_init_eeprom(rt2x00dev);
  2269. if (retval)
  2270. return retval;
  2271. /*
  2272. * Initialize hw specifications.
  2273. */
  2274. retval = rt2800usb_probe_hw_mode(rt2x00dev);
  2275. if (retval)
  2276. return retval;
  2277. /*
  2278. * This device has multiple filters for control frames
  2279. * and has a separate filter for PS Poll frames.
  2280. */
  2281. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  2282. __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
  2283. /*
  2284. * This device requires firmware.
  2285. */
  2286. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2287. __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
  2288. if (!modparam_nohwcrypt)
  2289. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  2290. /*
  2291. * Set the rssi offset.
  2292. */
  2293. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2294. return 0;
  2295. }
  2296. /*
  2297. * IEEE80211 stack callback functions.
  2298. */
  2299. static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
  2300. u32 *iv32, u16 *iv16)
  2301. {
  2302. struct rt2x00_dev *rt2x00dev = hw->priv;
  2303. struct mac_iveiv_entry iveiv_entry;
  2304. u32 offset;
  2305. offset = MAC_IVEIV_ENTRY(hw_key_idx);
  2306. rt2800_register_multiread(rt2x00dev, offset,
  2307. &iveiv_entry, sizeof(iveiv_entry));
  2308. memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
  2309. memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
  2310. }
  2311. static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2312. {
  2313. struct rt2x00_dev *rt2x00dev = hw->priv;
  2314. u32 reg;
  2315. bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  2316. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  2317. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  2318. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  2319. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  2320. rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  2321. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  2322. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  2323. rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  2324. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  2325. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  2326. rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  2327. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  2328. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  2329. rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  2330. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  2331. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  2332. rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  2333. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  2334. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  2335. rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  2336. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  2337. return 0;
  2338. }
  2339. static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  2340. const struct ieee80211_tx_queue_params *params)
  2341. {
  2342. struct rt2x00_dev *rt2x00dev = hw->priv;
  2343. struct data_queue *queue;
  2344. struct rt2x00_field32 field;
  2345. int retval;
  2346. u32 reg;
  2347. u32 offset;
  2348. /*
  2349. * First pass the configuration through rt2x00lib, that will
  2350. * update the queue settings and validate the input. After that
  2351. * we are free to update the registers based on the value
  2352. * in the queue parameter.
  2353. */
  2354. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  2355. if (retval)
  2356. return retval;
  2357. /*
  2358. * We only need to perform additional register initialization
  2359. * for WMM queues/
  2360. */
  2361. if (queue_idx >= 4)
  2362. return 0;
  2363. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  2364. /* Update WMM TXOP register */
  2365. offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  2366. field.bit_offset = (queue_idx & 1) * 16;
  2367. field.bit_mask = 0xffff << field.bit_offset;
  2368. rt2800_register_read(rt2x00dev, offset, &reg);
  2369. rt2x00_set_field32(&reg, field, queue->txop);
  2370. rt2800_register_write(rt2x00dev, offset, reg);
  2371. /* Update WMM registers */
  2372. field.bit_offset = queue_idx * 4;
  2373. field.bit_mask = 0xf << field.bit_offset;
  2374. rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  2375. rt2x00_set_field32(&reg, field, queue->aifs);
  2376. rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  2377. rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  2378. rt2x00_set_field32(&reg, field, queue->cw_min);
  2379. rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  2380. rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  2381. rt2x00_set_field32(&reg, field, queue->cw_max);
  2382. rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  2383. /* Update EDCA registers */
  2384. offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  2385. rt2800_register_read(rt2x00dev, offset, &reg);
  2386. rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  2387. rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  2388. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  2389. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  2390. rt2800_register_write(rt2x00dev, offset, reg);
  2391. return 0;
  2392. }
  2393. static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
  2394. {
  2395. struct rt2x00_dev *rt2x00dev = hw->priv;
  2396. u64 tsf;
  2397. u32 reg;
  2398. rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  2399. tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  2400. rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  2401. tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  2402. return tsf;
  2403. }
  2404. static const struct ieee80211_ops rt2800usb_mac80211_ops = {
  2405. .tx = rt2x00mac_tx,
  2406. .start = rt2x00mac_start,
  2407. .stop = rt2x00mac_stop,
  2408. .add_interface = rt2x00mac_add_interface,
  2409. .remove_interface = rt2x00mac_remove_interface,
  2410. .config = rt2x00mac_config,
  2411. .configure_filter = rt2x00mac_configure_filter,
  2412. .set_tim = rt2x00mac_set_tim,
  2413. .set_key = rt2x00mac_set_key,
  2414. .get_stats = rt2x00mac_get_stats,
  2415. .get_tkip_seq = rt2800usb_get_tkip_seq,
  2416. .set_rts_threshold = rt2800usb_set_rts_threshold,
  2417. .bss_info_changed = rt2x00mac_bss_info_changed,
  2418. .conf_tx = rt2800usb_conf_tx,
  2419. .get_tx_stats = rt2x00mac_get_tx_stats,
  2420. .get_tsf = rt2800usb_get_tsf,
  2421. .rfkill_poll = rt2x00mac_rfkill_poll,
  2422. };
  2423. static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
  2424. .probe_hw = rt2800usb_probe_hw,
  2425. .get_firmware_name = rt2800usb_get_firmware_name,
  2426. .check_firmware = rt2800usb_check_firmware,
  2427. .load_firmware = rt2800usb_load_firmware,
  2428. .initialize = rt2x00usb_initialize,
  2429. .uninitialize = rt2x00usb_uninitialize,
  2430. .clear_entry = rt2x00usb_clear_entry,
  2431. .set_device_state = rt2800usb_set_device_state,
  2432. .rfkill_poll = rt2800usb_rfkill_poll,
  2433. .link_stats = rt2800usb_link_stats,
  2434. .reset_tuner = rt2800usb_reset_tuner,
  2435. .link_tuner = rt2800usb_link_tuner,
  2436. .write_tx_desc = rt2800usb_write_tx_desc,
  2437. .write_tx_data = rt2x00usb_write_tx_data,
  2438. .write_beacon = rt2800usb_write_beacon,
  2439. .get_tx_data_len = rt2800usb_get_tx_data_len,
  2440. .kick_tx_queue = rt2800usb_kick_tx_queue,
  2441. .kill_tx_queue = rt2x00usb_kill_tx_queue,
  2442. .fill_rxdone = rt2800usb_fill_rxdone,
  2443. .config_shared_key = rt2800usb_config_shared_key,
  2444. .config_pairwise_key = rt2800usb_config_pairwise_key,
  2445. .config_filter = rt2800usb_config_filter,
  2446. .config_intf = rt2800usb_config_intf,
  2447. .config_erp = rt2800usb_config_erp,
  2448. .config_ant = rt2800usb_config_ant,
  2449. .config = rt2800usb_config,
  2450. };
  2451. static const struct data_queue_desc rt2800usb_queue_rx = {
  2452. .entry_num = RX_ENTRIES,
  2453. .data_size = AGGREGATION_SIZE,
  2454. .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE,
  2455. .priv_size = sizeof(struct queue_entry_priv_usb),
  2456. };
  2457. static const struct data_queue_desc rt2800usb_queue_tx = {
  2458. .entry_num = TX_ENTRIES,
  2459. .data_size = AGGREGATION_SIZE,
  2460. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2461. .priv_size = sizeof(struct queue_entry_priv_usb),
  2462. };
  2463. static const struct data_queue_desc rt2800usb_queue_bcn = {
  2464. .entry_num = 8 * BEACON_ENTRIES,
  2465. .data_size = MGMT_FRAME_SIZE,
  2466. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2467. .priv_size = sizeof(struct queue_entry_priv_usb),
  2468. };
  2469. static const struct rt2x00_ops rt2800usb_ops = {
  2470. .name = KBUILD_MODNAME,
  2471. .max_sta_intf = 1,
  2472. .max_ap_intf = 8,
  2473. .eeprom_size = EEPROM_SIZE,
  2474. .rf_size = RF_SIZE,
  2475. .tx_queues = NUM_TX_QUEUES,
  2476. .rx = &rt2800usb_queue_rx,
  2477. .tx = &rt2800usb_queue_tx,
  2478. .bcn = &rt2800usb_queue_bcn,
  2479. .lib = &rt2800usb_rt2x00_ops,
  2480. .hw = &rt2800usb_mac80211_ops,
  2481. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2482. .debugfs = &rt2800usb_rt2x00debug,
  2483. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2484. };
  2485. /*
  2486. * rt2800usb module information.
  2487. */
  2488. static struct usb_device_id rt2800usb_device_table[] = {
  2489. /* Abocom */
  2490. { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2491. { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2492. { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2493. { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2494. { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2495. { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2496. /* AirTies */
  2497. { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
  2498. /* Amigo */
  2499. { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2500. { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
  2501. /* Amit */
  2502. { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2503. /* ASUS */
  2504. { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
  2505. { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
  2506. { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
  2507. { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
  2508. { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
  2509. /* AzureWave */
  2510. { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
  2511. { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
  2512. { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
  2513. { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
  2514. /* Belkin */
  2515. { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
  2516. { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2517. { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2518. { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2519. /* Buffalo */
  2520. { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
  2521. { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2522. /* Conceptronic */
  2523. { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2524. { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
  2525. { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
  2526. { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2527. { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2528. { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
  2529. { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
  2530. { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2531. { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
  2532. { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
  2533. /* Corega */
  2534. { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2535. { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2536. { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2537. { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2538. { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
  2539. /* D-Link */
  2540. { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2541. { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2542. { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2543. { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2544. { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2545. { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2546. { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2547. { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
  2548. /* Edimax */
  2549. { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
  2550. { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
  2551. { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
  2552. /* Encore */
  2553. { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
  2554. /* EnGenius */
  2555. { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
  2556. { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
  2557. { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
  2558. { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
  2559. { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
  2560. { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
  2561. /* Gemtek */
  2562. { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
  2563. /* Gigabyte */
  2564. { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2565. { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2566. { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2567. /* Hawking */
  2568. { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
  2569. { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
  2570. { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
  2571. { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2572. /* I-O DATA */
  2573. { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
  2574. /* LevelOne */
  2575. { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
  2576. { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
  2577. /* Linksys */
  2578. { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2579. { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2580. { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
  2581. /* Logitec */
  2582. { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
  2583. { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
  2584. { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
  2585. /* Motorola */
  2586. { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2587. { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
  2588. /* Ovislink */
  2589. { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2590. /* Pegatron */
  2591. { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
  2592. { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2593. { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2594. /* Philips */
  2595. { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2596. /* Planex */
  2597. { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2598. { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
  2599. { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2600. /* Qcom */
  2601. { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
  2602. /* Quanta */
  2603. { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
  2604. /* Ralink */
  2605. { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
  2606. { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
  2607. { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2608. { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2609. { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2610. { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2611. { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2612. { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2613. { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
  2614. /* Samsung */
  2615. { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
  2616. /* Siemens */
  2617. { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
  2618. /* Sitecom */
  2619. { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
  2620. { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2621. { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2622. { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2623. { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
  2624. { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2625. { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2626. { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2627. { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2628. { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2629. { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
  2630. { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
  2631. /* SMC */
  2632. { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2633. { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
  2634. { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2635. { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2636. { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2637. { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2638. { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2639. { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2640. { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2641. /* Sparklan */
  2642. { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
  2643. /* Sweex */
  2644. { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
  2645. { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
  2646. { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
  2647. /* U-Media*/
  2648. { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2649. /* ZCOM */
  2650. { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
  2651. { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
  2652. /* Zinwell */
  2653. { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
  2654. { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
  2655. { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
  2656. { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
  2657. /* Zyxel */
  2658. { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
  2659. { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2660. { 0, }
  2661. };
  2662. MODULE_AUTHOR(DRV_PROJECT);
  2663. MODULE_VERSION(DRV_VERSION);
  2664. MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
  2665. MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
  2666. MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
  2667. MODULE_FIRMWARE(FIRMWARE_RT2870);
  2668. MODULE_LICENSE("GPL");
  2669. static struct usb_driver rt2800usb_driver = {
  2670. .name = KBUILD_MODNAME,
  2671. .id_table = rt2800usb_device_table,
  2672. .probe = rt2x00usb_probe,
  2673. .disconnect = rt2x00usb_disconnect,
  2674. .suspend = rt2x00usb_suspend,
  2675. .resume = rt2x00usb_resume,
  2676. };
  2677. static int __init rt2800usb_init(void)
  2678. {
  2679. return usb_register(&rt2800usb_driver);
  2680. }
  2681. static void __exit rt2800usb_exit(void)
  2682. {
  2683. usb_deregister(&rt2800usb_driver);
  2684. }
  2685. module_init(rt2800usb_init);
  2686. module_exit(rt2800usb_exit);