rt73usb.c 76 KB

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