rt73usb.c 76 KB

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