rt2800usb.c 101 KB

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