rt73usb.c 76 KB

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