rt73usb.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  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: rt73usb
  19. Abstract: rt73usb device specific routines.
  20. Supported chipsets: rt2571W & rt2671.
  21. */
  22. #include <linux/crc-itu-t.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/slab.h>
  29. #include <linux/usb.h>
  30. #include "rt2x00.h"
  31. #include "rt2x00usb.h"
  32. #include "rt73usb.h"
  33. /*
  34. * Allow hardware encryption to be disabled.
  35. */
  36. static int modparam_nohwcrypt;
  37. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  38. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  39. /*
  40. * Register access.
  41. * All access to the CSR registers will go through the methods
  42. * rt2x00usb_register_read and rt2x00usb_register_write.
  43. * BBP and RF register require indirect register access,
  44. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  45. * These indirect registers work with busy bits,
  46. * and we will try maximal REGISTER_BUSY_COUNT times to access
  47. * the register while taking a REGISTER_BUSY_DELAY us delay
  48. * between each attampt. When the busy bit is still set at that time,
  49. * the access attempt is considered to have failed,
  50. * and we will print an error.
  51. * The _lock versions must be used if you already hold the csr_mutex
  52. */
  53. #define WAIT_FOR_BBP(__dev, __reg) \
  54. rt2x00usb_regbusy_read((__dev), PHY_CSR3, PHY_CSR3_BUSY, (__reg))
  55. #define WAIT_FOR_RF(__dev, __reg) \
  56. rt2x00usb_regbusy_read((__dev), PHY_CSR4, PHY_CSR4_BUSY, (__reg))
  57. static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  58. const unsigned int word, const u8 value)
  59. {
  60. u32 reg;
  61. mutex_lock(&rt2x00dev->csr_mutex);
  62. /*
  63. * Wait until the BBP becomes available, afterwards we
  64. * can safely write the new data into the register.
  65. */
  66. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  67. reg = 0;
  68. rt2x00_set_field32(&reg, PHY_CSR3_VALUE, value);
  69. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  70. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  71. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
  72. rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
  73. }
  74. mutex_unlock(&rt2x00dev->csr_mutex);
  75. }
  76. static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  77. const unsigned int word, u8 *value)
  78. {
  79. u32 reg;
  80. mutex_lock(&rt2x00dev->csr_mutex);
  81. /*
  82. * Wait until the BBP becomes available, afterwards we
  83. * can safely write the read request into the register.
  84. * After the data has been written, we wait until hardware
  85. * returns the correct value, if at any time the register
  86. * doesn't become available in time, reg will be 0xffffffff
  87. * which means we return 0xff to the caller.
  88. */
  89. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  90. reg = 0;
  91. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  92. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  93. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
  94. rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
  95. WAIT_FOR_BBP(rt2x00dev, &reg);
  96. }
  97. *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
  98. mutex_unlock(&rt2x00dev->csr_mutex);
  99. }
  100. static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev,
  101. const unsigned int word, const u32 value)
  102. {
  103. u32 reg;
  104. mutex_lock(&rt2x00dev->csr_mutex);
  105. /*
  106. * Wait until the RF becomes available, afterwards we
  107. * can safely write the new data into the register.
  108. */
  109. if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  110. reg = 0;
  111. rt2x00_set_field32(&reg, PHY_CSR4_VALUE, value);
  112. /*
  113. * RF5225 and RF2527 contain 21 bits per RF register value,
  114. * all others contain 20 bits.
  115. */
  116. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS,
  117. 20 + (rt2x00_rf(rt2x00dev, RF5225) ||
  118. rt2x00_rf(rt2x00dev, RF2527)));
  119. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  120. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  121. rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR4, reg);
  122. rt2x00_rf_write(rt2x00dev, word, value);
  123. }
  124. mutex_unlock(&rt2x00dev->csr_mutex);
  125. }
  126. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  127. static const struct rt2x00debug rt73usb_rt2x00debug = {
  128. .owner = THIS_MODULE,
  129. .csr = {
  130. .read = rt2x00usb_register_read,
  131. .write = rt2x00usb_register_write,
  132. .flags = RT2X00DEBUGFS_OFFSET,
  133. .word_base = CSR_REG_BASE,
  134. .word_size = sizeof(u32),
  135. .word_count = CSR_REG_SIZE / sizeof(u32),
  136. },
  137. .eeprom = {
  138. .read = rt2x00_eeprom_read,
  139. .write = rt2x00_eeprom_write,
  140. .word_base = EEPROM_BASE,
  141. .word_size = sizeof(u16),
  142. .word_count = EEPROM_SIZE / sizeof(u16),
  143. },
  144. .bbp = {
  145. .read = rt73usb_bbp_read,
  146. .write = rt73usb_bbp_write,
  147. .word_base = BBP_BASE,
  148. .word_size = sizeof(u8),
  149. .word_count = BBP_SIZE / sizeof(u8),
  150. },
  151. .rf = {
  152. .read = rt2x00_rf_read,
  153. .write = rt73usb_rf_write,
  154. .word_base = RF_BASE,
  155. .word_size = sizeof(u32),
  156. .word_count = RF_SIZE / sizeof(u32),
  157. },
  158. };
  159. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  160. static int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  161. {
  162. u32 reg;
  163. rt2x00usb_register_read(rt2x00dev, MAC_CSR13, &reg);
  164. return rt2x00_get_field32(reg, MAC_CSR13_BIT7);
  165. }
  166. #ifdef CONFIG_RT2X00_LIB_LEDS
  167. static void rt73usb_brightness_set(struct led_classdev *led_cdev,
  168. enum led_brightness brightness)
  169. {
  170. struct rt2x00_led *led =
  171. container_of(led_cdev, struct rt2x00_led, led_dev);
  172. unsigned int enabled = brightness != LED_OFF;
  173. unsigned int a_mode =
  174. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  175. unsigned int bg_mode =
  176. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  177. if (led->type == LED_TYPE_RADIO) {
  178. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  179. MCU_LEDCS_RADIO_STATUS, enabled);
  180. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  181. 0, led->rt2x00dev->led_mcu_reg,
  182. REGISTER_TIMEOUT);
  183. } else if (led->type == LED_TYPE_ASSOC) {
  184. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  185. MCU_LEDCS_LINK_BG_STATUS, bg_mode);
  186. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  187. MCU_LEDCS_LINK_A_STATUS, a_mode);
  188. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  189. 0, led->rt2x00dev->led_mcu_reg,
  190. REGISTER_TIMEOUT);
  191. } else if (led->type == LED_TYPE_QUALITY) {
  192. /*
  193. * The brightness is divided into 6 levels (0 - 5),
  194. * this means we need to convert the brightness
  195. * argument into the matching level within that range.
  196. */
  197. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  198. brightness / (LED_FULL / 6),
  199. led->rt2x00dev->led_mcu_reg,
  200. REGISTER_TIMEOUT);
  201. }
  202. }
  203. static int rt73usb_blink_set(struct led_classdev *led_cdev,
  204. unsigned long *delay_on,
  205. unsigned long *delay_off)
  206. {
  207. struct rt2x00_led *led =
  208. container_of(led_cdev, struct rt2x00_led, led_dev);
  209. u32 reg;
  210. rt2x00usb_register_read(led->rt2x00dev, MAC_CSR14, &reg);
  211. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, *delay_on);
  212. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, *delay_off);
  213. rt2x00usb_register_write(led->rt2x00dev, MAC_CSR14, reg);
  214. return 0;
  215. }
  216. static void rt73usb_init_led(struct rt2x00_dev *rt2x00dev,
  217. struct rt2x00_led *led,
  218. enum led_type type)
  219. {
  220. led->rt2x00dev = rt2x00dev;
  221. led->type = type;
  222. led->led_dev.brightness_set = rt73usb_brightness_set;
  223. led->led_dev.blink_set = rt73usb_blink_set;
  224. led->flags = LED_INITIALIZED;
  225. }
  226. #endif /* CONFIG_RT2X00_LIB_LEDS */
  227. /*
  228. * Configuration handlers.
  229. */
  230. static int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  231. struct rt2x00lib_crypto *crypto,
  232. struct ieee80211_key_conf *key)
  233. {
  234. struct hw_key_entry key_entry;
  235. struct rt2x00_field32 field;
  236. u32 mask;
  237. u32 reg;
  238. if (crypto->cmd == SET_KEY) {
  239. /*
  240. * rt2x00lib can't determine the correct free
  241. * key_idx for shared keys. We have 1 register
  242. * with key valid bits. The goal is simple, read
  243. * the register, if that is full we have no slots
  244. * left.
  245. * Note that each BSS is allowed to have up to 4
  246. * shared keys, so put a mask over the allowed
  247. * entries.
  248. */
  249. mask = (0xf << crypto->bssidx);
  250. rt2x00usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  251. reg &= mask;
  252. if (reg && reg == mask)
  253. return -ENOSPC;
  254. key->hw_key_idx += reg ? ffz(reg) : 0;
  255. /*
  256. * Upload key to hardware
  257. */
  258. memcpy(key_entry.key, crypto->key,
  259. sizeof(key_entry.key));
  260. memcpy(key_entry.tx_mic, crypto->tx_mic,
  261. sizeof(key_entry.tx_mic));
  262. memcpy(key_entry.rx_mic, crypto->rx_mic,
  263. sizeof(key_entry.rx_mic));
  264. reg = SHARED_KEY_ENTRY(key->hw_key_idx);
  265. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  266. &key_entry, sizeof(key_entry));
  267. /*
  268. * The cipher types are stored over 2 registers.
  269. * bssidx 0 and 1 keys are stored in SEC_CSR1 and
  270. * bssidx 1 and 2 keys are stored in SEC_CSR5.
  271. * Using the correct defines correctly will cause overhead,
  272. * so just calculate the correct offset.
  273. */
  274. if (key->hw_key_idx < 8) {
  275. field.bit_offset = (3 * key->hw_key_idx);
  276. field.bit_mask = 0x7 << field.bit_offset;
  277. rt2x00usb_register_read(rt2x00dev, SEC_CSR1, &reg);
  278. rt2x00_set_field32(&reg, field, crypto->cipher);
  279. rt2x00usb_register_write(rt2x00dev, SEC_CSR1, reg);
  280. } else {
  281. field.bit_offset = (3 * (key->hw_key_idx - 8));
  282. field.bit_mask = 0x7 << field.bit_offset;
  283. rt2x00usb_register_read(rt2x00dev, SEC_CSR5, &reg);
  284. rt2x00_set_field32(&reg, field, crypto->cipher);
  285. rt2x00usb_register_write(rt2x00dev, SEC_CSR5, reg);
  286. }
  287. /*
  288. * The driver does not support the IV/EIV generation
  289. * in hardware. However it doesn't support the IV/EIV
  290. * inside the ieee80211 frame either, but requires it
  291. * to be provided separately for the descriptor.
  292. * rt2x00lib will cut the IV/EIV data out of all frames
  293. * given to us by mac80211, but we must tell mac80211
  294. * to generate the IV/EIV data.
  295. */
  296. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  297. }
  298. /*
  299. * SEC_CSR0 contains only single-bit fields to indicate
  300. * a particular key is valid. Because using the FIELD32()
  301. * defines directly will cause a lot of overhead we use
  302. * a calculation to determine the correct bit directly.
  303. */
  304. mask = 1 << key->hw_key_idx;
  305. rt2x00usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  306. if (crypto->cmd == SET_KEY)
  307. reg |= mask;
  308. else if (crypto->cmd == DISABLE_KEY)
  309. reg &= ~mask;
  310. rt2x00usb_register_write(rt2x00dev, SEC_CSR0, reg);
  311. return 0;
  312. }
  313. static int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  314. struct rt2x00lib_crypto *crypto,
  315. struct ieee80211_key_conf *key)
  316. {
  317. struct hw_pairwise_ta_entry addr_entry;
  318. struct hw_key_entry key_entry;
  319. u32 mask;
  320. u32 reg;
  321. if (crypto->cmd == SET_KEY) {
  322. /*
  323. * rt2x00lib can't determine the correct free
  324. * key_idx for pairwise keys. We have 2 registers
  325. * with key valid bits. The goal is simple, read
  326. * the first register, if that is full move to
  327. * the next register.
  328. * When both registers are full, we drop the key,
  329. * otherwise we use the first invalid entry.
  330. */
  331. rt2x00usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  332. if (reg && reg == ~0) {
  333. key->hw_key_idx = 32;
  334. rt2x00usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  335. if (reg && reg == ~0)
  336. return -ENOSPC;
  337. }
  338. key->hw_key_idx += reg ? ffz(reg) : 0;
  339. /*
  340. * Upload key to hardware
  341. */
  342. memcpy(key_entry.key, crypto->key,
  343. sizeof(key_entry.key));
  344. memcpy(key_entry.tx_mic, crypto->tx_mic,
  345. sizeof(key_entry.tx_mic));
  346. memcpy(key_entry.rx_mic, crypto->rx_mic,
  347. sizeof(key_entry.rx_mic));
  348. reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  349. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  350. &key_entry, sizeof(key_entry));
  351. /*
  352. * Send the address and cipher type to the hardware register.
  353. */
  354. memset(&addr_entry, 0, sizeof(addr_entry));
  355. memcpy(&addr_entry, crypto->address, ETH_ALEN);
  356. addr_entry.cipher = crypto->cipher;
  357. reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
  358. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  359. &addr_entry, sizeof(addr_entry));
  360. /*
  361. * Enable pairwise lookup table for given BSS idx,
  362. * without this received frames will not be decrypted
  363. * by the hardware.
  364. */
  365. rt2x00usb_register_read(rt2x00dev, SEC_CSR4, &reg);
  366. reg |= (1 << crypto->bssidx);
  367. rt2x00usb_register_write(rt2x00dev, SEC_CSR4, reg);
  368. /*
  369. * The driver does not support the IV/EIV generation
  370. * in hardware. However it doesn't support the IV/EIV
  371. * inside the ieee80211 frame either, but requires it
  372. * to be provided separately for the descriptor.
  373. * rt2x00lib will cut the IV/EIV data out of all frames
  374. * given to us by mac80211, but we must tell mac80211
  375. * to generate the IV/EIV data.
  376. */
  377. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  378. }
  379. /*
  380. * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
  381. * a particular key is valid. Because using the FIELD32()
  382. * defines directly will cause a lot of overhead we use
  383. * a calculation to determine the correct bit directly.
  384. */
  385. if (key->hw_key_idx < 32) {
  386. mask = 1 << key->hw_key_idx;
  387. rt2x00usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  388. if (crypto->cmd == SET_KEY)
  389. reg |= mask;
  390. else if (crypto->cmd == DISABLE_KEY)
  391. reg &= ~mask;
  392. rt2x00usb_register_write(rt2x00dev, SEC_CSR2, reg);
  393. } else {
  394. mask = 1 << (key->hw_key_idx - 32);
  395. rt2x00usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  396. if (crypto->cmd == SET_KEY)
  397. reg |= mask;
  398. else if (crypto->cmd == DISABLE_KEY)
  399. reg &= ~mask;
  400. rt2x00usb_register_write(rt2x00dev, SEC_CSR3, reg);
  401. }
  402. return 0;
  403. }
  404. static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev,
  405. const unsigned int filter_flags)
  406. {
  407. u32 reg;
  408. /*
  409. * Start configuration steps.
  410. * Note that the version error will always be dropped
  411. * and broadcast frames will always be accepted since
  412. * there is no filter for it at this time.
  413. */
  414. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  415. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  416. !(filter_flags & FIF_FCSFAIL));
  417. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  418. !(filter_flags & FIF_PLCPFAIL));
  419. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  420. !(filter_flags & (FIF_CONTROL | FIF_PSPOLL)));
  421. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  422. !(filter_flags & FIF_PROMISC_IN_BSS));
  423. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  424. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  425. !rt2x00dev->intf_ap_count);
  426. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  427. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  428. !(filter_flags & FIF_ALLMULTI));
  429. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  430. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS,
  431. !(filter_flags & FIF_CONTROL));
  432. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  433. }
  434. static void rt73usb_config_intf(struct rt2x00_dev *rt2x00dev,
  435. struct rt2x00_intf *intf,
  436. struct rt2x00intf_conf *conf,
  437. const unsigned int flags)
  438. {
  439. u32 reg;
  440. if (flags & CONFIG_UPDATE_TYPE) {
  441. /*
  442. * Enable synchronisation.
  443. */
  444. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  445. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  446. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  447. }
  448. if (flags & CONFIG_UPDATE_MAC) {
  449. reg = le32_to_cpu(conf->mac[1]);
  450. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  451. conf->mac[1] = cpu_to_le32(reg);
  452. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR2,
  453. conf->mac, sizeof(conf->mac));
  454. }
  455. if (flags & CONFIG_UPDATE_BSSID) {
  456. reg = le32_to_cpu(conf->bssid[1]);
  457. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  458. conf->bssid[1] = cpu_to_le32(reg);
  459. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR4,
  460. conf->bssid, sizeof(conf->bssid));
  461. }
  462. }
  463. static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
  464. struct rt2x00lib_erp *erp,
  465. u32 changed)
  466. {
  467. u32 reg;
  468. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  469. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, 0x32);
  470. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  471. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  472. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  473. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  474. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  475. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  476. !!erp->short_preamble);
  477. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  478. }
  479. if (changed & BSS_CHANGED_BASIC_RATES)
  480. rt2x00usb_register_write(rt2x00dev, TXRX_CSR5,
  481. erp->basic_rates);
  482. if (changed & BSS_CHANGED_BEACON_INT) {
  483. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  484. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  485. erp->beacon_int * 16);
  486. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  487. }
  488. if (changed & BSS_CHANGED_ERP_SLOT) {
  489. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  490. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
  491. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  492. rt2x00usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  493. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
  494. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  495. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
  496. rt2x00usb_register_write(rt2x00dev, MAC_CSR8, reg);
  497. }
  498. }
  499. static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  500. struct antenna_setup *ant)
  501. {
  502. u8 r3;
  503. u8 r4;
  504. u8 r77;
  505. u8 temp;
  506. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  507. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  508. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  509. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  510. /*
  511. * Configure the RX antenna.
  512. */
  513. switch (ant->rx) {
  514. case ANTENNA_HW_DIVERSITY:
  515. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  516. temp = !test_bit(CAPABILITY_FRAME_TYPE, &rt2x00dev->cap_flags)
  517. && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ);
  518. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp);
  519. break;
  520. case ANTENNA_A:
  521. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  522. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  523. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  524. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  525. else
  526. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  527. break;
  528. case ANTENNA_B:
  529. default:
  530. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  531. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  532. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  533. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  534. else
  535. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  536. break;
  537. }
  538. rt73usb_bbp_write(rt2x00dev, 77, r77);
  539. rt73usb_bbp_write(rt2x00dev, 3, r3);
  540. rt73usb_bbp_write(rt2x00dev, 4, r4);
  541. }
  542. static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  543. struct antenna_setup *ant)
  544. {
  545. u8 r3;
  546. u8 r4;
  547. u8 r77;
  548. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  549. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  550. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  551. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  552. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  553. !test_bit(CAPABILITY_FRAME_TYPE, &rt2x00dev->cap_flags));
  554. /*
  555. * Configure the RX antenna.
  556. */
  557. switch (ant->rx) {
  558. case ANTENNA_HW_DIVERSITY:
  559. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  560. break;
  561. case ANTENNA_A:
  562. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  563. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  564. break;
  565. case ANTENNA_B:
  566. default:
  567. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  568. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  569. break;
  570. }
  571. rt73usb_bbp_write(rt2x00dev, 77, r77);
  572. rt73usb_bbp_write(rt2x00dev, 3, r3);
  573. rt73usb_bbp_write(rt2x00dev, 4, r4);
  574. }
  575. struct antenna_sel {
  576. u8 word;
  577. /*
  578. * value[0] -> non-LNA
  579. * value[1] -> LNA
  580. */
  581. u8 value[2];
  582. };
  583. static const struct antenna_sel antenna_sel_a[] = {
  584. { 96, { 0x58, 0x78 } },
  585. { 104, { 0x38, 0x48 } },
  586. { 75, { 0xfe, 0x80 } },
  587. { 86, { 0xfe, 0x80 } },
  588. { 88, { 0xfe, 0x80 } },
  589. { 35, { 0x60, 0x60 } },
  590. { 97, { 0x58, 0x58 } },
  591. { 98, { 0x58, 0x58 } },
  592. };
  593. static const struct antenna_sel antenna_sel_bg[] = {
  594. { 96, { 0x48, 0x68 } },
  595. { 104, { 0x2c, 0x3c } },
  596. { 75, { 0xfe, 0x80 } },
  597. { 86, { 0xfe, 0x80 } },
  598. { 88, { 0xfe, 0x80 } },
  599. { 35, { 0x50, 0x50 } },
  600. { 97, { 0x48, 0x48 } },
  601. { 98, { 0x48, 0x48 } },
  602. };
  603. static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
  604. struct antenna_setup *ant)
  605. {
  606. const struct antenna_sel *sel;
  607. unsigned int lna;
  608. unsigned int i;
  609. u32 reg;
  610. /*
  611. * We should never come here because rt2x00lib is supposed
  612. * to catch this and send us the correct antenna explicitely.
  613. */
  614. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  615. ant->tx == ANTENNA_SW_DIVERSITY);
  616. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  617. sel = antenna_sel_a;
  618. lna = test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
  619. } else {
  620. sel = antenna_sel_bg;
  621. lna = test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
  622. }
  623. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  624. rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  625. rt2x00usb_register_read(rt2x00dev, PHY_CSR0, &reg);
  626. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  627. (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ));
  628. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  629. (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ));
  630. rt2x00usb_register_write(rt2x00dev, PHY_CSR0, reg);
  631. if (rt2x00_rf(rt2x00dev, RF5226) || rt2x00_rf(rt2x00dev, RF5225))
  632. rt73usb_config_antenna_5x(rt2x00dev, ant);
  633. else if (rt2x00_rf(rt2x00dev, RF2528) || rt2x00_rf(rt2x00dev, RF2527))
  634. rt73usb_config_antenna_2x(rt2x00dev, ant);
  635. }
  636. static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  637. struct rt2x00lib_conf *libconf)
  638. {
  639. u16 eeprom;
  640. short lna_gain = 0;
  641. if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
  642. if (test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags))
  643. lna_gain += 14;
  644. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  645. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  646. } else {
  647. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  648. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  649. }
  650. rt2x00dev->lna_gain = lna_gain;
  651. }
  652. static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
  653. struct rf_channel *rf, const int txpower)
  654. {
  655. u8 r3;
  656. u8 r94;
  657. u8 smart;
  658. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  659. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  660. smart = !(rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527));
  661. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  662. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  663. rt73usb_bbp_write(rt2x00dev, 3, r3);
  664. r94 = 6;
  665. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  666. r94 += txpower - MAX_TXPOWER;
  667. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  668. r94 += txpower;
  669. rt73usb_bbp_write(rt2x00dev, 94, r94);
  670. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  671. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  672. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  673. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  674. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  675. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  676. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  677. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  678. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  679. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  680. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  681. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  682. udelay(10);
  683. }
  684. static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  685. const int txpower)
  686. {
  687. struct rf_channel rf;
  688. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  689. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  690. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  691. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  692. rt73usb_config_channel(rt2x00dev, &rf, txpower);
  693. }
  694. static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  695. struct rt2x00lib_conf *libconf)
  696. {
  697. u32 reg;
  698. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  699. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_DOWN, 1);
  700. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_STEP, 0);
  701. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_FALLBACK_CCK, 0);
  702. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
  703. libconf->conf->long_frame_max_tx_count);
  704. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
  705. libconf->conf->short_frame_max_tx_count);
  706. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  707. }
  708. static void rt73usb_config_ps(struct rt2x00_dev *rt2x00dev,
  709. struct rt2x00lib_conf *libconf)
  710. {
  711. enum dev_state state =
  712. (libconf->conf->flags & IEEE80211_CONF_PS) ?
  713. STATE_SLEEP : STATE_AWAKE;
  714. u32 reg;
  715. if (state == STATE_SLEEP) {
  716. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  717. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN,
  718. rt2x00dev->beacon_int - 10);
  719. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP,
  720. libconf->conf->listen_interval - 1);
  721. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 5);
  722. /* We must first disable autowake before it can be enabled */
  723. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  724. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  725. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 1);
  726. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  727. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  728. USB_MODE_SLEEP, REGISTER_TIMEOUT);
  729. } else {
  730. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  731. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN, 0);
  732. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP, 0);
  733. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  734. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 0);
  735. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  736. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  737. USB_MODE_WAKEUP, REGISTER_TIMEOUT);
  738. }
  739. }
  740. static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
  741. struct rt2x00lib_conf *libconf,
  742. const unsigned int flags)
  743. {
  744. /* Always recalculate LNA gain before changing configuration */
  745. rt73usb_config_lna_gain(rt2x00dev, libconf);
  746. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  747. rt73usb_config_channel(rt2x00dev, &libconf->rf,
  748. libconf->conf->power_level);
  749. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  750. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  751. rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  752. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  753. rt73usb_config_retry_limit(rt2x00dev, libconf);
  754. if (flags & IEEE80211_CONF_CHANGE_PS)
  755. rt73usb_config_ps(rt2x00dev, libconf);
  756. }
  757. /*
  758. * Link tuning
  759. */
  760. static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev,
  761. struct link_qual *qual)
  762. {
  763. u32 reg;
  764. /*
  765. * Update FCS error count from register.
  766. */
  767. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  768. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  769. /*
  770. * Update False CCA count from register.
  771. */
  772. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  773. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  774. }
  775. static inline void rt73usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  776. struct link_qual *qual, u8 vgc_level)
  777. {
  778. if (qual->vgc_level != vgc_level) {
  779. rt73usb_bbp_write(rt2x00dev, 17, vgc_level);
  780. qual->vgc_level = vgc_level;
  781. qual->vgc_level_reg = vgc_level;
  782. }
  783. }
  784. static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  785. struct link_qual *qual)
  786. {
  787. rt73usb_set_vgc(rt2x00dev, qual, 0x20);
  788. }
  789. static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  790. struct link_qual *qual, const u32 count)
  791. {
  792. u8 up_bound;
  793. u8 low_bound;
  794. /*
  795. * Determine r17 bounds.
  796. */
  797. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  798. low_bound = 0x28;
  799. up_bound = 0x48;
  800. if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags)) {
  801. low_bound += 0x10;
  802. up_bound += 0x10;
  803. }
  804. } else {
  805. if (qual->rssi > -82) {
  806. low_bound = 0x1c;
  807. up_bound = 0x40;
  808. } else if (qual->rssi > -84) {
  809. low_bound = 0x1c;
  810. up_bound = 0x20;
  811. } else {
  812. low_bound = 0x1c;
  813. up_bound = 0x1c;
  814. }
  815. if (test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags)) {
  816. low_bound += 0x14;
  817. up_bound += 0x10;
  818. }
  819. }
  820. /*
  821. * If we are not associated, we should go straight to the
  822. * dynamic CCA tuning.
  823. */
  824. if (!rt2x00dev->intf_associated)
  825. goto dynamic_cca_tune;
  826. /*
  827. * Special big-R17 for very short distance
  828. */
  829. if (qual->rssi > -35) {
  830. rt73usb_set_vgc(rt2x00dev, qual, 0x60);
  831. return;
  832. }
  833. /*
  834. * Special big-R17 for short distance
  835. */
  836. if (qual->rssi >= -58) {
  837. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  838. return;
  839. }
  840. /*
  841. * Special big-R17 for middle-short distance
  842. */
  843. if (qual->rssi >= -66) {
  844. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x10);
  845. return;
  846. }
  847. /*
  848. * Special mid-R17 for middle distance
  849. */
  850. if (qual->rssi >= -74) {
  851. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x08);
  852. return;
  853. }
  854. /*
  855. * Special case: Change up_bound based on the rssi.
  856. * Lower up_bound when rssi is weaker then -74 dBm.
  857. */
  858. up_bound -= 2 * (-74 - qual->rssi);
  859. if (low_bound > up_bound)
  860. up_bound = low_bound;
  861. if (qual->vgc_level > up_bound) {
  862. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  863. return;
  864. }
  865. dynamic_cca_tune:
  866. /*
  867. * r17 does not yet exceed upper limit, continue and base
  868. * the r17 tuning on the false CCA count.
  869. */
  870. if ((qual->false_cca > 512) && (qual->vgc_level < up_bound))
  871. rt73usb_set_vgc(rt2x00dev, qual,
  872. min_t(u8, qual->vgc_level + 4, up_bound));
  873. else if ((qual->false_cca < 100) && (qual->vgc_level > low_bound))
  874. rt73usb_set_vgc(rt2x00dev, qual,
  875. max_t(u8, qual->vgc_level - 4, low_bound));
  876. }
  877. /*
  878. * Queue handlers.
  879. */
  880. static void rt73usb_start_queue(struct data_queue *queue)
  881. {
  882. struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
  883. u32 reg;
  884. switch (queue->qid) {
  885. case QID_RX:
  886. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  887. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  888. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  889. break;
  890. case QID_BEACON:
  891. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  892. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  893. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  894. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  895. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  896. break;
  897. default:
  898. break;
  899. }
  900. }
  901. static void rt73usb_stop_queue(struct data_queue *queue)
  902. {
  903. struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
  904. u32 reg;
  905. switch (queue->qid) {
  906. case QID_RX:
  907. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  908. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 1);
  909. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  910. break;
  911. case QID_BEACON:
  912. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  913. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  914. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  915. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  916. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  917. break;
  918. default:
  919. break;
  920. }
  921. }
  922. /*
  923. * Firmware functions
  924. */
  925. static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  926. {
  927. return FIRMWARE_RT2571;
  928. }
  929. static int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  930. const u8 *data, const size_t len)
  931. {
  932. u16 fw_crc;
  933. u16 crc;
  934. /*
  935. * Only support 2kb firmware files.
  936. */
  937. if (len != 2048)
  938. return FW_BAD_LENGTH;
  939. /*
  940. * The last 2 bytes in the firmware array are the crc checksum itself,
  941. * this means that we should never pass those 2 bytes to the crc
  942. * algorithm.
  943. */
  944. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  945. /*
  946. * Use the crc itu-t algorithm.
  947. */
  948. crc = crc_itu_t(0, data, len - 2);
  949. crc = crc_itu_t_byte(crc, 0);
  950. crc = crc_itu_t_byte(crc, 0);
  951. return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
  952. }
  953. static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  954. const u8 *data, const size_t len)
  955. {
  956. unsigned int i;
  957. int status;
  958. u32 reg;
  959. /*
  960. * Wait for stable hardware.
  961. */
  962. for (i = 0; i < 100; i++) {
  963. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  964. if (reg)
  965. break;
  966. msleep(1);
  967. }
  968. if (!reg) {
  969. ERROR(rt2x00dev, "Unstable hardware.\n");
  970. return -EBUSY;
  971. }
  972. /*
  973. * Write firmware to device.
  974. */
  975. rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, data, len);
  976. /*
  977. * Send firmware request to device to load firmware,
  978. * we need to specify a long timeout time.
  979. */
  980. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  981. 0, USB_MODE_FIRMWARE,
  982. REGISTER_TIMEOUT_FIRMWARE);
  983. if (status < 0) {
  984. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  985. return status;
  986. }
  987. return 0;
  988. }
  989. /*
  990. * Initialization functions.
  991. */
  992. static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
  993. {
  994. u32 reg;
  995. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  996. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  997. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  998. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  999. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1000. rt2x00usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  1001. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  1002. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  1003. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  1004. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  1005. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  1006. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  1007. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  1008. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  1009. rt2x00usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  1010. /*
  1011. * CCK TXD BBP registers
  1012. */
  1013. rt2x00usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  1014. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  1015. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  1016. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  1017. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  1018. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  1019. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  1020. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  1021. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  1022. rt2x00usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  1023. /*
  1024. * OFDM TXD BBP registers
  1025. */
  1026. rt2x00usb_register_read(rt2x00dev, TXRX_CSR3, &reg);
  1027. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  1028. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  1029. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  1030. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  1031. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  1032. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  1033. rt2x00usb_register_write(rt2x00dev, TXRX_CSR3, reg);
  1034. rt2x00usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1035. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1036. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1037. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1038. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1039. rt2x00usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  1040. rt2x00usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1041. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1042. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1043. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1044. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1045. rt2x00usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  1046. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1047. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1048. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1049. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1050. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1051. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1052. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1053. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1054. rt2x00usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1055. rt2x00usb_register_read(rt2x00dev, MAC_CSR6, &reg);
  1056. rt2x00_set_field32(&reg, MAC_CSR6_MAX_FRAME_UNIT, 0xfff);
  1057. rt2x00usb_register_write(rt2x00dev, MAC_CSR6, reg);
  1058. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718);
  1059. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1060. return -EBUSY;
  1061. rt2x00usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00);
  1062. /*
  1063. * Invalidate all Shared Keys (SEC_CSR0),
  1064. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1065. */
  1066. rt2x00usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1067. rt2x00usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1068. rt2x00usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1069. reg = 0x000023b0;
  1070. if (rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527))
  1071. rt2x00_set_field32(&reg, PHY_CSR1_RF_RPI, 1);
  1072. rt2x00usb_register_write(rt2x00dev, PHY_CSR1, reg);
  1073. rt2x00usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06);
  1074. rt2x00usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1075. rt2x00usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
  1076. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  1077. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1078. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  1079. /*
  1080. * Clear all beacons
  1081. * For the Beacon base registers we only need to clear
  1082. * the first byte since that byte contains the VALID and OWNER
  1083. * bits which (when set to 0) will invalidate the entire beacon.
  1084. */
  1085. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1086. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1087. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1088. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1089. /*
  1090. * We must clear the error counters.
  1091. * These registers are cleared on read,
  1092. * so we may pass a useless variable to store the value.
  1093. */
  1094. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  1095. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  1096. rt2x00usb_register_read(rt2x00dev, STA_CSR2, &reg);
  1097. /*
  1098. * Reset MAC and BBP registers.
  1099. */
  1100. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1101. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1102. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1103. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1104. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1105. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1106. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1107. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1108. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1109. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1110. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1111. return 0;
  1112. }
  1113. static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1114. {
  1115. unsigned int i;
  1116. u8 value;
  1117. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1118. rt73usb_bbp_read(rt2x00dev, 0, &value);
  1119. if ((value != 0xff) && (value != 0x00))
  1120. return 0;
  1121. udelay(REGISTER_BUSY_DELAY);
  1122. }
  1123. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1124. return -EACCES;
  1125. }
  1126. static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1127. {
  1128. unsigned int i;
  1129. u16 eeprom;
  1130. u8 reg_id;
  1131. u8 value;
  1132. if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
  1133. return -EACCES;
  1134. rt73usb_bbp_write(rt2x00dev, 3, 0x80);
  1135. rt73usb_bbp_write(rt2x00dev, 15, 0x30);
  1136. rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
  1137. rt73usb_bbp_write(rt2x00dev, 22, 0x38);
  1138. rt73usb_bbp_write(rt2x00dev, 23, 0x06);
  1139. rt73usb_bbp_write(rt2x00dev, 24, 0xfe);
  1140. rt73usb_bbp_write(rt2x00dev, 25, 0x0a);
  1141. rt73usb_bbp_write(rt2x00dev, 26, 0x0d);
  1142. rt73usb_bbp_write(rt2x00dev, 32, 0x0b);
  1143. rt73usb_bbp_write(rt2x00dev, 34, 0x12);
  1144. rt73usb_bbp_write(rt2x00dev, 37, 0x07);
  1145. rt73usb_bbp_write(rt2x00dev, 39, 0xf8);
  1146. rt73usb_bbp_write(rt2x00dev, 41, 0x60);
  1147. rt73usb_bbp_write(rt2x00dev, 53, 0x10);
  1148. rt73usb_bbp_write(rt2x00dev, 54, 0x18);
  1149. rt73usb_bbp_write(rt2x00dev, 60, 0x10);
  1150. rt73usb_bbp_write(rt2x00dev, 61, 0x04);
  1151. rt73usb_bbp_write(rt2x00dev, 62, 0x04);
  1152. rt73usb_bbp_write(rt2x00dev, 75, 0xfe);
  1153. rt73usb_bbp_write(rt2x00dev, 86, 0xfe);
  1154. rt73usb_bbp_write(rt2x00dev, 88, 0xfe);
  1155. rt73usb_bbp_write(rt2x00dev, 90, 0x0f);
  1156. rt73usb_bbp_write(rt2x00dev, 99, 0x00);
  1157. rt73usb_bbp_write(rt2x00dev, 102, 0x16);
  1158. rt73usb_bbp_write(rt2x00dev, 107, 0x04);
  1159. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1160. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1161. if (eeprom != 0xffff && eeprom != 0x0000) {
  1162. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1163. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1164. rt73usb_bbp_write(rt2x00dev, reg_id, value);
  1165. }
  1166. }
  1167. return 0;
  1168. }
  1169. /*
  1170. * Device state switch handlers.
  1171. */
  1172. static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1173. {
  1174. /*
  1175. * Initialize all registers.
  1176. */
  1177. if (unlikely(rt73usb_init_registers(rt2x00dev) ||
  1178. rt73usb_init_bbp(rt2x00dev)))
  1179. return -EIO;
  1180. return 0;
  1181. }
  1182. static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1183. {
  1184. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1185. /*
  1186. * Disable synchronisation.
  1187. */
  1188. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  1189. rt2x00usb_disable_radio(rt2x00dev);
  1190. }
  1191. static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1192. {
  1193. u32 reg, reg2;
  1194. unsigned int i;
  1195. char put_to_sleep;
  1196. put_to_sleep = (state != STATE_AWAKE);
  1197. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  1198. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1199. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1200. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1201. /*
  1202. * Device is not guaranteed to be in the requested state yet.
  1203. * We must wait until the register indicates that the
  1204. * device has entered the correct state.
  1205. */
  1206. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1207. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg2);
  1208. state = rt2x00_get_field32(reg2, MAC_CSR12_BBP_CURRENT_STATE);
  1209. if (state == !put_to_sleep)
  1210. return 0;
  1211. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1212. msleep(10);
  1213. }
  1214. return -EBUSY;
  1215. }
  1216. static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1217. enum dev_state state)
  1218. {
  1219. int retval = 0;
  1220. switch (state) {
  1221. case STATE_RADIO_ON:
  1222. retval = rt73usb_enable_radio(rt2x00dev);
  1223. break;
  1224. case STATE_RADIO_OFF:
  1225. rt73usb_disable_radio(rt2x00dev);
  1226. break;
  1227. case STATE_RADIO_IRQ_ON:
  1228. case STATE_RADIO_IRQ_OFF:
  1229. /* No support, but no error either */
  1230. break;
  1231. case STATE_DEEP_SLEEP:
  1232. case STATE_SLEEP:
  1233. case STATE_STANDBY:
  1234. case STATE_AWAKE:
  1235. retval = rt73usb_set_state(rt2x00dev, state);
  1236. break;
  1237. default:
  1238. retval = -ENOTSUPP;
  1239. break;
  1240. }
  1241. if (unlikely(retval))
  1242. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1243. state, retval);
  1244. return retval;
  1245. }
  1246. /*
  1247. * TX descriptor initialization
  1248. */
  1249. static void rt73usb_write_tx_desc(struct queue_entry *entry,
  1250. struct txentry_desc *txdesc)
  1251. {
  1252. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1253. __le32 *txd = (__le32 *) entry->skb->data;
  1254. u32 word;
  1255. /*
  1256. * Start writing the descriptor words.
  1257. */
  1258. rt2x00_desc_read(txd, 0, &word);
  1259. rt2x00_set_field32(&word, TXD_W0_BURST,
  1260. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1261. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1262. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1263. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1264. rt2x00_set_field32(&word, TXD_W0_ACK,
  1265. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1266. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1267. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1268. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1269. (txdesc->rate_mode == RATE_MODE_OFDM));
  1270. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->u.plcp.ifs);
  1271. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1272. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1273. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
  1274. test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
  1275. rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
  1276. test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
  1277. rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
  1278. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length);
  1279. rt2x00_set_field32(&word, TXD_W0_BURST2,
  1280. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1281. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
  1282. rt2x00_desc_write(txd, 0, word);
  1283. rt2x00_desc_read(txd, 1, &word);
  1284. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, entry->queue->qid);
  1285. rt2x00_set_field32(&word, TXD_W1_AIFSN, entry->queue->aifs);
  1286. rt2x00_set_field32(&word, TXD_W1_CWMIN, entry->queue->cw_min);
  1287. rt2x00_set_field32(&word, TXD_W1_CWMAX, entry->queue->cw_max);
  1288. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  1289. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1290. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1291. rt2x00_desc_write(txd, 1, word);
  1292. rt2x00_desc_read(txd, 2, &word);
  1293. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->u.plcp.signal);
  1294. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->u.plcp.service);
  1295. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW,
  1296. txdesc->u.plcp.length_low);
  1297. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH,
  1298. txdesc->u.plcp.length_high);
  1299. rt2x00_desc_write(txd, 2, word);
  1300. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1301. _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
  1302. _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
  1303. }
  1304. rt2x00_desc_read(txd, 5, &word);
  1305. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1306. TXPOWER_TO_DEV(entry->queue->rt2x00dev->tx_power));
  1307. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1308. rt2x00_desc_write(txd, 5, word);
  1309. /*
  1310. * Register descriptor details in skb frame descriptor.
  1311. */
  1312. skbdesc->flags |= SKBDESC_DESC_IN_SKB;
  1313. skbdesc->desc = txd;
  1314. skbdesc->desc_len = TXD_DESC_SIZE;
  1315. }
  1316. /*
  1317. * TX data initialization
  1318. */
  1319. static void rt73usb_write_beacon(struct queue_entry *entry,
  1320. struct txentry_desc *txdesc)
  1321. {
  1322. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1323. unsigned int beacon_base;
  1324. unsigned int padding_len;
  1325. u32 orig_reg, reg;
  1326. /*
  1327. * Disable beaconing while we are reloading the beacon data,
  1328. * otherwise we might be sending out invalid data.
  1329. */
  1330. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1331. orig_reg = reg;
  1332. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1333. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1334. /*
  1335. * Add space for the descriptor in front of the skb.
  1336. */
  1337. skb_push(entry->skb, TXD_DESC_SIZE);
  1338. memset(entry->skb->data, 0, TXD_DESC_SIZE);
  1339. /*
  1340. * Write the TX descriptor for the beacon.
  1341. */
  1342. rt73usb_write_tx_desc(entry, txdesc);
  1343. /*
  1344. * Dump beacon to userspace through debugfs.
  1345. */
  1346. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
  1347. /*
  1348. * Write entire beacon with descriptor and padding to register.
  1349. */
  1350. padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
  1351. if (padding_len && skb_pad(entry->skb, padding_len)) {
  1352. ERROR(rt2x00dev, "Failure padding beacon, aborting\n");
  1353. /* skb freed by skb_pad() on failure */
  1354. entry->skb = NULL;
  1355. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, orig_reg);
  1356. return;
  1357. }
  1358. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1359. rt2x00usb_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
  1360. entry->skb->len + padding_len);
  1361. /*
  1362. * Enable beaconing again.
  1363. *
  1364. * For Wi-Fi faily generated beacons between participating stations.
  1365. * Set TBTT phase adaptive adjustment step to 8us (default 16us)
  1366. */
  1367. rt2x00usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1368. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1369. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1370. /*
  1371. * Clean up the beacon skb.
  1372. */
  1373. dev_kfree_skb(entry->skb);
  1374. entry->skb = NULL;
  1375. }
  1376. static void rt73usb_clear_beacon(struct queue_entry *entry)
  1377. {
  1378. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1379. unsigned int beacon_base;
  1380. u32 reg;
  1381. /*
  1382. * Disable beaconing while we are reloading the beacon data,
  1383. * otherwise we might be sending out invalid data.
  1384. */
  1385. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1386. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1387. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1388. /*
  1389. * Clear beacon.
  1390. */
  1391. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1392. rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
  1393. /*
  1394. * Enable beaconing again.
  1395. */
  1396. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1397. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1398. }
  1399. static int rt73usb_get_tx_data_len(struct queue_entry *entry)
  1400. {
  1401. int length;
  1402. /*
  1403. * The length _must_ be a multiple of 4,
  1404. * but it must _not_ be a multiple of the USB packet size.
  1405. */
  1406. length = roundup(entry->skb->len, 4);
  1407. length += (4 * !(length % entry->queue->usb_maxpacket));
  1408. return length;
  1409. }
  1410. /*
  1411. * RX control handlers
  1412. */
  1413. static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1414. {
  1415. u8 offset = rt2x00dev->lna_gain;
  1416. u8 lna;
  1417. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1418. switch (lna) {
  1419. case 3:
  1420. offset += 90;
  1421. break;
  1422. case 2:
  1423. offset += 74;
  1424. break;
  1425. case 1:
  1426. offset += 64;
  1427. break;
  1428. default:
  1429. return 0;
  1430. }
  1431. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  1432. if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags)) {
  1433. if (lna == 3 || lna == 2)
  1434. offset += 10;
  1435. } else {
  1436. if (lna == 3)
  1437. offset += 6;
  1438. else if (lna == 2)
  1439. offset += 8;
  1440. }
  1441. }
  1442. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1443. }
  1444. static void rt73usb_fill_rxdone(struct queue_entry *entry,
  1445. struct rxdone_entry_desc *rxdesc)
  1446. {
  1447. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1448. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1449. __le32 *rxd = (__le32 *)entry->skb->data;
  1450. u32 word0;
  1451. u32 word1;
  1452. /*
  1453. * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
  1454. * frame data in rt2x00usb.
  1455. */
  1456. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1457. rxd = (__le32 *)skbdesc->desc;
  1458. /*
  1459. * It is now safe to read the descriptor on all architectures.
  1460. */
  1461. rt2x00_desc_read(rxd, 0, &word0);
  1462. rt2x00_desc_read(rxd, 1, &word1);
  1463. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1464. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1465. rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
  1466. rxdesc->cipher_status = rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
  1467. if (rxdesc->cipher != CIPHER_NONE) {
  1468. _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
  1469. _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
  1470. rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
  1471. _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
  1472. rxdesc->dev_flags |= RXDONE_CRYPTO_ICV;
  1473. /*
  1474. * Hardware has stripped IV/EIV data from 802.11 frame during
  1475. * decryption. It has provided the data separately but rt2x00lib
  1476. * should decide if it should be reinserted.
  1477. */
  1478. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1479. /*
  1480. * The hardware has already checked the Michael Mic and has
  1481. * stripped it from the frame. Signal this to mac80211.
  1482. */
  1483. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1484. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1485. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1486. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1487. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1488. }
  1489. /*
  1490. * Obtain the status about this packet.
  1491. * When frame was received with an OFDM bitrate,
  1492. * the signal is the PLCP value. If it was received with
  1493. * a CCK bitrate the signal is the rate in 100kbit/s.
  1494. */
  1495. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1496. rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1);
  1497. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1498. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1499. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1500. else
  1501. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1502. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1503. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1504. /*
  1505. * Set skb pointers, and update frame information.
  1506. */
  1507. skb_pull(entry->skb, entry->queue->desc_size);
  1508. skb_trim(entry->skb, rxdesc->size);
  1509. }
  1510. /*
  1511. * Device probe functions.
  1512. */
  1513. static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1514. {
  1515. u16 word;
  1516. u8 *mac;
  1517. s8 value;
  1518. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1519. /*
  1520. * Start validation of the data that has been read.
  1521. */
  1522. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1523. if (!is_valid_ether_addr(mac)) {
  1524. random_ether_addr(mac);
  1525. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1526. }
  1527. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1528. if (word == 0xffff) {
  1529. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1530. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1531. ANTENNA_B);
  1532. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1533. ANTENNA_B);
  1534. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1535. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1536. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1537. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226);
  1538. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1539. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1540. }
  1541. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1542. if (word == 0xffff) {
  1543. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0);
  1544. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1545. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1546. }
  1547. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1548. if (word == 0xffff) {
  1549. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0);
  1550. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0);
  1551. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0);
  1552. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0);
  1553. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0);
  1554. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0);
  1555. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0);
  1556. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0);
  1557. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1558. LED_MODE_DEFAULT);
  1559. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1560. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1561. }
  1562. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1563. if (word == 0xffff) {
  1564. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1565. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1566. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1567. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1568. }
  1569. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1570. if (word == 0xffff) {
  1571. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1572. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1573. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1574. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1575. } else {
  1576. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1577. if (value < -10 || value > 10)
  1578. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1579. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1580. if (value < -10 || value > 10)
  1581. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1582. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1583. }
  1584. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1585. if (word == 0xffff) {
  1586. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1587. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1588. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1589. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1590. } else {
  1591. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1592. if (value < -10 || value > 10)
  1593. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1594. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1595. if (value < -10 || value > 10)
  1596. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1597. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1598. }
  1599. return 0;
  1600. }
  1601. static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1602. {
  1603. u32 reg;
  1604. u16 value;
  1605. u16 eeprom;
  1606. /*
  1607. * Read EEPROM word for configuration.
  1608. */
  1609. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1610. /*
  1611. * Identify RF chipset.
  1612. */
  1613. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1614. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1615. rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET),
  1616. value, rt2x00_get_field32(reg, MAC_CSR0_REVISION));
  1617. if (!rt2x00_rt(rt2x00dev, RT2573) || (rt2x00_rev(rt2x00dev) == 0)) {
  1618. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1619. return -ENODEV;
  1620. }
  1621. if (!rt2x00_rf(rt2x00dev, RF5226) &&
  1622. !rt2x00_rf(rt2x00dev, RF2528) &&
  1623. !rt2x00_rf(rt2x00dev, RF5225) &&
  1624. !rt2x00_rf(rt2x00dev, RF2527)) {
  1625. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1626. return -ENODEV;
  1627. }
  1628. /*
  1629. * Identify default antenna configuration.
  1630. */
  1631. rt2x00dev->default_ant.tx =
  1632. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1633. rt2x00dev->default_ant.rx =
  1634. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1635. /*
  1636. * Read the Frame type.
  1637. */
  1638. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1639. __set_bit(CAPABILITY_FRAME_TYPE, &rt2x00dev->cap_flags);
  1640. /*
  1641. * Detect if this device has an hardware controlled radio.
  1642. */
  1643. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1644. __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
  1645. /*
  1646. * Read frequency offset.
  1647. */
  1648. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1649. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1650. /*
  1651. * Read external LNA informations.
  1652. */
  1653. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1654. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) {
  1655. __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
  1656. __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
  1657. }
  1658. /*
  1659. * Store led settings, for correct led behaviour.
  1660. */
  1661. #ifdef CONFIG_RT2X00_LIB_LEDS
  1662. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1663. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1664. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1665. if (value == LED_MODE_SIGNAL_STRENGTH)
  1666. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1667. LED_TYPE_QUALITY);
  1668. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  1669. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1670. rt2x00_get_field16(eeprom,
  1671. EEPROM_LED_POLARITY_GPIO_0));
  1672. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1673. rt2x00_get_field16(eeprom,
  1674. EEPROM_LED_POLARITY_GPIO_1));
  1675. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1676. rt2x00_get_field16(eeprom,
  1677. EEPROM_LED_POLARITY_GPIO_2));
  1678. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1679. rt2x00_get_field16(eeprom,
  1680. EEPROM_LED_POLARITY_GPIO_3));
  1681. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1682. rt2x00_get_field16(eeprom,
  1683. EEPROM_LED_POLARITY_GPIO_4));
  1684. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  1685. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1686. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  1687. rt2x00_get_field16(eeprom,
  1688. EEPROM_LED_POLARITY_RDY_G));
  1689. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  1690. rt2x00_get_field16(eeprom,
  1691. EEPROM_LED_POLARITY_RDY_A));
  1692. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1693. return 0;
  1694. }
  1695. /*
  1696. * RF value list for RF2528
  1697. * Supports: 2.4 GHz
  1698. */
  1699. static const struct rf_channel rf_vals_bg_2528[] = {
  1700. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1701. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1702. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1703. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1704. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1705. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1706. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1707. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1708. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1709. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1710. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1711. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1712. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1713. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1714. };
  1715. /*
  1716. * RF value list for RF5226
  1717. * Supports: 2.4 GHz & 5.2 GHz
  1718. */
  1719. static const struct rf_channel rf_vals_5226[] = {
  1720. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1721. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1722. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1723. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1724. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1725. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1726. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1727. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1728. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1729. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1730. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1731. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1732. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1733. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1734. /* 802.11 UNI / HyperLan 2 */
  1735. { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
  1736. { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
  1737. { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
  1738. { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
  1739. { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
  1740. { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
  1741. { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
  1742. { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
  1743. /* 802.11 HyperLan 2 */
  1744. { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
  1745. { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
  1746. { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
  1747. { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
  1748. { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
  1749. { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
  1750. { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
  1751. { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
  1752. { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
  1753. { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
  1754. /* 802.11 UNII */
  1755. { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
  1756. { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
  1757. { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
  1758. { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
  1759. { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
  1760. { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
  1761. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1762. { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
  1763. { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
  1764. { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
  1765. { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
  1766. };
  1767. /*
  1768. * RF value list for RF5225 & RF2527
  1769. * Supports: 2.4 GHz & 5.2 GHz
  1770. */
  1771. static const struct rf_channel rf_vals_5225_2527[] = {
  1772. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1773. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1774. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1775. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1776. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1777. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1778. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1779. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1780. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1781. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1782. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1783. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1784. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1785. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1786. /* 802.11 UNI / HyperLan 2 */
  1787. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1788. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1789. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1790. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1791. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1792. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1793. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1794. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1795. /* 802.11 HyperLan 2 */
  1796. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1797. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1798. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1799. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1800. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1801. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1802. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1803. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1804. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1805. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1806. /* 802.11 UNII */
  1807. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1808. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1809. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1810. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1811. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1812. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1813. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1814. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1815. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1816. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1817. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1818. };
  1819. static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1820. {
  1821. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1822. struct channel_info *info;
  1823. char *tx_power;
  1824. unsigned int i;
  1825. /*
  1826. * Initialize all hw fields.
  1827. *
  1828. * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING unless we are
  1829. * capable of sending the buffered frames out after the DTIM
  1830. * transmission using rt2x00lib_beacondone. This will send out
  1831. * multicast and broadcast traffic immediately instead of buffering it
  1832. * infinitly and thus dropping it after some time.
  1833. */
  1834. rt2x00dev->hw->flags =
  1835. IEEE80211_HW_SIGNAL_DBM |
  1836. IEEE80211_HW_SUPPORTS_PS |
  1837. IEEE80211_HW_PS_NULLFUNC_STACK;
  1838. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1839. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1840. rt2x00_eeprom_addr(rt2x00dev,
  1841. EEPROM_MAC_ADDR_0));
  1842. /*
  1843. * Initialize hw_mode information.
  1844. */
  1845. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1846. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1847. if (rt2x00_rf(rt2x00dev, RF2528)) {
  1848. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
  1849. spec->channels = rf_vals_bg_2528;
  1850. } else if (rt2x00_rf(rt2x00dev, RF5226)) {
  1851. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1852. spec->num_channels = ARRAY_SIZE(rf_vals_5226);
  1853. spec->channels = rf_vals_5226;
  1854. } else if (rt2x00_rf(rt2x00dev, RF2527)) {
  1855. spec->num_channels = 14;
  1856. spec->channels = rf_vals_5225_2527;
  1857. } else if (rt2x00_rf(rt2x00dev, RF5225)) {
  1858. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1859. spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527);
  1860. spec->channels = rf_vals_5225_2527;
  1861. }
  1862. /*
  1863. * Create channel information array
  1864. */
  1865. info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
  1866. if (!info)
  1867. return -ENOMEM;
  1868. spec->channels_info = info;
  1869. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1870. for (i = 0; i < 14; i++) {
  1871. info[i].max_power = MAX_TXPOWER;
  1872. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1873. }
  1874. if (spec->num_channels > 14) {
  1875. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1876. for (i = 14; i < spec->num_channels; i++) {
  1877. info[i].max_power = MAX_TXPOWER;
  1878. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1879. }
  1880. }
  1881. return 0;
  1882. }
  1883. static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1884. {
  1885. int retval;
  1886. /*
  1887. * Allocate eeprom data.
  1888. */
  1889. retval = rt73usb_validate_eeprom(rt2x00dev);
  1890. if (retval)
  1891. return retval;
  1892. retval = rt73usb_init_eeprom(rt2x00dev);
  1893. if (retval)
  1894. return retval;
  1895. /*
  1896. * Initialize hw specifications.
  1897. */
  1898. retval = rt73usb_probe_hw_mode(rt2x00dev);
  1899. if (retval)
  1900. return retval;
  1901. /*
  1902. * This device has multiple filters for control frames,
  1903. * but has no a separate filter for PS Poll frames.
  1904. */
  1905. __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
  1906. /*
  1907. * This device requires firmware.
  1908. */
  1909. __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
  1910. if (!modparam_nohwcrypt)
  1911. __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
  1912. __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
  1913. /*
  1914. * Set the rssi offset.
  1915. */
  1916. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1917. return 0;
  1918. }
  1919. /*
  1920. * IEEE80211 stack callback functions.
  1921. */
  1922. static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  1923. const struct ieee80211_tx_queue_params *params)
  1924. {
  1925. struct rt2x00_dev *rt2x00dev = hw->priv;
  1926. struct data_queue *queue;
  1927. struct rt2x00_field32 field;
  1928. int retval;
  1929. u32 reg;
  1930. u32 offset;
  1931. /*
  1932. * First pass the configuration through rt2x00lib, that will
  1933. * update the queue settings and validate the input. After that
  1934. * we are free to update the registers based on the value
  1935. * in the queue parameter.
  1936. */
  1937. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  1938. if (retval)
  1939. return retval;
  1940. /*
  1941. * We only need to perform additional register initialization
  1942. * for WMM queues/
  1943. */
  1944. if (queue_idx >= 4)
  1945. return 0;
  1946. queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
  1947. /* Update WMM TXOP register */
  1948. offset = AC_TXOP_CSR0 + (sizeof(u32) * (!!(queue_idx & 2)));
  1949. field.bit_offset = (queue_idx & 1) * 16;
  1950. field.bit_mask = 0xffff << field.bit_offset;
  1951. rt2x00usb_register_read(rt2x00dev, offset, &reg);
  1952. rt2x00_set_field32(&reg, field, queue->txop);
  1953. rt2x00usb_register_write(rt2x00dev, offset, reg);
  1954. /* Update WMM registers */
  1955. field.bit_offset = queue_idx * 4;
  1956. field.bit_mask = 0xf << field.bit_offset;
  1957. rt2x00usb_register_read(rt2x00dev, AIFSN_CSR, &reg);
  1958. rt2x00_set_field32(&reg, field, queue->aifs);
  1959. rt2x00usb_register_write(rt2x00dev, AIFSN_CSR, reg);
  1960. rt2x00usb_register_read(rt2x00dev, CWMIN_CSR, &reg);
  1961. rt2x00_set_field32(&reg, field, queue->cw_min);
  1962. rt2x00usb_register_write(rt2x00dev, CWMIN_CSR, reg);
  1963. rt2x00usb_register_read(rt2x00dev, CWMAX_CSR, &reg);
  1964. rt2x00_set_field32(&reg, field, queue->cw_max);
  1965. rt2x00usb_register_write(rt2x00dev, CWMAX_CSR, reg);
  1966. return 0;
  1967. }
  1968. static u64 rt73usb_get_tsf(struct ieee80211_hw *hw)
  1969. {
  1970. struct rt2x00_dev *rt2x00dev = hw->priv;
  1971. u64 tsf;
  1972. u32 reg;
  1973. rt2x00usb_register_read(rt2x00dev, TXRX_CSR13, &reg);
  1974. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  1975. rt2x00usb_register_read(rt2x00dev, TXRX_CSR12, &reg);
  1976. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  1977. return tsf;
  1978. }
  1979. static const struct ieee80211_ops rt73usb_mac80211_ops = {
  1980. .tx = rt2x00mac_tx,
  1981. .start = rt2x00mac_start,
  1982. .stop = rt2x00mac_stop,
  1983. .add_interface = rt2x00mac_add_interface,
  1984. .remove_interface = rt2x00mac_remove_interface,
  1985. .config = rt2x00mac_config,
  1986. .configure_filter = rt2x00mac_configure_filter,
  1987. .set_tim = rt2x00mac_set_tim,
  1988. .set_key = rt2x00mac_set_key,
  1989. .sw_scan_start = rt2x00mac_sw_scan_start,
  1990. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  1991. .get_stats = rt2x00mac_get_stats,
  1992. .bss_info_changed = rt2x00mac_bss_info_changed,
  1993. .conf_tx = rt73usb_conf_tx,
  1994. .get_tsf = rt73usb_get_tsf,
  1995. .rfkill_poll = rt2x00mac_rfkill_poll,
  1996. .flush = rt2x00mac_flush,
  1997. .set_antenna = rt2x00mac_set_antenna,
  1998. .get_antenna = rt2x00mac_get_antenna,
  1999. .get_ringparam = rt2x00mac_get_ringparam,
  2000. };
  2001. static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
  2002. .probe_hw = rt73usb_probe_hw,
  2003. .get_firmware_name = rt73usb_get_firmware_name,
  2004. .check_firmware = rt73usb_check_firmware,
  2005. .load_firmware = rt73usb_load_firmware,
  2006. .initialize = rt2x00usb_initialize,
  2007. .uninitialize = rt2x00usb_uninitialize,
  2008. .clear_entry = rt2x00usb_clear_entry,
  2009. .set_device_state = rt73usb_set_device_state,
  2010. .rfkill_poll = rt73usb_rfkill_poll,
  2011. .link_stats = rt73usb_link_stats,
  2012. .reset_tuner = rt73usb_reset_tuner,
  2013. .link_tuner = rt73usb_link_tuner,
  2014. .watchdog = rt2x00usb_watchdog,
  2015. .start_queue = rt73usb_start_queue,
  2016. .kick_queue = rt2x00usb_kick_queue,
  2017. .stop_queue = rt73usb_stop_queue,
  2018. .flush_queue = rt2x00usb_flush_queue,
  2019. .write_tx_desc = rt73usb_write_tx_desc,
  2020. .write_beacon = rt73usb_write_beacon,
  2021. .clear_beacon = rt73usb_clear_beacon,
  2022. .get_tx_data_len = rt73usb_get_tx_data_len,
  2023. .fill_rxdone = rt73usb_fill_rxdone,
  2024. .config_shared_key = rt73usb_config_shared_key,
  2025. .config_pairwise_key = rt73usb_config_pairwise_key,
  2026. .config_filter = rt73usb_config_filter,
  2027. .config_intf = rt73usb_config_intf,
  2028. .config_erp = rt73usb_config_erp,
  2029. .config_ant = rt73usb_config_ant,
  2030. .config = rt73usb_config,
  2031. };
  2032. static const struct data_queue_desc rt73usb_queue_rx = {
  2033. .entry_num = 32,
  2034. .data_size = DATA_FRAME_SIZE,
  2035. .desc_size = RXD_DESC_SIZE,
  2036. .priv_size = sizeof(struct queue_entry_priv_usb),
  2037. };
  2038. static const struct data_queue_desc rt73usb_queue_tx = {
  2039. .entry_num = 32,
  2040. .data_size = DATA_FRAME_SIZE,
  2041. .desc_size = TXD_DESC_SIZE,
  2042. .priv_size = sizeof(struct queue_entry_priv_usb),
  2043. };
  2044. static const struct data_queue_desc rt73usb_queue_bcn = {
  2045. .entry_num = 4,
  2046. .data_size = MGMT_FRAME_SIZE,
  2047. .desc_size = TXINFO_SIZE,
  2048. .priv_size = sizeof(struct queue_entry_priv_usb),
  2049. };
  2050. static const struct rt2x00_ops rt73usb_ops = {
  2051. .name = KBUILD_MODNAME,
  2052. .max_sta_intf = 1,
  2053. .max_ap_intf = 4,
  2054. .eeprom_size = EEPROM_SIZE,
  2055. .rf_size = RF_SIZE,
  2056. .tx_queues = NUM_TX_QUEUES,
  2057. .extra_tx_headroom = TXD_DESC_SIZE,
  2058. .rx = &rt73usb_queue_rx,
  2059. .tx = &rt73usb_queue_tx,
  2060. .bcn = &rt73usb_queue_bcn,
  2061. .lib = &rt73usb_rt2x00_ops,
  2062. .hw = &rt73usb_mac80211_ops,
  2063. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2064. .debugfs = &rt73usb_rt2x00debug,
  2065. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2066. };
  2067. /*
  2068. * rt73usb module information.
  2069. */
  2070. static struct usb_device_id rt73usb_device_table[] = {
  2071. /* AboCom */
  2072. { USB_DEVICE(0x07b8, 0xb21b) },
  2073. { USB_DEVICE(0x07b8, 0xb21c) },
  2074. { USB_DEVICE(0x07b8, 0xb21d) },
  2075. { USB_DEVICE(0x07b8, 0xb21e) },
  2076. { USB_DEVICE(0x07b8, 0xb21f) },
  2077. /* AL */
  2078. { USB_DEVICE(0x14b2, 0x3c10) },
  2079. /* Amigo */
  2080. { USB_DEVICE(0x148f, 0x9021) },
  2081. { USB_DEVICE(0x0eb0, 0x9021) },
  2082. /* AMIT */
  2083. { USB_DEVICE(0x18c5, 0x0002) },
  2084. /* Askey */
  2085. { USB_DEVICE(0x1690, 0x0722) },
  2086. /* ASUS */
  2087. { USB_DEVICE(0x0b05, 0x1723) },
  2088. { USB_DEVICE(0x0b05, 0x1724) },
  2089. /* Belkin */
  2090. { USB_DEVICE(0x050d, 0x705a) },
  2091. { USB_DEVICE(0x050d, 0x905b) },
  2092. { USB_DEVICE(0x050d, 0x905c) },
  2093. /* Billionton */
  2094. { USB_DEVICE(0x1631, 0xc019) },
  2095. { USB_DEVICE(0x08dd, 0x0120) },
  2096. /* Buffalo */
  2097. { USB_DEVICE(0x0411, 0x00d8) },
  2098. { USB_DEVICE(0x0411, 0x00d9) },
  2099. { USB_DEVICE(0x0411, 0x00f4) },
  2100. { USB_DEVICE(0x0411, 0x0116) },
  2101. { USB_DEVICE(0x0411, 0x0119) },
  2102. { USB_DEVICE(0x0411, 0x0137) },
  2103. /* CEIVA */
  2104. { USB_DEVICE(0x178d, 0x02be) },
  2105. /* CNet */
  2106. { USB_DEVICE(0x1371, 0x9022) },
  2107. { USB_DEVICE(0x1371, 0x9032) },
  2108. /* Conceptronic */
  2109. { USB_DEVICE(0x14b2, 0x3c22) },
  2110. /* Corega */
  2111. { USB_DEVICE(0x07aa, 0x002e) },
  2112. /* D-Link */
  2113. { USB_DEVICE(0x07d1, 0x3c03) },
  2114. { USB_DEVICE(0x07d1, 0x3c04) },
  2115. { USB_DEVICE(0x07d1, 0x3c06) },
  2116. { USB_DEVICE(0x07d1, 0x3c07) },
  2117. /* Edimax */
  2118. { USB_DEVICE(0x7392, 0x7318) },
  2119. { USB_DEVICE(0x7392, 0x7618) },
  2120. /* EnGenius */
  2121. { USB_DEVICE(0x1740, 0x3701) },
  2122. /* Gemtek */
  2123. { USB_DEVICE(0x15a9, 0x0004) },
  2124. /* Gigabyte */
  2125. { USB_DEVICE(0x1044, 0x8008) },
  2126. { USB_DEVICE(0x1044, 0x800a) },
  2127. /* Huawei-3Com */
  2128. { USB_DEVICE(0x1472, 0x0009) },
  2129. /* Hercules */
  2130. { USB_DEVICE(0x06f8, 0xe002) },
  2131. { USB_DEVICE(0x06f8, 0xe010) },
  2132. { USB_DEVICE(0x06f8, 0xe020) },
  2133. /* Linksys */
  2134. { USB_DEVICE(0x13b1, 0x0020) },
  2135. { USB_DEVICE(0x13b1, 0x0023) },
  2136. { USB_DEVICE(0x13b1, 0x0028) },
  2137. /* MSI */
  2138. { USB_DEVICE(0x0db0, 0x4600) },
  2139. { USB_DEVICE(0x0db0, 0x6877) },
  2140. { USB_DEVICE(0x0db0, 0x6874) },
  2141. { USB_DEVICE(0x0db0, 0xa861) },
  2142. { USB_DEVICE(0x0db0, 0xa874) },
  2143. /* Ovislink */
  2144. { USB_DEVICE(0x1b75, 0x7318) },
  2145. /* Ralink */
  2146. { USB_DEVICE(0x04bb, 0x093d) },
  2147. { USB_DEVICE(0x148f, 0x2573) },
  2148. { USB_DEVICE(0x148f, 0x2671) },
  2149. { USB_DEVICE(0x0812, 0x3101) },
  2150. /* Qcom */
  2151. { USB_DEVICE(0x18e8, 0x6196) },
  2152. { USB_DEVICE(0x18e8, 0x6229) },
  2153. { USB_DEVICE(0x18e8, 0x6238) },
  2154. /* Samsung */
  2155. { USB_DEVICE(0x04e8, 0x4471) },
  2156. /* Senao */
  2157. { USB_DEVICE(0x1740, 0x7100) },
  2158. /* Sitecom */
  2159. { USB_DEVICE(0x0df6, 0x0024) },
  2160. { USB_DEVICE(0x0df6, 0x0027) },
  2161. { USB_DEVICE(0x0df6, 0x002f) },
  2162. { USB_DEVICE(0x0df6, 0x90ac) },
  2163. { USB_DEVICE(0x0df6, 0x9712) },
  2164. /* Surecom */
  2165. { USB_DEVICE(0x0769, 0x31f3) },
  2166. /* Tilgin */
  2167. { USB_DEVICE(0x6933, 0x5001) },
  2168. /* Philips */
  2169. { USB_DEVICE(0x0471, 0x200a) },
  2170. /* Planex */
  2171. { USB_DEVICE(0x2019, 0xab01) },
  2172. { USB_DEVICE(0x2019, 0xab50) },
  2173. /* WideTell */
  2174. { USB_DEVICE(0x7167, 0x3840) },
  2175. /* Zcom */
  2176. { USB_DEVICE(0x0cde, 0x001c) },
  2177. /* ZyXEL */
  2178. { USB_DEVICE(0x0586, 0x3415) },
  2179. { 0, }
  2180. };
  2181. MODULE_AUTHOR(DRV_PROJECT);
  2182. MODULE_VERSION(DRV_VERSION);
  2183. MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
  2184. MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
  2185. MODULE_DEVICE_TABLE(usb, rt73usb_device_table);
  2186. MODULE_FIRMWARE(FIRMWARE_RT2571);
  2187. MODULE_LICENSE("GPL");
  2188. static int rt73usb_probe(struct usb_interface *usb_intf,
  2189. const struct usb_device_id *id)
  2190. {
  2191. return rt2x00usb_probe(usb_intf, &rt73usb_ops);
  2192. }
  2193. static struct usb_driver rt73usb_driver = {
  2194. .name = KBUILD_MODNAME,
  2195. .id_table = rt73usb_device_table,
  2196. .probe = rt73usb_probe,
  2197. .disconnect = rt2x00usb_disconnect,
  2198. .suspend = rt2x00usb_suspend,
  2199. .resume = rt2x00usb_resume,
  2200. };
  2201. static int __init rt73usb_init(void)
  2202. {
  2203. return usb_register(&rt73usb_driver);
  2204. }
  2205. static void __exit rt73usb_exit(void)
  2206. {
  2207. usb_deregister(&rt73usb_driver);
  2208. }
  2209. module_init(rt73usb_init);
  2210. module_exit(rt73usb_exit);