rt73usb.c 75 KB

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